1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDFileParameter.hxx"
22 #include "MEDFileUtilities.hxx"
23 #include "MEDLoaderBase.hxx"
25 #include "InterpKernelAutoPtr.hxx"
29 using namespace ParaMEDMEM;
31 MEDFileParameter1TS::MEDFileParameter1TS(int iteration, int order, double time):_iteration(iteration),_order(order),_time(time)
35 MEDFileParameter1TS::MEDFileParameter1TS():_iteration(-1),_order(-1),_time(0.)
39 bool MEDFileParameter1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
41 std::ostringstream oss;
43 { what="Other is null"; return false; }
44 if(_iteration!=other->_iteration)
45 { oss << "iteration number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
46 if(_order!=other->_order)
47 { oss << "order number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
48 if(fabs(_time-other->_time)>eps)
49 { oss << "time mismatches " << _time << " != " << other->_time << " eps=" << eps; what=oss.str(); return false; }
53 MEDFileParameter1TS *MEDFileParameterDouble1TSWTI::deepCpy() const
55 return new MEDFileParameterDouble1TSWTI(*this);
58 bool MEDFileParameterDouble1TSWTI::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
60 if(!MEDFileParameter1TS::isEqual(other,eps,what))
62 const MEDFileParameterDouble1TSWTI *otherC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(other);
64 { what="IsEqual fails because this is double parameter other no !"; return false; }
65 if(fabs(_arr-otherC->_arr)>eps)
66 { std::ostringstream oss; oss << "value differ " << _arr << " != " << otherC->_arr << " (eps=" << eps << ")"; return false; }
70 std::size_t MEDFileParameterDouble1TSWTI::getHeapMemorySizeWithoutChildren() const
72 return sizeof(MEDFileParameterDouble1TSWTI);
75 std::vector<const BigMemoryObject *> MEDFileParameterDouble1TSWTI::getDirectChildren() const
77 return std::vector<const BigMemoryObject *>();
80 std::string MEDFileParameterDouble1TSWTI::simpleRepr() const
82 std::ostringstream oss;
87 void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const
89 std::string startOfLine(bkOffset,' ');
90 oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl;
91 oss << startOfLine << "Time associacited = " << _time << std::endl;
92 oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl;
95 MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time)
97 return new MEDFileParameterDouble1TSWTI(iteration,order,time);
100 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits<double>::max())
104 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time)
108 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps)
110 std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : ";
111 for(int i=0;i<nbOfSteps;i++)
115 MEDparameterComputationStepInfo(fid,name.c_str(),i+1,&locDt,&locIt,&tim);
116 if(dt==locDt && it==locIt)
118 _iteration=locDt; _order=locIt; _time=tim;
119 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
124 oss << "(" << locDt << "," << locIt << ")";
129 throw INTERP_KERNEL::Exception(oss.str().c_str());
132 void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name)
134 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
137 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId)
141 MEDparameterComputationStepInfo(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt);
142 _iteration=locDt; _order=locIt; _time=dt;
143 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
146 void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const
148 char nameW[MED_NAME_SIZE+1];
149 MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy());
150 MEDparameterValueWr(fid,nameW,_iteration,_order,_time,reinterpret_cast<const unsigned char *>(&_arr));
153 std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const
155 return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity();
158 bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const
160 std::ostringstream oss;
161 if(_name!=other._name)
162 { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; }
163 if(_desc_name!=other._desc_name)
164 { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; }
165 if(_dt_unit!=other._dt_unit)
166 { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; }
170 void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const
172 char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1];
173 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy());
174 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy());
175 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy());
176 MEDparameterCr(fid,nameW,typ,descW,dtunitW);
179 void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const
181 std::string startOfLine(bkOffset,' ');
182 oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl;
183 oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl;
184 oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl;
187 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New()
189 return new MEDFileParameterDouble1TS;
192 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName)
194 return new MEDFileParameterDouble1TS(fileName);
197 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName, const std::string& paramName)
199 return new MEDFileParameterDouble1TS(fileName,paramName);
202 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName, const std::string& paramName, int dt, int it)
204 return new MEDFileParameterDouble1TS(fileName,paramName,dt,it);
207 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS()
211 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName, int dt, int it)
213 MEDFileUtilities::CheckFileForRead(fileName);
214 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
215 int nbPar=MEDnParameter(fid);
216 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
217 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
218 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
219 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
220 med_parameter_type paramType;
221 for(int i=0;i<nbPar;i++)
224 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
225 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
226 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
228 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
230 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
231 finishLoading(fid,_name,dt,it,nbOfSteps);
237 if(i!=nbPar-1) oss << ", ";
240 throw INTERP_KERNEL::Exception(oss.str().c_str());
243 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName)
245 MEDFileUtilities::CheckFileForRead(fileName);
246 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
247 int nbPar=MEDnParameter(fid);
248 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
249 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
250 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
251 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
252 med_parameter_type paramType;
253 for(int i=0;i<nbPar;i++)
256 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
257 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
258 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
262 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
264 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
265 finishLoading(fid,_name,0);
270 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
271 throw INTERP_KERNEL::Exception(oss2.str().c_str());
277 if(i!=nbPar-1) oss << ", ";
280 throw INTERP_KERNEL::Exception(oss.str().c_str());
283 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName)
285 MEDFileUtilities::CheckFileForRead(fileName);
286 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
287 int nbPar=MEDnParameter(fid);
290 std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !";
291 throw INTERP_KERNEL::Exception(oss2.str().c_str());
293 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
294 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
295 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
296 med_parameter_type paramType;
298 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
299 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
300 if(paramType==MED_FLOAT64)
304 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
306 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
307 finishLoading(fid,_name,0);
312 std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !";
313 throw INTERP_KERNEL::Exception(oss2.str().c_str());
318 std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !";
319 throw INTERP_KERNEL::Exception(oss2.str().c_str());
323 bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
325 if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what))
327 const MEDFileParameterDouble1TS *otherC=dynamic_cast<const MEDFileParameterDouble1TS *>(other);
329 { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; }
330 if(!isEqualStrings(*otherC,what))
335 MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const
337 return new MEDFileParameterDouble1TS(*this);
340 std::string MEDFileParameterDouble1TS::simpleRepr() const
342 std::ostringstream oss;
343 MEDFileParameterTinyInfo::mainRepr(0,oss);
344 MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss);
348 std::size_t MEDFileParameterDouble1TS::getHeapMemorySizeWithoutChildren() const
350 return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS);
353 std::vector<const BigMemoryObject *> MEDFileParameterDouble1TS::getDirectChildren() const
355 return std::vector<const BigMemoryObject *>();
358 void MEDFileParameterDouble1TS::write(const std::string& fileName, int mode) const
360 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
361 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
362 MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64);
363 MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this);
366 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New()
368 return new MEDFileParameterMultiTS;
371 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const std::string& fileName)
373 return new MEDFileParameterMultiTS(fileName);
376 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const std::string& fileName, const std::string& paramName)
378 return new MEDFileParameterMultiTS(fileName,paramName);
381 MEDFileParameterMultiTS::MEDFileParameterMultiTS()
385 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts)
388 for(std::size_t i=0;i<_param_per_ts.size();i++)
390 const MEDFileParameter1TS *elt=_param_per_ts[i];
392 _param_per_ts[i]=elt->deepCpy();
396 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const std::string& fileName)
398 MEDFileUtilities::CheckFileForRead(fileName);
399 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
400 int nbPar=MEDnParameter(fid);
403 std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ;
404 throw INTERP_KERNEL::Exception(oss.str().c_str());
406 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
407 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
408 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
409 med_parameter_type paramType;
411 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
412 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
413 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
415 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
416 finishLoading(fid,paramType,nbOfSteps);
419 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const std::string& fileName, const std::string& paramName)
421 MEDFileUtilities::CheckFileForRead(fileName);
422 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
423 int nbPar=MEDnParameter(fid);
424 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
425 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
426 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
427 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
428 med_parameter_type paramType;
429 for(int i=0;i<nbPar;i++)
432 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
433 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
434 if(paramNameCpp==paramName)
438 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
440 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
441 finishLoading(fid,paramType,nbOfSteps);
446 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
447 throw INTERP_KERNEL::Exception(oss2.str().c_str());
453 if(i!=nbPar-1) oss << ", ";
456 throw INTERP_KERNEL::Exception(oss.str().c_str());
459 void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps)
461 _param_per_ts.resize(nbOfSteps);
462 for(int i=0;i<nbOfSteps;i++)
466 MEDparameterComputationStepInfo(fid,_name.c_str(),i+1,&dt,&it,&tim);
470 _param_per_ts[i]=MEDFileParameterDouble1TSWTI::New(dt,it,tim);
471 _param_per_ts[i]->readValue(fid,_name.c_str());
477 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !");
482 std::size_t MEDFileParameterMultiTS::getHeapMemorySizeWithoutChildren() const
484 std::size_t ret(sizeof(MEDFileParameterMultiTS));
485 ret+=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS>)*_param_per_ts.capacity();
489 std::vector<const BigMemoryObject *> MEDFileParameterMultiTS::getDirectChildren() const
491 std::vector<const BigMemoryObject *> ret;
492 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
494 const MEDFileParameter1TS *elt(*it);
501 MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const
503 return new MEDFileParameterMultiTS(*this,true);
506 bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const
509 { what="other is null !"; return false; }
510 if(_param_per_ts.size()!=other->_param_per_ts.size())
511 { what="number of time steps differs !"; return false; }
512 std::ostringstream oss;
513 for(std::size_t i=0;i<_param_per_ts.size();i++)
515 const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]);
516 if((a && !b) || (!a && b))
517 { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
519 if(!a->isEqual(b,eps,what))
520 { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; }
525 void MEDFileParameterMultiTS::write(const std::string& fileName, int mode) const
527 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
528 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
532 void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const
534 std::set<med_parameter_type> diffType;
535 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
537 const MEDFileParameter1TS *elt(*it);
538 if(dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt))
539 diffType.insert(MED_FLOAT64);
541 if(diffType.size()>1)
542 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ...");
545 med_parameter_type typ=*diffType.begin();
546 MEDFileParameterTinyInfo::writeLLHeader(fid,typ);
547 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
549 const MEDFileParameter1TS *elt(*it);
551 elt->writeLL(fid,_name,mw);
555 std::string MEDFileParameterMultiTS::simpleRepr() const
557 std::ostringstream oss;
562 void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const
564 MEDFileParameterTinyInfo::mainRepr(bkOffset,oss);
565 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
567 const MEDFileParameter1TS *elt(*it);
569 elt->simpleRepr2(bkOffset+2,oss);
573 void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val)
575 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterDouble1TSWTI> elt=MEDFileParameterDouble1TSWTI::New(dt,it,time);
577 MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef();
578 _param_per_ts.push_back(elt2);
581 double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const
583 int pos=getPosOfTimeStep(iteration,order);
584 const MEDFileParameter1TS *elt=_param_per_ts[pos];
587 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
588 oss << " exists but elt is empty !";
589 throw INTERP_KERNEL::Exception(oss.str().c_str());
591 const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt);
594 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
595 oss << " exists but not double !";
597 return eltC->getValue();
600 int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const
603 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :";
604 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
606 const MEDFileParameter1TS *elt(*it);
609 if(elt->getIteration()==iteration && elt->getOrder()==order)
612 oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), ";
615 throw INTERP_KERNEL::Exception(oss.str().c_str());
618 int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const
621 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! Possibilities are :";
622 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
624 const MEDFileParameter1TS *elt(*it);
627 if(fabs(elt->getTimeValue()-time)<=eps)
630 oss << elt->getTimeValue() << ", ";
633 throw INTERP_KERNEL::Exception(oss.str().c_str());
637 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
639 MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const
641 if(posId<0 || posId>=(int)_param_per_ts.size())
643 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !";
644 throw INTERP_KERNEL::Exception(oss.str().c_str());
646 return const_cast<MEDFileParameter1TS *>(static_cast<const MEDFileParameter1TS *>(_param_per_ts[posId]));
649 void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
651 std::vector<bool> b(_param_per_ts.size(),true);
652 int len=(int)_param_per_ts.size();
653 for(const int *w=startIds;w!=endIds;w++)
658 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());
660 std::size_t newNb=std::count(b.begin(),b.end(),true);
661 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > paramPerTs(newNb);
663 for(std::size_t i=0;i<_param_per_ts.size();i++)
665 paramPerTs[j++]=_param_per_ts[i];
666 _param_per_ts=paramPerTs;
669 int MEDFileParameterMultiTS::getNumberOfTS() const
671 return (int) getIterations().size();
674 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getIterations() const
676 std::vector< std::pair<int,int> > ret;
677 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
679 const MEDFileParameter1TS *elt(*it);
681 ret.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
689 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getTimeSteps(std::vector<double>& ret1) const
691 std::vector< std::pair<int,int> > ret0;
693 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
695 const MEDFileParameter1TS *elt(*it);
698 ret0.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
699 ret1.push_back(elt->getTimeValue());
705 MEDFileParameters *MEDFileParameters::New()
707 return new MEDFileParameters;
710 MEDFileParameters *MEDFileParameters::New(const std::string& fileName)
712 return new MEDFileParameters(fileName);
715 MEDFileParameters::MEDFileParameters(const std::string& fileName)
717 MEDFileUtilities::CheckFileForRead(fileName);
718 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
719 int nbPar=MEDnParameter(fid);
720 _params.resize(nbPar);
721 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
722 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
723 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
724 med_parameter_type paramType;
725 for(int i=0;i<nbPar;i++)
728 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
729 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
730 _params[i]=MEDFileParameterMultiTS::New(fileName,paramNameCpp);
734 MEDFileParameters::MEDFileParameters()
738 std::size_t MEDFileParameters::getHeapMemorySizeWithoutChildren() const
740 std::size_t ret(sizeof(MEDFileParameters));
741 ret+=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>)*_params.capacity();
745 std::vector<const BigMemoryObject *> MEDFileParameters::getDirectChildren() const
747 std::vector<const BigMemoryObject *> ret;
748 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
750 const MEDFileParameterMultiTS *elt(*it);
757 MEDFileParameters *MEDFileParameters::deepCpy() const
759 return new MEDFileParameters(*this,true);
762 bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const
765 { what="other is null !"; return false; }
766 if(_params.size()!=other->_params.size())
767 { what="number of parameters differs !"; return false; }
768 std::ostringstream oss;
769 for(std::size_t i=0;i<_params.size();i++)
771 const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]);
772 if((a && !b) || (!a && b))
773 { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
775 if(!a->isEqual(b,eps,what))
776 { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; }
781 MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params)
784 for(std::size_t i=0;i<_params.size();i++)
786 const MEDFileParameterMultiTS *elt=_params[i];
788 _params[i]=elt->deepCpy();
792 void MEDFileParameters::write(const std::string& fileName, int mode) const
794 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
795 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
799 void MEDFileParameters::writeLL(med_idt fid) const
801 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
803 const MEDFileParameterMultiTS *elt(*it);
805 elt->writeLL(fid,*this);
809 std::vector<std::string> MEDFileParameters::getParamsNames() const
811 std::vector<std::string> ret(_params.size());
813 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,i++)
815 const MEDFileParameterMultiTS *p=(*it);
822 std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !";
823 throw INTERP_KERNEL::Exception(oss.str().c_str());
829 std::string MEDFileParameters::simpleRepr() const
831 std::ostringstream oss;
832 simpleReprWithoutHeader(oss);
836 void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const
838 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
840 const MEDFileParameterMultiTS *elt(*it);
842 elt->simpleRepr2(2,oss);
846 void MEDFileParameters::resize(int newSize)
849 throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !");
850 _params.resize(newSize);
853 void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param)
857 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
858 _params.push_back(elt);
861 void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param)
864 throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !");
865 if(i>=(int)_params.size())
869 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
874 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
876 MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const
878 if(i<0 || i>=(int)_params.size())
880 std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !";
881 throw INTERP_KERNEL::Exception(oss.str().c_str());
883 const MEDFileParameterMultiTS *elt=_params[i];
884 return const_cast<MEDFileParameterMultiTS *>(elt);
888 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
890 MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const std::string& paramName) const
892 int pos=getPosFromParamName(paramName);
893 return getParamAtPos(pos);
896 void MEDFileParameters::destroyParamAtPos(int i)
898 if(i<0 || i>=(int)_params.size())
900 std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !";
901 throw INTERP_KERNEL::Exception(oss.str().c_str());
903 _params[i]=MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>(0);
906 int MEDFileParameters::getPosFromParamName(const std::string& paramName) const
908 std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :";
910 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,ret++)
912 const MEDFileParameterMultiTS *elt(*it);
915 if(std::string(elt->getName())==paramName)
918 oss << elt->getName() << ", ";
921 throw INTERP_KERNEL::Exception(oss.str().c_str());
924 int MEDFileParameters::getNumberOfParams() const
926 return (int)_params.size();