Salome HOME
c78b010f9c762693adbeec4c2ebd90321bb10328
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.txx
1 // Copyright (C) 2007-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 #ifndef __MEDFILEFIELD_TXX__
22 #define __MEDFILEFIELD_TXX__
23
24 #include "MEDFileField.hxx"
25 #include "MEDCouplingTraits.hxx"
26 #include "MEDCouplingFieldInt.hxx"
27 #include "MEDCouplingFieldFloat.hxx"
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldTemplate.hxx"
30
31 namespace MEDCoupling
32 {
33   template<class T>
34   void MEDFileField1TSTemplateWithoutSDA<T>::setArray(DataArray *arr)
35   {
36     if(!arr)
37       {
38         _nb_of_tuples_to_be_allocated=-1;
39         _arr=0;
40         return ;
41       }
42     typename Traits<T>::ArrayType *arrC=dynamic_cast<typename Traits<T>::ArrayType *>(arr);
43     if(!arrC)
44       throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
45     else
46       _nb_of_tuples_to_be_allocated=-3;
47     arrC->incrRef();
48     _arr=arrC;
49   }
50   
51   /*!
52    * Returns a pointer to the underground DataArrayTemplate<T>  instance. So the
53    * caller should not decrRef() it. This method allows for a direct access to the field
54    * values. This method is quite unusable if there is more than a nodal field or a cell
55    * field on single geometric cell type. 
56    *  \return DataArrayTemplate<T> * - the pointer to the field values array.
57    */
58   template<class T>
59   DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray()
60   {
61     return getOrCreateAndGetArrayTemplate();
62   }
63   
64   template<class T>
65   const DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray() const
66   {
67     return getOrCreateAndGetArrayTemplate();
68   }
69   
70   template<class T>
71   DataArray *MEDFileField1TSTemplateWithoutSDA<T>::createNewEmptyDataArrayInstance() const
72   {
73     return Traits<T>::ArrayType::New();
74   }
75   
76   template<class T>
77   typename Traits<T>::ArrayType const *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate() const
78   {
79     typename Traits<T>::ArrayType const *ret(_arr);
80     if(ret)
81       return ret;
82     (const_cast< MEDFileField1TSTemplateWithoutSDA<T> *>(this))->_arr=Traits<T>::ArrayType::New();
83     return _arr;
84   }
85   
86   template<class T>
87   typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate()
88   {
89     typename Traits<T>::ArrayType *ret(_arr);
90     if(ret)
91       return ret;
92     _arr=Traits<T>::ArrayType::New();
93     return _arr;
94   }
95
96   /*!
97    * Returns a pointer to the underground DataArrayTemplate<T> instance. So the
98    * caller should not decrRef() it. This method allows for a direct access to the field
99    * values. This method is quite unusable if there is more than a nodal field or a cell
100    * field on single geometric cell type. 
101    *  \return DataArrayTemplate<T> * - the pointer to the field values array.
102    */
103   template<class T>
104   typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplate() const
105   {
106     typename Traits<T>::ArrayType const *ret(_arr);
107     if(ret)
108       return const_cast<typename Traits<T>::ArrayType *>(ret);
109     else
110       return 0;
111   }
112   
113   /*!
114    * Returns a pointer to the underground DataArrayDouble instance and a
115    * sequence describing parameters of a support of each part of \a this field. The
116    * caller should not decrRef() the returned DataArrayDouble. This method allows for a
117    * direct access to the field values. This method is intended for the field lying on one
118    * mesh only.
119    *  \param [in,out] entries - the sequence describing parameters of a support of each
120    *         part of \a this field. Each item of this sequence consists of two parts. The
121    *         first part describes a type of mesh entity and an id of discretization of a
122    *         current field part. The second part describes a range of values [begin,end)
123    *         within the returned array relating to the current field part.
124    *  \return DataArrayDouble * - the pointer to the field values array.
125    *  \throw If the number of underlying meshes is not equal to 1.
126    *  \throw If no field values are available.
127    *  \sa getUndergroundDataArrayTemplate()
128    */
129   template<class T>
130   typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplateExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
131   {
132     if(this->_field_per_mesh.size()!=1)
133       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
134     if(this->_field_per_mesh[0]==0)
135       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
136     this->_field_per_mesh[0]->getUndergroundDataArrayExt(entries);
137     return getUndergroundDataArrayTemplate();
138   }
139   
140   /*!
141    * Returns a pointer to the underground DataArrayDouble instance. So the
142    * caller should not decrRef() it. This method allows for a direct access to the field
143    * values. This method is quite unusable if there is more than a nodal field or a cell
144    * field on single geometric cell type. 
145    *  \return DataArrayDouble * - the pointer to the field values array.
146    */
147   template<class T>
148   DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArray() const
149   {
150     return getUndergroundDataArrayTemplate();
151   }
152   
153   template<class T>
154   void MEDFileField1TSTemplateWithoutSDA<T>::aggregate(const std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>& f1tss, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts)
155   {
156     if(f1tss.empty())
157       throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : empty vector !");
158     std::size_t sz(f1tss.size()),ii(0);
159     std::vector<const MEDFileFieldPerMesh *> pms;
160     std::vector<const DataArray *> das(sz);
161     for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,ii++)
162       {
163         if(!*it)
164           throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null pointer in input vector !");
165         if((*it)->_field_per_mesh.empty())
166           throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : no info !");
167         const typename Traits<T>::ArrayType *arr((*it)->getUndergroundDataArrayTemplate());
168         if(!arr)
169           throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null array !");
170         das[ii]=arr;
171         pms.push_back((*it)->_field_per_mesh[0]);
172       }
173     typename MLFieldTraits<T>::F1TSWSDAType const *refPt(f1tss[0]);
174     setName(refPt->getName());
175     
176     const DataArray *arr(refPt->getUndergroundDataArray());
177     std::size_t nbCompo(arr->getNumberOfComponents());
178     for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++)
179       {
180         const typename Traits<T>::ArrayType *myArr((*it)->getUndergroundDataArrayTemplate());
181         if(myArr->getNumberOfComponents()!=nbCompo)
182           throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : arrays must have same number of components !");
183       }
184     std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > > extractInfo;
185     mcIdType start(0);
186     MCAuto<MEDFileFieldPerMesh> fpm(MEDFileFieldPerMesh::Aggregate(start,pms,dts,this,extractInfo));
187     _field_per_mesh.push_back(fpm);
188     int iteration,order;
189     double tv(f1tss[0]->getTime(iteration,order));
190     _iteration=iteration; _order=order; _dt=tv;
191     _arr=Traits<T>::ArrayType::New();
192     _arr->alloc(start,nbCompo); _arr->copyStringInfoFrom(*arr);
193     start=0;
194     for(std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > >::const_iterator it=extractInfo.begin();it!=extractInfo.end();it++)
195       {
196         const DataArray *zeArr(das[(*it).first]);
197         _arr->setContigPartOfSelectedValuesSlice(start,zeArr,(*it).second.first,(*it).second.second,1);
198         start+=(*it).second.second-(*it).second.first;
199       }
200   }
201
202   template<class T>
203   void MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
204   {
205     if(!mcf)
206       throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom : input field is nullptr !");
207     int b(0),c(0);
208     double a(mcf->getTime(b,c));
209     setTime(b,c,a);
210   }
211
212   ///////////////////////////////////////////////////////
213
214   template<class T>
215   MEDFileField1TSWithoutSDA *MEDFileField1TSNDTemplateWithoutSDA<T>::convertToDouble() const
216   {
217     MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
218     ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
219     ret->deepCpyLeavesFrom(*this);
220     if(this->_arr.isNotNull())
221       {
222         MCAuto<DataArrayDouble> arr2(this->_arr->convertToDblArr());
223         ret->setArray(arr2);
224       }
225     return ret.retn();
226   }
227   
228   ///////////////////////////////////////////////////////
229
230   template<class T>
231   MEDFileTemplateField1TS<T>::MEDFileTemplateField1TS()
232   {
233     _content=new typename MLFieldTraits<T>::F1TSWSDAType;
234   }
235
236   /*!
237    * Returns a new empty instance of MEDFileField1TS.
238    *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
239    *          is to delete this field using decrRef() as it is no more needed.
240    */
241   template<class T>
242   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New()
243   {
244     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType);
245     ret->contentNotNull();
246     return ret.retn();
247   }
248
249   /*!
250    * Returns a new instance of MEDFileField1TS holding data of the first time step of 
251    * the first field that has been read from a specified MED file.
252    *  \param [in] fileName - the name of the MED file to read.
253    *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
254    *          is to delete this field using decrRef() as it is no more needed.
255    *  \throw If reading the file fails.
256    */
257   template<class T>
258   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, bool loadAll)
259   {
260     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
261     return New(fid,loadAll);
262   }
263   
264   template<class T>
265   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, bool loadAll)
266   {
267     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,loadAll,0));
268     ret->contentNotNull();
269     return ret.retn();
270   }
271
272   /*!
273    * Returns a new instance of MEDFileField1TS holding data of the first time step of 
274    * a given field that has been read from a specified MED file.
275    *  \param [in] fileName - the name of the MED file to read.
276    *  \param [in] fieldName - the name of the field to read.
277    *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
278    *          is to delete this field using decrRef() as it is no more needed.
279    *  \throw If reading the file fails.
280    *  \throw If there is no field named \a fieldName in the file.
281    */
282   template<class T>
283   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
284   {
285     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
286     return New(fid,fieldName,loadAll);
287   }
288
289   template<class T>
290   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
291   {
292     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,loadAll,0));
293     ret->contentNotNull();
294     return ret.retn();
295   }
296
297   /*!
298    * Returns a new instance of MEDFileField1TS holding data of a given time step of 
299    * a given field that has been read from a specified MED file.
300    *  \param [in] fileName - the name of the MED file to read.
301    *  \param [in] fieldName - the name of the field to read.
302    *  \param [in] iteration - the iteration number of a required time step.
303    *  \param [in] order - the iteration order number of required time step.
304    *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
305    *          is to delete this field using decrRef() as it is no more needed.
306    *  \throw If reading the file fails.
307    *  \throw If there is no field named \a fieldName in the file.
308    *  \throw If the required time step is missing from the file.
309    */
310   template<class T>
311   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
312   {
313     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
314     return New(fid,fieldName,iteration,order,loadAll);
315   }
316   
317   template<class T>
318   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
319   {
320     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,iteration,order,loadAll,0));
321     ret->contentNotNull();
322     return ret.retn();
323   }
324
325   /*!
326    * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
327    * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
328    *
329    * Returns a new instance of MEDFileField1TS holding either a shallow copy
330    * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
331    * \warning this is a shallow copy constructor
332    *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
333    *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
334    *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
335    *          is to delete this field using decrRef() as it is no more needed.
336    */
337   template<class T>
338   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent)
339   {
340     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(other,shallowCopyOfContent));
341     ret->contentNotNull();
342     return ret.retn();
343   }
344   
345   template<class T>
346   const typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull() const
347   {
348     const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
349     if(!pt)
350       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is null !");
351     const typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
352     if(!ret)
353       {
354         std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
355         throw INTERP_KERNEL::Exception(oss.str());
356       }
357     return ret;
358   }
359   
360   template<class T>
361   typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull()
362   {
363     MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
364     if(!pt)
365       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is null !");
366     typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
367     if(!ret)
368       {
369         std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
370         throw INTERP_KERNEL::Exception(oss.str());
371       }
372     return ret;
373   }
374   
375   template<class T>
376   typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr)
377   {
378     if(arr.isNull())
379       throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : no array !");
380     typename Traits<T>::ArrayType *arrOutC(dynamic_cast<typename Traits<T>::ArrayType *>((DataArray*)arr));
381     if(!arrOutC)
382       throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
383     arrOutC->incrRef();
384     return arrOutC;
385   }
386
387   /*!
388    * Returns values and a profile of the field of a given type lying on a given support.
389    * For more info, see \ref AdvMEDLoaderAPIFieldRW
390    *  \param [in] type - a spatial discretization of the field.
391    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
392    *  \param [in] mesh - the supporting mesh.
393    *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
394    *          field of interest lies on. If the field lies on all entities of the given
395    *          dimension, all ids in \a pfl are zero. The caller is to delete this array
396    *          using decrRef() as it is no more needed.  
397    *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
398    *          field. The caller is to delete this array using decrRef() as it is no more needed.
399    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
400    *  \throw If no field of \a this is lying on \a mesh.
401    *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
402    */
403   template<class T>
404   typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
405   {
406     MCAuto<DataArray> arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull()));
407     return ReturnSafelyTypedDataArray(arr);
408   }
409
410   template<class T>
411   void MEDFileTemplateField1TS<T>::setArray(DataArray *arr)
412   {
413     return contentNotNull()->setArray(arr);
414   }
415
416   template<class T>
417   typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArray() const
418   {
419     return contentNotNull()->getUndergroundDataArrayTemplate();
420   }
421   
422   template<class T>
423   typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
424   {
425     return contentNotNull()->getUndergroundDataArrayTemplateExt(entries);
426   }
427
428   template<class T>
429   MCAuto<typename Traits<T>::FieldType> MEDFileTemplateField1TS<T>::SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
430   {
431     if(!f)
432       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : input field is NULL !");
433     if(arr.isNull())
434       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : no array !");
435     int t1,t2;
436     double t0(f->getTime(t1,t2));
437     std::string tu(f->getTimeUnit());
438     MCAuto<typename Traits<T>::ArrayType> arr2(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(arr));
439     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
440     MCAuto<typename Traits<T>::FieldType> ret(Traits<T>::FieldType::New(*ft));
441     ret->setTime(t0,t1,t2); ret->setArray(arr2); ret->setTimeUnit(tu);
442     return ret.retn();
443   }
444
445   template<class T>
446   MCAuto<MEDCouplingFieldDouble> MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f)
447   {
448     int t1,t2;
449     double t0(f->getTime(t1,t2));
450     std::string tu(f->getTimeUnit());
451     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*f));
452     MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
453     ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
454     return ret.retn();
455   }
456
457   template<class T>
458   void MEDFileTemplateField1TS<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
459   {
460     contentNotNull()->copyTimeInfoFrom(mcf);
461   }
462
463   /*!
464    * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
465    * method should be called (getFieldOnMeshAtLevel for example).
466    * But for normal usage of field in MED file world this method is the most efficient to fetch data.
467    *
468    * \param [in] mesh - the mesh the field is lying on
469    * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
470    *          caller is to delete this field using decrRef() as it is no more needed. 
471    */
472   template<class T>
473   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::field(const MEDFileMesh *mesh) const
474   {
475     MCAuto<DataArray> arrOut;
476     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
477     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
478     return ret2.retn();
479   }
480
481   /*!
482    * Returns a new typename Traits<T>::FieldType of a given type lying on
483    * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
484    * has not been constructed via file reading, an exception is thrown.
485    * For more info, see \ref AdvMEDLoaderAPIFieldRW
486    *  \param [in] type - a spatial discretization of interest.
487    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
488    *  \param [in] renumPol - specifies how to permute values of the result field according to
489    *          the optional numbers of cells and nodes, if any. The valid values are
490    *          - 0 - do not permute.
491    *          - 1 - permute cells.
492    *          - 2 - permute nodes.
493    *          - 3 - permute cells and nodes.
494    *
495    *  \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
496    *          caller is to delete this field using decrRef() as it is no more needed. 
497    *  \throw If \a this field has not been constructed via file reading.
498    *  \throw If the MED file is not readable.
499    *  \throw If there is no mesh in the MED file.
500    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
501    *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
502    *  \sa getFieldOnMeshAtLevel()
503    */
504   template<class T>
505   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
506   {
507     if(getFileName().empty())
508       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
509     MCAuto<DataArray> arrOut;
510     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
511     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
512     return ret2.retn();
513   }
514
515   /*!
516    * Returns a new typename Traits<T>::FieldType of a given type lying on
517    * the top level cells of the first mesh in MED file. If \a this field 
518    * has not been constructed via file reading, an exception is thrown.
519    * For more info, see \ref AdvMEDLoaderAPIFieldRW
520    *  \param [in] type - a spatial discretization of interest.
521    *  \param [in] renumPol - specifies how to permute values of the result field according to
522    *          the optional numbers of cells and nodes, if any. The valid values are
523    *          - 0 - do not permute.
524    *          - 1 - permute cells.
525    *          - 2 - permute nodes.
526    *          - 3 - permute cells and nodes.
527    *
528    *  \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
529    *          caller is to delete this field using decrRef() as it is no more needed. 
530    *  \throw If \a this field has not been constructed via file reading.
531    *  \throw If the MED file is not readable.
532    *  \throw If there is no mesh in the MED file.
533    *  \throw If no field values of the given \a type.
534    *  \throw If no field values lying on the top level support.
535    *  \sa getFieldAtLevel()
536    */
537   template<class T>
538   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtTopLevel(TypeOfField type, int renumPol) const
539   {
540     if(getFileName().empty())
541       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
542     MCAuto<DataArray> arrOut;
543     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
544     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
545     return ret2.retn();
546   }
547
548   /*!
549    * Returns a new typename Traits<T>::FieldType of given type lying on a given mesh.
550    * For more info, see \ref AdvMEDLoaderAPIFieldRW
551    *  \param [in] type - a spatial discretization of the new field.
552    *  \param [in] mesh - the supporting mesh.
553    *  \param [in] renumPol - specifies how to permute values of the result field according to
554    *          the optional numbers of cells and nodes, if any. The valid values are
555    *          - 0 - do not permute.
556    *          - 1 - permute cells.
557    *          - 2 - permute nodes.
558    *          - 3 - permute cells and nodes.
559    *
560    *  \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
561    *          caller is to delete this field using decrRef() as it is no more needed. 
562    *  \throw If no field of \a this is lying on \a mesh.
563    *  \throw If the mesh is empty.
564    *  \throw If no field values of the given \a type are available.
565    *  \sa getFieldAtLevel()
566    *  \sa getFieldOnMeshAtLevel() 
567    */
568   template<class T>
569   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
570   {
571     MCAuto<DataArray> arrOut;
572     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
573     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
574     return ret2.retn();
575   }
576
577   /*!
578    * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
579    * For more info, see \ref AdvMEDLoaderAPIFieldRW
580    *  \param [in] type - a spatial discretization of interest.
581    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
582    *  \param [in] mesh - the supporting mesh.
583    *  \param [in] renumPol - specifies how to permute values of the result field according to
584    *          the optional numbers of cells and nodes, if any. The valid values are
585    *          - 0 - do not permute.
586    *          - 1 - permute cells.
587    *          - 2 - permute nodes.
588    *          - 3 - permute cells and nodes.
589    *
590    *  \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
591    *          caller is to delete this field using decrRef() as it is no more needed. 
592    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
593    *  \throw If no field of \a this is lying on \a mesh.
594    *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
595    *  \sa getFieldAtLevel()
596    *  \sa getFieldOnMeshAtLevel() 
597    */
598   template<class T>
599   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
600   {
601     MCAuto<DataArray> arrOut;
602     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
603     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
604     return ret2.retn();
605   }
606
607   /*!
608    * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
609    * This method is called "Old" because in MED3 norm a field has only one meshName
610    * attached, so this method is for readers of MED2 files. If \a this field 
611    * has not been constructed via file reading, an exception is thrown.
612    * For more info, see \ref AdvMEDLoaderAPIFieldRW
613    *  \param [in] type - a spatial discretization of interest.
614    *  \param [in] mName - a name of the supporting mesh.
615    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
616    *  \param [in] renumPol - specifies how to permute values of the result field according to
617    *          the optional numbers of cells and nodes, if any. The valid values are
618    *          - 0 - do not permute.
619    *          - 1 - permute cells.
620    *          - 2 - permute nodes.
621    *          - 3 - permute cells and nodes.
622    *
623    *  \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
624    *          caller is to delete this field using decrRef() as it is no more needed. 
625    *  \throw If the MED file is not readable.
626    *  \throw If there is no mesh named \a mName in the MED file.
627    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
628    *  \throw If \a this field has not been constructed via file reading.
629    *  \throw If no field of \a this is lying on the mesh named \a mName.
630    *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
631    *  \sa getFieldAtLevel()
632    */
633   template<class T>
634   typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
635   {
636     if(getFileName().empty())
637       throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
638     MCAuto<DataArray> arrOut;
639     MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
640     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
641     return ret2.retn();
642   }
643
644   /*!
645    * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
646    * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
647    * "Sort By Type"), if not, an exception is thrown. 
648    * For more info, see \ref AdvMEDLoaderAPIFieldRW
649    *  \param [in] field - the field to add to \a this.
650    *  \throw If the name of \a field is empty.
651    *  \throw If the data array of \a field is not set.
652    *  \throw If the data array is already allocated but has different number of components
653    *         than \a field.
654    *  \throw If the underlying mesh of \a field has no name.
655    *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
656    */
657   template<class T>
658   void MEDFileTemplateField1TS<T>::setFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
659   {
660     setFileName("");
661     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
662     contentNotNull()->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,field->getArray(),*this,*contentNotNull());
663   }
664
665   /*!
666    * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
667    * can be an aggregation of several MEDCouplingFieldDouble instances.
668    * The mesh support of input parameter \a field is ignored here, it can be NULL.
669    * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
670    * and \a profile.
671    *
672    * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
673    * A new profile is added only if no equal profile is missing.
674    * For more info, see \ref AdvMEDLoaderAPIFieldRW
675    *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
676    *  \param [in] mesh - the supporting mesh of \a field.
677    *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
678    *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
679    *  \throw If either \a field or \a mesh or \a profile has an empty name.
680    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
681    *  \throw If the data array of \a field is not set.
682    *  \throw If the data array of \a this is already allocated but has different number of
683    *         components than \a field.
684    *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
685    *  \sa setFieldNoProfileSBT, setFieldProfileFlatly
686    */
687   template<class T>
688   void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
689   {
690     setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
691   }
692
693   /*!
694    * Same as setFieldProfile except that here profile will be created unconditionally
695    * \sa setFieldProfile
696    */
697   template<class T>
698   void MEDFileTemplateField1TS<T>::setFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
699   {
700     setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
701   }
702
703   template<class T>
704   void MEDFileTemplateField1TS<T>::setFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
705   {
706     setFileName("");
707     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
708     contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull(),smartPflKiller);
709   }
710   
711   /*!
712    * Return an extraction of \a this using \a extractDef map to specify the extraction.
713    * The keys of \a extractDef is level relative to max ext of \a mm mesh.
714    *
715    * \return A new object that the caller is responsible to deallocate.
716    * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
717    */
718   template<class T>
719   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
720   {
721     if(!mm)
722       throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
723     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
724     std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
725     for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
726       {
727         if((*it0)!=ON_NODES)
728           {
729             std::vector<int> levs;
730             getNonEmptyLevels(mm->getName(),levs);
731             for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
732               {
733                 std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(*lev));
734                 if(it2!=extractDef.end())
735                   {
736                     MCAuto<DataArrayIdType> t((*it2).second);
737                     if(t.isNull())
738                       throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
739                     MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
740                     MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
741                     ret->setFieldNoProfileSBT(fOut);
742                   }
743               }
744           }
745         else
746           {
747             std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(1));
748             if(it2==extractDef.end())
749               throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
750             MCAuto<DataArrayIdType> t((*it2).second);
751             if(t.isNull())
752               throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
753             MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
754             MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
755             typename Traits<T>::ArrayType *arr(f->getArray());
756             MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
757             fOut->setArray(newArr);
758             ret->setFieldNoProfileSBT(fOut);
759           }
760       }
761     return ret.retn();
762   }
763
764   //////////////////////////
765
766   /*!
767    * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
768    * following the given input policy.
769    *
770    * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
771    *                            By default (true) the globals are deeply copied.
772    * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
773    */
774   template<class T>
775   MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
776   {
777     MCAuto<MEDFileField1TS> ret;
778     const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
779     if(content)
780       {
781         const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
782         if(!contc)
783           {
784             std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
785             throw INTERP_KERNEL::Exception(oss.str());
786           }
787         MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
788         ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
789       }
790     else
791       ret=MEDFileField1TS::New();
792     if(isDeepCpyGlobs)
793       ret->deepCpyGlobs(*this);
794     else
795       ret->shallowCpyGlobs(*this);
796     return ret.retn();
797   }
798
799   //////////////////////////
800
801   template<class T>
802   typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTSWithoutSDA<T>::New(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)
803   {
804     return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
805   }
806   
807   template<class T>
808   void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
809   {
810     if(!f1ts)
811       throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
812     const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
813     if(!f1tsC)
814       {
815         std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
816         throw INTERP_KERNEL::Exception(oss.str());
817       }
818   }
819   
820   template<class T>
821   const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
822   {
823     return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
824   }
825   
826   template<class T>
827   MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
828   {
829     return new typename MLFieldTraits<T>::FMTSWSDAType;
830   }
831   
832   template<class T>
833   MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
834   {
835     return new typename MLFieldTraits<T>::F1TSWSDAType;
836   }
837   
838   //////////////////////////
839
840   template<class T>
841   MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
842   {
843     MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
844     ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
845     int i=0;
846     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
847       {
848         const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
849         if(eltToConv)
850           {
851             const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
852             if(!eltToConvC)
853               throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
854           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
855           ret->setIteration(i,elt);
856           }
857       }
858     return ret.retn();
859   }
860   
861   //////////////////////////
862   
863   template<class T>
864   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
865   {
866     _content=new typename MLFieldTraits<T>::FMTSWSDAType;
867   }
868
869   template<class T>
870   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
871   {
872   }
873   
874   template<class T>
875   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
876   {
877   }
878   
879   template<class T>
880   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
881   {
882   }
883
884   /*!
885    * Return an extraction of \a this using \a extractDef map to specify the extraction.
886    * The keys of \a extractDef is level relative to max ext of \a mm mesh.
887    *
888    * \return A new object that the caller is responsible to deallocate.
889    */
890   template<class T>
891   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
892   {
893     if(!mm)
894       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
895     MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
896     int nbTS(getNumberOfTS());
897     for(int i=0;i<nbTS;i++)
898       {
899         MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
900         MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
901         MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
902         fmtsOut->pushBackTimeStep(f1tsOut);
903       }
904     return fmtsOut.retn();
905   }
906
907   /*!
908    * Returns a new empty instance of MEDFileFieldMultiTS.
909    *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
910    *          is to delete this field using decrRef() as it is no more needed.
911    */
912   template<class T>
913   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
914   {
915     return new typename MLFieldTraits<T>::FMTSType;
916   }
917
918   /*!
919    * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
920    * that has been read from a specified MED file.
921    *  \param [in] fileName - the name of the MED file to read.
922    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
923    *          is to delete this field using decrRef() as it is no more needed.
924    *  \throw If reading the file fails.
925    */
926   template<class T>
927   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
928   {
929     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
930     return New(fid,loadAll);
931   }
932
933   template<class T>
934   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
935   {
936     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
937     ret->contentNotNull();//to check that content type matches with \a this type.
938     return ret.retn();
939   }
940
941   /*!
942    * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
943    * that has been read from a specified MED file.
944    *  \param [in] fileName - the name of the MED file to read.
945    *  \param [in] fieldName - the name of the field to read.
946    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
947    *          is to delete this field using decrRef() as it is no more needed.
948    *  \throw If reading the file fails.
949    *  \throw If there is no field named \a fieldName in the file.
950    */
951   template<class T>
952   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
953   {
954     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
955     return New(fid,fieldName,loadAll);
956   }
957
958   template<class T>
959   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
960   {
961     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
962     ret->contentNotNull();//to check that content type matches with \a this type.
963     return ret.retn();
964   }
965
966   /*!
967    * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
968    * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
969    *
970    * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
971    * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
972    * \warning this is a shallow copy constructor
973    *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
974    *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
975    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
976    *          is to delete this field using decrRef() as it is no more needed.
977    */
978   template<class T>
979   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
980   {
981     return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
982   }
983
984   template<class T>
985   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
986   {
987     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
988     INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
989     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
990     ret->contentNotNull();//to check that content type matches with \a this type.
991     return ret.retn();
992   }
993
994   /*!
995    * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
996    * method should be called (getFieldOnMeshAtLevel for example).
997    * But for normal usage of field in MED file world this method is the most efficient to fetch data.
998    *
999    * \param [in] iteration - the iteration number of a required time step.
1000    * \param [in] order - the iteration order number of required time step.
1001    * \param [in] mesh - the mesh the field is lying on
1002    * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1003    *          caller is to delete this field using decrRef() as it is no more needed. 
1004    */
1005   template<class T>
1006   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
1007   {
1008     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1009     MCAuto<DataArray> arrOut;
1010     MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
1011     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1012     return ret2.retn();
1013   }
1014
1015   /*!
1016    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1017    * mesh entities of a given dimension of the first mesh in MED file.
1018    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1019    *  \param [in] type - a spatial discretization of interest.
1020    *  \param [in] iteration - the iteration number of a required time step.
1021    *  \param [in] order - the iteration order number of required time step.
1022    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1023    *  \param [in] renumPol - specifies how to permute values of the result field according to
1024    *          the optional numbers of cells and nodes, if any. The valid values are
1025    *          - 0 - do not permute.
1026    *          - 1 - permute cells.
1027    *          - 2 - permute nodes.
1028    *          - 3 - permute cells and nodes.
1029    *
1030    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1031    *          caller is to delete this field using decrRef() as it is no more needed. 
1032    *  \throw If the MED file is not readable.
1033    *  \throw If there is no mesh in the MED file.
1034    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1035    *  \throw If no field values of the required parameters are available.
1036    */
1037   template<class T>
1038   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1039   {
1040     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1041     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1042     if(!myF1TSC)
1043       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1044     MCAuto<DataArray> arrOut;
1045     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1046     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1047     return ret2.retn();
1048   }
1049
1050   /*!
1051    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1052    * the top level cells of the first mesh in MED file.
1053    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1054    *  \param [in] type - a spatial discretization of interest.
1055    *  \param [in] iteration - the iteration number of a required time step.
1056    *  \param [in] order - the iteration order number of required time step.
1057    *  \param [in] renumPol - specifies how to permute values of the result field according to
1058    *          the optional numbers of cells and nodes, if any. The valid values are
1059    *          - 0 - do not permute.
1060    *          - 1 - permute cells.
1061    *          - 2 - permute nodes.
1062    *          - 3 - permute cells and nodes.
1063    *
1064    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1065    *          caller is to delete this field using decrRef() as it is no more needed. 
1066    *  \throw If the MED file is not readable.
1067    *  \throw If there is no mesh in the MED file.
1068    *  \throw If no field values of the required parameters are available.
1069    */
1070   template<class T>
1071   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1072   {
1073     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1074     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1075     if(!myF1TSC)
1076       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1077     MCAuto<DataArray> arrOut;
1078     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1079     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1080     return ret2.retn();
1081   }
1082
1083   /*!
1084    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1085    * a given support.
1086    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1087    *  \param [in] type - a spatial discretization of interest.
1088    *  \param [in] iteration - the iteration number of a required time step.
1089    *  \param [in] order - the iteration order number of required time step.
1090    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1091    *  \param [in] mesh - the supporting mesh.
1092    *  \param [in] renumPol - specifies how to permute values of the result field according to
1093    *          the optional numbers of cells and nodes, if any. The valid values are
1094    *          - 0 - do not permute.
1095    *          - 1 - permute cells.
1096    *          - 2 - permute nodes.
1097    *          - 3 - permute cells and nodes.
1098    *
1099    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1100    *          caller is to delete this field using decrRef() as it is no more needed. 
1101    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1102    *  \throw If no field of \a this is lying on \a mesh.
1103    *  \throw If no field values of the required parameters are available.
1104    */
1105   template<class T>
1106   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1107   {
1108     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1109     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1110     if(!myF1TSC)
1111       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1112     MCAuto<DataArray> arrOut;
1113     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1114     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1115     return ret2.retn();
1116   }
1117
1118   /*!
1119    * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1120    * given support. 
1121    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1122    *  \param [in] type - a spatial discretization of the new field.
1123    *  \param [in] iteration - the iteration number of a required time step.
1124    *  \param [in] order - the iteration order number of required time step.
1125    *  \param [in] mesh - the supporting mesh.
1126    *  \param [in] renumPol - specifies how to permute values of the result field according to
1127    *          the optional numbers of cells and nodes, if any. The valid values are
1128    *          - 0 - do not permute.
1129    *          - 1 - permute cells.
1130    *          - 2 - permute nodes.
1131    *          - 3 - permute cells and nodes.
1132    *
1133    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1134    *          caller is to delete this field using decrRef() as it is no more needed. 
1135    *  \throw If no field of \a this is lying on \a mesh.
1136    *  \throw If no field values of the required parameters are available.
1137    */
1138   template<class T>
1139   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1140   {
1141     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1142     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1143     if(!myF1TSC)
1144       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1145     MCAuto<DataArray> arrOut;
1146     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1147     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1148     return ret2.retn();
1149   }
1150
1151   /*!
1152    * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1153    * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1154    * This method is useful for MED2 file format when field on different mesh was autorized.
1155    */
1156   template<class T>
1157   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
1158   {
1159     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1160     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1161     if(!myF1TSC)
1162       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
1163     MCAuto<DataArray> arrOut;
1164     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1165     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1166     return ret2.retn();
1167   }
1168
1169   /*!
1170    * Returns values and a profile of the field of a given type, of a given time step,
1171    * lying on a given support.
1172    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1173    *  \param [in] type - a spatial discretization of the field.
1174    *  \param [in] iteration - the iteration number of a required time step.
1175    *  \param [in] order - the iteration order number of required time step.
1176    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1177    *  \param [in] mesh - the supporting mesh.
1178    *  \param [out] pfl - a new instance of DataArrayIdType holding ids of mesh entities the
1179    *          field of interest lies on. If the field lies on all entities of the given
1180    *          dimension, all ids in \a pfl are zero. The caller is to delete this array
1181    *          using decrRef() as it is no more needed.  
1182    *  \param [in] glob - the global data storing profiles and localization.
1183    *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1184    *          field. The caller is to delete this array using decrRef() as it is no more needed.
1185    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1186    *  \throw If no field of \a this is lying on \a mesh.
1187    *  \throw If no field values of the required parameters are available.
1188    */
1189   template<class T>
1190   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
1191   {
1192     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1193     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1194     if(!myF1TSC)
1195       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1196     MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1197     return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1198   }
1199
1200   /*!
1201    * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1202    * the given field is checked if its elements are sorted suitable for writing to MED file
1203    * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
1204    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1205    *  \param [in] field - the field to add to \a this.
1206    *  \throw If the name of \a field is empty.
1207    *  \throw If the data array of \a field is not set.
1208    *  \throw If existing time steps have different name or number of components than \a field.
1209    *  \throw If the underlying mesh of \a field has no name.
1210    *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1211    */
1212   template<class T>
1213   void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1214   {
1215     const typename Traits<T>::ArrayType *arr(NULL);
1216     if(field)
1217       arr=field->getArray();
1218     MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1219     contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1220   }
1221
1222   /*!
1223    * Adds a MEDCouplingFieldDouble to \a this as another time step.
1224    * The mesh support of input parameter \a field is ignored here, it can be NULL.
1225    * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1226    * and \a profile.
1227    *
1228    * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1229    * A new profile is added only if no equal profile is missing.
1230    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1231    *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1232    *  \param [in] mesh - the supporting mesh of \a field.
1233    *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1234    *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
1235    *  \throw If either \a field or \a mesh or \a profile has an empty name.
1236    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1237    *  \throw If the data array of \a field is not set.
1238    *  \throw If the data array of \a this is already allocated but has different number of
1239    *         components than \a field.
1240    *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1241    *  \sa setFieldNoProfileSBT, appendFieldProfileFlatly
1242    */
1243   template<class T>
1244   void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1245   {
1246     appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
1247   }
1248
1249   /*!
1250    * same as appendFieldProfile except that here profile is created unconditionaly
1251    */
1252   template<class T>
1253   void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1254   {
1255     appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
1256   }
1257
1258   template<class T>
1259   void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
1260   {
1261     const typename Traits<T>::ArrayType *arr(NULL);
1262     if(field)
1263       arr=field->getArray();
1264     MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1265     contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this,smartPflKiller);
1266   }
1267   
1268   template<class T>
1269   const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1270   {
1271     const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1272     if(!pt)
1273       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1274     const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1275     if(!ret)
1276       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
1277     return ret;
1278   }
1279
1280   template<class T>
1281   typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1282   {
1283     MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1284     if(!pt)
1285       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1286     typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1287     if(!ret)
1288       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
1289     return ret;
1290   }
1291
1292   /*!
1293    * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1294    *  \param [in] pos - a time step id.
1295    *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1296    *          delete this field using decrRef() as it is no more needed.
1297    *  \throw If \a pos is not a valid time step id.
1298    */
1299   template<class T>
1300   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1301   {
1302     const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1303     if(!item)
1304       {
1305         std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1306         throw INTERP_KERNEL::Exception(oss.str());
1307       }
1308     const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1309     if(itemC)
1310       {
1311         MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1312         ret->shallowCpyGlobs(*this);
1313         return ret.retn();
1314       }
1315     std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1316     throw INTERP_KERNEL::Exception(oss.str());
1317   }
1318
1319   template<class T>
1320   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1321   {
1322     DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1323     if(!ret)
1324       return NULL;
1325     typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1326     if(!ret2)
1327       {
1328         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1329         throw INTERP_KERNEL::Exception(oss.str());
1330       }
1331     return ret2;
1332   }
1333
1334   template<class T>
1335   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1336   {
1337     DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1338     if(!ret)
1339       return NULL;
1340     typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1341     if(!ret2)
1342       {
1343         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1344         throw INTERP_KERNEL::Exception(oss.str());
1345       }
1346     return ret2;
1347   }
1348   
1349   template<class T>
1350   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1351   {
1352     return MLFieldTraits<T>::FMTSType::New();
1353   }
1354   
1355   template<class T>
1356   void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1357   {
1358     if(!f1ts)
1359       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1360     const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1361     if(!f1tsC)
1362       {
1363         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1364         throw INTERP_KERNEL::Exception(oss.str());
1365       }
1366   }
1367
1368   //////////////////////////
1369
1370   /*!
1371    * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1372    * following the given input policy.
1373    *
1374    * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1375    *                            By default (true) the globals are deeply copied.
1376    * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1377    */
1378   template<class T>
1379   MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1380   {
1381     MCAuto<MEDFileFieldMultiTS> ret;
1382     const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1383     if(content)
1384       {
1385         const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1386         if(!contc)
1387           throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1388         MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1389         ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1390       }
1391     else
1392       ret=MEDFileFieldMultiTS::New();
1393     if(isDeepCpyGlobs)
1394       ret->deepCpyGlobs(*this);
1395     else
1396       ret->shallowCpyGlobs(*this);
1397     return ret.retn();
1398   }
1399 }
1400
1401 #endif