+const medGeometryElement GIBI_MESH_DRIVER::geomGIBItoMED[nb_geometrie_gibi] =
+ { /*1 */ MED_POINT1 ,/*2 */ MED_SEG2 ,/*3 */ MED_SEG3 ,/*4 */ MED_TRIA3 ,/*5 */ MED_NONE ,
+ /*6 */ MED_TRIA6 ,/*7 */ MED_NONE ,/*8 */ MED_QUAD4 ,/*9 */ MED_NONE ,/*10*/ MED_QUAD8 ,
+ /*11*/ MED_NONE ,/*12*/ MED_NONE ,/*13*/ MED_NONE ,/*14*/ MED_HEXA8 ,/*15*/ MED_HEXA20 ,
+ /*16*/ MED_PENTA6 ,/*17*/ MED_PENTA15,/*18*/ MED_NONE ,/*19*/ MED_NONE ,/*20*/ MED_NONE ,
+ /*21*/ MED_NONE ,/*22*/ MED_NONE ,/*23*/ MED_TETRA4 ,/*24*/ MED_TETRA10,/*25*/ MED_PYRA5 ,
+ /*26*/ MED_PYRA13 ,/*27*/ MED_NONE ,/*28*/ MED_NONE ,/*29*/ MED_NONE ,/*30*/ MED_NONE ,
+ /*31*/ MED_NONE ,/*32*/ MED_NONE ,/*33*/ MED_NONE ,/*34*/ MED_NONE ,/*35*/ MED_NONE ,
+ /*36*/ MED_NONE ,/*37*/ MED_NONE ,/*38*/ MED_NONE ,/*39*/ MED_NONE ,/*40*/ MED_NONE ,
+ /*41*/ MED_NONE ,/*42*/ MED_NONE ,/*43*/ MED_NONE ,/*44*/ MED_NONE ,/*45*/ MED_NONE ,
+ /*46*/ MED_NONE ,/*47*/ MED_NONE };
+
+//=======================================================================
+//function : gibi2medGeom
+//purpose :
+//=======================================================================
+
+medGeometryElement GIBI_MESH_DRIVER::gibi2medGeom( size_t gibiTypeNb )
+{
+ if ( gibiTypeNb < 1 || gibiTypeNb > 47 )
+ return MED_NONE;
+
+ return geomGIBItoMED[ gibiTypeNb - 1 ];
+}
+
+//=======================================================================
+//function : med2gibiGeom
+//purpose :
+//=======================================================================
+
+int GIBI_MESH_DRIVER::med2gibiGeom( medGeometryElement medGeomType )
+{
+ for ( int i = 0; i < nb_geometrie_gibi; i++ )
+ if ( geomGIBItoMED[ i ] == medGeomType )
+ return i + 1;
+
+ return -1;
+}
+
+//=======================================================================
+//function : getGroupId
+//purpose :
+//=======================================================================
+
+static int getGroupId(const vector<int>& support_ids, _intermediateMED* medi)
+{
+ int group_id = 0;
+ vector<int>::const_iterator sb = support_ids.begin(), se = support_ids.end();
+ if (support_ids.size() == 1 || // one or equal support ids
+ *std::max_element( sb, se ) == *std::min_element( sb, se ))
+ {
+ group_id = support_ids[0] - 1;
+ }
+ else
+ {
+ // try to find an existing group with the same sub-groups
+ set<int> sup_set;
+ sup_set.insert( sb, se );
+
+ for ( group_id = 0; group_id < medi->groupes.size(); ++group_id )
+ {
+ if (sup_set.size() == medi->groupes[ group_id ].groupes.size() &&
+ std::equal (sup_set.begin(), sup_set.end(),
+ medi->groupes[ group_id ].groupes.begin()))
+ break;
+ }
+ if ( group_id == medi->groupes.size() )
+ {
+ // no such a group, add a new one
+ medi->groupes.push_back( _groupe() );
+ _groupe& new_grp = medi->groupes.back();
+ //new_grp.nom = string( group_id % 10 + 1, 'G' );
+ new_grp.groupes.reserve( sup_set.size() );
+ for ( set<int>::iterator it = sup_set.begin(); it != sup_set.end(); it++ ) {
+ new_grp.groupes.push_back( *it );
+ //new_grp.nom += "_" + medi->groupes[ *it - 1 ].nom;
+ }
+ }
+ }
+ return group_id;
+}
+
+//=======================================================================
+//function : isNamedObject
+//purpose :
+//=======================================================================
+
+#ifdef GIBI_READ_ONLY_NAMED_FIELD
+static inline bool isNamedObject( int obj_index, const vector<int>& indices_objets_nommes )
+{
+ return ( std::find( indices_objets_nommes.begin(), indices_objets_nommes.end(), obj_index)
+ != indices_objets_nommes.end() );
+}
+#endif
+
+//=======================================================================
+//function : read
+//purpose :
+//=======================================================================
+
+#define GIBI_EQUAL(var_str, stat_str) \
+ (strncmp (var_str, stat_str, sizeof(stat_str)-1) == 0)
+#define DUMP_LINE_NB " on line " << _lineNb
+
+bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields )
+{
+ const char * LOC = "GIBI_MESH_RDONLY_DRIVER::readFile() : " ;
+ BEGIN_OF(LOC);
+
+ // LECTURE DES DONNEES DS FICHIER GIBI
+
+ enum Readable_Piles {
+ PILE_SOUS_MAILLAGE=1,
+ PILE_NODES_FIELD =2,
+ PILE_NOEUDS =32,
+ PILE_COORDONNEES =33,
+ PILE_FIELD =39,
+ PILE_LAST_READABLE=39
+ };
+ Readable_Piles readable_Piles [] = {
+ PILE_SOUS_MAILLAGE,
+ PILE_NODES_FIELD,
+ PILE_NOEUDS,
+ PILE_COORDONNEES,
+ PILE_FIELD,
+ PILE_LAST_READABLE
+ };
+ char* ligne; // pour lire une ligne
+ const char* enregistrement_type=" ENREGISTREMENT DE TYPE";
+ vector<int> numero_noeuds; // tableau de travail (indices)
+ set<int> donePiles; // already read piles
+ unsigned space_dimension = 0;
+
+ while ( getNextLine(ligne, false)) // boucle externe de recherche de "ENREGISTREMENT DE TYPE"
+ {
+ if ( !GIBI_EQUAL( ligne, enregistrement_type ))
+ continue; // "ENREGISTREMENT DE TYPE" non trouvé -> on lit la ligne suivante
+
+ // lecture du numéro d'enregistrement
+ int numero_enregistrement = atoi( ligne + strlen(enregistrement_type) + 1 );
+
+ enum { ENREG_TYPE_2=2, ENREG_TYPE_4=4}; // énumération des types d'enregistrement traités
+ int numero_pile, nb_objets_nommes, nb_objets, nb_indices;
+ vector<int> indices_objets_nommes;
+ vector<string> objets_nommes;
+
+ if (numero_enregistrement == ENREG_TYPE_4)
+ {
+ getNextLine(ligne);
+ const char* s = " NIVEAU 15 NIVEAU ERREUR 0 DIMENSION";
+ space_dimension = atoi( ligne + strlen( s ) + 1 );
+ if ( !GIBI_EQUAL( ligne, " NIVEAU" ) || space_dimension < 1 ) {
+ INFOS( " Could not read file: syntax error in type 4 record");
+ return false;
+ }
+ }
+ else if (numero_enregistrement == ENREG_TYPE_2 )
+ {
+ if ( space_dimension == 0 ) {
+ INFOS( "Missing ENREGISTREMENT DE TYPE 4");
+ return false;
+ }
+ // FORMAT(' PILE NUMERO',I4,'NBRE OBJETS NOMMES',I8,'NBRE OBJETS',I8)
+ getNextLine(ligne);
+ const char *s1 = " PILE NUMERO", *s2 = "NBRE OBJETS NOMMES", *s3 = "NBRE OBJETS";
+ if ( ! GIBI_EQUAL( ligne, s1 ) ) {
+ INFOS( " Could not read file: error in type 2 record. " << ligne);
+ return false;
+ }
+ ligne = ligne + strlen(s1);
+ numero_pile = atoi( ligne );
+ ligne = ligne + 4 + strlen(s2);
+ nb_objets_nommes = atoi( ligne );
+ ligne = ligne + 8 + strlen(s3);
+ nb_objets = atoi( ligne );
+ if ( nb_objets_nommes<0 || nb_objets<0 ) {
+ INFOS(" Could not read file: " << nb_objets << " " <<nb_objets_nommes);
+ return false;
+ }
+ if ( !donePiles.insert( numero_pile ).second ) // piles may repeat
+ continue;
+
+ if ( numero_pile > PILE_LAST_READABLE )
+ break; // stop file reading
+
+ // skip not readable piles
+ int i = -1;
+ while ( readable_Piles[ ++i ] != PILE_LAST_READABLE )
+ if ( readable_Piles[ i ] == numero_pile )
+ break;
+ if ( readable_Piles[ i ] != numero_pile )
+ continue;
+
+ // lecture des objets nommés et de leurs indices
+ objets_nommes.resize(nb_objets_nommes);
+ indices_objets_nommes.resize(nb_objets_nommes);
+ for ( initNameReading( nb_objets_nommes ); more(); next() ) {
+ objets_nommes[ index() ] = getName();
+ }
+ for ( initIntReading( nb_objets_nommes ); more(); next() )
+ indices_objets_nommes[ index() ] = getInt();
+
+ // boucle interne : lecture de la pile
+
+ MESSAGE(LOC << "---- Traitement pile " << numero_pile);
+
+ // -----------------------------------
+ // MESH GROUPS
+ // -----------------------------------
+
+ if (numero_pile == PILE_SOUS_MAILLAGE )
+ {
+ map<int,int> strangeGroupType;
+ medi->groupes.reserve(nb_objets*2); // fields may add some groups
+ for (int objet=0; objet!=nb_objets; ++objet) // pour chaque groupe
+ {
+ initIntReading( 5 );
+ unsigned type_geom_castem = getInt(); next();
+ unsigned nb_sous_maillage = getInt(); next();
+ unsigned nb_reference = getInt(); next();
+ unsigned nb_noeud = getInt(); next();
+ unsigned nb_elements = getInt();
+
+ // le cas type_geom_castem=0 correspond aux maillages composites
+ if (type_geom_castem<0) {
+ INFOS(" Error while reading file, bad geometric type:" << type_geom_castem);
+ return false;
+ }
+
+ medi->groupes.push_back(_groupe());
+ _groupe & groupe = medi->groupes.back();
+
+ // si le groupe se compose de sous-maillages (ie groupe composite)
+ if (type_geom_castem==0 && nb_sous_maillage>0)
+ {
+ // lecture des indices des sous-maillages, stockage.
+ // les mailles correspondant a ces sous_maillages seront inserees a la fin du case
+ groupe.groupes.resize( nb_sous_maillage );
+ for ( initIntReading( nb_sous_maillage ); more(); next() ) {
+ groupe.groupes[ index() ] = getInt();
+ }
+ if ( readFields )
+ std::sort( groupe.groupes.begin(), groupe.groupes.end() );
+ }
+ // lecture des references (non utilisé pour MED)
+ for ( i = 0; i < nb_reference; i += 10 ) {// FORMAT(10I8)
+ getNextLine(ligne);
+ }
+ // lecture des couleurs (non utilisé pour MED)
+ for ( i = 0; i < nb_elements; i += 10 ) {
+ getNextLine(ligne);
+ }
+ // not a composit group
+ if (type_geom_castem>0 && nb_sous_maillage==0)
+ {
+ medGeometryElement medType = gibi2medGeom(type_geom_castem);
+ bool goodType = ( medType!=MED_NONE );
+ if ( !goodType )
+ strangeGroupType.insert( make_pair( objet, type_geom_castem ));
+
+ pair<set<_maille>::iterator,bool> p;
+ pair<map<int,_noeud>::iterator,bool> p_no;
+ _noeud no;
+ no.coord.resize(space_dimension);
+ _maille ma( medType, nb_noeud );
+ ma.sommets.resize(nb_noeud);
+ if ( goodType )
+ groupe.mailles.resize( nb_elements );
+
+ // lecture pour chaque maille des sommets et insertions
+ initIntReading( nb_elements * nb_noeud );
+ if ( !goodType ) {
+ while ( more() )
+ next();
+ }
+ else {
+ for ( i = 0; i < nb_elements; ++i )
+ {
+ for (unsigned n = 0; n < nb_noeud; ++n, next() )
+ {
+ if ( !more() ) {
+ INFOS( " Error while reading elem nodes ");
+ return false;
+ }
+ no.number = getInt();
+ p_no=medi->points.insert(make_pair(no.number, no));
+ ma.sommets[n]=p_no.first;
+ }
+ p=medi->maillage.insert(ma);
+ groupe.mailles[i] = p.first; // on stocke dans le groupe un iterateur sur la maille
+ }
+ }
+ }
+ } // loop on groups
+
+ // set group names
+ for (i=0; i!=nb_objets_nommes; ++i) {
+ int grpID = indices_objets_nommes[i];
+ _groupe & grp = medi->groupes[ grpID-1 ];
+ if ( !grp.nom.empty() ) // a group has several names
+ { // create a group with subgroup grp and named grp.nom
+ medi->groupes.push_back(_groupe());
+ medi->groupes.back().groupes.push_back( grpID );
+ medi->groupes.back().nom = grp.nom;
+ }
+ grp.nom=objets_nommes[i];
+ map<int,int>::iterator it = strangeGroupType.find( grpID - 1 );
+ if ( it != strangeGroupType.end() ) {
+ //INFOS( "Skip " << grp.nom << " of not supported CASTEM type: " << it->second );
+ }
+ }
+
+ }// Fin case PILE_SOUS_MAILLAGE
+
+ // ---------------------------------
+ // NODES
+ // ---------------------------------
+
+ else if ( numero_pile == PILE_NOEUDS )
+ {
+ getNextLine( ligne );
+ std::vector<int> place_noeuds;
+ nb_indices = atoi ( ligne );
+ if (nb_indices != nb_objets)
+ {
+ INFOS("Erreur de lecture dans enregistrement de pile " << PILE_NOEUDS);
+ return false;
+ }
+
+ place_noeuds.resize(nb_objets);
+ for ( initIntReading( nb_objets ); more(); next() )
+ place_noeuds[ index() ] = getInt();
+ int max=(* std::max_element(place_noeuds.begin(),place_noeuds.end()));
+
+ // numero_noeuds contient pour chacun des max noeuds qu'on va lire dans le case PILE_COORDONNEES
+ // son indice dans la connectivite du maillage. Cet indice correspond egalement a la cle du map
+ // medi->points ou l'on stocke les noeuds.
+ numero_noeuds.resize(max,-1);
+ for (unsigned i=0; i!=place_noeuds.size(); ++i)
+ numero_noeuds[place_noeuds[i]-1]=i+1;
+ }
+
+ // ---------------------------------------
+ // COORDINATES
+ // ---------------------------------------
+
+ else if ( numero_pile == PILE_COORDONNEES )
+ {
+ getNextLine( ligne );
+ unsigned nb_reels = atoi( ligne );
+ // PROVISOIRE : certains fichier gibi n`ont
+ if (nb_reels < numero_noeuds.size()*(space_dimension)) {
+ INFOS("Erreur de lecture dans enregistrement de pile " << PILE_COORDONNEES);
+ return false;
+ }
+ initDoubleReading( nb_reels );
+ map< int, _noeud >::iterator pIt;
+ for (unsigned i=0; i!=numero_noeuds.size(); ++i)
+ {
+ // si le noeud est utilisé dans le maillage,
+ //on lit ses coordonnées et on les stocke dans la structure
+ if (( numero_noeuds[i] != -1 ) &&
+ (( pIt = medi->points.find(numero_noeuds[i])) != medi->points.end()))
+ {
+ for (unsigned j=0; j!=space_dimension; ++j, next())
+ pIt->second.coord[j] = getDouble();
+ next(); // on ne conserve pas la densite
+ }
+ else // sinon, on passe au noeud suivant
+ {
+ for (unsigned j=0; j!=space_dimension+1; ++j)
+ next();
+ }
+ }
+ }
+
+ // ---------------------------------------
+ // NODE FIELDS
+ // ---------------------------------------
+
+ else if ( numero_pile == PILE_NODES_FIELD && readFields )
+ {
+ vector< _fieldBase* > fields( nb_objets );
+ for (int objet=0; objet!=nb_objets; ++objet) // pour chaque field
+ {
+ bool ignoreField = false;
+#ifdef GIBI_READ_ONLY_NAMED_FIELD
+ ignoreField = !isNamedObject( objet+1, indices_objets_nommes );
+ if ( ignoreField )
+ INFOS("Skip non-named field " << objet+1 << DUMP_LINE_NB);
+#endif
+
+ // EXAMPLE ( with no values )
+
+ // (1) 4 7 2 1
+ // (2) -88 0 3 -89 0 1 -90 0 2 -91
+ // (2) 0 1
+ // (3) FX FY FZ FZ FX FY FLX
+ // (4) 0 0 0 0 0 0 0
+ // (5) créé par muc pri
+ // (6)
+ // (7) 2
+
+ // (1): nb subcomponents, nb components(total), IFOUR, nb attributes
+ initIntReading( 4 );
+ int i_sub, nb_sub = getInt(); next();
+ int i_comp, total_nb_comp = getInt(); next();
+ next(); // ignore IFOUR
+ int nb_attr = getInt();
+ if ( nb_sub < 0 || total_nb_comp < 0 || nb_attr < 0 ) {
+ INFOS("Error of field reading: wrong nb of components "
+ << nb_sub << " " << total_nb_comp << DUMP_LINE_NB);
+ return false;
+ }
+ // (2) loop on subcomponents of a field, for each read
+ // (a) support, (b) number of values and (c) number of components
+ vector<int> support_ids( nb_sub );
+ vector<int> nb_values ( nb_sub );
+ vector<int> nb_comps ( nb_sub );
+ int total_nb_values = 0;
+ initIntReading( nb_sub * 3 );
+ for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
+ {
+ support_ids[ i_sub ] = -getInt(); next(); // (a) reference to support
+ if ( support_ids[ i_sub ] < 1 || support_ids[ i_sub ] > medi->groupes.size() ) {
+ INFOS("Error of field reading: wrong mesh reference "<< support_ids[ i_sub ]);
+ return false;
+ }
+ nb_values[ i_sub ] = getInt(); next(); // (b) nb points
+ total_nb_values += nb_values[ i_sub ];
+ if ( nb_values[ i_sub ] < 0 ) {
+ INFOS(" Wrong nb of points: " << nb_values[ i_sub ] );
+ return false;
+ }
+ nb_comps[ i_sub ] = getInt(); next(); // (c) nb of components in i_sub
+ }
+ // create a field if there are values
+ _field<double>* fdouble = 0;
+ if ( total_nb_values > 0 && !ignoreField )
+ {
+ fdouble = new _field<double>( MED_REEL64, nb_sub, total_nb_comp );
+ medi->fields.push_back( fields[ objet ] = fdouble );
+ }
+ // (3) component names
+ initNameReading( total_nb_comp, 4 );
+ for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
+ {
+ // store support id and nb components of a sub
+ if ( fdouble )
+ fdouble->_sub[ i_sub ].setData( nb_comps[ i_sub ], support_ids[ i_sub ] );
+ for ( i_comp = 0; i_comp < nb_comps[ i_sub ]; ++i_comp, next() )
+ {
+ ASSERT( more() );
+ // store component name
+ if ( fdouble )
+ fdouble->_sub[ i_sub ].compName( i_comp ) = getName();
+ }
+ }
+ // (4) nb harmonics ( ignored )
+ for ( initIntReading( nb_sub ); more(); next() )
+ ;
+ // (5) TYPE ( ignored )
+ getNextLine( ligne );
+ // (6) TITRE ( ignored )
+ getNextLine( ligne );
+ // (7) attributes ( ignored )
+ for ( initIntReading( nb_attr ); more(); next() )
+ ;
+
+ for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
+ {
+ // loop on components: read values
+ initDoubleReading( nb_values[ i_sub ] * nb_comps[ i_sub ] );
+ for ( i_comp = 0; i_comp < nb_comps[ i_sub ]; ++i_comp )
+ {
+ vector<double>* vals = 0;
+ if ( fdouble ) vals = & fdouble->addComponent( nb_values[ i_sub ] );
+ for ( int i = 0; more() && i < nb_values[ i_sub ]; next(), ++i ) {
+ if ( vals ) (*vals)[ i ] = getDouble();
+ }
+ }
+ } // loop on subcomponents of a field
+
+ // set id of a group including all subs supports but only
+ // if all subs have the same components
+ if ( fdouble && fdouble->hasSameComponentsBySupport() )
+ fdouble->_group_id = getGroupId( support_ids, medi );
+
+ } // end loop on field objects
+
+ // set field names
+ for ( i = 0; i < nb_objets_nommes; ++i ) {
+ int fieldIndex = indices_objets_nommes[ i ];
+ if ( fields[ fieldIndex - 1 ] )
+ fields[ fieldIndex - 1 ]->_name = objets_nommes[ i ];
+ }
+
+ } // Fin numero_pile == PILE_NODES_FIELD
+
+ // -------------------------------------------------
+ // FIELDS
+ // -------------------------------------------------
+
+ else if ( numero_pile == PILE_FIELD && readFields )
+ {
+ // REAL EXAMPLE
+
+ // (1) 1 2 6 16
+ // (2) CARACTERISTIQUES
+ // (3) -15 317773 4 0 0 0 -2 0 3
+ // (4) 317581
+ // (5) \0\0\0\0\0\0\0\0
+ // (6) 317767 317761 317755 317815
+ // (7) YOUN NU H SIGY
+ // (8) REAL*8 REAL*8 REAL*8 REAL*8
+ // (9) 1 1 0 0
+ // (10) 2.00000000000000E+05
+ // (11) 1 1 0 0
+ // (12) 3.30000000000000E-01
+ // (13) 1 1 0 0
+ // (14) 1.00000000000000E+04
+ // (15) 6 706 0 0
+ // (16) 1.00000000000000E+02 1.00000000000000E+02 1.00000000000000E+02
+ // (17) 1.00000000000000E+02 1.00000000000000E+02 1.00000000000000E+02
+ // (18) ...
+ vector< _fieldBase* > fields( nb_objets, (_fieldBase*)0 );
+ for (int objet=0; objet!=nb_objets; ++objet) // pour chaque field
+ {
+ bool ignoreField = false;
+#ifdef GIBI_READ_ONLY_NAMED_FIELD
+ ignoreField = !isNamedObject( objet+1, indices_objets_nommes );
+ if ( ignoreField )
+ INFOS("Skip non-named field " << objet+1 << DUMP_LINE_NB);
+#endif
+ initIntReading( 1 );
+ int i_sub, nb_sub = getInt(); // (1) <nb_sub> 2 6 <title length>
+ if ( nb_sub < 1 ) {
+ INFOS("Error of field reading: wrong nb of subcomponents " << nb_sub);
+ return false;
+ }
+ getNextLine( ligne ); // (2) title
+ // look for a line starting with '-' : <reference to support>
+ do {
+ initIntReading( nb_sub * 9 );
+ } while ( getInt() >= 0 );
+
+ int total_nb_comp = 0;
+ vector<int> support_ids( nb_sub ), nb_comp( nb_sub );
+ for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
+ { // (3)
+ support_ids[ i_sub ] = -getInt(); next(); // <reference to support>
+ next(); // ignore <address>
+ nb_comp [ i_sub ] = getInt(); next(); // <nb of components in the sub>
+ for ( i = 0; i < 6; ++i ) // ignore 6 ints, in example 0 0 0 -2 0 3
+ next();
+ if ( support_ids[ i_sub ] < 1 || support_ids[ i_sub ] > medi->groupes.size() ) {
+ INFOS("Error of field reading: wrong mesh reference "<< support_ids[ i_sub ]);
+ return false;
+ }
+ if ( nb_comp[ i_sub ] < 1 ) {
+ INFOS("Error of field reading: wrong nb of components " << nb_comp[ i_sub ]);
+ return false;
+ }
+ total_nb_comp += nb_comp[ i_sub ];
+ }
+ for ( initNameReading( nb_sub, 17 ); more(); next() )
+ ; // (4) dummy strings
+ for ( initNameReading( nb_sub ); more(); next() )
+ ; // (5) dummy strings
+
+ // loop on subcomponents of a field, each of which refers to
+ // a certain support and has its own number of components;
+ // read component values
+ _field<double>* fdouble = 0;
+ _field<int>* fint = 0;
+ _fieldBase * fbase = 0;
+ for ( i_sub = 0; i_sub < nb_sub; ++ i_sub )
+ {
+ vector<string> comp_names( nb_comp[ i_sub ]), comp_type( nb_comp[ i_sub ]);
+ for ( initIntReading( nb_comp[ i_sub ] ); more(); next() )
+ ; // (6) nb_comp addresses of MELVAL structure
+
+ // (7) component names
+ for ( initNameReading( nb_comp[ i_sub ] ); more(); next() )
+ comp_names[ index() ] = getName();
+
+ // (8) component type
+ for ( initNameReading( nb_comp[ i_sub ], 17 ); more(); next() ) { // 17 is name width
+ comp_type[ index() ] = getName();
+ // component types must be the same
+ if ( index() > 0 && comp_type[ index() ] != comp_type[ index() - 1] ) {
+ INFOS( "Error of field reading: diff component types <"
+ << comp_type[ index() ] << "> != <" << comp_type[ index() - 1 ] << ">");
+ return false;
+ }
+ }
+ // now type is known, create a field, one for all subs
+ bool isReal = ( comp_type[0] == "REAL*8" );
+ if ( !ignoreField && !fbase ) {
+ if ( !isReal ) {
+ fbase = fint = new _field<int>( MED_INT32, nb_sub, total_nb_comp );
+ INFOS( "Warning: read NOT REAL field, type <" << comp_type[0] << ">"
+ << DUMP_LINE_NB);
+ }
+ else
+ fbase = fdouble = new _field<double>( MED_REEL64, nb_sub, total_nb_comp );
+ medi->fields.push_back( fields[ objet ] = fbase ); // medi->fields is a std::list
+ }
+ // store support id and nb components of a sub
+ if ( fbase )
+ fbase->_sub[ i_sub ].setData( nb_comp[ i_sub ], support_ids[ i_sub ]);
+
+ // loop on components: read values
+ for ( int i_comp = 0; i_comp < nb_comp[ i_sub ]; ++i_comp )
+ {
+ // (9) nb of values
+ initIntReading( 2 );
+ int nb_val_by_elem = getInt(); next();
+ int nb_values = getInt();
+ if ( nb_val_by_elem != 1 ) {
+#ifdef STOP_READING_UNSUP_DATA
+ INFOS("Error of reading field " << objet + 1 << ": nb of values by element "
+ << " != 1 : " << nb_val_by_elem << DUMP_LINE_NB );
+ return false;
+#else
+ if ( fbase ) {
+ if ( isReal ) delete fdouble;
+ else delete fint;
+ fields[ objet ] = fbase = 0;
+ medi->fields.pop_back();
+ INFOS("Skip field " << objet + 1 << ": nb of values by element != 1 : "
+ << nb_val_by_elem << DUMP_LINE_NB);
+ }
+#endif
+ }
+ // (10) values
+ nb_values *= nb_val_by_elem;
+ if ( fbase ) {
+ if ( isReal ) {
+ vector<double> & vals = fdouble->addComponent( nb_values );
+ for ( initDoubleReading( nb_values ); more(); next()) {
+ vals[ index() ] = getDouble();
+ }
+ }
+ else {
+ vector<int> & vals = fint->addComponent( nb_values );
+ for ( initIntReading( nb_values ); more(); next() ) {
+ vals[ index() ] = getInt();
+ }
+ }
+ // store component name
+ fbase->_sub[ i_sub ].compName( i_comp ) = comp_names[ i_comp ];
+ }
+ else {
+ for ( isReal ? initDoubleReading( nb_values ) : initIntReading( nb_values );
+ more();
+ next() ) ;
+ }
+ }
+ } // loop on subcomponents of a field
+
+ // set id of a group including all sub supports but only
+ // if all subs have the same nb of components
+ if ( fbase && fbase->hasSameComponentsBySupport() )
+ fbase->_group_id = getGroupId( support_ids, medi );
+
+ } // end loop on field objects
+
+ // set field names
+ for ( i = 0; i < nb_objets_nommes; ++i ) {
+ int fieldIndex = indices_objets_nommes[ i ] - 1;
+ if ( fields[ fieldIndex ])
+ fields[ fieldIndex ]->_name = objets_nommes[ i ];
+ }
+
+ } // numero_pile == PILE_FIELD && readFields
+
+ else if ( numero_pile >= PILE_LAST_READABLE )
+ break; // stop file reading
+
+ } // Fin case ENREG_TYPE_2
+ } // fin de la boucle while de lecture externe
+
+ // check if all needed piles present
+ if ( donePiles.find( PILE_SOUS_MAILLAGE ) != donePiles.end() )
+ {
+ if (donePiles.find( PILE_NOEUDS ) == donePiles.end() ) {
+ INFOS( " Missing pile " << PILE_NOEUDS );
+ return false;
+ }
+ if (donePiles.find( PILE_COORDONNEES ) == donePiles.end()) {
+ INFOS( " Missing pile " << PILE_COORDONNEES );
+ return false;
+ }
+ }
+
+ END_OF(LOC);
+ return true;
+}