Salome HOME
First impl of MEDCouplingFieldFloat
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 2 May 2017 06:59:57 +0000 (08:59 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 2 May 2017 06:59:57 +0000 (08:59 +0200)
17 files changed:
src/MEDCoupling/CMakeLists.txt
src/MEDCoupling/MEDCouplingFieldFloat.cxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingFieldFloat.hxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingFieldTemplate.cxx
src/MEDCoupling/MEDCouplingFieldTemplate.hxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingMemArrayFloat.cxx
src/MEDCoupling/MEDCouplingTimeDiscretization.cxx
src/MEDCoupling/MEDCouplingTimeDiscretization.hxx
src/MEDCoupling/MEDCouplingTraits.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx
src/MEDCoupling_Swig/MEDCouplingMemArray.i

index 2c8a580ae5f949a216016101f60048565d6a0c72..f777468ddfd1878e3e2aa9214108fbbc17efbeb2 100644 (file)
@@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(
 
 SET(medcoupling_SOURCES
   MEDCouplingField.cxx
+  MEDCouplingFieldFloat.cxx
   MEDCouplingFieldDouble.cxx
   MEDCouplingFieldInt.cxx
   MEDCouplingUMesh.cxx
diff --git a/src/MEDCoupling/MEDCouplingFieldFloat.cxx b/src/MEDCoupling/MEDCouplingFieldFloat.cxx
new file mode 100644 (file)
index 0000000..7214562
--- /dev/null
@@ -0,0 +1,83 @@
+// Copyright (C) 2007-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "MEDCouplingFieldFloat.hxx"
+#include "MEDCouplingFieldT.txx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldTemplate.hxx"
+#include "MEDCouplingMesh.hxx"
+
+using namespace MEDCoupling;
+
+template class MEDCoupling::MEDCouplingFieldT<float>;
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(TypeOfField type, TypeOfTimeDiscretization td)
+{
+  return new MEDCouplingFieldFloat(type,td);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
+{
+  return new MEDCouplingFieldFloat(ft,td);
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT<float>(type,MEDCouplingTimeDiscretizationFloat::New(td))
+{
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCopy):MEDCouplingFieldT<float>(other,deepCopy)
+{
+}
+
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type):MEDCouplingFieldT<float>(type,n,td)
+{
+}
+
+/*!
+ * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
+ */
+MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingFieldT<float>(ft,MEDCouplingTimeDiscretizationFloat::New(td),false)
+{
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::deepCopy() const
+{
+  return cloneWithMesh(true);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldFloat::clone(bool recDeepCpy) const
+{
+  return new MEDCouplingFieldFloat(*this,recDeepCpy);
+}
+
+MEDCouplingFieldDouble *MEDCouplingFieldFloat::convertToDblField() const
+{
+  MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*this));
+  int t1,t2;
+  double t0(getTime(t1,t2));
+  MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*tmp,getTimeDiscretization()));
+  ret->setTime(t0,t1,t2);
+  if(getArray())
+    {
+      MCAuto<DataArrayDouble> arr(getArray()->convertToDblArr());
+      ret->setArray(arr);
+    }
+  return ret.retn();
+}
diff --git a/src/MEDCoupling/MEDCouplingFieldFloat.hxx b/src/MEDCoupling/MEDCouplingFieldFloat.hxx
new file mode 100644 (file)
index 0000000..83e7465
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2007-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#ifndef __MEDCOUPLINGFIELDFLOAT_HXX__
+#define __MEDCOUPLINGFIELDFLOAT_HXX__
+
+#include "MEDCoupling.hxx"
+#include "MEDCouplingFieldT.hxx"
+#include "MEDCouplingMemArray.hxx"
+
+#include <string>
+
+namespace MEDCoupling
+{
+  class MEDCouplingFieldDouble;
+  class MEDCouplingFieldTemplate;
+  
+  class MEDCouplingFieldFloat : public MEDCouplingFieldT<float>
+  {
+  public:
+    MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
+    MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+    MEDCOUPLING_EXPORT MEDCouplingFieldFloat *deepCopy() const;
+    MEDCOUPLING_EXPORT MEDCouplingFieldFloat *clone(bool recDeepCpy) const;
+    MEDCOUPLING_EXPORT MEDCouplingFieldDouble *convertToDblField() const;
+  protected:
+    MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td);
+    MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCopy);
+    MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type);
+    MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td);
+    ~MEDCouplingFieldFloat() { }
+  };
+}
+
+#endif
index 4f2893ab5d7945ffae5d83ca239b5fd41020e3a4..948ef2f646f1d31d39827a256a30532942990904 100644 (file)
@@ -21,6 +21,7 @@
 #include "MEDCouplingFieldTemplate.hxx"
 #include "MEDCouplingMesh.hxx"
 #include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingFieldDiscretization.hxx"
 
@@ -33,6 +34,11 @@ MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDo
   return new MEDCouplingFieldTemplate(f);
 }
 
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
+{
+  return new MEDCouplingFieldTemplate(f);
+}
+
 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
 {
   return new MEDCouplingFieldTemplate(f);
@@ -52,6 +58,12 @@ MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble&
   checkConsistencyLight();
 }
 
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f):MEDCouplingField(f,false) 
+{
+  forceTimeOfThis(f);
+  checkConsistencyLight();
+}
+
 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false) 
 {
   forceTimeOfThis(f);
index a00ba79ff2406b484c6dec0df29db11e921e5c03..6b27fc21847c3716ce559ffa31e8f2c313aee942 100644 (file)
@@ -26,6 +26,7 @@
 namespace MEDCoupling
 {
   class MEDCouplingFieldInt;
+  class MEDCouplingFieldFloat;
   class MEDCouplingFieldDouble;
   /*!
    * \brief A field template can be seen as a field without the array of values.
@@ -41,6 +42,7 @@ namespace MEDCoupling
   {
   public:
     MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f);
+    MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldFloat& f);
     MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f);
     MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(TypeOfField type);
     MEDCOUPLING_EXPORT std::string simpleRepr() const;
@@ -57,6 +59,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
   private:
     MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f);
+    MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f);
     MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f);
     MEDCouplingFieldTemplate(TypeOfField type);
   };
index 5067c1373dbe12a61bde8103a3da473b1c0c2312..2ad3aaf63fac24c693d06068edce70c257aafa22 100644 (file)
@@ -40,6 +40,8 @@ template class MEDCoupling::MemArray<int>;
 template class MEDCoupling::MemArray<double>;
 template class MEDCoupling::DataArrayTemplate<int>;
 template class MEDCoupling::DataArrayTemplate<double>;
+template class MEDCoupling::DataArrayTemplateClassic<int>;
+template class MEDCoupling::DataArrayTemplateClassic<double>;
 template class MEDCoupling::DataArrayTemplateFP<double>;
 
 template<int SPACEDIM>
@@ -812,13 +814,7 @@ DataArrayDouble *DataArrayDouble::deepCopy() const
  */
 DataArrayDouble *DataArrayDouble::performCopyOrIncrRef(bool dCpy) const
 {
-  if(dCpy)
-    return deepCopy();
-  else
-    {
-      incrRef();
-      return const_cast<DataArrayDouble *>(this);
-    }
+  return DataArrayTemplateClassic<double>::PerformCopyOrIncrRef(dCpy,*this);
 }
 
 /*!
@@ -1125,23 +1121,6 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other,
   return _mem.isEqual(other._mem,prec,tmp);
 }
 
-/*!
- * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
- * array to the new one.
- *  \return DataArrayInt * - the new instance of DataArrayInt.
- */
-DataArrayInt *DataArrayDouble::convertToIntArr() const
-{
-  DataArrayInt *ret=DataArrayInt::New();
-  ret->alloc(getNumberOfTuples(),getNumberOfComponents());
-  int *dest=ret->getPointer();
-  // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest);
-  for(const double *src=begin();src!=end();src++,dest++)
-    *dest=(int)*src;
-  ret->copyStringInfoFrom(*this);
-  return ret;
-}
-
 /*!
  * Returns a new DataArrayDouble holding the same values as \a this array but differently
  * arranged in memory. If \a this array holds 2 components of 3 values:
@@ -4731,13 +4710,7 @@ DataArrayInt *DataArrayInt::deepCopy() const
  */
 DataArrayInt *DataArrayInt::performCopyOrIncrRef(bool dCpy) const
 {
-  if(dCpy)
-    return deepCopy();
-  else
-    {
-      incrRef();
-      return const_cast<DataArrayInt *>(this);
-    }
+  return DataArrayTemplateClassic<int>::PerformCopyOrIncrRef(dCpy,*this);
 }
 
 /*!
@@ -6030,24 +6003,6 @@ bool DataArrayInt::hasUniqueValues() const
   return true;
 }
 
-/*!
- * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
- * array to the new one.
- *  \return DataArrayDouble * - the new instance of DataArrayInt.
- */
-DataArrayDouble *DataArrayInt::convertToDblArr() const
-{
-  checkAllocated();
-  DataArrayDouble *ret=DataArrayDouble::New();
-  ret->alloc(getNumberOfTuples(),getNumberOfComponents());
-  std::size_t nbOfVals=getNbOfElems();
-  const int *src=getConstPointer();
-  double *dest=ret->getPointer();
-  std::copy(src,src+nbOfVals,dest);
-  ret->copyStringInfoFrom(*this);
-  return ret;
-}
-
 /*!
  * Appends components of another array to components of \a this one, tuple by tuple.
  * So that the number of tuples of \a this array remains the same and the number of 
index 8a57b8d140fdf044dc7b9e55c045fdb5f763cec5..1d6acba01467329447e84fcf0eea7b8683d2b620 100644 (file)
@@ -298,7 +298,21 @@ namespace MEDCoupling
   };
 
   template<class T>
-  class DataArrayTemplateFP : public DataArrayTemplate<T>
+  class DataArrayTemplateClassic : public DataArrayTemplate<T>
+  {
+  public:
+    MEDCOUPLING_EXPORT MCAuto<DataArrayDouble> convertToDblArr() const;
+    MEDCOUPLING_EXPORT MCAuto<DataArrayInt> convertToIntArr() const;
+    MEDCOUPLING_EXPORT MCAuto<DataArrayFloat> convertToFloatArr() const;
+  protected:
+    static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
+  private:
+    template<class U>
+    MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
+  };
+  
+  template<class T>
+  class DataArrayTemplateFP : public DataArrayTemplateClassic<T>
   {
   public:
     MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const;
@@ -326,14 +340,14 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
     MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
     MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
-  public:
+  public:// non abstract but essential
     MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
     MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
     MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
-  public:
     MEDCOUPLING_EXPORT bool isEqual(const DataArrayFloat& other, float prec) const;
     MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const;
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const;
+    MEDCOUPLING_EXPORT DataArrayFloat *performCopyOrIncrRef(bool deepCopy) const;
   private:
     ~DataArrayFloat() { }
     DataArrayFloat() { }
@@ -370,7 +384,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const;
     MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const;
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const;
-    MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const;
     MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleId(new2OldBg,new2OldEnd); }
@@ -527,7 +540,7 @@ namespace MEDCoupling
 
   class DataArrayIntIterator;
 
-  class DataArrayInt : public DataArrayTemplate<int>
+  class DataArrayInt : public DataArrayTemplateClassic<int>
   {
   public:
     MEDCOUPLING_EXPORT static DataArrayInt *New();
@@ -573,7 +586,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const;
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const;
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const;
-    MEDCOUPLING_EXPORT DataArrayDouble *convertToDblArr() const;
     MEDCOUPLING_EXPORT DataArrayInt *fromNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayInt *toNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleId(new2OldBg,new2OldEnd); }
index 9fdf9051a94992c12dec226df8ce93a30dd21a28..425ceeaaeb0fcd67ac13287342407c0703ace129 100644 (file)
@@ -2252,6 +2252,76 @@ namespace MEDCoupling
       std::reverse(work,work+nbOfCompo);
     std::reverse(_info_on_compo.begin(),_info_on_compo.end());
   }
+
+  template<class T>
+  template<class U>
+  MCAuto< typename Traits<U>::ArrayType > DataArrayTemplateClassic<T>::convertToOtherTypeOfArr() const
+  {
+    this->checkAllocated();
+    MCAuto<typename Traits<U>::ArrayType> ret(Traits<U>::ArrayType::New());
+    ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents());
+    std::size_t nbOfVals(this->getNbOfElems());
+    const T *src(this->begin());
+    U *dest(ret->getPointer());
+    // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest);
+    //for(const T *src=this->begin();src!=this->end();src++,dest++)
+    //  *dest=(int)*src;
+    std::copy(src,src+nbOfVals,dest);
+    ret->copyStringInfoFrom(*this);
+    return ret;
+  }
+  
+  /*!
+   * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
+   * array to the new one.
+   *  \return DataArrayDouble * - the new instance of DataArrayInt.
+   */
+  template<class T>
+  MCAuto<DataArrayDouble> DataArrayTemplateClassic<T>::convertToDblArr() const
+  {
+    return convertToOtherTypeOfArr<double>();
+  }
+
+  /*!
+   * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
+   * array to the new one.
+   *  \return DataArrayInt * - the new instance of DataArrayInt.
+   */
+  template<class T>
+  MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::convertToIntArr() const
+  {
+    return convertToOtherTypeOfArr<int>();
+  }
+
+  /*!
+   * Creates a new DataArrayFloat and assigns all (textual and numerical) data of \a this
+   * array to the new one.
+   *  \return DataArrayFloat * - the new instance of DataArrayInt.
+   */
+  template<class T>
+  MCAuto<DataArrayFloat> DataArrayTemplateClassic<T>::convertToFloatArr() const
+  {
+    return convertToOtherTypeOfArr<float>();
+  }
+  
+  /*!
+   * Returns either a \a deep or \a shallow copy of this array. For more info see
+   * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
+   *  \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
+   *  \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
+   *          == \a true) or \a this instance (if \a dCpy == \a false).
+   */
+  template<class T>
+  typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self)
+  {
+    if(dCpy)
+      return self.deepCopy();
+    else
+      {
+        self.incrRef();
+        return const_cast<typename Traits<T>::ArrayType *>(&self);
+      }
+  }
   
   /*!
    * Checks if all values in \a this array are equal to \a val at precision \a eps.
index a06401848c202cfa4e71ef972d86e0c8190aa4a8..36f4de3bb5b345be0c15c540e6d9af18d39d098b 100644 (file)
@@ -24,6 +24,7 @@ using namespace MEDCoupling;
 
 template class MEDCoupling::MemArray<float>;
 template class MEDCoupling::DataArrayTemplate<float>;
+template class MEDCoupling::DataArrayTemplateClassic<float>;
 template class MEDCoupling::DataArrayTemplateFP<float>;
 
 DataArrayFloat *DataArrayFloat::New()
@@ -167,3 +168,15 @@ bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, f
   std::string tmp;
   return _mem.isEqual(other._mem,prec,tmp);
 }
+
+/*!
+ * Returns either a \a deep or \a shallow copy of this array. For more info see
+ * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
+ *  \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
+ *  \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
+ *          == \a true) or \a this instance (if \a dCpy == \a false).
+ */
+DataArrayFloat *DataArrayFloat::performCopyOrIncrRef(bool dCpy) const
+{
+  return DataArrayTemplateClassic<float>::PerformCopyOrIncrRef(dCpy,*this);
+}
index 14494736b61e658842c101a43e5966921617f608..f9c6b6a784e76825eba1a2fd3bd08596874a80d9 100644 (file)
@@ -842,7 +842,7 @@ MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(Type
   }
 }
 
-bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<int> *other, float prec, std::string& reason) const
+bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const
 {
   if(prec!=0)
     throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !");
@@ -854,16 +854,16 @@ bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDi
   const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
   if(!otherC)
     throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !");
-  if(!MEDCouplingTimeDiscretizationTemplate<int>::areStrictlyCompatible(other,reason))
+  if(!MEDCouplingTimeDiscretizationTemplate<float>::areStrictlyCompatible(other,reason))
     return false;
   if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
     return false;
   if(_array==other->getArray())
     return true;
-  return _array->isEqualIfNotWhy(*other->getArray(),reason);
+  return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
 }
 
-bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, float prec) const
+bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const
 {
   if(prec!=0)
     throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !");
@@ -878,7 +878,7 @@ bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDC
     return false;
   if(_array==other->getArray())
     return true;
-  return _array->isEqualWithoutConsideringStr(*(other->getArray()));
+  return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec);
 }
 
 ////////////////////////
index 9925c2cd12e9855b54589512a6437a1c6a7451fa..fd7e34e439166d6585f2de7d3a93c0ede0cd9e8c 100644 (file)
@@ -243,10 +243,10 @@ namespace MEDCoupling
   public:
     MEDCouplingTimeDiscretizationFloat() { }
     MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy);
