Salome HOME
useful methods again
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
index 89784e20f5ff400bce5409fb27b78a8aff93f08c..2b362ece3abb2d7f2b7b6ee536b3ccd9ba03a63b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -778,6 +778,8 @@ void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldN
   const DataArray *arr=getOrCreateAndGetArray();
   if(!arr)
     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
+  if(!arr->isAllocated())
+    throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
   const unsigned char *locToWrite=0;
@@ -6890,6 +6892,11 @@ DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& ar
   return arrC;
 }
 
+MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+  throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
+}
+
 /*!
  * Returns a new MEDCouplingFieldDouble of a given type lying on
  * the top level cells of the first mesh in MED file. If \a this field 
@@ -7954,7 +7961,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingF
     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
   if(!_time_steps.empty())
     checkCoherencyOfTinyInfo(field,arr);
-  MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
+  MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
   copyTinyInfoFrom(field,arr);
@@ -8959,6 +8966,27 @@ int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiT
   return nts;
 }
 
+/*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ */
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+  if(!mm)
+    throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
+  MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
+  int nbTS(getNumberOfTS());
+  for(int i=0;i<nbTS;i++)
+    {
+      MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
+      MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
+      fmtsOut->pushBackTimeStep(f1tsOut);
+    }
+  return fmtsOut.retn();
+}
+
 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
 {
   return new MEDFileAnyTypeFieldMultiTSIterator(this);
@@ -9389,25 +9417,9 @@ DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration,
   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
 }
 
-/*!
- * Return an extraction of \a this using \a extractDef map to specify the extraction.
- * The keys of \a extractDef is level relative to max ext of \a mm mesh.
- *
- * \return A new object that the caller is responsible to deallocate.
- */
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
 {
-  if(!mm)
-    throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
-  MCAuto<MEDFileFieldMultiTS> fmtsOut(MEDFileFieldMultiTS::New());
-  int nbTS(getNumberOfTS());
-  for(int i=0;i<nbTS;i++)
-    {
-      MCAuto<MEDFileField1TS> f1ts(getTimeStepAtPos(i));
-      MCAuto<MEDFileField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
-      fmtsOut->pushBackTimeStep(f1tsOut);
-    }
-  return fmtsOut.retn();
+  return MEDFileFieldMultiTS::New();
 }
 
 //= MEDFileAnyTypeFieldMultiTSIterator
@@ -9853,9 +9865,9 @@ DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int
   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
 }
 
-MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
 {
-  throw INTERP_KERNEL::Exception("*MEDFileIntFieldMultiTS::extractPart : not implemented yet for int !");
+  return MEDFileIntFieldMultiTS::New();
 }
 
 //= MEDFileFields
@@ -10362,7 +10374,7 @@ MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayIn
   int nbFields(getNumberOfFields());
   for(int i=0;i<nbFields;i++)
     {
-      MEDFileAnyTypeFieldMultiTS *fmts(getFieldAtPos(i));
+      MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
       if(!fmts)
         {
           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";