1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : SauvReader.cxx
20 // Created : Tue Aug 16 13:57:42 2011
21 // Author : Edward AGAPOV (eap)
24 #include "SauvReader.hxx"
26 #include "SauvMedConvertor.hxx"
28 #include "NormalizedUnstructuredMesh.hxx"
29 #include "MEDCouplingRefCountObject.hxx"
35 using namespace MEDCoupling;
36 using namespace SauvUtilities;
39 #define GIBI_EQUAL(var_str, stat_str) (strncmp (var_str, stat_str, strlen(stat_str)) == 0)
41 //================================================================================
43 * \brief Creates a reader of a given sauve file
45 //================================================================================
47 SauvReader* SauvReader::New(const std::string& fileName)
49 if ( fileName.empty() ) THROW_IK_EXCEPTION("Invalid file name");
51 MEDCoupling::MCAuto< SauvUtilities::FileReader> parser;
54 parser = new XDRReader( fileName.c_str() );
57 SauvReader* reader = new SauvReader;
58 reader->_fileReader = parser.retn();
62 // try to open as ASCII
63 parser = new ASCIIReader( fileName.c_str() );
66 SauvReader* reader = new SauvReader;
67 reader->_fileReader = parser.retn();
71 THROW_IK_EXCEPTION("Unable to open file |"<< fileName << "|");
73 //================================================================================
77 //================================================================================
79 SauvReader::~SauvReader()
81 _fileReader->decrRef();
84 std::size_t SauvReader::getHeapMemorySizeWithoutChildren() const
89 std::vector<const BigMemoryObject *> SauvReader::getDirectChildrenWithNull() const
91 return std::vector<const BigMemoryObject *>();
94 //================================================================================
96 * \brief Return current line of ASCII file to report an error
98 //================================================================================
100 std::string SauvReader::lineNb() const
103 return string(" (line #") + SauvUtilities::toString
104 ( static_cast<SauvUtilities::ASCIIReader*>( _fileReader )->lineNb() ) + ")";
109 //================================================================================
111 * \brief Reads contents of the sauve file and convert it to MEDFileData
113 //================================================================================
115 MEDCoupling::MEDFileData * SauvReader::loadInMEDFileDS()
117 SauvUtilities::IntermediateMED iMed; // intermadiate DS
120 char* line; // a current line
121 const char* enregistrement_type=" ENREGISTREMENT DE TYPE";
123 while ( getNextLine(line, /*raiseOEF=*/false)) // external loop looking for "ENREGISTREMENT DE TYPE"
125 if ( isASCII() && !GIBI_EQUAL( line, enregistrement_type ))
126 continue; // "ENREGISTREMENT DE TYPE" not found -> read the next line
128 // read the number of a record
131 recordNumber = atoi( line + strlen(enregistrement_type) + 1 );
133 recordNumber = getInt();
136 if ( recordNumber == 2 )
138 else if (recordNumber == 4 )
140 else if (recordNumber == 7 )
142 else if (recordNumber == 8 )
144 else if (recordNumber == 5 )
145 break; // stop reading
148 THROW_IK_EXCEPTION("XDR : ENREGISTREMENT DE TYPE " << recordNumber << " not implemented!!!");
151 MEDCoupling::MEDFileData* medFileData = iMed.convertInMEDFileDS();
156 //================================================================================
158 * \brief Reads "ENREGISTREMENT DE TYPE 4"
160 //================================================================================
162 void SauvReader::readRecord4()
166 getInt(); // skip NIVEAU
167 getInt(); // skip ERREUR
168 _iMed->_spaceDim = getInt();
169 getFloat(); // skip DENSITE
175 const char* s = " NIVEAU 15 NIVEAU ERREUR 0 DIMENSION";
176 _iMed->_spaceDim = atoi( line + strlen( s ) + 1 );
177 if ( !GIBI_EQUAL( line, " NIVEAU" ))
178 THROW_IK_EXCEPTION( "Could not read space dimension" << lineNb() );
180 if ( _iMed->_spaceDim < 1 )
181 THROW_IK_EXCEPTION( "Invalid space dimension:" << _iMed->_spaceDim );
184 //================================================================================
186 * \brief Reads "ENREGISTREMENT DE TYPE 7"
188 //================================================================================
190 void SauvReader::readRecord7()
194 getInt(); // skip NOMBRE INFO CASTEM2000
195 getInt(); // skip IFOUR
196 getInt(); // skip NIFOUR
197 getInt(); // skip IFOMOD
198 getInt(); // skip IECHO
199 getInt(); // skip IIMPI
200 getInt(); // skip IOSPI
201 getInt(); // skip ISOTYP
202 getInt(); // skip NSDPGE
207 // NOMBRE INFO CASTEM2000 8
208 // IFOUR 2 NIFOUR 0 IFOMOD 2 IECHO 1 IIMPI 0 IOSPI 0 ISOTYP 1
217 //================================================================================
219 * \brief Reads "ENREGISTREMENT DE TYPE 8"
221 //================================================================================
223 void SauvReader::readRecord8()
225 // This record is useless (a constant table)
242 while (i <= nbIntToSkip) {
249 //================================================================================
251 * \brief Reads the pile number, nb of objects and nb named of objects
253 //================================================================================
255 int SauvReader::readPileNumber(int& nbNamedObjects, int& nbObjects)
257 // FORMAT(' PILE NUMERO',I4,'NBRE OBJETS NOMMES',I8,'NBRE OBJETS',I8)
262 pileNumber = getInt(); next();
263 nbNamedObjects = getInt(); next();
264 nbObjects = getInt(); next();
270 const char *s1 = " PILE NUMERO", *s2 = "NBRE OBJETS NOMMES", *s3 = "NBRE OBJETS";
271 if ( ! GIBI_EQUAL( line, s1 ) )
272 THROW_IK_EXCEPTION("Could not read the pile number " << lineNb() );
273 line = line + strlen(s1);
274 pileNumber = atoi( line );
275 line = line + 4 + strlen(s2);
276 nbNamedObjects = atoi( line );
277 line = line + 8 + strlen(s3);
278 nbObjects = atoi( line );
280 if ( nbNamedObjects<0 )
281 THROW_IK_EXCEPTION("Invalid nb of named objects: " << nbNamedObjects << lineNb() );
283 THROW_IK_EXCEPTION("Invalid nb of objects: " << nbObjects << lineNb() );
284 // It appears to be a valid case
285 // if ( nbObjects<nbNamedObjects)
286 // THROW_IK_EXCEPTION("In PILE " << pileNumber <<
287 // " nb of objects is less than nb of named objects" << lineNb() );
291 //================================================================================
293 * \brief Reads "ENREGISTREMENT DE TYPE 2"
295 //================================================================================
297 void SauvReader::readRecord2()
299 if ( _iMed->_spaceDim == 0 )
300 THROW_IK_EXCEPTION("Missing ENREGISTREMENT DE TYPE 4");
302 // read a pile number
303 int pileNumber, nbNamedObjects, nbObjects;
304 pileNumber = readPileNumber(nbNamedObjects, nbObjects);
306 if ( !_encounteredPiles.insert( pileNumber ).second && // piles may repeat
310 // read object names and their indices
311 vector<string> objectNames(nbNamedObjects);
312 for ( initNameReading( nbNamedObjects ); more(); next() )
313 objectNames[ index() ] = getName();
315 vector<int> nameIndices(nbNamedObjects);
316 for ( initIntReading( nbNamedObjects ); more(); next() )
317 nameIndices[ index() ] = getInt();
319 switch ( pileNumber )
321 case PILE_SOUS_MAILLAGE:
322 read_PILE_SOUS_MAILLAGE(nbObjects, objectNames, nameIndices);
324 case PILE_NODES_FIELD:
325 read_PILE_NODES_FIELD(nbObjects, objectNames, nameIndices);
328 read_PILE_TABLES(nbObjects, objectNames, nameIndices);
331 read_PILE_LREEL(nbObjects, objectNames, nameIndices);
334 read_PILE_LOGIQUES(nbObjects, objectNames, nameIndices);
337 read_PILE_FLOATS(nbObjects, objectNames, nameIndices);
340 read_PILE_INTEGERS(nbObjects, objectNames, nameIndices);
343 read_PILE_STRINGS(nbObjects, objectNames, nameIndices);
346 read_PILE_LMOTS(nbObjects, objectNames, nameIndices);
349 read_PILE_NOEUDS(nbObjects, objectNames, nameIndices);
351 case PILE_COORDONNEES:
352 read_PILE_COORDONNEES(nbObjects, objectNames, nameIndices);
355 read_PILE_MODL(nbObjects, objectNames, nameIndices);
358 read_PILE_FIELD(nbObjects, objectNames, nameIndices);
362 THROW_IK_EXCEPTION("XDR : reading PILE " << pileNumber << " not implemented !!!");
366 //================================================================================
368 * \brief Reads "PILE NUMERO 1": gibi sub-meshes that are converted into med groups
370 //================================================================================
372 void SauvReader::read_PILE_SOUS_MAILLAGE(const int nbObjects,
373 std::vector<std::string>& objectNames,
374 std::vector<int>& nameIndices)
376 _iMed->_groups.reserve(nbObjects*2); // fields may add some groups
379 map<int,int> strangeGroupType;
382 for (int object=0; object!=nbObjects; ++object) // loop on sub-groups
385 int castemCellType = getIntNext();
386 int nbSubGroups = getIntNext();
387 int nbReferences = getIntNext();
388 int nbNodesPerElem = getIntNext();
389 int nbElements = getIntNext();
391 _iMed->_groups.push_back(Group());
392 SauvUtilities::Group & group = _iMed->_groups.back();
394 // Issue 0021311. Allocate places for names of referring groups
395 // that will be possibly filled after reading long names from
396 // PILE_TABLES and PILE_STRINGS
397 group._refNames.resize( nbReferences );
399 // castemCellType=0 corresponds to a sub-mesh composed of other sub-meshes
400 if (castemCellType==0 && nbSubGroups>0)
402 group._groups.resize( nbSubGroups );
403 for ( initIntReading( nbSubGroups ); more(); next() )
404 group._groups[ index() ] = & _iMed->_groups[ getInt() - 1 ];
405 //std::sort( group._groups.begin(), group._groups.end() ); // for _groups comparison in getFieldSupport()
409 for ( i = 0; i < nbReferences; i += 10 ) // FORMAT(10I8)
412 for (initIntReading(nbReferences); more(); next());
416 for ( i = 0; i < nbElements; i += 10 )
419 for (initIntReading(nbElements); more(); next());
421 // not a composite group
422 if (castemCellType>0 && nbSubGroups==0)
424 group._cellType = SauvUtilities::gibi2medGeom(castemCellType);
426 initIntReading( nbElements * nbNodesPerElem );
427 if ( group._cellType == INTERP_KERNEL::NORM_ERROR ) // look for group end
429 for ( ; more(); next());
430 strangeGroupType.insert( make_pair( object, castemCellType ));
434 // if ( group._cellType == MED_POINT1 ) group._cellType = NORM_ERROR; // issue 21199
436 // read connectivity of elements of a group
437 SauvUtilities::Cell ma( nbNodesPerElem );
438 SauvUtilities::Node* pNode;
439 group._cells.resize( nbElements );
440 for ( i = 0; i < nbElements; ++i )
443 for ( int n = 0; n < nbNodesPerElem; ++n )
445 int nodeID = getIntNext();
446 pNode = _iMed->getNode( nodeID );
447 ma._nodes[n] = pNode;
448 _iMed->_nbNodes += ( !pNode->isUsed() );
449 pNode->_number = nodeID;
451 ma._number = _iMed->getNbCellsOfType( group._cellType ) + 1;
452 group._cells[i] = _iMed->insert( group._cellType, ma );
459 for (i=0; i!=(int)objectNames.size(); ++i)
461 int grpID = nameIndices[i];
462 SauvUtilities::Group & grp = _iMed->_groups[ grpID-1 ];
463 if ( !grp._name.empty() ) // a group has several names
464 { // create a group with subgroup grp and named grp.name
465 SauvUtilities::Group* newGroup = _iMed->addNewGroup();
466 newGroup->_groups.push_back( &_iMed->_groups[ grpID-1 ]);
467 newGroup->_name = grp._name;
469 grp._name=objectNames[i];
471 map<int,int>::iterator it = strangeGroupType.find( grpID - 1 );
472 if ( it != strangeGroupType.end() )
473 cout << "Skip " << grp._name << " of not supported CASTEM type: " << it->second << endl;
476 } // read_PILE_SOUS_MAILLAGE()
478 //================================================================================
480 * \brief Skip "PILE NUMERO 18" of XDR file
482 //================================================================================
484 void SauvReader::read_PILE_LREEL (const int nbObjects, std::vector<std::string>&, std::vector<int>&)
488 for (int object=0; object!=nbObjects; ++object) // pour chaque Group
491 int nb_vals = getIntNext();
492 initDoubleReading(nb_vals);
493 for(int i=0; i<nb_vals; i++) next();
498 //================================================================================
500 * \brief Skip "PILE NUMERO 24" of XDR file
502 //================================================================================
504 void SauvReader::read_PILE_LOGIQUES (const int, std::vector<std::string>&, std::vector<int>&)
509 int nb_vals = getIntNext();
510 initIntReading(nb_vals);
511 for(int i=0; i<nb_vals; i++) next();
515 //================================================================================
517 * \brief Skip "PILE NUMERO 25" of XDR file
519 //================================================================================
521 void SauvReader::read_PILE_FLOATS (const int, std::vector<std::string>&, std::vector<int>&)
526 int nb_vals = getIntNext();
527 initDoubleReading(nb_vals);
528 for(int i=0; i<nb_vals; i++) next();
532 //================================================================================
534 * \brief Skip "PILE NUMERO 26" of XDR file
536 //================================================================================
538 void SauvReader::read_PILE_INTEGERS (const int, std::vector<std::string>&, std::vector<int>&)
543 int nb_vals = getIntNext();
544 initIntReading(nb_vals);
545 for(int i=0; i<nb_vals; i++) next();
549 //================================================================================
551 * \brief Skip "PILE NUMERO 29" of XDR file
553 //================================================================================
555 void SauvReader::read_PILE_LMOTS (const int nbObjects, std::vector<std::string>&, std::vector<int>&)
559 for (int object=0; object!=nbObjects; ++object) // pour chaque Group
562 int len = getIntNext();
563 int nb_vals = getIntNext();
564 int nb_char = len*nb_vals;
566 int fixed_length = 71;
567 while (nb_char_tmp < nb_char)
569 int remain_len = nb_char - nb_char_tmp;
571 if ( remain_len > fixed_length )
573 width = fixed_length;
579 initNameReading(1, width);
581 nb_char_tmp += width;
587 //================================================================================
589 * \brief Skip "PILE NUMERO 38" of XDR file
591 //================================================================================
593 void SauvReader::read_PILE_MODL (const int nbObjects, std::vector<std::string>&, std::vector<int>&)
597 for (int object=0; object!=nbObjects; ++object) // pour chaque Group
601 int n1 = getIntNext();
602 int nm2 = getIntNext();
603 int nm3 = getIntNext();
604 int nm4 = getIntNext();
605 int nm5 = getIntNext();
606 int n45 = getIntNext();
607 /*int nm6 =*/ getIntNext();
608 /*int nm7 =*/ getIntNext();
613 for (initIntReading(nm1); more(); next());
614 for (initIntReading(nm9); more(); next());
615 for (initNameReading(nm5, 8); more(); next());
616 for (initNameReading(nm2, 8); more(); next());
617 for (initNameReading(nm3, 8); more(); next());
618 for (initIntReading(nm4); more(); next());
621 } // Fin case pile 38
623 //================================================================================
625 * \brief Read "PILE NUMERO 32": links to node coordinates
627 //================================================================================
629 void SauvReader::read_PILE_NOEUDS (const int nbObjects, std::vector<std::string>&, std::vector<int>&)
632 int nb_indices = getIntNext();
634 if (nb_indices != nbObjects)
635 THROW_IK_EXCEPTION("Error of reading PILE NUMERO " << PILE_NOEUDS << lineNb() );
637 for ( initIntReading( nbObjects ); more(); next() )
639 int coordID = getInt();
640 _iMed->getNode( index()+1 )->_coordID = coordID;
644 //================================================================================
646 * \brief Read "PILE NUMERO 33": node coordinates
648 //================================================================================
650 void SauvReader::read_PILE_COORDONNEES (const int nbObjects, std::vector<std::string>&, std::vector<int>&)
653 int nbReals = getIntNext();
655 if ( nbReals < (int)(_iMed->_nbNodes*(_iMed->_spaceDim+1)) )
656 THROW_IK_EXCEPTION("Error of reading PILE NUMERO " << PILE_COORDONNEES << lineNb() );
658 // there are coordinates + density for each node
659 _iMed->_coords.resize( nbReals - nbReals/(_iMed->_spaceDim+1));
660 double* coordPtr = &_iMed->_coords[0];
662 initDoubleReading( nbReals );
665 for (unsigned j = 0; j < _iMed->_spaceDim; ++j, next())
666 *coordPtr++ = getDouble();
673 //================================================================================
675 * \brief Find or create a Group equal to a given field support
677 //================================================================================
679 void SauvReader::setFieldSupport(const vector<SauvUtilities::Group*>& supports,
680 SauvUtilities::DoubleField* field)
682 SauvUtilities::Group* group = NULL;
683 set<SauvUtilities::Group*> sup_set( supports.begin(), supports.end() );
684 if ( sup_set.size() == 1 ) // one or equal supports
690 // check if sub-components are on cells of different types
691 map<int,int> nbGaussByCellType;
692 for ( size_t i = 0; i < supports.size(); ++i )
694 map<int,int>::iterator ct2ng = nbGaussByCellType.find( supports[i]->_cellType );
695 if ( ct2ng == nbGaussByCellType.end() )
696 nbGaussByCellType[ supports[i]->_cellType ] = field->_sub[i].nbGauss();
697 else if ( ct2ng->second != field->_sub[i].nbGauss() )
700 bool isSameCellType = ( nbGaussByCellType.size() == 1 );
701 // try to find an existing composite group with the same sub-groups
702 if ( isSameCellType )
703 for ( size_t i = 0; i < _iMed->_groups.size() && !group; ++i )
705 Group & grp = _iMed->_groups[i];
706 if (sup_set.size() == grp._groups.size())
708 bool sameOrder = true;
709 for ( size_t j = 0; j < supports.size() && sameOrder; ++j )
710 sameOrder = ( supports[j] == grp._groups[ j % grp._groups.size() ]);
712 group = & _iMed->_groups[i];
715 if ( !group ) // no such a group, add a new one
717 vector<SauvUtilities::Group*> newGroups( supports.begin(),
718 supports.begin() + sup_set.size() );
719 // check if supports includes newGroups in the same order
720 bool sameOrder = true;
721 for ( size_t j = newGroups.size(); j < supports.size() && sameOrder; ++j )
722 sameOrder = ( supports[j] == newGroups[ j % newGroups.size() ]);
725 group = _iMed->addNewGroup( & newGroups );
726 group->_groups.swap( newGroups );
729 // sort field sub-components and supports by cell type
730 if ( group && !isSameCellType )
733 vector<SauvUtilities::Group*>& groups = group->_groups;
734 bool isModified = false, isSwapped = true;
738 for ( size_t i = 1; i < groups.size(); ++i )
740 int nbN1 = groups[i-1]->empty() ? 0 : groups[i-1]->_cells[0]->_nodes.size();
741 int nbN2 = groups[i ]->empty() ? 0 : groups[i ]->_cells[0]->_nodes.size();
744 isSwapped = isModified = true;
745 std::swap( groups[i], groups[i-1] );
749 // relocate sub-components according to a new order of groups
752 vector< DoubleField::_Sub_data > newSub ( field->_sub.size() );
753 vector< vector< double > > newValues( field->_comp_values.size() );
754 size_t iFromSub = 0, iNewSub = 0, iNewComp = 0;
755 for ( ; iFromSub < field->_sub.size(); iFromSub += groups.size() )
757 size_t iFromComp = iNewComp;
758 for ( size_t iG = 0; iG < groups.size(); ++iG )
760 size_t iComp = iFromComp;
761 for ( size_t iSub = iFromSub; iSub < field->_sub.size(); ++iSub )
762 if ( field->_sub[ iSub ]._support == groups[ iG ] )
764 newSub[ iNewSub++ ] = field->_sub[ iSub ];
765 int iC = 0, nbC = field->_sub[ iSub ].nbComponents();
766 for ( ; iC < nbC; ++iC )
767 newValues[ iNewComp++ ].swap( field->_comp_values[ iComp++ ]);
772 iComp += field->_sub[ iSub ].nbComponents();
776 field->_sub.swap( newSub );
777 field->_comp_values.swap( newValues );
782 group->_isProfile = true;
784 field->_group = group;
787 //================================================================================
789 * \brief Set field names
791 //================================================================================
793 void SauvReader::setFieldNames(const vector<SauvUtilities::DoubleField* >& fields,
794 const vector<string>& objets_nommes,
795 const vector<int>& indices_objets_nommes)
798 for ( i = 0; i < indices_objets_nommes.size(); ++i )
800 int fieldIndex = indices_objets_nommes[ i ];
801 if ( fields[ fieldIndex - 1 ] )
802 fields[ fieldIndex - 1 ]->_name = objets_nommes[ i ];
806 //================================================================================
808 * \brief Read "PILE NUMERO 2": NODE FIELDS
810 //================================================================================
812 void SauvReader::read_PILE_NODES_FIELD (const int nbObjects,
813 std::vector<std::string>& objectNames,
814 std::vector<int>& nameIndices)
816 _iMed->_nodeFields.resize( nbObjects, (SauvUtilities::DoubleField*) 0 );
817 for (int object=0; object!=nbObjects; ++object) // loop on fields
819 // EXAMPLE ( with no values )
822 // (2) -88 0 3 -89 0 1 -90 0 2 -91
824 // (3) FX FY FZ FZ FX FY FLX
826 // (5) cree par muc pri
830 // (1): nb subcomponents, nb components(total), IFOUR, nb attributes
831 int nb_sub, total_nb_comp, nb_attr;
834 nb_sub = getIntNext();
835 total_nb_comp = getIntNext();
836 next(); // ignore IFOUR
837 nb_attr = getIntNext();
838 if ( nb_sub < 0 || total_nb_comp < 0 || nb_attr < 0 )
839 THROW_IK_EXCEPTION("Error of field reading " << lineNb());
841 // (2) loop on subcomponents of a field, for each read
842 // (a) support, (b) number of values and (c) number of components
843 vector<Group*> supports( nb_sub );
844 vector<int> nb_values ( nb_sub );
845 vector<int> nb_comps ( nb_sub );
846 int total_nb_values = 0;
847 initIntReading( nb_sub * 3 );
848 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
850 int supId = -getIntNext(); // (a) reference to support
851 if ( supId < 1 || supId > (int)_iMed->_groups.size() )
852 THROW_IK_EXCEPTION("Wrong mesh reference: "<< supId << lineNb() );
853 supports[ i_sub ] = &_iMed->_groups[ supId-1 ]; // (a) reference to support
855 nb_values[ i_sub ] = getIntNext(); // (b) nb points
856 total_nb_values += nb_values[ i_sub ];
857 if ( nb_values[ i_sub ] < 0 )
858 THROW_IK_EXCEPTION(" Wrong nb of points: " << nb_values[ i_sub ] << lineNb() );
859 nb_comps[ i_sub ] = getInt(); next(); // (c) nb of components in i_sub
862 // create a field if there are values
863 SauvUtilities::DoubleField* fdouble = 0;
864 if ( total_nb_values > 0 )
865 fdouble = new DoubleField( nb_sub, total_nb_comp );
866 _iMed->_nodeFields[ object ] = fdouble;
868 // (3) component names
869 initNameReading( total_nb_comp, 4 );
870 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
872 // store support id and nb components of a sub
874 fdouble->_sub[ i_sub ].setData( nb_comps[ i_sub ], supports[ i_sub ] );
875 for ( i_comp = 0; i_comp < nb_comps[ i_sub ]; ++i_comp, next() )
877 // store component name
878 string compName = getName();
880 fdouble->_sub[ i_sub ].compName( i_comp ) = compName;
883 // (4) nb harmonics ( ignored )
884 for ( initIntReading( total_nb_comp ); more(); next() );
885 // (5) TYPE ( ignored )
886 for (initNameReading(1, /*length=*/71); more(); next());
887 // (6) TITRE ( ignored )
888 for (initNameReading(1, /*length=*/71); more(); next());
889 // (7) attributes ( ignored )
890 for ( initIntReading( nb_attr ); more(); next() );
892 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
894 // loop on components: read values
895 initDoubleReading( nb_values[ i_sub ] * nb_comps[ i_sub ] );
896 for ( i_comp = 0; i_comp < nb_comps[ i_sub ]; ++i_comp )
900 vector<double>& vals = fdouble->addComponent( nb_values[ i_sub ] );
901 for ( int i = 0; more() && i < nb_values[ i_sub ]; next(), ++i )
902 vals[ i ] = getDouble();
906 for ( int i = 0; i < nb_values[ i_sub ]; next(), ++i );
909 } // loop on subcomponents of a field
911 // set a supporting group including all subs supports but only
912 // if all subs have the same components
913 if ( fdouble && fdouble->hasSameComponentsBySupport() )
914 setFieldSupport( supports, fdouble );
916 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
917 fdouble->_sub[ i_sub ]._support->_isProfile = true;
919 } // end loop on field objects
922 setFieldNames( _iMed->_nodeFields, objectNames, nameIndices );
924 } // read_PILE_NODES_FIELD()
926 //================================================================================
928 * \brief Read "PILE NUMERO 39": FIELDS
930 //================================================================================
932 void SauvReader::read_PILE_FIELD (const int nbObjects,
933 std::vector<std::string>& objectNames,
934 std::vector<int>& nameIndices)
939 // (2) CARACTERISTIQUES
940 // (3) -15 317773 4 0 0 0 -2 0 3
943 // (6) 317767 317761 317755 317815
944 // (7) YOUN NU H SIGY
945 // (8) REAL*8 REAL*8 REAL*8 REAL*8
947 // (10) 2.00000000000000E+05
949 // (12) 3.30000000000000E-01
951 // (14) 1.00000000000000E+04
953 // (16) 1.00000000000000E+02 1.00000000000000E+02 1.00000000000000E+02
954 // (17) 1.00000000000000E+02 1.00000000000000E+02 1.00000000000000E+02
957 _iMed->_cellFields.resize( nbObjects, (SauvUtilities::DoubleField*) 0 );
958 for (int object=0; object!=nbObjects; ++object) // pour chaque field
961 int i_sub, nb_sub = getIntNext(); // (1) <nb_sub> 2 6 <title length>
964 int title_length = getIntNext(); // <title length>
966 THROW_IK_EXCEPTION("Error of field reading: wrong nb of subcomponents " << nb_sub << lineNb() );
973 initNameReading(1, title_length);
974 description = getName();
980 getNextLine( line ); // (2) title
981 const int len = 72; // line length
982 description = string(line + len - title_length, title_length); // title is right justified
985 // look for a line starting with '-' : <reference to support>
988 initIntReading( nb_sub * 9 );
993 initIntReading( nb_sub * 9 );
994 } while ( getInt() >= 0 );
996 int total_nb_comp = 0;
997 vector<Group*> supports( nb_sub );
998 vector<int> nb_comp( nb_sub );
999 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
1001 int supportId = -getIntNext(); // <reference to support>
1002 next(); // ignore <address>
1003 nb_comp [ i_sub ] = getIntNext(); // <nb of components in the sub>
1004 for ( int i = 0; i < 6; ++i ) next(); // ignore 6 ints, in example "0 0 0 -2 0 3"
1006 if ( supportId < 1 || supportId > (int)_iMed->_groups.size() )
1007 THROW_IK_EXCEPTION("Error of field reading: wrong mesh reference "<< supportId << lineNb() );
1008 if ( nb_comp[ i_sub ] < 0 )
1009 THROW_IK_EXCEPTION("Error of field reading: wrong nb of components " <<nb_comp[ i_sub ] << lineNb() );
1011 supports[ i_sub ] = &_iMed->_groups[ supportId-1 ];
1012 total_nb_comp += nb_comp[ i_sub ];
1014 // (4) dummy strings
1015 for ( initNameReading( nb_sub, 17 ); more(); next() );
1016 // (5) dummy strings
1017 for ( initNameReading( nb_sub ); more(); next() );
1019 // loop on subcomponents of a field, each of which refers to
1020 // a certain support and has its own number of components;
1021 // read component values
1022 SauvUtilities::DoubleField* fdouble = 0;
1023 for ( i_sub = 0; i_sub < nb_sub; ++ i_sub )
1025 vector<string> comp_names( nb_comp[ i_sub ]), comp_type( nb_comp[ i_sub ]);
1026 // (6) nb_comp addresses of MELVAL structure
1027 for ( initIntReading( nb_comp[ i_sub ] ); more(); next() );
1028 // (7) component names
1029 for ( initNameReading( nb_comp[ i_sub ] ); more(); next() )
1030 comp_names[ index() ] = getName();
1031 // (8) component type
1032 for ( initNameReading( nb_comp[ i_sub ], 17 ); more(); next() ) // 17 is name width
1034 comp_type[ index() ] = getName();
1035 // component types must be the same
1036 if ( index() > 0 && comp_type[ index() ] != comp_type[ index() - 1] )
1037 THROW_IK_EXCEPTION( "Error of field reading: diff component types <"
1038 << comp_type[ index() ] << "> != <" << comp_type[ index() - 1 ]
1039 << ">" << lineNb() );
1041 // now type is known, create a field, one for all subs
1042 bool isReal = (nb_comp[i_sub] > 0) ? (comp_type[0] == "REAL*8") : true;
1043 if ( !fdouble && total_nb_comp )
1046 cout << "Warning: read NOT REAL field, type <" << comp_type[0] << ">" << lineNb() << endl;
1047 _iMed->_cellFields[ object ] = fdouble = new SauvUtilities::DoubleField( nb_sub, total_nb_comp );
1048 fdouble->_description = description;
1050 // store support id and nb components of a sub
1052 fdouble->_sub[ i_sub ].setData( nb_comp[ i_sub ], supports[ i_sub ]);
1053 // loop on components: read values
1054 for ( int i_comp = 0; i_comp < nb_comp[ i_sub ]; ++i_comp )
1057 initIntReading( 4 );
1058 int nb_val_by_elem = getIntNext();
1059 int nb_values = getIntNext();
1062 fdouble->_sub[ i_sub ]._nb_gauss[ i_comp ] = nb_val_by_elem;
1065 nb_values *= nb_val_by_elem;
1068 vector<double> & vals = fdouble->addComponent( nb_values );
1069 for ( isReal ? initDoubleReading( nb_values ) : initIntReading( nb_values ); more(); next())
1070 vals[ index() ] = getDouble();
1071 // store component name
1072 fdouble->_sub[ i_sub ].compName( i_comp ) = comp_names[ i_comp ];
1076 for ( isReal ? initDoubleReading( nb_values ) : initIntReading( nb_values ); more(); next() ) ;
1079 } // loop on subcomponents of a field
1081 // set id of a group including all sub supports but only
1082 // if all subs have the same nb of components
1083 if ( fdouble && fdouble->hasSameComponentsBySupport() )
1084 setFieldSupport( supports, fdouble );
1086 for ( i_sub = 0; i_sub < nb_sub; ++i_sub )
1087 fdouble->_sub[ i_sub ]._support->_isProfile = true;
1089 } // end loop on field objects
1092 setFieldNames( _iMed->_cellFields, objectNames, nameIndices );
1094 } // read_PILE_FIELD()
1096 //================================================================================
1098 * \brief Read "PILE NUMERO 10": TABLES
1100 //================================================================================
1102 void SauvReader::read_PILE_TABLES (const int nbObjects,
1103 std::vector<std::string>& objectNames,
1104 std::vector<int>& nameIndices)
1106 // IMP 0020434: mapping GIBI names to MED names
1108 string table_med_mail = "MED_MAIL";
1109 string table_med_cham = "MED_CHAM";
1110 string table_med_comp = "MED_COMP";
1111 int table_med_mail_id = -1;
1112 int table_med_cham_id = -1;
1113 int table_med_comp_id = -1;
1114 for (size_t iname = 0; iname < objectNames.size(); iname++)
1115 if (objectNames[iname] == table_med_mail) table_med_mail_id = nameIndices[iname];
1116 else if (objectNames[iname] == table_med_cham) table_med_cham_id = nameIndices[iname];
1117 else if (objectNames[iname] == table_med_comp) table_med_comp_id = nameIndices[iname];
1120 if (table_med_mail_id < 0 && table_med_cham_id < 0 && table_med_comp_id < 0)
1123 for (int itable = 1; itable <= nbObjects; itable++)
1125 // read tables "MED_MAIL", "MED_CHAM" and "MED_COMP", that keeps correspondence
1126 // between GIBI names (8 symbols if any) and MED names (possibly longer)
1128 int nb_table_vals = getIntNext();
1129 if (nb_table_vals < 0)
1130 THROW_IK_EXCEPTION("Error of reading PILE NUMERO 10" << lineNb() );
1132 int name_i_med_pile;
1133 initIntReading(nb_table_vals);
1134 for (int i = 0; i < nb_table_vals/4; i++)
1136 if (itable == table_med_mail_id ||
1137 itable == table_med_cham_id ||
1138 itable == table_med_comp_id)
1140 nameGIBItoMED name_i;
1141 name_i_med_pile = getIntNext();
1142 name_i.med_id = getIntNext();
1143 name_i.gibi_pile = getIntNext();
1144 name_i.gibi_id = getIntNext();
1146 if (name_i_med_pile != PILE_STRINGS)
1148 // error: med(long) names are always kept in PILE_STRINGS
1150 if (itable == table_med_mail_id)
1152 if (name_i.gibi_pile != PILE_SOUS_MAILLAGE) {
1153 // error: must be PILE_SOUS_MAILLAGE
1155 _iMed->_listGIBItoMED_mail.push_back(name_i);
1157 else if (itable == table_med_cham_id)
1159 if (name_i.gibi_pile != PILE_FIELD &&
1160 name_i.gibi_pile != PILE_NODES_FIELD)
1162 // error: must be PILE_FIELD or PILE_NODES_FIELD
1164 _iMed->_listGIBItoMED_cham.push_back(name_i);
1166 else if (itable == table_med_comp_id)
1168 if (name_i.gibi_pile != PILE_STRINGS)
1170 // error: gibi(short) names of components are kept in PILE_STRINGS
1172 _iMed->_listGIBItoMED_comp.push_back(name_i);
1178 for ( int ii = 0; ii < 4; ++ii ) next();
1181 } // for (int itable = 0; itable < nbObjects; itable++)
1184 //================================================================================
1186 * \brief Read "PILE NUMERO 27"
1188 //================================================================================
1190 void SauvReader::read_PILE_STRINGS (const int nbObjects,
1191 std::vector<std::string>& objectNames,
1192 std::vector<int>& nameIndices)
1194 // IMP 0020434: mapping GIBI names to MED names
1196 int stringLen = getIntNext();
1197 int nbSubStrings = getIntNext();
1198 if (nbSubStrings != nbObjects)
1199 THROW_IK_EXCEPTION("Error of reading PILE NUMERO 27" << lineNb() );
1201 string aWholeString;
1204 const int fixedLength = 71;
1205 while ((int)aWholeString.length() < stringLen)
1207 int remainLen = stringLen - aWholeString.length();
1209 if ( remainLen > fixedLength )
1217 initNameReading(1, len);
1218 aWholeString += getName();
1225 const int fixedLength = 71;
1226 while ((int)aWholeString.length() < stringLen)
1228 getNextLine( line );
1229 int remainLen = stringLen - aWholeString.length();
1230 if ( remainLen > fixedLength )
1232 aWholeString += line + 1;
1236 aWholeString += line + ( 72 - remainLen );
1242 initIntReading(nbSubStrings);
1243 for (int istr = 1; istr <= nbSubStrings; istr++, next())
1245 currOffset = getInt();
1247 _iMed->_mapStrings[istr] = aWholeString.substr(prevOffset, currOffset - prevOffset);
1248 prevOffset = currOffset;