#include "MEDFileUtilities.hxx"
#include "MEDLoaderBase.hxx"
+#include "MEDLoader.hxx"
#include "InterpKernelAutoPtr.hxx"
void MEDCoupling::MEDFileWritableStandAlone::write30(const std::string& fileName, int mode) const
{
med_access_mode medmod(MEDFileUtilities::TraduceWriteMode(mode));
- throw INTERP_KERNEL::Exception("MEDFileWritableStandAlone::write30 : will be implemented with MEDFile >= 3.2.1 !");
- //MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,3,0,0));
- //writeLL(fid);
+#if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1
+ MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,3,0,0));
+ writeLL(fid);
+#else
+ std::ostringstream oss; oss << "MEDFileWritableStandAlone::write30 : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
+ throw INTERP_KERNEL::Exception(oss.str());
+#endif
}
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> MEDCoupling::MEDFileWritableStandAlone::serialize() const
memfile.app_image_ptr=0;
memfile.app_image_size=0;
//
- MEDFileUtilities::AutoFid fid(MEDmemFileOpen(DFT_FILENAME_IN_MEM,&memfile,MED_FALSE,MED_ACC_CREAT));
- writeLL(fid);
+ std::string dftFileName(GenerateUniqueDftFileNameInMem());
+ {// very important to let this braces ! The AutoFid destructor must be called, to have a "clean" memfile.app_image_ptr pointer embedded in the returned object.
+ MEDFileUtilities::AutoFid fid(MEDmemFileOpen(dftFileName.c_str(),&memfile,MED_FALSE,MED_ACC_CREAT));
+ writeLL(fid);
+ }
//
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> ret(MEDCoupling::DataArrayByte::New());
ret->useArray(reinterpret_cast<char *>(memfile.app_image_ptr),true,C_DEALLOC,memfile.app_image_size,1);
return ret;
}
+
+std::string MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInMem()
+{
+ static int ii=0;
+ std::ostringstream oss; oss << DFT_FILENAME_IN_MEM << "_" << ii++;
+ return oss.str();
+}