Back to index

salome-med  6.5.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
MEDMEM_ENSIGHT::_CaseFileDriver Class Reference

Reader/writer of EnSight Case file. More...

#include <MEDMEM_EnsightUtils.hxx>

Collaboration diagram for MEDMEM_ENSIGHT::_CaseFileDriver:
Collaboration graph
[legend]

List of all members.

Classes

struct  _FileSet
struct  _Model
struct  _TimeSet
struct  _Variable

Public Member Functions

 _CaseFileDriver (const string &fileName, const _CaseFileDriver_User *creator)
 Case file driver constructor.
 ~_CaseFileDriver ()
 Case file driver destructor.
void read () throw (MEDEXCEPTION)
 Read Case file.
int getNbMeshes () const
 sets all data necessary for meshDriver::read()
void setDataFileName (const int meshIndex, ENSIGHT_MESH_RDONLY_DRIVER *meshDriver)
 Sets all data necessary for meshDriver::read()
int getNbVariables () const
 Return nb of ensight variables.
int getNbVarSteps (const int variableIndex)
 return variable index by variable name, return 0 if none found
int getVariableIndex (const string &varName) const
 sets all data necessary for fieldDriver::read(), returns meshIndex
int setDataFileName (const int varIndex, const int stepIndex, ENSIGHT_FIELD_RDONLY_DRIVER *fieldDriver)
 sets all data necessary for fieldDriver::read()
void addMesh (const ENSIGHT_MESH_WRONLY_DRIVER *meshDriver)
 < add a mesh to the Case file
void addField (const ENSIGHT_FIELD_WRONLY_DRIVER *fieldDriver)
 write and set necessary data to added drivers
void write () throw (MEDEXCEPTION)
 writing Case file

Private Types

typedef std::map< std::string,
std::list
< ENSIGHT_FIELD_WRONLY_DRIVER * > > 
TFieldDriversByName

Private Member Functions

bool checkWasRead () const throw (MEDEXCEPTION)
 < throw if Case file has not been read else return false
int fixWildCardName (const int timeStep, const std::string &ts, const std::string &fs, std::string &fileName, std::string &time)
 replace '*' in file name if any and return index in file

Private Attributes

std::string _fileName
std::string _directory
EnSightFormat _format
_Model _model
std::map< int, _Variable_variables
 map order number to variable data
std::map< int, _TimeSet_timeSets
 map ts to time set data
std::map< int, _FileSet_fileSets
 map fs to file set data
const _CaseFileDriver_User * _user
 mesh/field driver
std::list
< ENSIGHT_MESH_WRONLY_DRIVER * > 
_meshDrivers
 added meshes
TFieldDriversByName _fieldDrivers
 added field drivers groupped by name
bool _blocked

Detailed Description

Reader/writer of EnSight Case file.

Apart from it's major job, it o assures cooperation of MED and Mesh/Field drivers so that the Case file created by MED driver is not overwritten by Mesh driver called by MED driver.

Definition at line 208 of file MEDMEM_EnsightUtils.hxx.


Class Documentation

struct MEDMEM_ENSIGHT::_CaseFileDriver::_FileSet

Definition at line 321 of file MEDMEM_EnsightUtils.hxx.

Collaboration diagram for MEDMEM_ENSIGHT::_CaseFileDriver::_FileSet:
Class Members
list< string > _fileIndex fi
list< int > _nbStepsInFile ns
int _number fs
struct MEDMEM_ENSIGHT::_CaseFileDriver::_Model

Definition at line 282 of file MEDMEM_EnsightUtils.hxx.

Collaboration diagram for MEDMEM_ENSIGHT::_CaseFileDriver::_Model:
Class Members
string _change_coords_only
string _fileName filename
string _fileSetNumber ts, fs
string _timeSetNumber
struct MEDMEM_ENSIGHT::_CaseFileDriver::_Variable

Definition at line 309 of file MEDMEM_EnsightUtils.hxx.

Collaboration diagram for MEDMEM_ENSIGHT::_CaseFileDriver::_Variable:
Class Members
string _fileNameOrData [cv]filename|Re_fn Im_fn freq|const_value(s)
string _fileSetNumber [ts], [fs]
string _name description
string _timeSetNumber
string _type constant|scalar|etc.

Member Typedef Documentation

typedef std::map<std::string, std::list< ENSIGHT_FIELD_WRONLY_DRIVER* > > MEDMEM_ENSIGHT::_CaseFileDriver::TFieldDriversByName [private]

Definition at line 351 of file MEDMEM_EnsightUtils.hxx.


Constructor & Destructor Documentation

MEDMEM_ENSIGHT::_CaseFileDriver::_CaseFileDriver ( const string &  fileName,
const _CaseFileDriver_User *  creator 
)

Case file driver constructor.

Definition at line 386 of file MEDMEM_EnsightUtils.cxx.

  : _fileName( fileName ), _directory("."), _user( creator )
{
  // Find out if the driver is blocked
  _blocked = isToIgnore( creator );
  if ( creator->getAccessMode() == MED_EN::RDONLY )
    _blocked = false;
  if ( !_blocked ) {
    // set directory
    string::size_type sepPos = _fileName.rfind( FILE_SEPARATOR );
    if ( sepPos != _fileName.npos ) {
      _directory = _fileName.substr( 0, sepPos );
    }
    _format = getEnSightFormatForWriting();
  }
}

Here is the call graph for this function:

Case file driver destructor.

Definition at line 410 of file MEDMEM_EnsightUtils.cxx.

{
  if ( !_blocked )
  {
    // to write case file again by same DRIVER
    unregister( _user );
    ((_CaseFileDriver_User*)_user)->_imed = 0;
  }
}

Here is the call graph for this function:


Member Function Documentation

void MEDMEM_ENSIGHT::_CaseFileDriver::addField ( const ENSIGHT_FIELD_WRONLY_DRIVER *  fieldDriver)

write and set necessary data to added drivers

add a field to the Case file

Definition at line 1333 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked )
    return;

  ENSIGHT_FIELD_WRONLY_DRIVER * fieldDriver =
    const_cast<ENSIGHT_FIELD_WRONLY_DRIVER*>( theFieldDriver );

  FIELD_* field = fieldDriver->getField();

  STRING problem;
  if ( field->getNumberOfValues() == 0 )
    problem << "getNumberOfValues() == 0";
  else if ( field->getGaussPresence() )
    problem << compatibilityPb("Gauss points are not supported by EnSight v8");
  else if ( !field->getSupport() )
    problem << "it has NULL support";

  switch ( field->getNumberOfComponents() ) {
  case 1:
  case 3:
  case 6:
  case 9: break; // ok, supported
  case 2:
    if ( const GMESH* mesh = field->getSupport()->getMesh() )
      if ( mesh->getSpaceDimension() == 2 )
        break; // we add one component to both mesh and field
  default:
    problem <<
      compatibilityPb(STRING("it has ") << field->getNumberOfComponents()
                      << " components but only 1,3,6 and 9 components are supported by EnSight");
  }
  if ( !problem.empty() )
    throw MEDEXCEPTION(STRING("Can't write field <") << field->getName() <<
                       "> to EnSight: " << problem);

  string fieldName = fieldDriver->getFieldName();
  if ( fieldName.empty() )
    fieldName = field->getName();
  if ( fieldName.empty() )
    fieldName = STRING("med_field_")<<_fieldDrivers.size();
  else { // replace illegal characters
    string::size_type pos = fieldName.find_first_of( ILLEGAL_FIELD_NAME_CHARACTERS );
    while ( pos != fieldName.npos ) {
      fieldName[ pos ] = '_';
      pos = fieldName.find_first_of( ILLEGAL_FIELD_NAME_CHARACTERS );
    }
  }
    
  _fieldDrivers[ fieldName ].push_back( fieldDriver );

  isToIgnore( fieldDriver ); // remeber
}

