Back to index

salome-med  6.5.0
Functions
ensight2med.cxx File Reference
#include <string>
#include <deque>
#include <vector>
#include "MEDMEM_Exception.hxx"
#include "MEDMEM_define.hxx"
#include "MEDMEM_Mesh.hxx"
#include "MEDMEM_Family.hxx"
#include "MEDMEM_Support.hxx"
#include "MEDMEM_Field.hxx"
#include "MEDMEM_EnsightMedDriver.hxx"
#include "MEDMEM_EnsightFieldDriver.hxx"
#include "MEDMEM_EnsightMeshDriver.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 51 of file ensight2med.cxx.

                                  {

  string filenameIN ;
  string filenameOUT;
 
  if ( argc == 3 ) {
    filenameIN  = argv[1] ;
    filenameOUT = argv[2] ;
    cout << " reading all into the Ensight file " << filenameIN << " and writing all into the Med file " << filenameOUT <<  endl ;

    vector< FIELD_* > fields;
    vector< const GMESH* > meshes;

    // Read

    ENSIGHT_MED_RDONLY_DRIVER medDriver(filenameIN, fields);
    medDriver.open();
    medDriver.read();
    medDriver.close();
    if ( !fields.empty() )
    {
      set<const GMESH*> uniqueMeshes;
      for ( unsigned i = 0; i < fields.size(); ++i )
        uniqueMeshes.insert( fields[i]->getSupport()->getMesh() );
      meshes.assign( uniqueMeshes.begin(), uniqueMeshes.end() );
    }
    else
    {
      // no fields but only meshes in the file
      MESH* mesh = 0;
      int meshIndex = 1;
      do
      {
        mesh = new MESH;
        meshes.push_back( mesh );
        ENSIGHT_MESH_RDONLY_DRIVER meshDriver( filenameIN, mesh, meshIndex++ );
        meshDriver.open();
        meshDriver.read();
        meshDriver.close();
      } while ( mesh->getNumberOfNodes() > 0 );
      meshes.back()->removeReference();
      meshes.pop_back();
    }

    // Write

    for ( unsigned i = 0; i < meshes.size(); ++i )
    {
      meshes[i]->write(MED_DRIVER,filenameOUT);
    }
    for ( unsigned i = 0; i < fields.size(); ++i )
    {
      fields[i]->write(MED_DRIVER,filenameOUT);
      fields[i]->removeReference();
    }
    for ( unsigned i = 0; i < meshes.size(); ++i )
      meshes[i]->removeReference();
  }
  else if ( argc == 4 && strncmp(argv[3], "I", 1 )==0 )
  {
    // we read all variables into INT32 fields
    // (we need such fields for test_operation_fieldint)

    filenameIN  = argv[1] ;
    filenameOUT = argv[2] ;

    vector< FIELD_* > fields;

    // Read

    ENSIGHT_MED_RDONLY_DRIVER medDriver(filenameIN, fields);
    medDriver.open();
    medDriver.readFileStruct();
    medDriver.close();

    if ( fields.empty() ) {
      cout << "No fileds found in EnSight file " << filenameIN << endl;
      return -1;
    }
    // read-write the mesh
    const GMESH* mesh = fields[0]->getSupport()->getMesh();
    const_cast<GMESH*>( mesh )->read();
    mesh->write(MED_DRIVER, filenameOUT );

    // read-write fields
    for ( unsigned i = 0; i < fields.size(); ++i )
    {
      for ( int timeStep = 1; ; ++timeStep )
      {
        FIELD<int> *intF=new FIELD<int>;
        intF->setName( fields[i]->getName() );
        try
        {
          ENSIGHT_FIELD_RDONLY_DRIVER fieldDriver( filenameIN, intF, timeStep );
          fieldDriver.open();
          fieldDriver.read();
          fieldDriver.close();
          // replace zero values as theses fields are used for division
          int nbVals = intF->getValueLength();
          int* values = const_cast<int*>(intF->getValue());
          while ( nbVals-- ) {
            if ( values[nbVals]==0 )
              values[nbVals]= nbVals%5 + 1;
          }
        }
        catch ( const MEDEXCEPTION& ex)
        {
          intF->removeReference();
          intF=0;
          break;
        }
        intF->write(MED_DRIVER,filenameOUT);
        intF->removeReference();
      }
      fields[i]->removeReference();
    }
    mesh->removeReference();
  }
  else usage(argv[0]);

}

Here is the call graph for this function:

static void usage ( char *  name) [static]

Definition at line 41 of file ensight2med.cxx.

{
  cout << " ERROR ABOUT SYNTAX " << endl ;
  cout << "  " << name << " <input ensight file> <output med file> [I - to read into MED_INT32 fields]"
       << endl ;
  exit(-1);
}

Here is the caller graph for this function: