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