-    static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type);
+    static MEDCouplingTimeDiscretizationFloat *New(TypeOfTimeDiscretization type);
     MEDCouplingTimeDiscretizationFloat *performCopyOrIncrRef(bool deepCopy) const;
     bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const;
-    bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, float prec) const;
+    bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const;
   private:
     static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME;
   };
index 262328e7173231b72e27a2c9f118e443f53d1039..22f203a45d74d020f29ecec10fba9b89efb06be5 100644 (file)
@@ -37,6 +37,7 @@ namespace MEDCoupling
   class DataArrayChar;
   class DataArrayByte;
   class MEDCouplingFieldDouble;
+  class MEDCouplingFieldFloat;
   class MEDCouplingFieldInt;
   
   template<>
@@ -58,7 +59,7 @@ namespace MEDCoupling
     static const char NPYStr[];
     typedef DataArrayFloat ArrayType;
     typedef DataArrayFloat ArrayTypeCh;
-    //typedef MEDCouplingFieldFloat FieldType;
+    typedef MEDCouplingFieldFloat FieldType;
   };
   
   template<>
index 3589367a5710397693478a151e441cd7d8949e71..460215242ac52c8c0e3f0a4b9324047f529554fa 100644 (file)
@@ -77,11 +77,9 @@ void MEDCouplingBasicsTest1::testArray2()
   arr->setInfoOnComponent(1,"hhhh");
   arr->setInfoOnComponent(2,"jj");
   arr->setInfoOnComponent(3,"kkkkkk");
