1 // Copyright (C) 2007-2012 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.
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"
27 using namespace ParaMEDMEM;
29 MEDFileParameter1TS::MEDFileParameter1TS(int iteration, int order, double time):_iteration(iteration),_order(order),_time(time)
33 MEDFileParameter1TS::MEDFileParameter1TS():_iteration(-1),_order(-1),_time(0.)
37 bool MEDFileParameter1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
39 std::ostringstream oss;
41 { what="Other is null"; return false; }
42 if(_iteration!=other->_iteration)
43 { oss << "iteration number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
44 if(_order!=other->_order)
45 { oss << "order number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
46 if(fabs(_time-other->_time)>eps)
47 { oss << "time mismatches " << _time << " != " << other->_time << " eps=" << eps; what=oss.str(); return false; }
51 MEDFileParameter1TS *MEDFileParameterDouble1TSWTI::deepCpy() const throw(INTERP_KERNEL::Exception)
53 return new MEDFileParameterDouble1TSWTI(*this);
56 bool MEDFileParameterDouble1TSWTI::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
58 if(!MEDFileParameter1TS::isEqual(other,eps,what))
60 const MEDFileParameterDouble1TSWTI *otherC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(other);
62 { what="IsEqual fails because this is double parameter other no !"; return false; }
63 if(fabs(_arr-otherC->_arr)>eps)
64 { std::ostringstream oss; oss << "value differ " << _arr << " != " << otherC->_arr << " (eps=" << eps << ")"; return false; }
68 std::size_t MEDFileParameterDouble1TSWTI::getHeapMemorySize() const
70 return sizeof(MEDFileParameterDouble1TSWTI);
73 std::string MEDFileParameterDouble1TSWTI::simpleRepr() const
75 std::ostringstream oss;
80 void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const
82 std::string startOfLine(bkOffset,' ');
83 oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl;
84 oss << startOfLine << "Time associacited = " << _time << std::endl;
85 oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl;
88 MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time)
90 return new MEDFileParameterDouble1TSWTI(iteration,order,time);
93 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits<double>::max())
97 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time)
101 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception)
103 std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : ";
104 for(int i=0;i<nbOfSteps;i++)
108 MEDparameterComputationStepInfo(fid,name.c_str(),i+1,&locDt,&locIt,&tim);
109 if(dt==locDt && it==locIt)
111 _iteration=locDt; _order=locIt; _time=tim;
112 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
117 oss << "(" << locDt << "," << locIt << ")";
122 throw INTERP_KERNEL::Exception(oss.str().c_str());
125 void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception)
127 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
130 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception)
134 MEDparameterComputationStepInfo(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt);
135 _iteration=locDt; _order=locIt; _time=dt;
136 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
139 void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception)
141 char nameW[MED_NAME_SIZE+1];
142 MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy());
143 MEDparameterValueWr(fid,nameW,_iteration,_order,_time,reinterpret_cast<const unsigned char *>(&_arr));
146 std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const
148 return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity();
151 bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const
153 std::ostringstream oss;
154 if(_name!=other._name)
155 { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; }
156 if(_desc_name!=other._desc_name)
157 { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; }
158 if(_dt_unit!=other._dt_unit)
159 { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; }
163 void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception)
165 char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1];
166 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy());
167 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy());
168 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy());
169 MEDparameterCr(fid,nameW,typ,descW,dtunitW);
172 void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const
174 std::string startOfLine(bkOffset,' ');
175 oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl;
176 oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl;
177 oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl;
180 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New()
182 return new MEDFileParameterDouble1TS;
185 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
187 return new MEDFileParameterDouble1TS(fileName);
190 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
192 return new MEDFileParameterDouble1TS(fileName,paramName);
195 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception)
197 return new MEDFileParameterDouble1TS(fileName,paramName,dt,it);
200 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS()
204 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception)
206 MEDFileUtilities::CheckFileForRead(fileName);
207 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
208 int nbPar=MEDnParameter(fid);
209 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
210 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
211 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
212 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
213 med_parameter_type paramType;
214 for(int i=0;i<nbPar;i++)
217 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
218 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
219 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
221 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
223 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
224 finishLoading(fid,_name,dt,it,nbOfSteps);
230 if(i!=nbPar-1) oss << ", ";
233 throw INTERP_KERNEL::Exception(oss.str().c_str());
236 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
238 MEDFileUtilities::CheckFileForRead(fileName);
239 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
240 int nbPar=MEDnParameter(fid);
241 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
242 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
243 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
244 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
245 med_parameter_type paramType;
246 for(int i=0;i<nbPar;i++)
249 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
250 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
251 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
255 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
257 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
258 finishLoading(fid,_name,0);
263 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
264 throw INTERP_KERNEL::Exception(oss2.str().c_str());
270 if(i!=nbPar-1) oss << ", ";
273 throw INTERP_KERNEL::Exception(oss.str().c_str());
276 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
278 MEDFileUtilities::CheckFileForRead(fileName);
279 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
280 int nbPar=MEDnParameter(fid);
283 std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !";
284 throw INTERP_KERNEL::Exception(oss2.str().c_str());
286 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
287 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
288 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
289 med_parameter_type paramType;
291 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
292 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
293 if(paramType==MED_FLOAT64)
297 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
299 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
300 finishLoading(fid,_name,0);
305 std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !";
306 throw INTERP_KERNEL::Exception(oss2.str().c_str());
311 std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !";
312 throw INTERP_KERNEL::Exception(oss2.str().c_str());
316 bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
318 if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what))
320 const MEDFileParameterDouble1TS *otherC=dynamic_cast<const MEDFileParameterDouble1TS *>(other);
322 { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; }
323 if(!isEqualStrings(*otherC,what))
328 MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
330 return new MEDFileParameterDouble1TS(*this);
333 std::string MEDFileParameterDouble1TS::simpleRepr() const
335 std::ostringstream oss;
336 MEDFileParameterTinyInfo::mainRepr(0,oss);
337 MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss);
341 std::size_t MEDFileParameterDouble1TS::getHeapMemorySize() const
343 return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS);
346 void MEDFileParameterDouble1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
348 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
349 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
350 MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64);
351 MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this);
354 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New()
356 return new MEDFileParameterMultiTS;
359 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
361 return new MEDFileParameterMultiTS(fileName);
364 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
366 return new MEDFileParameterMultiTS(fileName,paramName);
369 MEDFileParameterMultiTS::MEDFileParameterMultiTS()
373 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts)
376 for(std::size_t i=0;i<_param_per_ts.size();i++)
378 const MEDFileParameter1TS *elt=_param_per_ts[i];
380 _param_per_ts[i]=elt->deepCpy();
384 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
386 MEDFileUtilities::CheckFileForRead(fileName);
387 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
388 int nbPar=MEDnParameter(fid);
391 std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ;
392 throw INTERP_KERNEL::Exception(oss.str().c_str());
394 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
395 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
396 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
397 med_parameter_type paramType;
399 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
400 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
401 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
403 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
404 finishLoading(fid,paramType,nbOfSteps);
407 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
409 MEDFileUtilities::CheckFileForRead(fileName);
410 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
411 int nbPar=MEDnParameter(fid);
412 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
413 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
414 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
415 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
416 med_parameter_type paramType;
417 for(int i=0;i<nbPar;i++)
420 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
421 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
422 if(paramNameCpp==paramName)
426 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
428 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
429 finishLoading(fid,paramType,nbOfSteps);
434 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
435 throw INTERP_KERNEL::Exception(oss2.str().c_str());
441 if(i!=nbPar-1) oss << ", ";
444 throw INTERP_KERNEL::Exception(oss.str().c_str());
447 void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception)
449 _param_per_ts.resize(nbOfSteps);
450 for(int i=0;i<nbOfSteps;i++)
454 MEDparameterComputationStepInfo(fid,_name.c_str(),i+1,&dt,&it,&tim);
458 _param_per_ts[i]=MEDFileParameterDouble1TSWTI::New(dt,it,tim);
459 _param_per_ts[i]->readValue(fid,_name.c_str());
465 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !");
470 std::size_t MEDFileParameterMultiTS::getHeapMemorySize() const
472 std::size_t ret=sizeof(MEDFileParameterMultiTS);
473 std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS>)*_param_per_ts.capacity();
474 for(std::size_t i=0;i<_param_per_ts.size();i++)
476 const MEDFileParameter1TS *pt(_param_per_ts[i]);
478 ret2+=pt->getHeapMemorySize();
483 MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
485 return new MEDFileParameterMultiTS(*this,true);
488 bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const
491 { what="other is null !"; return false; }
492 if(_param_per_ts.size()!=other->_param_per_ts.size())
493 { what="number of time steps differs !"; return false; }
494 std::ostringstream oss;
495 for(std::size_t i=0;i<_param_per_ts.size();i++)
497 const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]);
498 if((a && !b) || (!a && b))
499 { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
501 if(!a->isEqual(b,eps,what))
502 { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; }
507 void MEDFileParameterMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
509 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
510 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
514 void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception)
516 std::set<med_parameter_type> diffType;
517 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
519 const MEDFileParameter1TS *elt(*it);
520 if(dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt))
521 diffType.insert(MED_FLOAT64);
523 if(diffType.size()>1)
524 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ...");
527 med_parameter_type typ=*diffType.begin();
528 MEDFileParameterTinyInfo::writeLLHeader(fid,typ);
529 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
531 const MEDFileParameter1TS *elt(*it);
533 elt->writeLL(fid,_name,mw);
537 std::string MEDFileParameterMultiTS::simpleRepr() const
539 std::ostringstream oss;
544 void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const
546 MEDFileParameterTinyInfo::mainRepr(bkOffset,oss);
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->simpleRepr2(bkOffset+2,oss);
555 void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception)
557 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterDouble1TSWTI> elt=MEDFileParameterDouble1TSWTI::New(dt,it,time);
559 MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef();
560 _param_per_ts.push_back(elt2);
563 double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception)
565 int pos=getPosOfTimeStep(iteration,order);
566 const MEDFileParameter1TS *elt=_param_per_ts[pos];
569 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
570 oss << " exists but elt is empty !";
571 throw INTERP_KERNEL::Exception(oss.str().c_str());
573 const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt);
576 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
577 oss << " exists but not double !";
579 return eltC->getValue();
582 int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
585 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :";
586 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
588 const MEDFileParameter1TS *elt(*it);
591 if(elt->getIteration()==iteration && elt->getOrder())
594 oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), ";
597 throw INTERP_KERNEL::Exception(oss.str().c_str());
600 int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
603 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! 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(fabs(elt->getTimeValue()-time)<=eps)
612 oss << elt->getTimeValue() << ", ";
615 throw INTERP_KERNEL::Exception(oss.str().c_str());
619 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
621 MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception)
623 if(posId<0 || posId>=(int)_param_per_ts.size())
625 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !";
626 throw INTERP_KERNEL::Exception(oss.str().c_str());
628 return const_cast<MEDFileParameter1TS *>(static_cast<const MEDFileParameter1TS *>(_param_per_ts[posId]));
631 void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
633 std::vector<bool> b(_param_per_ts.size(),true);
634 int len=(int)_param_per_ts.size();
635 for(const int *w=startIds;w!=endIds;w++)
640 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());
642 std::size_t newNb=std::count(b.begin(),b.end(),true);
643 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > paramPerTs(newNb);
645 for(std::size_t i=0;i<_param_per_ts.size();i++)
647 paramPerTs[j++]=_param_per_ts[i];
648 _param_per_ts=paramPerTs;
651 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getIterations() const throw(INTERP_KERNEL::Exception)
653 std::vector< std::pair<int,int> > ret;
654 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
656 const MEDFileParameter1TS *elt(*it);
658 ret.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
666 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
668 std::vector< std::pair<int,int> > ret0;
670 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
672 const MEDFileParameter1TS *elt(*it);
675 ret0.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
676 ret1.push_back(elt->getTimeValue());
682 MEDFileParameters *MEDFileParameters::New()
684 return new MEDFileParameters;
687 MEDFileParameters *MEDFileParameters::New(const char *fileName) throw(INTERP_KERNEL::Exception)
689 return new MEDFileParameters(fileName);
692 MEDFileParameters::MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception)
694 MEDFileUtilities::CheckFileForRead(fileName);
695 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
696 int nbPar=MEDnParameter(fid);
697 _params.resize(nbPar);
698 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
699 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
700 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
701 med_parameter_type paramType;
702 for(int i=0;i<nbPar;i++)
705 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
706 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
707 _params[i]=MEDFileParameterMultiTS::New(fileName,paramNameCpp.c_str());
711 MEDFileParameters::MEDFileParameters()
715 std::size_t MEDFileParameters::getHeapMemorySize() const
717 std::size_t ret=sizeof(MEDFileParameters);
718 std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>)*_params.capacity();
719 for(std::size_t i=0;i<_params.size();i++)
721 const MEDFileParameterMultiTS *pt(_params[i]);
723 ret2+=pt->getHeapMemorySize();
728 MEDFileParameters *MEDFileParameters::deepCpy() const throw(INTERP_KERNEL::Exception)
730 return new MEDFileParameters(*this,true);
733 bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const
736 { what="other is null !"; return false; }
737 if(_params.size()!=other->_params.size())
738 { what="number of parameters differs !"; return false; }
739 std::ostringstream oss;
740 for(std::size_t i=0;i<_params.size();i++)
742 const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]);
743 if((a && !b) || (!a && b))
744 { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
746 if(!a->isEqual(b,eps,what))
747 { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; }
752 MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params)
755 for(std::size_t i=0;i<_params.size();i++)
757 const MEDFileParameterMultiTS *elt=_params[i];
759 _params[i]=elt->deepCpy();
763 void MEDFileParameters::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
765 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
766 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
770 void MEDFileParameters::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
772 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
774 const MEDFileParameterMultiTS *elt(*it);
776 elt->writeLL(fid,*this);
780 std::vector<std::string> MEDFileParameters::getParamsNames() const throw(INTERP_KERNEL::Exception)
782 std::vector<std::string> ret(_params.size());
784 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,i++)
786 const MEDFileParameterMultiTS *p=(*it);
793 std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !";
794 throw INTERP_KERNEL::Exception(oss.str().c_str());
800 std::string MEDFileParameters::simpleRepr() const
802 std::ostringstream oss;
803 simpleReprWithoutHeader(oss);
807 void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const
809 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
811 const MEDFileParameterMultiTS *elt(*it);
813 elt->simpleRepr2(2,oss);
817 void MEDFileParameters::resize(int newSize) throw(INTERP_KERNEL::Exception)
820 throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !");
821 _params.resize(newSize);
824 void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception)
828 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
829 _params.push_back(elt);
832 void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception)
835 throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !");
836 if(i>=(int)_params.size())
840 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
845 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
847 MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const throw(INTERP_KERNEL::Exception)
849 if(i<0 || i>=(int)_params.size())
851 std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !";
852 throw INTERP_KERNEL::Exception(oss.str().c_str());
854 const MEDFileParameterMultiTS *elt=_params[i];
855 return const_cast<MEDFileParameterMultiTS *>(elt);
859 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
861 MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception)
863 int pos=getPosFromParamName(paramName);
864 return getParamAtPos(pos);
867 void MEDFileParameters::destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception)
869 if(i<0 || i>=(int)_params.size())
871 std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !";
872 throw INTERP_KERNEL::Exception(oss.str().c_str());
874 _params[i]=MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>(0);
877 int MEDFileParameters::getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception)
879 std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :";
881 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,ret++)
883 const MEDFileParameterMultiTS *elt(*it);
886 if(std::string(elt->getName())==paramName)
889 oss << elt->getName() << ", ";
892 throw INTERP_KERNEL::Exception(oss.str().c_str());
895 int MEDFileParameters::getNumberOfParams() const throw(INTERP_KERNEL::Exception)
897 return (int)_params.size();