]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Correction of msg on attempt of field loading from different type than those in file.
authorageay <ageay>
Tue, 5 Apr 2011 13:20:26 +0000 (13:20 +0000)
committerageay <ageay>
Tue, 5 Apr 2011 13:20:26 +0000 (13:20 +0000)
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/Swig/MEDLoaderTest.py
src/MEDLoader/Test/MEDLoaderTest.cxx

index 3fe82e307b14b6aae685e633ab2624fcb0aede36..14ea0cbb9177288ed0f2a402f74e7a4a43878905 100644 (file)
@@ -184,10 +184,10 @@ namespace MEDLoaderNS
   int buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
                                                   INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& 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<std::string>& infos, const char *fieldName, int iteration, int order, double time,
-                                                          std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType);
+                                                          std::list<MEDLoader::MEDFieldDoublePerCellType>& 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<std::string>& infos, const char *fieldName, int iteration, int order, double time,
-                                                                     std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType)
+                                                                     std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception)
 {
   if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
     MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDFieldDoublePerCellType>(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<MEDLoader::MEDFieldDoublePerCellType> 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)
index c8ca5275540c22a237a0d4134e981bf35ccd7775..4ea3a780814723ec44e40f48c5b9370c27b86330 100644 (file)
@@ -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):
index c2423d4690bc2136e6f6c1aa27153d7d9a210468..e0613e08346f2833fdf955f2060fa68f2427b14b 100644 (file)
@@ -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();
 }