Back to index

salome-med  6.5.0
Functions
med2vtk.cxx File Reference
#include <string>
#include <deque>
#include "MEDMEM_Exception.hxx"
#include "MEDMEM_define.hxx"
#include "MEDMEM_MedFileBrowser.hxx"
#include "MEDMEM_Mesh.hxx"
#include "MEDMEM_Grid.hxx"
#include "MEDMEM_Family.hxx"
#include "MEDMEM_Support.hxx"
#include "MEDMEM_Field.hxx"
#include "MEDMEM_VtkMedDriver.hxx"

Go to the source code of this file.

Functions

static void usage (char *name)
int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 46 of file med2vtk.cxx.

{
  if (argc != 3) usage(argv[0]);
  
  string filenameIN = argv[1] ;
  string filenameOUT = argv[2] ;
  
  try {
    // we read all meshes and fields in filenameIN //
    MEDFILEBROWSER myMed(filenameIN) ;
    vector< FIELD_* > fields;
    vector< GMESH* > meshes;

    // read all meshes

    cout << "Read all meshes "  ;
    int NumberOfMeshes = myMed.getNumberOfMeshes() ;
    cout << "( "<<NumberOfMeshes << " ) :" << endl ;
    vector<string> MeshName = myMed.getMeshNames() ;
    for (int i=0; i<NumberOfMeshes; i++) {
      GMESH* mesh = myMed.isStructuredMesh( MeshName[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
      mesh->addDriver(MED_DRIVER, filenameIN, MeshName[i] );
      mesh->read();
      cout << "  - Mesh "<<i+1<<", named "<<MeshName[i]<<" is read !" << endl;
      meshes.push_back( mesh );
    }

    // read all fields

    cout << "Read all fields " ;
    int NumberOfFields = myMed.getNumberOfFields() ;
    cout << "( "<<NumberOfFields << " ) :" << endl;
    vector<string> FieldName = myMed.getFieldNames() ;
    for (int i=0; i<NumberOfFields; i++) {
      vector<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
      cout << "  - Field "<<i+1<<", named "<<FieldName[i] << " :" << endl ;
      int NumberOfIteration = FieldIteration.size() ;
      cout << "    Number of iteration pair : "<< NumberOfIteration << endl;
      for (int j=0; j<NumberOfIteration; j++) {
        FIELD_ * myField = 0;
        switch( myMed.getFieldType( FieldName[j] ))
        {
        case MED_REEL64: myField = new FIELD<double>; break;
        case MED_INT32:  
        case MED_INT64:  myField = new FIELD<int>; break;
        default:
          cout << "Unknown value type - skipped" << endl;
          continue;
        }
        myField->setIterationNumber( FieldIteration[j].dt );
        myField->setOrderNumber( FieldIteration[j].it );
        myField->addDriver( MED_DRIVER, filenameIN, FieldName[i]);
        myField->read() ;
        cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is read !" << endl;
        fields.push_back( myField );
        string meshName = myMed.getMeshName( FieldName[j] );
        for ( unsigned m = 0; m < meshes.size(); ++m)
          if ( meshes[m]->getName() == meshName )
            myField->getSupport()->setMesh( meshes[m] );
      }
    }

    // we write all in VTK file filenameOUT //
    if ( !fields.empty() )
    {
      vector< const FIELD_* > constFields( fields.begin(), fields.end() );
      VTK_MED_DRIVER medDriver( filenameOUT, constFields );
      medDriver.write();
    }
    else if ( !meshes.empty() )
    {
      VTK_MESH_DRIVER meshDriver( filenameOUT, meshes[0] );
      meshDriver.write() ;
    }

    for ( unsigned i = 0; i < meshes.size(); ++ i)
      meshes[i]->removeReference();
    for ( unsigned i = 0; i < fields.size(); ++ i)
      fields[i]->removeReference();
  } 
  catch (MEDEXCEPTION& ex){
    cout << ex.what() << endl ;
  }

}

Here is the call graph for this function:

static void usage ( char *  name) [static]

Definition at line 39 of file med2vtk.cxx.

{
  cout << "  " << name << " <input med file> <output vtk file> " <<endl ;
  cout << "    " << "(the two file name are mandatory)" << endl ;
  exit(-1);
}

Here is the caller graph for this function: