Back to index

salome-med  6.5.0
duplicateMED.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include<string>
00024 
00025 #include "MEDMEM_Exception.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_Grid.hxx"
00028 #include "MEDMEM_Field.hxx"
00029 #include "MEDMEM_MedFileBrowser.hxx"
00030 
00031 using namespace std;
00032 using namespace MEDMEM;
00033 static void usage(char * name)
00034 {
00035   cout << "  " << name << " <input med file> <output med file> " <<endl ;
00036   cout << "    " << "(the two file name are mandatory)" << endl ;
00037   exit(-1);
00038 }
00039 
00040 int main (int argc, char ** argv) {
00041   if (argc != 3) usage(argv[0]);
00042   
00043   string filenameIN = argv[1] ;
00044   string filenameOUT = argv[2] ;
00045   
00046   try {
00047 
00048     MEDFILEBROWSER myMed(filenameIN) ;
00049 
00050     std::vector< std::string > meshNames = myMed.getMeshNames ();
00051     for ( unsigned i = 0; i < meshNames.size(); ++i )
00052     {
00053       GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
00054       int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
00055       mesh->read(drv);
00056       drv = mesh->addDriver(MED_DRIVER, filenameOUT, meshNames[i] );
00057       mesh->write(drv);
00058       mesh->removeReference();
00059     }
00060     
00061     vector<string> FieldName = myMed.getFieldNames() ;
00062     for (unsigned i=0; i<FieldName.size(); i++)
00063     {
00064       vector<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
00065       for (unsigned j=0; j<FieldIteration.size(); j++)
00066       {
00067         FIELD_ * myField = 0;
00068         switch( myMed.getFieldType( FieldName[i] ))
00069         {
00070         case MED_REEL64: myField = new FIELD<double>; break;
00071         case MED_INT32:  
00072         case MED_INT64:  myField = new FIELD<int>; break;
00073         default:
00074           continue;
00075         }
00076         myField->setIterationNumber( FieldIteration[j].dt );
00077         myField->setOrderNumber    ( FieldIteration[j].it );
00078         int drv = myField->addDriver( MED_DRIVER, filenameIN, FieldName[i]);
00079         myField->read( drv ) ;
00080         drv = myField->addDriver( MED_DRIVER, filenameOUT, FieldName[i]);
00081         myField->write( drv );
00082         myField->removeReference();
00083       }
00084     }
00085   } catch (MEDEXCEPTION& ex) {
00086     MESSAGE_MED(ex.what()) ;
00087   }
00088 
00089 }