Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEMBinTest / duplicateMED.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include<string>
24
25 #include "MEDMEM_Exception.hxx"
26 #include "MEDMEM_Mesh.hxx"
27 #include "MEDMEM_Grid.hxx"
28 #include "MEDMEM_Field.hxx"
29 #include "MEDMEM_MedFileBrowser.hxx"
30
31 using namespace std;
32 using namespace MEDMEM;
33 static void usage(char * name)
34 {
35   cout << "  " << name << " <input med file> <output med file> " <<endl ;
36   cout << "    " << "(the two file name are mandatory)" << endl ;
37   exit(-1);
38 }
39
40 int main (int argc, char ** argv) {
41   if (argc != 3) usage(argv[0]);
42   
43   string filenameIN = argv[1] ;
44   string filenameOUT = argv[2] ;
45   
46   try {
47
48     MEDFILEBROWSER myMed(filenameIN) ;
49
50     std::vector< std::string > meshNames = myMed.getMeshNames ();
51     for ( unsigned i = 0; i < meshNames.size(); ++i )
52     {
53       GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
54       int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
55       mesh->read(drv);
56       drv = mesh->addDriver(MED_DRIVER, filenameOUT, meshNames[i] );
57       mesh->write(drv);
58       mesh->removeReference();
59     }
60     
61     vector<string> FieldName = myMed.getFieldNames() ;
62     for (unsigned i=0; i<FieldName.size(); i++)
63     {
64       vector<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
65       for (unsigned j=0; j<FieldIteration.size(); j++)
66       {
67         FIELD_ * myField = 0;
68         switch( myMed.getFieldType( FieldName[i] ))
69         {
70         case MED_REEL64: myField = new FIELD<double>; break;
71         case MED_INT32:  
72         case MED_INT64:  myField = new FIELD<int>; break;
73         default:
74           continue;
75         }
76         myField->setIterationNumber( FieldIteration[j].dt );
77         myField->setOrderNumber    ( FieldIteration[j].it );
78         int drv = myField->addDriver( MED_DRIVER, filenameIN, FieldName[i]);
79         myField->read( drv ) ;
80         drv = myField->addDriver( MED_DRIVER, filenameOUT, FieldName[i]);
81         myField->write( drv );
82         myField->removeReference();
83       }
84     }
85   } catch (MEDEXCEPTION& ex) {
86     MESSAGE_MED(ex.what()) ;
87   }
88
89 }