From: ageay Date: Mon, 25 Feb 2013 17:53:07 +0000 (+0000) Subject: Management of MEDfileParameters. X-Git-Tag: V6_main_FINAL~339 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5557640c5801cbdcf062cf5fc2e54b281d004334;p=tools%2Fmedcoupling.git Management of MEDfileParameters. --- diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index 0a812c71a..aeca829c2 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -41,6 +41,7 @@ SET(medloader_SOURCES MEDFileBasis.cxx MEDFileMeshLL.cxx MEDFileField.cxx + MEDFileParameter.cxx MEDFileData.cxx SauvMedConvertor.cxx SauvReader.cxx diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index fbabd4709..f2d09da1c 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -40,8 +40,11 @@ MEDFileData *MEDFileData::deepCpy() const throw(INTERP_KERNEL::Exception) MEDCouplingAutoRefCountObjectPtr meshes; if((const MEDFileMeshes *)_meshes) meshes=_meshes->deepCpy(); + MEDCouplingAutoRefCountObjectPtr params; + if((const MEDFileParameters *)_params) + params=_params->deepCpy(); MEDCouplingAutoRefCountObjectPtr ret=MEDFileData::New(); - ret->_fields=fields; ret->_meshes=meshes; + ret->_fields=fields; ret->_meshes=meshes; ret->_params=params; return ret.retn(); } @@ -52,6 +55,8 @@ std::size_t MEDFileData::getHeapMemorySize() const ret+=_fields->getHeapMemorySize(); if((const MEDFileMeshes *)_meshes) ret+=_meshes->getHeapMemorySize(); + if((const MEDFileParameters *)_params) + ret+=_params->getHeapMemorySize(); return ret; } @@ -65,22 +70,33 @@ MEDFileMeshes *MEDFileData::getMeshes() const return const_cast(static_cast(_meshes)); } +MEDFileParameters *MEDFileData::getParams() const +{ + return const_cast(static_cast(_params)); +} + void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception) { - if(!fields) - throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !"); - fields->incrRef(); + if(fields) + fields->incrRef(); _fields=fields; } void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception) { - if(!meshes) - throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !"); - meshes->incrRef(); + if(meshes) + meshes->incrRef(); _meshes=meshes; } +void MEDFileData::setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception) +{ + if(!params) + params->incrRef(); + _params=params; + +} + int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception) { const MEDFileFields *f=_fields; @@ -97,6 +113,14 @@ int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception) return m->getNumberOfMeshes(); } +int MEDFileData::getNumberOfParams() const throw(INTERP_KERNEL::Exception) +{ + const MEDFileParameters *p=_params; + if(!p) + throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !"); + return p->getNumberOfParams(); +} + std::string MEDFileData::simpleRepr() const { std::ostringstream oss; @@ -117,6 +141,14 @@ std::string MEDFileData::simpleRepr() const } else oss << "No meshes set !!!\n"; + oss << "Params part :\n*************\n\n"; + const MEDFileParameters *tmp3=_params; + if(tmp3) + { + tmp3->simpleReprWithoutHeader(oss); + } + else + oss << "params set !!!\n"; return oss.str(); } @@ -207,4 +239,7 @@ void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNE const MEDFileFields *fs=_fields; if(fs) fs->writeLL(fid); + const MEDFileParameters *ps=_params; + if(ps) + ps->writeLL(fid); } diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index c732aad9d..43d9ac219 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -22,6 +22,7 @@ #define __MEDFILEDATA_HXX__ #include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDFileParameter.hxx" #include "MEDFileField.hxx" #include "MEDFileMesh.hxx" @@ -39,10 +40,13 @@ namespace ParaMEDMEM std::size_t getHeapMemorySize() const; MEDFileFields *getFields() const; MEDFileMeshes *getMeshes() const; + MEDFileParameters *getParams() const; void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + void setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; // bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); @@ -56,6 +60,7 @@ namespace ParaMEDMEM private: MEDCouplingAutoRefCountObjectPtr _fields; MEDCouplingAutoRefCountObjectPtr _meshes; + MEDCouplingAutoRefCountObjectPtr _params; }; } diff --git a/src/MEDLoader/MEDFileParameter.cxx b/src/MEDLoader/MEDFileParameter.cxx new file mode 100644 index 000000000..61a6d55fa --- /dev/null +++ b/src/MEDLoader/MEDFileParameter.cxx @@ -0,0 +1,840 @@ +// Copyright (C) 2007-2012 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#include "MEDFileParameter.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include "InterpKernelAutoPtr.hxx" + +using namespace ParaMEDMEM; + +MEDFileParameter1TS::MEDFileParameter1TS(int iteration, int order, double time):_iteration(iteration),_order(order),_time(time) +{ +} + +MEDFileParameter1TS::MEDFileParameter1TS():_iteration(-1),_order(-1),_time(0.) +{ +} + +bool MEDFileParameter1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + std::ostringstream oss; + if(!other) + { what="Other is null"; return false; } + if(_iteration!=other->_iteration) + { oss << "iteration number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; } + if(_order!=other->_order) + { oss << "order number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; } + if(fabs(_time-other->_time)>eps) + { oss << "time mismatches " << _time << " != " << other->_time << " eps=" << eps; what=oss.str(); return false; } + return true; +} + +MEDFileParameter1TS *MEDFileParameterDouble1TSWTI::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TSWTI(*this); +} + +bool MEDFileParameterDouble1TSWTI::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + if(!MEDFileParameter1TS::isEqual(other,eps,what)) + return false; + const MEDFileParameterDouble1TSWTI *otherC=dynamic_cast(other); + if(!otherC) + { what="IsEqual fails because this is double parameter other no !"; return false; } + if(fabs(_arr-otherC->_arr)>eps) + { std::ostringstream oss; oss << "value differ " << _arr << " != " << otherC->_arr << " (eps=" << eps << ")"; return false; } + return true; +} + +std::size_t MEDFileParameterDouble1TSWTI::getHeapMemorySize() const +{ + return sizeof(MEDFileParameterDouble1TSWTI); +} + +void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const +{ + std::string startOfLine(bkOffset,' '); + oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl; + oss << startOfLine << "Time associacited = " << _time << std::endl; + oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl; +} + +MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time) +{ + return new MEDFileParameterDouble1TSWTI(iteration,order,time); +} + +MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits::max()) +{ +} + +MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time) +{ +} + +void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : "; + for(int i=0;i(&_arr)); + return ; + } + else + { + oss << "(" << locDt << "," << locIt << ")"; + if(i!=nbOfSteps-1) + oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) +{ + MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast(&_arr)); +} + +void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception) +{ + int locDt,locIt; + double dt; + MEDparameterComputationStepInfo(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt); + _iteration=locDt; _order=locIt; _time=dt; + MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast(&_arr)); +} + +void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) +{ + char nameW[MED_NAME_SIZE+1]; + MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy()); + MEDparameterValueWr(fid,nameW,_iteration,_order,_time,reinterpret_cast(&_arr)); +} + +std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const +{ + return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity(); +} + +bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const +{ + std::ostringstream oss; + if(_name!=other._name) + { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; } + if(_desc_name!=other._desc_name) + { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; } + if(_dt_unit!=other._dt_unit) + { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; } + return true; +} + +void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception) +{ + char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1]; + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy()); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy()); + MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy()); + MEDparameterCr(fid,nameW,typ,descW,dtunitW); +} + +void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const +{ + std::string startOfLine(bkOffset,' '); + oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl; + oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl; + oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl; +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New() +{ + return new MEDFileParameterDouble1TS; +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName); +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName,paramName); +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName,paramName,dt,it); +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS() +{ +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : "; + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,_name,0); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + oss << paramNameCpp; + if(i!=nbPar-1) oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + if(nbPar<1) + { + std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + int nbOfSteps; + MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps); + std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE); + if(paramType==MED_FLOAT64) + { + if(nbOfSteps>0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,_name,0); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } +} + +bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what)) + return false; + const MEDFileParameterDouble1TS *otherC=dynamic_cast(other); + if(!otherC) + { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; } + if(!isEqualStrings(*otherC,what)) + return false; + return true; +} + +MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(*this); +} + +std::string MEDFileParameterDouble1TS::simpleRepr() const +{ + std::ostringstream oss; + MEDFileParameterTinyInfo::mainRepr(0,oss); + MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss); + return oss.str(); +} + +std::size_t MEDFileParameterDouble1TS::getHeapMemorySize() const +{ + return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS); +} + +void MEDFileParameterDouble1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64); + MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this); +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New() +{ + return new MEDFileParameterMultiTS; +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(fileName); +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(fileName,paramName); +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS() +{ +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts) +{ + if(deepCopy) + for(std::size_t i=0;i<_param_per_ts.size();i++) + { + const MEDFileParameter1TS *elt=_param_per_ts[i]; + if(elt) + _param_per_ts[i]=elt->deepCpy(); + } +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + if(nbPar<1) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + int nbOfSteps; + MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps); + std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE); + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,paramType,nbOfSteps); +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : "; + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,paramType,nbOfSteps); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + oss << paramNameCpp; + if(i!=nbPar-1) oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception) +{ + _param_per_ts.resize(nbOfSteps); + for(int i=0;ireadValue(fid,_name.c_str()); + break; + /*case MED_INT32; + _param_per_ts[i]=; + break;*/ + default: + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !"); + } + } +} + +std::size_t MEDFileParameterMultiTS::getHeapMemorySize() const +{ + std::size_t ret=sizeof(MEDFileParameterMultiTS); + std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr)*_param_per_ts.capacity(); + for(std::size_t i=0;i<_param_per_ts.size();i++) + { + const MEDFileParameter1TS *pt(_param_per_ts[i]); + if(pt) + ret2+=pt->getHeapMemorySize(); + } + return ret2+ret; +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(*this,true); +} + +void MEDFileParameterMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeLL(fid,*this); +} + +void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) +{ + std::set diffType; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(dynamic_cast(elt)) + diffType.insert(MED_FLOAT64); + } + if(diffType.size()>1) + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ..."); + if(diffType.empty()) + return; + med_parameter_type typ=*diffType.begin(); + MEDFileParameterTinyInfo::writeLLHeader(fid,typ); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + elt->writeLL(fid,_name,mw); + } +} + +std::string MEDFileParameterMultiTS::simpleRepr() const +{ + std::ostringstream oss; + simpleRepr2(0,oss); + return oss.str(); +} + +void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const +{ + MEDFileParameterTinyInfo::mainRepr(bkOffset,oss); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + elt->simpleRepr2(bkOffset+2,oss); + } +} + +void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr elt=MEDFileParameterDouble1TSWTI::New(dt,it,time); + elt->setValue(val); + MEDCouplingAutoRefCountObjectPtr elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef(); + _param_per_ts.push_back(elt2); +} + +double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosOfTimeStep(iteration,order); + const MEDFileParameter1TS *elt=_param_per_ts[pos]; + if(!elt) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order; + oss << " exists but elt is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast(elt); + if(!eltC) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order; + oss << " exists but not double !"; + } + return eltC->getValue(); +} + +int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + if(elt->getIteration()==iteration && elt->getOrder()) + return ret; + else + oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! Possibilities are :"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + if(fabs(elt->getTimeValue()-time)<=eps) + return ret; + else + oss << elt->getTimeValue() << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception) +{ + std::vector b(_param_per_ts.size(),true); + int len=(int)_param_per_ts.size(); + for(const int *w=startIds;w!=endIds;w++) + if(*w>=0 && *w > paramPerTs(newNb); + std::size_t j=0; + for(std::size_t i=0;i<_param_per_ts.size();i++) + if(b[i]) + paramPerTs[j++]=_param_per_ts[i]; + _param_per_ts=paramPerTs; +} + +std::vector< std::pair > MEDFileParameterMultiTS::getIterations() const throw(INTERP_KERNEL::Exception) +{ + std::vector< std::pair > ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + ret.push_back(std::pair(elt->getIteration(),elt->getOrder())); + } + return ret; +} + +/*! + * \param [out] ret1 + */ +std::vector< std::pair > MEDFileParameterMultiTS::getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception) +{ + std::vector< std::pair > ret0; + ret1.clear(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + ret0.push_back(std::pair(elt->getIteration(),elt->getOrder())); + ret1.push_back(elt->getTimeValue()); + } + } + return ret0; +} + +MEDFileParameters *MEDFileParameters::New() +{ + return new MEDFileParameters; +} + +MEDFileParameters *MEDFileParameters::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameters(fileName); +} + +MEDFileParameters::MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + _params.resize(nbPar); + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i)*_params.capacity(); + for(std::size_t i=0;i<_params.size();i++) + { + const MEDFileParameterMultiTS *pt(_params[i]); + if(pt) + ret2+=pt->getHeapMemorySize(); + } + return ret2+ret; +} + +MEDFileParameters *MEDFileParameters::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameters(*this,true); +} + +MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params) +{ + if(deepCopy) + for(std::size_t i=0;i<_params.size();i++) + { + const MEDFileParameterMultiTS *elt=_params[i]; + if(elt) + _params[i]=elt->deepCpy(); + } +} + +void MEDFileParameters::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeLL(fid); +} + +void MEDFileParameters::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + elt->writeLL(fid,*this); + } +} + +std::vector MEDFileParameters::getParamsNames() const throw(INTERP_KERNEL::Exception) +{ + std::vector ret(_params.size()); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++,i++) + { + const MEDFileParameterMultiTS *p=(*it); + if(p) + { + ret[i]=p->getName(); + } + else + { + std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + +std::string MEDFileParameters::simpleRepr() const +{ + std::ostringstream oss; + simpleReprWithoutHeader(oss); + return oss.str(); +} + +void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + elt->simpleRepr2(2,oss); + } +} + +void MEDFileParameters::resize(int newSize) throw(INTERP_KERNEL::Exception) +{ + if(newSize<0) + throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !"); + _params.resize(newSize); +} + +void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception) +{ + if(param) + param->incrRef(); + MEDCouplingAutoRefCountObjectPtr elt(param); + _params.push_back(elt); +} + +void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception) +{ + if(i<0) + throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !"); + if(i>=(int)_params.size()) + _params.resize(i+1); + if(param) + param->incrRef(); + MEDCouplingAutoRefCountObjectPtr elt(param); + _params[i]=elt; +} + +/*! + * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer. + */ +MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_params.size()) + { + std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileParameterMultiTS *elt=_params[i]; + return const_cast(elt); +} + +/*! + * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer. + */ +MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosFromParamName(paramName); + return getParamAtPos(pos); +} + +void MEDFileParameters::destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_params.size()) + { + std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _params[i]=MEDCouplingAutoRefCountObjectPtr(0); +} + +int MEDFileParameters::getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :"; + int ret=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++,ret++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + { + if(elt->getName()==paramName) + return ret; + else + oss << elt->getName() << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileParameters::getNumberOfParams() const throw(INTERP_KERNEL::Exception) +{ + return (int)_params.size(); +} diff --git a/src/MEDLoader/MEDFileParameter.hxx b/src/MEDLoader/MEDFileParameter.hxx new file mode 100644 index 000000000..5386a02b8 --- /dev/null +++ b/src/MEDLoader/MEDFileParameter.hxx @@ -0,0 +1,178 @@ +// Copyright (C) 2007-2012 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#ifndef __MEDFILEPARAMETER_HXX__ +#define __MEDFILEPARAMETER_HXX__ + +#include "MEDLoaderDefines.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +namespace ParaMEDMEM +{ + class MEDLOADER_EXPORT MEDFileParameter1TS : public RefCountObject + { + public: + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception) = 0; + virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + virtual void simpleRepr2(int bkOffset, std::ostream& oss) const = 0; + virtual void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) = 0; + virtual void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) = 0; + public: + void setIteration(int it) { _iteration=it; } + int getIteration() const { return _iteration; } + void setOrder(int order) { _order=order; } + int getOrder() const { return _order; } + void setTimeValue(double time) { _time=time; } + void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; } + double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; } + double getTimeValue() const { return _time; } + protected: + MEDFileParameter1TS(int iteration, int order, double time); + MEDFileParameter1TS(); + protected: + int _iteration; + int _order; + double _time; + }; + + class MEDLOADER_EXPORT MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS + { + public: + static MEDFileParameterDouble1TSWTI *New(int iteration, int order, double time); + MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + void setValue(double val) throw(INTERP_KERNEL::Exception) { _arr=val; } + double getValue() const throw(INTERP_KERNEL::Exception) { return _arr; } + bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + std::size_t getHeapMemorySize() const; + void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception); + protected: + MEDFileParameterDouble1TSWTI(); + MEDFileParameterDouble1TSWTI(int iteration, int order, double time); + void simpleRepr2(int bkOffset, std::ostream& oss) const; + void finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception); + protected: + double _arr; + }; + + class MEDLOADER_EXPORT MEDFileParameterTinyInfo : public MEDFileWritable + { + public: + void setDescription(const char *name) { _desc_name=name; } + const char *getDescription() const { return _desc_name.c_str(); } + void setTimeUnit(const char *unit) { _dt_unit=unit; } + const char *getTimeUnit() const { return _dt_unit.c_str(); } + std::size_t getHeapMemSizeOfStrings() const; + bool isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const; + protected: + void writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception); + void mainRepr(int bkOffset, std::ostream& oss) const; + protected: + std::string _dt_unit; + std::string _name; + std::string _desc_name; + }; + + class MEDLOADER_EXPORT MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterDouble1TS *New(); + static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + virtual std::string simpleRepr() const; + std::size_t getHeapMemorySize() const; + void setName(const char *name) throw(INTERP_KERNEL::Exception) { _name=name; } + const char *getName() const throw(INTERP_KERNEL::Exception) { return _name.c_str(); } + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + private: + MEDFileParameterDouble1TS(); + MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + }; + + class MEDLOADER_EXPORT MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterMultiTS *New(); + static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + const char *getName() const { return _name.c_str(); } + void setName(const char *name) { _name=name; } + std::size_t getHeapMemorySize() const; + MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception); + double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + void eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception); + std::vector< std::pair > getIterations() const throw(INTERP_KERNEL::Exception); + std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); + void simpleRepr2(int bkOffset, std::ostream& oss) const; + protected: + MEDFileParameterMultiTS(); + MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy); + MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception); + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _param_per_ts; + }; + + class MEDLOADER_EXPORT MEDFileParameters : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileParameters *New(); + static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySize() const; + MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + std::vector getParamsNames() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void simpleReprWithoutHeader(std::ostream& oss) const; + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception); + void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception); + int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); + protected: + void simpleRepr2(int bkOffset, std::ostream& oss) const; + MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameters(const MEDFileParameters& other, bool deepCopy); + MEDFileParameters(); + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _params; + }; +} + +#endif diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index ccb326f69..cd3ae6450 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -37,15 +37,16 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ -MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx MEDFileData.hxx \ +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ +MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx MEDFileData.hxx MEDFileParameter.hxx \ SauvMedConvertor.hxx SauvReader.hxx SauvWriter.hxx SauvUtilities.hxx dist_libmedloader_la_SOURCES= \ MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ -MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx \ -SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx +MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx \ +SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx \ +MEDFileParameter.cxx libmedloader_la_CPPFLAGS= $(MED3_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 84ff804d8..4452d34da 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -29,6 +29,7 @@ #include "MEDLoader.hxx" #include "MEDFileMesh.hxx" #include "MEDFileField.hxx" +#include "MEDFileParameter.hxx" #include "MEDFileData.hxx" #include "MEDLoaderTypemaps.i" #include "SauvReader.hxx" @@ -46,6 +47,11 @@ using namespace ParaMEDMEM; $result=convertMEDFileMesh($1,$owner); } +%typemap(out) ParaMEDMEM::MEDFileParameter1TS* +{ + $result=convertMEDFileParameter1TS($1,$owner); +} + %newobject MEDLoader::ReadUMeshFromFamilies; %newobject MEDLoader::ReadUMeshFromGroups; %newobject MEDLoader::ReadUMeshFromFile; @@ -121,6 +127,16 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileData::deepCpy; %newobject ParaMEDMEM::MEDFileData::getMeshes; %newobject ParaMEDMEM::MEDFileData::getFields; +%newobject ParaMEDMEM::MEDFileData::getParams; + +%newobject ParaMEDMEM::MEDFileParameterDouble1TS::New; +%newobject ParaMEDMEM::MEDFileParameterDouble1TS::deepCpy; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::New; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::deepCpy; +%newobject ParaMEDMEM::MEDFileParameters::New; +%newobject ParaMEDMEM::MEDFileParameters::deepCpy; +%newobject ParaMEDMEM::MEDFileParameters::getParamAtPos; +%newobject ParaMEDMEM::MEDFileParameters::getParamWithName; %newobject ParaMEDMEM::SauvWriter::New; %newobject ParaMEDMEM::SauvReader::New; @@ -135,6 +151,10 @@ using namespace ParaMEDMEM; %feature("unref") MEDFileField1TS "$this->decrRef();" %feature("unref") MEDFileFieldMultiTS "$this->decrRef();" %feature("unref") MEDFileFields "$this->decrRef();" +%feature("unref") MEDFileParameter1TS "$this->decrRef();" +%feature("unref") MEDFileParameterDouble1TS "$this->decrRef();" +%feature("unref") MEDFileParameterMultiTS "$this->decrRef();" +%feature("unref") MEDFileParameters "$this->decrRef();" %feature("unref") MEDFileData "$this->decrRef();" %feature("unref") SauvReader "$this->decrRef();" %feature("unref") SauvWriter "$this->decrRef();" @@ -1674,6 +1694,241 @@ namespace ParaMEDMEM } }; + class MEDFileParameter1TS : public RefCountObject + { + public: + void setIteration(int it); + int getIteration() const; + void setOrder(int order); + int getOrder() const; + void setTimeValue(double time); + void setTime(int dt, int it, double time); + double getTime(int& dt, int& it); + double getTimeValue() const; + }; + + class MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS + { + public: + void setValue(double val) throw(INTERP_KERNEL::Exception); + double getValue() const throw(INTERP_KERNEL::Exception); + }; + + class MEDFileParameterTinyInfo : public MEDFileWritable + { + public: + void setDescription(const char *name); + const char *getDescription() const; + void setTimeUnit(const char *unit); + const char *getTimeUnit() const; + }; + + class MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterDouble1TS *New(); + static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual std::string simpleRepr() const; + void setName(const char *name) throw(INTERP_KERNEL::Exception); + const char *getName() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameterDouble1TS() + { + return MEDFileParameterDouble1TS::New(); + } + + MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName); + } + + MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName,paramName); + } + + MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName,paramName,dt,it); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileParameter1TS *other, double eps) const + { + std::string what; + bool ret0=self->isEqual(other,eps,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + } + }; + + class MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterMultiTS *New(); + static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + const char *getName() const; + void setName(const char *name); + MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception); + double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameterMultiTS() + { + return MEDFileParameterMultiTS::New(); + } + + MEDFileParameterMultiTS(const char *fileName) + { + return MEDFileParameterMultiTS::New(fileName); + } + + MEDFileParameterMultiTS(const char *fileName, const char *paramName) + { + return MEDFileParameterMultiTS::New(fileName,paramName); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + void eraseTimeStepIds(PyObject *ids) throw(INTERP_KERNEL::Exception) + { + int sw; + int pos1; + std::vector pos2; + DataArrayInt *pos3=0; + DataArrayIntTuple *pos4=0; + convertObjToPossibleCpp1(ids,sw,pos1,pos2,pos3,pos4); + switch(sw) + { + case 1: + { + self->eraseTimeStepIds(&pos1,&pos1+1); + return; + } + case 2: + { + if(pos2.empty()) + return; + self->eraseTimeStepIds(&pos2[0],&pos2[0]+pos2.size()); + return ; + } + case 3: + { + self->eraseTimeStepIds(pos3->begin(),pos3->end()); + return ; + } + default: + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::eraseTimeStepIds : unexpected input array type recognized !"); + } + } + + PyObject *getIterations() const throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > res=self->getIterations(); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + + PyObject *getTimeSteps() const throw(INTERP_KERNEL::Exception) + { + std::vector res2; + std::vector< std::pair > res=self->getTimeSteps(res2); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(3); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second)); + PyTuple_SetItem(elt,2,SWIG_From_double(res2[rk])); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + } + }; + + class MEDFileParameters : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileParameters *New(); + static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + std::vector getParamsNames() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception); + int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameters() + { + return MEDFileParameters::New(); + } + + MEDFileParameters(const char *fileName) + { + return MEDFileParameters::New(fileName); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameterMultiTS *ret=self->getParamAtPos(i); + if(ret) + ret->incrRef(); + return ret; + } + + MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameterMultiTS *ret=self->getParamWithName(paramName); + if(ret) + ret->incrRef(); + return ret; + } + } + }; + class MEDFileData : public RefCountObject, public MEDFileWritable { public: @@ -1682,8 +1937,10 @@ namespace ParaMEDMEM MEDFileData *deepCpy() const throw(INTERP_KERNEL::Exception); void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + void setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); // bool changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception); bool unPolyzeMeshes() throw(INTERP_KERNEL::Exception); @@ -1714,6 +1971,14 @@ namespace ParaMEDMEM return ret; } + MEDFileParameters *getParams() const throw(INTERP_KERNEL::Exception) + { + MEDFileParameters *ret=self->getParams(); + if(ret) + ret->incrRef(); + return ret; + } + MEDFileFields *getFields() const throw(INTERP_KERNEL::Exception) { MEDFileFields *ret=self->getFields(); diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index cbab3a4d0..8ce6f26f3 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -34,6 +34,16 @@ static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) th return ret; } +static PyObject* convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=0; + if(dynamic_cast(p1ts)) + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !"); + return ret; +} + static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception) { std::vector > ret;