--- /dev/null
+// 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<const MEDFileParameterDouble1TSWTI *>(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<double>::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<nbOfSteps;i++)
+ {
+ int locDt,locIt;
+ double tim;
+ MEDparameterComputationStepInfo(fid,name.c_str(),i+1,&locDt,&locIt,&tim);
+ if(dt==locDt && it==locIt)
+ {
+ _iteration=locDt; _order=locIt; _time=tim;
+ MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_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<unsigned char *const>(&_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<unsigned char *const>(&_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<const unsigned char *>(&_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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
+ med_parameter_type paramType;
+ for(int i=0;i<nbPar;i++)
+ {
+ int nbOfSteps;
+ MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
+ std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
+ if(paramNameCpp==paramName && paramType==MED_FLOAT64)
+ {
+ _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
+ _name=paramNameCpp;
+ _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
+ finishLoading(fid,_name,dt,it,nbOfSteps);
+ return ;
+ }
+ else
+ {
+ oss << paramNameCpp;
+ if(i!=nbPar-1) oss << ", ";
+ }
+ }
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
+MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
+ med_parameter_type paramType;
+ for(int i=0;i<nbPar;i++)
+ {
+ int nbOfSteps;
+ MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
+ std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
+ if(paramNameCpp==paramName && 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 << "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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> 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<const MEDFileParameterDouble1TS *>(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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> 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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
+ med_parameter_type paramType;
+ for(int i=0;i<nbPar;i++)
+ {
+ int nbOfSteps;
+ MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
+ std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
+ if(paramNameCpp==paramName)
+ {
+ if(nbOfSteps>0)
+ {
+ _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;i<nbOfSteps;i++)
+ {
+ int dt,it;
+ double tim;
+ MEDparameterComputationStepInfo(fid,_name.c_str(),i+1,&dt,&it,&tim);
+ switch(typ)
+ {
+ case MED_FLOAT64:
+ _param_per_ts[i]=MEDFileParameterDouble1TSWTI::New(dt,it,tim);
+ _param_per_ts[i]->readValue(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<MEDFileParameter1TS>)*_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<med_parameter_type> diffType;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
+ {
+ const MEDFileParameter1TS *elt(*it);
+ if(dynamic_cast<const MEDFileParameterDouble1TS *>(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<MEDFileParameter1TS> >::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<MEDFileParameter1TS> >::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<MEDFileParameterDouble1TSWTI> elt=MEDFileParameterDouble1TSWTI::New(dt,it,time);
+ elt->setValue(val);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> 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<const MEDFileParameterDouble1TSWTI *>(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<MEDFileParameter1TS> >::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<MEDFileParameter1TS> >::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<bool> 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<len)
+ b[*w]=false;
+ else
+ {
+ std::ostringstream oss; oss << "MEDFileParameterMultiTS::eraseTimeStepIds : At pos #" << std::distance(startIds,w) << " value is " << *w << " should be in [0," << len << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ std::size_t newNb=std::count(b.begin(),b.end(),true);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > 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<int,int> > MEDFileParameterMultiTS::getIterations() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector< std::pair<int,int> > ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
+ {
+ const MEDFileParameter1TS *elt(*it);
+ if(elt)
+ ret.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
+ }
+ return ret;
+}
+
+/*!
+ * \param [out] ret1
+ */
+std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector< std::pair<int,int> > ret0;
+ ret1.clear();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
+ {
+ const MEDFileParameter1TS *elt(*it);
+ if(elt)
+ {
+ ret0.push_back(std::pair<int,int>(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<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
+ med_parameter_type paramType;
+ for(int i=0;i<nbPar;i++)
+ {
+ int nbOfSteps;
+ MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
+ std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
+ _params[i]=MEDFileParameterMultiTS::New(fileName,paramNameCpp.c_str());
+ }
+}
+
+MEDFileParameters::MEDFileParameters()
+{
+}
+
+std::size_t MEDFileParameters::getHeapMemorySize() const
+{
+ std::size_t ret=sizeof(MEDFileParameters);
+ std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>)*_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<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
+ {
+ const MEDFileParameterMultiTS *elt(*it);
+ if(elt)
+ elt->writeLL(fid,*this);
+ }
+}
+
+std::vector<std::string> MEDFileParameters::getParamsNames() const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ret(_params.size());
+ int i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::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<MEDFileParameterMultiTS> >::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<MEDFileParameterMultiTS> 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<MEDFileParameterMultiTS> 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<MEDFileParameterMultiTS *>(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<MEDFileParameterMultiTS>(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<MEDFileParameterMultiTS> >::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();
+}
--- /dev/null
+// 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<int,int> > getIterations() const throw(INTERP_KERNEL::Exception);
+ std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& 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<MEDFileParameter1TS> > _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<std::string> 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<MEDFileParameterMultiTS> > _params;
+ };
+}
+
+#endif
#include "MEDLoader.hxx"
#include "MEDFileMesh.hxx"
#include "MEDFileField.hxx"
+#include "MEDFileParameter.hxx"
#include "MEDFileData.hxx"
#include "MEDLoaderTypemaps.i"
#include "SauvReader.hxx"
$result=convertMEDFileMesh($1,$owner);
}
+%typemap(out) ParaMEDMEM::MEDFileParameter1TS*
+{
+ $result=convertMEDFileParameter1TS($1,$owner);
+}
+
%newobject MEDLoader::ReadUMeshFromFamilies;
%newobject MEDLoader::ReadUMeshFromGroups;
%newobject MEDLoader::ReadUMeshFromFile;
%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;
%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();"
}
};
+ 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<int> 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<int,int> > res=self->getIterations();
+ PyObject *ret=PyList_New(res.size());
+ int rk=0;
+ for(std::vector< std::pair<int,int> >::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<double> res2;
+ std::vector< std::pair<int,int> > res=self->getTimeSteps(res2);
+ PyObject *ret=PyList_New(res.size());
+ int rk=0;
+ for(std::vector< std::pair<int,int> >::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<std::string> 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:
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);
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();