-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2013 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
_nb_gauss_pt=_w.size();
}
+MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
+{
+ return new MEDFileFieldLoc(*this);
+}
+
+std::size_t MEDFileFieldLoc::getHeapMemorySize() const
+{
+ return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
+}
+
void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
{
static const char OFF7[]="\n ";
return new MEDFileFieldPerMeshPerTypePerDisc(other);
}
+std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySize() const
+{
+ return _profile.capacity()+_localization.capacity()+5*sizeof(int);
+}
+
+MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
+ ret->_father=father;
+ return ret.retn();
+}
+
MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception)
try:_type(atype),_father(fath)
{
}
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
- std::set<int> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
//
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
arrPart->renumberInPlace(renumTupleIds->begin());
arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
bool ret=false;
- std::set<int>::const_iterator idIt=diffVals.begin();
+ const int *idIt=diffVals->begin();
std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
int offset2=0;
- for(std::size_t i=0;i<diffVals.size();i++,idIt++)
+ for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
{
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
return new MEDFileFieldPerMeshPerType(fath,geoType);
}
+std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
+{
+ std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
+ ret+=(*it)->getHeapMemorySize();
+ return ret;
+}
+
+MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
+ ret->_father=father;
+ std::size_t i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
+ {
+ if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
+ ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
+ }
+ return ret.retn();
+}
+
void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
{
std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
if(!disc2)
throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
const DataArrayInt *da=disc2->getArrayOfDiscIds();
+ if(!da)
+ throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
- std::set<int> retTmp=da2->getDifferentValues();
- if(retTmp.find(-1)!=retTmp.end())
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
+ if(retTmp->presenceOfValue(-1))
throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
- std::vector<int> ret(retTmp.begin(),retTmp.end());
+ std::vector<int> ret(retTmp->begin(),retTmp->end());
return ret;
}
if(!disc2)
throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
const DataArrayInt *da=disc2->getArrayOfDiscIds();
+ if(!da)
+ throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
- std::set<int> retTmp=da2->getDifferentValues();
- if(retTmp.find(-1)!=retTmp.end())
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
+ if(retTmp->presenceOfValue(-1))
throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
- std::vector<int> ret(retTmp.begin(),retTmp.end());
+ std::vector<int> ret(retTmp->begin(),retTmp->end());
return ret;
}
return new MEDFileFieldPerMesh(fath,mesh);
}
+std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
+{
+ std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
+ if((const MEDFileFieldPerMeshPerType *)*it)
+ ret+=(*it)->getHeapMemorySize();
+ return ret;
+}
+
+MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
+ ret->_father=father;
+ std::size_t i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
+ {
+ if((const MEDFileFieldPerMeshPerType *)*it)
+ ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
+ }
+ return ret.retn();
+}
+
void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
{
std::string startLine(bkOffset,' ');
return finishField(type,glob,dads,locs,mesh,isPfl);
}
else
- return finishField3(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl);
+ return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl);
}
}
}
}
//
- ret->incrRef();
- return ret;
+ return ret.retn();
}
/*!
m2->setName(mesh->getName());
MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl);
isPfl=true;
- ret->incrRef();
- return ret;
+ return ret.retn();
}
/*!
* This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
*/
-MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField3(const MEDFileFieldGlobsReal *glob,
- const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
- const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
+MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
+ const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
+ const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
{
if(da->isIdentity())
{
int nbOfTuples=da->getNumberOfTuples();
- const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
- if(nbOfTuples==ComputeNbOfElems(glob,ON_NODES,geoTypes2,dads,locs))//No problem for NORM_ERROR because it is in context of node
+ if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
return finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
}
// Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
meshuc->finishInsertingCells();
ret->setMesh(meshuc);
ret->checkCoherency();
- ret->incrRef();
- return ret;
+ return ret.retn();
}
}
//
MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
int nnodes=mesh2->getNumberOfNodes();
- if(nnodes==da->getNbOfElems())
+ if(nnodes==(int)da->getNbOfElems())
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->getConstPointer(),arr2->getConstPointer()+arr2->getNbOfElems());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
ret->getArray()->renumberInPlace(da3->getConstPointer());
mesh2->setName(mesh->getName());
ret->setMesh(mesh2);
- ret->incrRef();
- return ret;
+ return ret.retn();
}
else
{
- std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishField3 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
+ std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
for(int i=0;i<nbOfComp;i++)
da->setInfoOnComponent(i,infos[i].c_str());
safePfl->incrRef();
- da->incrRef();
- return da;
+ return da.retn();
}
MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
return new MEDFileFieldGlobs;
}
+std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
+{
+ std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
+ ret+=(*it)->getHeapMemorySize();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
+ ret+=(*it)->getHeapMemorySize();
+ return ret;
+}
+
+MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
+ std::size_t i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
+ {
+ if((const DataArrayInt *)*it)
+ ret->_pfls[i]=(*it)->deepCpy();
+ }
+ i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
+ {
+ if((const MEDFileFieldLoc*)*it)
+ ret->_locs[i]=(*it)->deepCpy();
+ }
+ return ret.retn();
+}
+
MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
{
}
{
}
+std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
+{
+ std::size_t ret=0;
+ if((const MEDFileFieldGlobs *)_globals)
+ ret+=_globals->getHeapMemorySize();
+ return ret;
+}
+
void MEDFileFieldGlobsReal::simpleRepr(std::ostream& oss) const
{
oss << "Globals information on fields :" << "\n*******************************\n\n";
_globals=other._globals;
}
+void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
+{
+ _globals=other._globals;
+ if((const MEDFileFieldGlobs *)_globals)
+ _globals=other._globals->deepCpy();
+}
+
void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
{
_globals->appendGlobs(*other._globals,eps);
if(mName==0)
mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
else
- mm=MEDFileMesh::New(glob->getFileName(),mName,-1,-1);
+ mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
}
if(mName==0)
mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
else
- mm=MEDFileMesh::New(glob->getFileName(),mName,-1,-1);
+ mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
int absDim=getDimension();
int meshDimRelToMax=absDim-mm->getMeshDimension();
return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
case 0:
{
//no need to test _field_per_mesh.empty() because geMeshName has already done it
- ret->incrRef();
- return ret;
+ return ret.retn();
}
case 3:
case 1:
//no need to test _field_per_mesh.empty() because geMeshName has already done it
if(cellRenum)
{
- if(cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
+ if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
{
std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
ret->renumberCells(cellRenum->getConstPointer(),true);
}
if(renumPol==1)
- {
- ret->incrRef();
- return ret;
- }
+ return ret.retn();
}
case 2:
{
throw INTERP_KERNEL::Exception(msg1);
if(nodeRenum)
{
- if(nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
+ if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
{
std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
oss << "\"" << getName() << "\" not defined on all nodes !";
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
ret->renumberNodes(nodeRenumSafe->getConstPointer());
}
- ret->incrRef();
- return ret;
+ return ret.retn();
}
default:
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
}
+std::size_t MEDFileField1TSWithoutSDA::getHeapMemorySize() const
+{
+ std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
+ if((const DataArrayDouble *)_arr)
+ ret+=_arr->getHeapMemorySize();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
+ ret+=(*it)->getHeapMemorySize();
+ return ret;
+}
+
+MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=new MEDFileField1TSWithoutSDA(*this);
+ if((const DataArrayDouble *)_arr)
+ ret->_arr=_arr->deepCpy();
+ std::size_t i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++)
+ {
+ if((const MEDFileFieldPerMesh *)*it)
+ ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileField1TSWithoutSDA *)ret);
+ }
+ return ret.retn();
+}
+
DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
{
DataArrayDouble *ret=_arr;
return ret2;
}
+/*!
+ * This methods returns a new instance (to be dealt by the caller).
+ * This method returns for the first field in the file \a fileName the first time step of this first field, if
+ * such field exists and time step exists. If not, an INTERP_KERNEL::Exception will be thrown.
+ */
+MEDFileField1TS *MEDFileField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileField1TS(fileName);
+}
+
+/*!
+ * This methods returns a new instance (to be dealt by the caller).
+ * This method returns the first time step of the field \a fieldName in file \a fieldName, if
+ * such field exists. If not, an INTERP_KERNEL::Exception will be thrown.
+ */
+MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileField1TS(fileName,fieldName);
+}
+
MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
return new MEDFileField1TS(fileName,fieldName,iteration,order);
/*!
* \warning this is a shallow copy constructor
*/
-MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool deepCpy)
+MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
{
- return new MEDFileField1TS(other,deepCpy);
+ return new MEDFileField1TS(other,shallowCopyOfContent);
}
MEDFileField1TS *MEDFileField1TS::New()
std::string info=getInfo()[i];
std::string c,u;
MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);
- MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
+ MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
}
if(getName().empty())
throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
writeLL(fid);
}
-MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
-try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector<std::string>()))
+MEDFileField1TS::MEDFileField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
+try:MEDFileFieldGlobsReal(fileName)
{
MEDFileUtilities::CheckFileForRead(fileName);
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
- int nbFields=MEDnField(fid);
med_field_type typcha;
- bool found=false;
- std::vector<std::string> fns(nbFields);
- int nbOfStep2=-1;
- for(int i=0;i<nbFields && !found;i++)
+ //
+ int nbFields=MEDnField(fid);
+ if(nbFields<1)
{
- int ncomp=MEDfieldnComponent(fid,i+1);
- INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
- med_bool localMesh;
- int nbOfStep;
- MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
- std::string tmp(nomcha);
- fns[i]=tmp;
- found=(tmp==fieldName);
- if(found)
- {
- nbOfStep2=nbOfStep;
- std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
- std::vector<std::string> infos(ncomp);
- for(int j=0;j<ncomp;j++)
- infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
- _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
- }
+ std::ostringstream oss; oss << "MEDFileField1TS(fileName) : no field present in file \'" << fileName << "\' !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- if(!found)
+ int ncomp=MEDfieldnComponent(fid,1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localMesh;
+ int nbOfStep;
+ MEDfieldInfo(fid,1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
+ std::string fieldName(nomcha);
+ if(nbOfStep<1)
{
- std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
- std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
+ std::ostringstream oss; oss << "MEDFileField1TS(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ std::vector<std::string> infos(ncomp);
+ for(int j=0;j<ncomp;j++)
+ infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
+ _content=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
+ _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
+ //
+ med_int numdt,numit;
+ med_float dt;
+ MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
+ _content->setTime(numdt,numit,dt);
+ _content->_csit=1;
+ _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
+ _content->finishLoading(fid);
+ //
+ loadGlobals(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>()))
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_field_type typcha;
+ int nbSteps=locateField(fid,fileName,fieldName,typcha);
+ if(nbSteps<1)
+ {
+ std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- found=false;
+ //
+ med_int numdt,numit;
+ med_float dt;
+ MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
+ _content->setTime(numdt,numit,dt);
+ _content->_csit=1;
+ _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
+ _content->finishLoading(fid);
+ //
+ loadGlobals(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector<std::string>()))
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_field_type typcha;
+ int nbOfStep2=locateField(fid,fileName,fieldName,typcha);
+ bool found=false;
std::vector< std::pair<int,int> > dtits(nbOfStep2);
for(int i=0;i<nbOfStep2 && !found;i++)
{
/*!
* \warning this is a shallow copy constructor
*/
-MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool deepCpy)
+MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
{
- if(!deepCpy)
+ if(!shallowCopyOfContent)
{
const MEDFileField1TSWithoutSDA *otherPtr(&other);
otherPtr->incrRef();
{
}
+/*!
+ * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
+ *
+ * \param [out]
+ * \return in case of success the number of time steps available for the field with name \a fieldName.
+ */
+int MEDFileField1TS::locateField(med_idt fid, const char *fileName, const char *fieldName, med_field_type& typcha) throw(INTERP_KERNEL::Exception)
+{
+ int nbFields=MEDnField(fid);
+ bool found=false;
+ std::vector<std::string> fns(nbFields);
+ int nbOfStep2=-1;
+ for(int i=0;i<nbFields && !found;i++)
+ {
+ int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localMesh;
+ int nbOfStep;
+ MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
+ std::string tmp(nomcha);
+ fns[i]=tmp;
+ found=(tmp==fieldName);
+ if(found)
+ {
+ nbOfStep2=nbOfStep;
+ std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
+ std::vector<std::string> infos(ncomp);
+ for(int j=0;j<ncomp;j++)
+ infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
+ _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
+ }
+ }
+ if(!found)
+ {
+ std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
+ for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
+ oss << "\"" << *it << "\" ";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return nbOfStep2;
+}
+
/*!
* This method returns all profiles whose name is non empty used.
* \b WARNING If profile is used several times it will be reported \b only \b once.
}
}
+std::size_t MEDFileField1TS::getHeapMemorySize() const
+{
+ std::size_t ret=0;
+ if((const MEDFileField1TSWithoutSDA *)_content)
+ ret+=_content->getHeapMemorySize();
+ return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
+}
+
+MEDFileField1TS *MEDFileField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(*this);
+ if((const MEDFileField1TSWithoutSDA *)_content)
+ ret->_content=_content->deepCpy();
+ ret->deepCpyGlobs(*this);
+ return ret.retn();
+}
+
int MEDFileField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
{
return _content->copyTinyInfoFrom(field);
finishLoading(fid,nbOfStep);
}
catch(INTERP_KERNEL::Exception& e)
- {
- throw e;
- }
+{
+ throw e;
+}
+
+std::size_t MEDFileFieldMultiTSWithoutSDA::getHeapMemorySize() const
+{
+ std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
+ for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
+ ret+=(*it).capacity();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ if((const MEDFileField1TSWithoutSDA *)(*it))
+ ret+=(*it)->getHeapMemorySize();
+ return ret;
+}
+
+MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret=new MEDFileFieldMultiTSWithoutSDA(*this);
+ std::size_t i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
+ {
+ if((const MEDFileField1TSWithoutSDA *)*it)
+ ret->_time_steps[i]=(*it)->deepCpy();
+ }
+ return ret.retn();
+}
const std::vector<std::string>& MEDFileFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
{
std::string info=infos[i];
std::string c,u;
MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
- MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
+ MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
}
if(_name.empty())
throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
return new MEDFileFieldMultiTS(fileName,fieldName);
}
-MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool deepCpy)
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
{
- return new MEDFileFieldMultiTS(other,deepCpy);
+ return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
}
+std::size_t MEDFileFieldMultiTS::getHeapMemorySize() const
+{
+ std::size_t ret=0;
+ if((const MEDFileFieldMultiTSWithoutSDA*)_content)
+ ret+=_content->getHeapMemorySize();
+ return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
+}
+
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(*this);
+ if((const MEDFileFieldMultiTSWithoutSDA *)_content)
+ ret->_content=_content->deepCpy();
+ ret->deepCpyGlobs(*this);
+ return ret.retn();
+}
+
+/*!
+ * \return a new allocated object that the caller should deal with.
+ */
MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
{
const MEDFileField1TSWithoutSDA *item=_content->getTimeStepAtPos2(pos);
MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*item,false);
ret->shallowCpyGlobs(*this);
- ret->incrRef();
- return ret;
+ return ret.retn();
}
+/*!
+ * \return a new allocated object that the caller should deal with.
+ */
MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
{
int pos=getPosOfTimeStep(iteration,order);
return getTimeStepAtPos(pos);
}
+/*!
+ * \return a new allocated object that the caller should deal with.
+ */
MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
{
int pos=getPosGivenTime(time,eps);
throw e;
}
-MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool deepCpy)
+MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
{
- if(!deepCpy)
+ if(!shallowCopyOfContent)
{
const MEDFileFieldMultiTSWithoutSDA *otherPtr(&other);
otherPtr->incrRef();
return new MEDFileFields(fileName);
}
+std::size_t MEDFileFields::getHeapMemorySize() const
+{
+ std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA>);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
+ if((const MEDFileFieldMultiTSWithoutSDA *)*it)
+ ret+=(*it)->getHeapMemorySize();
+ return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
+}
+
+MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=new MEDFileFields(*this);
+ std::size_t i=0;
+ for( std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
+ {
+ if((const MEDFileFieldMultiTSWithoutSDA*)*it)
+ ret->_fields[i]=(*it)->deepCpy();
+ }
+ ret->deepCpyGlobs(*this);
+ return ret.retn();
+}
+
int MEDFileFields::getNumberOfFields() const
{
return _fields.size();
const MEDFileFieldMultiTSWithoutSDA *fmts=_fields[i];
MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New(*fmts,false);
ret->shallowCpyGlobs(*this);
- ret->incrRef();
- return ret;
+ return ret.retn();
}
MEDFileFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)