m->write(fileName,mod);
}
-void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
+template<class T>
+void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
{
- MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
+ MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
AssignStaticWritePropertiesTo(*ff);
- MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
+ MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
const MEDCouplingMesh *m(f2->getMesh());
const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
ff->write(fileName,0);
}
-void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
+template<class T>
+void WriteFieldImpl(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
{
if(!f)
throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
f->checkConsistencyLight();
- int status=MEDLoaderBase::getStatusOfFile(fileName);
+ int status(MEDLoaderBase::getStatusOfFile(fileName));
if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
{
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
}
if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
{
- MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
+ MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
}
else
{
throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
std::string fileNameCpp(f->getMesh()->getName());
if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
- MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
+ MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
else
{
MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
if(!mmuPtr)
throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
- MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
- MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
+ MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
+ MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
if(!m)
throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
- MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
+ MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
f2->renumberCells(o2n->begin(),false);
m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
{
m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
DataArrayInt *part=0;
- bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
+ bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
MCAuto<DataArrayInt> partSafe(part);
if(!b)
{
std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
AssignStaticWritePropertiesTo(*f1ts);
if(part->isIota(mread->getNumberOfCells()))
f1ts->setFieldNoProfileSBT(f2);
}
else
{
- DataArrayInt *part=0;
- bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
+ DataArrayInt *part(NULL);
+ bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
MCAuto<DataArrayInt> partSafe(part);
if(!b)
{
std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
AssignStaticWritePropertiesTo(*f1ts);
if(part->isIota(mread->getNumberOfNodes()))
f1ts->setFieldNoProfileSBT(f2);
}
}
+void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
+{
+ const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
+ if(f1)
+ {
+ WriteFieldImpl<double>(fileName,f1,writeFromScratch);
+ return ;
+ }
+ const MEDCoupling::MEDCouplingFieldInt *f2(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
+ if(f2)
+ {
+ WriteFieldImpl<int>(fileName,f2,writeFromScratch);
+ return ;
+ }
+ const MEDCoupling::MEDCouplingFieldFloat *f3(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
+ if(f3)
+ {
+ WriteFieldImpl<float>(fileName,f3,writeFromScratch);
+ return ;
+ }
+ if(f)
+ throw INTERP_KERNEL::Exception("WriteField : only fielddouble, fieldint and fieldfloat are managed !");
+ WriteFieldImpl<double>(fileName,NULL,writeFromScratch);
+}
+
void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
{
WriteField(fileName,f,writeFromScratch);
WriteFieldUsingAlreadyWrittenMeshImpl<float>(fileName,f3);
return ;
}
+ if(f)
+ throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : only fielddouble, fieldint and fieldfloat are managed !");
WriteFieldUsingAlreadyWrittenMeshImpl<double>(fileName,NULL);
}