Here is the call graph for this function:

void MEDMEM_ENSIGHT::_CaseFileDriver::addMesh ( const ENSIGHT_MESH_WRONLY_DRIVER *  meshDriver)

< add a mesh to the Case file

add a mesh to the Case file

add a field to the Case file

Definition at line 1304 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked )
    return;

  _meshDrivers.push_back( const_cast<ENSIGHT_MESH_WRONLY_DRIVER*>( meshDriver ));

  if ( _format == ENSIGHT_6 )
  {
    const GMESH* mesh = _meshDrivers.back()->getMesh();
    if ( mesh->getNumberOfElements(MED_CELL, MED_POLYGON) > 0 ||
         mesh->getNumberOfElements(MED_FACE, MED_POLYGON) > 0 ||
         mesh->getNumberOfElements(MED_CELL, MED_POLYHEDRA) > 0 )
      throw MEDEXCEPTION
        ( compatibilityPb(STRING("Can't write mesh <") << mesh->getName() <<
                          "> since Ensight6 format does not support poly elements,"
                          " use Ensight Gold format instead: call "
                          "setEnSightFormatForWriting( ENSIGHT_GOLD )"));
  }

  isToIgnore( meshDriver ); // remeber
}

Here is the call graph for this function:

bool MEDMEM_ENSIGHT::_CaseFileDriver::checkWasRead ( ) const throw (MEDEXCEPTION) [private]

< throw if Case file has not been read else return false

Throws if case file has not been read else return false.

replace '*' in file name if any and return index in a file and time

Definition at line 1217 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _model._fileName.empty() )
    throw MEDEXCEPTION(STRING("Case file ") << _fileName << " has not been successfully read");
  return false;
}

Here is the caller graph for this function:

int MEDMEM_ENSIGHT::_CaseFileDriver::fixWildCardName ( const int  timeStep,
const std::string &  ts,
const std::string &  fs,
std::string &  fileName,
std::string &  time 
) [private]

replace '*' in file name if any and return index in file

Definition at line 1230 of file MEDMEM_EnsightUtils.cxx.

{
  int indexInFile = 0;
  string fileIndex;

  STRING badFile("Invalid Case file ");
  badFile << _fileName << "\n";

  if ( !fs.empty() ) { // single file mode
    const _FileSet & fileSet = _fileSets[ _ATOI( fs ) ];
    if ( fileSet._fileIndex.empty() ) { // no file continuation
      indexInFile = timeStep;
    }
    else {
      list<int>::const_iterator   nbStepsIt = fileSet._nbStepsInFile.begin();
      list<string>::const_iterator fIndexIt = fileSet._fileIndex.begin();
      int nbSteps = 0;
      for ( ; nbStepsIt != fileSet._nbStepsInFile.end(); ++nbStepsIt ) {
        if ( nbSteps + *nbStepsIt <= timeStep )
          break;
        nbSteps += *nbStepsIt;
      }
      if ( nbStepsIt == fileSet._nbStepsInFile.end() )
        throw MEDEXCEPTION(LOCALIZED(badFile << "Cant'f find file index for time step " <<
                                     timeStep << " in file set " << fs ));
      indexInFile = timeStep - nbSteps;
      fileIndex   = *fIndexIt;
    }
  }

  string head, queue;
  _ASCIIFileReader::split( fileName, head, queue, '*' );
  int indexWidth = fileName.size() - head.size() - queue.size();

  if ( indexWidth > 0 || !ts.empty() || timeStep > 1 ) {
    int tsId = ts.empty() ? 1 : _ATOI( ts );
    const _TimeSet& timeSet = _timeSets[ tsId ];
    if ( timeStep > (int)timeSet._times.size() )
      throw MEDEXCEPTION(LOCALIZED(badFile << "Cant'f find time for time step " <<
                                   timeStep << " in time set " << ts ));
    time = timeSet._times[ timeStep-1 ];
    if ( timeStep-1 < (int)timeSet._fileIndex.size()  )
      fileIndex = timeSet._fileIndex[ timeStep-1 ];
    if ( !indexInFile )
      indexInFile = 1;
  }
      
  if ( indexWidth > 0 )
  {
    if ( fileIndex.empty() ) {
      throw MEDEXCEPTION(LOCALIZED(badFile << "Can't find file index for time step " <<
                                   timeStep << " in time set <" << ts <<
                                   "> and file set <" << fs << ">"));
    }
    if ( indexWidth ==  (int)fileIndex.size() ) {
      fileName = head + fileIndex + queue;
    }
    else {
      fileName = (STRING(head) << setw(indexWidth) << setfill('0') << fileIndex << queue);
    }
  }
  return indexInFile;
}

Here is the call graph for this function:

Here is the caller graph for this function:

sets all data necessary for meshDriver::read()

return number of time steps of a model

Definition at line 939 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked || checkWasRead())
    return 0 ;
  if ( _model._timeSetNumber.empty() )
    return 1;
  int ts = _ATOI( _model._timeSetNumber );
  map< int, _TimeSet >::const_iterator its = _timeSets.find( ts );
  if ( its == _timeSets.end() )
    throw MEDEXCEPTION(STRING() << "Invalid format of Case file " << _fileName
                       << "\n Inexistent time set number of a model" );
  return its->second._times.size();
}

Here is the call graph for this function:

Return nb of ensight variables.

Definition at line 989 of file MEDMEM_EnsightUtils.cxx.

{
  return _variables.empty() ? 0 : _variables.rbegin()->first;
}
int MEDMEM_ENSIGHT::_CaseFileDriver::getNbVarSteps ( const int  variableIndex)

return variable index by variable name, return 0 if none found

return number of time steps of a variable

Definition at line 1000 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked || checkWasRead() )
    return 0;

  map< int, _Variable>::const_iterator ivar = _variables.find( variableIndex );
  if ( ivar == _variables.end() ) {
    // it can be index of real part of complex variable
    ivar = _variables.find( variableIndex+1 );
    if ( ivar == _variables.end() || !contains( "complex", ivar->second._type.c_str() )) {
      throw MEDEXCEPTION(STRING( "_CaseFileDriver::getNbVarSteps(): invalid variable index: ")
                         << variableIndex);
    }
  }
  const _Variable & var = ivar->second;
  if ( var._timeSetNumber.empty() )
    return 1;

  const _TimeSet & ts = _timeSets[ _ATOI( var._timeSetNumber)];
  return ts._times.size();
}

Here is the call graph for this function:

int MEDMEM_ENSIGHT::_CaseFileDriver::getVariableIndex ( const string &  varName) const

sets all data necessary for fieldDriver::read(), returns meshIndex

return variable index by variable name, return 0 if none found

