Salome HOME
ab4a0d17826d548c9790faf0ebd143e7cb155967
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.txx
1 // Copyright (C) 2007-2016  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<int,int> > >& 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,int> > >& 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     int 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<int,int> > > extractInfo;
185     int 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<int,int> > >::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, DataArrayInt *&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<int,int> > >& 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()
686    */
687   template<class T>
688   void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
689   {
690     setFileName("");
691     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
692     contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
693   }
694
695   /*!
696    * Return an extraction of \a this using \a extractDef map to specify the extraction.
697    * The keys of \a extractDef is level relative to max ext of \a mm mesh.
698    *
699    * \return A new object that the caller is responsible to deallocate.
700    * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
701    */
702   template<class T>
703   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
704   {
705     if(!mm)
706       throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
707     MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
708     std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
709     for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
710       {
711         if((*it0)!=ON_NODES)
712           {
713             std::vector<int> levs;
714             getNonEmptyLevels(mm->getName(),levs);
715             for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
716               {
717                 std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
718                 if(it2!=extractDef.end())
719                   {
720                     MCAuto<DataArrayInt> t((*it2).second);
721                     if(t.isNull())
722                       throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
723                     MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
724                     MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
725                     ret->setFieldNoProfileSBT(fOut);
726                   }
727               }
728           }
729         else
730           {
731             std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
732             if(it2==extractDef.end())
733               throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
734             MCAuto<DataArrayInt> t((*it2).second);
735             if(t.isNull())
736               throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
737             MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
738             MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
739             typename Traits<T>::ArrayType *arr(f->getArray());
740             MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
741             fOut->setArray(newArr);
742             ret->setFieldNoProfileSBT(fOut);
743           }
744       }
745     return ret.retn();
746   }
747
748   //////////////////////////
749
750   /*!
751    * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
752    * following the given input policy.
753    *
754    * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
755    *                            By default (true) the globals are deeply copied.
756    * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
757    */
758   template<class T>
759   MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
760   {
761     MCAuto<MEDFileField1TS> ret;
762     const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
763     if(content)
764       {
765         const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
766         if(!contc)
767           {
768             std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
769             throw INTERP_KERNEL::Exception(oss.str());
770           }
771         MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
772         ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
773       }
774     else
775       ret=MEDFileField1TS::New();
776     if(isDeepCpyGlobs)
777       ret->deepCpyGlobs(*this);
778     else
779       ret->shallowCpyGlobs(*this);
780     return ret.retn();
781   }
782
783   //////////////////////////
784
785   template<class T>
786   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)
787   {
788     return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
789   }
790   
791   template<class T>
792   void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
793   {
794     if(!f1ts)
795       throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
796     const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
797     if(!f1tsC)
798       {
799         std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
800         throw INTERP_KERNEL::Exception(oss.str());
801       }
802   }
803   
804   template<class T>
805   const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
806   {
807     return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
808   }
809   
810   template<class T>
811   MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
812   {
813     return new typename MLFieldTraits<T>::FMTSWSDAType;
814   }
815   
816   template<class T>
817   MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
818   {
819     return new typename MLFieldTraits<T>::F1TSWSDAType;
820   }
821   
822   //////////////////////////
823
824   template<class T>
825   MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
826   {
827     MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
828     ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
829     int i=0;
830     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
831       {
832         const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
833         if(eltToConv)
834           {
835             const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
836             if(!eltToConvC)
837               throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
838           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
839           ret->setIteration(i,elt);
840           }
841       }
842     return ret.retn();
843   }
844   
845   //////////////////////////
846   
847   template<class T>
848   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
849   {
850     _content=new typename MLFieldTraits<T>::FMTSWSDAType;
851   }
852
853   template<class T>
854   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
855   {
856   }
857   
858   template<class T>
859   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
860   {
861   }
862   
863   template<class T>
864   MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
865   {
866   }
867
868   /*!
869    * Return an extraction of \a this using \a extractDef map to specify the extraction.
870    * The keys of \a extractDef is level relative to max ext of \a mm mesh.
871    *
872    * \return A new object that the caller is responsible to deallocate.
873    */
874   template<class T>
875   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
876   {
877     if(!mm)
878       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
879     MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
880     int nbTS(getNumberOfTS());
881     for(int i=0;i<nbTS;i++)
882       {
883         MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
884         MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
885         MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
886         fmtsOut->pushBackTimeStep(f1tsOut);
887       }
888     return fmtsOut.retn();
889   }
890
891   /*!
892    * Returns a new empty instance of MEDFileFieldMultiTS.
893    *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
894    *          is to delete this field using decrRef() as it is no more needed.
895    */
896   template<class T>
897   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
898   {
899     return new typename MLFieldTraits<T>::FMTSType;
900   }
901
902   /*!
903    * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
904    * that has been read from a specified MED file.
905    *  \param [in] fileName - the name of the MED file to read.
906    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
907    *          is to delete this field using decrRef() as it is no more needed.
908    *  \throw If reading the file fails.
909    */
910   template<class T>
911   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
912   {
913     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
914     return New(fid,loadAll);
915   }
916
917   template<class T>
918   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
919   {
920     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
921     ret->contentNotNull();//to check that content type matches with \a this type.
922     return ret.retn();
923   }
924
925   /*!
926    * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
927    * that has been read from a specified MED file.
928    *  \param [in] fileName - the name of the MED file to read.
929    *  \param [in] fieldName - the name of the field to read.
930    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
931    *          is to delete this field using decrRef() as it is no more needed.
932    *  \throw If reading the file fails.
933    *  \throw If there is no field named \a fieldName in the file.
934    */
935   template<class T>
936   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
937   {
938     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
939     return New(fid,fieldName,loadAll);
940   }
941
942   template<class T>
943   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
944   {
945     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
946     ret->contentNotNull();//to check that content type matches with \a this type.
947     return ret.retn();
948   }
949
950   /*!
951    * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
952    * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
953    *
954    * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
955    * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
956    * \warning this is a shallow copy constructor
957    *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
958    *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
959    *  \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
960    *          is to delete this field using decrRef() as it is no more needed.
961    */
962   template<class T>
963   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
964   {
965     return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
966   }
967
968   template<class T>
969   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)
970   {
971     MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
972     INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
973     MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
974     ret->contentNotNull();//to check that content type matches with \a this type.
975     return ret.retn();
976   }
977
978   /*!
979    * 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
980    * method should be called (getFieldOnMeshAtLevel for example).
981    * But for normal usage of field in MED file world this method is the most efficient to fetch data.
982    *
983    * \param [in] iteration - the iteration number of a required time step.
984    * \param [in] order - the iteration order number of required time step.
985    * \param [in] mesh - the mesh the field is lying on
986    * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
987    *          caller is to delete this field using decrRef() as it is no more needed. 
988    */
989   template<class T>
990   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
991   {
992     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
993     MCAuto<DataArray> arrOut;
994     MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
995     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
996     return ret2.retn();
997   }
998
999   /*!
1000    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1001    * mesh entities of a given dimension of the first mesh in MED file.
1002    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1003    *  \param [in] type - a spatial discretization of interest.
1004    *  \param [in] iteration - the iteration number of a required time step.
1005    *  \param [in] order - the iteration order number of required time step.
1006    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1007    *  \param [in] renumPol - specifies how to permute values of the result field according to
1008    *          the optional numbers of cells and nodes, if any. The valid values are
1009    *          - 0 - do not permute.
1010    *          - 1 - permute cells.
1011    *          - 2 - permute nodes.
1012    *          - 3 - permute cells and nodes.
1013    *
1014    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1015    *          caller is to delete this field using decrRef() as it is no more needed. 
1016    *  \throw If the MED file is not readable.
1017    *  \throw If there is no mesh in the MED file.
1018    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1019    *  \throw If no field values of the required parameters are available.
1020    */
1021   template<class T>
1022   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1023   {
1024     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1025     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1026     if(!myF1TSC)
1027       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1028     MCAuto<DataArray> arrOut;
1029     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1030     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1031     return ret2.retn();
1032   }
1033
1034   /*!
1035    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1036    * the top level cells of the first mesh in MED file.
1037    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1038    *  \param [in] type - a spatial discretization of interest.
1039    *  \param [in] iteration - the iteration number of a required time step.
1040    *  \param [in] order - the iteration order number of required time step.
1041    *  \param [in] renumPol - specifies how to permute values of the result field according to
1042    *          the optional numbers of cells and nodes, if any. The valid values are
1043    *          - 0 - do not permute.
1044    *          - 1 - permute cells.
1045    *          - 2 - permute nodes.
1046    *          - 3 - permute cells and nodes.
1047    *
1048    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1049    *          caller is to delete this field using decrRef() as it is no more needed. 
1050    *  \throw If the MED file is not readable.
1051    *  \throw If there is no mesh in the MED file.
1052    *  \throw If no field values of the required parameters are available.
1053    */
1054   template<class T>
1055   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1056   {
1057     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1058     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1059     if(!myF1TSC)
1060       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1061     MCAuto<DataArray> arrOut;
1062     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1063     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1064     return ret2.retn();
1065   }
1066
1067   /*!
1068    * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1069    * a given support.
1070    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1071    *  \param [in] type - a spatial discretization of interest.
1072    *  \param [in] iteration - the iteration number of a required time step.
1073    *  \param [in] order - the iteration order number of required time step.
1074    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1075    *  \param [in] mesh - the supporting mesh.
1076    *  \param [in] renumPol - specifies how to permute values of the result field according to
1077    *          the optional numbers of cells and nodes, if any. The valid values are
1078    *          - 0 - do not permute.
1079    *          - 1 - permute cells.
1080    *          - 2 - permute nodes.
1081    *          - 3 - permute cells and nodes.
1082    *
1083    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1084    *          caller is to delete this field using decrRef() as it is no more needed. 
1085    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1086    *  \throw If no field of \a this is lying on \a mesh.
1087    *  \throw If no field values of the required parameters are available.
1088    */
1089   template<class T>
1090   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1091   {
1092     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1093     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1094     if(!myF1TSC)
1095       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1096     MCAuto<DataArray> arrOut;
1097     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1098     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1099     return ret2.retn();
1100   }
1101
1102   /*!
1103    * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1104    * given support. 
1105    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1106    *  \param [in] type - a spatial discretization of the new field.
1107    *  \param [in] iteration - the iteration number of a required time step.
1108    *  \param [in] order - the iteration order number of required time step.
1109    *  \param [in] mesh - the supporting mesh.
1110    *  \param [in] renumPol - specifies how to permute values of the result field according to
1111    *          the optional numbers of cells and nodes, if any. The valid values are
1112    *          - 0 - do not permute.
1113    *          - 1 - permute cells.
1114    *          - 2 - permute nodes.
1115    *          - 3 - permute cells and nodes.
1116    *
1117    *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1118    *          caller is to delete this field using decrRef() as it is no more needed. 
1119    *  \throw If no field of \a this is lying on \a mesh.
1120    *  \throw If no field values of the required parameters are available.
1121    */
1122   template<class T>
1123   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1124   {
1125     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1126     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1127     if(!myF1TSC)
1128       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1129     MCAuto<DataArray> arrOut;
1130     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1131     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1132     return ret2.retn();
1133   }
1134
1135   /*!
1136    * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1137    * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1138    * This method is useful for MED2 file format when field on different mesh was autorized.
1139    */
1140   template<class T>
1141   typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, 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>::getFieldAtLevelOld : mismatch of type of field !");
1147     MCAuto<DataArray> arrOut;
1148     MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1149     MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1150     return ret2.retn();
1151   }
1152
1153   /*!
1154    * Returns values and a profile of the field of a given type, of a given time step,
1155    * lying on a given support.
1156    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1157    *  \param [in] type - a spatial discretization of the field.
1158    *  \param [in] iteration - the iteration number of a required time step.
1159    *  \param [in] order - the iteration order number of required time step.
1160    *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1161    *  \param [in] mesh - the supporting mesh.
1162    *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
1163    *          field of interest lies on. If the field lies on all entities of the given
1164    *          dimension, all ids in \a pfl are zero. The caller is to delete this array
1165    *          using decrRef() as it is no more needed.  
1166    *  \param [in] glob - the global data storing profiles and localization.
1167    *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1168    *          field. The caller is to delete this array using decrRef() as it is no more needed.
1169    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1170    *  \throw If no field of \a this is lying on \a mesh.
1171    *  \throw If no field values of the required parameters are available.
1172    */
1173   template<class T>
1174   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
1175   {
1176     const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1177     const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1178     if(!myF1TSC)
1179       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1180     MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1181     return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1182   }
1183
1184   /*!
1185    * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1186    * the given field is checked if its elements are sorted suitable for writing to MED file
1187    * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
1188    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1189    *  \param [in] field - the field to add to \a this.
1190    *  \throw If the name of \a field is empty.
1191    *  \throw If the data array of \a field is not set.
1192    *  \throw If existing time steps have different name or number of components than \a field.
1193    *  \throw If the underlying mesh of \a field has no name.
1194    *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1195    */
1196   template<class T>
1197   void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1198   {
1199     const typename Traits<T>::ArrayType *arr(NULL);
1200     if(field)
1201       arr=field->getArray();
1202     MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1203     contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1204   }
1205
1206   /*!
1207    * Adds a MEDCouplingFieldDouble to \a this as another time step.
1208    * The mesh support of input parameter \a field is ignored here, it can be NULL.
1209    * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1210    * and \a profile.
1211    *
1212    * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1213    * A new profile is added only if no equal profile is missing.
1214    * For more info, see \ref AdvMEDLoaderAPIFieldRW
1215    *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1216    *  \param [in] mesh - the supporting mesh of \a field.
1217    *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1218    *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
1219    *  \throw If either \a field or \a mesh or \a profile has an empty name.
1220    *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1221    *  \throw If the data array of \a field is not set.
1222    *  \throw If the data array of \a this is already allocated but has different number of
1223    *         components than \a field.
1224    *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1225    *  \sa setFieldNoProfileSBT()
1226    */
1227   template<class T>
1228   void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
1229   {
1230     const typename Traits<T>::ArrayType *arr(NULL);
1231     if(field)
1232       arr=field->getArray();
1233     MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1234     contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this);
1235   }
1236
1237   template<class T>
1238   const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1239   {
1240     const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1241     if(!pt)
1242       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1243     const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1244     if(!ret)
1245       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 !");
1246     return ret;
1247   }
1248
1249   template<class T>
1250   typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1251   {
1252     MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1253     if(!pt)
1254       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1255     typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1256     if(!ret)
1257       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 !");
1258     return ret;
1259   }
1260
1261   /*!
1262    * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1263    *  \param [in] pos - a time step id.
1264    *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1265    *          delete this field using decrRef() as it is no more needed.
1266    *  \throw If \a pos is not a valid time step id.
1267    */
1268   template<class T>
1269   typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1270   {
1271     const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1272     if(!item)
1273       {
1274         std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1275         throw INTERP_KERNEL::Exception(oss.str());
1276       }
1277     const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1278     if(itemC)
1279       {
1280         MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1281         ret->shallowCpyGlobs(*this);
1282         return ret.retn();
1283       }
1284     std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1285     throw INTERP_KERNEL::Exception(oss.str());
1286   }
1287
1288   template<class T>
1289   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1290   {
1291     DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1292     if(!ret)
1293       return NULL;
1294     typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1295     if(!ret2)
1296       {
1297         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1298         throw INTERP_KERNEL::Exception(oss.str());
1299       }
1300     return ret2;
1301   }
1302
1303   template<class T>
1304   typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1305   {
1306     DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1307     if(!ret)
1308       return NULL;
1309     typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1310     if(!ret2)
1311       {
1312         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1313         throw INTERP_KERNEL::Exception(oss.str());
1314       }
1315     return ret2;
1316   }
1317   
1318   template<class T>
1319   typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1320   {
1321     return MLFieldTraits<T>::FMTSType::New();
1322   }
1323   
1324   template<class T>
1325   void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1326   {
1327     if(!f1ts)
1328       throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1329     const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1330     if(!f1tsC)
1331       {
1332         std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1333         throw INTERP_KERNEL::Exception(oss.str());
1334       }
1335   }
1336
1337   //////////////////////////
1338
1339   /*!
1340    * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1341    * following the given input policy.
1342    *
1343    * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1344    *                            By default (true) the globals are deeply copied.
1345    * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1346    */
1347   template<class T>
1348   MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1349   {
1350     MCAuto<MEDFileFieldMultiTS> ret;
1351     const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1352     if(content)
1353       {
1354         const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1355         if(!contc)
1356           throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1357         MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1358         ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1359       }
1360     else
1361       ret=MEDFileFieldMultiTS::New();
1362     if(isDeepCpyGlobs)
1363       ret->deepCpyGlobs(*this);
1364     else
1365       ret->shallowCpyGlobs(*this);
1366     return ret.retn();
1367   }
1368 }
1369
1370 #endif