-  DataArrayInt *arr2=arr->convertToIntArr();
-  DataArrayDouble *arr3=arr2->convertToDblArr();
-  arr2->decrRef();
+  MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
+  MCAuto<DataArrayDouble> arr3(arr2->convertToDblArr());
   CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
-  arr3->decrRef();
   arr->decrRef();
 }
 
index a6e7075caeff5d0985ba041a72d774012b86fe0b..42972290c7edf0294f80eab911a74030a7e712ba 100644 (file)
@@ -681,7 +681,7 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
   const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
   for(int i=0;i<30;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
-  DataArrayInt *a3=a1->convertToIntArr();
+  MCAuto<DataArrayInt> a3(a1->convertToIntArr());
   DataArrayInt *a4=static_cast<DataArrayInt *>(a3->keepSelectedComponents(arr2V));
   CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
   CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
@@ -713,7 +713,7 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
   const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
   for(int i=0;i<30;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
-  DataArrayInt *a6=a5->convertToIntArr();
+  MCAuto<DataArrayInt> a6=a5->convertToIntArr();
   a6->setInfoOnComponent(0,"eeee");
   a6->setInfoOnComponent(1,"ffff");
   a4->setSelectedComponents(a6,arr4V);
@@ -740,10 +740,8 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
   arr7V.resize(3);
   CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
   //
-  a6->decrRef();
   a5->decrRef();
   a4->decrRef();
-  a3->decrRef();
   a2->decrRef();
   a1->decrRef();
 }
@@ -1066,14 +1064,13 @@ void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
   CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
   CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
-  DataArrayDouble *da3=da->convertToDblArr();
+  MCAuto<DataArrayDouble> da3=da->convertToDblArr();
   DataArrayDouble *da4=da3->fromNoInterlace();
   CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
   CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
   for(int i=0;i<15;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
   da4->decrRef();
-  da3->decrRef();
   da2->decrRef();
   da->decrRef();
 }
@@ -1089,14 +1086,13 @@ void MEDCouplingBasicsTest3::testDAToNoInterlace1()
   CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
   CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
-  DataArrayDouble *da3=da->convertToDblArr();
+  MCAuto<DataArrayDouble> da3=da->convertToDblArr();
   DataArrayDouble *da4=da3->toNoInterlace();
   CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
   CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
   for(int i=0;i<15;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
   da4->decrRef();
-  da3->decrRef();
   da2->decrRef();
   da->decrRef();
 }
@@ -1112,13 +1108,12 @@ void MEDCouplingBasicsTest3::testDAIsUniform1()
   CPPUNIT_ASSERT(!da->isUniform(1));
   da->setIJ(2,0,1);
   CPPUNIT_ASSERT(da->isUniform(1));
-  DataArrayDouble *da2=da->convertToDblArr();
+  MCAuto<DataArrayDouble> da2=da->convertToDblArr();
   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
   da2->setIJ(1,0,1.+1.e-13);
   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
   da2->setIJ(1,0,1.+1.e-11);
   CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
-  da2->decrRef();
   da->decrRef();
 }
 