Definition at line 1028 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked || checkWasRead() )
    return 0;

  map< int, _Variable>::const_iterator ivar = _variables.begin();
  for ( ; ivar != _variables.end(); ++ivar )
  {
    if ( ivar->second._name == varName ) {
      if ( contains( "complex", ivar->second._type.c_str() ))
        return ivar->first - 1; // real part of complex variable
      return ivar->first;
    }
  }
  // maybe varName is "<true_varName>_Im"
  size_t _ImBeg = varName.size() - 3;
  if ( varName[ _ImBeg + 0 ] == '_' &&
       varName[ _ImBeg + 1 ] == 'I' &&
       varName[ _ImBeg + 2 ] == 'm' )
  {
    int i = getVariableIndex( varName.substr( 0, _ImBeg ));
    return ( i ? i + 1 : i ); // getVariableIndex() returns index for a real part
  }
  return 0;
}

Here is the call graph for this function:

void MEDMEM_ENSIGHT::_CaseFileDriver::read ( void  ) throw (MEDEXCEPTION)

Read Case file.

Definition at line 429 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked )
    return;

  _ASCIIFileReader reader( _fileName );

  STRING badFile("Invalid Case file ");
  badFile << _fileName << "\n";

  list<_FileSet> fileSets;
  list<_TimeSet> timeSets;

  set<string> varNames; // to detect equal variable names

  string section = "_";
  int lineNb = 0;
  while ( !reader.eof() )
  {
    string line = reader.getLine();
    ++lineNb;

    // cut off comments
    string comment;
    reader.split( line, line, comment, '#');
    if ( line.empty() )
      READ_NEXT_LINE;

    string key, value; // parts of a line splited by column
    reader.split( line, key, value, ':');

    STRING errorMsg;

    // analyse not empty lines
    switch ( section[0] ) {
    case 'V': {
      // --------------------------------------------------------------------------------
      // VARIABLE

      string type, s, ts, fs;
      reader.split(key,type,s);
      int newVarIndex = _variables.empty() ? 1 : _variables.rbegin()->first + 1;

      if ( type == "scalar" || type == "vector" || type == "tensor" )
      {
        // scalar per node:        [ts] [fs] description filename
        // vector per node:        [ts] [fs] description filename
        // tensor symm per node:       [ts]  [fs]   description filename
        // tensor asym per node:       [ts]  [fs]   description filename
        // scalar per element:         [ts]  [fs]   description filename
        // vector per element:         [ts]  [fs]   description filename
        // tensor symm per element:    [ts]  [fs]   description filename
        // tensor asym per element:    [ts]  [fs]   description filename
        // scalar per measured node:   [ts]  [fs]   description filename
        // vector per measured node:   [ts]  [fs]   description filename
        list<string> parts;
        int nbParts = reader.split( value, parts );
        if ( nbParts < 2 ) {
          errorMsg << "invalid variable format:\n" << line;
          RAISE_EXCEPTION;
        }
        if ( contains( "per measured node", s.c_str() )) {
          //cout << "Skip not supported data type: " << key << endl;
          READ_NEXT_LINE;
        }
        list<string>::reverse_iterator p = parts.rbegin();
        _Variable& var      = _variables[newVarIndex];
        var._type           = key;
        var._fileNameOrData = *p++;
        var._name           = *p++;
        if ( nbParts == 3 ) {
          var._timeSetNumber = *p;
        }
        else if ( nbParts == 4 ) {
          var._fileSetNumber = *p++;
          var._timeSetNumber = *p;
        }
        varNames.insert( var._name );
        READ_NEXT_LINE;
      }
      else if ( type == "constant" )
      {
        // constant per case:      [ts]      description const_value(s)
        // constant per case file: [ts]      description cvfilename
        reader.split(value,s,value);
        if ( reader.isDigit( s )) {
          ts = s;
          reader.split(value,s,value);
        }
        _Variable& var      = _variables[newVarIndex];
        var._type           = key;
        var._name           = s;
        var._fileNameOrData = value;
        var._timeSetNumber  = ts;
        if ( var._name.empty() || var._fileNameOrData.empty() ) {
          errorMsg << "invalid variable format:\n" << line;
          RAISE_EXCEPTION;
        }
        varNames.insert( var._name );
        READ_NEXT_LINE;
      }
      else if ( type == "complex" )
      {
        // complex scalar per node:    [ts]  [fs]   description Re_fn   Im_fn freq
        // complex vector per node:    [ts]  [fs]   description Re_fn   Im_fn freq
        // complex scalar per element:    [ts] [fs] description Re_fn   Im_fn freq
        // complex vector per element:    [ts] [fs] description Re_fn   Im_fn freq
        reader.split(value,s,value);
        if ( reader.isDigit( s )) {
          ts = s;
          reader.split(value,s,value);
          if ( reader.isDigit( s )) {
            fs = s;
            reader.split(value,s,value);
          }
        }
        list<string> parts;
        int nbParts = reader.split( value, parts );
        if ( nbParts < 3 ) {
          errorMsg << "invalid variable format:\n" << line;
          RAISE_EXCEPTION;
        }
        // a variable contains two fields. We leave one slot in _variables empty
        // in order to have last key in _variables equal to number of fields.
        // Variable index equal to missing slot key corresponds to real part (Re_fn)
        _Variable& var     = _variables[++newVarIndex];
        var._type          = key;
        var._name          = s;
        var._timeSetNumber = ts;
        var._fileSetNumber = fs;
        var._fileNameOrData = value;
        varNames.insert( var._name );
        READ_NEXT_LINE;
      }
      break;
    }
    case 'T': {
      // --------------------------------------------------------------------------------
      // TIME
      //    time set:              ts [description]
      //    number of steps:       ns
      //    filename start number: fs
      //    filename increment:    fi
      //    time values:           time_1 time_2 .... time_ns
      // or
      //    time set:              ts [description]
      //    number of steps:       ns
      //    filename numbers:      fn
      //    time values:           time_1 time_2 .... time_ns
      // or
      //    time set:              ts [description]
      //    number of steps:       ns
      //    filename numbers file: fnfilename
      //    time values file:      tvfilename
      _TimeSet* timeSet = timeSets.empty() ? 0 : & timeSets.back();
      // ---------------------------------------------------------
      if ( key == "time set" )
      {
        int nb = _ATOI( value );
        if ( nb < 1 ) {
          errorMsg << "Invalid time set number: " << value;
          RAISE_EXCEPTION;
        }
        timeSets.push_back( _TimeSet() );
        timeSets.back()._number = nb;
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "number of steps" )
      {
        if ( !timeSet || !timeSet->_times.empty() ) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        int nbSteps = _ATOI( value );
        if ( nbSteps < 1 ) {
          errorMsg << "invalid number of steps: " << value;
          RAISE_EXCEPTION;
        }
        timeSet->_times.resize( nbSteps );
        timeSet->_fileIndex.resize( nbSteps );
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "filename start number" )
      {
        if ( !timeSet || timeSet->_fileIndex.empty() ) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        if ( !reader.isDigit( value )) {
          errorMsg << "invalid " << line;
          RAISE_EXCEPTION;
        }
        timeSet->_fileIndex[0] = value;
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "filename increment" ) {
        int incr = _ATOI( value );
        if ( incr == 0 ) {
          errorMsg << "invalid " << line;
          RAISE_EXCEPTION;
        }
        if ( !timeSet ||
             timeSet->_fileIndex.empty() ||
             timeSet->_fileIndex[0].empty() ) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        int index = incr + _ATOI( timeSet->_fileIndex[0] );
        int nbSteps = timeSet->_fileIndex.size();
        for ( int i = 1; i < nbSteps; ++i, index += incr )
          timeSet->_fileIndex[i] = STRING( index );
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "time values" )
      {
        if ( !timeSet || timeSet->_times.empty() ) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        list<string> times;
        int i, nbTimes = reader.split( value, times );
        list<string>::iterator t = times.begin();
        for ( i = 0; i < nbTimes; ++i, ++t )
          timeSet->_times[i] = *t;
        while ( nbTimes != (int)timeSet->_times.size() ) {
          value = reader.getLine();
          ++lineNb;
          nbTimes += reader.split( value, times );
          for (t = times.begin(); i < nbTimes; ++i, ++t ) {
            if ( ! reader.isDigit( *t, /*real=*/true ))
              break;
            timeSet->_times[i] = *t;
          }
        }
        if ( nbTimes != (int)timeSet->_times.size() ) {
          errorMsg << "incorrect number of times in time set " << timeSet->_number;
          RAISE_EXCEPTION;
        }
        for ( i = 1; i < nbTimes; ++i )
          if ( _ATOF( timeSet->_times[ i ]) <= _ATOF(timeSet->_times[ i-1 ] ))
            break;
        if ( i < nbTimes ) { // break from the previous loop occured
          errorMsg << "time values are not in ascending order in time set " << timeSet->_number;
          RAISE_EXCEPTION;
        }
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "filename numbers" )
      {
        if ( !timeSet || timeSet->_fileIndex.empty()) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        list<string> numbers;
        int i, nb = reader.split( value, numbers );
        int nbFiles = timeSet->_fileIndex.size();
        timeSet->_fileIndex.insert(timeSet->_fileIndex.begin(), numbers.begin(), numbers.end() );
        while ( nb != nbFiles ) {
          value = reader.getLine();
          ++lineNb;
          i = nb;
          nb += reader.split( value, numbers );
          list<string>::iterator n = numbers.begin();
          for ( ; i < nb; ++i, ++n ) {
            if ( ! reader.isDigit( *n ))
              break;
            timeSet->_fileIndex[i] = *n;
          }
        }
        if ( nb != nbFiles ) {
          errorMsg << "incorrect number of " << key << " in time set " << timeSet->_number;
          RAISE_EXCEPTION;
        }
        READ_NEXT_LINE;
      }
      // ---------------------------------------------------------
      if ( key == "filename numbers file" ||
           key == "time values file" )
      {
        if ( !timeSet || timeSet->_fileIndex.empty()) {
          errorMsg << "Unexpected command: " << key;
          RAISE_EXCEPTION;
        }
        string fileName = _directory + FILE_SEPARATOR + value;
        if ( !_user->canOpenFile( fileName, RDONLY )) {
          errorMsg << "Can not open file " << fileName;
          RAISE_EXCEPTION;
        }
        _ASCIIFileReader file( fileName );
        list<string> numbers;
        while ( !file.eof() )
          numbers.push_back( file.getWord() );
        int nb = numbers.size();
        if ( nb != (int)timeSet->_times.size() ) {
          errorMsg << "incorrect number of values in file " << value;
          RAISE_EXCEPTION;
        }
        if ( key[0] == 'f' )
          timeSet->_fileIndex.assign( numbers.begin(), numbers.end() );
        else
          timeSet->_times.assign( numbers.begin(), numbers.end() );
        READ_NEXT_LINE;
      }
      break;
    }
    case 'F': {
      if ( section[1] == 'I' ) {
        // --------------------------------------------------------------------------------
        // FILE
        // file set:               fs
        // filename index:         fi # Note: only used when data continues in other files
        // number of steps:        ns
        if ( key == "file set" ) {
          int nb = _ATOI( value );
          if ( nb < 1 ) {
            errorMsg << "Invalid file set number: " << value;
          }
          else {
            fileSets.push_back( _FileSet() );
            fileSets.back()._number = nb;
            READ_NEXT_LINE;
          }
        }
        else if ( key == "filename index" ) {
          if ( fileSets.empty() ) {
            errorMsg << "'filename index' before 'file set'";
          }
          else if ( !value.empty() ) {
            fileSets.back()._fileIndex.push_back( value );
            READ_NEXT_LINE;
          }
        }
        else if ( key == "number of steps" ) {
          if ( fileSets.empty() ) {
            errorMsg << "'number of steps' before 'file set'";
          }
          else if ( value.empty() ) {
            errorMsg << "number of steps omitted: " << line;
          }
          else if ( !reader.isDigit( value )) {
            errorMsg << "invalid number of steps: " << value;
          }
          else {
            int n = _ATOI( value );
            if ( n < 1 ) {
              errorMsg << "invalid number of steps: " << value;
              RAISE_EXCEPTION;
            }
            fileSets.back()._nbStepsInFile.push_back( n );
            READ_NEXT_LINE;
          }
        }
      }
      else {
        // --------------------------------------------------------------------------------
        // FORMAT
        // type:  ensight
        if ( key != "type" ) {
          errorMsg << "unexpected info in section " << section << ":\n" << line;
          RAISE_EXCEPTION;
        }
        else {
          if ( value == "ensight gold" ) {
            _format = ENSIGHT_GOLD;
          }
          else if ( value == "ensight" ) {
            _format = ENSIGHT_6;
          }
          else {
            errorMsg << "Unsupported EnSight format: " << value;
            RAISE_EXCEPTION;
          }
          section = "_";
          READ_NEXT_LINE;
        }
      }
      break;
    }
    case 'G': {
      // --------------------------------------------------------------------------------
      // GEOMETRY
      // model:    [ts] [fs] filename [change_coords_only]
      // measured: [ts] [fs] filename [change_coords_only]
      // match:              filename
      // boundary:           filename
      // rigid_body:         filename
      if ( key == "measured" || key == "match" || key == "boundary" || key == "rigid_body") {
        //errorMsg << key << " geometry not supported";
        cout << "Warning: " << key << " geomerty not supported" << endl;
        READ_NEXT_LINE;
      }
      else if ( key == "model" ) {
        list<string> parts;
        reader.split( value, parts );
        list<string>::reverse_iterator s = parts.rbegin();
        for ( ; s != parts.rend(); ++s )
        {
          if ( *s == "change_coords_only" )
            _model._change_coords_only = *s;
          else if ( _model._fileName.empty() )
            _model._fileName = *s;
          else if ( _model._fileSetNumber.empty() )
            _model._fileSetNumber = *s;
          else
            _model._timeSetNumber = *s;
        }
        if ( _model._timeSetNumber.empty() && !_model._fileSetNumber.empty() )
          swap( _model._timeSetNumber, _model._fileSetNumber );
        if ( _model._fileName.empty() ) {
          errorMsg << "invalid model: " << value;
          RAISE_EXCEPTION;
        }
        READ_NEXT_LINE;
      }
      break;
    }
    case 'M': { // MATERIAL
      string keyWord1;
      reader.split(key,keyWord1,key);
      if ( keyWord1 == "material" || keyWord1 == "species" )
        READ_NEXT_LINE;
      break;
    }
    } // end switch (section[0])

    if ( !errorMsg.empty() ) {
      throw MEDEXCEPTION(STRING("Invalid Case file ") << _fileName
                         << ":" << lineNb << "\n" << errorMsg );
    }

    // we are here if a line was not recognized to belong to a current section
    if ( line == "FORMAT"   ||
         line == "GEOMETRY" ||
         line == "VARIABLE" ||
         line == "TIME"     ||
         line == "FILE"     ||
         line == "MATERIAL")
      section = line;
    else
      throw MEDEXCEPTION(STRING() << "Invalid format of Case file " << _fileName
                         << "\nwrong line: " << line );
  }

  if ( _model._fileName.empty() )
    throw MEDEXCEPTION(badFile << "no supported geometry information found" );

  // store time sets and file sets
  list<_FileSet>::iterator fs = fileSets.begin();
  for ( ; fs != fileSets.end(); ++fs ) {
    if ( fs->_nbStepsInFile.size() > 1 && fs->_fileIndex.empty() )
      throw MEDEXCEPTION(badFile << "missing file indices in a file set " << fs->_number );
    _fileSets[ fs->_number ] = *fs;
  }
  list<_TimeSet>::iterator ts = timeSets.begin();
  for ( ; ts != timeSets.end(); ++ts )
    _timeSets[ ts->_number ] = *ts;

  // check validity of ts and fs

  if ( !isValidIndex( _model._timeSetNumber, _timeSets ))
    throw MEDEXCEPTION(badFile << "bad time set index:" << _model._timeSetNumber );
  if ( !isValidIndex( _model._fileSetNumber, _fileSets ))
    throw MEDEXCEPTION(badFile << "bad file set index:" << _model._timeSetNumber );

  map< int, _Variable>::iterator ivars = _variables.begin();
  for ( ; ivars != _variables.end(); ++ivars ) {
    if ( !isValidIndex( ivars->second._timeSetNumber, _timeSets ))
      throw MEDEXCEPTION(badFile << "bad time set index:" << ivars->second._timeSetNumber );
    if ( !isValidIndex( ivars->second._fileSetNumber, _fileSets ))
      throw MEDEXCEPTION(badFile << "bad file set index:" << ivars->second._fileSetNumber );
  }

  // check uniqueness of variable names
  if ( varNames.size() != _variables.size() )
    cout << badFile <<
      "Warning: there are different fields with equal names, you may have problems!" << endl;
//     throw MEDEXCEPTION(badFile );

  // As variable does not refer to time set if there is one step (issue 0020113),
  // we try to restore the reference

  for ( ivars = _variables.begin(); ivars != _variables.end(); ++ivars ) {
    _Variable & var = ivars->second;
    if ( var._timeSetNumber.empty() )
    {
      // try to find time set with id equal to variable order number
      map< int, _TimeSet >::iterator iTs = _timeSets.find( ivars->first );
      if ( iTs != _timeSets.end() && iTs->second._times.size() == 1 )
        var._timeSetNumber = STRING( iTs->second._number );
      else {
        // find any time set with 1 time value
        for ( iTs = _timeSets.begin(); iTs != _timeSets.end(); ++iTs )
          if ( iTs->second._times.size() == 1 )
            var._timeSetNumber = STRING( iTs->second._number ); 
      }
    }
  }
}

Here is the call graph for this function:

void MEDMEM_ENSIGHT::_CaseFileDriver::setDataFileName ( const int  meshIndex,
ENSIGHT_MESH_RDONLY_DRIVER *  meshDriver 
)

Sets all data necessary for meshDriver::read()

Parameters:
meshIndex- time step index
meshDriver- driver

Definition at line 961 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked || checkWasRead())
    return;
  isToIgnore( meshDriver ); // remeber

  meshDriver->_dataFileName    = _directory + FILE_SEPARATOR + _model._fileName;
  meshDriver->_indexInDataFile = fixWildCardName( meshIndex,
                                                  _model._timeSetNumber,
                                                  _model._fileSetNumber,
                                                  meshDriver->_dataFileName,
                                                  meshDriver->_time);
  meshDriver->_isGoldFormat    = ( _format == ENSIGHT_GOLD );
  meshDriver->_transientMode   = ( !_model._timeSetNumber.empty() );
  meshDriver->_singleFileMode  = ( !_fileSets.empty() );
  meshDriver->_imedMapKey      = STRING(_fileName)<<":"<<meshIndex;

  GMESH* ptrMesh = meshDriver->getMesh();
  ptrMesh->setName(STRING("EnSight mesh ") << meshIndex);
}

Here is the call graph for this function:

int MEDMEM_ENSIGHT::_CaseFileDriver::setDataFileName ( const int  varIndex,
const int  stepIndex,
ENSIGHT_FIELD_RDONLY_DRIVER *  fieldDriver 
)

sets all data necessary for fieldDriver::read()

Definition at line 1060 of file MEDMEM_EnsightUtils.cxx.

{
  const char* LOC = "_CaseFileDriver::setDataFileName(): ";
  if ( _blocked || checkWasRead() )
    return 0;
  isToIgnore( fieldDriver ); // remeber

  map< int, _Variable>::iterator ivar = _variables.find( varIndex );
  if ( ivar == _variables.end() ) {
    // it can be index of real part of complex variable
    ivar = _variables.find( varIndex+1 );
    if ( ivar == _variables.end() || !contains( "complex", ivar->second._type.c_str() ))
      throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "invalid variable index: " << varIndex));
  }
  _Variable & var = ivar->second;

  const bool isComplex = contains( "complex", var._type.c_str() );
  const bool isImaginary = ( isComplex && varIndex == ivar->first );

  // complex scalar per element:    [ts] [fs] description Re_fn   Im_fn freq
  // complex scalar per node:       [ts] [fs] description Re_fn   Im_fn freq
  // complex vector per element:    [ts] [fs] description Re_fn   Im_fn freq
  // complex vector per node:       [ts] [fs] description Re_fn   Im_fn freq
  // constant per case file:        [ts]      description cvfilename
  // constant per case:             [ts]      description const_value(s)
  // scalar per element:            [ts] [fs] description filename
  // scalar per measured node:      [ts] [fs] description filename
  // scalar per node:               [ts] [fs] description filename
  // tensor asym per element:       [ts] [fs] description filename
  // tensor asym per node:          [ts] [fs] description filename
  // tensor symm per element:       [ts] [fs] description filename
  // tensor symm per node:          [ts] [fs] description filename
  // vector per element:            [ts] [fs] description filename
  // vector per measured node:      [ts] [fs] description filename
  // vector per node:               [ts] [fs] description filename

  FIELD_* field = fieldDriver->getField();

  // field name
  if ( field->getName().empty() ) {
    if ( isImaginary )
      field->setName( var._name + "_Im" );
    else
      field->setName( var._name );
  }
  // nb of components
  list<string> type_parts;
  _ASCIIFileReader::split( var._type, type_parts );
  string type1 = type_parts.front(); type_parts.pop_front();
  string type2 = type_parts.front(); type_parts.pop_front();
  int nbComponents = 1;
  if ( type1 == "vector" || type2 == "vector" )
    nbComponents = 3;
  else if ( type1 == "tensor" )
    nbComponents = ( type2 == "symm" ) ? 6 : 9;
  field->setNumberOfComponents( nbComponents );

  // component names
  vector<string> compNames( nbComponents );
  switch ( nbComponents ) {
  case 1:
    compNames[0] = type1;
    break;
  case 3: {
    const char* xyz[3] = { "X comp","Y comp","Z comp" };
    compNames.assign(xyz, xyz+3);
    break;
  }
  case 6: {
    const char* xyz[6] = { "11 comp", "22 comp", "33 comp","12 comp", "13 comp", "23 comp" };
    compNames.assign(xyz, xyz+6);
    break;
  }
  case 9: {
    const char* xyz[9] = { "11 comp", "12 comp", "13 comp", "21 comp", "22 comp", "23 comp",
                           "31 comp", "32 comp", "33 comp" };
    compNames.assign(xyz, xyz+9);
    break;
  }}
  field->setComponentsNames( & compNames[0] );

  // componet units
  vector<UNIT> units( nbComponents );
  vector<string> unitS( nbComponents ), descriptions( nbComponents );
  field->setComponentsUnits(&units[0]);
  field->setMEDComponentsUnits(&unitS[0]);
  field->setComponentsDescriptions(&descriptions[0]);

  // support type
  SUPPORT* sup = const_cast<SUPPORT*>( field->getSupport());
  if ( !sup ) {
    field->setSupport( sup = new SUPPORT );
    sup->removeReference(); // sup belongs to field
  }
  medEntityMesh entity = ( type_parts.back() == "node" ) ? MED_NODE : MED_CELL;
  sup->setEntity( entity );

  // data file name etc.
  list<string> fileData_parts;
  _ASCIIFileReader::split( var._fileNameOrData, fileData_parts );
  if ( isImaginary )
    fieldDriver->_dataFileName  = _directory + FILE_SEPARATOR + *(++fileData_parts.begin());
  else
    fieldDriver->_dataFileName  = _directory + FILE_SEPARATOR + fileData_parts.front();
  fieldDriver->_indexInDataFile = fixWildCardName( stepIndex,
                                                   var._timeSetNumber,
                                                   var._fileSetNumber,
                                                   fieldDriver->_dataFileName,
                                                   fieldDriver->_time);
  fieldDriver->_isGoldFormat    = ( _format == ENSIGHT_GOLD );
  fieldDriver->_transientMode   = ( !var._timeSetNumber.empty() );
  fieldDriver->_singleFileMode  = ( !_fileSets.empty() );

  if ( type1 == "constant" ) {
    if ( type_parts.back() == "file" ) {
      // append constant values from cvfilename to fileData_parts
      string cvfilename = _directory + FILE_SEPARATOR + fileData_parts.back();
      _ASCIIFileReader cvfile( cvfilename );
      fileData_parts.pop_back();
      while ( !cvfile.eof() )
        fileData_parts.push_back( cvfile.getWord() );
    }
    if ( (int)fileData_parts.size() < stepIndex )
      throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "can't find value for step " << stepIndex
                                   << " of " << var._type << " " << var._name));
    list<string>::iterator value = fileData_parts.begin();
    advance( value, stepIndex-1 );
    fieldDriver->setConstantValue( *value );
  }

  // mesh data
  int meshIndex = 1;
  if ( _model._fileName.find('*') != _model._fileName.npos ) {
    _TimeSet& ts = _timeSets[ _ATOI( _model._timeSetNumber )];
    vector<string>::iterator t = find( ts._times.begin(), ts._times.end(), fieldDriver->_time );
    if ( t != ts._times.end() )
      meshIndex += distance( ts._times.begin(), t );
  }
  fieldDriver->_imedMapKey = STRING(_fileName) << ":" << meshIndex;

  // time
  if ( fieldDriver->_transientMode ) {
    field->setTime( _ATOF( fieldDriver->_time ));
    //field->setOrderNumber( stepIndex );
    field->setIterationNumber( stepIndex );
  }
  return meshIndex;
}

