1 // Copyright (C) 2007-2013 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"
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 throw(INTERP_KERNEL::Exception)
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::getHeapMemorySize() const
72 return sizeof(MEDFileParameterDouble1TSWTI);
75 std::string MEDFileParameterDouble1TSWTI::simpleRepr() const
77 std::ostringstream oss;
82 void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const
84 std::string startOfLine(bkOffset,' ');
85 oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl;
86 oss << startOfLine << "Time associacited = " << _time << std::endl;
87 oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl;
90 MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time)
92 return new MEDFileParameterDouble1TSWTI(iteration,order,time);
95 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits<double>::max())
99 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time)
103 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception)
105 std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : ";
106 for(int i=0;i<nbOfSteps;i++)
110 MEDparameterComputationStepInfo(fid,name.c_str(),i+1,&locDt,&locIt,&tim);
111 if(dt==locDt && it==locIt)
113 _iteration=locDt; _order=locIt; _time=tim;
114 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
119 oss << "(" << locDt << "," << locIt << ")";
124 throw INTERP_KERNEL::Exception(oss.str().c_str());
127 void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception)
129 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
132 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception)
136 MEDparameterComputationStepInfo(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt);
137 _iteration=locDt; _order=locIt; _time=dt;
138 MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr));
141 void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception)
143 char nameW[MED_NAME_SIZE+1];
144 MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy());
145 MEDparameterValueWr(fid,nameW,_iteration,_order,_time,reinterpret_cast<const unsigned char *>(&_arr));
148 std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const
150 return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity();
153 bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const
155 std::ostringstream oss;
156 if(_name!=other._name)
157 { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; }
158 if(_desc_name!=other._desc_name)
159 { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; }
160 if(_dt_unit!=other._dt_unit)
161 { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; }
165 void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception)
167 char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1];
168 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy());
169 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy());
170 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy());
171 MEDparameterCr(fid,nameW,typ,descW,dtunitW);
174 void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const
176 std::string startOfLine(bkOffset,' ');
177 oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl;
178 oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl;
179 oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl;
182 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New()
184 return new MEDFileParameterDouble1TS;
187 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
189 return new MEDFileParameterDouble1TS(fileName);
192 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
194 return new MEDFileParameterDouble1TS(fileName,paramName);
197 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception)
199 return new MEDFileParameterDouble1TS(fileName,paramName,dt,it);
202 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS()
206 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception)
208 MEDFileUtilities::CheckFileForRead(fileName);
209 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
210 int nbPar=MEDnParameter(fid);
211 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
212 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
213 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
214 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
215 med_parameter_type paramType;
216 for(int i=0;i<nbPar;i++)
219 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
220 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
221 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
223 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
225 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
226 finishLoading(fid,_name,dt,it,nbOfSteps);
232 if(i!=nbPar-1) oss << ", ";
235 throw INTERP_KERNEL::Exception(oss.str().c_str());
238 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
240 MEDFileUtilities::CheckFileForRead(fileName);
241 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
242 int nbPar=MEDnParameter(fid);
243 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
244 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
245 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
246 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
247 med_parameter_type paramType;
248 for(int i=0;i<nbPar;i++)
251 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
252 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
253 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
257 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
259 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
260 finishLoading(fid,_name,0);
265 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
266 throw INTERP_KERNEL::Exception(oss2.str().c_str());
272 if(i!=nbPar-1) oss << ", ";
275 throw INTERP_KERNEL::Exception(oss.str().c_str());
278 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
280 MEDFileUtilities::CheckFileForRead(fileName);
281 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
282 int nbPar=MEDnParameter(fid);
285 std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !";
286 throw INTERP_KERNEL::Exception(oss2.str().c_str());
288 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
289 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
290 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
291 med_parameter_type paramType;
293 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
294 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
295 if(paramType==MED_FLOAT64)
299 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
301 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
302 finishLoading(fid,_name,0);
307 std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !";
308 throw INTERP_KERNEL::Exception(oss2.str().c_str());
313 std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !";
314 throw INTERP_KERNEL::Exception(oss2.str().c_str());
318 bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
320 if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what))
322 const MEDFileParameterDouble1TS *otherC=dynamic_cast<const MEDFileParameterDouble1TS *>(other);
324 { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; }
325 if(!isEqualStrings(*otherC,what))
330 MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
332 return new MEDFileParameterDouble1TS(*this);
335 std::string MEDFileParameterDouble1TS::simpleRepr() const
337 std::ostringstream oss;
338 MEDFileParameterTinyInfo::mainRepr(0,oss);
339 MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss);
343 std::size_t MEDFileParameterDouble1TS::getHeapMemorySize() const
345 return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS);
348 void MEDFileParameterDouble1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
350 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
351 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
352 MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64);
353 MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this);
356 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New()
358 return new MEDFileParameterMultiTS;
361 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
363 return new MEDFileParameterMultiTS(fileName);
366 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
368 return new MEDFileParameterMultiTS(fileName,paramName);
371 MEDFileParameterMultiTS::MEDFileParameterMultiTS()
375 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts)
378 for(std::size_t i=0;i<_param_per_ts.size();i++)
380 const MEDFileParameter1TS *elt=_param_per_ts[i];
382 _param_per_ts[i]=elt->deepCpy();
386 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
388 MEDFileUtilities::CheckFileForRead(fileName);
389 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
390 int nbPar=MEDnParameter(fid);
393 std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ;
394 throw INTERP_KERNEL::Exception(oss.str().c_str());
396 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
397 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
398 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
399 med_parameter_type paramType;
401 MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps);
402 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
403 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
405 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
406 finishLoading(fid,paramType,nbOfSteps);
409 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception)
411 MEDFileUtilities::CheckFileForRead(fileName);
412 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
413 int nbPar=MEDnParameter(fid);
414 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
415 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
416 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
417 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
418 med_parameter_type paramType;
419 for(int i=0;i<nbPar;i++)
422 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
423 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
424 if(paramNameCpp==paramName)
428 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
430 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
431 finishLoading(fid,paramType,nbOfSteps);
436 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
437 throw INTERP_KERNEL::Exception(oss2.str().c_str());
443 if(i!=nbPar-1) oss << ", ";
446 throw INTERP_KERNEL::Exception(oss.str().c_str());
449 void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception)
451 _param_per_ts.resize(nbOfSteps);
452 for(int i=0;i<nbOfSteps;i++)
456 MEDparameterComputationStepInfo(fid,_name.c_str(),i+1,&dt,&it,&tim);
460 _param_per_ts[i]=MEDFileParameterDouble1TSWTI::New(dt,it,tim);
461 _param_per_ts[i]->readValue(fid,_name.c_str());
467 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !");
472 std::size_t MEDFileParameterMultiTS::getHeapMemorySize() const
474 std::size_t ret=sizeof(MEDFileParameterMultiTS);
475 std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS>)*_param_per_ts.capacity();
476 for(std::size_t i=0;i<_param_per_ts.size();i++)
478 const MEDFileParameter1TS *pt(_param_per_ts[i]);
480 ret2+=pt->getHeapMemorySize();
485 MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
487 return new MEDFileParameterMultiTS(*this,true);
490 bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const
493 { what="other is null !"; return false; }
494 if(_param_per_ts.size()!=other->_param_per_ts.size())
495 { what="number of time steps differs !"; return false; }
496 std::ostringstream oss;
497 for(std::size_t i=0;i<_param_per_ts.size();i++)
499 const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]);
500 if((a && !b) || (!a && b))
501 { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
503 if(!a->isEqual(b,eps,what))
504 { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; }
509 void MEDFileParameterMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
511 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
512 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
516 void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception)
518 std::set<med_parameter_type> diffType;
519 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
521 const MEDFileParameter1TS *elt(*it);
522 if(dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt))
523 diffType.insert(MED_FLOAT64);
525 if(diffType.size()>1)
526 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ...");
529 med_parameter_type typ=*diffType.begin();
530 MEDFileParameterTinyInfo::writeLLHeader(fid,typ);
531 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
533 const MEDFileParameter1TS *elt(*it);
535 elt->writeLL(fid,_name,mw);
539 std::string MEDFileParameterMultiTS::simpleRepr() const
541 std::ostringstream oss;
546 void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const
548 MEDFileParameterTinyInfo::mainRepr(bkOffset,oss);
549 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
551 const MEDFileParameter1TS *elt(*it);
553 elt->simpleRepr2(bkOffset+2,oss);
557 void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception)
559 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterDouble1TSWTI> elt=MEDFileParameterDouble1TSWTI::New(dt,it,time);
561 MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef();
562 _param_per_ts.push_back(elt2);
565 double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception)
567 int pos=getPosOfTimeStep(iteration,order);
568 const MEDFileParameter1TS *elt=_param_per_ts[pos];
571 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
572 oss << " exists but elt is empty !";
573 throw INTERP_KERNEL::Exception(oss.str().c_str());
575 const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt);
578 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
579 oss << " exists but not double !";
581 return eltC->getValue();
584 int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
587 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :";
588 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
590 const MEDFileParameter1TS *elt(*it);
593 if(elt->getIteration()==iteration && elt->getOrder())
596 oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), ";
599 throw INTERP_KERNEL::Exception(oss.str().c_str());
602 int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
605 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! Possibilities are :";
606 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
608 const MEDFileParameter1TS *elt(*it);
611 if(fabs(elt->getTimeValue()-time)<=eps)
614 oss << elt->getTimeValue() << ", ";
617 throw INTERP_KERNEL::Exception(oss.str().c_str());
621 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
623 MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception)
625 if(posId<0 || posId>=(int)_param_per_ts.size())
627 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !";
628 throw INTERP_KERNEL::Exception(oss.str().c_str());
630 return const_cast<MEDFileParameter1TS *>(static_cast<const MEDFileParameter1TS *>(_param_per_ts[posId]));
633 void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
635 std::vector<bool> b(_param_per_ts.size(),true);
636 int len=(int)_param_per_ts.size();
637 for(const int *w=startIds;w!=endIds;w++)
642 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());
644 std::size_t newNb=std::count(b.begin(),b.end(),true);
645 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > paramPerTs(newNb);
647 for(std::size_t i=0;i<_param_per_ts.size();i++)
649 paramPerTs[j++]=_param_per_ts[i];
650 _param_per_ts=paramPerTs;
653 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getIterations() const throw(INTERP_KERNEL::Exception)
655 std::vector< std::pair<int,int> > ret;
656 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
658 const MEDFileParameter1TS *elt(*it);
660 ret.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
668 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
670 std::vector< std::pair<int,int> > ret0;
672 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
674 const MEDFileParameter1TS *elt(*it);
677 ret0.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
678 ret1.push_back(elt->getTimeValue());
684 MEDFileParameters *MEDFileParameters::New()
686 return new MEDFileParameters;
689 MEDFileParameters *MEDFileParameters::New(const char *fileName) throw(INTERP_KERNEL::Exception)
691 return new MEDFileParameters(fileName);
694 MEDFileParameters::MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception)
696 MEDFileUtilities::CheckFileForRead(fileName);
697 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
698 int nbPar=MEDnParameter(fid);
699 _params.resize(nbPar);
700 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
701 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
702 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
703 med_parameter_type paramType;
704 for(int i=0;i<nbPar;i++)
707 MEDparameterInfo(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps);
708 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
709 _params[i]=MEDFileParameterMultiTS::New(fileName,paramNameCpp.c_str());
713 MEDFileParameters::MEDFileParameters()
717 std::size_t MEDFileParameters::getHeapMemorySize() const
719 std::size_t ret=sizeof(MEDFileParameters);
720 std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>)*_params.capacity();
721 for(std::size_t i=0;i<_params.size();i++)
723 const MEDFileParameterMultiTS *pt(_params[i]);
725 ret2+=pt->getHeapMemorySize();
730 MEDFileParameters *MEDFileParameters::deepCpy() const throw(INTERP_KERNEL::Exception)
732 return new MEDFileParameters(*this,true);
735 bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const
738 { what="other is null !"; return false; }
739 if(_params.size()!=other->_params.size())
740 { what="number of parameters differs !"; return false; }
741 std::ostringstream oss;
742 for(std::size_t i=0;i<_params.size();i++)
744 const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]);
745 if((a && !b) || (!a && b))
746 { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
748 if(!a->isEqual(b,eps,what))
749 { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; }
754 MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params)
757 for(std::size_t i=0;i<_params.size();i++)
759 const MEDFileParameterMultiTS *elt=_params[i];
761 _params[i]=elt->deepCpy();
765 void MEDFileParameters::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
767 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
768 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
772 void MEDFileParameters::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
774 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
776 const MEDFileParameterMultiTS *elt(*it);
778 elt->writeLL(fid,*this);
782 std::vector<std::string> MEDFileParameters::getParamsNames() const throw(INTERP_KERNEL::Exception)
784 std::vector<std::string> ret(_params.size());
786 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,i++)
788 const MEDFileParameterMultiTS *p=(*it);
795 std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !";
796 throw INTERP_KERNEL::Exception(oss.str().c_str());
802 std::string MEDFileParameters::simpleRepr() const
804 std::ostringstream oss;
805 simpleReprWithoutHeader(oss);
809 void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const
811 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
813 const MEDFileParameterMultiTS *elt(*it);
815 elt->simpleRepr2(2,oss);
819 void MEDFileParameters::resize(int newSize) throw(INTERP_KERNEL::Exception)
822 throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !");
823 _params.resize(newSize);
826 void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception)
830 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
831 _params.push_back(elt);
834 void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception)
837 throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !");
838 if(i>=(int)_params.size())
842 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
847 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
849 MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const throw(INTERP_KERNEL::Exception)
851 if(i<0 || i>=(int)_params.size())
853 std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !";
854 throw INTERP_KERNEL::Exception(oss.str().c_str());
856 const MEDFileParameterMultiTS *elt=_params[i];
857 return const_cast<MEDFileParameterMultiTS *>(elt);
861 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
863 MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception)
865 int pos=getPosFromParamName(paramName);
866 return getParamAtPos(pos);
869 void MEDFileParameters::destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception)
871 if(i<0 || i>=(int)_params.size())
873 std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !";
874 throw INTERP_KERNEL::Exception(oss.str().c_str());
876 _params[i]=MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>(0);
879 int MEDFileParameters::getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception)
881 std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :";
883 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,ret++)
885 const MEDFileParameterMultiTS *elt(*it);
888 if(std::string(elt->getName())==paramName)
891 oss << elt->getName() << ", ";
894 throw INTERP_KERNEL::Exception(oss.str().c_str());
897 int MEDFileParameters::getNumberOfParams() const throw(INTERP_KERNEL::Exception)
899 return (int)_params.size();