@@ -1648,7 +1643,7 @@ void MEDCouplingBasicsTest3::testDAMeld1()
   //
   da1->fillWithValue(7.);
   da2->iota(0.);
-  DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
+  MCAuto<DataArrayDouble> da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
   //
   da1->setInfoOnComponent(0,"c0da1");
   da1->setInfoOnComponent(1,"c1da1");
@@ -1670,8 +1665,8 @@ void MEDCouplingBasicsTest3::testDAMeld1()
   for(int i=0;i<35;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
   //
-  DataArrayInt *dai1=da1C->convertToIntArr();
-  DataArrayInt *dai3=da3->convertToIntArr();
+  MCAuto<DataArrayInt> dai1=da1C->convertToIntArr();
+  MCAuto<DataArrayInt> dai3=da3->convertToIntArr();
   dai1->meldWith(dai3);
   CPPUNIT_ASSERT_EQUAL(5,(int)dai1->getNumberOfComponents());
   CPPUNIT_ASSERT_EQUAL(7,(int)dai1->getNumberOfTuples());
@@ -1694,7 +1689,6 @@ void MEDCouplingBasicsTest3::testDAMeld1()
   for(int i=0;i<35;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
   // test of static method DataArrayInt::meld
-  dai1->decrRef();
   dai1=da1C->convertToIntArr();
   DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
   CPPUNIT_ASSERT_EQUAL(5,(int)dai4->getNumberOfComponents());
@@ -1709,12 +1703,9 @@ void MEDCouplingBasicsTest3::testDAMeld1()
   //
   dai4->decrRef();
   da4->decrRef();
-  dai3->decrRef();
-  dai1->decrRef();
   da1C->decrRef();
   da1->decrRef();
   da2->decrRef();
-  da3->decrRef();
 }
 
 void MEDCouplingBasicsTest3::testFieldMeld1()
@@ -2140,7 +2131,7 @@ void MEDCouplingBasicsTest3::testDARearrange1()
   for(int i=0;i<12;i++)
     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
   //double
-  DataArrayDouble *da2=da1->convertToDblArr();
+  MCAuto<DataArrayDouble> da2=da1->convertToDblArr();
   da1->decrRef();
   const double *ptr2=da2->getConstPointer();
   //
@@ -2180,7 +2171,6 @@ void MEDCouplingBasicsTest3::testDARearrange1()
   CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
   for(int i=0;i<12;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
-  da2->decrRef();
 }
 
 void MEDCouplingBasicsTest3::testGetDifferentValues1()
@@ -2224,7 +2214,7 @@ void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
   c=a->buildPermutationArr(*b);
   const int expect2[5]={1,3,4,2,3};
   CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
-  DataArrayDouble *d=b->convertToDblArr();
+  MCAuto<DataArrayDouble> d=b->convertToDblArr();
   b->sort();
   const int expect3[5]={4,4,5,6,8};
   CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
@@ -2234,10 +2224,9 @@ void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
   for(int i=0;i<5;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
   //
-  d->decrRef();
+  b->decrRef();
   c->decrRef();
   a->decrRef();
-  b->decrRef();
 }
 
 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
index 6ed02e3ede897a8c62b6bdf6852ff7d238212b2b..fc199652f01eae4ed539d8df30e1e0711c1a0271 100644 (file)
@@ -998,7 +998,7 @@ void MEDCouplingBasicsTest4::testDACpyFrom1()
   d1->deepCopyFrom(*d);
   CPPUNIT_ASSERT(d->isEqual(*d1,1e-12));
   //
-  DataArrayInt *d2=d->convertToIntArr();
+  MCAuto<DataArrayInt> d2=d->convertToIntArr();
   DataArrayInt *d4=DataArrayInt::New();
   CPPUNIT_ASSERT(!d2->isEqual(*d4));
   d4->deepCopyFrom(*d2);
@@ -1012,7 +1012,6 @@ void MEDCouplingBasicsTest4::testDACpyFrom1()
   //
   d->decrRef();
   d1->decrRef();
-  d2->decrRef();
   d4->decrRef();
 }
 