Here is the call graph for this function:

void MEDMEM_ENSIGHT::_CaseFileDriver::write ( void  ) throw (MEDEXCEPTION)

writing Case file

Definition at line 1393 of file MEDMEM_EnsightUtils.cxx.

{
  if ( _blocked )
    return;

  // Make case file data from added drivers

  bool dataIsRead = !_model._fileName.empty();
  if ( !dataIsRead && _meshDrivers.empty() )
    throw MEDEXCEPTION("no mesh to write into Case file");

  const int defaultNbDigits = 3; // in file index

  string path, name, ext;
  _ASCIIFileReader::split( _fileName, path, name, FILE_SEPARATOR, /*fromBack=*/true);
  _ASCIIFileReader::split( name, name, ext, '.', /*fromBack=*/true);
  if ( name.empty())
    name = ext; // _fileName: "path/.name"

  list<ENSIGHT_MESH_WRONLY_DRIVER*>::iterator mDrv = _meshDrivers.begin();
  TFieldDriversByName::iterator               fDrv = _fieldDrivers.begin();

  map< string, string > fileToRenameTo;

  int i, nbOldMeshes = 0, nbNewMeshes = _meshDrivers.size();

  if ( nbNewMeshes > 0 )
  {
    if ( dataIsRead )
    {
      // A mesh is going to be added into an existing case file.
      // Check that number of parts is same in the existing model
      // and in the added ones
      string geoFileName     = _directory + FILE_SEPARATOR + _model._fileName;
      string realGeoFileName = geoFileName, time;
      fixWildCardName( 1,
                       _model._timeSetNumber,
                       _model._fileSetNumber,
                       realGeoFileName,
                       time);
      int nbParts = ENSIGHT_MESH_RDONLY_DRIVER::countParts(realGeoFileName,
                                                           !_model._fileSetNumber.empty());
      for ( ; mDrv != _meshDrivers.end(); ++mDrv )
      {
        int nbNewParts = (*mDrv)->nbPartsToWrite();
        if ( nbParts != nbNewParts )
          throw MEDEXCEPTION(compatibilityPb("Can't add a mesh ") << (*mDrv)->getMesh()->getName()
                             << "to " << _fileName << " as number of parts in the file "
                             "differs from number of parts going to be written");
      }
      if ( !_model._timeSetNumber.empty() && !_variables.empty() ) {
        // Make time set of the model independent of that of variables as
        // the number of time steps is apparently becoming different
        map< int, _Variable>::iterator ivar = _variables.begin();
        for ( ; ivar != _variables.end(); ++ivar ) {
          if ( ivar->second._timeSetNumber == _model._timeSetNumber ) {
            int tsNum    = _timeSets.rbegin()->first + 1;
            _TimeSet& ts = _timeSets[ tsNum ];
            ts._number   = tsNum;
            ts           = _timeSets[ _ATOI( _model._timeSetNumber )];
            _model._timeSetNumber = STRING(tsNum);
            break;
          }
        }
      }
      string::size_type digitPos = _model._fileName.find('*');
      bool isSeveralFiles = ( digitPos != _model._fileName.npos );
      int nbDigits = defaultNbDigits;
      if ( isSeveralFiles ) {
        nbDigits = 1;
        while ( _model._fileName[ ++digitPos ] == '*' )
          nbDigits++;
      }
      // Update time set and file set of the model 
      int nbMeshes;
      if ( _model._timeSetNumber.empty() ) {
        // old model is static, create a time set
        nbMeshes = nbNewMeshes + 1;
        int tsNum    = _timeSets.empty() ? 1 : _timeSets.rbegin()->first + 1;
        _TimeSet& ts = _timeSets[ tsNum ];
        ts._number   = tsNum;
        _model._timeSetNumber = STRING(tsNum);
        // fill the new time set
        ts._fileIndex.resize( nbMeshes );
        ts._times.resize    ( nbMeshes );
        for ( i = 0; i < nbMeshes; ++i ) {
          ts._fileIndex[ i ] = (STRING() << setw(nbDigits) << setfill('0') << i);
          ts._times    [ i ] = STRING(i);
        }
        // not to create equal time sets
        map< int, _TimeSet >::iterator its, tsEnd = _timeSets.end();
        for ( --tsEnd, its = _timeSets.begin(); its != tsEnd; ++its ) {
          if ( ts == its->second ) {
            _model._timeSetNumber = STRING( its->first );
            _timeSets.erase( tsEnd );
            break;
          }
        }
      }
      else {
        // old model is transient, add times and file indices for new meshes
        _TimeSet& ts = _timeSets[ _ATOI( _model._timeSetNumber )];
        nbOldMeshes = ts._times.size();
        nbMeshes = nbNewMeshes + nbOldMeshes;
        ts._times.resize( nbMeshes );
        double time = 1. + _ATOF( ts._times[ nbOldMeshes-1 ] );
        for ( i = nbOldMeshes; i < nbMeshes; ++i, time+=1. )
          ts._times[ i ] = STRING( time );
        if ( _model._fileSetNumber.empty() ) { // multi-file mode
          ts._fileIndex.resize( nbMeshes, string(nbDigits,'0'));
          i = nbOldMeshes;
          int index = 1 + _ATOI( ts._fileIndex[ i-1 ] );
          for ( ; i < nbMeshes; ++i, ++index )
            ts._fileIndex[ i ] = (STRING() << setw(nbDigits) << setfill('0') << index);
        }
        else { // single-file mode
          _FileSet & fs = _fileSets[ _ATOI( _model._fileSetNumber )];
          for ( i = 0; i < nbNewMeshes; ++i )
            fs._nbStepsInFile.push_back( 1 );
          int index = 1;
          if ( fs._fileIndex.empty() )
            fs._fileIndex.push_back(string(nbDigits,'0'));
          else
            index += _ATOI( fs._fileIndex.back() );
          for ( i = fs._fileIndex.size(); i < nbMeshes; ++i, ++index )
            ts._fileIndex[ i ] = (STRING() << setw(3) << setfill('0') << index);
        }
      }
      // file of the old model is to be renamed
      if ( !isSeveralFiles ) {
        _model._fileName += string(nbDigits,'*');
        fileToRenameTo[ geoFileName ] = geoFileName + string(nbDigits,'0');
      }
    }
    else if ( nbNewMeshes > 1 )
    {
      // Store meshes into a new case file: create a time set
      int tsNum    = _timeSets.empty() ? 1 : _timeSets.rbegin()->first + 1;
      _TimeSet& ts = _timeSets[ tsNum ];
      ts._number   = tsNum;
      _model._timeSetNumber = STRING(tsNum);
      _model._fileName      = name + ".geo" + string(defaultNbDigits, '*');
      // fill the new time set
      ts._fileIndex.resize( nbNewMeshes );
      ts._times.resize    ( nbNewMeshes );
      for ( i = 0; i < nbNewMeshes; ++i ) {
        ts._fileIndex[ i ] = (STRING() << setw(defaultNbDigits) << setfill('0') << i);
        ts._times    [ i ] = STRING(i);
      }
    }
    else {
      // One mesh in a new file
      _model._fileName = name + ".geo";
    }

    // Set data to mesh drivers
    i = nbOldMeshes + 1;
    for ( mDrv = _meshDrivers.begin(); mDrv != _meshDrivers.end(); ++mDrv, ++i )
    {
      _CaseFileDriver_User* meshDriver = (*mDrv);
      meshDriver->_dataFileName    = _directory + FILE_SEPARATOR + _model._fileName;
      meshDriver->_indexInDataFile = fixWildCardName( i,
                                                      _model._timeSetNumber,
                                                      _model._fileSetNumber,
                                                      meshDriver->_dataFileName,
                                                      meshDriver->_time);
      meshDriver->_isGoldFormat    = ( _format == ENSIGHT_GOLD );
      meshDriver->_transientMode   = ( meshDriver->_indexInDataFile > 0 );
      meshDriver->_singleFileMode  = ( !_fileSets.empty() );
      meshDriver->_imedMapKey      = STRING(_fileName)<<":"<<i;
    }
  }

  typedef map< double, ENSIGHT_FIELD_WRONLY_DRIVER* > FDriverByDouble;

  //bool isVarsRead = ( !_variables.empty() );
  for ( ; fDrv != _fieldDrivers.end(); ++fDrv )
  {
    const string &                       fieldName = fDrv->first;
    list< ENSIGHT_FIELD_WRONLY_DRIVER* > & drivers = fDrv->second;

    int nbNewSteps = drivers.size();

    // find out by which parameter fields differ and sort them by the parameter
    FDriverByDouble timeMap, iterMap, orderMap;
    list< ENSIGHT_FIELD_WRONLY_DRIVER* >::iterator drv;
    for ( drv = drivers.begin(); drv != drivers.end(); ++drv ) {
      FIELD_* field = (*drv)->getField();
      double time = field->getTime();
      int    iter = field->getIterationNumber();
      int    ordr = field->getOrderNumber();
      timeMap.insert  ( make_pair( time, *drv ));
      iterMap.insert  ( make_pair( iter, *drv ));
      orderMap.insert ( make_pair( ordr, *drv ));
    }
    FDriverByDouble * sortedDrivers;
    FDriverByDouble::iterator tDrv;
    if ( (int)timeMap.size() == nbNewSteps )
      sortedDrivers = & timeMap;
    else if ( (int)iterMap.size() == nbNewSteps )
      sortedDrivers = & iterMap;
    else if ( (int)orderMap.size() == nbNewSteps )
      sortedDrivers = & orderMap;
    else {
      timeMap.clear();
      sortedDrivers = & timeMap;
      for ( drv = drivers.begin(); drv != drivers.end(); ++drv ) {
        double time = (*drv)->getField()->getTime();
        if ( ! timeMap.insert( make_pair( time, *drv )).second )
          timeMap.insert( make_pair( timeMap.rbegin()->first + 1., *drv ));
      }
    }

//     if ( isVarsRead ) {
//       int iVar = getVariableIndex( fieldName );
//       if ( iVar > 0 ) {
//         // A variable with fieldName already exists,
//         // add more time steps to it
//         _Variable& var = _variables[ iVar ];
//         _TimeSet& ts = _timeSets[ _ATOI( var._timeSetNumber )];
//         int nbOldSteps = ts._times.size();
//       }
//     }
    FIELD_* field = drivers.front()->getField();
    int varNum = _variables.size() + 1;
    _Variable& var = _variables[ varNum ];
    var._name = fieldName;
    switch ( field->getNumberOfComponents() ) {
    case 1: var._type = "scalar "; break;
    case 2: var._type = "vector "; break;// we add one component to a vector in 2d space
    case 3: var._type = "vector "; break;
    case 6: var._type = "tensor symm "; break;
    case 9: var._type = "tensor asym "; break;
    }
    if ( field->getSupport()->getEntity() == MED_NODE )
      var._type += "per node";
    else
      var._type += "per element";
    var._fileNameOrData = name + "." + fieldName;

    // always create Time set to store time
    int nbDigits = defaultNbDigits;
    int tsNum = _timeSets.empty() ? 1 : _timeSets.rbegin()->first + 1;
    var._timeSetNumber = STRING( tsNum );
    _TimeSet & ts = _timeSets[ tsNum ];
    ts._number    = tsNum;
    ts._fileIndex.resize( nbNewSteps );
    ts._times.resize    ( nbNewSteps );
    tDrv = sortedDrivers->begin();
    for ( i = 0; tDrv != sortedDrivers->end(); ++tDrv, ++i ) {
      ts._times    [ i ] = (STRING( tDrv->first ));
      ts._fileIndex[ i ] = (STRING() << setw(nbDigits) << setfill('0') << i);
    }
    if ( nbNewSteps > 1 )
      var._fileNameOrData += string( nbDigits, '*' );
    else
      ts._fileIndex.clear();
    // not to create equal time sets
    map< int, _TimeSet >::iterator its, tsEnd = _timeSets.end();
    for ( --tsEnd, its = _timeSets.begin(); its != tsEnd; ++its ) {
      if ( ts == its->second ) {
        tsNum = its->first;
        var._timeSetNumber = STRING( tsNum );
        _timeSets.erase( tsEnd );
        break;
      }
    }
    tDrv = sortedDrivers->begin();
    for ( i = 1; tDrv != sortedDrivers->end(); ++tDrv, ++i ) {
      _CaseFileDriver_User* fieldDriver = tDrv->second;
      fieldDriver->_dataFileName    = _directory + FILE_SEPARATOR + var._fileNameOrData;
      fieldDriver->_indexInDataFile = fixWildCardName( i,
                                                       var._timeSetNumber,
                                                       var._fileSetNumber,
                                                       fieldDriver->_dataFileName,
                                                       fieldDriver->_time);
      fieldDriver->_isGoldFormat    = ( _format == ENSIGHT_GOLD );
      fieldDriver->_transientMode   = ( fieldDriver->_indexInDataFile > 0 );
      fieldDriver->_singleFileMode  = ( !_fileSets.empty() );
    }

    // do not refer to time set if there is one step (issue 0020113)
    if ( nbNewSteps == 1 )
      var._timeSetNumber = "";

  } // loop on _fieldDrivers

  if ( nbOldMeshes + nbNewMeshes > 1 && !_variables.empty() )
  {
    // if there are variables on a transient model, model should not change much,
    // nb of entities in all parts with values must be same
    if ( nbOldMeshes == 0 ) {
      // TODO: check consistency
    }
    if ( toIgnoreIncompatibility() )
      cout << "Warning: EnSight file will be probably invalid " << _fileName << endl;
    else
      throw MEDEXCEPTION
        (compatibilityPb(STRING("EnSight file will be invalid if fields refer to "
                                "the second mesh, which differ from the first one too much.\n"
                                "If you are sure in data correctness, you can suppress "
                                "this exception by calling setIgnoreIncompatibility(1)\n")
                         << _fileName));
  }

  // Write a file

  ofstream caseFile( _fileName.c_str(), ios::out );
  if ( !caseFile )
    throw MEDEXCEPTION(STRING("Can't open file for writing ") << _fileName);

  caseFile << "# generated by MEDMEM-to-EnSight driver" << endl << endl
           << "FORMAT" << endl
           << "type: " << (_format==ENSIGHT_GOLD ? "ensight gold" : "ensight") << endl
           << endl
           << "GEOMETRY"
           << endl
           << "model:\t"
           << _model._timeSetNumber << " "
           << _model._fileSetNumber << " "
           << _model._fileName << " \t"
           << _model._change_coords_only
           << endl << endl;

  // write VARIABLE section
  if ( !_variables.empty() )
  {
    caseFile << "VARIABLE" << endl;

    map< int, _Variable>::iterator ivar = _variables.begin();
    for ( ; ivar != _variables.end(); ++ivar )
    {
      _Variable& var = ivar->second;
      caseFile << var._type << ": \t"
               << var._timeSetNumber << " "
               << var._fileSetNumber << " \t"
               << var._name << " \t"
               << var._fileNameOrData << endl;
    }
    caseFile << endl;
  }
  // write TIME section
  if ( !_timeSets.empty() )
  {
    caseFile << "TIME" << endl;

    map< int, _TimeSet>::iterator its = _timeSets.begin();
    for ( ; its != _timeSets.end(); ++its )
    {
      _TimeSet & ts = its->second;
      caseFile << "time set:\t"        << ts._number << endl
               << "number of steps:\t" << ts._times.size() << endl;
      if ( !ts._fileIndex.empty() ) {
        STRING numbers( "filename numbers:" );
        for ( unsigned i = 0; i < ts._fileIndex.size(); ++i ) {
          if (int( numbers.size() + ts._fileIndex[i].size() + 2) > MAX_LINE_LENGTH ) {
            caseFile << numbers << endl;
            numbers = STRING();
          }
          numbers << " " << ts._fileIndex[i];
        }
        caseFile << numbers << endl;
      }
      STRING times( "time values:" );
      for ( unsigned i = 0; i < ts._times.size(); ++i ) {
        if (int( times.size() + ts._times[i].size() + 2 ) > MAX_LINE_LENGTH ) {
          caseFile << times << endl;
          times = STRING();
        }
        times << " " << ts._times[i];
      }
      caseFile << times << endl;
    }
  }
  // write FILE section
  if ( !_fileSets.empty() )
  {
    caseFile << "FILE" << endl;

    map< int, _FileSet >::iterator ifs = _fileSets.begin();
    for ( ; ifs != _fileSets.end(); ++ifs )
    {
      _FileSet & fs = ifs->second;
      caseFile << "file set: " << fs._number << endl;

      list<int>::iterator nbSteps = fs._nbStepsInFile.begin();
      list<string>::iterator fileIndex = fs._fileIndex.begin();
      for ( ; nbSteps != fs._nbStepsInFile.end(); ++nbSteps )
      {
        if ( fileIndex != fs._fileIndex.end() )
          caseFile << "filename index: " << *fileIndex++;
        caseFile << "number of steps: " << *nbSteps << endl;
      }
    }
  }

  caseFile.close();

} // _CaseFileDriver::write()

