void MEDFileData::setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception)
{
- if(!params)
+ if(params)
params->incrRef();
_params=params;
-
}
int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
tmp2->simpleReprWithoutHeader(oss);
}
else
- oss << "No meshes set !!!\n";
+ oss << "No meshes set !!!\n\n";
oss << "Params part :\n*************\n\n";
const MEDFileParameters *tmp3=_params;
if(tmp3)
{
_fields=MEDFileFields::New(fileName);
_meshes=MEDFileMeshes::New(fileName);
+ _params=MEDFileParameters::New(fileName);
}
catch(INTERP_KERNEL::Exception& e)
{
return sizeof(MEDFileParameterDouble1TSWTI);
}
+std::string MEDFileParameterDouble1TSWTI::simpleRepr() const
+{
+ std::ostringstream oss;
+ simpleRepr2(0,oss);
+ return oss.str();
+}
+
void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const
{
std::string startOfLine(bkOffset,' ');
return new MEDFileParameterMultiTS(*this,true);
}
+bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const
+{
+ if(!other)
+ { what="other is null !"; return false; }
+ if(_param_per_ts.size()!=other->_param_per_ts.size())
+ { what="number of time steps differs !"; return false; }
+ std::ostringstream oss;
+ for(std::size_t i=0;i<_param_per_ts.size();i++)
+ {
+ const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]);
+ if((a && !b) || (!a && b))
+ { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
+ if(a)
+ if(!a->isEqual(b,eps,what))
+ { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; }
+ }
+ return true;
+}
+
void MEDFileParameterMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
{
med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
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))
+ if(dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt))
diffType.insert(MED_FLOAT64);
}
if(diffType.size()>1)
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
+/*!
+ * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
+ */
+MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception)
+{
+ if(posId<0 || posId>=(int)_param_per_ts.size())
+ {
+ std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return const_cast<MEDFileParameter1TS *>(static_cast<const MEDFileParameter1TS *>(_param_per_ts[posId]));
+}
+
void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
{
std::vector<bool> b(_param_per_ts.size(),true);
return new MEDFileParameters(*this,true);
}
+bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const
+{
+ if(!other)
+ { what="other is null !"; return false; }
+ if(_params.size()!=other->_params.size())
+ { what="number of parameters differs !"; return false; }
+ std::ostringstream oss;
+ for(std::size_t i=0;i<_params.size();i++)
+ {
+ const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]);
+ if((a && !b) || (!a && b))
+ { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
+ if(a)
+ if(!a->isEqual(b,eps,what))
+ { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; }
+ }
+ return true;
+}
+
MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params)
{
if(deepCopy)
const MEDFileParameterMultiTS *elt(*it);
if(elt)
{
- if(elt->getName()==paramName)
+ if(std::string(elt->getName())==paramName)
return ret;
else
oss << elt->getName() << ", ";
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);
+ std::string simpleRepr() const;
protected:
MEDFileParameterDouble1TSWTI();
MEDFileParameterDouble1TSWTI(int iteration, int order, double time);
void setName(const char *name) { _name=name; }
std::size_t getHeapMemorySize() const;
MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception);
+ bool isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const;
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;
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);
+ MEDFileParameter1TS *getTimeStepAtPos(int posId) 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);
static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception);
std::size_t getHeapMemorySize() const;
MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception);
+ bool isEqual(const MEDFileParameters *other, double eps, std::string& what) const;
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);
%newobject ParaMEDMEM::MEDFileParameterDouble1TS::deepCpy;
%newobject ParaMEDMEM::MEDFileParameterMultiTS::New;
%newobject ParaMEDMEM::MEDFileParameterMultiTS::deepCpy;
+%newobject ParaMEDMEM::MEDFileParameterMultiTS::getTimeStepAtPos;
+%newobject ParaMEDMEM::MEDFileParameterMultiTS::__getitem__;
%newobject ParaMEDMEM::MEDFileParameters::New;
%newobject ParaMEDMEM::MEDFileParameters::deepCpy;
%newobject ParaMEDMEM::MEDFileParameters::getParamAtPos;
%newobject ParaMEDMEM::MEDFileParameters::getParamWithName;
+%newobject ParaMEDMEM::MEDFileParameters::__getitem__;
%newobject ParaMEDMEM::SauvWriter::New;
%newobject ParaMEDMEM::SauvReader::New;
%feature("unref") MEDFileFieldMultiTS "$this->decrRef();"
%feature("unref") MEDFileFields "$this->decrRef();"
%feature("unref") MEDFileParameter1TS "$this->decrRef();"
+%feature("unref") MEDFileParameterDouble1TSWTI "$this->decrRef();"
%feature("unref") MEDFileParameterDouble1TS "$this->decrRef();"
%feature("unref") MEDFileParameterMultiTS "$this->decrRef();"
%feature("unref") MEDFileParameters "$this->decrRef();"
public:
void setValue(double val) throw(INTERP_KERNEL::Exception);
double getValue() const throw(INTERP_KERNEL::Exception);
+ std::string simpleRepr() const;
+ %extend
+ {
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->simpleRepr();
+ }
+ }
};
class MEDFileParameterTinyInfo : public MEDFileWritable
return self->simpleRepr();
}
+ PyObject *isEqual(const MEDFileParameterMultiTS *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;
+ }
+
void eraseTimeStepIds(PyObject *ids) throw(INTERP_KERNEL::Exception)
{
int sw;
}
}
+ int getTimeStepId(PyObject *elt0) const throw(INTERP_KERNEL::Exception)
+ {
+ if(elt0 && PyInt_Check(elt0))
+ {//fmts[3]
+ int pos=PyInt_AS_LONG(elt0);
+ return pos;
+ }
+ else if(elt0 && PyTuple_Check(elt0))
+ {
+ if(PyTuple_Size(elt0)==2)
+ {
+ PyObject *o0=PyTuple_GetItem(elt0,0);
+ PyObject *o1=PyTuple_GetItem(elt0,1);
+ if(PyInt_Check(o0) && PyInt_Check(o1))
+ {//fmts(1,-1)
+ int iter=PyInt_AS_LONG(o0);
+ int order=PyInt_AS_LONG(o1);
+ return self->getPosOfTimeStep(iter,order);
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input param ! input is a tuple of size 2 but two integers are expected in this tuple to request a time steps !");
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input param ! input is a tuple of size != 2 ! two integers are expected in this tuple to request a time steps !");
+ }
+ else if(elt0 && PyFloat_Check(elt0))
+ {
+ double val=PyFloat_AS_DOUBLE(elt0);
+ return self->getPosGivenTime(val);
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input params ! expected fmts[int], fmts[int,int] or fmts[double] to request time step !");
+ }
+
+ MEDFileParameter1TS *__getitem__(PyObject *elt0) const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileParameter1TS *ret=self->getTimeStepAtPos(ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepId(self,elt0));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
+ std::vector<int> getTimeStepIds(PyObject *elts) const throw(INTERP_KERNEL::Exception)
+ {
+ if(PyList_Check(elts))
+ {
+ int sz=PyList_Size(elts);
+ std::vector<int> ret(sz);
+ for(int i=0;i<sz;i++)
+ {
+ PyObject *elt=PyList_GetItem(elts,i);
+ ret[i]=ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepId(self,elt);
+ }
+ return ret;
+ }
+ else
+ {
+ std::vector<int> ret(1);
+ ret[0]=ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepId(self,elts);
+ return ret;
+ }
+ }
+
+ void __delitem__(PyObject *elts) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> idsToRemove=ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepIds(self,elts);
+ if(!idsToRemove.empty())
+ self->eraseTimeStepIds(&idsToRemove[0],&idsToRemove[0]+idsToRemove.size());
+ }
+
+ MEDFileParameter1TS *getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileParameter1TS *ret=self->getTimeStepAtPos(posId);
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+
PyObject *getIterations() const throw(INTERP_KERNEL::Exception)
{
std::vector< std::pair<int,int> > res=self->getIterations();
return self->simpleRepr();
}
+ MEDFileParameterMultiTS *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ if(PyInt_Check(obj))
+ {
+ MEDFileParameterMultiTS *ret=self->getParamAtPos((int)PyInt_AS_LONG(obj));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ else if(PyString_Check(obj))
+ {
+ MEDFileParameterMultiTS *ret=self->getParamWithName(PyString_AsString(obj));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileParameters::__getitem__ : only integer or string with meshname supported !");
+ }
+
MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception)
{
MEDFileParameterMultiTS *ret=self->getParamAtPos(i);
ret->incrRef();
return ret;
}
+
+ PyObject *isEqual(const MEDFileParameters *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;
+ }
}
};
PyObject *ret=0;
if(dynamic_cast<MEDFileParameterDouble1TS *>(p1ts))
ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner);
+ if(dynamic_cast<MEDFileParameterDouble1TSWTI *>(p1ts))
+ ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TSWTI,owner);
if(!ret)
throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !");
return ret;