index 3213b5728b2478d4f99c52b5f276da82e7be03a8..b18a7d3def641306b91daa6f7239b356a2fe1b31 100644 (file)
@@ -601,7 +601,7 @@ void MEDCouplingBasicsTest5::testDataArrayAbs1()
   const double expected1[12]={2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.};
   d1->alloc(6,2);
   std::copy(val1,val1+12,d1->getPointer());
-  DataArrayInt *d2=d1->convertToIntArr();
+  MCAuto<DataArrayInt> d2=d1->convertToIntArr();
   //
   d1->abs();
   for(int i=0;i<12;i++)
@@ -612,7 +612,6 @@ void MEDCouplingBasicsTest5::testDataArrayAbs1()
   for(int i=0;i<12;i++)
     CPPUNIT_ASSERT_EQUAL(expected2[i],d2->getIJ(0,i));
   //
-  d2->decrRef();
   d1->decrRef();
 }
 
index 1fd7a8d6e065eb6c3bb974a6411be28ba2bd85a6..0b6ca517bc632bc65ec2afd681ada1e100d0fbb7 100644 (file)
@@ -54,6 +54,7 @@
 %newobject MEDCoupling::DataArrayInt::__iter__;
 %newobject MEDCoupling::DataArrayInt::selectPartDef;
 %newobject MEDCoupling::DataArrayInt::convertToDblArr;
+%newobject MEDCoupling::DataArrayInt::convertToFloatArr;
 %newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef;
 %newobject MEDCoupling::DataArrayInt::subArray;
 %newobject MEDCoupling::DataArrayInt::changeNbOfComponents;
 %newobject MEDCoupling::DataArrayDouble::__iter__;
 %newobject MEDCoupling::DataArrayDouble::selectPartDef;
 %newobject MEDCoupling::DataArrayDouble::convertToIntArr;
+%newobject MEDCoupling::DataArrayDouble::convertToFloatArr;
 %newobject MEDCoupling::DataArrayDouble::performCopyOrIncrRef;
 %newobject MEDCoupling::DataArrayDouble::Aggregate;
 %newobject MEDCoupling::DataArrayDouble::Meld;
@@ -773,7 +775,6 @@ namespace MEDCoupling
     std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception);
     bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
     bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
@@ -890,6 +891,18 @@ namespace MEDCoupling
         return ret.retn();
       }
 
+      DataArrayFloat *convertToFloatArr() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayFloat> ret(self->convertToFloatArr());
+        return ret.retn();
+      }
+      
+      DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayInt> ret(self->convertToIntArr());
+        return ret.retn();
+      }
+
       void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception)
       {
         double val;
@@ -2341,7 +2354,6 @@ namespace MEDCoupling
     DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
-    DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception);
     DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
     DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception);
@@ -2543,6 +2555,18 @@ namespace MEDCoupling
         {
           return MEDCoupling_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp);
         }
+      
+      DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayDouble> ret(self->convertToDblArr());
+        return ret.retn();
+      }
+      
+      DataArrayFloat *convertToFloatArr() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayFloat> ret(self->convertToFloatArr());
+        return ret.retn();
+      }
 
       std::string __str__() const throw(INTERP_KERNEL::Exception)
       {