1 // Copyright (C) 2007-2008 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
26 #include "MEDMEM_Exception.hxx"
27 #include "MEDMEM_define.hxx"
29 #include "MEDMEM_Med.hxx"
30 #include "MEDMEM_Mesh.hxx"
31 #include "MEDMEM_Family.hxx"
32 #include "MEDMEM_Support.hxx"
33 #include "MEDMEM_Field.hxx"
34 #include "MEDMEM_EnsightMedDriver.hxx"
37 using namespace MEDMEM;
38 void usage(char * name)
40 cout << " ERROR ABOUT SYNTAX " << endl ;
41 cout << " " << name << " <input ensight file> <output med file> [I - to read into MED_INT32 fields]"
46 // ensight2med toto.case toto.med => input : toto.case => output : toto.med....
48 int main (int argc, char ** argv) {
54 filenameIN = argv[1] ;
55 filenameOUT = argv[2] ;
56 cout << " reading all into the Ensight file " << filenameIN << " and writing all into the Med file " << filenameOUT << endl ;
58 MED myMed(ENSIGHT_DRIVER,filenameIN) ;
61 int id = myMed.addDriver(MED_DRIVER,filenameOUT);
64 else if ( argc == 4 && strncmp(argv[3], "I", 1 )==0 )
66 // we read all variables into INT32 fields
67 // (we need such fields for test_operation_fieldint)
69 filenameIN = argv[1] ;
70 filenameOUT = argv[2] ;
71 MED myMed(ENSIGHT_DRIVER,filenameIN);
73 // read-write the mesh
74 if ( myMed.getNumberOfMeshes() < 1 ) {
75 cout << "No meshes found in EnSight file " << filenameIN << endl;
78 vector<string> meshNames( myMed.getNumberOfMeshes() );
79 myMed.getMeshNames( &meshNames[0] );
80 MESH * mesh = myMed.getMesh( meshNames[0] );
82 int drv = mesh->addDriver(MED_DRIVER, filenameOUT, mesh->getName() );
86 int nbFields = myMed.getNumberOfFields();
87 vector<string> fieldNames( nbFields );
88 myMed.getFieldNames( &fieldNames[0] );
89 for ( int i = 0; i < nbFields; ++i )
91 deque<DT_IT_> dis = myMed.getFieldIteration( fieldNames[i] );
92 for ( deque<DT_IT_>::iterator d_i = dis.begin(); d_i != dis.end(); ++d_i )
94 FIELD_* f = myMed.getField( fieldNames[i], d_i->dt, d_i->it );
95 FIELD<int> intF(ENSIGHT_DRIVER, filenameIN, f->getName() );
96 // replace zero values as theses fields are used for division
97 int nbVals = intF.getValueLength();
98 int* values = const_cast<int*>(intF.getValue());
100 if ( values[nbVals]==0 )
101 values[nbVals]= nbVals%5 + 1;
103 int drv = intF.addDriver(MED_DRIVER, filenameOUT, f->getName() );