[MOAB-dev] commit/MOAB: danwu: Updated HelloMOAB example to use new error handling code. We can change the mesh file name (e.g. 3k-tri-sphere.vtk -> 4k-tri-sphere.vtk) to test a trivial "No such file or directory" error. Other examples will be updated similarly later.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jul 14 17:09:14 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/e1e603b143e3/
Changeset:   e1e603b143e3
Branch:      danwu/error_handling_enhancement
User:        danwu
Date:        2014-07-15 00:07:17
Summary:     Updated HelloMOAB example to use new error handling code. We can change the mesh file name (e.g. 3k-tri-sphere.vtk -> 4k-tri-sphere.vtk) to test a trivial "No such file or directory" error. Other examples will be updated similarly later.

Affected #:  1 file

diff --git a/examples/HelloMOAB.cpp b/examples/HelloMOAB.cpp
index 6ca2b23..0c160de 100644
--- a/examples/HelloMOAB.cpp
+++ b/examples/HelloMOAB.cpp
@@ -9,7 +9,6 @@
 
 #include "moab/Core.hpp"
 #include <iostream>
-#include <assert.h>
 
 using namespace moab;
 using namespace std;
@@ -18,45 +17,47 @@ using namespace std;
 #define MESH_DIR "."
 #endif
 
+// Note: change the file name below to test a trivial "No such file or directory" error
 string test_file_name = string(MESH_DIR) + string("/3k-tri-sphere.vtk");
 
-int main( int argc, char** argv )
+int main(int argc, char** argv)
 {
-  Interface *iface = new Core;
+  Interface* iface = new Core;
 
-    // need option handling here for input filename
-  if (argc > 1){
-    //user has input a mesh file
+  // Need option handling here for input filename
+  if (argc > 1) {
+    // User has input a mesh file
     test_file_name = argv[1];
-  }  
-    //load the mesh from vtk file
-  ErrorCode rval = iface->load_mesh( test_file_name.c_str() );
-  assert(rval == MB_SUCCESS);
+  }
 
-    // get verts entities, by type
+  MBErrorHandler_Init();
+
+  // Load the mesh from vtk file
+  ErrorCode rval = iface->load_mesh(test_file_name.c_str());CHK_ERR(rval);
+
+  // Get verts entities, by type
   Range verts;
-  rval = iface->get_entities_by_type(0, MBVERTEX, verts);
-  assert(rval == MB_SUCCESS);
-    //get edge entities, by type
+  rval = iface->get_entities_by_type(0, MBVERTEX, verts);CHK_ERR(rval);
+
+  // Get edge entities, by type
   Range edges;
-  rval = iface->get_entities_by_type(0, MBEDGE, edges);
-  assert(rval == MB_SUCCESS);
+  rval = iface->get_entities_by_type(0, MBEDGE, edges);CHK_ERR(rval);
 
-    // get faces, by dimension, so we stay generic to entity type
+  // Get faces, by dimension, so we stay generic to entity type
   Range faces;
-  rval = iface->get_entities_by_dimension(0, 2, faces);
-  assert(rval == MB_SUCCESS);
+  rval = iface->get_entities_by_dimension(0, 2, faces);CHK_ERR(rval);
 
-    //get regions, by dimension, so we stay generic to entity type
+  // Get regions, by dimension, so we stay generic to entity type
   Range elems;
-  rval = iface->get_entities_by_dimension(0, 3, elems);
-  assert(rval == MB_SUCCESS);
-
-   //output the number of entities
-  cout << "Number of vertices is " << verts.size() <<  endl;
-  cout << "Number of edges is " << edges.size() <<  endl;
-  cout << "Number of faces is " << faces.size() <<  endl;
-  cout << "Number of elements is " << elems.size() <<  endl;
+  rval = iface->get_entities_by_dimension(0, 3, elems);CHK_ERR(rval);
+
+  MBErrorHandler_Finalize();
+
+  // Output the number of entities
+  cout << "Number of vertices is " << verts.size() << endl;
+  cout << "Number of edges is " << edges.size() << endl;
+  cout << "Number of faces is " << faces.size() << endl;
+  cout << "Number of elements is " << elems.size() << endl;
 
   delete iface;

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list