Back to index

salome-med  6.5.0
Functions
Reading and writing files

Fields can be read or written to/from MED files. More...

Functions

 MEDMEM::FIELD< T, INTERLACING_TAG >::FIELD (const SUPPORT *Support, driverTypes driverType, const string &fileName="", const string &fieldName="", const int iterationNumber=-1, const int orderNumber=-1) throw (MEDEXCEPTION)
 Constructor with parameters; the object is set via a file and its associated driver.
 MEDMEM::FIELD< T, INTERLACING_TAG >::FIELD (driverTypes driverType, const string &fileName, const string &fieldDriverName, const int iterationNumber=-1, const int orderNumber=-1, GMESH *mesh=0) throw (MEDEXCEPTION)
 If the mesh argument is not initialized or passed NULL, this constructor, at least, allows to create a FIELD without creating any SUPPORT then without having to load a MESH object, a support is created.

Detailed Description

Fields can be read or written to/from MED files.

Reading fields

For reading a field a typical use consists in :

As an example :

//reading mesh from file
MESH mesh(MED_DRIVER, "file.med", "my_Mesh");
//reading the field from the file
FIELD<double> field(group,MED_DRIVER,"file.med","my_Field",1,1,&mesh);

It is also possible to read a field without specifying its support. In this case, the field constructor creates a support with no link to the initial mesh:

FIELD<double> field(MED_DRIVER, "file.med", "myField",1,1);
SUPPORT* support= field->getSupport();

See also FIELD<T> constructors

Writing fields

When it comes to write fields, it is enough to call write() method. A typical use will be :

mesh.write(MED_DRIVER, "myResultFile.med");
field.write(MED_DRIVER, "myResultFile.med");

Function Documentation

template<class T , class INTERLACING_TAG >
MEDMEM::FIELD< T, INTERLACING_TAG >::FIELD ( driverTypes  driverType,
const string &  fileName,
const string &  fieldDriverName,
const int  iterationNumber = -1,
const int  orderNumber = -1,
GMESH *  mesh = 0 
) throw (MEDEXCEPTION)

If the mesh argument is not initialized or passed NULL, this constructor, at least, allows to create a FIELD without creating any SUPPORT then without having to load a MESH object, a support is created.

It provides the meshName related mesh but doesn't not set a mesh in the created support. If the passed mesh contains corresponding support, this support will be used for the field. This support will be found in mesh by name of one of profiles, on which the FIELD lays in MED-file. This has sense for the case, then MED-file was created by MEDMEM, and so name of profile contains name of corresponding support.

Definition at line 2910 of file MEDMEM_Field.hxx.

                       :FIELD_()
{
  int current;
  const char* LOC = "FIELD<T,INTERLACING_TAG>::FIELD( driverTypes driverType, const string & fileName, string & fieldDriverName, int iterationNumber, int orderNumber) : ";
  BEGIN_OF_MED(LOC);

  init();

  _mesh = mesh;
  if(_mesh)
    _mesh->addReference();

  //INITIALISATION DE _valueType DS LE CONSTRUCTEUR DE FIELD_
  ASSERT_MED(FIELD_::_valueType == MED_EN::MED_UNDEFINED_TYPE)
  FIELD_::_valueType = SET_VALUE_TYPE<T>::_valueType;

  //INITIALISATION DE _interlacingType DS LE CONSTRUCTEUR DE FIELD_
  ASSERT_MED(FIELD_::_interlacingType == MED_EN::MED_UNDEFINED_INTERLACE)
  FIELD_::_interlacingType = SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType;

  _support = (SUPPORT *) NULL;
  // OCC 10/03/2006 -- According to the rules defined with help of 
  // MEDMEM_IntrelacingTraits class, it is not allowed to instantiate
  // MEDMEM_Array<> template using INTERLACING_TAG parameter of 
  // FIELD template - MSVC++ 2003 compiler generated an error here.
  // _value = (MEDMEM_Array<T, INTERLACING_TAG> *) NULL;
  _value = NULL;

  _iterationNumber = iterationNumber;
  _time = 0.0;
  _orderNumber = orderNumber;

  current = addDriver(driverType,fileName,fieldDriverName,MED_EN::RDONLY);

  _drivers[current]->open();
  _drivers[current]->read();
  _drivers[current]->close();

  END_OF_MED(LOC);
}
template<class T , class INTERLACING_TAG >
MEDMEM::FIELD< T, INTERLACING_TAG >::FIELD ( const SUPPORT *  Support,
driverTypes  driverType,
const string &  fileName = "",
const string &  fieldDriverName = "",
const int  iterationNumber = -1,
const int  orderNumber = -1 
) throw (MEDEXCEPTION)

Constructor with parameters; the object is set via a file and its associated driver.

For the moment only the MED_DRIVER is considered and if the last two argument (iterationNumber and orderNumber) are not set; their default value is -1. If the field fieldDriverName with the iteration number iterationNumber and the order number orderNumber does not exist in the file fieldDriverName; the constructor raises an exception.

Definition at line 2850 of file MEDMEM_Field.hxx.

{
  const char* LOC = "template <class T> FIELD<T>::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName=\"\", const string & fieldName=\"\", const int iterationNumber=-1, const int orderNumber=-1) : ";
  BEGIN_OF_MED(LOC);

  int current;

  init();

  _mesh  = ( MESH* ) NULL;

  //INITIALISATION DE _valueType DS LE CONSTRUCTEUR DE FIELD_
  ASSERT_MED(FIELD_::_valueType == MED_EN::MED_UNDEFINED_TYPE)
  FIELD_::_valueType=SET_VALUE_TYPE<T>::_valueType;

  //INITIALISATION DE _interlacingType DS LE CONSTRUCTEUR DE FIELD_
  ASSERT_MED(FIELD_::_interlacingType == MED_EN::MED_UNDEFINED_INTERLACE)
  FIELD_::_interlacingType=SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType;

  _support = Support;
  //A.G. Addings for RC
  if(_support)
    _support->addReference();
  // OCC 10/03/2006 -- According to the rules defined with help of 
  // MEDMEM_IntrelacingTraits class, it is not allowed to instantiate
  // MEDMEM_Array<> template using INTERLACING_TAG parameter of 
  // FIELD template - MSVC++ 2003 compiler generated an error here.
  // _value = (MEDMEM_Array<T, INTERLACING_TAG> *) NULL;
  _value = NULL;

  _iterationNumber = iterationNumber;
  _time = 0.0;
  _orderNumber = orderNumber;

  current = addDriver(driverType,fileName,fieldDriverName,MED_EN::RDONLY);

  _drivers[current]->open();
  _drivers[current]->read();
  _drivers[current]->close();

  END_OF_MED(LOC);
}