1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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
23 #include "MED_Wrapper.hxx"
24 #include "MED_TStructures.hxx"
25 #include "MED_Utilities.hxx"
26 #include "MED_TFile.hxx"
28 #include "MEDFileUtilities.hxx"
31 #include <med_proto.h>
37 #include <boost/version.hpp>
40 static int MYDEBUG = 0;
41 static int MYVALUEDEBUG = 0;
43 // static int MYDEBUG = 0; // unused in release mode
44 // static int MYVALUEDEBUG = 0; // unused in release mode
49 //---------------------------------------------------------------
51 ::TLockProxy(TWrapper* theWrapper):
54 #if BOOST_VERSION >= 103500
55 myWrapper->myMutex.lock();
57 boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex);
59 INITMSG(MYDEBUG, "TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
65 INITMSG(MYDEBUG, "~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
66 #if BOOST_VERSION >= 103500
67 myWrapper->myMutex.unlock();
69 boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex);
75 ::operator->() const // never throws
80 //---------------------------------------------------------------
81 const TIdt& MEDIDTHoder::Id() const
84 EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
88 void TMemFile::Open(EModeAcces theMode, TErr* theErr)
90 if (this->myCount++ == 0)
92 std::string dftFileName = MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInMem();
93 med_access_mode modeTmp(MED_ACC_CREAT);
94 if(memfile.app_image_ptr)
95 modeTmp = med_access_mode(theMode);
96 myFid = MEDmemFileOpen(dftFileName.c_str(),&memfile,MED_FALSE,modeTmp);
99 *theErr = TErr(myFid);
101 EXCEPTION(std::runtime_error,"TMemFile - MEDmemFileOpen");
104 TFile::TFile(const std::string& theFileName, TInt theMajor, TInt theMinor):
105 myFileName(theFileName),
109 if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM;
110 if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
113 void TFile::Open(EModeAcces theMode, TErr* theErr)
115 if (myCount++ == 0) {
116 const char* aFileName = myFileName.c_str();
118 if (med_access_mode(theMode) == MED_ACC_RDWR) {
119 // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5
120 std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1";
122 const char* to_decode = aReadOlnyRmCmd.c_str();
123 int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0);
124 wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1];
125 MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed);
126 awReadOlnyRmCmd[size_needed] = '\0';
127 _wsystem(awReadOlnyRmCmd);
128 delete[] awReadOlnyRmCmd;
130 system(aReadOlnyRmCmd.c_str());
134 myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
137 *theErr = TErr(myFid);
139 EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< myMajor <<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
142 //---------------------------------------------------------------
145 PFileInternal myFile;
149 TFileWrapper(const PFileInternal& theFile,
156 if (myMinor < 0) myMinor = MED_MINOR_NUM;
157 myFile->Open(theMode, theErr);
166 //----------------------------------------------------------------------------
167 template<class TimeStampValueType>
169 Print(SharedPtr<TimeStampValueType> theTimeStampValue)
171 INITMSG(MYDEBUG,"Print - TimeStampValue\n");
172 typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
173 typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
174 for (; anIter != aGeom2Value.end(); anIter++) {
175 const EGeometrieElement& aGeom = anIter->first;
176 const typename TimeStampValueType::TTMeshValue& aMeshValue = anIter->second;
177 TInt aNbElem = aMeshValue.myNbElem;
178 TInt aNbGauss = aMeshValue.myNbGauss;
179 TInt aNbComp = aMeshValue.myNbComp;
180 INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
181 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
182 typename TimeStampValueType::TTMeshValue::TCValueSliceArr aValueSliceArr =
183 aMeshValue.GetGaussValueSliceArr(iElem);
184 ADDMSG(MYVALUEDEBUG, "{");
185 for (TInt iGauss = 0; iGauss < aNbGauss; iGauss++) {
186 const typename TimeStampValueType::TTMeshValue::TCValueSlice& aValueSlice =
187 aValueSliceArr[iGauss];
188 for (TInt iComp = 0; iComp < aNbComp; iComp++) {
189 ADDMSG(MYVALUEDEBUG, aValueSlice[iComp]<<" ");
191 ADDMSG(MYVALUEDEBUG, "| ");
193 ADDMSG(MYVALUEDEBUG, "} ");
195 ADDMSG(MYDEBUG, "\n");
199 //---------------------------------------------------------------
201 ::TWrapper(const std::string& theFileName, bool write, TFileInternal *tfileInst, TInt theMajor, TInt theMinor):
206 myFile.reset(new TFile(theFileName, theMajor, theMinor) );
208 myFile.reset(new TFileDecorator(tfileInst) );
212 myFile->Open(eLECTURE_ECRITURE, &aRet);
215 myFile->Open(eCREATION, &aRet);
219 myFile->Open(eLECTURE, &aRet);
223 //----------------------------------------------------------------------------
229 //----------------------------------------------------------------------------
232 ::GetNbMeshes(TErr* theErr)
234 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
236 if (theErr && *theErr < 0)
239 return MEDnMesh(myFile->Id());
242 //----------------------------------------------------------------------------
245 ::GetMeshInfo(TInt theMeshId,
246 MED::TMeshInfo& theInfo,
249 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
251 if (theErr && *theErr < 0)
254 TValueHolder<TString, char> aMeshName(theInfo.myName);
255 TValueHolder<TInt, med_int> aDim(theInfo.myDim);
256 TValueHolder<TInt, med_int> aSpaceDim(theInfo.mySpaceDim);
257 TValueHolder<EMaillage, med_mesh_type> aType(theInfo.myType);
258 char dtunit[MED_SNAME_SIZE+1];
259 med_sorting_type sorttype;
262 int naxis = MEDmeshnAxis(myFile->Id(), theMeshId);
263 char *axisname = new char[naxis*MED_SNAME_SIZE+1];
264 char *axisunit = new char[naxis*MED_SNAME_SIZE+1];
265 TErr aRet = MEDmeshInfo(myFile->Id(),
281 EXCEPTION(std::runtime_error, "GetMeshInfo - MEDmeshInfo(...)");
284 //----------------------------------------------------------------------------
287 ::SetMeshInfo(const MED::TMeshInfo& theInfo,
291 SetMeshInfo(theInfo, eLECTURE_ECRITURE, &aRet);
294 SetMeshInfo(theInfo, eLECTURE_AJOUT, &aRet);
297 SetMeshInfo(theInfo, eCREATION, &aRet);
303 //----------------------------------------------------------------------------
306 ::SetMeshInfo(const MED::TMeshInfo& theInfo,
310 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
312 if (theErr && *theErr < 0)
315 MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
317 TValueHolder<TString, char> aMeshName(anInfo.myName);
318 TValueHolder<TInt, med_int> aDim(anInfo.myDim);
319 TValueHolder<TInt, med_int> aSpaceDim(anInfo.mySpaceDim);
320 TValueHolder<EMaillage, med_mesh_type> aType(anInfo.myType);
321 TValueHolder<TString, char> aDesc(anInfo.myDesc);
323 char *nam = new char[aSpaceDim*MED_SNAME_SIZE+1];
324 std::fill(nam, nam+aSpaceDim*MED_SNAME_SIZE+1, '\0');
325 char *unit = new char[aSpaceDim*MED_SNAME_SIZE+1];
326 std::fill(unit, unit+aSpaceDim*MED_SNAME_SIZE+1, '\0');
327 TErr aRet = MEDmeshCr(myFile->Id(),
342 // aRet = MEDunvCr(myFile->Id(),&aMeshName);
344 INITMSG(MYDEBUG, "TWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
349 EXCEPTION(std::runtime_error, "SetMeshInfo - MEDmeshCr(...)");
352 //----------------------------------------------------------------------------
355 ::CrMeshInfo(TInt theDim,
357 const std::string& theValue,
359 const std::string& theDesc)
361 return PMeshInfo(new TTMeshInfo
369 //----------------------------------------------------------------------------
372 ::CrMeshInfo(const PMeshInfo& theInfo)
374 return PMeshInfo(new TTMeshInfo(theInfo));
377 //----------------------------------------------------------------------------
380 ::GetPMeshInfo(TInt theId,
383 PMeshInfo anInfo = CrMeshInfo();
384 GetMeshInfo(theId, *anInfo, theErr);
388 //----------------------------------------------------------------------------
391 ::GetNbFamilies(const MED::TMeshInfo& theInfo,
394 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
396 if (theErr && *theErr < 0)
399 MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
400 TValueHolder<TString, char> aName(anInfo.myName);
401 return MEDnFamily(myFile->Id(), &aName);
404 //----------------------------------------------------------------------------
407 ::GetNbFamAttr(TInt theFamId,
408 const MED::TMeshInfo& theInfo,
411 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
413 if (theErr && *theErr < 0)
416 MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
418 TValueHolder<TString, char> aName(anInfo.myName);
420 return MEDnFamily23Attribute(myFile->Id(), &aName, theFamId);
423 //----------------------------------------------------------------------------
426 ::GetNbFamGroup(TInt theFamId,
427 const MED::TMeshInfo& theInfo,
430 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
432 if (theErr && *theErr < 0)
435 MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
437 TValueHolder<TString, char> aName(anInfo.myName);
439 return MEDnFamilyGroup(myFile->Id(), &aName, theFamId);
442 //----------------------------------------------------------------------------
445 ::GetFamilyInfo(TInt theFamId,
446 MED::TFamilyInfo& theInfo,
449 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
451 if (theErr && *theErr < 0)
454 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
456 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
457 TValueHolder<TString, char> aFamilyName(theInfo.myName);
458 TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
459 TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
460 TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
461 TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
462 TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
464 TErr aRet = MEDfamily23Info(myFile->Id(),
477 EXCEPTION(std::runtime_error, "GetFamilyInfo - MEDfamily23Info(...) - "<<
478 " aMeshInfo.myName = '"<<&aMeshName<<
479 "'; theFamId = "<<theFamId<<
480 "; theInfo.myNbGroup = "<<theInfo.myNbGroup<<
481 "; theInfo.myNbAttr = "<<theInfo.myNbAttr);
484 //----------------------------------------------------------------------------
487 ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
491 SetFamilyInfo(theInfo, eLECTURE_ECRITURE, &aRet);
494 SetFamilyInfo(theInfo, eLECTURE_AJOUT, &aRet);
500 //----------------------------------------------------------------------------
503 ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
507 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
509 if (theErr && *theErr < 0)
512 MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo);
513 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
515 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
516 TValueHolder<TString, char> aFamilyName(anInfo.myName);
517 TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
518 TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
519 TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
520 TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
521 TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
522 TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
523 TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
525 TErr aRet = MEDfamilyCr(myFile->Id(),
532 INITMSG(MYDEBUG, "TWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
537 EXCEPTION(std::runtime_error, "SetFamilyInfo - MEDfamilyCr(...)");
540 //----------------------------------------------------------------------------
543 ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
547 const std::string& theValue)
549 return PFamilyInfo(new TTFamilyInfo
557 //----------------------------------------------------------------------------
560 ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
561 const std::string& theValue,
563 const MED::TStringSet& theGroupNames,
564 const MED::TStringVector& theAttrDescs,
565 const MED::TIntVector& theAttrIds,
566 const MED::TIntVector& theAttrVals)
568 return PFamilyInfo(new TTFamilyInfo
578 //----------------------------------------------------------------------------
581 ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
582 const PFamilyInfo& theInfo)
584 return PFamilyInfo(new TTFamilyInfo
589 //----------------------------------------------------------------------------
592 ::GetPFamilyInfo(const PMeshInfo& theMeshInfo,
596 // must be reimplemented in connection with mesh type eSTRUCTURE
597 // if (theMeshInfo->GetType() != eNON_STRUCTURE)
598 // return PFamilyInfo();
600 TInt aNbAttr = GetNbFamAttr(theId, *theMeshInfo);
601 TInt aNbGroup = GetNbFamGroup(theId, *theMeshInfo);
602 PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo, aNbGroup, aNbAttr);
603 GetFamilyInfo(theId, *anInfo, theErr);
606 std::string aName = anInfo->GetName();
607 INITMSG(MYDEBUG, "GetPFamilyInfo - aFamilyName = '"<<aName<<
608 "'; andId = "<<anInfo->GetId()<<
609 "; aNbAttr = "<<aNbAttr<<
610 "; aNbGroup = "<<aNbGroup<<"\n");
611 for (TInt iGroup = 0; iGroup < aNbGroup; iGroup++) {
612 aName = anInfo->GetGroupName(iGroup);
613 INITMSG(MYDEBUG, "aGroupName = '"<<aName<<"'\n");
620 //----------------------------------------------------------------------------
623 ::GetNames(TElemInfo& theInfo,
625 EEntiteMaillage theEntity,
626 EGeometrieElement theGeom,
629 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
631 if (theErr && *theErr < 0)
634 if (theGeom == eBALL)
635 theGeom = GetBallGeom(theInfo.myMeshInfo);
637 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
639 TValueHolder<TString, char> aMeshName (aMeshInfo.myName);
640 TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
641 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
642 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
644 TErr aRet = MEDmeshEntityNameRd(myFile->Id(),
652 theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ;
658 //----------------------------------------------------------------------------
661 ::SetNames(const TElemInfo& theInfo,
662 EEntiteMaillage theEntity,
663 EGeometrieElement theGeom,
666 SetNames(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
669 //----------------------------------------------------------------------------
672 ::SetNames(const TElemInfo& theInfo,
674 EEntiteMaillage theEntity,
675 EGeometrieElement theGeom,
678 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
680 if (theErr && *theErr < 0)
683 if (theGeom == eBALL)
684 theGeom = GetBallGeom(theInfo.myMeshInfo);
686 MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
687 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
690 if (theInfo.myIsElemNames) {
691 TValueHolder<TString, char> aMeshName (aMeshInfo.myName);
692 TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
693 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
694 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
696 aRet = MEDmeshEntityNameWr(myFile->Id(),
702 (TInt)anInfo.myElemNames->size(),
707 EXCEPTION(std::runtime_error, "SetNames - MEDmeshEntityNameWr(...)");
711 //----------------------------------------------------------------------------
714 ::GetNumeration(TElemInfo& theInfo,
716 EEntiteMaillage theEntity,
717 EGeometrieElement theGeom,
720 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
722 if (theErr && *theErr < 0)
725 if (theGeom == eBALL)
726 theGeom = GetBallGeom(theInfo.myMeshInfo);
728 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
730 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
731 TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
732 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
733 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
735 TErr aRet = MEDmeshEntityNumberRd(myFile->Id(),
743 theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI;
749 //----------------------------------------------------------------------------
752 ::SetNumeration(const TElemInfo& theInfo,
753 EEntiteMaillage theEntity,
754 EGeometrieElement theGeom,
757 SetNumeration(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
760 //----------------------------------------------------------------------------
763 ::SetNumeration(const TElemInfo& theInfo,
765 EEntiteMaillage theEntity,
766 EGeometrieElement theGeom,
769 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
771 if (theErr && *theErr < 0)
774 if (theGeom == eBALL)
775 theGeom = GetBallGeom(theInfo.myMeshInfo);
777 MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
778 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
781 if (theInfo.myIsElemNum) {
782 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
783 TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
784 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
785 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
787 aRet = MEDmeshEntityNumberWr(myFile->Id(),
793 (TInt)anInfo.myElemNum->size(),
798 EXCEPTION(std::runtime_error, "SetNumeration - MEDmeshEntityNumberWr(...)");
802 //----------------------------------------------------------------------------
805 ::GetFamilies(TElemInfo& theInfo,
807 EEntiteMaillage theEntity,
808 EGeometrieElement theGeom,
811 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
813 if (theErr && *theErr < 0)
816 if (theGeom == eBALL)
817 theGeom = GetBallGeom(theInfo.myMeshInfo);
819 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
821 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
822 TValueHolder<TElemNum, med_int> aFamNum (theInfo.myFamNum);
823 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
824 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
826 TErr aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
835 // if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
837 int aSize = (int)theInfo.myFamNum->size();
838 theInfo.myFamNum->clear();
839 theInfo.myFamNum->resize(aSize,0);
843 // EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...) of CELLS");
849 //----------------------------------------------------------------------------
852 ::SetFamilies(const TElemInfo& theInfo,
853 EEntiteMaillage theEntity,
854 EGeometrieElement theGeom,
857 SetFamilies(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
860 //----------------------------------------------------------------------------
863 ::SetFamilies(const TElemInfo& theInfo,
865 EEntiteMaillage theEntity,
866 EGeometrieElement theGeom,
869 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
871 if (theErr && *theErr < 0)
874 if (theGeom == eBALL)
875 theGeom = GetBallGeom(theInfo.myMeshInfo);
877 MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
878 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
880 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
881 TValueHolder<TElemNum, med_int> aFamNum (anInfo.myFamNum);
882 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theEntity);
883 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theGeom);
885 TErr aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
891 (TInt)anInfo.myFamNum->size(),
897 EXCEPTION(std::runtime_error, "SetFamilies - MEDmeshEntityFamilyNumberWr(...)");
900 //----------------------------------------------------------------------------
903 ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
906 return GetNbNodes(theMeshInfo, eCOOR, theErr);
909 //----------------------------------------------------------------------------
912 ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
916 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
918 if (theErr && *theErr < 0)
921 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
923 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
924 TValueHolder<ETable, med_data_type > aTable(theTable);
926 return MEDmeshnEntity(myFile->Id(),
938 //----------------------------------------------------------------------------
941 ::GetNodeInfo(MED::TNodeInfo& theInfo,
944 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
946 if (theErr && *theErr < 0)
949 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
951 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
952 TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
953 TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
954 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
955 TValueHolder<ERepere, med_axis_type> aSystem(theInfo.mySystem);
956 TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
957 TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
958 TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
959 //TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
960 TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
961 //TValueHolder<EBooleen, med_bool> anIsElemNum(theInfo.myIsElemNum);
962 TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
963 TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
965 TErr aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
972 TErr aRet2 =MEDmeshEntityFamilyNumberRd(myFile->Id(),
980 // if (aRet2 == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
982 int mySize = (int)theInfo.myFamNum->size();
983 theInfo.myFamNum->clear();
984 theInfo.myFamNum->resize(mySize,0);
987 // EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshEntityFamilyNumberRd(...)");
990 if (MEDmeshEntityNameRd(myFile->Id(),
996 &anElemNames) < 0) theInfo.myIsElemNames=eFAUX;
998 if (MEDmeshEntityNumberRd(myFile->Id(),
1004 &anElemNum) < 0) theInfo.myIsElemNum=eFAUX;
1009 EXCEPTION(std::runtime_error, "GetNodeInfo - MEDmeshNodeCoordinateRd(...)");
1012 //----------------------------------------------------------------------------
1015 ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1019 SetNodeInfo(theInfo, eLECTURE_ECRITURE, &aRet);
1022 SetNodeInfo(theInfo, eLECTURE_AJOUT, &aRet);
1028 //----------------------------------------------------------------------------
1031 ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1035 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1037 if (theErr && *theErr < 0)
1040 MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
1041 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1043 TValueHolder<TString, char> aMeshName (aMeshInfo.myName);
1044 TValueHolder<TNodeCoord, med_float> aCoord (anInfo.myCoord);
1045 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch (anInfo.myModeSwitch);
1046 TValueHolder<ERepere, med_axis_type> aSystem (anInfo.mySystem);
1047 TValueHolder<TString, char> aCoordNames (anInfo.myCoordNames);
1048 TValueHolder<TString, char> aCoordUnits (anInfo.myCoordUnits);
1049 TValueHolder<TString, char> anElemNames (anInfo.myElemNames);
1050 TValueHolder<EBooleen, med_bool> anIsElemNames(anInfo.myIsElemNames);
1051 TValueHolder<TElemNum, med_int> anElemNum (anInfo.myElemNum);
1052 TValueHolder<EBooleen, med_bool> anIsElemNum (anInfo.myIsElemNum);
1053 TValueHolder<TElemNum, med_int> aFamNum (anInfo.myFamNum);
1054 TValueHolder<TInt, med_int> aNbElem (anInfo.myNbElem);
1056 TErr aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
1065 MEDmeshEntityFamilyNumberWr(myFile->Id(),
1074 MEDmeshEntityNameWr(myFile->Id(),
1083 MEDmeshEntityNumberWr(myFile->Id(),
1094 EXCEPTION(std::runtime_error, "SetNodeInfo - MEDmeshNodeCoordinateWr(...)");
1097 //----------------------------------------------------------------------------
1100 ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1102 EModeSwitch theMode,
1104 EBooleen theIsElemNum,
1105 EBooleen theIsElemNames)
1107 return PNodeInfo(new TTNodeInfo
1116 //----------------------------------------------------------------------------
1119 ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1120 const TFloatVector& theNodeCoords,
1121 EModeSwitch theMode,
1123 const TStringVector& theCoordNames,
1124 const TStringVector& theCoordUnits,
1125 const TIntVector& theFamilyNums,
1126 const TIntVector& theElemNums,
1127 const TStringVector& theElemNames)
1129 return PNodeInfo(new TTNodeInfo
1141 //----------------------------------------------------------------------------
1144 ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1145 const PNodeInfo& theInfo)
1147 return PNodeInfo(new TTNodeInfo
1152 //----------------------------------------------------------------------------
1155 ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
1158 TInt aNbElems = GetNbNodes(*theMeshInfo);
1159 if (aNbElems == 0) {
1163 PNodeInfo anInfo = CrNodeInfo(theMeshInfo, aNbElems);
1164 GetNodeInfo(*anInfo, theErr);
1167 TInt aDim = theMeshInfo->myDim;
1168 TInt aNbElem = anInfo->GetNbElem();
1169 INITMSG(MYDEBUG, "GetPNodeInfo: ");
1171 INITMSG(MYDEBUG, "aCoords: "<<aNbElem<<": ");
1172 TNodeCoord& aCoord = anInfo->myCoord;
1173 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1174 for (TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++) {
1175 ADDMSG(MYVALUEDEBUG, aCoord[anId]<<",");
1177 ADDMSG(MYVALUEDEBUG, " ");
1179 ADDMSG(MYDEBUG, std::endl);
1181 BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
1182 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1183 ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
1185 ADDMSG(MYVALUEDEBUG, std::endl);
1187 if (anInfo->IsElemNum()) {
1188 BEGMSG(MYVALUEDEBUG, "GetElemNum: ");
1189 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1190 ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
1192 ADDMSG(MYVALUEDEBUG, std::endl);
1195 ADDMSG(MYDEBUG, std::endl);
1201 //----------------------------------------------------------------------------
1204 ::CrElemInfo(const PMeshInfo& theMeshInfo,
1206 EBooleen theIsElemNum,
1207 EBooleen theIsElemNames)
1209 return PElemInfo(new TTElemInfo
1216 //----------------------------------------------------------------------------
1219 ::CrElemInfo(const PMeshInfo& theMeshInfo,
1221 const TIntVector& theFamNum,
1222 const TIntVector& aElemNum,
1223 const TStringVector& aElemNames)
1225 return PElemInfo(new TTElemInfo
1233 //----------------------------------------------------------------------------
1236 ::GetPElemInfo(const PMeshInfo& theMeshInfo,
1237 EEntiteMaillage theEntity,
1238 EGeometrieElement theGeom,
1239 EConnectivite theConnMode,
1242 EMaillage aType = theMeshInfo->GetType();
1243 if (aType == eNON_STRUCTURE) {
1246 if (theEntity == eNOEUD)
1247 return GetPNodeInfo(theMeshInfo, theErr);
1248 return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1251 return GetPPolygoneInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1254 return GetPPolyedreInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1257 return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1261 PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
1264 EBooleen theIsElemNum = eFAUX;
1268 nbElems = aGrille->GetNbNodes();
1269 theIsElemNum = eVRAI;
1274 nbElems = aGrille->GetNbCells();
1281 TIntVector aElemNum;
1282 TStringVector aElemNames;
1284 PElemInfo aElemInfo;
1286 if (theGeom == ePOINT1) {
1287 aElemInfo = CrElemInfo(theMeshInfo,
1290 MED::TElemInfo &aTElemInfo = *aElemInfo;
1292 // must be reimplemente in connection with mesh type eSTRUCTURE
1293 // GetNumeration(aTElemInfo,
1299 GetFamilies(aTElemInfo,
1305 // must be reimplemente in connection with mesh type eSTRUCTURE
1306 // GetNames(aTElemInfo,
1313 aElemInfo = CrElemInfo(theMeshInfo,
1325 //----------------------------------------------------------------------------
1328 ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo,
1329 EEntiteMaillage theEntity,
1330 EGeometrieElement theGeom,
1331 EConnectivite theConnMode,
1334 return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1337 //----------------------------------------------------------------------------
1340 ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo,
1341 EEntiteMaillage theEntity,
1342 EGeometrieElement theGeom,
1343 EConnectivite theConnMode,
1346 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1348 if (theErr && *theErr < 0)
1351 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1353 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1354 med_int aTaille = 0;
1356 aTaille=MEDmeshnEntity(myFile->Id(),
1360 med_entity_type(theEntity),
1361 med_geometry_type(theGeom),
1363 med_connectivity_mode(theConnMode),
1368 EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1370 return TInt(aTaille);
1373 //-----------------------------------------------------------------
1376 ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
1379 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1381 if (theErr && *theErr < 0)
1384 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1386 TValueHolder<TString, char > aMeshName(aMeshInfo.myName);
1387 TValueHolder<TElemNum, med_int > anIndex (theInfo.myIndex);
1388 TValueHolder<TElemNum, med_int > aConn (theInfo.myConn);
1389 TValueHolder<EEntiteMaillage, med_entity_type > anEntity (theInfo.myEntity);
1390 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theInfo.myGeom);
1391 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1392 TInt aNbElem = (TInt)theInfo.myElemNum->size();
1395 aRet = MEDmeshPolygon2Rd(myFile->Id(), &aMeshName,
1396 MED_NO_DT, MED_NO_IT,
1398 aConnMode, &anIndex, &aConn);
1403 EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolygonRd(...)");
1405 if (theInfo.myIsElemNames) {
1406 GetNames(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1411 if (theInfo.myIsElemNum) {
1412 GetNumeration(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1417 GetFamilies(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1422 //----------------------------------------------------------------------------
1425 ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1428 SetPolygoneInfo(theInfo, eLECTURE_ECRITURE, theErr);
1431 //----------------------------------------------------------------------------
1434 ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1438 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1440 if (theErr && *theErr < 0)
1443 MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo);
1444 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1446 TValueHolder<TString, char > aMeshName(aMeshInfo.myName);
1447 TValueHolder<TElemNum, med_int > anIndex (anInfo.myIndex);
1448 TValueHolder<TElemNum, med_int > aConn (anInfo.myConn);
1449 TValueHolder<EEntiteMaillage, med_entity_type > anEntity (anInfo.myEntity);
1450 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (anInfo.myGeom);
1451 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1453 TErr aRet = MEDmeshPolygon2Wr(myFile->Id(), &aMeshName,
1454 MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
1456 aConnMode, anInfo.myNbElem + 1,
1461 EXCEPTION(std::runtime_error, "SetPolygoneInfo - MEDmeshPolygonWr(...)");
1463 SetNames(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1467 SetNumeration(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1471 SetFamilies(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1476 //----------------------------------------------------------------------------
1479 ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1480 EEntiteMaillage theEntity,
1481 EGeometrieElement theGeom,
1484 EConnectivite theConnMode,
1485 EBooleen theIsElemNum,
1486 EBooleen theIsElemNames)
1488 return PPolygoneInfo(new TTPolygoneInfo
1499 //----------------------------------------------------------------------------
1502 ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1503 EEntiteMaillage theEntity,
1504 EGeometrieElement theGeom,
1505 const TIntVector& theIndexes,
1506 const TIntVector& theConnectivities,
1507 EConnectivite theConnMode,
1508 const TIntVector& theFamilyNums,
1509 const TIntVector& theElemNums,
1510 const TStringVector& theElemNames)
1512 return PPolygoneInfo(new TTPolygoneInfo
1524 //----------------------------------------------------------------------------
1527 ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1528 const PPolygoneInfo& theInfo)
1530 return PPolygoneInfo(new TTPolygoneInfo
1535 //----------------------------------------------------------------------------
1538 ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
1539 EEntiteMaillage theEntity,
1540 EGeometrieElement theGeom,
1541 EConnectivite theConnMode)
1543 if (theMeshInfo->GetType() != eNON_STRUCTURE)
1544 return PPolygoneInfo();
1546 TInt aNbElem = GetNbPolygones(theMeshInfo, theEntity, theGeom, theConnMode);
1547 TInt aConnSize = GetPolygoneConnSize(theMeshInfo, theEntity, theGeom, theConnMode);
1548 PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo, theEntity, theGeom, aNbElem, aConnSize, theConnMode);
1549 GetPolygoneInfo(anInfo);
1552 INITMSG(MYDEBUG, "GetPPolygoneInfo"<<
1553 " - theGeom = "<<theGeom<<
1554 "; aNbElem = "<<aNbElem<<": ");
1555 for (TInt iElem = 1; iElem < aNbElem; iElem++) {
1556 TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
1557 TInt aConnDim = aConnSlice.size();
1558 for (TInt iConn = 0; iConn < aConnDim; iConn++) {
1559 ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1561 ADDMSG(MYDEBUG, " ");
1563 ADDMSG(MYDEBUG, std::endl);
1569 //----------------------------------------------------------------------------
1572 ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo,
1573 EEntiteMaillage theEntity,
1574 EGeometrieElement theGeom,
1575 EConnectivite theConnMode,
1578 return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1581 //----------------------------------------------------------------------------
1584 ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo,
1587 EConnectivite theConnMode,
1590 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1592 if (theErr && *theErr < 0)
1593 EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
1595 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1597 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1598 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theConnMode);
1599 //TValueHolder<TInt, med_int> aNbFaces(theNbFaces);
1600 //TValueHolder<TInt, med_int> aConnSize(theConnSize);
1602 med_bool chgt, trsf;
1603 theNbFaces = MEDmeshnEntity(myFile->Id(),
1614 theConnSize = MEDmeshnEntity(myFile->Id(),
1625 if (theNbFaces < 0 || theConnSize<0)
1626 EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1630 //-----------------------------------------------------------------
1633 ::GetPolyedreInfo(TPolyedreInfo& theInfo,
1636 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1638 if (theErr && *theErr < 0)
1641 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1643 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1644 TInt aNbElem = (TInt)theInfo.myElemNum->size();
1645 TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex);
1646 TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces);
1647 TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
1648 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1651 aRet = MEDmeshPolyhedronRd(myFile->Id(),
1664 EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolyhedronRd(...)");
1666 if (theInfo.myIsElemNames) {
1667 GetNames(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1672 if (theInfo.myIsElemNum) {
1673 GetNumeration(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1678 GetFamilies(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1683 //----------------------------------------------------------------------------
1686 ::SetPolyedreInfo(const TPolyedreInfo& theInfo,
1689 SetPolyedreInfo(theInfo, eLECTURE_ECRITURE, theErr);
1692 //----------------------------------------------------------------------------
1695 ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo,
1699 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1701 if (theErr && *theErr < 0)
1704 MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo);
1705 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1707 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1708 TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex);
1709 TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces);
1710 TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
1711 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1714 aRet = MEDmeshPolyhedronWr(myFile->Id(),
1723 (TInt)anInfo.myFaces->size(),
1730 EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshPolyhedronWr(...)");
1732 TValueHolder<EEntiteMaillage, med_entity_type> anEntity(anInfo.myEntity);
1734 if (theInfo.myIsElemNames) {
1735 TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
1736 aRet = MEDmeshEntityNameWr(myFile->Id(),
1742 (TInt)anInfo.myElemNames->size(),
1747 EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNameWr(...)");
1750 if (theInfo.myIsElemNum) {
1751 TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1752 aRet = MEDmeshEntityNumberWr(myFile->Id(),
1758 (TInt)anInfo.myElemNum->size(),
1763 EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNumberWr(...)");
1766 TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
1767 aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
1773 (TInt)anInfo.myFamNum->size(),
1779 EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityFamilyNumberWr(...)");
1782 //----------------------------------------------------------------------------
1785 ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1786 EEntiteMaillage theEntity,
1787 EGeometrieElement theGeom,
1791 EConnectivite theConnMode,
1792 EBooleen theIsElemNum,
1793 EBooleen theIsElemNames)
1795 return PPolyedreInfo(new TTPolyedreInfo
1807 //----------------------------------------------------------------------------
1810 ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1811 EEntiteMaillage theEntity,
1812 EGeometrieElement theGeom,
1813 const TIntVector& theIndexes,
1814 const TIntVector& theFaces,
1815 const TIntVector& theConnectivities,
1816 EConnectivite theConnMode,
1817 const TIntVector& theFamilyNums,
1818 const TIntVector& theElemNums,
1819 const TStringVector& theElemNames)
1821 return PPolyedreInfo(new TTPolyedreInfo
1834 //----------------------------------------------------------------------------
1837 ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1838 const PPolyedreInfo& theInfo)
1840 return PPolyedreInfo(new TTPolyedreInfo
1845 //----------------------------------------------------------------------------
1848 ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
1849 EEntiteMaillage theEntity,
1850 EGeometrieElement theGeom,
1851 EConnectivite theConnMode)
1853 if (theMeshInfo->GetType() != eNON_STRUCTURE)
1854 return PPolyedreInfo();
1855 TInt aNbElem = GetNbPolyedres(theMeshInfo, theEntity, theGeom, theConnMode);
1856 TInt aNbFaces, aConnSize;
1857 GetPolyedreConnSize(theMeshInfo, aNbFaces, aConnSize, theConnMode);
1858 PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo, theEntity, theGeom, aNbElem, aNbFaces, aConnSize, theConnMode);
1859 GetPolyedreInfo(anInfo);
1862 INITMSG(MYDEBUG, "GetPPolyedreInfo"<<
1863 " - theGeom = "<<theGeom<<
1864 "; aNbElem = "<<aNbElem<<": ");
1865 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1866 TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
1867 TInt aNbFaces = aConnSliceArr.size();
1868 ADDMSG(MYDEBUG, "{");
1869 for (TInt iFace = 0; iFace < aNbFaces; iFace++) {
1870 TCConnSlice aConnSlice = aConnSliceArr[iFace];
1871 TInt aNbConn = aConnSlice.size();
1872 ADDMSG(MYDEBUG, "[");
1873 for (TInt iConn = 0; iConn < aNbConn; iConn++) {
1874 ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1876 ADDMSG(MYDEBUG, "] ");
1878 ADDMSG(MYDEBUG, "} ");
1880 ADDMSG(MYDEBUG, std::endl);
1886 //-----------------------------------------------------------------
1889 ::GetEntityInfo(const MED::TMeshInfo& theMeshInfo,
1890 EConnectivite theConnMode,
1895 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1897 if (theErr && *theErr < 0)
1900 if (theMeshInfo.GetType() == eNON_STRUCTURE) {
1901 TInt aNbElem = GetNbNodes(theMeshInfo);
1903 anInfo[eNOEUD][ePOINT1] = aNbElem;
1904 const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
1905 TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
1906 TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
1907 for (; anIter != anIterEnd; anIter++) {
1908 const EEntiteMaillage& anEntity = anIter->first;
1909 const TGeomSet& aGeomSet = anIter->second;
1910 TGeomSet::const_iterator anIter2 = aGeomSet.begin();
1911 TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
1912 for (; anIter2 != anIterEnd2; anIter2++) {
1913 const EGeometrieElement& aGeom = *anIter2;
1914 aNbElem = GetNbCells(theMeshInfo, anEntity, aGeom, theConnMode, theErr);
1916 if (anEntity == eSTRUCT_ELEMENT) {
1917 const TInt nbStructTypes = aNbElem;
1918 for (TInt structType = 0; structType < nbStructTypes; ++structType) {
1919 // check type name to keep only "MED_BALL" structured element
1920 TValueHolder<TString, char> aMeshName((TString&) theMeshInfo.myName);
1921 char geotypename[ MED_NAME_SIZE + 1] = "";
1922 med_geometry_type geotype;
1923 MEDmeshEntityInfo(myFile->Id(), &aMeshName, MED_NO_DT, MED_NO_IT,
1924 med_entity_type(anEntity), structType+1,
1925 geotypename, &geotype);
1926 if (strcmp(geotypename, MED_BALL_NAME) == 0) {
1927 aNbElem = GetNbCells(theMeshInfo, anEntity, EGeometrieElement(geotype),
1928 theConnMode, theErr);
1930 anInfo[anEntity][EGeometrieElement(geotype)] = aNbElem;
1935 anInfo[anEntity][aGeom] = aNbElem;
1942 else { // eSTRUCTURE
1943 EGrilleType aGrilleType;
1947 TInt aDim = theMeshInfo.GetDim();
1948 EGeometrieElement aGeom, aSubGeom;
1949 EEntiteMaillage aSubEntity = eMAILLE;
1951 GetGrilleType(theMeshInfo, aGrilleType);
1953 TIntVector aStruct(aDim);
1954 if (aGrilleType == eGRILLE_STANDARD)
1956 GetGrilleStruct(theMeshInfo, aStruct, theErr);
1959 { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1960 ETable aTable[3] = { eCOOR_IND1, eCOOR_IND2, eCOOR_IND3 };
1961 for (med_int anAxis = 0; anAxis < aDim; anAxis++)
1962 aStruct[ anAxis ] = GetNbNodes(theMeshInfo, aTable[anAxis]);
1964 for (med_int i = 0; i < aDim; i++) {
1965 aNbNodes = aNbNodes * aStruct[i];
1966 aNbElem = aNbElem * (aStruct[i] - 1);
1975 aSubEntity = eARETE;
1977 (aStruct[0]) * (aStruct[1]-1) +
1978 (aStruct[0]-1) * (aStruct[1]);
1985 (aStruct[0]) * (aStruct[1]-1) * (aStruct[2]-1) +
1986 (aStruct[0]-1) * (aStruct[1]) * (aStruct[2]-1) +
1987 (aStruct[0]-1) * (aStruct[1]-1) * (aStruct[2]);
1990 anInfo[eNOEUD][ePOINT1] = aNbNodes;
1991 anInfo[eMAILLE][aGeom] = aNbElem;
1993 anInfo[aSubEntity][aSubGeom] = aNbSub;
1998 //-----------------------------------------------------------------
2001 ::GetNbCells(const MED::TMeshInfo& theMeshInfo,
2002 EEntiteMaillage theEntity,
2003 EGeometrieElement theGeom,
2004 EConnectivite theConnMode,
2007 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2009 if (theErr && *theErr < 0)
2012 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
2013 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2014 med_bool chgt, trsf;
2017 case MED::ePOLYGONE:
2018 case MED::ePOLYGON2:
2020 return MEDmeshnEntity(myFile->Id(), &aMeshName,
2021 MED_NO_DT, MED_NO_IT,
2022 med_entity_type(theEntity), med_geometry_type(theGeom),
2023 MED_INDEX_NODE, med_connectivity_mode(theConnMode),
2026 case MED::ePOLYEDRE:
2028 return MEDmeshnEntity(myFile->Id(), &aMeshName,
2029 MED_NO_DT, MED_NO_IT,
2030 med_entity_type(theEntity), MED_POLYHEDRON,
2031 MED_INDEX_FACE, med_connectivity_mode(theConnMode),
2036 return GetNbBalls(theMeshInfo);
2040 return MEDmeshnEntity(myFile->Id(), &aMeshName,
2041 MED_NO_DT, MED_NO_IT,
2042 med_entity_type(theEntity), med_geometry_type(theGeom),
2043 MED_CONNECTIVITY, med_connectivity_mode(theConnMode),
2050 //----------------------------------------------------------------------------
2053 ::GetCellInfo(MED::TCellInfo& theInfo,
2056 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2058 if (theErr && *theErr < 0)
2061 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
2063 TValueHolder<TString, char> aMeshName (aMeshInfo.myName);
2064 TValueHolder<TElemNum, med_int> aConn (theInfo.myConn);
2065 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch (theInfo.myModeSwitch);
2066 TValueHolder<TString, char> anElemNames (theInfo.myElemNames);
2067 TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
2068 TValueHolder<TElemNum, med_int> anElemNum (theInfo.myElemNum);
2069 TValueHolder<EBooleen, med_bool> anIsElemNum (theInfo.myIsElemNum);
2070 TValueHolder<TElemNum, med_int> aFamNum (theInfo.myFamNum);
2071 TValueHolder<EBooleen, med_bool> anIsFamNum (theInfo.myIsFamNum);
2072 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (theInfo.myEntity);
2073 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theInfo.myGeom);
2074 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode (theInfo.myConnMode);
2078 aRet = MEDmeshnEntity(myFile->Id(),
2089 // names are present in the file, they will be read in spite of theInfo.myIsElemNames
2090 theInfo.myIsElemNames = eVRAI;
2091 theInfo.myElemNames.reset( new TString( theInfo.myNbElem * GetPNOMLength() + 1 ));
2092 anElemNames.myRepresentation = & ((TString&) theInfo.myElemNames )[0];
2095 aRet = MEDmeshElementRd(myFile->Id(),
2114 EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)");
2116 if (anIsFamNum == MED_FALSE)
2118 int mySize = (int) theInfo.myFamNum->size();
2119 theInfo.myFamNum->clear();
2120 theInfo.myFamNum->resize(mySize, 0);
2125 //----------------------------------------------------------------------------
2128 ::SetCellInfo(const MED::TCellInfo& theInfo,
2131 SetCellInfo(theInfo, eLECTURE_ECRITURE, theErr);
2134 //----------------------------------------------------------------------------
2137 ::SetCellInfo(const MED::TCellInfo& theInfo,
2141 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2143 if (theErr && *theErr < 0)
2146 MED::TCellInfo& anInfo = const_cast<MED::TCellInfo&>(theInfo);
2147 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
2149 TValueHolder<TString, char> aMeshName (aMeshInfo.myName);
2150 TValueHolder<TElemNum, med_int> aConn (anInfo.myConn);
2151 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch (anInfo.myModeSwitch);
2152 TValueHolder<TString, char> anElemNames (anInfo.myElemNames);
2153 TValueHolder<EBooleen, med_bool> anIsElemNames(anInfo.myIsElemNames);
2154 TValueHolder<TElemNum, med_int> anElemNum (anInfo.myElemNum);
2155 TValueHolder<EBooleen, med_bool> anIsElemNum (anInfo.myIsElemNum);
2156 TValueHolder<TElemNum, med_int> aFamNum (anInfo.myFamNum);
2157 TValueHolder<EBooleen, med_bool> anIsFamNum (anInfo.myIsFamNum);
2158 TValueHolder<EEntiteMaillage, med_entity_type> anEntity (anInfo.myEntity);
2159 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (anInfo.myGeom);
2160 TValueHolder<EConnectivite, med_connectivity_mode> aConnMode (anInfo.myConnMode);
2161 TValueHolder<TInt, med_int> aNbElem (anInfo.myNbElem);
2164 aRet = MEDmeshElementConnectivityWr(myFile->Id(),
2176 MEDmeshEntityFamilyNumberWr(myFile->Id(),
2185 MEDmeshEntityNameWr(myFile->Id(),
2194 MEDmeshEntityNumberWr(myFile->Id(),
2205 EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...), ret="<< aRet);
2208 //----------------------------------------------------------------------------
2211 ::CrCellInfo(const PMeshInfo& theMeshInfo,
2212 EEntiteMaillage theEntity,
2213 EGeometrieElement theGeom,
2215 EConnectivite theConnMode,
2216 EBooleen theIsElemNum,
2217 EBooleen theIsElemNames,
2218 EModeSwitch theMode)
2220 return PCellInfo(new TTCellInfo
2231 //----------------------------------------------------------------------------
2234 ::CrCellInfo(const PMeshInfo& theMeshInfo,
2235 EEntiteMaillage theEntity,
2236 EGeometrieElement theGeom,
2237 const TIntVector& theConnectivities,
2238 EConnectivite theConnMode,
2239 const TIntVector& theFamilyNums,
2240 const TIntVector& theElemNums,
2241 const TStringVector& theElemNames,
2242 EModeSwitch theMode)
2244 return PCellInfo(new TTCellInfo
2256 //----------------------------------------------------------------------------
2259 ::CrCellInfo(const PMeshInfo& theMeshInfo,
2260 const PCellInfo& theInfo)
2262 return PCellInfo(new TTCellInfo
2267 //----------------------------------------------------------------------------
2270 ::GetPCellInfo(const PMeshInfo& theMeshInfo,
2271 EEntiteMaillage theEntity,
2272 EGeometrieElement theGeom,
2273 EConnectivite theConnMode,
2276 if (theMeshInfo->GetType() != eNON_STRUCTURE)
2278 TInt aNbElem = GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode);
2279 PCellInfo anInfo = CrCellInfo(theMeshInfo, theEntity, theGeom, aNbElem, theConnMode);
2280 GetCellInfo(anInfo, theErr);
2283 TInt aConnDim = anInfo->GetConnDim();
2284 INITMSG(MYDEBUG, "GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
2285 BEGMSG(MYDEBUG, "GetPCellInfo - aNbElem: "<<aNbElem<<": ");
2286 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2287 TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
2288 for (TInt iConn = 0; iConn < aConnDim; iConn++) {
2289 ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
2291 ADDMSG(MYVALUEDEBUG, " ");
2293 ADDMSG(MYDEBUG, std::endl);
2295 BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetFamNum: ");
2296 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2297 ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
2299 ADDMSG(MYVALUEDEBUG, std::endl);
2301 if (anInfo->IsElemNum()) {
2302 BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetElemNum: ");
2303 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2304 ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
2306 ADDMSG(MYVALUEDEBUG, std::endl);
2308 ADDMSG(MYDEBUG, std::endl);
2314 //----------------------------------------------------------------------------
2317 ::GetBallGeom(const TMeshInfo& /*theMeshInfo*/)
2320 TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2322 // read med_geometry_type of "MED_BALL" element
2323 char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2324 return EGeometrieElement(MEDstructElementGeotype(myFile->Id(), geotypename));
2327 //----------------------------------------------------------------------------
2330 ::GetNbBalls(const TMeshInfo& theMeshInfo)
2333 TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2335 EGeometrieElement ballType = GetBallGeom(theMeshInfo);
2339 return GetNbCells(theMeshInfo, eSTRUCT_ELEMENT, ballType, eNOD);
2342 //----------------------------------------------------------------------------
2345 ::GetBallInfo(TBallInfo& theInfo,
2348 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2350 // check geometry of MED_BALL
2351 if (theInfo.myGeom == eBALL)
2353 theInfo.myGeom = GetBallGeom(*theInfo.myMeshInfo);
2354 if (theInfo.myGeom < 0) {
2356 EXCEPTION(std::runtime_error, "GetBallInfo - no balls in the mesh");
2357 *theErr = theInfo.myGeom;
2363 GetCellInfo(theInfo);
2366 TValueHolder<TString, char> aMeshName (theInfo.myMeshInfo->myName);
2367 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (theInfo.myGeom);
2368 TValueHolder<TFloatVector, void> aDiam (theInfo.myDiameters);
2369 char varattname[ MED_NAME_SIZE + 1] = MED_BALL_DIAMETER;
2371 TErr aRet = MEDmeshStructElementVarAttRd(myFile->Id(), &aMeshName,
2372 MED_NO_DT, MED_NO_IT,
2379 EXCEPTION(std::runtime_error, "GetBallInfo - pb at reading diameters");
2382 //----------------------------------------------------------------------------
2385 ::SetBallInfo(const TBallInfo& theInfo,
2388 SetBallInfo(theInfo, eLECTURE_ECRITURE, theErr);
2391 //----------------------------------------------------------------------------
2394 ::SetBallInfo(const TBallInfo& theInfo,
2398 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2401 char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
2402 EGeometrieElement ballGeom = GetBallGeom(*theInfo.myMeshInfo);
2405 // no ball model in the file, create support mesh for it
2406 char dummyname [MED_NAME_SIZE*3+1] = "";
2407 if ((ret = MEDsupportMeshCr(myFile->Id(),
2409 theInfo.myMeshInfo->GetSpaceDim(),
2410 theInfo.myMeshInfo->GetDim(),
2411 "Support mesh for a ball model",
2413 /*axisname=*/dummyname,
2414 /*unitname=*/dummyname)) < 0) {
2416 EXCEPTION(std::runtime_error, "SetBallInfo - MEDsupportMeshCr");
2420 // write coordinates of 1 node
2421 med_float coord[3] = {0, 0, 0};
2422 if ((ret = MEDmeshNodeCoordinateWr(myFile->Id(),
2423 ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
2424 MED_FULL_INTERLACE, /*nnode=*/1, coord)) < 0) {
2426 EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshNodeCoordinateWr");
2430 // ball model creation
2431 char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2432 if ((ballGeom = (EGeometrieElement) MEDstructElementCr(myFile->Id(),
2434 theInfo.myMeshInfo->GetSpaceDim(),
2436 MED_NODE,MED_NONE)) < 0) {
2438 EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementCr");
2442 // create diameter attribute
2443 if ((ret = MEDstructElementVarAttCr(myFile->Id(),
2444 geotypename, MED_BALL_DIAMETER,
2445 MED_ATT_FLOAT64, /*ncomp=*/1)) < 0) {
2447 EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementVarAttCr");
2453 TBallInfo& aBallInfo = ((TBallInfo&) theInfo);
2454 aBallInfo.myGeom = ballGeom;
2457 SetCellInfo(theInfo, theMode, theErr);
2458 if (theErr && *theErr < 0)
2462 TValueHolder<TString, char> aMeshName (aBallInfo.myMeshInfo->myName);
2463 TValueHolder<EGeometrieElement, med_geometry_type> aGeom (aBallInfo.myGeom);
2464 TValueHolder<TFloatVector, void> aDiam (aBallInfo.myDiameters);
2465 ret = MEDmeshStructElementVarAttWr(myFile->Id(), &aMeshName,
2466 MED_NO_DT, MED_NO_IT,
2467 aGeom, MED_BALL_DIAMETER,
2468 theInfo.myNbElem, &aDiam);
2472 EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshStructElementVarAttWr");
2475 //----------------------------------------------------------------------------
2478 ::CrBallInfo(const PMeshInfo& theMeshInfo,
2480 EBooleen theIsElemNum)
2482 return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
2485 //----------------------------------------------------------------------------
2488 ::CrBallInfo(const PMeshInfo& theMeshInfo,
2489 const TIntVector& theNodes,
2490 TFloatVector& theDiameters,
2491 const TIntVector& theFamilyNums,
2492 const TIntVector& theElemNums)
2494 return PBallInfo(new TTBallInfo(theMeshInfo, theNodes, theDiameters,
2495 theFamilyNums, theElemNums));
2498 //----------------------------------------------------------------------------
2501 ::CrBallInfo(const PMeshInfo& theMeshInfo,
2502 const PBallInfo& theInfo)
2504 return PBallInfo(new TTBallInfo(theMeshInfo, theInfo));
2507 //----------------------------------------------------------------------------
2510 ::GetPBallInfo(const PMeshInfo& theMeshInfo)
2512 TInt nbBalls = GetNbBalls(theMeshInfo);
2513 if (nbBalls < 1) return PBallInfo();
2515 PBallInfo anInfo = CrBallInfo(theMeshInfo, nbBalls);
2516 GetBallInfo(anInfo);
2521 //-----------------------------------------------------------------
2524 ::GetNbFields(TErr* theErr)
2526 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2528 if (theErr && *theErr < 0)
2531 return MEDnField(myFile->Id());
2534 //----------------------------------------------------------------------------
2537 ::GetNbComp(TInt theFieldId,
2540 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2542 if (theErr && *theErr < 0)
2545 return MEDfieldnComponent(myFile->Id(), theFieldId);
2548 //----------------------------------------------------------------------------
2551 ::GetFieldInfo(TInt theFieldId,
2552 MED::TFieldInfo& theInfo,
2555 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2557 if (theErr && *theErr < 0)
2560 TString aFieldName(256); // Protect from memory problems with too long names
2561 TValueHolder<ETypeChamp, med_field_type> aType(theInfo.myType);
2562 TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
2563 TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
2564 MED::TMeshInfo& aMeshInfo = theInfo.myMeshInfo;
2568 char dtunit[MED_SNAME_SIZE+1];
2569 char local_mesh_name[MED_NAME_SIZE+1]="";
2571 theInfo.myNbComp = MEDfieldnComponent(myFile->Id(), theFieldId);
2572 aRet = MEDfieldInfo(myFile->Id(),
2583 if (strcmp(&aMeshInfo.myName[0], local_mesh_name) != 0) {
2589 theInfo.SetName(aFieldName);
2594 EXCEPTION(std::runtime_error, "GetFieldInfo - MEDfieldInfo(...)");
2597 //----------------------------------------------------------------------------
2600 ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2604 SetFieldInfo(theInfo, eLECTURE_ECRITURE, &aRet);
2607 SetFieldInfo(theInfo, eLECTURE_AJOUT, &aRet);
2613 //----------------------------------------------------------------------------
2616 ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2620 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2622 if (theErr && *theErr < 0)
2625 MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2627 TValueHolder<TString, char> aFieldName(anInfo.myName);
2628 TValueHolder<ETypeChamp, med_field_type> aType(anInfo.myType);
2629 TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
2630 TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
2631 MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2633 char dtunit[MED_SNAME_SIZE+1];
2634 std::fill(dtunit, dtunit+MED_SNAME_SIZE+1, '\0');
2635 aRet = MEDfieldCr(myFile->Id(),
2642 &aMeshInfo.myName[0]);
2646 EXCEPTION(std::runtime_error, "SetFieldInfo - MEDfieldCr(...)");
2649 //----------------------------------------------------------------------------
2652 ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2655 const std::string& theValue,
2656 EBooleen theIsLocal,
2659 return PFieldInfo(new TTFieldInfo
2668 //----------------------------------------------------------------------------
2671 ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2672 const PFieldInfo& theInfo)
2674 return PFieldInfo(new TTFieldInfo
2679 //----------------------------------------------------------------------------
2682 ::GetPFieldInfo(const PMeshInfo& theMeshInfo,
2686 TInt aNbComp = GetNbComp(theId);
2687 PFieldInfo anInfo = CrFieldInfo(theMeshInfo, aNbComp);
2688 GetFieldInfo(theId, *anInfo, theErr);
2693 "- aName = '"<<anInfo->GetName()<<"'"<<
2694 "; aType = "<<anInfo->GetType()<<
2695 "; aNbComp = "<<aNbComp<<
2702 //----------------------------------------------------------------------------
2705 ::GetNbGauss(TErr* theErr)
2707 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2709 if (theErr && *theErr < 0)
2712 return MEDnLocalization(myFile->Id());
2715 //----------------------------------------------------------------------------
2718 ::GetGaussPreInfo(TInt theId,
2721 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2723 if (theErr && *theErr < 0)
2724 return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
2726 med_int aNbGaussPoints = med_int();
2727 TVector<char> aName(GetNOMLength()+1);
2728 med_geometry_type aGeom = MED_NONE;
2732 char geointerpname[MED_NAME_SIZE+1] = "";
2733 char ipointstructmeshname[MED_NAME_SIZE+1] = "";
2734 med_int nsectionmeshcell;
2735 med_geometry_type sectiongeotype;
2736 aRet = MEDlocalizationInfo (myFile->Id(),
2743 ipointstructmeshname,
2749 EXCEPTION(std::runtime_error, "GetGaussPreInfo - MEDlocalizationInfo(...)");
2750 return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom), &aName[0]),
2751 TInt(aNbGaussPoints));
2754 //----------------------------------------------------------------------------
2757 ::GetGaussInfo(TInt /*theId*/,
2758 TGaussInfo& theInfo,
2761 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2763 if (theErr && *theErr < 0)
2766 TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord);
2767 TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord);
2768 TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight);
2769 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
2770 TValueHolder<TString, char> aGaussName(theInfo.myName);
2773 aRet = MEDlocalizationRd(myFile->Id(),
2783 EXCEPTION(std::runtime_error, "GetGaussInfo - MEDlocalizationRd(...)");
2786 //----------------------------------------------------------------------------
2789 ::CrGaussInfo(const TGaussInfo::TInfo& theInfo,
2790 EModeSwitch theMode)
2792 return PGaussInfo(new TTGaussInfo
2797 //-----------------------------------------------------------------
2800 ::GetNbTimeStamps(const MED::TFieldInfo& theInfo,
2801 const MED::TEntityInfo& theEntityInfo,
2802 EEntiteMaillage& theEntity,
2803 TGeom2Size& theGeom2Size,
2806 theEntity = EEntiteMaillage(-1);
2807 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2810 if (theEntityInfo.empty())
2815 else if (theEntityInfo.empty())
2816 EXCEPTION(std::runtime_error, "GetNbTimeStamps - There is no any Entity on the Mesh");
2818 bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
2820 theGeom2Size.clear();
2821 TInt aNbTimeStamps = 0;
2822 TIdt anId = myFile->Id();
2824 MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2825 TValueHolder<TString, char> aFieldName(anInfo.myName);
2826 MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2828 // workaround for IPAL13676
2829 MED::TEntityInfo localEntityInfo = theEntityInfo;
2830 TEntityInfo::iterator anLocalIter = localEntityInfo.find(eMAILLE);
2831 if (anLocalIter != localEntityInfo.end()) {
2832 localEntityInfo[eNOEUD_ELEMENT] = anLocalIter->second;
2835 TEntityInfo::const_iterator anIter = localEntityInfo.begin();
2836 for (; anIter != localEntityInfo.end(); anIter++) {
2837 med_entity_type anEntity = med_entity_type(anIter->first);
2838 const TGeom2Size& aGeom2Size = anIter->second;
2839 TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
2840 for (; anGeomIter != aGeom2Size.end(); anGeomIter++) {
2841 med_geometry_type aGeom = med_geometry_type(anGeomIter->first);
2842 char aMeshName[MED_NAME_SIZE+1];
2845 char dtunit[MED_SNAME_SIZE+1];
2846 med_int myNbComp = MEDfieldnComponentByName(anId, &aFieldName);
2847 char *cname=new char[myNbComp*MED_SNAME_SIZE+1];
2848 char *unitname=new char[myNbComp*MED_SNAME_SIZE+1];
2850 MEDfieldInfoByName(anId,
2867 MEDfieldComputingStepInfo(anId,
2873 char profilename[MED_NAME_SIZE+1];
2874 char locname[MED_NAME_SIZE+1];
2878 // protection from crash (division by zero)
2879 // inside MEDfieldnValueWithProfile function
2880 // caused by the workaround for IPAL13676 (see above)
2881 if (anEntity == MED_NODE_ELEMENT && aGeom % 100 == 0)
2884 nval = MEDfieldnValueWithProfile(anId,
2889 med_geometry_type(aGeom),
2897 bool anIsSatisfied =(nval > 0);
2898 if (anIsSatisfied) {
2900 "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
2901 "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
2902 if (anIsPerformAdditionalCheck) {
2903 anIsSatisfied = !strcmp(&aMeshName[0], &aMeshInfo.myName[0]);
2904 if (!anIsSatisfied) {
2906 "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
2907 "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
2911 if (anIsSatisfied) {
2912 theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
2913 theEntity = EEntiteMaillage(anEntity);
2914 aNbTimeStamps = aNbStamps;
2917 if (!theGeom2Size.empty())
2920 return aNbTimeStamps;
2923 //----------------------------------------------------------------------------
2926 ::GetTimeStampInfo(TInt theTimeStampId,
2927 MED::TTimeStampInfo& theInfo,
2930 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2932 const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
2935 if (aGeom2Size.empty())
2940 else if (aGeom2Size.empty())
2941 EXCEPTION(std::runtime_error, "GetTimeStampInfo - There is no any cell");
2943 MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
2944 MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
2946 TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
2947 TValueHolder<EEntiteMaillage, med_entity_type> anEntity(theInfo.myEntity);
2948 TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
2949 TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
2950 TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
2951 TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
2952 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2953 TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo.myIsLocal);
2954 TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef);
2956 TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
2958 // just to get a time stamp unit (anUnitDt)
2959 med_field_type aFieldType;
2960 med_int aNbComp = MEDfieldnComponentByName(myFile->Id(), &aFieldName);
2961 char *aCompName = new char[aNbComp*MED_SNAME_SIZE+1];
2962 char *aCompUnit = new char[aNbComp*MED_SNAME_SIZE+1];
2964 MEDfieldInfoByName(myFile->Id(),
2973 delete [] aCompName;
2974 delete [] aCompUnit;
2976 TGeom2Size::const_iterator anIter = aGeom2Size.begin();
2977 for (; anIter != aGeom2Size.end(); anIter++) {
2978 const EGeometrieElement& aGeom = anIter->first;
2979 med_int aNbGauss = -1;
2982 aRet = MEDfieldComputingStepInfo(myFile->Id(),
2988 char profilename[MED_NAME_SIZE+1];
2990 char locname[MED_NAME_SIZE+1];
2991 MEDfieldnValueWithProfile(myFile->Id(),
2996 med_geometry_type(aGeom),
3004 static TInt MAX_NB_GAUSS_POINTS = 32;
3005 if (aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
3008 aGeom2NbGauss[aGeom] = aNbGauss;
3013 EXCEPTION(std::runtime_error, "GetTimeStampInfo - MEDfieldnValueWithProfile(...)");
3017 //----------------------------------------------------------------------------
3020 ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
3021 EEntiteMaillage theEntity,
3022 const TGeom2Size& theGeom2Size,
3023 const TGeom2NbGauss& theGeom2NbGauss,
3027 const std::string& theUnitDt,
3028 const TGeom2Gauss& theGeom2Gauss)
3030 return PTimeStampInfo(new TTTimeStampInfo
3042 //----------------------------------------------------------------------------
3045 ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
3046 const PTimeStampInfo& theInfo)
3048 return PTimeStampInfo(new TTTimeStampInfo
3053 //----------------------------------------------------------------------------
3056 ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
3057 EEntiteMaillage theEntity,
3058 const TGeom2Size& theGeom2Size,
3062 PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo, theEntity, theGeom2Size);
3063 GetTimeStampInfo(theId, *anInfo, theErr);
3066 INITMSG(MYDEBUG, "GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
3067 TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
3068 TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
3069 for (; anIter != aGeom2NbGauss.end(); anIter++) {
3070 const EGeometrieElement& aGeom = anIter->first;
3071 INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
3078 //----------------------------------------------------------------------------
3081 ::GetNbProfiles(TErr* theErr)
3083 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3085 if (theErr && *theErr < 0)
3088 return MEDnProfile(myFile->Id());
3091 //----------------------------------------------------------------------------
3094 ::GetProfilePreInfo(TInt theId,
3097 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3099 if (theErr && *theErr < 0)
3100 return TProfileInfo::TInfo();
3103 TVector<char> aName(GetNOMLength()+1);
3106 aRet = MEDprofileInfo(myFile->Id(),
3113 EXCEPTION(std::runtime_error, "GetProfilePreInfo - MEDprofileInfo(...)");
3115 return TProfileInfo::TInfo(&aName[0], aSize);
3118 //----------------------------------------------------------------------------
3121 ::GetProfileInfo(TInt /*theId*/,
3122 TProfileInfo& theInfo,
3125 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3127 if (theErr && *theErr < 0)
3130 TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3131 TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3132 TValueHolder<TString, char> aProfileName(anInfo.myName);
3135 aRet = MEDprofileRd(myFile->Id(),
3141 EXCEPTION(std::runtime_error, "GetProfileInfo - MEDprofileRd(...)");
3144 //----------------------------------------------------------------------------
3147 ::SetProfileInfo(const TProfileInfo& theInfo,
3151 SetProfileInfo(theInfo, eLECTURE_ECRITURE, &aRet);
3154 SetProfileInfo(theInfo, eLECTURE_AJOUT, &aRet);
3157 SetProfileInfo(theInfo, eCREATION, &aRet);
3163 //----------------------------------------------------------------------------
3166 ::SetProfileInfo(const TProfileInfo& theInfo,
3170 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3172 if (theErr && *theErr < 0)
3175 TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3176 TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3177 TValueHolder<TString, char> aProfileName(anInfo.myName);
3180 aRet = MEDprofileWr(myFile->Id(), // descripteur du fichier.
3181 &aProfileName, // tableau de valeurs du profil.
3182 theInfo.GetSize(), // taille du profil.
3183 &anElemNum); // nom profil.
3187 EXCEPTION(std::runtime_error, "SetProfileInfo - MEDprofileWr(...)");
3190 //----------------------------------------------------------------------------
3193 ::CrProfileInfo(const TProfileInfo::TInfo& theInfo,
3194 EModeProfil theMode)
3196 return PProfileInfo(new TTProfileInfo
3201 //----------------------------------------------------------------------------
3204 ::GetPProfileInfo(TInt theId,
3205 EModeProfil theMode,
3208 TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
3209 PProfileInfo anInfo = CrProfileInfo(aPreInfo, theMode);
3210 GetProfileInfo(theId, *anInfo, theErr);
3215 //----------------------------------------------------------------------------
3218 ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3219 const TMKey2Profile& theMKey2Profile,
3220 const TKey2Gauss& theKey2Gauss,
3223 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3225 if (theErr && *theErr < 0)
3228 TIdt anId = myFile->Id();
3230 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3231 MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3233 MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3234 TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3235 TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3236 TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3238 MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3239 TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3240 TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo->myIsLocal);
3242 MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3243 TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3245 TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3246 TVector<char> aGaussName(GetNOMLength()+1);
3248 med_storage_mode aProfileMode = med_storage_mode(boost::get<0>(theMKey2Profile));
3249 MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
3250 TVector<char> aProfileName(GetNOMLength()+1);
3252 TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
3253 TGeom2Size::iterator anIter = aGeom2Size.begin();
3254 for (; anIter != aGeom2Size.end(); anIter++) {
3255 EGeometrieElement aGeom = anIter->first;
3256 TInt aNbElem = anIter->second;
3257 med_int profilesize, aNbGauss;
3259 TInt aNbVal = MEDfieldnValueWithProfile(anId,
3264 med_geometry_type(aGeom),
3277 EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldnValueWithProfile(...) - aNbVal == "<<aNbVal<<" <= 0");
3280 TInt aNbComp = aFieldInfo->myNbComp;
3281 TInt aNbValue = aNbVal;// / aNbGauss; rules in MED changed
3282 theTimeStampValue->AllocateValue(aGeom,
3286 TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
3289 "TWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
3290 "; aNbVal = "<<aNbVal<<
3291 "; aNbValue = "<<aNbValue<<
3292 "; aNbGauss = "<<aNbGauss<<
3293 "; aNbComp = "<<aNbComp<<
3296 TErr aRet = MEDfieldValueWithProfileRd(anId,
3301 med_geometry_type(aGeom),
3305 MED_ALL_CONSTITUENT,
3306 theTimeStampValue->GetValuePtr(aGeom));
3309 *theErr = MED_FALSE;
3312 EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldValueWithProfileRd(...)");
3315 MED::PGaussInfo aGaussInfo;
3316 TGaussInfo::TKey aKey(aGeom, &aGaussName[0]);
3317 if (strcmp(&aGaussName[0], "") != 0) {
3318 MED::TKey2Gauss::const_iterator anIter = theKey2Gauss.find(aKey);
3319 if (anIter != theKey2Gauss.end()) {
3320 aGaussInfo = anIter->second;
3321 aGeom2Gauss[aGeom] = aGaussInfo;
3325 MED::PProfileInfo aProfileInfo;
3326 if (strcmp(&aProfileName[0], MED_NO_PROFILE) != 0) {
3327 MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
3328 if (anIter != aKey2Profile.end()) {
3329 aProfileInfo = anIter->second;
3330 aGeom2Profile[aGeom] = aProfileInfo;
3334 if (aGaussInfo && aNbGauss != aGaussInfo->GetNbGauss()) {
3336 *theErr = MED_FALSE;
3339 EXCEPTION(std::runtime_error, "GetTimeStampValue - aNbGauss != aGaussInfo->GetNbGauss()");
3342 if (aProfileInfo && aProfileInfo->IsPresent()) {
3343 TInt aNbSubElem = aProfileInfo->GetSize();
3344 TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
3345 if (aProfileSize != aValueSize) {
3350 EXCEPTION(std::runtime_error,
3351 "GetTimeStampValue - aProfileSize("<<aProfileSize<<
3352 ") != aValueSize("<<aValueSize<<
3353 "); aNbVal = "<<aNbVal<<
3354 "; anEntity = "<<anEntity<<
3355 "; aGeom = "<<aGeom<<
3356 "; aNbElem = "<<aNbElem<<
3357 "; aNbSubElem = "<<aNbSubElem<<
3358 "; aNbComp = "<<aNbComp<<
3359 "; aNbGauss = "<<aNbGauss<<
3364 if ((aProfileMode == MED_GLOBAL_STMODE) && (aNbElem != aNbValue)) {
3369 EXCEPTION(std::runtime_error,
3370 "GetTimeStampValue - aNbElem("<<aNbElem<<
3371 ") != aNbValue("<<aNbValue<<
3372 "); aNbVal = "<<aNbVal<<
3373 "; anEntity = "<<anEntity<<
3374 "; aGeom = "<<aGeom<<
3375 "; aNbElem = "<<aNbElem<<
3376 "; aNbComp = "<<aNbComp<<
3377 "; aNbGauss = "<<aNbGauss<<
3384 //----------------------------------------------------------------------------
3387 ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3391 SetTimeStampValue(theTimeStampValue, eLECTURE_ECRITURE, &aRet);
3394 SetTimeStampValue(theTimeStampValue, eLECTURE_AJOUT, &aRet);
3400 //----------------------------------------------------------------------------
3403 ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
3407 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3409 if (theErr && *theErr < 0)
3413 TIdt anId = myFile->Id();
3415 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3416 MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3418 MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3419 TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3420 TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3421 TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3422 TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
3423 TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
3424 MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3426 MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3427 TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3429 MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3430 TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3432 const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
3433 TGeomSet::const_iterator anIter = aGeomSet.begin();
3434 for (; anIter != aGeomSet.end(); anIter++) {
3435 EGeometrieElement aGeom = *anIter;
3437 TVector<char> aGaussName(GetNOMLength()+1);
3438 MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aGeom);
3439 if (aGaussIter != aGeom2Gauss.end()) {
3440 MED::PGaussInfo aGaussInfo = aGaussIter->second;
3441 strcpy(&aGaussName[0], &aGaussInfo->myName[0]);
3444 TVector<char> aProfileName(GetNOMLength()+1);
3445 med_storage_mode aProfileMode = med_storage_mode(eNO_PFLMOD);
3446 MED::TGeom2Profile::const_iterator aProfileIter = aGeom2Profile.find(aGeom);
3447 if (aProfileIter != aGeom2Profile.end()) {
3448 MED::PProfileInfo aProfileInfo = aProfileIter->second;
3449 aProfileMode = med_storage_mode(aProfileInfo->myMode);
3450 strcpy(&aProfileName[0], &aProfileInfo->myName[0]);
3453 med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
3455 aRet = MEDfieldValueWithProfileWr(anId,
3461 med_geometry_type(aGeom),
3466 MED_ALL_CONSTITUENT,
3468 theTimeStampValue->GetValuePtr(aGeom));
3471 *theErr = MED_FALSE;
3474 EXCEPTION(std::runtime_error, "SetTimeStampValue - MEDfieldValueWithProfileWr(...)");
3479 INITMSG(MYDEBUG, "TWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
3482 //----------------------------------------------------------------------------
3485 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3486 ETypeChamp theTypeChamp,
3487 const TGeom2Profile& theGeom2Profile,
3488 EModeSwitch theMode)
3490 if (theTypeChamp == eFLOAT64)
3491 return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3496 return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3503 //----------------------------------------------------------------------------
3506 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3507 const TGeom2Profile& theGeom2Profile,
3508 EModeSwitch theMode)
3510 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3511 return CrTimeStampValue(theTimeStampInfo,
3512 aFieldInfo->GetType(),
3517 //----------------------------------------------------------------------------
3520 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3521 const PTimeStampValueBase& theInfo,
3522 ETypeChamp theTypeChamp)
3524 if (theTypeChamp == eFLOAT64)
3525 return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3529 return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3535 //----------------------------------------------------------------------------
3538 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3539 const PTimeStampValueBase& theInfo)
3541 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3542 return CrTimeStampValue(theTimeStampInfo,
3544 aFieldInfo->GetType());
3547 //----------------------------------------------------------------------------
3550 ::GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3551 const TMKey2Profile& theMKey2Profile,
3552 const TKey2Gauss& theKey2Gauss,
3555 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3556 PTimeStampValueBase anInfo = CrTimeStampValue(theTimeStampInfo,
3557 aFieldInfo->GetType());
3558 GetTimeStampValue(anInfo,
3563 if (aFieldInfo->GetType() == eFLOAT64)
3564 Print<TFloatTimeStampValue>(anInfo);
3566 Print<TIntTimeStampValue>(anInfo);
3571 //----------------------------------------------------------------------------
3574 ::GetTimeStampVal(const PTimeStampVal& theVal,
3575 const TMKey2Profile& theMKey2Profile,
3576 const TKey2Gauss& theKey2Gauss,
3579 PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3580 PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3581 if (aFieldInfo->GetType() == eFLOAT64)
3582 GetTimeStampValue(theVal,
3587 PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3590 GetTimeStampValue(aVal,
3594 CopyTimeStampValueBase(aVal, theVal);
3598 //----------------------------------------------------------------------------
3601 ::SetTimeStamp(const PTimeStampVal& theVal,
3604 PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3605 PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3606 if (aFieldInfo->GetType() == eFLOAT64)
3607 SetTimeStampValue(theVal, theErr);
3609 PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3611 theVal->GetGeom2Profile(),
3612 theVal->GetModeSwitch());
3613 CopyTimeStampValueBase(theVal, aVal);
3614 SetTimeStampValue(aVal, theErr);
3618 //----------------------------------------------------------------------------
3621 ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3622 const TGeom2Profile& theGeom2Profile,
3623 EModeSwitch theMode)
3625 return CrTimeStampValue(theTimeStampInfo,
3631 //----------------------------------------------------------------------------
3634 ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3635 const PTimeStampVal& theInfo)
3637 return CrTimeStampValue(theTimeStampInfo,
3642 //----------------------------------------------------------------------------
3645 ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3646 const TMKey2Profile& theMKey2Profile,
3647 const TKey2Gauss& theKey2Gauss,
3650 PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
3651 GetTimeStampVal(anInfo,
3658 //----------------------------------------------------------------------------
3661 ::GetPGrilleInfo(const PMeshInfo& theMeshInfo)
3663 if (theMeshInfo->GetType() != eSTRUCTURE)
3664 return PGrilleInfo();
3667 GetGrilleType(*theMeshInfo, type);
3669 if (type == eGRILLE_STANDARD) {
3670 const TInt nnoeuds = GetNbNodes(*theMeshInfo);
3671 anInfo = CrGrilleInfo(theMeshInfo, type, nnoeuds);
3675 aVec.resize(theMeshInfo->GetDim());
3676 for (int aAxe=0;aAxe<theMeshInfo->GetDim();aAxe++) {
3677 ETable aATable = eCOOR_IND1;
3680 aATable = eCOOR_IND1;
3683 aATable = eCOOR_IND2;
3686 aATable = eCOOR_IND3;
3689 aVec[aAxe] = GetNbNodes(*theMeshInfo, aATable);
3691 anInfo = CrGrilleInfo(theMeshInfo, type, aVec);
3694 GetGrilleInfo(anInfo);
3695 anInfo->SetGrilleType(type);
3698 INITMSG(MYDEBUG, "GetPGrilleInfo: ");
3700 TInt aNbElem = anInfo->GetNbNodes();
3701 BEGMSG(MYVALUEDEBUG, "GetFamNumNode: ");
3702 for (TInt iElem = 0; iElem < aNbElem; iElem++) {
3703 ADDMSG(MYVALUEDEBUG, anInfo->GetFamNumNode(iElem)<<", ");
3705 TInt aNbCells = anInfo->GetNbCells();
3706 BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
3707 for (TInt iElem = 0; iElem < aNbCells; iElem++) {
3708 ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
3710 ADDMSG(MYVALUEDEBUG, std::endl);
3711 BEGMSG(MYVALUEDEBUG, "GetCoordName: ");
3712 for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3713 ADDMSG(MYVALUEDEBUG, anInfo->GetCoordName(iElem)<<", ");
3715 ADDMSG(MYVALUEDEBUG, std::endl);
3716 BEGMSG(MYVALUEDEBUG, "GetCoordUnit: ");
3717 for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3718 ADDMSG(MYVALUEDEBUG, anInfo->GetCoordUnit(iElem)<<", ");
3720 ADDMSG(MYVALUEDEBUG, std::endl);
3728 //----------------------------------------------------------------------------
3731 ::GetPGrilleInfo(const PMeshInfo& theMeshInfo,
3732 const PGrilleInfo& theInfo)
3734 PGrilleInfo anInfo = CrGrilleInfo(theMeshInfo, theInfo);
3738 //----------------------------------------------------------------------------
3741 ::GetGrilleInfo(TGrilleInfo& theInfo,
3744 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3746 if (theErr && *theErr < 0)
3749 MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
3750 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3751 EMaillage aMaillageType = aMeshInfo.myType;
3753 GetGrilleType(aMeshInfo, theInfo.myGrilleType, theErr);
3754 EGrilleType aGrilleType = theInfo.myGrilleType;
3757 if (aMaillageType == eSTRUCTURE && aGrilleType == eGRILLE_STANDARD) {
3758 GetGrilleStruct(aMeshInfo, theInfo.myGrilleStructure, theErr);
3760 TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
3761 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
3762 TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
3763 TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
3764 //med_axis_type aRepere;
3766 aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
3776 EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshNodeCoordinateRd(...)");
3778 //TInt aNbNodes = theInfo.GetNbNodes();//GetNbFamilies(aMeshInfo);
3779 TValueHolder<TElemNum, med_int> aFamNumNode(theInfo.myFamNumNode);
3781 aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3790 // if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3792 int mySize = (int)theInfo.myFamNumNode.size();
3793 theInfo.myFamNumNode.clear();
3794 theInfo.myFamNumNode.resize(mySize,0);
3798 // EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3803 //============================
3806 if (aMaillageType == eSTRUCTURE && aGrilleType != eGRILLE_STANDARD) {
3807 ETable aTable = eCOOR_IND1;
3808 for (med_int anAxis = 1; anAxis <= aMeshInfo.myDim; anAxis++) {
3811 aTable = eCOOR_IND1;
3814 aTable = eCOOR_IND2;
3817 aTable = eCOOR_IND3;
3826 EXCEPTION(std::runtime_error, "GetGrilleInfo - anAxis number out of range(...)");
3828 TInt aNbIndexes = GetNbNodes(aMeshInfo, aTable);
3830 EXCEPTION(std::runtime_error, "GetGrilleInfo - Erreur a la lecture de la taille de l'indice");
3832 TValueHolder<TFloatVector, med_float> anIndexes(theInfo.GetIndexes(anAxis-1));
3833 //TValueHolder<ETable, med_data_type > table(aTable);
3834 //char aCompNames[MED_SNAME_SIZE+1];
3835 //char anUnitNames[MED_SNAME_SIZE+1];
3836 aRet=MEDmeshGridIndexCoordinateRd(myFile->Id(),
3838 MED_NO_DT,MED_NO_IT,
3842 //theInfo.SetCoordName(anAxis-1, aCompNames);
3843 //theInfo.SetCoordUnit(anAxis-1, anUnitNames);
3844 theInfo.SetGrilleStructure(anAxis-1, aNbIndexes);
3849 EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDindicesCoordLire(...)");
3853 EGeometrieElement aGeom = theInfo.GetGeom();
3854 EEntiteMaillage aEntity = theInfo.GetEntity();
3855 TInt aNbCells = theInfo.GetNbCells();
3857 theInfo.myFamNum.resize(aNbCells);
3858 TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
3860 aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3861 &aMeshName, MED_NO_DT, MED_NO_IT, med_entity_type(aEntity),
3862 med_geometry_type(aGeom), &aFamNum);
3864 if (aMeshInfo.myDim == 3)
3866 aGeom = theInfo.GetSubGeom();
3867 aEntity = theInfo.GetSubEntity();
3868 aNbCells = theInfo.GetNbSubCells();
3870 theInfo.myFamSubNum.resize(aNbCells, 0);
3871 TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamSubNum);
3873 aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3877 med_entity_type(aEntity),
3878 med_geometry_type(aGeom),
3882 // if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3884 int mySize = (int)theInfo.myFamNumNode.size();
3885 theInfo.myFamNumNode.clear();
3886 theInfo.myFamNumNode.resize(mySize, 0);
3890 // EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3896 //----------------------------------------------------------------------------
3899 ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3902 SetGrilleInfo(theInfo, eLECTURE_ECRITURE, theErr);
3905 //----------------------------------------------------------------------------
3908 ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3912 if (theInfo.myMeshInfo->myType != eSTRUCTURE)
3914 TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3916 if (theErr && *theErr < 0)
3919 MED::TGrilleInfo& anInfo = const_cast<MED::TGrilleInfo&>(theInfo);
3921 MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
3922 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3924 TValueHolder<EGrilleType, med_grid_type > aGrilleType(anInfo.myGrilleType);
3927 aRet = MEDmeshGridTypeRd(myFile->Id(),
3933 EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridTypeRd(...)");
3935 if (anInfo.myGrilleType == eGRILLE_STANDARD) {
3936 TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
3937 TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(anInfo.myModeSwitch);
3938 TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
3939 TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
3940 med_int aNbNoeuds = med_int(anInfo.myCoord.size() / aMeshInfo.myDim);
3941 //med_axis_type aRepere = MED_CARTESIAN;
3943 aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
3953 EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshNodeCoordinateWr(...)");
3955 TValueHolder<TIntVector, med_int> aGrilleStructure(anInfo.myGrilleStructure);
3956 aRet = MEDmeshGridStructWr(myFile->Id(),
3963 EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridStructWr(...)");
3967 for (med_int aAxis = 0; aAxis < aMeshInfo.myDim; aAxis++) {
3968 aRet = MEDmeshGridIndexCoordinateWr(myFile->Id(),
3974 anInfo.GetIndexes(aAxis).size(),
3975 &anInfo.GetIndexes(aAxis)[0]);
3978 EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridIndexCoordinateWr(...)");
3986 //----------------------------------------------------------------------------
3989 ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3990 const PGrilleInfo& theInfo)
3992 return PGrilleInfo(new TTGrilleInfo
3997 //----------------------------------------------------------------------------
4000 ::CrGrilleInfo(const PMeshInfo& /*theMeshInfo*/)
4002 return PGrilleInfo(); // not implemented????
4005 //----------------------------------------------------------------------------
4008 ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
4009 const EGrilleType& type)
4011 return PGrilleInfo(new TTGrilleInfo
4016 //----------------------------------------------------------------------------
4019 ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
4020 const EGrilleType& type,
4021 const TInt& nbNodes)
4023 return PGrilleInfo(new TTGrilleInfo
4029 //----------------------------------------------------------------------------
4032 ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
4033 const EGrilleType& type,
4034 const MED::TIntVector& nbNodeVec)
4036 return PGrilleInfo(new TTGrilleInfo
4042 //----------------------------------------------------------------------------
4045 ::GetGrilleType(const MED::TMeshInfo& theMeshInfo,
4046 EGrilleType& theGridType,
4049 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
4051 if (theErr && *theErr < 0)
4052 EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)");
4054 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4056 if (aMeshInfo.myType == eSTRUCTURE) {
4057 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4058 TValueHolder<EGrilleType, med_grid_type> aGridType(theGridType);
4059 TErr aRet = MEDmeshGridTypeRd(myFile->Id(),
4064 EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridTypeRd(...)");
4068 //----------------------------------------------------------------------------
4071 ::GetGrilleStruct(const MED::TMeshInfo& theMeshInfo,
4072 TIntVector& theStruct,
4075 TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
4077 if (theErr && *theErr < 0)
4081 MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4083 TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4084 TValueHolder<TIntVector, med_int> aGridStructure(theStruct);
4086 aRet = MEDmeshGridStructRd(myFile->Id(),
4094 EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridStructRd(...)");