-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <med.h>
#include <med_err.h>
+#include <med_proto.h>
+
+#ifdef WIN32
+#include <windows.h>
+#endif
#include <boost/version.hpp>
TFile(const TFile&);
public:
- TFile(const std::string& theFileName):
+ TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1):
myCount(0),
myFid(0),
- myFileName(theFileName)
- {}
+ myFileName(theFileName),
+ myMajor(theMajor),
+ myMinor(theMinor)
+ {
+ if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM;
+ if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
+ }
~TFile()
{
{
if (myCount++ == 0) {
const char* aFileName = myFileName.c_str();
- myFid = MEDfileOpen(aFileName, med_access_mode(theMode));
+#ifdef WIN32
+ if (med_access_mode(theMode) == MED_ACC_RDWR) {
+ // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5
+ std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1";
+#ifdef UNICODE
+ const char* to_decode = aReadOlnyRmCmd.c_str();
+ int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0);
+ wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1];
+ MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed);
+ awReadOlnyRmCmd[size_needed] = '\0';
+ _wsystem(awReadOlnyRmCmd);
+ delete[] awReadOlnyRmCmd;
+#else
+ system(aReadOlnyRmCmd.c_str());
+#endif
+ }
+#endif
+ myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
}
if (theErr)
*theErr = TErr(myFid);
else if (myFid < 0)
- EXCEPTION(std::runtime_error, "TFile - MEDfileOpen('"<<myFileName<<"',"<<theMode<<")");
+ EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< MED_MAJOR_NUM<<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
}
const TIdt&
TInt myCount;
TIdt myFid;
std::string myFileName;
+ TInt myMajor;
+ TInt myMinor;
};
//---------------------------------------------------------------
class TFileWrapper
{
PFile myFile;
+ TInt myMinor;
public:
TFileWrapper(const PFile& theFile,
EModeAcces theMode,
- TErr* theErr = NULL):
- myFile(theFile)
+ TErr* theErr = NULL,
+ TInt theMinor=-1):
+ myFile(theFile),
+ myMinor(theMinor)
{
+ if (myMinor < 0) myMinor = MED_MINOR_NUM;
myFile->Open(theMode, theErr);
}
//---------------------------------------------------------------
TWrapper
- ::TWrapper(const std::string& theFileName):
- myFile(new TFile(theFileName))
+ ::TWrapper(const std::string& theFileName, bool write, TInt theMajor, TInt theMinor):
+ myFile(new TFile(theFileName, theMajor, theMinor)),
+ myMajor(theMajor),
+ myMinor(theMinor)
{
TErr aRet;
- myFile->Open(eLECTURE_ECRITURE, &aRet);
- // if (aRet < 0)
- // myFile->Close();
- // myFile->Open(eLECTURE_AJOUT, &aRet);
- // }
- if (aRet < 0) {
- myFile->Close();
- myFile->Open(eLECTURE, &aRet);
+ if ( write ) {
+ myFile->Open(eLECTURE_ECRITURE, &aRet);
+ if (aRet < 0) {
+ myFile->Close();
+ myFile->Open(eCREATION, &aRet);
+ }
}
- if (aRet < 0) {
- myFile->Close();
- myFile->Open(eCREATION, &aRet);
+ else {
+ myFile->Open(eLECTURE, &aRet);
}
}
TWrapper
::GetNbMeshes(TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
MED::TMeshInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
::GetNbFamilies(const MED::TMeshInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
const MED::TMeshInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
const MED::TMeshInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
MED::TFamilyInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGeometrieElement theGeom,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
ETable theTable,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
::GetNodeInfo(MED::TNodeInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EConnectivite theConnMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return 0;
::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EConnectivite theConnMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
::GetPolyedreInfo(TPolyedreInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
{
TEntityInfo anInfo;
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return anInfo;
EConnectivite theConnMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
::GetCellInfo(MED::TCellInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
TValueHolder<EConnectivite, med_connectivity_mode> aConnMode (theInfo.myConnMode);
TErr aRet;
+ med_bool dummy;
+ aRet = MEDmeshnEntity(myFile->Id(),
+ &aMeshName,
+ MED_NO_DT,
+ MED_NO_IT,
+ anEntity,
+ aGeom,
+ MED_NAME,
+ aConnMode,
+ &dummy, &dummy);
+ if ( aRet > 0 )
+ {
+ // names are present in the file, they will be read in spite of theInfo.myIsElemNames
+ theInfo.myIsElemNames = eVRAI;
+ theInfo.myElemNames.reset( new TString( theInfo.myNbElem * GetPNOMLength() + 1 ));
+ anElemNames.myRepresentation = & ((TString&) theInfo.myElemNames )[0];
+ }
+
aRet = MEDmeshElementRd(myFile->Id(),
&aMeshName,
MED_NO_DT,
EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)");
if (anIsFamNum == MED_FALSE)
- {
- int mySize = (int) theInfo.myFamNum->size();
- theInfo.myFamNum->clear();
- theInfo.myFamNum->resize(mySize, 0);
- }
+ {
+ int mySize = (int) theInfo.myFamNum->size();
+ theInfo.myFamNum->clear();
+ theInfo.myFamNum->resize(mySize, 0);
+ }
}
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
if (theErr)
*theErr = aRet;
else if (aRet < 0)
- EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...)");
+ EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...), ret="<< aRet);
}
//----------------------------------------------------------------------------
TWrapper
::GetBallGeom(const TMeshInfo& theMeshInfo)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE);
+ TErr anError;
+ TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
// read med_geometry_type of "MED_BALL" element
char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
TWrapper
::GetNbBalls(const TMeshInfo& theMeshInfo)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE);
+ TErr anError;
+ TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
EGeometrieElement ballType = GetBallGeom(theMeshInfo);
if (ballType < 0)
::GetBallInfo(TBallInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
// check geometry of MED_BALL
if (theInfo.myGeom == eBALL)
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
TErr ret;
char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
// write node ids
SetCellInfo(theInfo, theMode, theErr);
- if (theErr && theErr < 0)
+ if (theErr && *theErr < 0)
return;
// write diameter
TWrapper
::GetNbFields(TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
::GetNbComp(TInt theFieldId,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
MED::TFieldInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
TWrapper
::GetNbGauss(TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
::GetGaussPreInfo(TInt theId,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
TGaussInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
TErr* theErr)
{
theEntity = EEntiteMaillage(-1);
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr) {
if (theEntityInfo.empty())
MED::TTimeStampInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
TWrapper
::GetNbProfiles(TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return -1;
::GetProfilePreInfo(TInt theId,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return TProfileInfo::TInfo();
TProfileInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
const TKey2Gauss& theKey2Gauss,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EModeAcces theMode,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
::GetGrilleInfo(TGrilleInfo& theInfo,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;
{
if (theInfo.myMeshInfo->myType != eSTRUCTURE)
return;
- TFileWrapper aFileWrapper(myFile, theMode, theErr);
+ TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
if (theErr && *theErr < 0)
return;
EGrilleType& theGridType,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)");
TIntVector& theStruct,
TErr* theErr)
{
- TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
+ TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
if (theErr && *theErr < 0)
return;