-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDFileUtilities.hxx"
+#include "MEDLoaderNS.hxx"
#include "MEDFileSafeCaller.txx"
#include "MEDFileMesh.hxx"
#include "MEDFileField.hxx"
using namespace MEDCoupling;
-/// @cond INTERNAL
-
-namespace MEDLoaderNS
-{
- int readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities);
- void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
- void writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch);
- med_int getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName);
- std::vector<std::string> getMeshNamesFid(med_idt fid);
-}
-
-/// @endcond
-
-
/// @cond INTERNAL
/*!
int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
{
possibilities.clear();
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
int ret;
std::set<int> poss;
char nommaa[MED_NAME_SIZE+1];
std::string MEDCoupling::MEDFileVersionStr()
{
- return std::string(MED_VERSION_STR);
+ const int SZ=20;
+ char buf[SZ];
+ std::fill(buf,buf+SZ,'\0');
+ const char START_EXPECTED[]="MED-";
+ med_err ret(MEDlibraryStrVersion(buf));
+ if(ret!=0)
+ throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
+ std::string zeRet(buf);
+ std::size_t pos(zeRet.find(START_EXPECTED,0));
+ if(pos!=0)
+ {
+ std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
+}
+
+std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
+{
+#if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
+ const int SZ=20;
+ const char START_EXPECTED[]="MED-";
+ char buf[SZ];
+ std::fill(buf,buf+SZ,'\0');
+ MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
+ std::string ret(buf);
+ std::size_t pos(ret.find(START_EXPECTED,0));
+ if(pos!=0)
+ {
+ std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
+#else
+ std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
+ throw INTERP_KERNEL::Exception(oss.str());
+#endif
}
void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
{
- major=MED_NUM_MAJEUR;
- minor=MED_NUM_MINEUR;
- release=MED_NUM_RELEASE;
+ med_int majj,minn,rell;
+ med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
+ if(ret!=0)
+ throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
+ major=majj;
+ minor=minn;
+ release=rell;
}
/*!
*/
std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, int& numberOfNodes)
{
- CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
std::set<int> poss;
char nommaa[MED_NAME_SIZE+1];
char maillage_description[MED_COMMENT_SIZE+1];
std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
- std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
- return ret;
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
+ return MEDLoaderNS::getMeshNamesFid(fid);
}
std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields(MEDnField(fid));
std::vector<std::string> fields(nbFields);
med_field_type typcha;
std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector<std::string> ret;
//
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nfam=MEDnFamily(fid,meshName.c_str());
std::vector<std::string> ret(nfam);
char nomfam[MED_NAME_SIZE+1];
std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nfam=MEDnFamily(fid,meshName.c_str());
std::vector<std::string> ret;
char nomfam[MED_NAME_SIZE+1];
std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
- med_int nfam=MEDnFamily(fid,meshName.c_str());
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
+ med_int nfam(MEDnFamily(fid,meshName.c_str()));
std::vector<std::string> ret;
char nomfam[MED_NAME_SIZE+1];
med_int numfam;
std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nfam=MEDnFamily(fid,meshName.c_str());
std::vector<std::string> ret;
char nomfam[MED_NAME_SIZE+1];
std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector<std::string> ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
med_field_type typcha;
for(int i=0;i<nbFields;i++)
std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector<std::string> ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector<std::string> ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector<std::string> ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
char pflname[MED_NAME_SIZE+1]="";
char locname[MED_NAME_SIZE+1]="";
std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::vector< std::pair< std::pair<int,int>, double > > ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
{
- MEDCoupling::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;
std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
{
- MEDCoupling::CheckFileForRead(fileName);
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
med_int nbFields=MEDnField(fid);
//
med_field_type typcha;