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