# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+if(MED_INT_IS_LONG)
+ add_definitions(-DMED_INT_IS_LONG)
+endif(MED_INT_IS_LONG)
+
# InterpKERNEL
ADD_SUBDIRECTORY(INTERP_KERNEL)
IF(MEDCOUPLING_BUILD_TESTS)
namespace MEDCoupling
{
+#ifdef MED_INT_IS_LONG
+ using DataArrayMedInt = DataArrayInt64;
+#else
+ using DataArrayMedInt = DataArrayInt32;
+#endif
- class DataArrayMedInt : public DataArrayDiscreteSigned< med_int >
+ template<class INTARRAY>
+ DataArrayMedInt * DataArrayMedInt_Copy( const INTARRAY* intArray )
{
- friend class DataArrayDiscrete<med_int>;
- public:
- template<class INTARRAY>
- static DataArrayMedInt *Copy( const INTARRAY* array );
- static DataArrayMedInt *New() { return new DataArrayMedInt(); }
- std::string getClassName() const override { return std::string("DataArrayMedInt"); }
- DataArrayMedInt *deepCopy() const { return new DataArrayMedInt(*this); }
- //DataArrayMedInt *buildNewEmptyInstance() const { return new DataArrayMedInt(); }//ko
- DataArray *buildNewEmptyInstance() const { if ( sizeof(med_int)==sizeof(int)) return DataArrayInt32::New(); return DataArrayInt64::New(); }
- public:
- DataArrayMedInt *copySorted(bool asc=true) const override { MCAuto<DataArrayMedInt> ret(this->deepCopy()); ret->sort(); return ret.retn(); }
- DataArray *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
- DataArray *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
- DataArray *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
- DataArray *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return this->myKeepSelectedComponents(compoIds); }
- DataArray *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return this->mySelectByTupleIdSafeSlice(bg,end2,step); }
- DataArray *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return this->mySelectByTupleRanges(ranges); }
- private:
- ~DataArrayMedInt() { }
- DataArrayMedInt() { }
- };
+ DataArrayMedInt* medIntArray = DataArrayMedInt::New();
+ medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() );
+ medIntArray->copyStringInfoFrom( *intArray );
+ std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() );
+ return medIntArray;
+ }
template< class T1, class T2 >
MCAuto<T1> StaticCast( const MCAuto< T2 >& array )
{
if ( sizeof( med_int ) == sizeof( typename INTARRAY::Type ))
return StaticCast< DataArrayMedInt >( intArray );
- return DataArrayMedInt::Copy((const INTARRAY*) intArray );
+ return DataArrayMedInt_Copy((const INTARRAY*) intArray );
}
template< class INT >
ia->incrRef();
return StaticCast< DataArrayMedInt >( ia );
}
- return DataArrayMedInt::Copy( intArray );
+ return DataArrayMedInt_Copy( intArray );
}
template< class INT >
return static_cast< INT >( mi );
}
- template<class INTARRAY>
- DataArrayMedInt * DataArrayMedInt::Copy( const INTARRAY* intArray )
- {
- DataArrayMedInt* medIntArray = DataArrayMedInt::New();
- medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() );
- medIntArray->copyStringInfoFrom( *intArray );
- std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() );
- return medIntArray;
- }
}
#endif
INTERP_KERNEL::AutoPtr<char> name(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,meshName2,getFather()->getMesh()->getTooLongStrPolicy());
MEDLoaderBase::safeStrCpy(equName.c_str(),MED_NAME_SIZE,name,getFather()->getMesh()->getTooLongStrPolicy());
- MCAuto<DataArrayMedInt> da2(DataArrayMedInt::Copy(da)); da2->rearrange(1); da2->applyLin(1,1); da2->rearrange(2);
+ MCAuto<DataArrayMedInt> da2(DataArrayMedInt_Copy(da)); da2->rearrange(1); da2->applyLin(1,1); da2->rearrange(2);
MEDFILESAFECALLERWR0(MEDequivalenceCorrespondenceWr,(fid,meshName2,name,dt,it,medtype,medgt,ToMedInt(da2->getNumberOfTuples()),da2->begin()));
}
std::size_t nbOfPfls=_pfls.size();
for(std::size_t i=0;i<nbOfPfls;i++)
{
- MCAuto<DataArrayMedInt> cpy=DataArrayMedInt::Copy((const DataArrayIdType*)_pfls[i]);
+ MCAuto<DataArrayMedInt> cpy=DataArrayMedInt_Copy((const DataArrayIdType*)_pfls[i]);
cpy->applyLin(1,1,0);
INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
MEDFileCapability mfcap(fid);
if( ( !entities || entities->areAllStaticPresentAndNoDyn() ) && mfcap.isFastReader())
{// no entities
- int nentitype(MEDfieldnEntityType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT));
+ med_int nentitype(MEDfieldnEntityType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT));
INTERP_KERNEL::AutoPtr<med_entity_type> types(new med_entity_type[nentitype]);
med_int usedbyncs;
MEDFILESAFECALLERRD0(MEDfieldEntityType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types,&usedbyncs));
std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > entitiesFastP;
for(int i=0;i<nentitype;i++)
{
- int ngeotype(MEDfieldnGeometryType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i]));
+ med_int ngeotype(MEDfieldnGeometryType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i]));
INTERP_KERNEL::AutoPtr<med_geometry_type> geotypes(new med_geometry_type[ngeotype]);
med_int geousedbyncs;
MEDFILESAFECALLERRD0(MEDfieldGeometryType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i],geotypes,&geousedbyncs));
- for(int j=0;j<ngeotype;j++)
+ for(med_int j=0;j<ngeotype;j++)
{
std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> p(MEDFileMesh::ConvertFromMEDFileEntity(types[i]),ConvertGeometryType(geotypes[j]));
entitiesFastP.push_back(p);
const MEDCoupling1SGTUMesh *m0(dynamic_cast<const MEDCoupling1SGTUMesh *>(m));
if(!m0)
throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !");
- MCAuto<DataArrayMedInt> arr(DataArrayMedInt::Copy(m0->getNodalConnectivity()));
+ MCAuto<DataArrayMedInt> arr(DataArrayMedInt_Copy(m0->getNodalConnectivity()));
std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,ToMedInt(nbOfCells),arr->begin()));
}
throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !");
if(ikt==INTERP_KERNEL::NORM_POLYGON || ikt==INTERP_KERNEL::NORM_QPOLYG)
{
- MCAuto<DataArrayMedInt> arr(DataArrayMedInt::Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt::Copy(m0->getNodalConnectivityIndex()));
+ MCAuto<DataArrayMedInt> arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt_Copy(m0->getNodalConnectivityIndex()));
std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
MEDFILESAFECALLERWR0(MEDmeshPolygon2Wr,(fid,mname.c_str(),dt,it,timm,MED_CELL,ikt==INTERP_KERNEL::NORM_POLYGON?MED_POLYGON:MED_POLYGON2,MED_NODAL,ToMedInt(nbOfCells+1),arrI->begin(),arr->begin()));
char nomfam[MED_NAME_SIZE+1];
for(med_int i=0;i<nbFams;++i)
{
- med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),i+1)),famId;
+ med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),FromMedInt<int>(i+1))),famId;
std::unique_ptr<char[]> gro{new char[MED_LNAME_SIZE*nbGrps+1]};
- MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get()));
+ MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),FromMedInt<int>(i+1),nomfam,&famId,gro.get()));
std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
families[fam] = FromMedInt<mcIdType>(famId);
std::vector<std::string> v(nbGrps);
self.assertTrue(v.isEqual(DataArrayDouble([0.0]),1e-14))
pass
+ @WriteInTmpDir
+ def test43(self):
+ """
+ EDF23724 : point to error during 64bit convertion into medcoupling a DataArrayMedInt class was created.
+ This class is not dynamic_castable to DataArrayInt32 nor DataArrayInt64. It lead previously to strange behaviour
+ """
+ fname = "tessss.med"
+ arr=DataArrayDouble(10) ; arr.iota()
+ m = MEDCouplingCMesh() ; m.setCoords(arr)
+ m = m.buildUnstructured()
+ m.setName("mesh")
+ mm = MEDFileUMesh() ; mm[0] = m
+ mm.setGlobalNumFieldAtLevel(1,DataArrayInt([0,4,5,6,10,12,16,17,19,20]))
+ mm.write(fname,2)
+ mm_reload = MEDFileMesh.New(fname)
+ # DataArrayMedInt class no more exists. Check that.
+ self.assertNotEqual(mm_reload.getGlobalNumFieldAtLevel(1).getClassName() , "DataArrayMedInt")
+ pass
+
pass
if __name__ == "__main__":