1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #include "MEDMEM_Utilities.hxx"
28 #include "MEDMEM_Field.hxx"
29 #include "MEDMEM_EnsightUtils.hxx"
31 #define TStrTool _ASCIIFileReader
33 using namespace MED_EN;
34 using namespace MEDMEM_ENSIGHT;
38 // ==============================================================================
40 * \brief Iterator on specified values of a field component
42 template <typename T> class _SelectedValueIterator
49 _SelectedValueIterator() // by default next() returns zero
50 : myDelta( 0 ), myPtr (_ValueIterator<T>::zeroPtr()),
51 myIndexDelta( 0 ), myIndex(_ValueIterator<int>::zeroPtr()) {}
53 _SelectedValueIterator(const T* values, int delta, const int* index)
54 : myDelta( delta ), myPtr(values), myIndexDelta(1), myIndex(index-1) {}
56 const T & next() { myIndex += myIndexDelta; return myPtr[ (*myIndex) * myDelta ]; }
59 // ==============================================================================
61 * \brief Container of values of any type to read/write from/to EnSight variable.
62 * It stores values relating to one element type within a part
67 const char * myValues;
68 medModeSwitch myInterlace;
69 bool myOwnValues; // to delete or not myValues
70 string myConstValue; // if myConstValue is set, other members are meaningless
72 // for writing values of a field-on-all-entities for a group
73 const int * myNumbers;
76 set<int> myUndefIndices;
77 vector<int> myPartialIndices;
79 _SubPartValues(const _SubPart& sub=_SubPart())
80 : mySubPart(sub), myValues(0), myInterlace(MED_NO_INTERLACE), myOwnValues(true) {};
82 ~_SubPartValues() { clear(); }
83 void clear() { if ( myOwnValues ) delete [] myValues; myValues = 0; }
85 // -------------------------------------------------------------------
86 //!< copying removes data from the source object
87 _SubPartValues(const _SubPartValues& other)
88 :mySubPart(other.mySubPart), myValues(other.myValues),
89 myInterlace(other.myInterlace), myOwnValues(true)
90 { ((_SubPartValues&)other).myValues=0; }
92 // -------------------------------------------------------------------
93 //!< Return iterator on values of a component counted from 1
94 // nbElements is a number of values of a component located one by one in
96 template <typename T> _ValueIterator<T>
97 getValues( int component, int nbElements, int nbComponents ) const
99 const T* values = (T*) myValues;
100 if ( myInterlace == MED_FULL_INTERLACE ) {
101 values += (component - 1);
102 return _ValueIterator<T>( values, nbComponents );
105 values += (component - 1) * nbElements;
106 return _ValueIterator<T>( values, 1 );
109 // -------------------------------------------------------------------
110 //!< Return iterator on specified values of a component counted from 1.
111 // nbElements is a number of values of a component located one by one in
112 // not full interlace
113 template <typename T> _SelectedValueIterator<T>
114 getSelectedValues( int component, int nbElements, int nbComponents ) const
116 // Values are specified by myNumbers. myValues points to the value
117 // relating to myNumbers[0] element.
118 const T* values = (T*) myValues;
119 if ( myInterlace == MED_FULL_INTERLACE ) {
120 values -= myNumbers[0] * nbComponents;
121 values += (component - 1);
122 return _SelectedValueIterator<T>( values, nbComponents, myNumbers );
125 values -= myNumbers[0];
126 values += (component - 1) * nbElements;
127 return _SelectedValueIterator<T>( values, 1, myNumbers );
130 // -------------------------------------------------------------------
131 //!< Return iterators on all values of all components
132 template <typename T> vector< _ValueIterator<T> >
133 getAllValues( int nbElements, int nbComponents, bool add3dComp ) const
135 // add the 3-d component to a vector in 2D space
136 int addComp = ( add3dComp && nbComponents == 2 ) ? 1 : 0;
137 vector< _ValueIterator<T> > compValIt( nbComponents + addComp);
138 for ( int j = 1; j <= nbComponents; ++j )
139 compValIt[ j-1 ] = getValues<T>( j, nbElements, nbComponents );
142 // -------------------------------------------------------------------
143 //!< Return iterators on specified values for all components
144 template <typename T> vector< _SelectedValueIterator<T> >
145 getAllSelectedValues( int nbElements, int nbComponents, bool add3dComp ) const
147 // add the 3-d component to a vector in 2D space
148 int addComp = ( add3dComp && nbComponents == 2 ) ? 1 : 0;
149 vector< _SelectedValueIterator<T> > compValIt( nbComponents + addComp);
150 for ( int j = 1; j <= nbComponents; ++j )
151 compValIt[ j-1 ] = getSelectedValues<T>( j, nbElements, nbComponents );
156 //=======================================================================
158 use file reader to get values of a _SubPart
160 template <class FileReader>
161 void readSubPartValues( FileReader& reader,
163 _SubPartValues & subValues)
165 medEntityMesh entity = field->getSupport()->getEntity();
166 int nbComponents = field->getNumberOfComponents();
169 if ( entity == MED_NODE )
170 nbElements = subValues.mySubPart.myNbNodes;
172 nbElements = subValues.mySubPart.myNbCells;
174 int nbValues = nbElements * nbComponents;
178 const char* undefValue = 0;
179 set<int>* undefIndices = &subValues.myUndefIndices;
180 vector<int>* partial = 0;
181 if ( !subValues.myUndefValue.empty() )
182 undefValue = subValues.myUndefValue.c_str();
183 if ( !subValues.myPartialIndices.empty() )
184 partial = &subValues.myPartialIndices;
186 if ( field->getValueType() == MED_REEL64 )
187 subValues.myValues = reader.template convertReals<double>( nbValues,
188 undefValue, undefIndices,
189 partial, nbComponents );
190 else if ( field->getValueType() == MED_INT32 )
191 subValues.myValues = reader.template convertReals<int> ( nbValues,
192 undefValue, undefIndices,
193 partial, nbComponents );
195 subValues.myValues = reader.template convertReals<long> ( nbValues,
196 undefValue, undefIndices,
197 partial, nbComponents );
198 // convert partial indices into undef indices
199 if ( !subValues.myPartialIndices.empty() )
202 set<int> sortedPartial;
203 vector<int>::iterator p = partial->begin(), pEnd = partial->end();
205 sortedPartial.insert( sortedPartial.end(), *p++ );
208 // fill undef indices
209 set<int> & undef = subValues.myUndefIndices;
210 set<int>::iterator sp = sortedPartial.begin();
212 for ( ; sp != sortedPartial.end() && i <= nbElements; ++i, ++sp ) {
214 undef.insert( undef.end(), i++ );
216 while ( i <= nbElements )
217 undef.insert( undef.end(), i++ );
220 //=======================================================================
222 set values to an array
224 template <class T, class TMailIter, class TArray >
225 void _setValuesToArray( vector< _ValueIterator<T> > & compValIt,
229 _Support* interSupport,
230 const set<int>& localUndefIndices,
231 set<int> & globalUndefIndices)
233 int nbComponents = array->getDim();
234 if ( localUndefIndices.empty() )
236 for ( int c = 0; c < nbValues; ++c, ++cellIt )
238 int i = interSupport->getIndex( *cellIt );
239 for ( int j = 1; j <= nbComponents; ++j )
240 array->setIJ( i, j, compValIt[ j ].next() );
245 // set values from the first till undefined end
246 set<int>::const_iterator undef = localUndefIndices.begin();
247 int c = 1, last = min( nbValues, *localUndefIndices.rbegin() );
248 for ( ; c <= last; ++c, ++cellIt )
250 int i = interSupport->getIndex( *cellIt );
252 globalUndefIndices.insert( i );
255 for ( int j = 1; j <= nbComponents; ++j )
256 array->setIJ( i, j, compValIt[ j ].next() );
258 // set all the rest values
259 for ( ; c <= nbValues; ++c, ++cellIt )
261 int i = interSupport->getIndex( *cellIt );
262 for ( int j = 1; j <= nbComponents; ++j )
263 array->setIJ( i, j, compValIt[ j ].next() );
268 //================================================================================
270 * \brief creates a new support excluding undef indices
272 //================================================================================
274 SUPPORT* makeShiftedSupport(const SUPPORT* support,
275 const set<int> undefIndices)
277 int nbElements = support->getNumberOfElements(MED_ALL_ELEMENTS);
278 int nbTypes = support->getNumberOfTypes();
281 set<int>::const_iterator undef;
283 // shift support numbers
284 int * index = new int[ nbTypes + 1 ];
285 int * number = new int[ nbElements - undefIndices.size() ];
286 if ( support->isOnAllElements() ) {
287 // make shifted number
288 int * numberPtr = number;
289 for ( i = 0, undef = undefIndices.begin(); undef != undefIndices.end(); ++undef )
290 while ( ++i < *undef )
292 while ( ++i <= nbElements )
294 // fill index but without shift
295 const int * oldNbElemByType = support->getNumberOfElements();
297 for ( int t = 0; t < nbTypes; ++t )
298 index[ t+1 ] = index[ t ] + oldNbElemByType[ t ];
301 // shift existing number
303 const int * oldNumber = support->getNumber( MED_ALL_ELEMENTS );
304 std::copy( oldNumber, oldNumber + *undefIndices.begin()-1, number ); // copy [0:firstUndef]
305 for ( undef = undefIndices.begin(); undef != undefIndices.end(); ) {
307 int nextUndef = ( undef != undefIndices.end() ) ? *undef : nbElements + 1;
308 while ( ++i < nextUndef )
309 number[ i-1 - shitf ] = oldNumber[ i-1 ]; // shift number
313 const int * oldIndex = support->getNumberIndex();
314 std::copy( oldIndex, oldIndex + nbTypes + 1, index );
318 set<int>::const_reverse_iterator undef = undefIndices.rbegin();
319 for ( ; undef != undefIndices.rend(); ++undef ) {
320 for ( int t = nbTypes; t ; --t )
321 if ( *undef < index[ t ] )
327 // count number of elements by type
328 vector<int> nbElem( nbTypes );
329 for ( int t = 0; t < nbTypes; ++t )
330 nbElem[ t ] = index[ t+1 ] - index[ t ];
332 SUPPORT* newSup = new SUPPORT();
333 newSup->setMesh ( support->getMesh() );
334 newSup->setNumberOfGeometricType( nbTypes );
335 newSup->setGeometricType ( support->getTypes() );
336 newSup->setNumberOfElements ( &nbElem[0] );
337 newSup->setNumber ( index, number, /*shallowCopy =*/ true );
338 newSup->setEntity ( support->getEntity() );
339 newSup->setAll ( false );
344 //=======================================================================
346 set values to a field
348 template <class T, class INTERLACE>
349 void _setValuesToField( FIELD<T,INTERLACE>* field,
350 _Support* interSupport,
351 list<_SubPartValues> & subPartValues )
353 medEntityMesh entity = field->getSupport()->getEntity();
354 SUPPORT* support = interSupport->medSupport( entity );
355 field->setSupport( support );
357 int j, nbComponents = field->getNumberOfComponents();
358 int nbElements = field->getSupport()->getNumberOfElements(MED_ALL_ELEMENTS);
360 typedef typename MEDMEM_ArrayInterface<T,INTERLACE,NoGauss>::Array TArray;
362 const string& constValue = subPartValues.front().myConstValue;
363 if ( !constValue.empty() )
365 vector<T> values(nbComponents * nbElements, (T)atof(constValue.c_str()));
366 field->setArray( new TArray( &values[0], nbComponents, nbElements ));
367 field->setNumberOfValues( nbElements );
371 field->allocValue( nbComponents, nbElements );
372 TArray * array = field->getArrayNoGauss();
374 set<int> undefIndices; // indices of undefined values
376 // loop on subParts conatining ensight field values
377 list<_SubPartValues>::iterator subValue = subPartValues.begin();
378 for ( ; subValue != subPartValues.end(); ++subValue )
380 _SubPart & subPart = subValue->mySubPart;
381 int nbValues = entity==MED_NODE ? subPart.myNbNodes : subPart.myNbCells;
384 // value iterator for each component
385 vector< _ValueIterator<T> > compValIt( nbComponents+1 );
386 for ( j = 1; j <= nbComponents; ++j )
387 compValIt[ j ] = subValue->template getValues<T>( j, nbValues, nbComponents );
391 if ( entity == MED_NODE ) {
392 map< int, _noeud >::iterator inode = subPart.myFirstNode;
393 _setValuesToArray( compValIt, nbValues, array, inode, interSupport,
394 subValue->myUndefIndices, undefIndices );
397 _groupe::TMailleIter cell = subPart.myFirstCell;
398 _setValuesToArray( compValIt, nbValues, array, cell, interSupport,
399 subValue->myUndefIndices, undefIndices );
403 if ( !undefIndices.empty() )
405 // Some values are undefined; it's necessary to compact values in the array
406 // and create a new support of defined numbers only.
410 set<int>::iterator undef = undefIndices.begin();
411 while ( undef != undefIndices.end() ) {
413 int nextUndef = ( undef != undefIndices.end() ) ? *undef : nbElements + 1;
414 while ( ++i < nextUndef ) {
415 for ( int j = 1; j <= nbComponents; ++j )
416 array->setIJ( i - shitf, j, array->getIJ( i, j )); // shift value
417 //number[ i-1 - shitf ] = oldNumber[ i-1 ]; // shift number
421 array->_nbelem -= undefIndices.size();
422 array->_arraySize = array->_nbelem * nbComponents;
424 support = makeShiftedSupport( support, undefIndices );
425 support->setName( STRING("Partial for ") << field->getName() );
426 field->setSupport( support );
427 field->setNumberOfValues( array->_nbelem );
429 if ( support->getName().empty() )
430 support->setName( STRING("Support for ") << field->getName() );
433 //=======================================================================
435 set values to a field
437 void setValuesToField( FIELD_* field,
438 _Support* interSupport,
439 list<_SubPartValues> & subPartValues )
441 switch ( field->getInterlacingType() ) {
442 case MED_FULL_INTERLACE:
443 if ( field->getValueType() == MED_REEL64 )
444 _setValuesToField( static_cast< FIELD<double, FullInterlace>* >( field ),
445 interSupport, subPartValues );
447 _setValuesToField( static_cast< FIELD<int, FullInterlace>* >( field ),
448 interSupport, subPartValues );
450 case MED_NO_INTERLACE:
451 if ( field->getValueType() == MED_REEL64 )
452 _setValuesToField( static_cast< FIELD<double, NoInterlace>* >( field ),
453 interSupport, subPartValues );
455 _setValuesToField( static_cast< FIELD<int, NoInterlace>* >( field ),
456 interSupport, subPartValues );
458 case MED_NO_INTERLACE_BY_TYPE:
459 if ( field->getValueType() == MED_REEL64 )
460 _setValuesToField( static_cast< FIELD<double, NoInterlaceByType>* >( field ),
461 interSupport, subPartValues );
463 _setValuesToField( static_cast< FIELD<int, NoInterlaceByType>* >( field ),
464 interSupport, subPartValues );
471 //================================================================================
473 * \brief Return node numbers of a non-nodal support
475 //================================================================================
477 int* getNodeNumbers( const SUPPORT* support, int & nbNodes )
479 map<int, int> nodeNumbers;
480 _CaseFileDriver_User::getSupportNodes( support, nodeNumbers );
481 nbNodes = nodeNumbers.size();
482 int* nNumbers = new int[ nbNodes ];
483 int* nPtr = nNumbers;
484 map<int, int>::iterator n = nodeNumbers.begin(), nEnd = nodeNumbers.end();
486 *nPtr++ = n->first, n++;
493 //=======================================================================
497 ENSIGHT_FIELD_DRIVER::ENSIGHT_FIELD_DRIVER():
498 _CaseFileDriver_User(),
499 _ptrField((FIELD_ *) 0)
501 //=======================================================================
505 ENSIGHT_FIELD_DRIVER::ENSIGHT_FIELD_DRIVER(const string & fileName,
507 med_mode_acces accessMode):
508 _CaseFileDriver_User(fileName,accessMode),
509 _ptrField((FIELD_ *) ptrField)
512 //=======================================================================
516 ENSIGHT_FIELD_DRIVER::ENSIGHT_FIELD_DRIVER(const ENSIGHT_FIELD_DRIVER & fieldDriver):
517 _CaseFileDriver_User(fieldDriver),
518 _ptrField(fieldDriver._ptrField),
519 _fieldName(fieldDriver._fieldName)
522 //=======================================================================
524 Take missing data from other driver.
526 void ENSIGHT_FIELD_DRIVER::merge ( const GENDRIVER& driver )
528 _CaseFileDriver_User::merge( driver );
530 const ENSIGHT_FIELD_DRIVER* other = dynamic_cast< const ENSIGHT_FIELD_DRIVER* >( &driver );
533 _ptrField = other->_ptrField;
534 if ( _constantValue.empty() )
535 _constantValue = other->_constantValue;
536 // _fieldName is copied by GENDRIVER
539 //=======================================================================
543 ENSIGHT_FIELD_DRIVER::~ENSIGHT_FIELD_DRIVER()
546 //=======================================================================
548 Set the name of the FIELD in EnSight file
550 void ENSIGHT_FIELD_DRIVER::setFieldName(const string & fieldName) throw (MEDEXCEPTION)
552 const char* LOC = "ENSIGHT_FIELD_DRIVER::setFieldName(): ";
553 if ( fieldName.size() > MAX_FIELD_NAME_LENGTH )
554 throw MEDEXCEPTION( compatibilityPb(LOC) << "too long name (> " <<
555 MAX_FIELD_NAME_LENGTH << "): " << fieldName);
557 // look for illegal characters
558 string::size_type pos = fieldName.find_first_of( ILLEGAL_FIELD_NAME_CHARACTERS );
559 if ( pos != fieldName.npos )
560 throw MEDEXCEPTION( compatibilityPb(LOC) << "Character " << pos << " (" << fieldName[pos] <<
561 ") "<< " in " << fieldName << " is not allowed in field name in EnSight\n"
562 "The illegal characters are: '" << ILLEGAL_FIELD_NAME_CHARACTERS << "'");
563 _fieldName = fieldName;
565 //=======================================================================
567 Check possibility to open a case file or a data file
569 void ENSIGHT_FIELD_DRIVER::openConst(bool checkDataFile) const throw (MEDEXCEPTION)
571 const char * LOC ="ENSIGHT_FIELD_DRIVER::open() : ";
576 if ( !getConstantValue().empty() )
577 return; // constant value is either stored in case file or is read by _CaseFileDriver
579 if ( getDataFileName().empty() )
581 ( LOCALIZED( STRING(LOC) << "Internal error, variable file name is empty"));
583 if (!canOpenFile( getDataFileName(), getAccessMode() ))
585 ( LOCALIZED( STRING(LOC) << "Can not open Ensight Variable file " << getDataFileName()
586 << " in access mode " << getAccessMode()));
590 if ( getCaseFileName().empty() )
592 ( LOCALIZED( STRING(LOC) << "Case file name is empty, "
593 "please set a correct fileName before calling open()"));
595 if ( !canOpenFile( getCaseFileName(), getAccessMode() ))
597 ( LOCALIZED( STRING(LOC) << "Can not open Ensight Case file " << getCaseFileName()
598 << " in access mode " << getAccessMode()));
603 // ==========================================================================================
604 //function : ENSIGHT_FIELD_RDONLY_DRIVER
606 ENSIGHT_FIELD_RDONLY_DRIVER::ENSIGHT_FIELD_RDONLY_DRIVER()
607 :ENSIGHT_FIELD_DRIVER(), _fieldStep(1)
611 //=======================================================================
613 Constructor to read a field of index-th time step
615 //=======================================================================
617 ENSIGHT_FIELD_RDONLY_DRIVER::ENSIGHT_FIELD_RDONLY_DRIVER(const string & fileName,
620 :ENSIGHT_FIELD_DRIVER(fileName,ptrField,MED_EN::RDONLY),_fieldStep(step)
624 //=======================================================================
625 //function : ENSIGHT_FIELD_RDONLY_DRIVER
626 //=======================================================================
628 ENSIGHT_FIELD_RDONLY_DRIVER::ENSIGHT_FIELD_RDONLY_DRIVER(const ENSIGHT_FIELD_RDONLY_DRIVER & drv)
629 :ENSIGHT_FIELD_DRIVER(drv),_fieldStep(drv._fieldStep)
633 //=======================================================================
634 //function : ~ENSIGHT_FIELD_RDONLY_DRIVER
635 //=======================================================================
637 ENSIGHT_FIELD_RDONLY_DRIVER::~ENSIGHT_FIELD_RDONLY_DRIVER()
642 //=======================================================================
644 //=======================================================================
646 GENDRIVER * ENSIGHT_FIELD_RDONLY_DRIVER::copy(void) const
648 ENSIGHT_FIELD_RDONLY_DRIVER * myDriver = new ENSIGHT_FIELD_RDONLY_DRIVER(*this);
652 //=======================================================================
653 // Take missing data from other driver.
654 //=======================================================================
656 void ENSIGHT_FIELD_RDONLY_DRIVER::merge ( const GENDRIVER& driver )
658 ENSIGHT_FIELD_DRIVER::merge( driver );
660 const ENSIGHT_FIELD_RDONLY_DRIVER* other =
661 dynamic_cast< const ENSIGHT_FIELD_RDONLY_DRIVER* >( &driver );
663 if ( _fieldStep < other->_fieldStep )
664 _fieldStep = other->_fieldStep;
668 //=======================================================================
670 //=======================================================================
672 void ENSIGHT_FIELD_RDONLY_DRIVER::read (void)
675 const char * LOC = "ENSIGHT_FIELD_RDONLY_DRIVER::read() : " ;
678 openConst(false); // check if can read case file
680 _CaseFileDriver caseFile( getCaseFileName(), this);
683 // find out index of variable to read
684 int variableIndex = caseFile.getVariableIndex( _fieldName );
685 if ( !variableIndex )
686 variableIndex = caseFile.getVariableIndex( _ptrField->getName() );
687 if ( !variableIndex ) {
688 if ( !_fieldName.empty() )
690 (LOCALIZED(STRING(LOC) << "no field found by name |" << _fieldName << "|"));
693 (LOCALIZED(STRING(LOC) << "no field found by name |" << _ptrField->getName() << "|"));
696 // here data from Case File is passed:
698 // * number of components
700 caseFile.setDataFileName( variableIndex, _fieldStep, this );
702 openConst(true); // check if can read data file
704 getInterData(); // get data on nb of entities by type and on their relocation
706 cout << "-> Entering into the field file " << getDataFileName() << endl ;
708 if ( !getConstantValue().empty() )
710 // Create a constant value field
712 medEntityMesh entity = MED_CELL;
713 GROUP* support = new GROUP;
714 support->setName( string("SupportOnAll_")+entNames[entity]);
715 support->setMesh( getInterData()->_medMesh );
716 support->setAll( true );
717 support->setEntity( entity );
721 interGroup.medGroup = support;
722 _Support interSupport;
723 interSupport.setGroup( &interGroup );
725 list<_SubPartValues> subPartValues( 1 );
726 subPartValues.back().myConstValue = getConstantValue();
728 setValuesToField( _ptrField, &interSupport, subPartValues );
734 if ( isBinaryDataFile( getDataFileName() ) ) // binary
736 if ( isGoldFormat() ) // Gold
747 if ( isGoldFormat() ) // Gold
759 //=======================================================================
761 Read Ensight Gold ASCII
763 //=======================================================================
765 void ENSIGHT_FIELD_RDONLY_DRIVER::readGoldASCII ()
768 // data that was set by CaseFile Driver
769 medEntityMesh entity = _ptrField->getSupport()->getEntity();
771 _SupportDesc supportDescriptor;
772 list<_SubPartValues> subPartValues;
774 _ASCIIFileReader varFile( getDataFileName() );
776 if ( isSingleFileMode() ) {
778 while ( curTimeStep < getIndexInDataFile() ) {
779 while ( !varFile.isTimeStepEnd() )
783 while ( !varFile.isTimeStepBeginning() )
786 string description = varFile.getLine(); // description line
787 _ptrField->setDescription( description );
790 _SubPartValues subValuesSample; // to keep interlace
791 subValuesSample.myInterlace = MED_NO_INTERLACE;
792 while ( !varFile.isTimeStepEnd() )
794 string word, restLine, line = varFile.getLine();
795 TStrTool::split( line, word, restLine );
796 if ( word == "part" ) {
797 partNumber = varFile.getInt(); // part #
800 subPartValues.push_back( subValuesSample );
801 _SubPartValues & subValues = subPartValues.back();
803 if ( restLine == "undef" )
804 subValues.myUndefValue = varFile.getWord(); // undef
806 if ( restLine == "partial" ) {
807 int nbPartial = varFile.getInt(); // ne
808 subValues.myPartialIndices.reserve( nbPartial );
809 while ( nbPartial-- )
810 subValues.myPartialIndices.push_back( varFile.getInt() ); // i_ne
812 _SubPartDesc desc( partNumber, word );
813 subValues.mySubPart = *getSubPart( desc );
814 readSubPartValues( varFile, _ptrField, subValues );
815 supportDescriptor.insert( desc );
818 _Support* interSupport = getSupport( supportDescriptor, entity );
819 setValuesToField( _ptrField, interSupport, subPartValues );
823 //=======================================================================
825 Read Ensight GOLD binary
827 //=======================================================================
829 void ENSIGHT_FIELD_RDONLY_DRIVER::readGoldBinary()
832 // data that was set by CaseFile Driver
833 medEntityMesh entity = _ptrField->getSupport()->getEntity();
835 _SupportDesc supportDescriptor;
836 list<_SubPartValues> subPartValues;
838 _BinaryFileReader varFile( getDataFileName() );
840 // check if swapping bytes needed
842 skipTimeStamp( varFile );
848 if ( getIndexInDataFile() <= 1 )
851 if ( isSingleFileMode() ) {
852 // one time step may be skipped by skipTimeStamp()
853 int curTimeStep = varFile.getPosition() ? 2 : 1 ;
854 while ( curTimeStep < getIndexInDataFile() ) {
855 skipTimeStamp( varFile );
858 varFile.skipTimeStepBeginning();
860 TStrOwner description( varFile.getLine() ); // description line
861 _ptrField->setDescription( description.myValues );
864 _SubPartValues subValuesSample; // to keep interlace
865 subValuesSample.myInterlace = MED_NO_INTERLACE;
866 while ( !varFile.eof() )
868 TStrOwner line( varFile.getLine() );
869 if ( isTimeStepEnd( line.myValues ))
871 string word, restLine;
872 TStrTool::split( line.myValues, word, restLine );
873 if ( word == "part" ) {
874 partNumber = *TIntOwner( varFile.getInt(1)); // part #
877 subPartValues.push_back( subValuesSample );
878 _SubPartValues & subValues = subPartValues.back();
880 if ( restLine == "undef" )
881 subValues.myUndefValue = (STRING( *TFltOwner( varFile.getFlt(1) ))); // undef
883 if ( restLine == "partial" ) {
884 int nbPartial = *TIntOwner( varFile.getInt(1) ); // ne
885 TIntOwner partial( varFile.getInt( nbPartial ));
886 subValues.myPartialIndices.assign( partial.myValues,
887 partial.myValues+nbPartial ); // i_ne
889 _SubPartDesc desc( partNumber, word );
890 subValues.mySubPart = *getSubPart( desc );
891 readSubPartValues( varFile, _ptrField, subValues );
892 supportDescriptor.insert( desc );
895 _Support* interSupport = getSupport( supportDescriptor, entity );
896 setValuesToField( _ptrField, interSupport, subPartValues );
900 //=======================================================================
904 //=======================================================================
906 void ENSIGHT_FIELD_RDONLY_DRIVER::read6ASCII()
909 // data that was set by CaseFile Driver
910 medEntityMesh entity = _ptrField->getSupport()->getEntity();
912 _SupportDesc supportDescriptor;
913 list<_SubPartValues> subPartValues;
915 _ASCIIFileReader varFile( getDataFileName() );
917 if ( isSingleFileMode() ) {
919 while ( curTimeStep < getIndexInDataFile() ) {
920 while ( !varFile.isTimeStepEnd() )
924 while ( !varFile.isTimeStepBeginning() )
927 string description = varFile.getLine(); // description line
928 _ptrField->setDescription( description );
930 const _SubPart* subPart = 0;
931 if ( entity == MED_NODE ) // variable per node
933 _SubPartDesc desc = _SubPartDesc::globalCoordDesc();
934 subPart = getSubPart( desc );
936 supportDescriptor.insert( desc );
937 _SubPartValues subValues( *subPart );
938 subValues.myInterlace = MED_FULL_INTERLACE;
939 readSubPartValues( varFile, _ptrField, subValues );
940 subPartValues.push_back( subValues );
944 while ( !varFile.isTimeStepEnd() )
946 string word = varFile.getWord();
947 if ( word == "part" ) {
948 partNumber = varFile.getInt();
951 _SubPartDesc desc( partNumber, word );
952 supportDescriptor.insert( desc );
953 subPart = getSubPart( desc );
954 _SubPartValues subValues( *subPart );
955 if ( desc.typeName() == "block" )
956 subValues.myInterlace = MED_NO_INTERLACE;
958 subValues.myInterlace = MED_FULL_INTERLACE;
959 readSubPartValues( varFile, _ptrField, subValues );
960 subPartValues.push_back( subValues );
963 _Support* interSupport = getSupport( supportDescriptor, entity );
964 setValuesToField( _ptrField, interSupport, subPartValues );
968 //=======================================================================
972 //=======================================================================
974 void ENSIGHT_FIELD_RDONLY_DRIVER::read6Binary()
977 // data that was set by CaseFile Driver
978 medEntityMesh entity = _ptrField->getSupport()->getEntity();
980 _SupportDesc supportDescriptor;
981 list<_SubPartValues> subPartValues;
982 const _SubPart* subPart = 0;
985 _BinaryFileReader varFile( getDataFileName() );
987 // check if swapping bytes needed
989 skipTimeStamp( varFile );
995 if ( getIndexInDataFile() <= 1 )
998 if ( isSingleFileMode() ) {
999 // one time step may be skipped by skipTimeStamp()
1000 int curTimeStep = varFile.getPosition() ? 2 : 1 ;
1001 while ( curTimeStep < getIndexInDataFile() ) {
1002 skipTimeStamp( varFile );
1005 varFile.skipTimeStepBeginning();
1008 TStrOwner description( varFile.getLine() ); // description line
1009 _ptrField->setDescription( description.myValues );
1011 if ( entity == MED_NODE ) // global unstructured node values
1013 _SubPartDesc desc = _SubPartDesc::globalCoordDesc();
1014 subPart = getSubPart( desc );
1016 supportDescriptor.insert( desc );
1017 _SubPartValues subValues( *subPart );
1018 subValues.myInterlace = MED_FULL_INTERLACE;
1019 readSubPartValues( varFile, _ptrField, subValues );
1020 subPartValues.push_back( subValues );
1023 while ( !varFile.eof() )
1025 TStrOwner line( varFile.getLine() );
1026 if ( isTimeStepEnd( line ))
1028 string word, restLine;
1029 TStrTool::split( line.myValues, word, restLine );
1030 if ( word == "part" ) {
1031 partNumber = atoi( restLine.c_str() );
1034 _SubPartDesc desc( partNumber, word );
1035 supportDescriptor.insert( desc );
1036 subPart = getSubPart( desc );
1037 _SubPartValues subValues( *subPart );
1038 if ( desc.typeName() == "block" )
1039 subValues.myInterlace = MED_NO_INTERLACE;
1041 subValues.myInterlace = MED_FULL_INTERLACE;
1042 readSubPartValues( varFile, _ptrField, subValues );
1043 subPartValues.push_back( subValues );
1046 _Support* interSupport = getSupport( supportDescriptor, entity );
1047 setValuesToField( _ptrField, interSupport, subPartValues );
1051 //================================================================================
1053 * \brief Looks for beginning of the next time stamp
1055 //================================================================================
1057 void ENSIGHT_FIELD_RDONLY_DRIVER::skipTimeStamp(_BinaryFileReader& varFile)
1059 medEntityMesh entity = _ptrField->getSupport()->getEntity();
1060 int nbComponents = _ptrField->getNumberOfComponents();
1062 if ( isSingleFileMode() )
1063 varFile.skipTimeStepBeginning();
1065 varFile.skip( 80 ); // description
1068 if ( entity == MED_NODE && !isGoldFormat() ) { // skip values on global nodes
1069 subPart = getSubPart( _SubPartDesc::globalCoordDesc() );
1071 varFile.skip( subPart->myNbNodes * nbComponents * sizeof(float) );
1074 while ( !varFile.eof() )
1076 TStrOwner line( varFile.getLine() );
1077 if ( isTimeStepEnd( line ))
1080 string word, restLine;
1081 TStrTool::split( line.myValues, word, restLine );
1083 if ( word == "part" ) {
1084 if ( isGoldFormat() )
1085 partNumber = *TIntOwner( varFile.getInt(1));
1087 partNumber = atoi( restLine.c_str() );
1090 if ( restLine == "undef" ) {
1091 varFile.skip( sizeof(int) );
1093 if ( restLine == "partial" ) {
1094 int nbPartial = *TIntOwner( varFile.getInt(1)); // ne
1095 varFile.skip( nbPartial * sizeof(int));
1098 _SubPartDesc desc( partNumber, word );
1099 subPart = getSubPart( desc );
1100 int nbElems = ( entity == MED_NODE ) ? subPart->myNbNodes : subPart->myNbCells;
1101 varFile.skip( nbElems * nbComponents * sizeof(float) );
1105 //=======================================================================
1107 //=======================================================================
1109 void ENSIGHT_FIELD_RDONLY_DRIVER::write(void) const
1110 throw (MEDEXCEPTION)
1112 throw MEDEXCEPTION("ENSIGHT_FIELD_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
1115 //=======================================================================
1116 //function : ENSIGHT_FIELD_WRONLY_DRIVER
1117 //=======================================================================
1119 ENSIGHT_FIELD_WRONLY_DRIVER::ENSIGHT_FIELD_WRONLY_DRIVER()
1120 :ENSIGHT_FIELD_DRIVER()
1124 //=======================================================================
1125 //function : ENSIGHT_FIELD_WRONLY_DRIVER
1126 //=======================================================================
1128 ENSIGHT_FIELD_WRONLY_DRIVER::ENSIGHT_FIELD_WRONLY_DRIVER(const string & fileName,
1130 :ENSIGHT_FIELD_DRIVER(fileName,ptrField,MED_EN::WRONLY)
1134 //=======================================================================
1135 //function : ENSIGHT_FIELD_WRONLY_DRIVER
1136 //=======================================================================
1139 ENSIGHT_FIELD_WRONLY_DRIVER::ENSIGHT_FIELD_WRONLY_DRIVER(const ENSIGHT_FIELD_WRONLY_DRIVER & drv)
1140 :ENSIGHT_FIELD_DRIVER(drv)
1144 //=======================================================================
1145 //function : ~ENSIGHT_FIELD_WRONLY_DRIVER
1146 //=======================================================================
1148 ENSIGHT_FIELD_WRONLY_DRIVER::~ENSIGHT_FIELD_WRONLY_DRIVER()
1154 //=======================================================================
1156 //=======================================================================
1158 GENDRIVER * ENSIGHT_FIELD_WRONLY_DRIVER::copy(void) const
1160 ENSIGHT_FIELD_WRONLY_DRIVER * myDriver = new ENSIGHT_FIELD_WRONLY_DRIVER(*this);
1165 //=======================================================================
1167 //=======================================================================
1169 void ENSIGHT_FIELD_WRONLY_DRIVER::read (void)
1170 throw (MEDEXCEPTION)
1172 throw MEDEXCEPTION("ENSIGHT_FIELD_WRONLY_DRIVER::read : Can't read with a write only!");
1175 //================================================================================
1177 * \brief Return pointer to the value of the i-th element
1179 //================================================================================
1181 const char* getValuePointer( int i, const FIELD_* field )
1183 switch ( field->getInterlacingType() ) {
1184 case MED_FULL_INTERLACE:
1185 if ( field->getValueType() == MED_REEL64 )
1186 return (const char*) & static_cast<const FIELD<double, FullInterlace>* >
1187 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1189 return (const char*) & static_cast<const FIELD<int, FullInterlace>* >
1190 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1191 case MED_NO_INTERLACE:
1192 if ( field->getValueType() == MED_REEL64 )
1193 return (const char*) & static_cast<const FIELD<double, NoInterlace>* >
1194 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1196 return (const char*) & static_cast<const FIELD<int, NoInterlace>* >
1197 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1198 case MED_NO_INTERLACE_BY_TYPE:
1199 if ( field->getValueType() == MED_REEL64 )
1200 return (const char*) & static_cast<const FIELD<double, NoInterlaceByType>* >
1201 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1203 return (const char*) & static_cast<const FIELD<int, NoInterlaceByType>* >
1204 ( field )->getArrayNoGauss()->getIJ( i, 1 );
1210 //=======================================================================
1212 * \brief Write field values in EnSight6 ASCII format
1214 //=======================================================================
1216 template< typename T >
1217 void write6ASCIIValues( const _SubPartValues& subPartValues,
1221 ofstream & ensightDataFile )
1223 // add the 3-d component to a vector in 2D space
1224 const bool add3dComp = true;
1226 if ( subPartValues.myNumbers )
1228 vector< _SelectedValueIterator<T> > compValIt =
1229 subPartValues.template getAllSelectedValues<T>( componentShift, nbComponents, add3dComp );
1230 nbComponents = compValIt.size();
1231 // in full interlace
1232 for (int i=0; i<nbValues; i++)
1233 for(int j=0; j<nbComponents; j++) {
1234 ensightDataFile << setw(12) << _toFloat( compValIt[j].next() );
1235 if (++mypoint == 6) {
1236 ensightDataFile << endl ;
1242 vector< _ValueIterator<T> > compValIt =
1243 subPartValues.template getAllValues<T>( componentShift, nbComponents, add3dComp );
1244 nbComponents = compValIt.size();
1245 // in full interlace
1246 for (int i=0; i<nbValues; i++)
1247 for(int j=0; j<nbComponents; j++) {
1248 ensightDataFile << setw(12) << _toFloat( compValIt[j].next() );
1249 if (++mypoint == 6) {
1250 ensightDataFile << endl ;
1255 if ( nbValues * nbComponents % 6 )
1256 ensightDataFile << endl;
1259 //=======================================================================
1261 * \brief Write field values in EnSight GOLD ASCII format
1263 //=======================================================================
1265 template< typename T >
1266 void writeGoldASCIIValues( const _SubPartValues& subPartValues,
1270 ofstream & ensightDataFile )
1273 for(int j=1; j<=nbComponents; j++) {
1274 if ( subPartValues.myNumbers )
1276 _SelectedValueIterator<T> values
1277 = subPartValues.template getSelectedValues<T>( j, componentShift, nbComponents );
1278 for (int i=0; i<nbValues; i++)
1279 ensightDataFile << setw(12) << _toFloat( values.next() ) << endl;
1282 _ValueIterator<T> values
1283 = subPartValues.template getValues<T>( j, componentShift, nbComponents );
1284 for (int i=0; i<nbValues; i++)
1285 ensightDataFile << setw(12) << _toFloat( values.next() )<< endl;
1288 // add the 3-d component to a vector in 2D space
1289 if ( nbComponents == 2 ) {
1290 for (int i=0; i<nbValues; i++)
1291 ensightDataFile << " 0.00000e+00" << endl;
1295 //=======================================================================
1297 * \brief Write field values in EnSight6 Binary format
1299 //=======================================================================
1301 template< typename T >
1302 void write6BinaryValues( const _SubPartValues& subPartValues,
1306 _BinaryFileWriter & ensightDataFile )
1308 const bool add3dComp = true;
1309 if ( subPartValues.myNumbers )
1311 vector< _SelectedValueIterator<T> > compValIt =
1312 subPartValues.template getAllSelectedValues<T>( componentShift, nbComponents, add3dComp );
1313 ensightDataFile.addReal( compValIt, nbValues, MED_FULL_INTERLACE );
1317 vector< _ValueIterator<T> > compValIt =
1318 subPartValues.template getAllValues<T>( componentShift, nbComponents, add3dComp );
1319 ensightDataFile.addReal( compValIt, nbValues, MED_FULL_INTERLACE );
1323 //=======================================================================
1325 * \brief Write field values in EnSight GOLD Binary format
1327 //=======================================================================
1329 template< typename T >
1330 void writeGoldBinaryValues( const _SubPartValues& subPartValues,
1334 _BinaryFileWriter & ensightDataFile )
1336 const bool add3dComp = false;
1337 if ( subPartValues.myNumbers )
1339 vector< _SelectedValueIterator<T> > compValIt =
1340 subPartValues.template getAllSelectedValues<T>( componentShift, nbComponents, add3dComp );
1341 ensightDataFile.addReal( compValIt, nbValues, MED_NO_INTERLACE );
1345 vector< _ValueIterator<T> > compValIt =
1346 subPartValues.template getAllValues<T>( componentShift, nbComponents, add3dComp );
1347 ensightDataFile.addReal( compValIt, nbValues, MED_NO_INTERLACE );
1349 // add the 3-d component to a vector in 2D space
1350 if ( nbComponents == 2 ) {
1351 vector<float> values( nbValues, 0. );
1352 ensightDataFile.addReal( & values[0], nbValues );
1356 //=======================================================================
1358 //=======================================================================
1360 void ENSIGHT_FIELD_WRONLY_DRIVER::write(void) const
1361 throw (MEDEXCEPTION)
1363 const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::write(void) const " ;
1366 openConst(false) ; // check if can write to case file
1368 // Ensight case organization requires a main file (filename.case) which defines organization
1370 _CaseFileDriver caseFile( getCaseFileName(), this);
1372 caseFile.addField( this );
1373 caseFile.write(); // all fields of _CaseFileDriver_User are set by this method
1375 openConst(true) ; // check if can write to data file
1377 const FIELD_* field = _ptrField;
1378 const SUPPORT * support = field->getSupport();
1379 const MESH * mesh = support->getMesh();
1381 int dt = field->getIterationNumber();
1382 int it = field->getOrderNumber();
1383 int nbComponents = field->getNumberOfComponents();
1384 med_type_champ type = field->getValueType() ;
1386 medEntityMesh entity = support->getEntity();
1387 int totalNbValues = support->getNumberOfElements(MED_ALL_ELEMENTS);
1388 //const int* mainNbValsByType = support->getNumberOfElements();
1390 int nbValuesByType = 0;
1391 int& componentShift = (type == MED_NO_INTERLACE_BY_TYPE) ? nbValuesByType : totalNbValues;
1393 bool isOnAll = support->isOnAllElements();
1394 if (!isOnAll && !mesh)
1395 throw MED_EXCEPTION(STRING("Can't write field ") << field->getName() <<
1396 ", which is not on all elements while mesh is not set to its support");
1398 isOnAll = ( mesh->getNumberOfElements(entity,MED_ALL_ELEMENTS) == componentShift );
1399 if (!isOnAll && entity == MED_NODE && !isGoldFormat() ) {
1400 throw MED_EXCEPTION(compatibilityPb("Can't write field ") << field->getName() <<
1401 " which is not on all nodes of the mesh in EnSight6 format,"
1402 " use EnSight Gold format instead");
1404 if ( entity == MED_EDGE && mesh && !isToWriteEntity( MED_EDGE, mesh ))
1405 throw MED_EXCEPTION(STRING(LOC) << "Can't write field " << field->getName()
1406 << ", fields on MED_EDGE in volumic mesh are not supported");
1409 int partNum = getPartNumber( support );
1410 string isPartial = "";
1412 if ( !isGoldFormat() )
1413 throw MED_EXCEPTION(STRING("Can't write field ") << field->getName()
1414 << " in EnSight6 format, it's support " << support->getName()
1415 << " is not stored in geo file, use EnSight Gold format instead");
1416 isPartial = " partial";
1418 tmpSupport.setAll(true);
1419 tmpSupport.setEntity( entity );
1420 partNum = getPartNumber( &tmpSupport );
1423 // supports to write the field for
1424 map< int, const SUPPORT* > parts;
1425 map< int, const SUPPORT* >::iterator partNumIt;
1426 parts[ partNum ] = support;
1428 // In Ensight 6, nodal field is visible on all parts as nodes are global, for
1429 // the rest cases we write field for all groups in order to see values on them
1430 if ( isOnAll && ( isGoldFormat() || entity != MED_NODE ) && mesh )
1432 // In Ensight Gold, to see nodal field on all groups we write them all
1433 int ent = entity, toEntity = entity + 1;
1434 if ( isGoldFormat() && entity == MED_NODE )
1435 ent = MED_CELL, toEntity = MED_ALL_ENTITIES;
1437 for ( ; ent < toEntity; ++ent ) {
1438 int nbGroups = mesh->getNumberOfGroups(ent);
1439 for ( int i=1; i<=nbGroups; i++) {
1440 const GROUP* group = mesh->getGroup( ent, i );
1441 if ( group != support && !group->isOnAllElements() ) {
1442 partNum = getPartNumber( group );
1444 parts.insert( make_pair( partNum, group ));
1451 string description = field->getDescription();
1452 if ( description.empty() )
1453 description = STRING(field->getName()) << " dt=" << dt << " it=" << it;
1455 cout << "-> Creating the Ensight data file " << getDataFileName() << endl ;
1458 _SubPartValues geoTypeValues;
1459 geoTypeValues.myOwnValues = false;
1460 geoTypeValues.myInterlace = field->getInterlacingType();
1461 int nbWrittenValues = 0;
1463 if ( isBinaryEnSightFormatForWriting() )
1465 // ======================================================
1467 // ======================================================
1469 // function to write values
1470 typedef void (* TWriteValues) (const _SubPartValues& , int, int, int, _BinaryFileWriter &);
1471 TWriteValues writeValues;
1472 if ( isGoldFormat() ) {
1473 if ( type == MED_REEL64 ) writeValues = writeGoldBinaryValues<double>;
1474 else if ( type == MED_INT32 ) writeValues = writeGoldBinaryValues<int>;
1475 else writeValues = writeGoldBinaryValues<long>;
1478 if ( type == MED_REEL64 ) writeValues = write6BinaryValues<double>;
1479 else if ( type == MED_INT32 ) writeValues = write6BinaryValues<int>;
1480 else writeValues = write6BinaryValues<long>;
1482 _BinaryFileWriter ensightDataFile( getDataFileName() );
1485 ensightDataFile.addString( description );
1487 for ( partNumIt = parts.begin(); partNumIt != parts.end(); ++partNumIt)
1489 const SUPPORT* partSup = partNumIt->second;
1490 partNum = partNumIt->first;
1491 const bool otherEntity = ( entity != partSup->getEntity() ); // Gold, nodal field
1492 nbWrittenValues = 0;
1495 if ( isGoldFormat() ) {
1496 ensightDataFile.addString("part");
1497 ensightDataFile.addInt( partNum );
1499 else if ( entity != MED_NODE ) {
1500 ensightDataFile.addString( STRING("part ") << partNum );
1503 int nbTypes = partSup->getNumberOfTypes();
1504 const medGeometryElement* geoType = partSup->getTypes();
1505 for (int i=0; i<nbTypes; i++)
1507 const medGeometryElement medType = geoType[i];
1508 nbValuesByType = partSup->getNumberOfElements(medType);
1511 if ( entity != MED_NODE ) {
1512 const TEnSightElemType& ensightType = getEnSightType(medType);
1513 ensightDataFile.addString( ensightType._name + isPartial );
1515 else if ( isGoldFormat() ) {
1516 ensightDataFile.addString( "coordinates" + isPartial );
1519 // supporting numbers (Gold only)
1520 if ( !isPartial.empty() ) {
1521 const int *number = partSup->getNumber(medType);
1522 ensightDataFile.addInt( nbValuesByType );
1523 ensightDataFile.addInt( number, nbValuesByType );
1527 if ( otherEntity ) { // Gold, nodal field, non-nodal group (partSup)
1528 if ( isOnAll && partSup->isOnAllElements() ) {
1529 geoTypeValues.myNumbers = 0;
1530 geoTypeValues.myValues = getValuePointer( 1, field );
1531 nbValuesByType = totalNbValues;
1534 geoTypeValues.myNumbers = getNodeNumbers( partSup, nbValuesByType );
1535 geoTypeValues.myValues = getValuePointer( geoTypeValues.myNumbers[0], field );
1538 else if ( partSup->getNumberOfElements(MED_ALL_ELEMENTS) != totalNbValues ) {
1539 geoTypeValues.myNumbers = partSup->getNumber(medType);
1540 geoTypeValues.myValues = getValuePointer( geoTypeValues.myNumbers[0], field );
1543 geoTypeValues.myNumbers = 0;
1544 geoTypeValues.myValues = getValuePointer( nbWrittenValues + 1, field );
1547 writeValues(geoTypeValues, nbValuesByType, nbComponents, componentShift, ensightDataFile);
1548 nbWrittenValues += nbValuesByType;
1550 if ( otherEntity ) {
1551 if ( geoTypeValues.myNumbers ) delete [] geoTypeValues.myNumbers;
1552 break; // all nodal values are written at once
1559 // ======================================================
1561 // ======================================================
1563 // function to write values
1564 typedef void (* TWriteValues) (const _SubPartValues& , int, int, int, ofstream &);
1565 TWriteValues writeValues;
1566 if ( isGoldFormat() ) {
1567 if ( type == MED_REEL64 ) writeValues = writeGoldASCIIValues<double>;
1568 else if ( type == MED_INT32 ) writeValues = writeGoldASCIIValues<int>;
1569 else writeValues = writeGoldASCIIValues<long>;
1572 if ( type == MED_REEL64 ) writeValues = write6ASCIIValues<double>;
1573 else if ( type == MED_INT32 ) writeValues = write6ASCIIValues<int>;
1574 else writeValues = write6ASCIIValues<long>;
1576 const int iw = isGoldFormat() ? 10 : 8; // width of integer
1578 ofstream ensightDataFile( getDataFileName().c_str(), ios::out);
1579 ensightDataFile.setf(ios::scientific);
1580 ensightDataFile.precision(5);
1583 ensightDataFile << description << endl;
1585 for ( partNumIt = parts.begin(); partNumIt != parts.end(); ++partNumIt)
1587 const SUPPORT* partSup = partNumIt->second;
1588 partNum = partNumIt->first;
1589 const bool otherEntity = ( entity != partSup->getEntity() ); // Gold, nodal field
1590 nbWrittenValues = 0;
1593 if ( isGoldFormat() )
1594 ensightDataFile << "part" << endl << setw(iw) << partNum << endl;
1595 else if ( entity != MED_NODE ) {
1596 ensightDataFile << "part " << partNum << endl;
1599 int nbTypes = partSup->getNumberOfTypes();
1600 const medGeometryElement* geoType = partSup->getTypes();
1601 for (int i=0; i<nbTypes; i++)
1603 const medGeometryElement medType = geoType[i];
1604 nbValuesByType = partSup->getNumberOfElements(medType);
1607 if ( entity != MED_NODE ) {
1608 const TEnSightElemType& ensightType = getEnSightType(medType);
1609 ensightDataFile << ensightType._name << isPartial << endl;
1611 else if ( isGoldFormat() ) {
1612 ensightDataFile << "coordinates" << isPartial << endl;
1615 // supporting numbers (Gold only)
1616 if ( !isPartial.empty() ) {
1617 const int *number = partSup->getNumber(medType);
1618 const int *nEnd = number + nbValuesByType;
1619 ensightDataFile << setw(iw) << nbValuesByType << endl;
1620 while ( number < nEnd )
1621 ensightDataFile << setw(iw) << *number++ << endl;
1625 if ( otherEntity ) { // Gold, nodal field, non-nodal group (partSup)
1626 if ( isOnAll && partSup->isOnAllElements() ) {
1627 geoTypeValues.myNumbers = 0;
1628 geoTypeValues.myValues = getValuePointer( 1, field );
1629 nbValuesByType = totalNbValues;
1632 geoTypeValues.myNumbers = getNodeNumbers( partSup, nbValuesByType );
1633 geoTypeValues.myValues = getValuePointer( geoTypeValues.myNumbers[0], field );
1636 else if ( partSup->getNumberOfElements(MED_ALL_ELEMENTS) != totalNbValues ) {
1637 geoTypeValues.myNumbers = partSup->getNumber(medType);
1638 geoTypeValues.myValues = getValuePointer( geoTypeValues.myNumbers[0], field );
1641 geoTypeValues.myNumbers = 0;
1642 geoTypeValues.myValues = getValuePointer( nbWrittenValues + 1, field );
1646 writeValues(geoTypeValues, nbValuesByType, nbComponents, componentShift, ensightDataFile);
1647 nbWrittenValues += nbValuesByType;
1649 if ( otherEntity ) {
1650 if ( geoTypeValues.myNumbers ) delete [] geoTypeValues.myNumbers;
1651 break; // all nodal values are written at once
1654 } // loop on supports
1656 ensightDataFile.close();