Salome HOME
117d84d63b68e2ded256bef253e9171e7341abac
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldMultiTS.cxx
1 // Copyright (C) 2017-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #include "MEDFileFieldMultiTS.hxx"
22 #include "MEDFileFieldVisitor.hxx"
23 #include "MEDFileSafeCaller.txx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDFileField.txx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldTemplate.hxx"
29
30 #include <sstream>
31
32 using namespace MEDCoupling;
33
34 template class MEDCoupling::MEDFileTemplateFieldMultiTSWithoutSDA<int>;
35 template class MEDCoupling::MEDFileTemplateFieldMultiTSWithoutSDA<float>;
36 template class MEDCoupling::MEDFileTemplateFieldMultiTSWithoutSDA<double>;
37 template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<int>;
38 template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<float>;
39 template class MEDCoupling::MEDFileTemplateFieldMultiTS<int>;
40 template class MEDCoupling::MEDFileTemplateFieldMultiTS<float>;
41 template class MEDCoupling::MEDFileTemplateFieldMultiTS<double>;
42 template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<int>;
43 template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<float>;
44
45 extern INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype);
46   
47 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
48
49 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
50 {
51 }
52
53 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
54 {
55 }
56
57 /*!
58  * \param [in] fieldId field id in C mode
59  */
60 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
61 {
62   med_field_type typcha;
63   std::string dtunitOut,meshName;
64   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
65   setMeshName(meshName);
66   setDtUnit(dtunitOut.c_str());
67   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
68 }
69
70 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
71 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
72 {
73   setDtUnit(dtunit.c_str());
74   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
75 }
76 catch(INTERP_KERNEL::Exception& e)
77 {
78     throw e;
79 }
80
81 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
82 {
83   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
84   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
85     ret+=(*it).capacity();
86   return ret;
87 }
88
89 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
90 {
91   std::vector<const BigMemoryObject *> ret;
92   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
93     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
94   return ret;
95 }
96
97 /*!
98  * If one of the id in [ \a startIds , \a endIds ) points to a null element, there is not throw. Simply, this empty element is added as if it were not
99  * NULL.
100  */
101 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
102 {
103   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
104   ret->setInfo(_infos);
105   int sz=(int)_time_steps.size();
106   for(const int *id=startIds;id!=endIds;id++)
107     {
108       if(*id>=0 && *id<sz)
109         {
110           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
111           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
112           if(tse)
113             {
114               tse->incrRef();
115               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
116             }
117           ret->pushBackTimeStep(tse2);
118         }
119       else
120         {
121           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
122           oss << " ! Should be in [0," << sz << ") !";
123           throw INTERP_KERNEL::Exception(oss.str());
124         }
125     }
126   if(ret->getNumberOfTS()>0)
127     ret->synchronizeNameScope();
128   ret->copyNameScope(*this);
129   return ret.retn();
130 }
131
132 /*!
133  * If one of the id in the input range points to a null element, there is not throw. Simply, this empty element is added as if it were not
134  * NULL.
135  */
136 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
137 {
138   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
139   mcIdType nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
140   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
141   ret->setInfo(_infos);
142   std::size_t sz=_time_steps.size();
143   std::size_t j=bg;
144   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
145     {
146       if(j>=0 && j<sz)
147         {
148           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
149           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
150           if(tse)
151             {
152               tse->incrRef();
153               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
154             }
155           ret->pushBackTimeStep(tse2);
156         }
157       else
158         {
159           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
160           oss << " ! Should be in [0," << sz << ") !";
161           throw INTERP_KERNEL::Exception(oss.str());
162         }
163     }
164   if(ret->getNumberOfTS()>0)
165     ret->synchronizeNameScope();
166   ret->copyNameScope(*this);
167   return ret.retn();
168 }
169
170 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
171 {
172   int id=0;
173   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
174   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
175     {
176       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
177       if(!cur)
178         continue;
179       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
180       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
181         ids->pushBackSilent(id);
182     }
183   return buildFromTimeStepIds(ids->begin(),ids->end());
184 }
185
186 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
187 {
188   int id=0;
189   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
190   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
191     {
192       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
193       if(!cur)
194         continue;
195       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
196       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
197         ids->pushBackSilent(id);
198     }
199   return buildFromTimeStepIds(ids->begin(),ids->end());
200 }
201
202 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
203 {
204   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
205     if((*it).isNotNull())
206       if((*it)->presenceOfStructureElements())
207         return true;
208   return false;
209 }
210
211 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
212 {
213   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
214     if((*it).isNotNull())
215       if(!(*it)->onlyStructureElements())
216         return false;
217   return true;
218 }
219
220 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
221 {
222   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
223   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
224     if((*it).isNotNull())
225       {
226         if((*it)->presenceOfStructureElements())
227           {
228             if(!(*it)->onlyStructureElements())
229               {
230                 (*it)->killStructureElements();
231                 ret.push_back(*it);
232               }
233           }
234         else
235           {
236             ret.push_back(*it);
237           }
238       }
239   _time_steps=ret;
240 }
241
242 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
243 {
244   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
245   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
246     if((*it).isNotNull())
247       {
248         if((*it)->presenceOfStructureElements())
249           {
250             if(!(*it)->onlyStructureElements())
251               (*it)->keepOnlyStructureElements();
252             ret.push_back(*it);
253           }
254       }
255   _time_steps=ret;
256 }
257
258 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
259 {
260   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
261   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
262     if((*it).isNotNull())
263       (*it)->keepOnlyOnSE(seName);
264 }
265
266 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
267 {
268   std::vector< std::pair<std::string,std::string> > ps2;
269   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
270     if((*it).isNotNull())
271       {
272         (*it)->getMeshSENames(ps2);
273         break;
274       }
275   if(ps2.empty())
276     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
277   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
278     if((*it).isNotNull())
279       {
280         std::vector< std::pair<std::string,std::string> > ps3;
281         (*it)->getMeshSENames(ps3);
282         if(ps2!=ps3)
283           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
284       }
285   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
286     {
287       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
288       if(it2==ps.end())
289         ps.push_back(*it);
290     }
291 }
292
293 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
294 {
295   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
296     {
297       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
298       if(!cur)
299         continue;
300       if(cur->presenceOfMultiDiscPerGeoType())
301         return true;
302     }
303   return false;
304 }
305
306 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
307 {
308   return _infos;
309 }
310
311 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
312 {
313   _infos=info;
314 }
315
316 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
317 {
318   int ret=0;
319   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
320     {
321       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
322       if(pt->isDealingTS(iteration,order))
323         return ret;
324     }
325   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
326   std::vector< std::pair<int,int> > vp=getIterations();
327   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
328     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
329   throw INTERP_KERNEL::Exception(oss.str());
330 }
331
332 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
333 {
334   return *_time_steps[getTimeStepPos(iteration,order)];
335 }
336
337 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
338 {
339   return *_time_steps[getTimeStepPos(iteration,order)];
340 }
341
342 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
343 {
344   bool ret(false);
345   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
346     {
347       if((*it).first==getMeshName())
348         {
349           setMeshName((*it).second);
350           ret=true;
351         }
352     }
353   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
354     {
355       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
356       if(cur)
357         ret=cur->changeMeshNames(modifTab) || ret;
358     }
359   return ret;
360 }
361
362 /*!
363  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
364  */
365 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
366 {
367   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
368 }
369
370 /*!
371  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
372  */
373 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
374 {
375   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
376 }
377
378 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<mcIdType>& oldCode, const std::vector<mcIdType>& newCode, const DataArrayIdType *renumO2N,
379                                                                        MEDFileFieldGlobsReal& glob)
380 {
381   bool ret=false;
382   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
383     {
384       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
385       if(f1ts)
386         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
387     }
388   return ret;
389 }
390
391 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
392 {
393   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
394     if((*it).isNotNull())
395       {
396         visitor.newTimeStepEntry(*it);
397         (*it)->accept(visitor);
398         visitor.endTimeStepEntry(*it);
399       }
400 }
401
402 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
403 {
404   std::string startLine(bkOffset,' ');
405   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
406   if(fmtsId>=0)
407     oss << " (" << fmtsId << ")";
408   oss << " has the following name: \"" << _name << "\"." << std::endl;
409   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
410   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
411     {
412       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
413     }
414   int i=0;
415   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
416     {
417       std::string chapter(17,'0'+i);
418       oss << startLine << chapter << std::endl;
419       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
420       if(cur)
421         cur->simpleRepr(bkOffset+2,oss,i);
422       else
423         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
424       oss << startLine << chapter << std::endl;
425     }
426 }
427
428 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
429 {
430   std::size_t sz=_time_steps.size();
431   std::vector< std::pair<int,int> > ret(sz);
432   ret1.resize(sz);
433   for(std::size_t i=0;i<sz;i++)
434     {
435       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
436       if(f1ts)
437         {
438           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
439         }
440       else
441         {
442           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
443           throw INTERP_KERNEL::Exception(oss.str());
444         }
445     }
446   return ret;
447 }
448
449 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
450 {
451   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
452   if(!tse2)
453     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
454   checkCoherencyOfType(tse2);
455   if(_time_steps.empty())
456     {
457       setName(tse2->getName());
458       setMeshName(tse2->getMeshName());
459       setInfo(tse2->getInfo());
460     }
461   checkThatComponentsMatch(tse2->getInfo());
462   if(getDtUnit().empty() && !tse->getDtUnit().empty())
463     setDtUnit(tse->getDtUnit());
464   _time_steps.push_back(tse);
465 }
466
467 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
468 {
469   std::size_t nbOfCompo=_infos.size();
470   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
471     {
472       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
473       if(cur)
474         {
475           if((cur->getInfo()).size()!=nbOfCompo)
476             {
477               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
478               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
479               throw INTERP_KERNEL::Exception(oss.str());
480             }
481           cur->copyNameScope(*this);
482         }
483     }
484 }
485
486 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
487 {
488   _time_steps.resize(nbPdt);
489   //
490   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entitiesFast;
491   const MEDFileEntities *entitiesForSubInstances(entities);
492   MEDFileCapability mfcap(fid);
493   if( ( !entities || entities->areAllStaticPresentAndNoDyn() ) && mfcap.isFastReader())
494     {// no entities
495       int nentitype(MEDfieldnEntityType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT));
496       INTERP_KERNEL::AutoPtr<med_entity_type> types(new med_entity_type[nentitype]);
497       med_int usedbyncs;
498       MEDFILESAFECALLERRD0(MEDfieldEntityType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types,&usedbyncs));
499       std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesFastP;
500       for(int i=0;i<nentitype;i++)
501         {
502           int ngeotype(MEDfieldnGeometryType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i]));
503           INTERP_KERNEL::AutoPtr<med_geometry_type> geotypes(new med_geometry_type[ngeotype]);
504           med_int geousedbyncs;
505           MEDFILESAFECALLERRD0(MEDfieldGeometryType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i],geotypes,&geousedbyncs));
506           for(int j=0;j<ngeotype;j++)
507             {
508               std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> p(MEDFileMesh::ConvertFromMEDFileEntity(types[i]),ConvertGeometryType(geotypes[j]));
509               entitiesFastP.push_back(p);
510             }
511         }
512       entitiesFast=new MEDFileStaticEntities(entitiesFastP);
513       entitiesForSubInstances=entitiesFast;
514     }
515   for(int i=0;i<nbPdt;i++)
516     {
517       std::vector< std::pair<int,int> > ts;
518       med_int numdt=0,numo=0;
519       med_float dt=0.0;
520       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
521       switch(fieldTyp)
522       {
523         case MED_FLOAT64:
524           {
525             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,FromMedInt<int>(numdt),FromMedInt<int>(numo),_infos);
526             break;
527           }
528         case MED_INT32:
529           {
530             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,FromMedInt<int>(numdt),FromMedInt<int>(numo),_infos);
531             break;
532           }
533         case MED_FLOAT32:
534           {
535             _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,FromMedInt<int>(numdt),FromMedInt<int>(numo),_infos);
536             break;
537           }
538         case MED_INT:
539           {
540             if(sizeof(med_int)==sizeof(int))
541               {
542                 _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,FromMedInt<int>(numdt),FromMedInt<int>(numo),_infos);
543                 break;
544               }
545           }
546         default:
547           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !");
548       }
549       if(loadAll)
550         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entitiesForSubInstances);
551       else
552         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entitiesForSubInstances,&mfcap);
553     }
554   synchronizeNameScope();
555 }
556
557 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
558 {
559   if(_time_steps.empty())
560     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
561   checkThatNbOfCompoOfTSMatchThis();
562   std::vector<std::string> infos(getInfo());
563   std::size_t nbComp=infos.size();
564   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
565   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
566   for(unsigned int i=0;i<nbComp;i++)
567     {
568       std::string info=infos[i];
569       std::string c,u;
570       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
571       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
572       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
573     }
574   if(_name.empty())
575     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
576   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),ToMedInt(nbComp),comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
577   std::size_t nbOfTS=_time_steps.size();
578   for(std::size_t i=0;i<nbOfTS;i++)
579     _time_steps[i]->writeLL(fid,opts,*this);
580 }
581
582 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
583 {
584   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
585     {
586       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
587       if(elt)
588         elt->loadBigArraysRecursively(fid,nasc);
589     }
590 }
591
592 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
593 {
594   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
595     {
596       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
597       if(elt)
598         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
599     }
600 }
601
602 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
603 {
604   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
605     {
606       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
607       if(elt)
608         elt->unloadArrays();
609     }
610 }
611
612 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
613 {
614   return (int)_time_steps.size();
615 }
616
617 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
618 {
619   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
620   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
621     {
622       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
623       if(tmp)
624         newTS.push_back(*it);
625     }
626   _time_steps=newTS;
627 }
628
629 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
630 {
631   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
632   int maxId=(int)_time_steps.size();
633   int ii=0;
634   std::set<int> idsToDel;
635   for(const int *id=startIds;id!=endIds;id++,ii++)
636     {
637       if(*id>=0 && *id<maxId)
638         {
639           idsToDel.insert(*id);
640         }
641       else
642         {
643           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
644           throw INTERP_KERNEL::Exception(oss.str());
645         }
646     }
647   for(int iii=0;iii<maxId;iii++)
648     if(idsToDel.find(iii)==idsToDel.end())
649       newTS.push_back(_time_steps[iii]);
650   _time_steps=newTS;
651 }
652
653 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
654 {
655   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
656   mcIdType nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
657   if(nbOfEntriesToKill==0)
658     return ;
659   std::size_t sz=_time_steps.size();
660   std::vector<bool> b(sz,true);
661   int j=bg;
662   for(mcIdType i=0;i<nbOfEntriesToKill;i++,j+=step)
663     b[j]=false;
664   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
665   for(std::size_t i=0;i<sz;i++)
666     if(b[i])
667       newTS.push_back(_time_steps[i]);
668   _time_steps=newTS;
669 }
670
671 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
672 {
673   int ret=0;
674   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
675   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
676     {
677       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
678       if(tmp)
679         {
680           int it2,ord;
681           tmp->getTime(it2,ord);
682           if(it2==iteration && order==ord)
683             return ret;
684           else
685             oss << "(" << it2 << ","  << ord << "), ";
686         }
687     }
688   throw INTERP_KERNEL::Exception(oss.str());
689 }
690
691 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
692 {
693   int ret=0;
694   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
695   oss.precision(15);
696   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
697     {
698       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
699       if(tmp)
700         {
701           int it2,ord;
702           double ti=tmp->getTime(it2,ord);
703           if(fabs(time-ti)<eps)
704             return ret;
705           else
706             oss << ti << ", ";
707         }
708     }
709   throw INTERP_KERNEL::Exception(oss.str());
710 }
711
712 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
713 {
714   std::size_t lgth=_time_steps.size();
715   std::vector< std::pair<int,int> > ret(lgth);
716   for(std::size_t i=0;i<lgth;i++)
717     _time_steps[i]->fillIteration(ret[i]);
718   return ret;
719 }
720
721 /*!
722  * This method has 3 inputs 'iteration' 'order' 'mname'. 'mname' can be null if the user is the general case where there is only one meshName lying on 'this'
723  * This method returns two things.
724  * - The absolute dimension of 'this' in first parameter. 
725  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
726  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
727  *
728  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
729  * Only these 3 discretizations will be taken into account here.
730  *
731  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
732  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
733  * case the caller has to know the underlying mesh it refers to. By default it is the level 0 of the corresponding mesh.
734  *
735  * This method is useful to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
736  * It is possible (even if it is not common) that the highest level in 'this' were not equal to the meshDimension of the underlying mesh in 'this'.
737  * 
738  * Let's consider the typical following case :
739  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
740  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
741  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
742  *   TETRA4 and SEG2
743  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
744  *
745  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
746  * 
747  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
748  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
749  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
750  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
751  */
752 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
753 {
754   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
755 }
756
757 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
758 {
759   if(pos<0 || pos>=(int)_time_steps.size())
760     {
761       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
762       throw INTERP_KERNEL::Exception(oss.str());
763     }
764   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
765   if(item==0)
766     {
767       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
768       oss << "\nTry to use following method eraseEmptyTS !";
769       throw INTERP_KERNEL::Exception(oss.str());
770     }
771   return item;
772 }
773
774 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
775 {
776   if(pos<0 || pos>=(int)_time_steps.size())
777     {
778       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
779       throw INTERP_KERNEL::Exception(oss.str());
780     }
781   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
782   if(item==0)
783     {
784       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
785       oss << "\nTry to use following method eraseEmptyTS !";
786       throw INTERP_KERNEL::Exception(oss.str());
787     }
788   return item;
789 }
790
791 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
792 {
793   std::vector<std::string> ret;
794   std::set<std::string> ret2;
795   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
796     {
797       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
798       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
799         if(ret2.find(*it2)==ret2.end())
800           {
801             ret.push_back(*it2);
802             ret2.insert(*it2);
803           }
804     }
805   return ret;
806 }
807
808 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
809 {
810   std::vector<std::string> ret;
811   std::set<std::string> ret2;
812   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
813     {
814       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
815       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
816         if(ret2.find(*it2)==ret2.end())
817           {
818             ret.push_back(*it2);
819             ret2.insert(*it2);
820           }
821     }
822   return ret;
823 }
824
825 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
826 {
827   std::vector<std::string> ret;
828   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
829     {
830       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
831       ret.insert(ret.end(),tmp.begin(),tmp.end());
832     }
833   return ret;
834 }
835
836 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
837 {
838   std::vector<std::string> ret;
839   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
840     {
841       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
842       ret.insert(ret.end(),tmp.begin(),tmp.end());
843     }
844   return ret;
845 }
846
847 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
848 {
849   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
850     (*it)->changePflsRefsNamesGen2(mapOfModif);
851 }
852
853 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
854 {
855   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
856     (*it)->changeLocsRefsNamesGen2(mapOfModif);
857 }
858
859 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
860 {
861   std::size_t lgth=_time_steps.size();
862   std::vector< std::vector<TypeOfField> > ret(lgth);
863   for(std::size_t i=0;i<lgth;i++)
864     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
865   return ret;
866 }
867
868 /*!
869  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
870  */
871 std::vector< std::vector< std::pair<mcIdType,mcIdType> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
872 {
873   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
874 }
875
876 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
877 {
878   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
879   std::size_t i=0;
880   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
881     {
882       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
883         ret->_time_steps[i]=(*it)->deepCopy();
884     }
885   return ret.retn();
886 }
887
888 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
889 {
890   std::size_t sz(_infos.size()),sz2(_time_steps.size());
891   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
892   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
893   for(std::size_t i=0;i<sz;i++)
894     {
895       ret[i]=shallowCpy();
896       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
897     }
898   for(std::size_t i=0;i<sz2;i++)
899     {
900       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
901       if(ret1.size()!=sz)
902         {
903           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
904           throw INTERP_KERNEL::Exception(oss.str());
905         }
906       ts[i]=ret1;
907     }
908   for(std::size_t i=0;i<sz;i++)
909     for(std::size_t j=0;j<sz2;j++)
910       ret[i]->_time_steps[j]=ts[j][i];
911   return ret;
912 }
913
914 /*!
915  * This method splits into discretization each time steps in \a this.
916  * ** WARNING ** the returned instances are not compulsory defined on the same time steps series !
917  */
918 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
919 {
920   std::size_t sz(_time_steps.size());
921   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
922   for(std::size_t i=0;i<sz;i++)
923     {
924       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
925       if(!timeStep)
926         {
927           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
928           throw INTERP_KERNEL::Exception(oss.str());
929         }
930       items[i]=timeStep->splitDiscretizations();  
931     }
932   //
933   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
934   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
935   std::vector< TypeOfField > types;
936   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
937     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
938       {
939         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
940         if(ts.size()!=1)
941           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
942         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
943         if(it2==types.end())
944           types.push_back(ts[0]);
945       }
946   ret.resize(types.size()); ret2.resize(types.size());
947   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
948     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
949       {
950         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
951         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
952         ret2[pos].push_back(*it1);
953       }
954   for(std::size_t i=0;i<types.size();i++)
955     {
956       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
957       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
958         elt->pushBackTimeStep(*it1);//also updates infos in elt
959       ret[i]=elt;
960       elt->MEDFileFieldNameScope::operator=(*this);
961     }
962   return ret;
963 }
964
965 /*!
966  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
967  */
968 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
969 {
970   std::size_t sz(_time_steps.size());
971   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
972   std::size_t szOut(std::numeric_limits<std::size_t>::max());
973   for(std::size_t i=0;i<sz;i++)
974     {
975       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
976       if(!timeStep)
977         {
978           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
979           throw INTERP_KERNEL::Exception(oss.str());
980         }
981       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
982       if(szOut==std::numeric_limits<std::size_t>::max())
983         szOut=items[i].size();
984       else
985         if(items[i].size()!=szOut)
986           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
987     }
988   if(szOut==std::numeric_limits<std::size_t>::max())
989     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
990   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
991   for(std::size_t i=0;i<szOut;i++)
992     {
993       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
994       for(std::size_t j=0;j<sz;j++)
995         elt->pushBackTimeStep(items[j][i]);
996       ret[i]=elt;
997       elt->MEDFileFieldNameScope::operator=(*this);
998     }
999   return ret;
1000 }
1001
1002 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
1003 {
1004   setName(field->getName());
1005   if(field->getMesh())
1006     setMeshName(field->getMesh()->getName());
1007   if(_name.empty())
1008     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
1009   if(!arr)
1010     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
1011   _infos=arr->getInfoOnComponents();
1012 }
1013
1014 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
1015 {
1016   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
1017   if(_name!=field->getName())
1018     {
1019       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
1020       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
1021       throw INTERP_KERNEL::Exception(oss.str());
1022     }
1023   if(!arr)
1024     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
1025   checkThatComponentsMatch(arr->getInfoOnComponents());
1026 }
1027
1028 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
1029 {
1030   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
1031   if(getInfo().size()!=compos.size())
1032     {
1033       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
1034       oss << " number of components of element to append (" << compos.size() << ") !";
1035       throw INTERP_KERNEL::Exception(oss.str());
1036     }
1037   if(_infos!=compos)
1038     {
1039       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
1040       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
1041       oss << " But compo in input fields are : ";
1042       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
1043       oss << " !";
1044       throw INTERP_KERNEL::Exception(oss.str());
1045     }
1046 }
1047
1048 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
1049 {
1050   std::size_t sz=_infos.size();
1051   int j=0;
1052   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
1053     {
1054       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
1055       if(elt)
1056         if(elt->getInfo().size()!=sz)
1057           {
1058             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
1059             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
1060             throw INTERP_KERNEL::Exception(oss.str());
1061           }
1062     }
1063 }
1064
1065 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1066 {
1067   if(!field)
1068     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
1069   if(!_time_steps.empty())
1070     checkCoherencyOfTinyInfo(field,arr);
1071   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(createNew1TSWithoutSDAEmptyInstance());
1072   {
1073     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
1074     obj->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,arr,glob,*this);
1075   }
1076   copyTinyInfoFrom(field,arr);
1077   _time_steps.push_back(obj);
1078 }
1079
1080 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, MEDFileFieldGlobsReal& glob, bool smartPflKiller)
1081 {
1082   if(!field)
1083     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
1084   if(!_time_steps.empty())
1085     checkCoherencyOfTinyInfo(field,arr);
1086   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(createNew1TSWithoutSDAEmptyInstance());
1087   {
1088     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
1089     obj->setFieldProfile(field->timeDiscrSafe(),ft,arr,mesh,meshDimRelToMax,profile,glob,*this,smartPflKiller);
1090   }
1091   copyTinyInfoFrom(field,arr);
1092   setMeshName(obj->getMeshName());
1093   _time_steps.push_back(obj);
1094 }
1095
1096 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
1097 {
1098   int sz=(int)_time_steps.size();
1099   if(i<0 || i>=sz)
1100     {
1101       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
1102       throw INTERP_KERNEL::Exception(oss.str());
1103     }
1104   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
1105   if(tsPtr)
1106     {
1107       if(tsPtr->getNumberOfComponents()!=_infos.size())
1108         {
1109           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
1110           throw INTERP_KERNEL::Exception(oss.str());
1111         }
1112     }
1113   _time_steps[i]=ts;
1114 }
1115
1116 //= MEDFileFieldMultiTSWithoutSDA
1117
1118 /*!
1119  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
1120  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
1121  */
1122 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
1123 {
1124   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
1125   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
1126   if(!myF1TSC)
1127     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
1128   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
1129 }
1130
1131 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
1132 {
1133   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
1134   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
1135   int i=0;
1136   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
1137     {
1138       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
1139       if(eltToConv)
1140         {
1141           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
1142           if(!eltToConvC)
1143             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
1144           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
1145           ret->setIteration(i,elt);
1146         }
1147     }
1148   return ret.retn();
1149 }
1150
1151 //= MEDFileAnyTypeFieldMultiTS
1152
1153 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
1154 {
1155 }
1156
1157 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
1158 try:MEDFileFieldGlobsReal(fid)
1159 {
1160   _content=BuildContentFrom(fid,loadAll,ms);
1161   loadGlobals(fid);
1162 }
1163 catch(INTERP_KERNEL::Exception& e)
1164 {
1165     throw e;
1166 }
1167
1168 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1169 {
1170   med_field_type typcha;
1171   std::vector<std::string> infos;
1172   std::string dtunit;
1173   std::string meshName;
1174   int i(-1);
1175   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
1176   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
1177   switch(typcha)
1178   {
1179     case MED_FLOAT64:
1180       {
1181         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
1182         break;
1183       }
1184     case MED_INT32:
1185       {
1186         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
1187         break;
1188       }
1189     case MED_FLOAT32:
1190       {
1191         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
1192         break;
1193       }
1194     case MED_INT:
1195       {
1196         if(sizeof(med_int)==sizeof(int))
1197           {
1198             ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
1199             break;
1200           }
1201       }
1202     default:
1203       {
1204         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
1205         throw INTERP_KERNEL::Exception(oss.str());
1206       }
1207   }
1208   ret->setMeshName(meshName);
1209   ret->setDtUnit(dtunit.c_str());
1210   return ret.retn();
1211 }
1212
1213 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
1214 {
1215   med_field_type typcha;
1216   //
1217   std::vector<std::string> infos;
1218   std::string dtunit,fieldName,meshName;
1219   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
1220   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
1221   switch(typcha)
1222   {
1223     case MED_FLOAT64:
1224       {
1225         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
1226         break;
1227       }
1228     case MED_INT32:
1229       {
1230         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
1231         break;
1232       }
1233     case MED_FLOAT32:
1234       {
1235         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
1236         break;
1237       }
1238     case MED_INT:
1239       {
1240         if(sizeof(med_int)==sizeof(int))
1241           {
1242             ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
1243             break;
1244           }
1245       }
1246     default:
1247       {
1248         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32] !";
1249         throw INTERP_KERNEL::Exception(oss.str());
1250       }
1251   }
1252   ret->setMeshName(meshName);
1253   ret->setDtUnit(dtunit.c_str());
1254   return ret.retn();
1255 }
1256
1257 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
1258 {
1259   if(!c)
1260     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
1261   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
1262     {
1263       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
1264       ret->_content=c;  c->incrRef();
1265       return ret.retn();
1266     }
1267   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
1268     {
1269       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
1270       ret->_content=c;  c->incrRef();
1271       return ret.retn();
1272     }
1273   if(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(c))
1274     {
1275       MCAuto<MEDFileFloatFieldMultiTS> ret(MEDFileFloatFieldMultiTS::New());
1276       ret->_content=c;  c->incrRef();
1277       return ret.retn();
1278     }
1279   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
1280 }
1281
1282 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
1283 {
1284   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
1285   std::string fileName(FileNameFromFID(fid));
1286   ret->setFileName(fileName);
1287   return ret;
1288 }
1289
1290 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1291 try:MEDFileFieldGlobsReal(fid)
1292 {
1293   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
1294   loadGlobals(fid);
1295 }
1296 catch(INTERP_KERNEL::Exception& e)
1297 {
1298     throw e;
1299 }
1300
1301 //= MEDFileAnyTypeFieldMultiTS
1302
1303 /*!
1304  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
1305  * that has been read from a specified MED file.
1306  *  \param [in] fileName - the name of the MED file to read.
1307  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
1308  *          is to delete this field using decrRef() as it is no more needed.
1309  *  \throw If reading the file fails.
1310  */
1311 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
1312 {
1313   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
1314   return New(fid,loadAll);
1315 }
1316
1317 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
1318 {
1319   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
1320   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
1321   ret->loadGlobals(fid);
1322   return ret.retn();
1323 }
1324
1325 /*!
1326  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
1327  * that has been read from a specified MED file.
1328  *  \param [in] fileName - the name of the MED file to read.
1329  *  \param [in] fieldName - the name of the field to read.
1330  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
1331  *          is to delete this field using decrRef() as it is no more needed.
1332  *  \throw If reading the file fails.
1333  *  \throw If there is no field named \a fieldName in the file.
1334  */
1335 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
1336 {
1337   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
1338   return New(fid,fieldName,loadAll);
1339 }
1340
1341 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
1342 {
1343   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
1344   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
1345   ret->loadGlobals(fid);
1346   return ret.retn();
1347 }
1348
1349 /*!
1350  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
1351  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
1352  *
1353  * \warning this is a shallow copy constructor
1354  */
1355 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
1356 {
1357   if(!shallowCopyOfContent)
1358     {
1359       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
1360       otherPtr->incrRef();
1361       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
1362     }
1363   else
1364     {
1365       _content=other.shallowCpy();
1366     }
1367 }
1368
1369 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
1370 {
1371   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
1372   if(!ret)
1373     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
1374   return ret;
1375 }
1376
1377 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
1378 {
1379   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
1380   if(!ret)
1381     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
1382   return ret;
1383 }
1384
1385 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
1386 {
1387   return contentNotNullBase()->getPflsReallyUsed2();
1388 }
1389
1390 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
1391 {
1392   return contentNotNullBase()->getLocsReallyUsed2();
1393 }
1394
1395 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
1396 {
1397   return contentNotNullBase()->getPflsReallyUsedMulti2();
1398 }
1399
1400 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
1401 {
1402   return contentNotNullBase()->getLocsReallyUsedMulti2();
1403 }
1404
1405 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1406 {
1407   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
1408 }
1409
1410 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1411 {
1412   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
1413 }
1414
1415 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
1416 {
1417   return contentNotNullBase()->getNumberOfTS();
1418 }
1419
1420 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
1421 {
1422   contentNotNullBase()->eraseEmptyTS();
1423 }
1424
1425 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
1426 {
1427   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
1428 }
1429
1430 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
1431 {
1432   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
1433 }
1434
1435 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
1436 {
1437   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
1438   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
1439   ret->_content=c;
1440   return ret.retn();
1441 }
1442
1443 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
1444 {
1445   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
1446   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
1447   ret->_content=c;
1448   return ret.retn();
1449 }
1450
1451 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
1452 {
1453   return contentNotNullBase()->getIterations();
1454 }
1455
1456 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
1457 {
1458   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
1459     pushBackTimeStep(*it);
1460 }
1461
1462 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
1463 {
1464   if(!fmts)
1465     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
1466   int nbOfTS(fmts->getNumberOfTS());
1467   for(int i=0;i<nbOfTS;i++)
1468     {
1469       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
1470       pushBackTimeStep(elt);
1471     }
1472 }
1473
1474 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
1475 {
1476   if(!f1ts)
1477     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
1478   checkCoherencyOfType(f1ts);
1479   f1ts->incrRef();
1480   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
1481   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
1482   c->incrRef();
1483   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
1484   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
1485     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
1486   _content->pushBackTimeStep(cSafe);
1487   appendGlobs(*f1ts,1e-12);
1488 }
1489
1490 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
1491 {
1492   contentNotNullBase()->synchronizeNameScope();
1493 }
1494
1495 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
1496 {
1497   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
1498 }
1499
1500 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
1501 {
1502   return contentNotNullBase()->getPosGivenTime(time,eps);
1503 }
1504
1505 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
1506 {
1507   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
1508 }
1509
1510 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
1511 {
1512   return contentNotNullBase()->getTypesOfFieldAvailable();
1513 }
1514
1515 std::vector< std::vector< std::pair<mcIdType,mcIdType> > > MEDFileAnyTypeFieldMultiTS::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
1516 {
1517   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
1518 }
1519
1520 std::string MEDFileAnyTypeFieldMultiTS::getName() const
1521 {
1522   return contentNotNullBase()->getName();
1523 }
1524
1525 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
1526 {
1527   contentNotNullBase()->setName(name);
1528 }
1529
1530 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
1531 {
1532   return contentNotNullBase()->getDtUnit();
1533 }
1534
1535 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
1536 {
1537   contentNotNullBase()->setDtUnit(dtUnit);
1538 }
1539
1540 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
1541 {
1542   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
1543 }
1544
1545 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
1546 {
1547   return contentNotNullBase()->getTimeSteps(ret1);
1548 }
1549
1550 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
1551 {
1552   return contentNotNullBase()->getMeshName();
1553 }
1554
1555 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
1556 {
1557   contentNotNullBase()->setMeshName(newMeshName);
1558 }
1559
1560 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1561 {
1562   return contentNotNullBase()->changeMeshNames(modifTab);
1563 }
1564
1565 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
1566 {
1567   return contentNotNullBase()->getInfo();
1568 }
1569
1570 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
1571 {
1572   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
1573 }
1574
1575 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
1576 {
1577   return contentNotNullBase()->setInfo(info);
1578 }
1579
1580 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
1581 {
1582   const std::vector<std::string> ret=getInfo();
1583   return (int)ret.size();
1584 }
1585
1586 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
1587 {
1588   writeGlobals(fid,*this);
1589   contentNotNullBase()->writeLL(fid,*this);
1590 }
1591
1592 /*!
1593  * This method alloc the arrays and load potentially huge arrays contained in this field.
1594  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
1595  * This method can be also called to refresh or reinit values from a file.
1596  * 
1597  * \throw If the fileName is not set or points to a non readable MED file.
1598  */
1599 void MEDFileAnyTypeFieldMultiTS::loadArrays()
1600 {
1601   if(getFileName().empty())
1602     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
1603   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
1604   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
1605 }
1606
1607 /*!
1608  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
1609  * But once data loaded once, this method does nothing.
1610  * 
1611  * \throw If the fileName is not set or points to a non readable MED file.
1612  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
1613  */
1614 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
1615 {
1616   if(!getFileName().empty())
1617     {
1618       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
1619       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
1620     }
1621 }
1622
1623 /*!
1624  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
1625  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
1626  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
1627  * 
1628  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
1629  */
1630 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
1631 {
1632   contentNotNullBase()->unloadArrays();
1633 }
1634
1635 /*!
1636  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
1637  * This method is the symmetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
1638  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
1639  * 
1640  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
1641  */
1642 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
1643 {
1644   if(!getFileName().empty())
1645     contentNotNullBase()->unloadArrays();
1646 }
1647
1648 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
1649 {
1650   std::ostringstream oss;
1651   contentNotNullBase()->simpleRepr(0,oss,-1);
1652   simpleReprGlobs(oss);
1653   return oss.str();
1654 }
1655
1656 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
1657 {
1658   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
1659 }
1660
1661 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
1662 {
1663   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
1664   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
1665   return ret;
1666 }
1667
1668 /*!
1669  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
1670  * The returned instances are deep copy of \a this except that for globals that are shared with those contained in \a this.
1671  * ** WARNING ** do no forget to rename the output instances to avoid to write n-times in the same MED file field !
1672  */
1673 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
1674 {
1675   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
1676   if(!content)
1677     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
1678   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
1679   std::size_t sz(contentsSplit.size());
1680   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
1681   for(std::size_t i=0;i<sz;i++)
1682     {
1683       ret[i]=shallowCpy();
1684       ret[i]->_content=contentsSplit[i];
1685     }
1686   return ret;
1687 }
1688
1689 /*!
1690  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
1691  * The returned instances are shallow copied of \a this included globals that are shared with those contained in \a this.
1692  */
1693 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
1694 {
1695   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
1696   if(!content)
1697     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
1698   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
1699   std::size_t sz(contentsSplit.size());
1700   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
1701   for(std::size_t i=0;i<sz;i++)
1702     {
1703       ret[i]=shallowCpy();
1704       ret[i]->_content=contentsSplit[i];
1705     }
1706   return ret;
1707 }
1708
1709 /*!
1710  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
1711  * The returned instances are shallow copied of \a this included globals that are shared with those contained in \a this.
1712  */
1713 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
1714 {
1715   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
1716   if(!content)
1717     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
1718   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
1719   std::size_t sz(contentsSplit.size());
1720   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
1721   for(std::size_t i=0;i<sz;i++)
1722     {
1723       ret[i]=shallowCpy();
1724       ret[i]->_content=contentsSplit[i];
1725     }
1726   return ret;
1727 }
1728
1729 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
1730 {
1731   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
1732   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
1733     ret->_content=_content->deepCopy();
1734   ret->deepCpyGlobs(*this);
1735   return ret.retn();
1736 }
1737
1738 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
1739 {
1740   return _content;
1741 }
1742
1743 /*!
1744  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
1745  *  \param [in] iteration - the iteration number of a required time step.
1746  *  \param [in] order - the iteration order number of required time step.
1747  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
1748  *          delete this field using decrRef() as it is no more needed.
1749  *  \throw If there is no required time step in \a this field.
1750  */
1751 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
1752 {
1753   int pos=getPosOfTimeStep(iteration,order);
1754   return getTimeStepAtPos(pos);
1755 }
1756
1757 /*!
1758  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
1759  *  \param [in] time - the time of the time step of interest.
1760  *  \param [in] eps - a precision used to compare time values.
1761  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1762  *          delete this field using decrRef() as it is no more needed.
1763  *  \throw If there is no required time step in \a this field.
1764  */
1765 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
1766 {
1767   int pos=getPosGivenTime(time,eps);
1768   return getTimeStepAtPos(pos);
1769 }
1770
1771 /*!
1772  * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
1773  * The float64 value of time attached to the pair of integers are not considered here.
1774  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
1775  *
1776  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
1777  * \throw If there is a null pointer in \a vectFMTS.
1778  */
1779 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
1780 {
1781   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
1782   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
1783   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
1784   while(!lstFMTS.empty())
1785     {
1786       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
1787       MEDFileAnyTypeFieldMultiTS *curIt(*it);
1788       if(!curIt)
1789         throw INTERP_KERNEL::Exception(msg);
1790       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
1791       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
1792       elt.push_back(curIt); it=lstFMTS.erase(it);
1793       while(it!=lstFMTS.end())
1794         {
1795           curIt=*it;
1796           if(!curIt)
1797             throw INTERP_KERNEL::Exception(msg);
1798           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
1799           if(refIts==curIts)
1800             { elt.push_back(curIt); it=lstFMTS.erase(it); }
1801           else
1802             it++;
1803         }
1804       ret.push_back(elt);
1805     }
1806   return ret;
1807 }
1808
1809 /*!
1810  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
1811  * All returned instances in a subvector can be safely loaded, rendered along time
1812  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
1813  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
1814  * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items).
1815  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
1816  * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector.
1817  *
1818  * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName().
1819  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
1820  * \param [out] fsc - A vector having same size than returned vector. It specifies the support comporator of the corresponding vector of MEDFileAnyTypeFieldMultiTS in returned vector of vector.
1821  * \return - A vector of vector of objects that contains the same pointers (objects) than thoose in \a vectFMTS except that there are organized differently. So pointers included in returned vector of vector should \b not been dealt by the caller.
1822  *
1823  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
1824  * \throw If an element in \a vectFMTS change of spatial discretization along time.
1825  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
1826  * \thorw If some elements in \a vectFMTS do not have the same times steps.
1827  * \throw If mesh is null.
1828  * \throw If an element in \a vectFMTS is null.
1829  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
1830  */
1831 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
1832 {
1833   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
1834   if(!mesh)
1835     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
1836   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
1837   if(vectFMTS.empty())
1838     return ret;
1839   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
1840   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
1841   if(!frstElt)
1842     throw INTERP_KERNEL::Exception(msg);
1843   std::size_t i=0;
1844   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
1845   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
1846   for(;it!=vectFMTS.end();it++,i++)
1847     {
1848       if(!(*it))
1849         throw INTERP_KERNEL::Exception(msg);
1850       TypeOfField tof0,tof1;
1851       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
1852         {
1853           if(tof1!=ON_NODES)
1854             vectFMTSNotNodes.push_back(*it);
1855           else
1856             vectFMTSNodes.push_back(*it);
1857         }
1858       else
1859         vectFMTSNotNodes.push_back(*it);
1860     }
1861   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
1862   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
1863   ret=retCell;
1864   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
1865     {
1866       i=0;
1867       bool isFetched(false);
1868       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
1869         {
1870           if((*it0).empty())
1871             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
1872           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
1873             { ret[i].push_back(*it2); isFetched=true; }
1874         }
1875       if(!isFetched)
1876         {
1877           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
1878           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
1879           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
1880         }
1881     }
1882   fsc=cmps;
1883   return ret;
1884 }
1885
1886 /*!
1887  * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES.
1888  * \param [out] cmps - same size than the returned vector.
1889  */
1890 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
1891 {
1892   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
1893   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
1894   while(!lstFMTS.empty())
1895     {
1896       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
1897       MEDFileAnyTypeFieldMultiTS *ref(*it);
1898       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
1899       elt.push_back(ref); it=lstFMTS.erase(it);
1900       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
1901       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
1902       while(it!=lstFMTS.end())
1903         {
1904           MEDFileAnyTypeFieldMultiTS *curIt(*it);
1905           if(cmp->isEqual(curIt))
1906             { elt.push_back(curIt); it=lstFMTS.erase(it); }
1907           else
1908             it++;
1909         }
1910       ret.push_back(elt); cmps.push_back(cmp);
1911     }
1912   return ret;
1913 }
1914
1915 /*!
1916  * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh.
1917  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
1918  *
1919  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
1920  * \throw If \a f0 or \a f1 change of spatial discretization along time.
1921  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
1922  * \thorw If \a f0 and \a f1 do not have the same times steps.
1923  * \throw If mesh is null.
1924  * \throw If \a f0 or \a f1 is null.
1925  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
1926  */
1927 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
1928 {
1929   if(!mesh)
1930     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
1931   if(!f0 || !f1)
1932     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
1933   if(f0->getMeshName()!=mesh->getName())
1934     {
1935       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
1936       throw INTERP_KERNEL::Exception(oss.str());
1937     }
1938   if(f1->getMeshName()!=mesh->getName())
1939     {
1940       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
1941       throw INTERP_KERNEL::Exception(oss.str());
1942     }
1943   int nts=f0->getNumberOfTS();
1944   if(nts!=f1->getNumberOfTS())
1945     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
1946   if(nts==0)
1947     return nts;
1948   for(int i=0;i<nts;i++)
1949     {
1950       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
1951       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
1952       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
1953       if(tofs0.size()!=1 || tofs1.size()!=1)
1954         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
1955       if(i!=0)
1956         {
1957           if(tof0!=tofs0[0] || tof1!=tofs1[0])
1958             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
1959         }
1960       else
1961         { tof0=tofs0[0]; tof1=tofs1[0]; }
1962       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
1963         {
1964           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
1965           throw INTERP_KERNEL::Exception(oss.str());
1966         }
1967       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
1968         {
1969           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
1970           throw INTERP_KERNEL::Exception(oss.str());
1971         }
1972       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
1973         {
1974           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !";
1975           throw INTERP_KERNEL::Exception(oss.str());
1976         }
1977     }
1978   return nts;
1979 }
1980
1981 template<class T>
1982 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts)
1983 {
1984   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
1985   if(f1tss.empty())
1986     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
1987   std::size_t sz(f1tss.size()),i(0);
1988   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
1989   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
1990     {
1991       typename MLFieldTraits<T>::F1TSType const *elt(*it);
1992       if(!elt)
1993         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
1994       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
1995     }
1996   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
1997   if(!retc)
1998     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
1999   retc->aggregate(f1tsw,dts);
2000   ret->setDtUnit(f1tss[0]->getDtUnit());
2001   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
2002 }
2003
2004 template<class T>
2005 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts)
2006 {
2007   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
2008   if(fmtss.empty())
2009     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
2010   std::size_t sz(fmtss.size());
2011   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
2012     {
2013       typename MLFieldTraits<T>::FMTSType const *elt(*it);
2014       if(!elt)
2015         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
2016     }
2017   int nbTS(fmtss[0]->getNumberOfTS());
2018   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
2019     if((*it)->getNumberOfTS()!=nbTS)
2020       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
2021   for(int iterTS=0;iterTS<nbTS;iterTS++)
2022     {
2023       std::size_t i(0);
2024       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
2025       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
2026       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
2027         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
2028       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
2029       ret->pushBackTimeStep(f1ts);
2030       ret->setDtUnit(f1ts->getDtUnit());
2031     }
2032   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
2033 }
2034
2035 /*!
2036  * \a dts and \a ftmss are expected to have same size.
2037  */
2038 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts)
2039 {
2040   if(fmtss.empty())
2041     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
2042   std::size_t sz(fmtss.size());
2043   std::vector<const MEDFileFieldMultiTS *> fmtss1;
2044   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
2045   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
2046     {
2047       if(!(*it))
2048         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
2049       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
2050       if(elt1)
2051         {
2052           fmtss1.push_back(elt1);
2053           continue;
2054         }
2055       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
2056       if(elt2)
2057         {
2058           fmtss2.push_back(elt2);
2059           continue;
2060         }
2061       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
2062     }
2063   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
2064     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
2065   if(fmtss1.size()==sz)
2066     return AggregateHelperFMTS<double>(fmtss1,dts);
2067   if(fmtss2.size()!=sz)
2068     return AggregateHelperFMTS<int>(fmtss2,dts);
2069   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
2070 }
2071
2072 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
2073 {
2074   return new MEDFileAnyTypeFieldMultiTSIterator(this);
2075 }
2076
2077 //= MEDFileFieldMultiTS
2078
2079 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
2080 {
2081   return new MEDFileFieldMultiTS(*this);
2082 }
2083
2084 /*!
2085  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
2086  * following the given input policy.
2087  *
2088  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
2089  *                            By default (true) the globals are deeply copied.
2090  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
2091  */
2092 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
2093 {
2094   MCAuto<MEDFileIntFieldMultiTS> ret;
2095   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
2096   if(content)
2097     {
2098       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
2099       if(!contc)
2100         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
2101       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
2102       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
2103     }
2104   else
2105     ret=MEDFileIntFieldMultiTS::New();
2106   if(isDeepCpyGlobs)
2107     ret->deepCpyGlobs(*this);
2108   else
2109     ret->shallowCpyGlobs(*this);
2110   return ret.retn();
2111 }
2112
2113 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
2114 try:MEDFileTemplateFieldMultiTS<double>(fid,loadAll,ms)
2115 {
2116 }
2117 catch(INTERP_KERNEL::Exception& e)
2118 { throw e; }
2119
2120 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
2121 try:MEDFileTemplateFieldMultiTS<double>(fid,fieldName,loadAll,ms,entities)
2122 {
2123 }
2124 catch(INTERP_KERNEL::Exception& e)
2125 { throw e; }
2126
2127 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<double>(other,shallowCopyOfContent)
2128 {
2129 }
2130
2131 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
2132 {
2133   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
2134 }
2135
2136 //= MEDFileAnyTypeFieldMultiTSIterator
2137
2138 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
2139 {
2140   if(fmts)
2141     {
2142       fmts->incrRef();
2143       _nb_iter=fmts->getNumberOfTS();
2144     }
2145 }
2146
2147 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
2148 {
2149 }
2150
2151 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
2152 {
2153   if(_iter_id<_nb_iter)
2154     {
2155       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
2156       if(fmts)
2157         return fmts->getTimeStepAtPos(_iter_id++);
2158       else
2159         return 0;
2160     }
2161   else
2162     return 0;
2163 }
2164
2165 //= MEDFileIntFieldMultiTS