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