Here is the call graph for this function:


Member Data Documentation

Definition at line 355 of file MEDMEM_EnsightUtils.hxx.

Definition at line 340 of file MEDMEM_EnsightUtils.hxx.

added field drivers groupped by name

to block all calls from a mesh/field driver governed by med driver

Definition at line 352 of file MEDMEM_EnsightUtils.hxx.

Definition at line 339 of file MEDMEM_EnsightUtils.hxx.

map fs to file set data

Definition at line 345 of file MEDMEM_EnsightUtils.hxx.

Definition at line 341 of file MEDMEM_EnsightUtils.hxx.

std::list<ENSIGHT_MESH_WRONLY_DRIVER*> MEDMEM_ENSIGHT::_CaseFileDriver::_meshDrivers [private]

added meshes

Definition at line 349 of file MEDMEM_EnsightUtils.hxx.

Definition at line 342 of file MEDMEM_EnsightUtils.hxx.

map ts to time set data

Definition at line 344 of file MEDMEM_EnsightUtils.hxx.

const _CaseFileDriver_User* MEDMEM_ENSIGHT::_CaseFileDriver::_user [private]

mesh/field driver

Definition at line 347 of file MEDMEM_EnsightUtils.hxx.

map order number to variable data

Definition at line 343 of file MEDMEM_EnsightUtils.hxx.


The documentation for this class was generated from the following files: