[MOAB-dev] r3834 - MOAB/trunk/src/io

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Mon May 3 12:59:53 CDT 2010


Author: kraftche
Date: 2010-05-03 12:59:53 -0500 (Mon, 03 May 2010)
New Revision: 3834

Modified:
   MOAB/trunk/src/io/ReadSmf.cpp
   MOAB/trunk/src/io/ReadSmf.hpp
   MOAB/trunk/src/io/SMF_State.cpp
   MOAB/trunk/src/io/SMF_State.hpp
Log:
Misc. cleanups for SMF reader:
  o check parsing of numeric values
  o don't read past end of array if input file is invalid
  o fix memory leaks
  o don't print gibberish if passed file is not an SMF file
  o report errors through moab::Error rather than printing to std::cerr
  o include line number in error messages


Modified: MOAB/trunk/src/io/ReadSmf.cpp
===================================================================
--- MOAB/trunk/src/io/ReadSmf.cpp	2010-05-03 02:07:26 UTC (rev 3833)
+++ MOAB/trunk/src/io/ReadSmf.cpp	2010-05-03 17:59:53 UTC (rev 3834)
@@ -55,21 +55,20 @@
     { "scale", &ReadSmf::scale },
     { "rot", &ReadSmf::rot },
 
-    { "", NULL }
+    { NULL, NULL }
 };
 
-AffineXform mat_from_args(std::vector<std::string> & argv)
+ErrorCode ReadSmf::parse_mat(const std::vector<std::string> & argv, AffineXform& mat)
 {
-    double m3[9], offset[3];
-    for (int i=0; i<9; i++)
-	m3[i] = atof(argv[i].c_str());
-    for (int j=0; j<3; j++)
-	offset[j] = atof(argv[j+9].c_str());// only the first 12 are used, the last row (or column?) is 0001?
-    AffineXform M(m3, offset);
-    return M;
+    double values[12];
+    ErrorCode err = parse_doubles( 12, argv, values );
+    if (MB_SUCCESS != err) return err;
+    
+    mat = AffineXform(values, values+9);
+    return MB_SUCCESS;
 }
 
-void bad_annotation(char *cmd)
+void ReadSmf::bad_annotation(const char *cmd)
 {
     std::cerr << "SMF: Malformed annotation ["<< cmd << "]" << std::endl;
 }
@@ -115,6 +114,10 @@
                                 const Tag* file_id_tag) 
 {
   ErrorCode result;
+  lineNo = 0;
+  commandNo = 0;
+  versionMajor = 0;
+  versionMinor = 0;
   
   if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for VTK." );
@@ -133,13 +136,16 @@
   {
     return MB_FILE_DOES_NOT_EXIST;
   }
-  init();


More information about the moab-dev mailing list