]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/testAnalFile.cxx
Salome HOME
Join modifications from branch CEAFor_V3_2_0
[modules/med.git] / src / MEDMEM / testAnalFile.cxx
1 #include <string>
2 #include <deque>
3 #include <iostream>
4 #include "MEDMEM_MedMedDriver.hxx"
5 #include "MEDMEM_Med.hxx"
6 #include "MEDMEM_MedMeshDriver.hxx"
7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Field.hxx"
9 #include "MEDMEM_DriverFactory.hxx"
10
11 using namespace std;
12 using namespace MEDMEM;
13 using namespace MED_EN;
14
15 int main(int argc, char *argv[])
16 {
17   if (argc !=2)
18     {
19       cerr << "Usage : " << argv[0] 
20            << " fileName.med where fileName.med should be a med file" << endl;
21       cerr << "        It will then generate two med files fileNameAnal_V21.med (med V2.1 format)" << endl;
22       cerr << "and fileNameAnal_V21.med (med V2.2 format)" << endl << endl;
23       exit(-1);
24     }
25
26   int i;
27   // This test program is more or less designed to work with file TimeStamps.med
28   // If you want to use it for other Med files, you have to alter the mounting in memory of the fields f1 and f2
29   //string fileIn="/export/home/geay32/SALOME225/KERNEL_SRC/examples/TimeStamps.med";
30
31   string fileIn = argv[1] ;
32   const string ext=".med";
33   string::size_type pos=fileIn.find(ext,0);
34   string baseName (fileIn, 0, pos); // nom sans extension
35   string fileOut21=baseName + "Anal_V21.med";
36   string fileOut22=baseName + "Anal_V22.med";
37
38   MED *myMed=new MED;
39   MED_MED_RDONLY_DRIVER *driverIn=new MED_MED_RDONLY_DRIVER(fileIn,myMed);
40   driverIn->open();
41   driverIn->readFileStruct();
42   driverIn->close();
43   int nbOfMeshes=myMed->getNumberOfMeshes();
44   int nbOfFields=myMed->getNumberOfFields();
45   cout << nbOfMeshes << " --- " << nbOfFields << endl;
46   deque<string> names=myMed->getMeshNames();
47   for(i=0;i<nbOfMeshes;i++)
48     cout << names[i] << endl;
49   cout << "************* " << endl;
50   deque<string> names2=myMed->getFieldNames();
51   for(i=0;i<nbOfFields;i++)
52     cout << names2[i] << endl;
53   MESH *mesh=myMed->getMesh(names[0]);
54   mesh->read();
55   myMed->updateSupport();
56   deque<DT_IT_> iterations=myMed->getFieldIteration(names2[2]);
57   cout << iterations.size() << endl;
58   FIELD_ *f1=myMed->getField(names2[2],iterations[0].dt,iterations[0].it);
59   FIELD_ *f2=myMed->getField(names2[2],iterations[1].dt,iterations[1].it);
60   FIELD<double> *f1s=(FIELD<double> *)f1;
61   f1s->read();
62   FIELD<double> *f2s=(FIELD<double> *)f2;
63   f2s->read();
64   DRIVERFACTORY::setMedFileVersionForWriting(V21);
65   int id=mesh->addDriver(MED_DRIVER,fileOut21,mesh->getName());
66   mesh->write(id);
67   id=f1s->addDriver(MED_DRIVER, fileOut21, f1s->getName());
68   f1s->write(id);
69   id=f2s->addDriver(MED_DRIVER, fileOut21, f2s->getName());
70   f2s->write(id);
71
72   DRIVERFACTORY::setMedFileVersionForWriting(V22);
73   id=mesh->addDriver(MED_DRIVER,fileOut22,mesh->getName());
74   mesh->write(id);
75   id=f1s->addDriver(MED_DRIVER, fileOut22, f1s->getName());
76   f1s->write(id);
77   id=f2s->addDriver(MED_DRIVER, fileOut22, f2s->getName());
78   f2s->write(id);
79
80   delete myMed;
81   return 0;
82 }
83