1 // Copyright (C) 2007-2015 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 "MEDFileSafeCaller.txx"
24 #include "MEDLoaderBase.hxx"
26 #include "InterpKernelAutoPtr.hxx"
30 using namespace ParaMEDMEM;
32 MEDFileParameter1TS::MEDFileParameter1TS(int iteration, int order, double time):_iteration(iteration),_order(order),_time(time)
36 MEDFileParameter1TS::MEDFileParameter1TS():_iteration(-1),_order(-1),_time(0.)
40 bool MEDFileParameter1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
42 std::ostringstream oss;
44 { what="Other is null"; return false; }
45 if(_iteration!=other->_iteration)
46 { oss << "iteration number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
47 if(_order!=other->_order)
48 { oss << "order number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; }
49 if(fabs(_time-other->_time)>eps)
50 { oss << "time mismatches " << _time << " != " << other->_time << " eps=" << eps; what=oss.str(); return false; }
54 MEDFileParameter1TS *MEDFileParameterDouble1TSWTI::deepCpy() const
56 return new MEDFileParameterDouble1TSWTI(*this);
59 bool MEDFileParameterDouble1TSWTI::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
61 if(!MEDFileParameter1TS::isEqual(other,eps,what))
63 const MEDFileParameterDouble1TSWTI *otherC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(other);
65 { what="IsEqual fails because this is double parameter other no !"; return false; }
66 if(fabs(_arr-otherC->_arr)>eps)
67 { std::ostringstream oss; oss << "value differ " << _arr << " != " << otherC->_arr << " (eps=" << eps << ")"; return false; }
71 std::size_t MEDFileParameterDouble1TSWTI::getHeapMemorySizeWithoutChildren() const
73 return sizeof(MEDFileParameterDouble1TSWTI);
76 std::vector<const BigMemoryObject *> MEDFileParameterDouble1TSWTI::getDirectChildrenWithNull() const
78 return std::vector<const BigMemoryObject *>();
81 std::string MEDFileParameterDouble1TSWTI::simpleRepr() const
83 std::ostringstream oss;
88 void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const
90 std::string startOfLine(bkOffset,' ');
91 oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl;
92 oss << startOfLine << "Time associacited = " << _time << std::endl;
93 oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl;
96 MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time)
98 return new MEDFileParameterDouble1TSWTI(iteration,order,time);
101 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits<double>::max())
105 MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time)
109 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps)
111 std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : ";
112 for(int i=0;i<nbOfSteps;i++)
116 MEDFILESAFECALLERRD0(MEDparameterComputationStepInfo,(fid,name.c_str(),i+1,&locDt,&locIt,&tim));
117 if(dt==locDt && it==locIt)
119 _iteration=locDt; _order=locIt; _time=tim;
120 MEDFILESAFECALLERRD0(MEDparameterValueRd,(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr)));
125 oss << "(" << locDt << "," << locIt << ")";
130 throw INTERP_KERNEL::Exception(oss.str().c_str());
133 void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name)
135 MEDFILESAFECALLERRD0(MEDparameterValueRd,(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr)));
138 void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId)
142 MEDFILESAFECALLERRD0(MEDparameterComputationStepInfo,(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt));
143 _iteration=locDt; _order=locIt; _time=dt;
144 MEDFILESAFECALLERRD0(MEDparameterValueRd,(fid,name.c_str(),_iteration,_order,reinterpret_cast<unsigned char *const>(&_arr)));
147 void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const
149 char nameW[MED_NAME_SIZE+1];
150 MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy());
151 MEDFILESAFECALLERWR0(MEDparameterValueWr,(fid,nameW,_iteration,_order,_time,reinterpret_cast<const unsigned char *>(&_arr)));
154 std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const
156 return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity();
159 bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const
161 std::ostringstream oss;
162 if(_name!=other._name)
163 { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; }
164 if(_desc_name!=other._desc_name)
165 { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; }
166 if(_dt_unit!=other._dt_unit)
167 { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; }
171 void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const
173 char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1];
174 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy());
175 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy());
176 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy());
177 MEDFILESAFECALLERWR0(MEDparameterCr,(fid,nameW,typ,descW,dtunitW));
180 void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const
182 std::string startOfLine(bkOffset,' ');
183 oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl;
184 oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl;
185 oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl;
188 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New()
190 return new MEDFileParameterDouble1TS;
193 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName)
195 return new MEDFileParameterDouble1TS(fileName);
198 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName, const std::string& paramName)
200 return new MEDFileParameterDouble1TS(fileName,paramName);
203 MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const std::string& fileName, const std::string& paramName, int dt, int it)
205 return new MEDFileParameterDouble1TS(fileName,paramName,dt,it);
208 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS()
212 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName, int dt, int it)
214 MEDFileUtilities::CheckFileForRead(fileName);
215 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
216 int nbPar=MEDnParameter(fid);
217 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
218 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
219 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
220 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
221 med_parameter_type paramType;
222 for(int i=0;i<nbPar;i++)
225 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps));
226 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
227 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
229 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
231 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
232 finishLoading(fid,_name,dt,it,nbOfSteps);
238 if(i!=nbPar-1) oss << ", ";
241 throw INTERP_KERNEL::Exception(oss.str().c_str());
244 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName)
246 MEDFileUtilities::CheckFileForRead(fileName);
247 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
248 int nbPar=MEDnParameter(fid);
249 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
250 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
251 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
252 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
253 med_parameter_type paramType;
254 for(int i=0;i<nbPar;i++)
257 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps));
258 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
259 if(paramNameCpp==paramName && paramType==MED_FLOAT64)
263 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
265 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
266 finishLoading(fid,_name,0);
271 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
272 throw INTERP_KERNEL::Exception(oss2.str().c_str());
278 if(i!=nbPar-1) oss << ", ";
281 throw INTERP_KERNEL::Exception(oss.str().c_str());
284 MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const std::string& fileName)
286 MEDFileUtilities::CheckFileForRead(fileName);
287 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
288 int nbPar=MEDnParameter(fid);
291 std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !";
292 throw INTERP_KERNEL::Exception(oss2.str().c_str());
294 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
295 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
296 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
297 med_parameter_type paramType;
299 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,1,pName,¶mType,descName,unitName,&nbOfSteps));
300 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
301 if(paramType==MED_FLOAT64)
305 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
307 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
308 finishLoading(fid,_name,0);
313 std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !";
314 throw INTERP_KERNEL::Exception(oss2.str().c_str());
319 std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !";
320 throw INTERP_KERNEL::Exception(oss2.str().c_str());
324 bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const
326 if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what))
328 const MEDFileParameterDouble1TS *otherC=dynamic_cast<const MEDFileParameterDouble1TS *>(other);
330 { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; }
331 if(!isEqualStrings(*otherC,what))
336 MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const
338 return new MEDFileParameterDouble1TS(*this);
341 std::string MEDFileParameterDouble1TS::simpleRepr() const
343 std::ostringstream oss;
344 MEDFileParameterTinyInfo::mainRepr(0,oss);
345 MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss);
349 std::size_t MEDFileParameterDouble1TS::getHeapMemorySizeWithoutChildren() const
351 return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS);
354 std::vector<const BigMemoryObject *> MEDFileParameterDouble1TS::getDirectChildrenWithNull() const
356 return std::vector<const BigMemoryObject *>();
359 void MEDFileParameterDouble1TS::write(const std::string& fileName, int mode) const
361 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
362 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
363 MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64);
364 MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this);
367 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New()
369 return new MEDFileParameterMultiTS;
372 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const std::string& fileName)
374 return new MEDFileParameterMultiTS(fileName);
377 MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const std::string& fileName, const std::string& paramName)
379 return new MEDFileParameterMultiTS(fileName,paramName);
382 MEDFileParameterMultiTS::MEDFileParameterMultiTS()
386 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts)
389 for(std::size_t i=0;i<_param_per_ts.size();i++)
391 const MEDFileParameter1TS *elt=_param_per_ts[i];
393 _param_per_ts[i]=elt->deepCpy();
397 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const std::string& fileName)
399 MEDFileUtilities::CheckFileForRead(fileName);
400 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
401 int nbPar=MEDnParameter(fid);
404 std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ;
405 throw INTERP_KERNEL::Exception(oss.str().c_str());
407 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
408 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
409 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
410 med_parameter_type paramType;
412 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,1,pName,¶mType,descName,unitName,&nbOfSteps));
413 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
414 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
416 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
417 finishLoading(fid,paramType,nbOfSteps);
420 MEDFileParameterMultiTS::MEDFileParameterMultiTS(const std::string& fileName, const std::string& paramName)
422 MEDFileUtilities::CheckFileForRead(fileName);
423 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
424 int nbPar=MEDnParameter(fid);
425 std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : ";
426 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
427 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
428 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
429 med_parameter_type paramType;
430 for(int i=0;i<nbPar;i++)
433 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps));
434 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
435 if(paramNameCpp==paramName)
439 _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE);
441 _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE);
442 finishLoading(fid,paramType,nbOfSteps);
447 std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !";
448 throw INTERP_KERNEL::Exception(oss2.str().c_str());
454 if(i!=nbPar-1) oss << ", ";
457 throw INTERP_KERNEL::Exception(oss.str().c_str());
460 void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps)
462 _param_per_ts.resize(nbOfSteps);
463 for(int i=0;i<nbOfSteps;i++)
467 MEDFILESAFECALLERRD0(MEDparameterComputationStepInfo,(fid,_name.c_str(),i+1,&dt,&it,&tim));
471 _param_per_ts[i]=MEDFileParameterDouble1TSWTI::New(dt,it,tim);
472 _param_per_ts[i]->readValue(fid,_name.c_str());
478 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !");
483 std::size_t MEDFileParameterMultiTS::getHeapMemorySizeWithoutChildren() const
485 std::size_t ret(sizeof(MEDFileParameterMultiTS));
486 ret+=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS>)*_param_per_ts.capacity();
490 std::vector<const BigMemoryObject *> MEDFileParameterMultiTS::getDirectChildrenWithNull() const
492 std::vector<const BigMemoryObject *> ret;
493 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
494 ret.push_back((const MEDFileParameter1TS *)*it);
498 MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const
500 return new MEDFileParameterMultiTS(*this,true);
503 bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const
506 { what="other is null !"; return false; }
507 if(_param_per_ts.size()!=other->_param_per_ts.size())
508 { what="number of time steps differs !"; return false; }
509 std::ostringstream oss;
510 for(std::size_t i=0;i<_param_per_ts.size();i++)
512 const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]);
513 if((a && !b) || (!a && b))
514 { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
516 if(!a->isEqual(b,eps,what))
517 { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; }
522 void MEDFileParameterMultiTS::write(const std::string& fileName, int mode) const
524 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
525 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
529 void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const
531 std::set<med_parameter_type> diffType;
532 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
534 const MEDFileParameter1TS *elt(*it);
535 if(dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt))
536 diffType.insert(MED_FLOAT64);
538 if(diffType.size()>1)
539 throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ...");
542 med_parameter_type typ=*diffType.begin();
543 MEDFileParameterTinyInfo::writeLLHeader(fid,typ);
544 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
546 const MEDFileParameter1TS *elt(*it);
548 elt->writeLL(fid,_name,mw);
552 std::string MEDFileParameterMultiTS::simpleRepr() const
554 std::ostringstream oss;
559 void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const
561 MEDFileParameterTinyInfo::mainRepr(bkOffset,oss);
562 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
564 const MEDFileParameter1TS *elt(*it);
566 elt->simpleRepr2(bkOffset+2,oss);
570 void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val)
572 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterDouble1TSWTI> elt=MEDFileParameterDouble1TSWTI::New(dt,it,time);
574 MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef();
575 _param_per_ts.push_back(elt2);
578 double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const
580 int pos=getPosOfTimeStep(iteration,order);
581 const MEDFileParameter1TS *elt=_param_per_ts[pos];
584 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
585 oss << " exists but elt is empty !";
586 throw INTERP_KERNEL::Exception(oss.str().c_str());
588 const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast<const MEDFileParameterDouble1TSWTI *>(elt);
591 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order;
592 oss << " exists but not double !";
594 return eltC->getValue();
597 int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const
600 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :";
601 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
603 const MEDFileParameter1TS *elt(*it);
606 if(elt->getIteration()==iteration && elt->getOrder()==order)
609 oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), ";
612 throw INTERP_KERNEL::Exception(oss.str().c_str());
615 int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const
618 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! Possibilities are :";
619 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++)
621 const MEDFileParameter1TS *elt(*it);
624 if(fabs(elt->getTimeValue()-time)<=eps)
627 oss << elt->getTimeValue() << ", ";
630 throw INTERP_KERNEL::Exception(oss.str().c_str());
634 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
636 MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const
638 if(posId<0 || posId>=(int)_param_per_ts.size())
640 std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !";
641 throw INTERP_KERNEL::Exception(oss.str().c_str());
643 return const_cast<MEDFileParameter1TS *>(static_cast<const MEDFileParameter1TS *>(_param_per_ts[posId]));
646 void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
648 std::vector<bool> b(_param_per_ts.size(),true);
649 int len=(int)_param_per_ts.size();
650 for(const int *w=startIds;w!=endIds;w++)
655 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());
657 std::size_t newNb=std::count(b.begin(),b.end(),true);
658 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > paramPerTs(newNb);
660 for(std::size_t i=0;i<_param_per_ts.size();i++)
662 paramPerTs[j++]=_param_per_ts[i];
663 _param_per_ts=paramPerTs;
666 int MEDFileParameterMultiTS::getNumberOfTS() const
668 return (int) getIterations().size();
671 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getIterations() const
673 std::vector< std::pair<int,int> > ret;
674 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
676 const MEDFileParameter1TS *elt(*it);
678 ret.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
686 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getTimeSteps(std::vector<double>& ret1) const
688 std::vector< std::pair<int,int> > ret0;
690 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++)
692 const MEDFileParameter1TS *elt(*it);
695 ret0.push_back(std::pair<int,int>(elt->getIteration(),elt->getOrder()));
696 ret1.push_back(elt->getTimeValue());
702 MEDFileParameters *MEDFileParameters::New()
704 return new MEDFileParameters;
707 MEDFileParameters *MEDFileParameters::New(const std::string& fileName)
709 return new MEDFileParameters(fileName);
712 MEDFileParameters::MEDFileParameters(const std::string& fileName)
714 MEDFileUtilities::CheckFileForRead(fileName);
715 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
716 int nbPar=MEDnParameter(fid);
717 _params.resize(nbPar);
718 INTERP_KERNEL::AutoPtr<char> pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
719 INTERP_KERNEL::AutoPtr<char> descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
720 INTERP_KERNEL::AutoPtr<char> unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
721 med_parameter_type paramType;
722 for(int i=0;i<nbPar;i++)
725 MEDFILESAFECALLERRD0(MEDparameterInfo,(fid,i+1,pName,¶mType,descName,unitName,&nbOfSteps));
726 std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE);
727 _params[i]=MEDFileParameterMultiTS::New(fileName,paramNameCpp);
731 MEDFileParameters::MEDFileParameters()
735 std::size_t MEDFileParameters::getHeapMemorySizeWithoutChildren() const
737 std::size_t ret(sizeof(MEDFileParameters));
738 ret+=sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>)*_params.capacity();
742 std::vector<const BigMemoryObject *> MEDFileParameters::getDirectChildrenWithNull() const
744 std::vector<const BigMemoryObject *> ret;
745 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
746 ret.push_back((const MEDFileParameterMultiTS *)*it);
750 MEDFileParameters *MEDFileParameters::deepCpy() const
752 return new MEDFileParameters(*this,true);
755 bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const
758 { what="other is null !"; return false; }
759 if(_params.size()!=other->_params.size())
760 { what="number of parameters differs !"; return false; }
761 std::ostringstream oss;
762 for(std::size_t i=0;i<_params.size();i++)
764 const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]);
765 if((a && !b) || (!a && b))
766 { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; }
768 if(!a->isEqual(b,eps,what))
769 { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; }
774 MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params)
777 for(std::size_t i=0;i<_params.size();i++)
779 const MEDFileParameterMultiTS *elt=_params[i];
781 _params[i]=elt->deepCpy();
785 void MEDFileParameters::write(const std::string& fileName, int mode) const
787 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
788 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
792 void MEDFileParameters::writeLL(med_idt fid) const
794 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
796 const MEDFileParameterMultiTS *elt(*it);
798 elt->writeLL(fid,*this);
802 std::vector<std::string> MEDFileParameters::getParamsNames() const
804 std::vector<std::string> ret(_params.size());
806 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,i++)
808 const MEDFileParameterMultiTS *p=(*it);
815 std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !";
816 throw INTERP_KERNEL::Exception(oss.str().c_str());
822 std::string MEDFileParameters::simpleRepr() const
824 std::ostringstream oss;
825 simpleReprWithoutHeader(oss);
829 void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const
831 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++)
833 const MEDFileParameterMultiTS *elt(*it);
835 elt->simpleRepr2(2,oss);
839 void MEDFileParameters::resize(int newSize)
842 throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !");
843 _params.resize(newSize);
846 void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param)
850 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
851 _params.push_back(elt);
854 void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param)
857 throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !");
858 if(i>=(int)_params.size())
862 MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> elt(param);
867 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
869 MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const
871 if(i<0 || i>=(int)_params.size())
873 std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !";
874 throw INTERP_KERNEL::Exception(oss.str().c_str());
876 const MEDFileParameterMultiTS *elt=_params[i];
877 return const_cast<MEDFileParameterMultiTS *>(elt);
881 * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer.
883 MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const std::string& paramName) const
885 int pos=getPosFromParamName(paramName);
886 return getParamAtPos(pos);
889 void MEDFileParameters::destroyParamAtPos(int i)
891 if(i<0 || i>=(int)_params.size())
893 std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !";
894 throw INTERP_KERNEL::Exception(oss.str().c_str());
896 _params[i]=MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS>(0);
899 int MEDFileParameters::getPosFromParamName(const std::string& paramName) const
901 std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :";
903 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> >::const_iterator it=_params.begin();it!=_params.end();it++,ret++)
905 const MEDFileParameterMultiTS *elt(*it);
908 if(std::string(elt->getName())==paramName)
911 oss << elt->getName() << ", ";
914 throw INTERP_KERNEL::Exception(oss.str().c_str());
917 int MEDFileParameters::getNumberOfParams() const
919 return (int)_params.size();