1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
32 using namespace MEDMEM;
33 static void usage(char * name)
35 cout << " " << name << " <input med file> <output med file> " <<endl ;
36 cout << " " << "(the two file name are mandatory)" << endl ;
40 int main (int argc, char ** argv) {
41 if (argc != 3) usage(argv[0]);
43 string filenameIN = argv[1] ;
44 string filenameOUT = argv[2] ;
48 MEDFILEBROWSER myMed(filenameIN) ;
50 std::vector< std::string > meshNames = myMed.getMeshNames ();
51 for ( unsigned i = 0; i < meshNames.size(); ++i )
53 GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
54 int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
56 drv = mesh->addDriver(MED_DRIVER, filenameOUT, meshNames[i] );
58 mesh->removeReference();
61 vector<string> FieldName = myMed.getFieldNames() ;
62 for (unsigned i=0; i<FieldName.size(); i++)
64 vector<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
65 for (unsigned j=0; j<FieldIteration.size(); j++)
68 switch( myMed.getFieldType( FieldName[i] ))
70 case MED_REEL64: myField = new FIELD<double>; break;
72 case MED_INT64: myField = new FIELD<int>; break;
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();
85 } catch (MEDEXCEPTION& ex) {
86 MESSAGE_MED(ex.what()) ;