SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tecplot_binaries.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
72 #ifndef SLIP_TECPLOT_BINARIES_HPP
73 #define SLIP_TECPLOT_BINARIES_HPP
74 #include <typeinfo>
75 #include <vector>
76 #include <string>
77 #include <fstream>
78 #include "Vector2d.hpp"
79 #include "Vector3d.hpp"
80 #include "Array2d.hpp"
81 #include "Array3d.hpp"
82 #include "Point2d.hpp"
83 #include "Point3d.hpp"
84 
85 namespace slip
86 {
87 
88  template <typename T>
90  {
91  public:
92  GenericComparator(int s_) : s(s_) {};
93  bool operator()(const T &i,const T &j) const
94  {
95  return i[s]<j[s];
96  }
97  int s;
98  };
99 
111 template<typename T>
113 {
114  int type=0;
115  if (typeid(T)==typeid((float) 0.))
116  type=1;
117  else if (typeid(T)==typeid((double) 0.))
118  type=2;
119  else if (typeid(T)==typeid((int) 0.))
120  type=3;
121  else if (typeid(T)==typeid((short int) 0.))
122  type=4;
123  else if (typeid(T)==typeid((char) 0.))
124  type=5;
125  else
126  type=6;
127  return type;
128 }
129 
145 int plt_get_order(std::ifstream &fp)
146 {
147  if (!fp.is_open())
148  {
149  std::cerr<<"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
150  return -1;
151  }
152  long pos = fp.tellg();
153  fp.seekg (0);
154 // Read tecplot file version
155  for (size_t i = 0; i < 8; ++i)
156  {
157  char tmp;
158  fp.get(tmp);
159  }
160 
161 // Read order (???)
162  int Order=-1;
163  {
164  int *tmp=new int;
165  fp.read((char*)tmp, sizeof(int));
166  Order=*tmp;
167  delete tmp;
168  }
169 
170  fp.seekg (pos);
171  return Order;
172 }
173 
188 int plt_get_order(const std::string & file_path_name)
189 {
190  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
191  return plt_get_order(fp);
192 }
193 
224 int plt_get_file_type(std::ifstream &fp)
225 {
226  if (!fp.is_open())
227  {
228  std::cerr<<"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
229  return -1;
230  }
231  long pos = fp.tellg();
232  fp.seekg (0);
233 // Read tecplot file version
234  for (size_t i = 0; i < 8; ++i)
235  {
236  char tmp;
237  fp.get(tmp);
238  }
239 
240 // Read order (???)
241  {
242  int *tmp=new int;
243  fp.read((char*)tmp, sizeof(int));
244  delete tmp;
245  }
246 
247 // Read file type
248  int Type=-1;
249  {
250  int *tmp=new int;
251  fp.read((char*)tmp, sizeof(int));
252  Type=*tmp;
253  delete tmp;
254  }
255 
256  fp.seekg (pos);
257  return Type;
258 }
259 
289 int plt_get_file_type(const std::string & file_path_name)
290 {
291  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
292  return plt_get_file_type(fp);
293 }
294 
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)
331 {
332  title.clear();
333  zonename.clear();
334  varnames.clear();
335  NbVars=0;
336  NbZones=0;
337  K=0;
338  I=0;
339  J=0;
340  SolTime=0.;
341  if (NumZone<1)
342  NumZone=1;
343  if (!fp.is_open())
344  {
345  std::cerr<<"Error in the \"plt_read_header\" function : the file is not opened"<<std::endl;
346  return;
347  }
348 /****************************************************************************/
349 /********************************** HEADER **********************************/
350 /****************************************************************************/
351 // Read tecplot file version
352  for (size_t i = 0; i < 8; ++i)
353  {
354  char tmp;
355  fp.get(tmp);
356  }
357 
358 // Read order (???)
359  {
360  int *tmp=new int;
361  fp.read((char*)tmp, sizeof(int));
362  delete tmp;
363  }
364 
365 // Read file type
366  int Type=0;
367  {
368  int *tmp=new int;
369  fp.read((char*)tmp, sizeof(int));
370  Type=*tmp;
371  delete tmp;
372  }
373 
374 // read title
375  {
376  int *tmp=new int;
377  *tmp=-10;
378  int i=0;
379  while (*tmp!=0)
380  {
381  fp.read((char*)tmp, sizeof(int));
382  title.append((char*)tmp);
383  ++i;
384  if (i>255) break;
385  }
386  delete tmp;
387  }
388 
389 // Read the number of variables
390  {
391  int *tmp=new int;
392  fp.read((char*)tmp, sizeof(int));
393  NbVars=*tmp;
394  delete tmp;
395  }
396 
397 // Read the variables name
398  {
399  for (int i = 0; i < NbVars; ++i)
400  {
401  int *tmp=new int;
402  *tmp=-10;
403  int j=0;
404  std::string nom_temp;
405  while (*tmp!=0)
406  {
407  fp.read((char*)tmp, sizeof(int));
408  nom_temp.append((char*)tmp);
409  ++j;
410  if (j>255) break;
411  }
412  varnames.push_back(nom_temp);
413  delete tmp;
414  }
415  }
416 
417 // Read zone parameters
418  int ZoneType=0;
419  NbZones=0;
420  int size=0;
421  I=1;
422  J=1;
423  K=1;
424  float *marker=new float;
425  *marker=-1.;
426  while ((*marker!=357.0) && (*marker!=399.0))
427  {
428 // Read zone marker
429  if (*marker!=357.0)
430  {
431  float *tmp=new float;
432  *tmp=-10;
433  int i=0;
434  while (*tmp!=299.0)
435  {
436  fp.read((char*)tmp, sizeof(float));
437  ++i;
438  if (i>255) break;
439  if (*tmp==357.0)
440  {
441  *marker=357.0;
442  break;
443  }
444  }
445  if (*tmp==299.0)
446  {
447  ++NbZones;
448  }
449  delete tmp;
450  }
451 
452  if (*marker!=357.0)
453  {
454 // Read zone name
455  {
456  int *tmp=new int;
457  *tmp=-10;
458  int i=0;
459  while (*tmp!=0)
460  {
461  fp.read((char*)tmp, sizeof(int));
462  if (NbZones==NumZone)
463  zonename.append((char*)tmp);
464  ++i;
465  if (i>255) break;
466  if (*tmp==357.0)
467  {
468  *marker=357.0;
469  break;
470  }
471  }
472  delete tmp;
473  }
474 
475 // Read Parent zone
476  {
477  int *tmp=new int;
478  fp.read((char*)tmp, sizeof(int));
479  if (*tmp==357.0)
480  {
481  *marker=357.0;
482  break;
483  }
484  delete tmp;
485  }
486 
487 // Read StrandID
488  {
489  int *tmp=new int;
490  fp.read((char*)tmp, sizeof(int));
491  if (*tmp==357.0)
492  {
493  *marker=357.0;
494  break;
495  }
496  delete tmp;
497  }
498 
499 // Read Solution time
500  {
501  double *tmp=new double;
502  fp.read((char*)tmp, sizeof(double));
503  SolTime=*tmp;
504  if (*tmp==357.0)
505  {
506  *marker=357.0;
507  break;
508  }
509  delete tmp;
510  }
511 
512 // Read useless -1
513  {
514  int *tmp=new int;
515  fp.read((char*)tmp, sizeof(int));
516  if (*tmp==357.0)
517  {
518  *marker=357.0;
519  break;
520  }
521  else if (*tmp!=-1)
522  {
523  std::cerr<<"Reading error in plt_to_array"<<std::endl;
524  break;
525  }
526  delete tmp;
527  }
528 
529 // Read ZoneType
530  {
531  int *tmp=new int;
532  fp.read((char*)tmp, sizeof(int));
533  ZoneType=*tmp;
534  if (*tmp==357.0)
535  {
536  *marker=357.0;
537  break;
538  }
539  delete tmp;
540  }
541 
542 // Read Specify Var Location
543  {
544  int *tmp=new int;
545  fp.read((char*)tmp, sizeof(int));
546  if (*tmp==357.0)
547  {
548  *marker=357.0;
549  break;
550  }
551  else if (*tmp==1)
552  {
553  for (int z=0; z<NbVars; ++z)
554  {
555  fp.read((char*)tmp, sizeof(int));
556  if (*tmp==357.0)
557  {
558  *marker=357.0;
559  break;
560  }
561  }
562  }
563  delete tmp;
564  }
565 
566 // Read Supplied Face Neighboring
567  {
568  int *tmp=new int;
569  fp.read((char*)tmp, sizeof(int));
570  if (*tmp==357.0)
571  {
572  *marker=357.0;
573  break;
574  }
575  delete tmp;
576  }
577 
578 // Read User Defined Face Connections
579  {
580  int *tmp=new int;
581  fp.read((char*)tmp, sizeof(int));
582  if (*tmp==357.0)
583  {
584  *marker=357.0;
585  break;
586  }
587  else if (*tmp==1)
588  {
589  int *tmp2=new int;
590  fp.read((char*)tmp2, sizeof(int));
591  if (*tmp2==357.0)
592  {
593  *marker=357.0;
594  break;
595  }
596  delete tmp2;
597  }
598  delete tmp;
599  }
600 
601 // Read Finite Element Face Neighbors
602  if (ZoneType!=0)
603  {
604  int *tmp=new int;
605  fp.read((char*)tmp, sizeof(int));
606  if (*tmp==357.0)
607  {
608  *marker=357.0;
609  break;
610  }
611  delete tmp;
612  }
613 // Read KMax, IMax, JMax
614  else
615  {
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)
622  {
623  K=*KMax;
624  I=*IMax;
625  J=*JMax;
626  }
627  delete IMax;
628  delete JMax;
629  delete KMax;
630  }
631 
632 // Read Auxiliary Name
633  {
634  int *tmp=new int;
635  fp.read((char*)tmp, sizeof(int));
636  if (*tmp==357.0)
637  {
638  *marker=357.0;
639  break;
640  }
641  delete tmp;
642  }
643  }
644  }
645  delete marker;
646 }
647 
672 void plt_read_header(std::ifstream &fp, int &NbVars, int &NbZones, int &K, int &I, int &J, int NumZone=1)
673 {
674  std::string _useless_string;
675  std::vector<std::string> _useless_varnames;
676  double SolTime;
677  plt_read_header(fp, NbVars, NbZones, K, I, J, _useless_string, _useless_string, _useless_varnames, SolTime, NumZone);
678 }
679 
703 void plt_read_header(const std::string & file_path_name, int &NbVars, int &NbZones, int &K, int &I, int &J, int NumZone=1)
704 {
705  double SolTime;
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);
710 }
711 
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)
739 {
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);
744 }
745 
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)
779 {
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);
782 }
783 
802 template<typename Container2d>
803 void plt_to_Array2d(const std::string & file_path_name,
804  Container2d & reg,
805  const int zone_loaded=1)
806 {
807  typedef typename Container2d::value_type T;
808 
809  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
810  int ZoneLoaded = zone_loaded;
811 /****************************************************************************/
812 /********************************** HEADER **********************************/
813 /****************************************************************************/
814  int nbvars=0;
815  int nbzones=0, size=0;
816  int Imax=1, Jmax=1, Kmax=1;
817  plt_read_header(fp, nbvars, nbzones, Kmax, Imax, Jmax, ZoneLoaded);
818  size=Imax*Jmax*Kmax;
819 /****************************************************************************/
820 /*********************************** DATA ***********************************/
821 /****************************************************************************/
822  reg.resize(size,nbvars);
823  if (ZoneLoaded>nbzones)
824  {
825  ZoneLoaded=nbzones;
826  }
827  if (ZoneLoaded<1)
828  {
829  ZoneLoaded=1;
830  }
831 // Read zones data
832  for (int NumZone = 1; NumZone <= nbzones; ++NumZone)
833  {
834  int *datatype=new int[nbvars];
835  {
836  float *tmp=new float;
837  fp.read((char*)tmp, sizeof(float));
838  delete tmp;
839  }
840 
841 // Read data type
842  for (int i = 0; i < nbvars; ++i)
843  {
844  int *tmp=new int;
845  fp.read((char*)tmp, sizeof(int));
846  datatype[i]=*tmp;
847  delete tmp;
848  }
849 
850 // Read useless things
851  for (size_t i = 0; i < 3; ++i)
852  {
853  int *tmp=new int;
854  fp.read((char*)tmp, sizeof(int));
855  if ((i==0||i==1)&&(*tmp)!=0)
856  {
857  for (int j = 0; j < nbvars; ++j)
858  {
859  fp.read((char*)tmp, sizeof(int));
860  }
861  }
862  delete tmp;
863  }
864 
865 // Read variable min et max value
866  for (int i = 0; i < nbvars; ++i)
867  {
868  double *min=new double, *max=new double;
869  fp.read((char*)min, sizeof(double));
870  fp.read((char*)max, sizeof(double));
871  delete min;
872  delete max;
873  }
874  if (NumZone!=ZoneLoaded)
875  {
876  for (int i = 0; i < nbvars; ++i)
877  {
878  switch (datatype[i])
879  {
880  case 1:
881  fp.seekg((size)*sizeof(float), std::ios::cur);
882  break;
883  case 2:
884  fp.seekg((size)*sizeof(double), std::ios::cur);
885  break;
886  case 3:
887  fp.seekg((size)*sizeof(int), std::ios::cur);
888  break;
889  case 4:
890  fp.seekg((size)*sizeof(short int), std::ios::cur);
891  break;
892  case 5:
893  case 6:
894  fp.seekg((size)*sizeof(char), std::ios::cur);
895  break;
896  default:
897  break;
898  }
899  }
900  }
901  else
902  {
903  for (int i = 0; i < nbvars; ++i)
904  {
905  switch (datatype[i])
906  {
907  case 1:
908  {
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));
913  delete[] tmp;
914  break;
915  }
916  case 2:
917  {
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));
922  delete[] tmp;
923  break;
924  }
925  case 3:
926  {
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));
931  delete[] tmp;
932  break;
933  }
934  case 4:
935  {
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));
940  delete[] tmp;
941  break;
942  }
943  case 5:
944  case 6:
945  {
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));
950  delete[] tmp;
951  break;
952  }
953  }
954  }
955  }
956  delete[] datatype;
957  }
958 }
959 
989 template<typename RegularVector3dField3d>
990 void plt_to_RegularVector3dField3d(const std::string &file_path_name,
992  std::string &title,
993  std::string &zonename,
994  std::vector<std::string> &varnames,
995  const int zone_loaded=1)
996 {
998  typedef typename RegularVector3dField3d::grid_value_type GridT;
999  int ZoneLoaded = zone_loaded;
1000  double SolTime;
1001  title.clear();
1002  zonename.clear();
1003  varnames.clear();
1004  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
1005  slip::Point3d<GridT> init;
1006  slip::Point3d<GridT> grid;
1007 /**********************************************************************/
1008 /********************************** HEADER ****************************/
1009 /**********************************************************************/
1010  int nbvars=0;
1011  int nbzones=0, size=0;
1012  int Imax=1, Jmax=1, Kmax=1;
1013  const int FileType=plt_get_file_type(fp);
1014  plt_read_header(fp, nbvars, nbzones, Kmax, Imax, Jmax, title, zonename, varnames, SolTime, ZoneLoaded);
1015  size=Imax*Jmax*Kmax;
1016 /**********************************************************************/
1017 /*********************************** DATA *****************************/
1018 /**********************************************************************/
1019  reg.resize(Kmax,Imax,Jmax);
1020  if (ZoneLoaded>nbzones) ZoneLoaded=nbzones;
1021  if (ZoneLoaded<1) ZoneLoaded=1;
1022  // Lecture des données des zones
1023  for (int NumZone = 1; NumZone <= nbzones; ++NumZone)
1024  {
1025  {
1026  float *tmp=new float;
1027  fp.read((char*)tmp, sizeof(float));
1028  delete tmp;
1029  }
1030 
1031 // Lecture du type des données
1032  int *datatype=new int[nbvars];
1033  for (int i = 0; i < nbvars; ++i)
1034  {
1035  int *tmp=new int;
1036  fp.read((char*)tmp, sizeof(int));
1037  datatype[i]=*tmp;
1038  delete tmp;
1039  }
1040 
1041 // Lecture de trucs inutiles pour nous
1042  for (size_t i = 0; i < 3; ++i)
1043  {
1044  int *tmp=new int;
1045  fp.read((char*)tmp, sizeof(int));
1046  if ((i==0||i==1)&&(*tmp)!=0)
1047  {
1048  for (int j = 0; j < nbvars; ++j)
1049  {
1050  fp.read((char*)tmp, sizeof(int));
1051  }
1052  }
1053  delete tmp;
1054  }
1055 
1056 // Lecture des min et max de chaque variable
1057  for (int i = 0; i < nbvars; ++i)
1058  {
1059  double *min=new double, *max=new double;
1060  fp.read((char*)min, sizeof(double));
1061  fp.read((char*)max, sizeof(double));
1062  delete min;
1063  delete max;
1064  }
1065  if (NumZone!=ZoneLoaded)
1066  {
1067  for (int num = 0; num < nbvars; num++)
1068  {
1069  switch (datatype[num])
1070  {
1071  case 1:
1072  fp.seekg((size)*sizeof(float), std::ios::cur);
1073  break;
1074  case 2:
1075  fp.seekg((size)*sizeof(double), std::ios::cur);
1076  break;
1077  case 3:
1078  fp.seekg((size)*sizeof(int), std::ios::cur);
1079  break;
1080  case 4:
1081  fp.seekg((size)*sizeof(short int), std::ios::cur);
1082  break;
1083  case 5:
1084  case 6:
1085  fp.seekg((size)*sizeof(char), std::ios::cur);
1086  break;
1087  default:
1088  break;
1089  }
1090  }
1091  }
1092  else
1093  {
1094  for (int i = 0; i < nbvars; ++i)
1095  {
1096  if ( FileType!=2 && i<3 )
1097  {
1098  GridT *min=new GridT, *max=new GridT;
1099  switch (datatype[i])
1100  {
1101  case 1:
1102  {
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);
1109  delete tmp;
1110  break;
1111  }
1112  case 2:
1113  {
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);
1120  delete tmp;
1121  break;
1122  }
1123  case 3:
1124  {
1125  int *tmp=new int;
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);
1131  delete tmp;
1132  break;
1133  }
1134  case 4:
1135  {
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);
1142  delete tmp;
1143  break;
1144  }
1145  case 5:
1146  case 6:
1147  {
1148  char *tmp=new char;
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);
1154  delete tmp;
1155  break;
1156  }
1157  }
1158 
1159  int Nmax=1;
1160  switch (i)
1161  {
1162  case 0:
1163  Nmax=Jmax;
1164  break;
1165  case 1:
1166  Nmax=Imax;
1167  break;
1168  case 2:
1169  Nmax=Kmax;
1170  break;
1171  default:
1172  break;
1173  }
1174  init[i]=*min;
1175  if (Nmax>1)
1176  grid[i]=std::abs((*min)-(*max))/(Nmax-1.);
1177  else
1178  grid[i]=1.;
1179  delete min;
1180  delete max;
1181  }
1182  else if ( ( FileType==0 && i<6 ) || ( FileType==2 && i<3 ) )
1183  {
1184  int n=0, comp=i-3;
1185  if (FileType==2)
1186  comp=i;
1187  switch (datatype[i])
1188  {
1189  case 1:
1190  {
1191  float *tmp=new float[size];
1192  fp.read((char*)tmp, size*sizeof(float));
1193  for (int kk = Kmax-1; kk >= 0; --kk)
1194  {
1195  for (int ii = Imax-1; ii >= 0; --ii)
1196  {
1197  for (int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1198  reg(kk,ii,jj)[comp]=static_cast<T>(*(tmp+n));
1199  }
1200  }
1201  delete[] tmp;
1202  break;
1203  }
1204  case 2:
1205  {
1206  double *tmp=new double[size];
1207  fp.read((char*)tmp, size*sizeof(double));
1208  for (int kk = Kmax-1; kk >= 0; --kk)
1209  {
1210  for (int ii = Imax-1; ii >= 0; --ii)
1211  {
1212  for (int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1213  reg(kk,ii,jj)[comp]=static_cast<T>(*(tmp+n));
1214  }
1215  }
1216  delete[] tmp;
1217  break;
1218  }
1219  case 3:
1220  {
1221  int *tmp=new int[size];
1222  fp.read((char*)tmp, size*sizeof(int));
1223  for (int kk = Kmax-1; kk >= 0; --kk)
1224  {
1225  for (int ii = Imax-1; ii >= 0; --ii)
1226  {
1227  for (int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1228  reg(kk,ii,jj)[comp]=static_cast<T>(*(tmp+n));
1229  }
1230  }
1231  delete[] tmp;
1232  break;
1233  }
1234  case 4:
1235  {
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)
1239  {
1240  for (int ii = Imax-1; ii >= 0; --ii)
1241  {
1242  for (int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1243  reg(kk,ii,jj)[comp]=static_cast<T>(*(tmp+n));
1244  }
1245  }
1246  delete[] tmp;
1247  break;
1248  }
1249  case 5:
1250  case 6:
1251  {
1252  char *tmp=new char[size];
1253  fp.read((char*)tmp, size*sizeof(char));
1254  for (int kk = Kmax-1; kk >= 0; --kk)
1255  {
1256  for (int ii = Imax-1; ii >= 0; --ii)
1257  {
1258  for (int jj = 0; jj < Jmax && n<size; ++jj, ++n)
1259  reg(kk,ii,jj)[comp]=static_cast<T>(*(tmp+n));
1260  }
1261  }
1262  delete[] tmp;
1263  break;
1264  }
1265  }
1266  }
1267  }
1268  }
1269  delete[] datatype;
1270  }
1271  if ( FileType!=2 )
1272  {
1273  reg.set_init_point(init);
1274  reg.set_grid_step(grid);
1275  }
1276 }
1277 
1297 template<typename RegularVector3dField3d>
1298 void plt_to_RegularVector3dField3d(const std::string &file_path_name,
1300  const int zone_loaded=1)
1301 {
1303  std::string _useless_string;
1304  std::vector<std::string> _useless_varnames;
1305  slip::plt_to_RegularVector3dField3d(file_path_name,
1306  reg,
1307  _useless_string,
1308  _useless_string,
1309  _useless_varnames,
1310  zone_loaded);
1311 }
1312 
1340 bool compareTwoRows3D(double* rowA, double* rowB)
1341 {
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])) );
1343 }
1344 
1373 template<typename RegularVector3dField3d>
1374 void generic_plt_to_RegularVector3dField3d(const std::string &file_path_name,
1376  std::string &title,
1377  std::string &zonename,
1378  std::vector<std::string> &varnames,
1379  const int zone_loaded=1)
1380 {
1382  typedef typename RegularVector3dField3d::grid_value_type GridT;
1383  int ZoneLoaded = zone_loaded;
1384  double SolTime;
1385  title.clear();
1386  zonename.clear();
1387  varnames.clear();
1388  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
1389  slip::Point3d<GridT> init;
1390  slip::Point3d<GridT> grid;
1391 
1392  slip::Array2d<T> data, test_data;
1393  const int FileType=plt_get_file_type(file_path_name);
1394  slip::plt_to_Array2d(file_path_name, data, ZoneLoaded);
1395 
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 )
1397  {
1398  // sorting array
1399  // std::sort(data.begin(),data.begin()+data.dim1(),&compareTwoRows3D);
1400  // std::sort(data.col_begin(),data.col_begin()+data.dim1(),&compareTwoRows3D);
1401  //data.sort(&compareTwoRows3D); //Adrien
1402  T** datab = &(data[0]);
1403  std::sort(datab,datab+data.dim1(),&compareTwoRows3D);
1404  test_data.resize(data.dim1(), data.dim2());
1405  for (size_t i = 0; i < data.dim1(); ++i)
1406  {
1407  for (size_t j = 0; j < data.dim2(); ++j)
1408  {
1409  test_data[i][j]=data[i][j]; // ne pas utiliser les iterators ici !!! ( ils ont été invalidés par std::sort() )
1410  }
1411  }
1412  data.resize(0,0);
1413  data=test_data;
1414  }
1415 
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);
1422 
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]));
1426 
1427  bool y_direct = (init[1] == data[0][1]);
1428 
1429  reg.resize(size_z,size_y,size_x);
1430 
1431  if( data[0][0] == data[1][0] || FileType==1 )
1432  {
1433  //cas x fixe, y varie
1434  grid[0]=static_cast<GridT>(std::abs(*(data.col_begin(0)+size_y)-(*(data.col_begin(0)))));
1435  grid[1]=static_cast<GridT>(std::abs(*(data.col_begin(1)+1)-*(data.col_begin(1))));
1436  grid[2]=static_cast<GridT>(std::abs(*(data.col_begin(2)+size_xy)-*(data.col_begin(2))));
1437  if ( FileType==0 )
1438  {
1439  std::size_t gridz = 0;
1440  for(std::size_t k = 0 ; k < size_z; ++k)
1441  {
1442  std::size_t gridy = 0;
1443 
1444  for(std::size_t j = 0; j < size_x; ++j)
1445  {
1446  if(y_direct)
1447  {
1448  std::copy(data.col_begin(4) + gridz + gridy,
1449  data.col_begin(4) + (gridz + gridy + size_y),
1450  reg.col_rbegin(1,(size_z-1)-k,j));
1451  std::copy(data.col_begin(3) + gridz + gridy,
1452  data.col_begin(3) + (gridz + gridy + size_y),
1453  reg.col_rbegin(0,(size_z-1)-k,j));
1454  std::copy(data.col_begin(5) + gridz + gridy,
1455  data.col_begin(5) + (gridz + gridy + size_y),
1456  reg.col_rbegin(2,(size_z-1)-k,j));
1457  gridy += size_y;
1458  }
1459  else
1460  {
1461  std::copy(data.col_begin(4) + gridz + gridy,
1462  data.col_begin(4) + (gridz + gridy + size_y),
1463  reg.col_begin(1,(size_z-1)-k,j));
1464  std::copy(data.col_begin(3) + gridz + gridy,
1465  data.col_begin(3) + (gridz + gridy + size_y),
1466  reg.col_begin(0,(size_z-1)-k,j));
1467  std::copy(data.col_begin(5) + gridz + gridy,
1468  data.col_begin(5) + (gridz + gridy + size_y),
1469  reg.col_begin(2,(size_z-1)-k,j));
1470  gridy += size_y;
1471  }
1472  }
1473  gridz+=size_xy;
1474  }
1475  }
1476  }
1477  else
1478  {
1479  //cas x varie, y fixe
1480  grid[0]=static_cast<GridT>(std::abs(*(data.col_begin(0)+1)-(*(data.col_begin(0)))));
1481  grid[1]=static_cast<GridT>(std::abs(*(data.col_begin(1)+size_x) - *(data.col_begin(1))));
1482  grid[2]=static_cast<GridT>(std::abs(*(data.col_begin(2)+size_xy) - *(data.col_begin(2))));
1483  std::size_t gridz = 0;
1484  for(std::size_t k = 0 ; k < size_z; ++k)
1485  {
1486  std::size_t gridx = 0;
1487  for(std::size_t j = 0; j < size_y; ++j)
1488  {
1489  if(y_direct)
1490  {
1491  std::copy(data.col_begin(3) + gridz + gridx,
1492  data.col_begin(3) + (gridz + gridx + size_x),
1493  reg.row_begin(0,(size_z-1)-k,(size_y - 1) - j));
1494  std::copy(data.col_begin(4) + gridz + gridx,
1495  data.col_begin(4) + (gridz + gridx + size_x),
1496  reg.row_begin(1,(size_z-1)-k,(size_y - 1) - j));
1497  std::copy(data.col_begin(5) + gridz + gridx,
1498  data.col_begin(5) + (gridz + gridx + size_x),
1499  reg.row_begin(2,(size_z-1)-k,(size_y - 1) - j));
1500 
1501  }
1502  else
1503  {
1504  std::copy(data.col_begin(3) + gridz + gridx,
1505  data.col_begin(3) + gridz + (gridx + size_x),
1506  reg.row_begin(0,(size_z-1)-k,j));
1507  std::copy(data.col_begin(4) + gridz + gridx,
1508  data.col_begin(4) + (gridz + gridx + size_x),
1509  reg.row_begin(1,(size_z-1)-k,j));
1510  std::copy(data.col_begin(5) + gridz + gridx,
1511  data.col_begin(5) + (gridz + gridx + size_x),
1512  reg.row_begin(2,(size_z-1)-k,j));
1513  }
1514  gridx += size_x;
1515  }
1516  gridz+=size_xy;
1517  }
1518  }
1519 
1520  if ( FileType!=2 )
1521  {
1522  reg.set_init_point(init);
1523  reg.set_grid_step(grid);
1524  }
1525 }
1526 
1547 template<typename RegularVector3dField3d>
1548 void generic_plt_to_RegularVector3dField3d(const std::string &file_path_name,
1550  const int zone_loaded=1)
1551 {
1553  std::string _useless_string;
1554  std::vector<std::string> _useless_varnames;
1556  reg,
1557  _useless_string,
1558  _useless_string,
1559  _useless_varnames,
1560  zone_loaded);
1561 }
1562 
1585 template<typename RegularVector3dField3d>
1586 void RegularVector3dField3d_to_plt(const std::string &file_path_name,
1588  std::string title,
1589  std::string zone,
1590  const double SolTime,
1591  std::vector<std::string> varnames=std::vector<std::string>(),
1592  const int FileType=0)
1593 {
1595  typedef typename RegularVector3dField3d::grid_value_type GridT;
1596  std::ofstream fp (file_path_name.c_str(), std::ios::out|std::ios::binary);
1597 /******************************************************************************/
1598 /********************************** HEADER ************************************/
1599 /******************************************************************************/
1600 
1601 // Lecture de la version du fichier Tecplot
1602  fp.write("#!TDV112",8);
1603  int *myint=new int;
1604  char *mychar=new char;
1605  float *myfloat=new float;
1606  double *mydouble=new double;
1607 // Écriture de l'ordre
1608  *myint=1;
1609  fp.write((char*)myint, sizeof(int));
1610 
1611 // Écriture du type de fichier
1612  *myint=FileType;
1613  fp.write((char*)myint, sizeof(int));
1614 
1615 // // Écriture du titre
1616  std::string strtmp=title;
1617  for (size_t i = 0; i <= strtmp.size(); i++)
1618  {
1619  *myint=(int)strtmp[i];
1620  fp.write((char*)myint,sizeof(int));
1621  }
1622 
1623 // Définition des variables en fonction du type de fichier
1624  size_t imin=0, imax=6, nbvars=6;
1625  switch (FileType)
1626  {
1627  case 1:
1628  imin=0;
1629  imax=3;
1630  nbvars=3;
1631  if (varnames.size()<3)
1632  {
1633  varnames.clear();
1634  varnames.push_back("X");
1635  varnames.push_back("Y");
1636  varnames.push_back("Z");
1637  }
1638  break;
1639  case 2:
1640  imin=0;
1641  imax=3;
1642  nbvars=3;
1643  if (varnames.size()<3)
1644  {
1645  varnames.clear();
1646  varnames.push_back("U");
1647  varnames.push_back("V");
1648  varnames.push_back("W");
1649  }
1650  break;
1651  default:
1652  if (varnames.size()<6)
1653  {
1654  varnames.clear();
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");
1661  }
1662  break;
1663  }
1664 
1665 // Écriture du nombre de variables
1666  *myint=nbvars;
1667  fp.write((char*)myint, sizeof(int));
1668 
1669 // Écriture des noms des variables
1670  for (size_t i = imin; i < imax; i++)
1671  {
1672  for (size_t j = 0; j <= varnames[i].size(); j++)
1673  {
1674  *myint=(int)varnames[i][j];
1675  fp.write((char*)myint,sizeof(int));
1676  }
1677  }
1678 
1679 // Écriture des paramètres des zones
1680 // Écriture du zone marker
1681  *myfloat=299.0;
1682  fp.write((char*)myfloat, sizeof(float));
1683 // Écriture du nom de la zone
1684  strtmp=zone;
1685  for (size_t i = 0; i <= strtmp.size(); i++)
1686  {
1687  *myint=(int)strtmp[i];
1688  fp.write((char*)myint,sizeof(int));
1689  }
1690 // Écriture du Parent zone
1691  *myint=-1;
1692  fp.write((char*)myint, sizeof(int));
1693 // Écriture du StrandID
1694  *myint=-1;
1695  fp.write((char*)myint, sizeof(int));
1696 // Écriture du Solution time
1697  *mydouble=SolTime;
1698  fp.write((char*)mydouble, sizeof(double));
1699 // Écriture du -1 inutile
1700  *myint=-1;
1701  fp.write((char*)myint, sizeof(int));
1702 // Écriture du ZoneType
1703  *myint=0;
1704  fp.write((char*)myint, sizeof(int));
1705 // Écriture du Specify Var Location
1706  fp.write((char*)myint, sizeof(int));
1707 // Écriture du Supplied Face Neighboring
1708  fp.write((char*)myint, sizeof(int));
1709 // Écriture du User Defined Face Connections
1710  fp.write((char*)myint, sizeof(int));
1711 // Écriture des IMax, JMax et KMax
1712  *myint=reg.dim3();
1713  fp.write((char*)myint, sizeof(int));
1714  *myint=reg.dim2();
1715  fp.write((char*)myint, sizeof(int));
1716  *myint=reg.dim1();
1717  fp.write((char*)myint, sizeof(int));
1718 // Écriture du Auxiliary Name
1719  *myint=0;
1720  fp.write((char*)myint, sizeof(int));
1721 // Écriture du marker de fin de header
1722  *myfloat=357.0;
1723  fp.write((char*)myfloat, sizeof(float));
1724 
1725 /******************************************************************************/
1726 /*********************************** DATA *************************************/
1727 /******************************************************************************/
1728 // Écriture des données des zones
1729 // Écriture du marker de début de zone
1730  *myfloat=299.0;
1731  fp.write((char*)myfloat, sizeof(float));
1732 // Écriture du type des données
1733  *myint=get_tecplot_type<GridT>();
1734  if (FileType==0 || FileType==1)
1735  {
1736  for (size_t i = 0; i < 3; ++i)
1737  fp.write((char*)myint, sizeof(int));
1738  }
1739  *myint=get_tecplot_type<T>();
1740  if (FileType==0 || FileType==2)
1741  {
1742  for (size_t i = 0; i < 3; ++i)
1743  fp.write((char*)myint, sizeof(int));
1744  }
1745 // Écriture de trucs inutiles pour nous
1746  *myint=0;
1747  fp.write((char*)myint, sizeof(int));
1748  fp.write((char*)myint, sizeof(int));
1749  *myint=-1;
1750  fp.write((char*)myint, sizeof(int));
1751 // Écriture des min et max de chaque variable
1752  if (FileType==0 || FileType==1)
1753  {
1754  *mydouble=static_cast<double>(reg.get_init_point()[0]);
1755  fp.write((char*)mydouble, sizeof(double));
1756  *mydouble=static_cast<double>(reg.get_init_point()[0]+(reg.dim3()-1)*reg.get_grid_step()[0]);
1757  fp.write((char*)mydouble, sizeof(double));
1758  *mydouble=static_cast<double>(reg.get_init_point()[1]);
1759  fp.write((char*)mydouble, sizeof(double));
1760  *mydouble=static_cast<double>(reg.get_init_point()[1]+(reg.dim2()-1)*reg.get_grid_step()[1]);
1761  fp.write((char*)mydouble, sizeof(double));
1762  *mydouble=static_cast<double>(reg.get_init_point()[2]);
1763  fp.write((char*)mydouble, sizeof(double));
1764  *mydouble=static_cast<double>(reg.get_init_point()[2]+(reg.dim1()-1)*reg.get_grid_step()[2]);
1765  fp.write((char*)mydouble, sizeof(double));
1766  }
1767 
1768  if (FileType==0 || FileType==2)
1769  {
1770  double umin, umax, vmin, vmax, wmin, wmax;
1771  umin=static_cast<double>((*std::min_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(0)))[0]);
1772  umax=static_cast<double>((*std::max_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(0)))[0]);
1773  vmin=static_cast<double>((*std::min_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(1)))[1]);
1774  vmax=static_cast<double>((*std::max_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(1)))[1]);
1775  wmin=static_cast<double>((*std::min_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(2)))[2]);
1776  wmax=static_cast<double>((*std::max_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector3d<T> >(2)))[2]);
1777  *mydouble=umin;
1778  fp.write((char*)mydouble, sizeof(double));
1779  *mydouble=umax;
1780  fp.write((char*)mydouble, sizeof(double));
1781  *mydouble=vmin;
1782  fp.write((char*)mydouble, sizeof(double));
1783  *mydouble=vmax;
1784  fp.write((char*)mydouble, sizeof(double));
1785  *mydouble=wmin;
1786  fp.write((char*)mydouble, sizeof(double));
1787  *mydouble=wmax;
1788  fp.write((char*)mydouble, sizeof(double));
1789  }
1790 
1791  if (FileType==0 || FileType==1)
1792  {
1793  const int size_grid=sizeof(GridT);
1794  for (int kk = reg.dim1()-1; kk >= 0; --kk)
1795  {
1796  for (int ii = reg.dim2()-1; ii >= 0; --ii)
1797  {
1798  for (int jj = 0; jj < (int)reg.dim3(); ++jj)
1799  {
1800  GridT *temp=new GridT;
1801  *temp=reg.x(kk,ii,jj);
1802  fp.write((char*)temp, size_grid);
1803  delete temp;
1804  }
1805  }
1806  }
1807  for (int kk = reg.dim1()-1; kk >= 0; --kk)
1808  {
1809  for (int ii = reg.dim2()-1; ii >= 0; --ii)
1810  {
1811  for (int jj = 0; jj < (int)reg.dim3(); ++jj)
1812  {
1813  GridT *temp=new GridT;
1814  *temp=reg.y(kk,ii,jj);
1815  fp.write((char*)temp, size_grid);
1816  delete temp;
1817  }
1818  }
1819  }
1820  for (int kk = reg.dim1()-1; kk >= 0; --kk)
1821  {
1822  for (int ii = reg.dim2()-1; ii >= 0; --ii)
1823  {
1824  for (int jj = 0; jj < (int)reg.dim3(); ++jj)
1825  {
1826  GridT *temp=new GridT;
1827  *temp=reg.z(kk,ii,jj);
1828  fp.write((char*)temp, size_grid);
1829  delete temp;
1830  }
1831  }
1832  }
1833  }
1834 
1835  if (FileType==0 || FileType==2)
1836  {
1837  const int size_data=sizeof(T);
1838  for (size_t i = 0; i < 3; ++i)
1839  {
1840  for (int kk = reg.dim1()-1; kk >= 0; --kk)
1841  {
1842  for (int ii = reg.dim2()-1; ii >= 0; --ii)
1843  {
1844  for (int jj = 0; jj < (int)reg.dim3(); ++jj)
1845  {
1846  T *temp=new T;
1847  *temp=reg(kk,ii,jj)[i];
1848  fp.write((char*)temp, size_data);
1849  delete temp;
1850  }
1851  }
1852  }
1853  }
1854  }
1855  delete myint;
1856  delete mychar;
1857  delete myfloat;
1858  delete mydouble;
1859 }
1860 
1878 template<typename RegularVector3dField3d>
1879 void RegularVector3dField3d_to_plt(const std::string &file_path_name,
1881  const int FileType=0)
1882 {
1883  RegularVector3dField3d_to_plt(file_path_name, reg, "Title", "Zone", 0., std::vector<std::string>(), FileType);
1884 }
1885 
1905 template<typename RegularVector3dField3d>
1906 void RegularVector3dField3d_to_plt(const std::string &file_path_name,
1908  const double SolTime,
1909  const int FileType=0)
1910 {
1911  RegularVector3dField3d_to_plt(file_path_name, reg, "Title", "Zone", SolTime, std::vector<std::string>(), FileType);
1912 }
1913 
1933 template<typename RegularVector3dField3d>
1934 void RegularVector3dField3d_to_plt(const std::string &file_path_name,
1936  std::string title,
1937  std::string zone,
1938  const int FileType=0)
1939 {
1940  RegularVector3dField3d_to_plt(file_path_name, reg, title, zone, 0., std::vector<std::string>(), FileType);
1941 }
1942 
1963 template<typename RegularVector3dField3d>
1964 void RegularVector3dField3d_to_plt(const std::string &file_path_name,
1966  std::string title,
1967  std::string zone,
1968  std::vector<std::string> varnames,
1969  const int FileType=0)
1970 {
1971  RegularVector3dField3d_to_plt(file_path_name, reg, title, zone, 0., varnames, FileType);
1972 }
1973 
2002 template<typename RegularVector2dField2d>
2003 void plt_to_RegularVector2dField2d(const std::string &file_path_name,
2005  std::string &title,
2006  std::string &zonename,
2007  std::vector<std::string> &varnames,
2008  const int zone_loaded=1)
2009 {
2011  typedef typename RegularVector2dField2d::grid_value_type GridT;
2012  int ZoneLoaded = zone_loaded;
2013  if (ZoneLoaded<1) ZoneLoaded=1;
2014  double SolTime;
2015  title.clear();
2016  zonename.clear();
2017  varnames.clear();
2018  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
2019  slip::Point2d<GridT> init;
2020  slip::Point2d<GridT> grid;
2021 /**********************************************************************/
2022 /********************************** HEADER ****************************/
2023 /**********************************************************************/
2024  int nbvars=0;
2025  int nbzones=0, size=0;
2026  int Imax=1, Jmax=1, Kmax=1;
2027  const int FileType=plt_get_file_type(file_path_name);
2028  plt_read_header(fp, nbvars, nbzones, Kmax, Imax, Jmax, title, zonename, varnames, SolTime, ZoneLoaded);
2029  size=Imax*Jmax*Kmax;
2030 /**********************************************************************/
2031 /*********************************** DATA *****************************/
2032 /**********************************************************************/
2033  reg.resize(Imax,Jmax);
2034  if (ZoneLoaded>nbzones) ZoneLoaded=nbzones;
2035 // // Lecture des données des zones
2036  for (int NumZone = 1; NumZone <= nbzones; ++NumZone)
2037  {
2038  {
2039  float *tmp=new float;
2040  fp.read((char*)tmp, sizeof(float));
2041  delete tmp;
2042  }
2043 
2044 // Lecture du type des données
2045  int *datatype=new int[nbvars];
2046  for (int i = 0; i < nbvars; ++i)
2047  {
2048  int *tmp=new int;
2049  fp.read((char*)tmp, sizeof(int));
2050  datatype[i]=*tmp;
2051  delete tmp;
2052  }
2053 // Lecture de trucs inutiles pour nous
2054  for (size_t i = 0; i < 3; ++i)
2055  {
2056  int *tmp=new int;
2057  fp.read((char*)tmp, sizeof(int));
2058  if ((i==0||i==1)&&(*tmp)!=0)
2059  {
2060  for (int j = 0; j < nbvars; ++j)
2061  {
2062  fp.read((char*)tmp, sizeof(int));
2063  }
2064  delete tmp;
2065  }
2066  }
2067 
2068 // Lecture des min et max de chaque variable
2069  for (int i = 0; i < nbvars; ++i)
2070  {
2071  double *min=new double, *max=new double;
2072  fp.read((char*)min, sizeof(double));
2073  fp.read((char*)max, sizeof(double));
2074  delete min;
2075  delete max;
2076  }
2077  if (NumZone!=ZoneLoaded)
2078  {
2079  for (int num = 0; num < nbvars; num++)
2080  switch (datatype[num])
2081  {
2082  case 1:
2083  fp.seekg((size)*sizeof(float), std::ios::cur);
2084  break;
2085  case 2:
2086  fp.seekg((size)*sizeof(double), std::ios::cur);
2087  break;
2088  case 3:
2089  fp.seekg((size)*sizeof(int), std::ios::cur);
2090  break;
2091  case 4:
2092  fp.seekg((size)*sizeof(short int), std::ios::cur);
2093  break;
2094  case 5:
2095  case 6:
2096  fp.seekg((size)*sizeof(char), std::ios::cur);
2097  break;
2098  default:
2099  break;
2100  }
2101  }
2102  else
2103  {
2104  for (int i = 0; i < nbvars; ++i)
2105  {
2106  if ( FileType!=2 && i<2 )
2107  {
2108  GridT *min=new GridT, *max=new GridT;
2109  if (datatype[i]==1)
2110  {
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);
2117  delete tmp;
2118  }
2119  else if (datatype[i]==2)
2120  {
2121  int *tmp=new int;
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);
2127  delete tmp;
2128  }
2129  else if (datatype[i]==3)
2130  {
2131  int *tmp=new int;
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);
2137  delete tmp;
2138  }
2139  else if (datatype[i]==4)
2140  {
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);
2147  delete tmp;
2148  }
2149  else if (datatype[i]==5||datatype[i]==6)
2150  {
2151  char *tmp=new char;
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);
2157  delete tmp;
2158  }
2159 
2160  int Nmax=1;
2161  switch (i)
2162  {
2163  case 0:
2164  Nmax=Jmax;
2165  break;
2166  case 1:
2167  Nmax=Imax;
2168  break;
2169  default:
2170  break;
2171  }
2172  init[i]=*min;
2173  if (Nmax>1)
2174  grid[i]=std::abs((*min)-(*max))/(Nmax-1.);
2175  else
2176  grid[i]=1.;
2177  delete min;
2178  delete max;
2179  }
2180  else if ( ( FileType==0 && i<4 ) || ( FileType==2 && i<2 ) )
2181  {
2182  int n=0, comp=i-2;
2183  if (FileType==2)
2184  comp=i;
2185  switch (datatype[i])
2186  {
2187  case 1:
2188  {
2189  float *tmp=new float[size];
2190  fp.read((char*)tmp, size*sizeof(float));
2191  for (int ii = Imax-1; ii >= 0; --ii)
2192  {
2193  for (int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2194  {
2195  reg(ii,jj)[comp]=static_cast<T>(*(tmp+n));
2196  }
2197  }
2198  delete[] tmp;
2199  break;
2200  }
2201  case 2:
2202  {
2203  double *tmp=new double[size];
2204  fp.read((char*)tmp, size*sizeof(double));
2205  for (int ii = Imax-1; ii >= 0; --ii)
2206  {
2207  for (int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2208  {
2209  reg(ii,jj)[comp]=static_cast<T>(*(tmp+n));
2210  }
2211  }
2212  delete[] tmp;
2213  break;
2214  }
2215  case 3:
2216  {
2217  int *tmp=new int[size];
2218  fp.read((char*)tmp, size*sizeof(int));
2219  for (int ii = Imax-1; ii >= 0; --ii)
2220  {
2221  for (int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2222  {
2223  reg(ii,jj)[comp]=static_cast<T>(*(tmp+n));
2224  }
2225  }
2226  delete[] tmp;
2227  break;
2228  }
2229  case 4:
2230  {
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)
2234  {
2235  for (int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2236  {
2237  reg(ii,jj)[comp]=static_cast<T>(*(tmp+n));
2238  }
2239  }
2240  delete[] tmp;
2241  break;
2242  }
2243  case 5:
2244  case 6:
2245  {
2246  char *tmp=new char[size];
2247  fp.read((char*)tmp, size*sizeof(char));
2248  for (int ii = Imax-1; ii >= 0; --ii)
2249  {
2250  for (int jj = 0; jj < Jmax && n < size; ++jj, ++n)
2251  {
2252  reg(ii,jj)[comp]=static_cast<T>(*(tmp+n));
2253  }
2254  }
2255  delete[] tmp;
2256  break;
2257  }
2258  }
2259  }
2260  }
2261  }
2262  delete[] datatype;
2263  }
2264  if ( FileType!=2 )
2265  {
2266  reg.set_init_point(init);
2267  reg.set_grid_step(grid);
2268  }
2269 }
2270 
2291 template<typename RegularVector2dField2d>
2292 void plt_to_RegularVector2dField2d(const std::string &file_path_name,
2294  const int zone_loaded=1)
2295 {
2296  std::string _useless_string;
2297  std::vector<std::string> _useless_varnames;
2298  slip::plt_to_RegularVector2dField2d(file_path_name,
2299  reg,
2300  _useless_string,
2301  _useless_string,
2302  _useless_varnames,
2303  zone_loaded);
2304 }
2305 
2333 bool compareTwoRows2D(double* rowA, double* rowB)
2334 {
2335  return ( (rowA[0]<rowB[0]) || ( (rowA[0]==rowB[0])&&(rowA[1]<rowB[1]) ) );
2336 }
2337 
2366 template<typename RegularVector2dField2d>
2367 void generic_plt_to_RegularVector2dField2d(const std::string &file_path_name,
2369  std::string &title,
2370  std::string &zonename,
2371  std::vector<std::string> &varnames,
2372  const int zone_loaded=1)
2373 {
2375  typedef typename RegularVector2dField2d::grid_value_type GridT;
2376  int ZoneLoaded = zone_loaded;
2377  if (ZoneLoaded<1) ZoneLoaded=1;
2378  double SolTime;
2379  title.clear();
2380  zonename.clear();
2381  varnames.clear();
2382  std::ifstream fp (file_path_name.c_str(), std::ios::in|std::ios::binary);
2383  slip::Point2d<GridT> init;
2384  slip::Point2d<GridT> grid;
2385 
2386  slip::Array2d<T> data, test_data;
2387  const int FileType=plt_get_file_type(file_path_name);
2388  slip::plt_to_Array2d(file_path_name, data, ZoneLoaded);
2389 
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] ) ) )
2391  {
2392  // sorting array
2393  // std::sort(data.begin(),data.begin()+data.dim1(),&compareTwoRows2D);
2394  //data.sort(&compareTwoRows2D); //Adrien
2395  T** datab = &(data[0]);
2396  std::sort(datab,datab+data.dim1(),&compareTwoRows2D);
2397 
2398  test_data.resize(data.dim1(), data.dim2());
2399  for (size_t i = 0; i < data.dim1(); ++i)
2400  {
2401  for (size_t j = 0; j < data.dim2(); ++j)
2402  {
2403  test_data[i][j]=data[i][j]; // ne pas utiliser les iterators ici !!! ( ils ont été invalidés par std::sort() )
2404  }
2405  }
2406  data.resize(0,0);
2407  data=test_data;
2408  }
2409 
2410  std::size_t size_y = std::count(data.col_begin(0),data.col_end(0),
2411  data[0][0]);
2412  std::size_t size_x = data.rows() / size_y;
2413 
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]));
2416 
2417  bool y_direct = (init[1] == data[0][1]);
2418 
2419  reg.resize(size_y,size_x);
2420  if( data[0][0] == data[1][0] || FileType==1 )
2421  {
2422  //cas x fixe, y varie
2423  grid[0]=static_cast<GridT>(std::abs(*(data.col_begin(0)+size_y)-(*(data.col_begin(0)))));
2424  grid[1]=static_cast<GridT>(std::abs(*(data.col_begin(1)+1)-*(data.col_begin(1))));
2425  if ( FileType==0 )
2426  {
2427  std::size_t gridy = 0;
2428 
2429  for(std::size_t j = 0; j < size_x; ++j)
2430  {
2431  if(y_direct)
2432  {
2433  std::copy(data.col_begin(3) + gridy,
2434  data.col_begin(3) + (gridy + size_y),
2435  reg.col_rbegin(1,j));
2436  std::copy(data.col_begin(2) + gridy,
2437  data.col_begin(2) + (gridy + size_y),
2438  reg.col_rbegin(0,j));
2439  gridy += size_y;
2440  }
2441  else
2442  {
2443  std::copy(data.col_begin(3) + gridy,
2444  data.col_begin(3) + (gridy + size_y),
2445  reg.col_begin(1,j));
2446  std::copy(data.col_begin(2) + gridy,
2447  data.col_begin(2) + (gridy + size_y),
2448  reg.col_begin(0,j));
2449  gridy += size_y;
2450  }
2451  }
2452  }
2453  }
2454  else
2455  {
2456  //cas x varie, y fixe
2457  grid[0]=static_cast<GridT>(std::abs(*(data.col_begin(0)+1)-(*(data.col_begin(0)))));
2458  grid[1]=static_cast<GridT>(std::abs(*(data.col_begin(1)+size_x) - *(data.col_begin(1))));
2459  std::size_t gridx = 0;
2460  for(std::size_t j = 0; j < size_y; ++j)
2461  {
2462  if(y_direct)
2463  {
2464  std::copy(data.col_begin(2) + gridx,
2465  data.col_begin(2) + (gridx + size_x),
2466  reg.row_begin(0,(size_y - 1) - j));
2467  std::copy(data.col_begin(3) + gridx,
2468  data.col_begin(3) + (gridx + size_x),
2469  reg.row_begin(1,(size_y - 1) - j));
2470 
2471  }
2472  else
2473  {
2474  std::copy(data.col_begin(2) + gridx,
2475  data.col_begin(2) + (gridx + size_x),
2476  reg.row_begin(0,j));
2477  std::copy(data.col_begin(3) + gridx,
2478  data.col_begin(3) + (gridx + size_x),
2479  reg.row_begin(1,j));
2480  }
2481  gridx += size_x;
2482  }
2483  }
2484 
2485  if ( FileType!=2 )
2486  {
2487  reg.set_init_point(init);
2488  reg.set_grid_step(grid);
2489  }
2490 }
2491 
2512 template<typename RegularVector2dField2d>
2513 void generic_plt_to_RegularVector2dField2d(const std::string &file_path_name,
2515  const int zone_loaded=1)
2516 {
2517  std::string _useless_string;
2518  std::vector<std::string> _useless_varnames;
2520  reg,
2521  _useless_string,
2522  _useless_string,
2523  _useless_varnames,
2524  zone_loaded);
2525 }
2526 
2546 template<typename RegularVector2dField2d>
2547 void RegularVector2dField2d_to_plt(const std::string &file_path_name,
2549  std::string title,
2550  std::string zone,
2551  const double SolTime,
2552  std::vector<std::string> varnames=std::vector<std::string>(),
2553  const int FileType=0)
2554 {
2556  typedef typename RegularVector2dField2d::grid_value_type GridT;
2557  std::ofstream fp (file_path_name.c_str(), std::ios::out|std::ios::binary);
2558 /******************************************************************************/
2559 /********************************** HEADER ************************************/
2560 /******************************************************************************/
2561 
2562 // Lecture de la version du fichier Tecplot
2563  fp.write("#!TDV112",8);
2564  int *myint=new int;
2565  char *mychar=new char;
2566  float *myfloat=new float;
2567  double *mydouble=new double;
2568 // Écriture de l'ordre
2569  *myint=1;
2570  fp.write((char*)myint, sizeof(int));
2571 
2572 // Écriture du type de fichier
2573  *myint=FileType;
2574  fp.write((char*)myint, sizeof(int));
2575 
2576 // // Écriture du titre
2577  std::string strtmp=title;
2578  for (size_t i = 0; i <= strtmp.size(); i++)
2579  {
2580  *myint=(int)strtmp[i];
2581  fp.write((char*)myint,sizeof(int));
2582  }
2583 
2584 // Définition des variables en fonction du type de fichier
2585  size_t imin=0, imax=4, nbvars=4;
2586  switch (FileType)
2587  {
2588  case 1:
2589  imin=0;
2590  imax=2;
2591  nbvars=2;
2592  if (varnames.size()<2)
2593  {
2594  varnames.clear();
2595  varnames.push_back("X");
2596  varnames.push_back("Y");
2597  }
2598  break;
2599  case 2:
2600  imin=0;
2601  imax=2;
2602  nbvars=2;
2603  if (varnames.size()<2)
2604  {
2605  varnames.clear();
2606  varnames.push_back("U");
2607  varnames.push_back("V");
2608  }
2609  break;
2610  default:
2611  if (varnames.size()<4)
2612  {
2613  varnames.clear();
2614  varnames.push_back("X");
2615  varnames.push_back("Y");
2616  varnames.push_back("U");
2617  varnames.push_back("V");
2618  }
2619  break;
2620  }
2621 
2622 // Écriture du nombre de variables
2623  *myint=nbvars;
2624  fp.write((char*)myint, sizeof(int));
2625 
2626 // Écriture des noms des variables
2627  for (size_t i = imin; i < imax; i++)
2628  {
2629  for (size_t j = 0; j <= varnames[i].size(); j++)
2630  {
2631  *myint=(int)varnames[i][j];
2632  fp.write((char*)myint,sizeof(int));
2633  }
2634  }
2635 
2636 // Écriture des paramètres des zones
2637 // Écriture du zone marker
2638  *myfloat=299.0;
2639  fp.write((char*)myfloat, sizeof(float));
2640 // Écriture du nom de la zone
2641  strtmp=zone;
2642  for (size_t i = 0; i <= strtmp.size(); i++)
2643  {
2644  *myint=(int)strtmp[i];
2645  fp.write((char*)myint,sizeof(int));
2646  }
2647 // Écriture du Parent zone
2648  *myint=-1;
2649  fp.write((char*)myint, sizeof(int));
2650 // Écriture du StrandID
2651  *myint=-1;
2652  fp.write((char*)myint, sizeof(int));
2653 // Écriture du Solution time
2654  *mydouble=SolTime;
2655  fp.write((char*)mydouble, sizeof(double));
2656 // Écriture du -1 inutile
2657  *myint=-1;
2658  fp.write((char*)myint, sizeof(int));
2659 // Écriture du ZoneType
2660  *myint=0;
2661  fp.write((char*)myint, sizeof(int));
2662 // Écriture du Specify Var Location
2663  fp.write((char*)myint, sizeof(int));
2664 // Écriture du Supplied Face Neighboring
2665  fp.write((char*)myint, sizeof(int));
2666 // Écriture du User Defined Face Connections
2667  fp.write((char*)myint, sizeof(int));
2668 // Écriture des IMax, JMax et KMax
2669  *myint=reg.dim2();
2670  fp.write((char*)myint, sizeof(int));
2671  *myint=reg.dim1();
2672  fp.write((char*)myint, sizeof(int));
2673  *myint=1;
2674  fp.write((char*)myint, sizeof(int));
2675 // Écriture du Auxiliary Name
2676  *myint=0;
2677  fp.write((char*)myint, sizeof(int));
2678 // Écriture du marker de fin de header
2679  *myfloat=357.0;
2680  fp.write((char*)myfloat, sizeof(float));
2681 
2682 /******************************************************************************/
2683 /*********************************** DATA *************************************/
2684 /******************************************************************************/
2685 // Écriture des données des zones
2686 // Écriture du marker de début de zone
2687  *myfloat=299.0;
2688  fp.write((char*)myfloat, sizeof(float));
2689 // Écriture du type des données
2690  *myint=get_tecplot_type<GridT>();
2691  if (FileType==0 || FileType==1)
2692  {
2693  for (size_t i = 0; i < 2; ++i)
2694  fp.write((char*)myint, sizeof(int));
2695  }
2696  *myint=get_tecplot_type<T>();
2697  if (FileType==0 || FileType==2)
2698  {
2699  for (size_t i = 0; i < 2; ++i)
2700  fp.write((char*)myint, sizeof(int));
2701  }
2702 // Écriture de trucs inutiles pour nous
2703  *myint=0;
2704  fp.write((char*)myint, sizeof(int));
2705  fp.write((char*)myint, sizeof(int));
2706  *myint=-1;
2707  fp.write((char*)myint, sizeof(int));
2708 // Écriture des min et max de chaque variable
2709  if (FileType==0 || FileType==1)
2710  {
2711  *mydouble=static_cast<double>(reg.get_init_point()[0]);
2712  fp.write((char*)mydouble, sizeof(double));
2713  *mydouble=static_cast<double>(reg.get_init_point()[0]+(reg.dim2()-1)*reg.get_grid_step()[0]);
2714  fp.write((char*)mydouble, sizeof(double));
2715  *mydouble=static_cast<double>(reg.get_init_point()[1]);
2716  fp.write((char*)mydouble, sizeof(double));
2717  *mydouble=static_cast<double>(reg.get_init_point()[1]+(reg.dim1()-1)*reg.get_grid_step()[1]);
2718  fp.write((char*)mydouble, sizeof(double));
2719  }
2720 
2721  if (FileType==0 || FileType==2)
2722  {
2723  double umin, umax, vmin, vmax, wmin, wmax;
2724  umin=static_cast<double>((*std::min_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector2d<T> >(0)))[0]);
2725  umax=static_cast<double>((*std::max_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector2d<T> >(0)))[0]);
2726  vmin=static_cast<double>((*std::min_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector2d<T> >(1)))[1]);
2727  vmax=static_cast<double>((*std::max_element(reg.begin(),reg.end(),slip::GenericComparator<slip::Vector2d<T> >(1)))[1]);
2728  *mydouble=umin;
2729  fp.write((char*)mydouble, sizeof(double));
2730  *mydouble=umax;
2731  fp.write((char*)mydouble, sizeof(double));
2732  *mydouble=vmin;
2733  fp.write((char*)mydouble, sizeof(double));
2734  *mydouble=vmax;
2735  fp.write((char*)mydouble, sizeof(double));
2736  }
2737 
2738  if (FileType==0 || FileType==1)
2739  {
2740  const int size_grid=sizeof(GridT);
2741  for (int ii = reg.dim1()-1; ii >= 0; --ii)
2742  {
2743  for (int jj = 0; jj < (int)reg.dim2(); ++jj)
2744  {
2745  GridT *temp=new GridT;
2746  *temp=reg.x(ii,jj);
2747  fp.write((char*)temp, size_grid);
2748  delete temp;
2749  }
2750  }
2751  for (int ii = reg.dim1()-1; ii >= 0; --ii)
2752  {
2753  for (int jj = 0; jj < (int)reg.dim2(); ++jj)
2754  {
2755  GridT *temp=new GridT;
2756  *temp=reg.y(ii,jj);
2757  fp.write((char*)temp, size_grid);
2758  delete temp;
2759  }
2760  }
2761  }
2762 
2763  if (FileType==0 || FileType==2)
2764  {
2765  const int size_data=sizeof(T);
2766  for (size_t i = 0; i < 2; ++i)
2767  {
2768  for (int ii = reg.dim1()-1; ii >= 0; --ii)
2769  {
2770  for (int jj = 0; jj < (int)reg.dim2(); ++jj)
2771  {
2772  T *temp=new T;
2773  *temp=reg(ii,jj)[i];
2774  fp.write((char*)temp, size_data);
2775  delete temp;
2776  }
2777  }
2778  }
2779  }
2780  delete myint;
2781  delete mychar;
2782  delete myfloat;
2783  delete mydouble;
2784 }
2785 
2803 template<typename RegularVector2dField2d>
2804 void RegularVector2dField2d_to_plt(const std::string &file_path_name,
2806  const int FileType=0)
2807 {
2808  RegularVector2dField2d_to_plt(file_path_name, reg, "Title", "Zone", 0., std::vector<std::string>(), FileType);
2809 }
2810 
2830 template<typename RegularVector2dField2d>
2831 void RegularVector2dField2d_to_plt(const std::string &file_path_name,
2833  const double SolTime,
2834  const int FileType=0)
2835 {
2836  RegularVector2dField2d_to_plt(file_path_name, reg, "Title", "Zone", SolTime, std::vector<std::string>(), FileType);
2837 }
2838 
2858 template<typename RegularVector2dField2d>
2859 void RegularVector2dField2d_to_plt(const std::string &file_path_name,
2861  std::string title,
2862  std::string zone,
2863  const int FileType=0)
2864 {
2865  RegularVector2dField2d_to_plt(file_path_name, reg, title, zone, 0., std::vector<std::string>(), FileType);
2866 }
2867 
2888 template<typename RegularVector2dField2d>
2889 void RegularVector2dField2d_to_plt(const std::string &file_path_name,
2891  std::string title,
2892  std::string zone,
2893  std::vector<std::string> varnames,
2894  const int FileType=0)
2895 {
2896  RegularVector2dField2d_to_plt(file_path_name, reg, title, zone, 0., varnames, FileType);
2897 }
2898 
2899 }//::slip
2900 #endif
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.
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 &reg, 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 &reg, 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.
Definition: Array2d.hpp:2323
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 &reg, 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.
Definition: Array2d.hpp:3145
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Definition: copy_ext.hpp:177
Provides a class to manipulate 3d Vector.
size_type rows() const
Returns the number of rows (first dimension size) in the Array2d.
Definition: Array2d.hpp:3139
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 &reg, 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 &reg, 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 &reg, 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 &reg, 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...
Definition: Array2d.hpp:135
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.
Definition: Array2d.hpp:3134
size_type dim1() const
Returns the number of slices (first dimension size) in the GenericMultiComponent3d.