From: ageay Date: Tue, 5 Apr 2011 13:20:26 +0000 (+0000) Subject: Correction of msg on attempt of field loading from different type than those in file. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=381bf8dd573c22f929d1ec0ae230621619181c14;p=tools%2Fmedcoupling.git Correction of msg on attempt of field loading from different type than those in file. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 3fe82e307..14ea0cbb9 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -184,10 +184,10 @@ namespace MEDLoaderNS int buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector& conn, const std::vector& connIndex, const std::vector& families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& fam4MEDFile, std::vector& renumber); ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, - ParaMEDMEM::TypeOfField typeOfOutField); + ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception); ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh, const std::vector& infos, const char *fieldName, int iteration, int order, double time, - std::list& fieldPerCellType); + std::list& fieldPerCellType) throw(INTERP_KERNEL::Exception); med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt); void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds); @@ -1764,7 +1764,7 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh, const std::vector& infos, const char *fieldName, int iteration, int order, double time, - std::list& fieldPerCellType) + std::list& fieldPerCellType) throw(INTERP_KERNEL::Exception) { if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) MEDLoaderNS::keepSpecifiedMeshDim(fieldPerCellType,meshDim); @@ -1862,7 +1862,7 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char } ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, - ParaMEDMEM::TypeOfField typeOfOutField) + ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception) { std::list fieldPerCellType; double time; @@ -1875,6 +1875,16 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char typesToKeep.push_back((*iter).getType()); unsigned meshDim; int *cellRenum; + if(fieldPerCellType.empty()) + { + std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << meshName << "\" meshDimRelToMax=" << meshDimRelToMax; + oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl; + if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) + oss << "Request for cell field, maybe it is a node field instead ?"; + else + oss << "Request for a node field, maybe it is a cell field instead ?"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType); if(cellRenum) diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index c8ca52755..4ea3a7808 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -74,6 +74,7 @@ class MEDLoaderTest(unittest.TestCase): MEDLoader.MEDLoader.WriteField("Pyfile7.med",f1,True); f2=MEDLoader.MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + self.assertRaises(Exception,MEDLoader.MEDLoader.ReadFieldCell,"file7.med",f1.getMesh().getName(),0,f1.getName(),2,3); pass def testFieldRW2(self): diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index c2423d469..e0613e083 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -99,6 +99,9 @@ void MEDLoaderTest::testFieldRW1() MEDLoader::WriteField("file7.med",f1,true); f2=MEDLoader::ReadFieldNode("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3); CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + // testing kind message on error of field type. + CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3),INTERP_KERNEL::Exception); + // f1->decrRef(); f2->decrRef(); }