72 #ifndef SLIP_TECPLOT_BINARIES_HPP
73 #define SLIP_TECPLOT_BINARIES_HPP
115 if (
typeid(T)==
typeid((
float) 0.))
117 else if (
typeid(T)==
typeid((
double) 0.))
119 else if (
typeid(T)==
typeid((
int) 0.))
121 else if (
typeid(T)==
typeid((
short int) 0.))
123 else if (
typeid(T)==
typeid((
char) 0.))
149 std::cerr<<
"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
152 long pos = fp.tellg();
155 for (
size_t i = 0; i < 8; ++i)
165 fp.read((
char*)tmp,
sizeof(
int));
190 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
228 std::cerr<<
"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
231 long pos = fp.tellg();
234 for (
size_t i = 0; i < 8; ++i)
243 fp.read((
char*)tmp,
sizeof(
int));
251 fp.read((
char*)tmp,
sizeof(
int));
291 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
330 void plt_read_header(std::ifstream &fp,
int &NbVars,
int &NbZones,
int &K,
int &I,
int &J, std::string &title, std::string &zonename, std::vector<std::string> &varnames,
double &SolTime,
int NumZone=1)
345 std::cerr<<
"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
352 for (
size_t i = 0; i < 8; ++i)
361 fp.read((
char*)tmp,
sizeof(
int));
369 fp.read((
char*)tmp,
sizeof(
int));
381 fp.read((
char*)tmp,
sizeof(
int));
382 title.append((
char*)tmp);
392 fp.read((
char*)tmp,
sizeof(
int));
399 for (
int i = 0; i < NbVars; ++i)
404 std::string nom_temp;
407 fp.read((
char*)tmp,
sizeof(
int));
408 nom_temp.append((
char*)tmp);
412 varnames.push_back(nom_temp);
424 float *marker=
new float;
426 while ((*marker!=357.0) && (*marker!=399.0))
431 float *tmp=
new float;
436 fp.read((
char*)tmp,
sizeof(
float));
461 fp.read((
char*)tmp,
sizeof(
int));
462 if (NbZones==NumZone)
463 zonename.append((
char*)tmp);
478 fp.read((
char*)tmp,
sizeof(
int));
490 fp.read((
char*)tmp,
sizeof(
int));
501 double *tmp=
new double;
502 fp.read((
char*)tmp,
sizeof(
double));
515 fp.read((
char*)tmp,
sizeof(
int));
523 std::cerr<<
"Reading error in plt_to_array"<<std::endl;
532 fp.read((
char*)tmp,
sizeof(
int));
545 fp.read((
char*)tmp,
sizeof(
int));
553 for (
int z=0; z<NbVars; ++z)
555 fp.read((
char*)tmp,
sizeof(
int));
569 fp.read((
char*)tmp,
sizeof(
int));
581 fp.read((
char*)tmp,
sizeof(
int));
590 fp.read((
char*)tmp2,
sizeof(
int));
605 fp.read((
char*)tmp,
sizeof(
int));
616 int *IMax=
new int, *JMax=
new int, *KMax=
new int;
617 fp.read((
char*)JMax,
sizeof(
int));
618 fp.read((
char*)IMax,
sizeof(
int));
619 fp.read((
char*)KMax,
sizeof(
int));
620 size=(*IMax)*(*JMax)*(*KMax);
621 if (NbZones==NumZone)
635 fp.read((
char*)tmp,
sizeof(
int));
672 void plt_read_header(std::ifstream &fp,
int &NbVars,
int &NbZones,
int &K,
int &I,
int &J,
int NumZone=1)
674 std::string _useless_string;
675 std::vector<std::string> _useless_varnames;
677 plt_read_header(fp, NbVars, NbZones, K, I, J, _useless_string, _useless_string, _useless_varnames, SolTime, NumZone);
703 void plt_read_header(
const std::string & file_path_name,
int &NbVars,
int &NbZones,
int &K,
int &I,
int &J,
int NumZone=1)
706 std::string _useless_string;
707 std::vector<std::string> _useless_varnames;
708 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
709 plt_read_header(fp, NbVars, NbZones, K, I, J, _useless_string, _useless_string, _useless_varnames, SolTime, NumZone);
738 void plt_read_header(
const std::string & file_path_name,
int &NbVars,
int &NbZones,
int &K,
int &I,
int &J,
double &SolTime,
int NumZone=1)
740 std::string _useless_string;
741 std::vector<std::string> _useless_varnames;
742 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
743 plt_read_header(fp, NbVars, NbZones, K, I, J, _useless_string, _useless_string, _useless_varnames, SolTime, NumZone);
778 void plt_read_header(
const std::string & file_path_name,
int &NbVars,
int &NbZones,
int &K,
int &I,
int &J, std::string &title, std::string &zonename, std::vector<std::string> &varnames,
double &SolTime,
int NumZone=1)
780 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
781 plt_read_header(fp, NbVars, NbZones, K, I, J, title, zonename, varnames, SolTime, NumZone);
802 template<
typename Container2d>
805 const int zone_loaded=1)
807 typedef typename Container2d::value_type T;
809 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
810 int ZoneLoaded = zone_loaded;
815 int nbzones=0, size=0;
816 int Imax=1, Jmax=1, Kmax=1;
822 reg.resize(size,nbvars);
823 if (ZoneLoaded>nbzones)
832 for (
int NumZone = 1; NumZone <= nbzones; ++NumZone)
834 int *datatype=
new int[nbvars];
836 float *tmp=
new float;
837 fp.read((
char*)tmp,
sizeof(
float));
842 for (
int i = 0; i < nbvars; ++i)
845 fp.read((
char*)tmp,
sizeof(
int));
851 for (
size_t i = 0; i < 3; ++i)
854 fp.read((
char*)tmp,
sizeof(
int));
855 if ((i==0||i==1)&&(*tmp)!=0)
857 for (
int j = 0; j < nbvars; ++j)
859 fp.read((
char*)tmp,
sizeof(
int));
866 for (
int i = 0; i < nbvars; ++i)
868 double *
min=
new double, *
max=
new double;
869 fp.read((
char*)min,
sizeof(
double));
870 fp.read((
char*)max,
sizeof(
double));
874 if (NumZone!=ZoneLoaded)
876 for (
int i = 0; i < nbvars; ++i)
881 fp.seekg((size)*
sizeof(
float), std::ios::cur);
884 fp.seekg((size)*
sizeof(
double), std::ios::cur);
887 fp.seekg((size)*
sizeof(
int), std::ios::cur);
890 fp.seekg((size)*
sizeof(
short int), std::ios::cur);
894 fp.seekg((size)*
sizeof(
char), std::ios::cur);
903 for (
int i = 0; i < nbvars; ++i)
909 float *tmp=
new float[size];
910 fp.read((
char*)tmp, size*
sizeof(
float));
911 for (
int ii = 0; ii < size; ii++)
912 reg(ii,i)=
static_cast<T
>(*(tmp+ii));
918 double *tmp=
new double[size];
919 fp.read((
char*)tmp, size*
sizeof(
double));
920 for (
int ii = 0; ii < size; ii++)
921 reg(ii,i)=
static_cast<T
>(*(tmp+ii));
927 int *tmp=
new int[size];
928 fp.read((
char*)tmp, size*
sizeof(
int));
929 for (
int ii = 0; ii < size; ii++)
930 reg(ii,i)=
static_cast<T
>(*(tmp+ii));
936 short int *tmp=
new short int[size];
937 fp.read((
char*)tmp, size*
sizeof(
short int));
938 for (
int ii = 0; ii < size; ii++)
939 reg(ii,i)=
static_cast<T
>(*(tmp+ii));
946 char *tmp=
new char[size];
947 fp.read((
char*)tmp, size*
sizeof(
char));
948 for (
int ii = 0; ii < size; ii++)
949 reg(ii,i)=
static_cast<T
>(*(tmp+ii));
989 template<
typename RegularVector3dField3d>
993 std::string &zonename,
994 std::vector<std::string> &varnames,
995 const int zone_loaded=1)
999 int ZoneLoaded = zone_loaded;
1004 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
1011 int nbzones=0, size=0;
1012 int Imax=1, Jmax=1, Kmax=1;
1014 plt_read_header(fp, nbvars, nbzones, Kmax, Imax, Jmax, title, zonename, varnames, SolTime, ZoneLoaded);
1015 size=Imax*Jmax*Kmax;
1019 reg.
resize(Kmax,Imax,Jmax);
1020 if (ZoneLoaded>nbzones) ZoneLoaded=nbzones;
1021 if (ZoneLoaded<1) ZoneLoaded=1;
1023 for (
int NumZone = 1; NumZone <= nbzones; ++NumZone)
1026 float *tmp=
new float;
1027 fp.read((
char*)tmp,
sizeof(
float));
1032 int *datatype=
new int[nbvars];
1033 for (
int i = 0; i < nbvars; ++i)
1036 fp.read((
char*)tmp,
sizeof(
int));
1042 for (
size_t i = 0; i < 3; ++i)
1045 fp.read((
char*)tmp,
sizeof(
int));
1046 if ((i==0||i==1)&&(*tmp)!=0)
1048 for (
int j = 0; j < nbvars; ++j)
1050 fp.read((
char*)tmp,
sizeof(
int));
1057 for (
int i = 0; i < nbvars; ++i)
1059 double *
min=
new double, *
max=
new double;
1060 fp.read((
char*)min,
sizeof(
double));
1061 fp.read((
char*)max,
sizeof(
double));
1065 if (NumZone!=ZoneLoaded)
1067 for (
int num = 0; num < nbvars; num++)
1069 switch (datatype[num])
1072 fp.seekg((size)*
sizeof(
float), std::ios::cur);
1075 fp.seekg((size)*
sizeof(
double), std::ios::cur);
1078 fp.seekg((size)*
sizeof(
int), std::ios::cur);
1081 fp.seekg((size)*
sizeof(
short int), std::ios::cur);
1085 fp.seekg((size)*
sizeof(
char), std::ios::cur);
1094 for (
int i = 0; i < nbvars; ++i)
1096 if ( FileType!=2 && i<3 )
1098 GridT *
min=
new GridT, *
max=
new GridT;
1099 switch (datatype[i])
1103 float *tmp=
new float;
1104 fp.read((
char*)tmp,
sizeof(
float));
1105 *min=
static_cast<GridT
>(*tmp);
1106 fp.seekg((size-2)*
sizeof(
float), std::ios::cur);
1107 fp.read((
char*)tmp,
sizeof(
float));
1108 *max=
static_cast<GridT
>(*tmp);
1114 double *tmp=
new double;
1115 fp.read((
char*)tmp,
sizeof(
double));
1116 *min=
static_cast<GridT
>(*tmp);
1117 fp.seekg((size-2)*
sizeof(
double), std::ios::cur);
1118 fp.read((
char*)tmp,
sizeof(
double));
1119 *max=
static_cast<GridT
>(*tmp);
1126 fp.read((
char*)tmp,
sizeof(
int));
1127 *min=
static_cast<GridT
>(*tmp);
1128 fp.seekg((size-2)*
sizeof(
int), std::ios::cur);
1129 fp.read((
char*)tmp,
sizeof(
int));
1130 *max=
static_cast<GridT
>(*tmp);
1136 short int *tmp=
new short int;
1137 fp.read((
char*)tmp,
sizeof(
short int));
1138 *min=
static_cast<GridT
>(*tmp);
1139 fp.seekg((size-2)*
sizeof(
short int), std::ios::cur);
1140 fp.read((
char*)tmp,
sizeof(
short int));
1141 *max=
static_cast<GridT
>(*tmp);
1149 fp.read((
char*)tmp,
sizeof(
char));
1150 *min=
static_cast<GridT
>(*tmp);
1151 fp.seekg((size-2)*
sizeof(
char), std::ios::cur);
1152 fp.read((
char*)tmp,
sizeof(
char));
1153 *max=
static_cast<GridT
>(*tmp);
1176 grid[i]=
std::abs((*min)-(*max))/(Nmax-1.);
1182 else if ( ( FileType==0 && i<6 ) || ( FileType==2 && i<3 ) )
1187 switch (datatype[i])
1191 float *tmp=
new float[size];
1192 fp.read((
char*)tmp, size*
sizeof(
float));
1193 for (
int kk = Kmax-1; kk >= 0; --kk)
1195 for (
int ii = Imax-1; ii >= 0; --ii)
1197 for (
int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1198 reg(kk,ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
1206 double *tmp=
new double[size];
1207 fp.read((
char*)tmp, size*
sizeof(
double));
1208 for (
int kk = Kmax-1; kk >= 0; --kk)
1210 for (
int ii = Imax-1; ii >= 0; --ii)
1212 for (
int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1213 reg(kk,ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
1221 int *tmp=
new int[size];
1222 fp.read((
char*)tmp, size*
sizeof(
int));
1223 for (
int kk = Kmax-1; kk >= 0; --kk)
1225 for (
int ii = Imax-1; ii >= 0; --ii)
1227 for (
int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1228 reg(kk,ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
1236 short int *tmp=
new short int[size];
1237 fp.read((
char*)tmp, size*
sizeof(
short int));
1238 for (
int kk = Kmax-1; kk >= 0; --kk)
1240 for (
int ii = Imax-1; ii >= 0; --ii)
1242 for (
int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1243 reg(kk,ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
1252 char *tmp=
new char[size];
1253 fp.read((
char*)tmp, size*
sizeof(
char));
1254 for (
int kk = Kmax-1; kk >= 0; --kk)
1256 for (
int ii = Imax-1; ii >= 0; --ii)
1258 for (
int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1259 reg(kk,ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
1297 template<
typename RegularVector3dField3d>
1300 const int zone_loaded=1)
1303 std::string _useless_string;
1304 std::vector<std::string> _useless_varnames;
1342 return ( (rowA[2]<rowB[2]) || ((rowA[2]==rowB[2])&&(rowA[0]<rowB[0])) || ((rowA[2]==rowB[2])&&(rowA[0]==rowB[0])&&(rowA[1]<rowB[1])) );
1373 template<
typename RegularVector3dField3d>
1377 std::string &zonename,
1378 std::vector<std::string> &varnames,
1379 const int zone_loaded=1)
1383 int ZoneLoaded = zone_loaded;
1388 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
1396 if ( ! ( ( data[0][0] == data[1][0] && data[0][1] != data[1][1] ) || ( data[0][0] != data[1][0] && data[0][1] == data[1][1] ) ) || FileType==2 )
1402 T** datab = &(data[0]);
1405 for (
size_t i = 0; i < data.
dim1(); ++i)
1407 for (
size_t j = 0; j < data.
dim2(); ++j)
1409 test_data[i][j]=data[i][j];
1416 std::size_t size = data.
rows();
1417 std::size_t size_xy = std::count(data.
col_begin(2),data.
col_end(2),data[0][2]);
1418 std::size_t size_z = size / size_xy;
1419 std::size_t size_y = std::count(data.
col_begin(0),data.
col_end(0),data[0][0]);
1420 size_y = size_y / size_z;
1421 std::size_t size_x = size / (size_y * size_z);
1423 init[0]=
static_cast<GridT
>(
std::min(data[0][0],data[data.
rows()-1][0]));
1424 init[1]=
static_cast<GridT
>(
std::min(data[0][1],data[data.
rows()-1][1]));
1425 init[2]=
static_cast<GridT
>(
std::min(data[0][2],data[data.
rows()-1][2]));
1427 bool y_direct = (init[1] == data[0][1]);
1429 reg.
resize(size_z,size_y,size_x);
1431 if( data[0][0] == data[1][0] || FileType==1 )
1439 std::size_t gridz = 0;
1440 for(std::size_t k = 0 ; k < size_z; ++k)
1442 std::size_t gridy = 0;
1444 for(std::size_t j = 0; j < size_x; ++j)
1449 data.
col_begin(4) + (gridz + gridy + size_y),
1452 data.
col_begin(3) + (gridz + gridy + size_y),
1455 data.
col_begin(5) + (gridz + gridy + size_y),
1462 data.
col_begin(4) + (gridz + gridy + size_y),
1465 data.
col_begin(3) + (gridz + gridy + size_y),
1468 data.
col_begin(5) + (gridz + gridy + size_y),
1483 std::size_t gridz = 0;
1484 for(std::size_t k = 0 ; k < size_z; ++k)
1486 std::size_t gridx = 0;
1487 for(std::size_t j = 0; j < size_y; ++j)
1492 data.
col_begin(3) + (gridz + gridx + size_x),
1493 reg.
row_begin(0,(size_z-1)-k,(size_y - 1) - j));
1495 data.
col_begin(4) + (gridz + gridx + size_x),
1496 reg.
row_begin(1,(size_z-1)-k,(size_y - 1) - j));
1498 data.
col_begin(5) + (gridz + gridx + size_x),
1499 reg.
row_begin(2,(size_z-1)-k,(size_y - 1) - j));
1505 data.
col_begin(3) + gridz + (gridx + size_x),
1508 data.
col_begin(4) + (gridz + gridx + size_x),
1511 data.
col_begin(5) + (gridz + gridx + size_x),
1547 template<
typename RegularVector3dField3d>
1550 const int zone_loaded=1)
1553 std::string _useless_string;
1554 std::vector<std::string> _useless_varnames;
1585 template<
typename RegularVector3dField3d>
1590 const double SolTime,
1591 std::vector<std::string> varnames=std::vector<std::string>(),
1592 const int FileType=0)
1596 std::ofstream fp (file_path_name.c_str(), std::ios::out|std::ios::binary);
1602 fp.write(
"#!TDV112",8);
1604 char *mychar=
new char;
1605 float *myfloat=
new float;
1606 double *mydouble=
new double;
1609 fp.write((
char*)myint,
sizeof(
int));
1613 fp.write((
char*)myint,
sizeof(
int));
1616 std::string strtmp=title;
1617 for (
size_t i = 0; i <= strtmp.size(); i++)
1619 *myint=(int)strtmp[i];
1620 fp.write((
char*)myint,
sizeof(
int));
1624 size_t imin=0, imax=6, nbvars=6;
1631 if (varnames.size()<3)
1634 varnames.push_back(
"X");
1635 varnames.push_back(
"Y");
1636 varnames.push_back(
"Z");
1643 if (varnames.size()<3)
1646 varnames.push_back(
"U");
1647 varnames.push_back(
"V");
1648 varnames.push_back(
"W");
1652 if (varnames.size()<6)
1655 varnames.push_back(
"X");
1656 varnames.push_back(
"Y");
1657 varnames.push_back(
"Z");
1658 varnames.push_back(
"U");
1659 varnames.push_back(
"V");
1660 varnames.push_back(
"W");
1667 fp.write((
char*)myint,
sizeof(
int));
1670 for (
size_t i = imin; i < imax; i++)
1672 for (
size_t j = 0; j <= varnames[i].size(); j++)
1674 *myint=(int)varnames[i][j];
1675 fp.write((
char*)myint,
sizeof(
int));
1682 fp.write((
char*)myfloat,
sizeof(
float));
1685 for (
size_t i = 0; i <= strtmp.size(); i++)
1687 *myint=(int)strtmp[i];
1688 fp.write((
char*)myint,
sizeof(
int));
1692 fp.write((
char*)myint,
sizeof(
int));
1695 fp.write((
char*)myint,
sizeof(
int));
1698 fp.write((
char*)mydouble,
sizeof(
double));
1701 fp.write((
char*)myint,
sizeof(
int));
1704 fp.write((
char*)myint,
sizeof(
int));
1706 fp.write((
char*)myint,
sizeof(
int));
1708 fp.write((
char*)myint,
sizeof(
int));
1710 fp.write((
char*)myint,
sizeof(
int));
1713 fp.write((
char*)myint,
sizeof(
int));
1715 fp.write((
char*)myint,
sizeof(
int));
1717 fp.write((
char*)myint,
sizeof(
int));
1720 fp.write((
char*)myint,
sizeof(
int));
1723 fp.write((
char*)myfloat,
sizeof(
float));
1731 fp.write((
char*)myfloat,
sizeof(
float));
1733 *myint=get_tecplot_type<GridT>();
1734 if (FileType==0 || FileType==1)
1736 for (
size_t i = 0; i < 3; ++i)
1737 fp.write((
char*)myint,
sizeof(
int));
1739 *myint=get_tecplot_type<T>();
1740 if (FileType==0 || FileType==2)
1742 for (
size_t i = 0; i < 3; ++i)
1743 fp.write((
char*)myint,
sizeof(
int));
1747 fp.write((
char*)myint,
sizeof(
int));
1748 fp.write((
char*)myint,
sizeof(
int));
1750 fp.write((
char*)myint,
sizeof(
int));
1752 if (FileType==0 || FileType==1)
1755 fp.write((
char*)mydouble,
sizeof(
double));
1757 fp.write((
char*)mydouble,
sizeof(
double));
1759 fp.write((
char*)mydouble,
sizeof(
double));
1761 fp.write((
char*)mydouble,
sizeof(
double));
1763 fp.write((
char*)mydouble,
sizeof(
double));
1765 fp.write((
char*)mydouble,
sizeof(
double));
1768 if (FileType==0 || FileType==2)
1770 double umin, umax, vmin, vmax, wmin, wmax;
1778 fp.write((
char*)mydouble,
sizeof(
double));
1780 fp.write((
char*)mydouble,
sizeof(
double));
1782 fp.write((
char*)mydouble,
sizeof(
double));
1784 fp.write((
char*)mydouble,
sizeof(
double));
1786 fp.write((
char*)mydouble,
sizeof(
double));
1788 fp.write((
char*)mydouble,
sizeof(
double));
1791 if (FileType==0 || FileType==1)
1793 const int size_grid=
sizeof(GridT);
1794 for (
int kk = reg.
dim1()-1; kk >= 0; --kk)
1796 for (
int ii = reg.
dim2()-1; ii >= 0; --ii)
1798 for (
int jj = 0; jj < (int)reg.
dim3(); ++jj)
1800 GridT *temp=
new GridT;
1801 *temp=reg.
x(kk,ii,jj);
1802 fp.write((
char*)temp, size_grid);
1807 for (
int kk = reg.
dim1()-1; kk >= 0; --kk)
1809 for (
int ii = reg.
dim2()-1; ii >= 0; --ii)
1811 for (
int jj = 0; jj < (int)reg.
dim3(); ++jj)
1813 GridT *temp=
new GridT;
1814 *temp=reg.
y(kk,ii,jj);
1815 fp.write((
char*)temp, size_grid);
1820 for (
int kk = reg.
dim1()-1; kk >= 0; --kk)
1822 for (
int ii = reg.
dim2()-1; ii >= 0; --ii)
1824 for (
int jj = 0; jj < (int)reg.
dim3(); ++jj)
1826 GridT *temp=
new GridT;
1827 *temp=reg.
z(kk,ii,jj);
1828 fp.write((
char*)temp, size_grid);
1835 if (FileType==0 || FileType==2)
1837 const int size_data=
sizeof(T);
1838 for (
size_t i = 0; i < 3; ++i)
1840 for (
int kk = reg.
dim1()-1; kk >= 0; --kk)
1842 for (
int ii = reg.
dim2()-1; ii >= 0; --ii)
1844 for (
int jj = 0; jj < (int)reg.
dim3(); ++jj)
1847 *temp=reg(kk,ii,jj)[i];
1848 fp.write((
char*)temp, size_data);
1878 template<
typename RegularVector3dField3d>
1881 const int FileType=0)
1905 template<
typename RegularVector3dField3d>
1908 const double SolTime,
1909 const int FileType=0)
1933 template<
typename RegularVector3dField3d>
1938 const int FileType=0)
1963 template<
typename RegularVector3dField3d>
1968 std::vector<std::string> varnames,
1969 const int FileType=0)
2002 template<
typename RegularVector2dField2d>
2006 std::string &zonename,
2007 std::vector<std::string> &varnames,
2008 const int zone_loaded=1)
2012 int ZoneLoaded = zone_loaded;
2013 if (ZoneLoaded<1) ZoneLoaded=1;
2018 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
2025 int nbzones=0, size=0;
2026 int Imax=1, Jmax=1, Kmax=1;
2028 plt_read_header(fp, nbvars, nbzones, Kmax, Imax, Jmax, title, zonename, varnames, SolTime, ZoneLoaded);
2029 size=Imax*Jmax*Kmax;
2034 if (ZoneLoaded>nbzones) ZoneLoaded=nbzones;
2036 for (
int NumZone = 1; NumZone <= nbzones; ++NumZone)
2039 float *tmp=
new float;
2040 fp.read((
char*)tmp,
sizeof(
float));
2045 int *datatype=
new int[nbvars];
2046 for (
int i = 0; i < nbvars; ++i)
2049 fp.read((
char*)tmp,
sizeof(
int));
2054 for (
size_t i = 0; i < 3; ++i)
2057 fp.read((
char*)tmp,
sizeof(
int));
2058 if ((i==0||i==1)&&(*tmp)!=0)
2060 for (
int j = 0; j < nbvars; ++j)
2062 fp.read((
char*)tmp,
sizeof(
int));
2069 for (
int i = 0; i < nbvars; ++i)
2071 double *
min=
new double, *
max=
new double;
2072 fp.read((
char*)min,
sizeof(
double));
2073 fp.read((
char*)max,
sizeof(
double));
2077 if (NumZone!=ZoneLoaded)
2079 for (
int num = 0; num < nbvars; num++)
2080 switch (datatype[num])
2083 fp.seekg((size)*
sizeof(
float), std::ios::cur);
2086 fp.seekg((size)*
sizeof(
double), std::ios::cur);
2089 fp.seekg((size)*
sizeof(
int), std::ios::cur);
2092 fp.seekg((size)*
sizeof(
short int), std::ios::cur);
2096 fp.seekg((size)*
sizeof(
char), std::ios::cur);
2104 for (
int i = 0; i < nbvars; ++i)
2106 if ( FileType!=2 && i<2 )
2108 GridT *
min=
new GridT, *
max=
new GridT;
2111 float *tmp=
new float;
2112 fp.read((
char*)tmp,
sizeof(
float));
2113 *min=
static_cast<GridT
>(*tmp);
2114 fp.seekg((size-2)*
sizeof(
float), std::ios::cur);
2115 fp.read((
char*)tmp,
sizeof(
float));
2116 *max=
static_cast<GridT
>(*tmp);
2119 else if (datatype[i]==2)
2122 fp.read((
char*)tmp,
sizeof(
double));
2123 *min=
static_cast<GridT
>(*tmp);
2124 fp.seekg((size-2)*
sizeof(
double), std::ios::cur);
2125 fp.read((
char*)tmp,
sizeof(
double));
2126 *max=
static_cast<GridT
>(*tmp);
2129 else if (datatype[i]==3)
2132 fp.read((
char*)tmp,
sizeof(
int));
2133 *min=
static_cast<GridT
>(*tmp);
2134 fp.seekg((size-2)*
sizeof(
int), std::ios::cur);
2135 fp.read((
char*)tmp,
sizeof(
int));
2136 *max=
static_cast<GridT
>(*tmp);
2139 else if (datatype[i]==4)
2141 short int *tmp=
new short int;
2142 fp.read((
char*)tmp,
sizeof(
short int));
2143 *min=
static_cast<GridT
>(*tmp);
2144 fp.seekg((size-2)*
sizeof(
short int), std::ios::cur);
2145 fp.read((
char*)tmp,
sizeof(
short int));
2146 *max=
static_cast<GridT
>(*tmp);
2149 else if (datatype[i]==5||datatype[i]==6)
2152 fp.read((
char*)tmp,
sizeof(
char));
2153 *min=
static_cast<GridT
>(*tmp);
2154 fp.seekg((size-2)*
sizeof(
char), std::ios::cur);
2155 fp.read((
char*)tmp,
sizeof(
char));
2156 *max=
static_cast<GridT
>(*tmp);
2174 grid[i]=
std::abs((*min)-(*max))/(Nmax-1.);
2180 else if ( ( FileType==0 && i<4 ) || ( FileType==2 && i<2 ) )
2185 switch (datatype[i])
2189 float *tmp=
new float[size];
2190 fp.read((
char*)tmp, size*
sizeof(
float));
2191 for (
int ii = Imax-1; ii >= 0; --ii)
2193 for (
int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2195 reg(ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
2203 double *tmp=
new double[size];
2204 fp.read((
char*)tmp, size*
sizeof(
double));
2205 for (
int ii = Imax-1; ii >= 0; --ii)
2207 for (
int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2209 reg(ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
2217 int *tmp=
new int[size];
2218 fp.read((
char*)tmp, size*
sizeof(
int));
2219 for (
int ii = Imax-1; ii >= 0; --ii)
2221 for (
int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2223 reg(ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
2231 short int *tmp=
new short int[size];
2232 fp.read((
char*)tmp, size*
sizeof(
short int));
2233 for (
int ii = Imax-1; ii >= 0; --ii)
2235 for (
int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2237 reg(ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
2246 char *tmp=
new char[size];
2247 fp.read((
char*)tmp, size*
sizeof(
char));
2248 for (
int ii = Imax-1; ii >= 0; --ii)
2250 for (
int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2252 reg(ii,jj)[comp]=
static_cast<T
>(*(tmp+n));
2291 template<
typename RegularVector2dField2d>
2294 const int zone_loaded=1)
2296 std::string _useless_string;
2297 std::vector<std::string> _useless_varnames;
2335 return ( (rowA[0]<rowB[0]) || ( (rowA[0]==rowB[0])&&(rowA[1]<rowB[1]) ) );
2366 template<
typename RegularVector2dField2d>
2370 std::string &zonename,
2371 std::vector<std::string> &varnames,
2372 const int zone_loaded=1)
2376 int ZoneLoaded = zone_loaded;
2377 if (ZoneLoaded<1) ZoneLoaded=1;
2382 std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
2390 if ( ! ( ( data[0][0] == data[1][0] && data[0][1] != data[1][1] ) || ( data[0][0] != data[1][0] && data[0][1] == data[1][1] ) ) )
2395 T** datab = &(data[0]);
2399 for (
size_t i = 0; i < data.
dim1(); ++i)
2401 for (
size_t j = 0; j < data.
dim2(); ++j)
2403 test_data[i][j]=data[i][j];
2412 std::size_t size_x = data.
rows() / size_y;
2414 init[0]=
static_cast<GridT
>(
std::min(data[0][0],data[data.
rows()-1][0]));
2415 init[1]=
static_cast<GridT
>(
std::min(data[0][1],data[data.
rows()-1][1]));
2417 bool y_direct = (init[1] == data[0][1]);
2419 reg.
resize(size_y,size_x);
2420 if( data[0][0] == data[1][0] || FileType==1 )
2427 std::size_t gridy = 0;
2429 for(std::size_t j = 0; j < size_x; ++j)
2459 std::size_t gridx = 0;
2460 for(std::size_t j = 0; j < size_y; ++j)
2512 template<
typename RegularVector2dField2d>
2515 const int zone_loaded=1)
2517 std::string _useless_string;
2518 std::vector<std::string> _useless_varnames;
2546 template<
typename RegularVector2dField2d>
2551 const double SolTime,
2552 std::vector<std::string> varnames=std::vector<std::string>(),
2553 const int FileType=0)
2557 std::ofstream fp (file_path_name.c_str(), std::ios::out|std::ios::binary);
2563 fp.write(
"#!TDV112",8);
2565 char *mychar=
new char;
2566 float *myfloat=
new float;
2567 double *mydouble=
new double;
2570 fp.write((
char*)myint,
sizeof(
int));
2574 fp.write((
char*)myint,
sizeof(
int));
2577 std::string strtmp=title;
2578 for (
size_t i = 0; i <= strtmp.size(); i++)
2580 *myint=(int)strtmp[i];
2581 fp.write((
char*)myint,
sizeof(
int));
2585 size_t imin=0, imax=4, nbvars=4;
2592 if (varnames.size()<2)
2595 varnames.push_back(
"X");
2596 varnames.push_back(
"Y");
2603 if (varnames.size()<2)
2606 varnames.push_back(
"U");
2607 varnames.push_back(
"V");
2611 if (varnames.size()<4)
2614 varnames.push_back(
"X");
2615 varnames.push_back(
"Y");
2616 varnames.push_back(
"U");
2617 varnames.push_back(
"V");
2624 fp.write((
char*)myint,
sizeof(
int));
2627 for (
size_t i = imin; i < imax; i++)
2629 for (
size_t j = 0; j <= varnames[i].size(); j++)
2631 *myint=(int)varnames[i][j];
2632 fp.write((
char*)myint,
sizeof(
int));
2639 fp.write((
char*)myfloat,
sizeof(
float));
2642 for (
size_t i = 0; i <= strtmp.size(); i++)
2644 *myint=(int)strtmp[i];
2645 fp.write((
char*)myint,
sizeof(
int));
2649 fp.write((
char*)myint,
sizeof(
int));
2652 fp.write((
char*)myint,
sizeof(
int));
2655 fp.write((
char*)mydouble,
sizeof(
double));
2658 fp.write((
char*)myint,
sizeof(
int));
2661 fp.write((
char*)myint,
sizeof(
int));
2663 fp.write((
char*)myint,
sizeof(
int));
2665 fp.write((
char*)myint,
sizeof(
int));
2667 fp.write((
char*)myint,
sizeof(
int));
2670 fp.write((
char*)myint,
sizeof(
int));
2672 fp.write((
char*)myint,
sizeof(
int));
2674 fp.write((
char*)myint,
sizeof(
int));
2677 fp.write((
char*)myint,
sizeof(
int));
2680 fp.write((
char*)myfloat,
sizeof(
float));
2688 fp.write((
char*)myfloat,
sizeof(
float));
2690 *myint=get_tecplot_type<GridT>();
2691 if (FileType==0 || FileType==1)
2693 for (
size_t i = 0; i < 2; ++i)
2694 fp.write((
char*)myint,
sizeof(
int));
2696 *myint=get_tecplot_type<T>();
2697 if (FileType==0 || FileType==2)
2699 for (
size_t i = 0; i < 2; ++i)
2700 fp.write((
char*)myint,
sizeof(
int));
2704 fp.write((
char*)myint,
sizeof(
int));
2705 fp.write((
char*)myint,
sizeof(
int));
2707 fp.write((
char*)myint,
sizeof(
int));
2709 if (FileType==0 || FileType==1)
2712 fp.write((
char*)mydouble,
sizeof(
double));
2714 fp.write((
char*)mydouble,
sizeof(
double));
2716 fp.write((
char*)mydouble,
sizeof(
double));
2718 fp.write((
char*)mydouble,
sizeof(
double));
2721 if (FileType==0 || FileType==2)
2723 double umin, umax, vmin, vmax, wmin, wmax;
2729 fp.write((
char*)mydouble,
sizeof(
double));
2731 fp.write((
char*)mydouble,
sizeof(
double));
2733 fp.write((
char*)mydouble,
sizeof(
double));
2735 fp.write((
char*)mydouble,
sizeof(
double));
2738 if (FileType==0 || FileType==1)
2740 const int size_grid=
sizeof(GridT);
2741 for (
int ii = reg.
dim1()-1; ii >= 0; --ii)
2743 for (
int jj = 0; jj < (int)reg.
dim2(); ++jj)
2745 GridT *temp=
new GridT;
2747 fp.write((
char*)temp, size_grid);
2751 for (
int ii = reg.
dim1()-1; ii >= 0; --ii)
2753 for (
int jj = 0; jj < (int)reg.
dim2(); ++jj)
2755 GridT *temp=
new GridT;
2757 fp.write((
char*)temp, size_grid);
2763 if (FileType==0 || FileType==2)
2765 const int size_data=
sizeof(T);
2766 for (
size_t i = 0; i < 2; ++i)
2768 for (
int ii = reg.
dim1()-1; ii >= 0; --ii)
2770 for (
int jj = 0; jj < (int)reg.
dim2(); ++jj)
2773 *temp=reg(ii,jj)[i];
2774 fp.write((
char*)temp, size_data);
2803 template<
typename RegularVector2dField2d>
2806 const int FileType=0)
2830 template<
typename RegularVector2dField2d>
2833 const double SolTime,
2834 const int FileType=0)
2858 template<
typename RegularVector2dField2d>
2863 const int FileType=0)
2888 template<
typename RegularVector2dField2d>
2893 std::vector<std::string> varnames,
2894 const int FileType=0)
Provides a class to manipulate 2d dynamic and generic arrays.
const GridT x(const size_type i, const size_type j) const
Subscript access to the real x1 value of the indexed (i,j) point of the RegularVector2dField2d.
Provides a class to modelize 3d points.
iterator begin()
Returns a read/write iterator that points to the first element in the GenericMultiComponent2d. Iteration is done in ordinary element order.
bool compareTwoRows3D(double *rowA, double *rowB)
Comparator used to sort an Array2d.
const GridT x(const size_type k, const size_type i, const size_type j) const
Subscript access to the real x1 value of the indexed (k,i,j) point of the RegularVector3dField3d.
col_iterator col_begin(const size_type col)
Returns a read/write iterator that points to the first element of the column column in the GenericMul...
void resize(const size_type height, const size_type width, const Block &val=Block())
Resizes a GenericMultiComponent2d.
size_type dim3() const
Returns the number of columns (third dimension size) in the GenericMultiComponent3d.
const GridT y(const size_type k, const size_type i, const size_type j) const
Subscript access to the real x2 value of the indexed (k,i,j) point of the RegularVector3dField3d.
void set_grid_step(const slip::Point2d< GridT > &grid_step)
Write access to the grid step of the grid.
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
iterator begin()
Returns a read/write iterator that points to the first element in the GenericMultiComponent3d. Iteration is done in ordinary element order.
row_iterator row_begin(const size_type slice, const size_type row)
Returns a read/write iterator that points to the first element of the row row of the slice slice in t...
size_type dim2() const
Returns the number of rows (second dimension size) in the GenericMultiComponent3d.
GenericComparator(int s_)
size_type dim2() const
Returns the number of columns (second dimension size) in the GenericMultiComponent2d.
row_iterator row_begin(const size_type row)
Returns a read/write iterator that points to the first element of the row row in the GenericMultiComp...
void generic_plt_to_RegularVector3dField3d(const std::string &file_path_name, RegularVector3dField3d ®, std::string &title, std::string &zonename, std::vector< std::string > &varnames, const int zone_loaded=1)
Read a slip::RegularVector3dField3d from a binary tecplot file even if data are not properly sorted...
const slip::Point2d< GridT > & get_grid_step() const
Read access to the init point of the grid.
Provides a class to manipulate 2d Vector.
This is a 2d Field containing slip::Vector2d associated with a regular grid. This container statisfie...
HyperVolume< T > abs(const HyperVolume< T > &M)
void set_grid_step(const slip::Point3d< GridT > &grid_step)
Write access to the grid step of the grid.
void set_init_point(const slip::Point2d< GridT > &init_point)
Write access to the init point of the grid.
void plt_to_Array2d(const std::string &file_path_name, Container2d ®, const int zone_loaded=1)
Read a binary tecplot file and put the data in a 2d container.
reverse_col_iterator col_rbegin(const size_type slice, const size_type col)
Returns a read/write reverse iterator that points to the last element of the column column of the sli...
col_iterator col_begin(const size_type slice, const size_type col)
Returns a read/write iterator that points to the first element of the column column of the slice slic...
int get_tecplot_type()
Convert the type of a variable to an integer using Tecplot conventions.
size_type dim1() const
Returns the number of rows (first dimension size) in the GenericMultiComponent2d. ...
const slip::Point3d< GridT > & get_grid_step() const
Read access to the init point of the grid.
void resize(const size_type d1, const size_type d2, const T &val=T())
Resizes a Array2d.
const slip::Point3d< GridT > & get_init_point() const
Read access to the init point of the grid.
void generic_plt_to_RegularVector2dField2d(const std::string &file_path_name, RegularVector2dField2d ®, std::string &title, std::string &zonename, std::vector< std::string > &varnames, const int zone_loaded=1)
Read a slip::RegularVector2dField2d from a binary tecplot file.
size_type dim2() const
Returns the number of columns (second dimension size) in the Array2d.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Provides a class to manipulate 3d Vector.
size_type rows() const
Returns the number of rows (first dimension size) in the Array2d.
const GridT z(const size_type k, const size_type i, const size_type j) const
Subscript access to the real x3 value of the indexed (k,i,j) point of the RegularVector3dField3d.
col_iterator col_begin(const size_type col)
Returns a read/write iterator that points to the first element of the column column in the Array2d...
void plt_to_RegularVector2dField2d(const std::string &file_path_name, RegularVector2dField2d ®, std::string &title, std::string &zonename, std::vector< std::string > &varnames, const int zone_loaded=1)
Read a slip::RegularVector2dField2d from a binary tecplot file.
void plt_to_RegularVector3dField3d(const std::string &file_path_name, RegularVector3dField3d ®, std::string &title, std::string &zonename, std::vector< std::string > &varnames, const int zone_loaded=1)
Read a slip::RegularVector3dField3d from a binary tecplot file.
void RegularVector2dField2d_to_plt(const std::string &file_path_name, RegularVector2dField2d ®, std::string title, std::string zone, const double SolTime, std::vector< std::string > varnames=std::vector< std::string >(), const int FileType=0)
Write a slip::RegularVector2dField2d to a binary tecplot file.
void RegularVector3dField3d_to_plt(const std::string &file_path_name, RegularVector3dField3d ®, std::string title, std::string zone, const double SolTime, std::vector< std::string > varnames=std::vector< std::string >(), const int FileType=0)
Write a slip::RegularVector3dField3d to a binary tecplot file.
void resize(const size_type slices, const size_type rows, const size_type cols, const Block &val=Block())
Resizes a GenericMultiComponent3d.
int plt_get_order(std::ifstream &fp)
Read a binary tecplot file, move the stream pointer and return header informations.
const slip::Point2d< GridT > & get_init_point() const
Read access to the init point of the grid.
iterator end()
Returns a read/write iterator that points one past the last element in the GenericMultiComponent2d. Iteration is done in ordinary element order.
reverse_col_iterator col_rbegin(const size_type col)
Returns a read/write reverse iterator that points to the last element of the column column in the Gen...
bool compareTwoRows2D(double *rowA, double *rowB)
Comparator used to sort an Array2d.
int plt_get_file_type(std::ifstream &fp)
Read a binary tecplot file, move the stream pointer and return header informations.
void set_init_point(const slip::Point3d< GridT > &init_point)
Write access to the init point of the grid.
iterator end()
Returns a read/write iterator that points one past the last element in the GenericMultiComponent3d. Iteration is done in ordinary element order.
Provides a class to manipulate 3d dynamic and generic arrays.
col_iterator col_end(const size_type col)
Returns a read/write iterator that points one past the end element of the column column in the Array2...
bool operator()(const T &i, const T &j) const
void plt_read_header(std::ifstream &fp, int &NbVars, int &NbZones, int &K, int &I, int &J, std::string &title, std::string &zonename, std::vector< std::string > &varnames, double &SolTime, int NumZone=1)
Read a binary tecplot file, move the stream pointer and return header informations.
This is a Regular Vector3d Field. This container statisfies the BidirectionnalContainer concepts of t...
Provides a class to modelize 2d points.
This is a two-dimensional dynamic and generic container. This container statisfies the Bidirectionnal...
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
const GridT y(const size_type i, const size_type j) const
Subscript access to the real x2 value of the indexed (i,j) point of the RegularVector2dField2d.
size_type dim1() const
Returns the number of rows (first dimension size) in the Array2d.
size_type dim1() const
Returns the number of slices (first dimension size) in the GenericMultiComponent3d.