[cig-commits] r21843 - short/3D/PyLith/trunk/libsrc/pylith/meshio

brad at geodynamics.org brad at geodynamics.org
Fri Apr 12 12:25:11 PDT 2013


Author: brad
Date: 2013-04-12 12:25:11 -0700 (Fri, 12 Apr 2013)
New Revision: 21843

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFile.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileAscii.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileBinary.cc
Log:
Code cleanup.

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc	2013-04-12 17:48:52 UTC (rev 21842)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc	2013-04-12 19:25:11 UTC (rev 21843)
@@ -20,6 +20,8 @@
 
 #include "ExodusII.hh" // implementation of class methods
 
+#include "pylith/utils/petscerror.h" // USES PYLITH_METHOD_BEGIN/END
+
 #include "petsc.h" // USES MPI_Comm
 
 // :KLUDGE: Prevent NetCDF from definining MPI types
@@ -59,7 +61,11 @@
 void
 pylith::meshio::ExodusII::deallocate(void)
 { // deallocate
+  PYLITH_METHOD_BEGIN;
+
   close();
+
+  PYLITH_METHOD_END;
 } // deallocate
 
 // ----------------------------------------------------------------------
@@ -83,6 +89,8 @@
 void
 pylith::meshio::ExodusII::open(void)
 { // open
+  PYLITH_METHOD_BEGIN;
+
   close();
 
   _file = new NcFile(_filename.c_str());
@@ -92,6 +100,8 @@
 	<< "' for reading.\n";
     throw std::runtime_error(msg.str());
   } // if
+
+  PYLITH_METHOD_END;
 } // open
 
 // ----------------------------------------------------------------------
@@ -99,9 +109,13 @@
 void
 pylith::meshio::ExodusII::close(void)
 { // close
+  PYLITH_METHOD_BEGIN;
+
   if (_file)
     _file->close();
   delete _file; _file = 0;
+
+  PYLITH_METHOD_END;
 } // close
 
 // ----------------------------------------------------------------------
@@ -109,6 +123,8 @@
 bool
 pylith::meshio::ExodusII::hasDim(const char* name) const
 { // hasDim
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
 
   bool found = false;
@@ -123,7 +139,7 @@
     } // if
   } // for
   
-  return found;
+  PYLITH_METHOD_RETURN(found);
 } // hasDim
 
 // ----------------------------------------------------------------------
@@ -131,6 +147,8 @@
 bool
 pylith::meshio::ExodusII::hasAtt(const char* name) const
 { // hasAtt
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
 
   bool found = false;
@@ -147,7 +165,7 @@
     delete att; att = 0;
   } // for
   
-  return found;
+  PYLITH_METHOD_RETURN(found);
 } // hasAtt
 
 // ----------------------------------------------------------------------
@@ -155,6 +173,8 @@
 bool
 pylith::meshio::ExodusII::hasVar(const char* name) const
 { // hasVar
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
 
   bool found = false;
@@ -169,7 +189,7 @@
     } // if
   } // for
 
-  return found;
+  PYLITH_METHOD_RETURN(found);
 } // hasVar
 
 // ----------------------------------------------------------------------
@@ -177,6 +197,8 @@
 int
 pylith::meshio::ExodusII::getDim(const char* name) const
 { // getDim
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
 
   if (!hasDim(name)) {
@@ -187,7 +209,7 @@
   
   NcDim* dim = _file->get_dim(name);
   assert(dim);
-  return dim->size();
+  PYLITH_METHOD_RETURN(dim->size());
 } // getDim
 
 // ----------------------------------------------------------------------
@@ -198,6 +220,8 @@
 				 int ndims,
 				 const char* name) const
 { // getVar
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
   assert(values);
 
@@ -236,6 +260,8 @@
     msg << "Coult not get values for variable '" << name << ".";
     throw std::runtime_error(msg.str());
   } // if
+
+  PYLITH_METHOD_END;
 } // getVar
 
 // ----------------------------------------------------------------------
@@ -246,6 +272,8 @@
 				 int ndims,
 				 const char* name) const
 { // getVar
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
   assert(values);
 
@@ -284,6 +312,8 @@
     msg << "Coult not get values for variable '" << name << ".";
     throw std::runtime_error(msg.str());
   } // if
+
+  PYLITH_METHOD_END;
 } // getVar
 
 // ----------------------------------------------------------------------
@@ -293,6 +323,8 @@
 				 int dim,
 				 const char* name) const
 { // getVar
+  PYLITH_METHOD_BEGIN;
+
   assert(_file);
   assert(values);
   
@@ -328,6 +360,8 @@
   } // for
   delete[] buffer; buffer = 0;
   delete[] counts; counts = 0;
+
+  PYLITH_METHOD_END;
 } // getVar
 
 

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFile.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFile.cc	2013-04-12 17:48:52 UTC (rev 21842)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFile.cc	2013-04-12 19:25:11 UTC (rev 21843)
@@ -22,6 +22,8 @@
 
 #include "GMVFileAscii.hh"
 
+#include "pylith/utils/petscerror.h" // USES PYLITH_METHOD_BEGIN/END
+
 #include <fstream> // uses std::fstream
 #include <sstream> // uses std::ostringstream
 #include <cstring> // uses strcmp()
@@ -42,6 +44,8 @@
 bool
 pylith::meshio::GMVFile::isAscii(const char* filename)
 { // isAscii
+  PYLITH_METHOD_BEGIN;
+
   std::ifstream fin(filename);
   if (!(fin.is_open() && fin.good())) {
     std::ostringstream msg;
@@ -52,7 +56,9 @@
   char buffer[headerLen];
   fin.get(buffer, headerLen, '\n');
   fin.close();
-  return (0 == strcmp(GMVFileAscii::header(), buffer)) ? true : false;
+
+  const bool result = (0 == strcmp(GMVFileAscii::header(), buffer)) ? true : false;
+  PYLITH_METHOD_RETURN(result);
 } // isAscii
 
 

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileAscii.cc	2013-04-12 17:48:52 UTC (rev 21842)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileAscii.cc	2013-04-12 19:25:11 UTC (rev 21843)
@@ -21,6 +21,7 @@
 #include "GMVFileAscii.hh" // implementation of class methods
 
 #include "pylith/utils/array.hh" // USES scalar_array, int_array
+#include "pylith/utils/petscerror.h" // USES PYLITH_METHOD_BEGIN/END
 
 #include "journal/info.h" // USES journal::info_t
 
@@ -59,15 +60,17 @@
 				   int* numCells,
 				   int* numCorners)
 { // read
-  assert(0 != coordinates);
-  assert(0 != cells);
-  assert(0 != materialIds);
-  assert(0 != meshDim);
-  assert(0 != spaceDim);
-  assert(0 != numVertices);
-  assert(0 != numCells);
-  assert(0 != numCorners);
+  PYLITH_METHOD_BEGIN;
 
+  assert(coordinates);
+  assert(cells);
+  assert(materialIds);
+  assert(meshDim);
+  assert(spaceDim);
+  assert(numVertices);
+  assert(numCells);
+  assert(numCorners);
+
   *meshDim = 3;
 
   journal::info_t info("gmvfile");
@@ -103,6 +106,8 @@
   assert(coordinates->size() == (*numVertices) * (*spaceDim));
   assert(cells->size() == (*numCells) * (*numCorners));
   assert(materialIds->size() == *numCells);
+
+  PYLITH_METHOD_END;
 } // read
 
 // ----------------------------------------------------------------------
@@ -117,6 +122,8 @@
 				    const int numCells,
 				    const int numCorners)
 { // write
+  PYLITH_METHOD_BEGIN;
+
   assert(coordinates.size() == numVertices * spaceDim);
   assert(cells.size() == numCells * numCorners);
   assert(materialIds.size() == numCells);
@@ -127,16 +134,20 @@
   _writeCells(cells);
   _writeMaterials(materialIds);
 #endif
+
+  PYLITH_METHOD_END;
 } // write
 
 // ----------------------------------------------------------------------
 void
 pylith::meshio::GMVFileAscii::_readHeader(std::ifstream& fin)
 { // _readHeader
+  PYLITH_METHOD_BEGIN;
+
   const int headerLen = strlen(_HEADER)+1;
   char buffer[headerLen];
   fin.get(buffer, headerLen, '\n');
-  if (0 != strcmp(_HEADER, buffer)) {
+  if (strcmp(_HEADER, buffer)) {
     std::ostringstream msg;
     msg
       << "Header in ASCII GMV file '" << buffer
@@ -144,6 +155,8 @@
       << _HEADER << "'";
     throw std::runtime_error(msg.str());
   } // if
+
+  PYLITH_METHOD_END;
 } // _readHeader
 
 // ----------------------------------------------------------------------
@@ -153,10 +166,12 @@
 					    int* numVertices,
 					    int* spaceDim)
 { // _readVertices
-  assert(0 != coordinates);
-  assert(0 != numVertices);
-  assert(0 != spaceDim);
+  PYLITH_METHOD_BEGIN;
 
+  assert(coordinates);
+  assert(numVertices);
+  assert(spaceDim);
+
   *spaceDim = 3;
 
   journal::info_t info("gmvfile");
@@ -173,9 +188,10 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // readVertices
 
-#include <iostream>
 // ----------------------------------------------------------------------
 void
 pylith::meshio::GMVFileAscii::_readCells(std::ifstream& fin,
@@ -183,10 +199,12 @@
 					 int* numCells,
 					 int* numCorners)
 { // readCells
-  assert(0 != cells);
-  assert(0 != numCells);
-  assert(0 != numCorners);
+  PYLITH_METHOD_BEGIN;
 
+  assert(cells);
+  assert(numCells);
+  assert(numCorners);
+
   journal::info_t info("gmvfile");
 
   *numCorners = 0;
@@ -200,7 +218,7 @@
     int numCornersCur = 0;
     fin >> cellStringCur;
     fin >> numCornersCur;
-    if (0 != *numCorners) {
+    if (*numCorners) {
       if (cellStringCur != cellString) {
 	std::ostringstream msg;
 	msg 
@@ -224,6 +242,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // readCells
 
 // ----------------------------------------------------------------------
@@ -232,6 +252,8 @@
 					     const int numVertices,
 					     const int numCells)
 { // _readVariables
+  PYLITH_METHOD_BEGIN;
+
   journal::info_t info("gmvfile");
 
   info << journal::at(__HERE__)
@@ -258,6 +280,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readVariables
 
 // ----------------------------------------------------------------------
@@ -266,6 +290,8 @@
 					 const int numVertices,
 					 const int numCells)
 { // _readFlags
+  PYLITH_METHOD_BEGIN;
+
   journal::info_t info("gmvfile");
 
   info << journal::at(__HERE__)
@@ -295,6 +321,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readFlags
 
 // ----------------------------------------------------------------------
@@ -304,8 +332,10 @@
 					     const int numVertices,
 					     const int numCells)
 { // _readMaterials
-  assert(0 != materialIds);
+  PYLITH_METHOD_BEGIN;
 
+  assert(materialIds);
+
   journal::info_t info("gmvfile");
   info << journal::at(__HERE__)
        << "Reading materials..." << journal::endl;
@@ -330,6 +360,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readMaterials
 
 

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileBinary.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileBinary.cc	2013-04-12 17:48:52 UTC (rev 21842)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/GMVFileBinary.cc	2013-04-12 19:25:11 UTC (rev 21843)
@@ -23,6 +23,7 @@
 #include "BinaryIO.hh" // USES readString()
 
 #include "pylith/utils/array.hh" // USES scalar_array, int_array
+#include "pylith/utils/petscerror.h" // USES PYLITH_METHOD_BEGIN/END
 
 #include "journal/info.h" // USES journal::info_t
 
@@ -62,15 +63,17 @@
 				    int* numCells,
 				    int* numCorners)
 { // read
-  assert(0 != coordinates);
-  assert(0 != cells);
-  assert(0 != materialIds);
-  assert(0 != meshDim);
-  assert(0 != spaceDim);
-  assert(0 != numVertices);
-  assert(0 != numCells);
-  assert(0 != numCorners);
+  PYLITH_METHOD_BEGIN;
 
+  assert(coordinates);
+  assert(cells);
+  assert(materialIds);
+  assert(meshDim);
+  assert(spaceDim);
+  assert(numVertices);
+  assert(numCells);
+  assert(numCorners);
+
   *meshDim = 3;
 
   journal::info_t info("gmvfile");
@@ -108,6 +111,8 @@
   assert(coordinates->size() == (*numVertices) * (*spaceDim));
   assert(cells->size() == (*numCells) * (*numCorners));
   assert(materialIds->size() == *numCells);
+
+  PYLITH_METHOD_END;
 } // read
 
 // ----------------------------------------------------------------------
@@ -122,6 +127,8 @@
 				     const int numCells,
 				     const int numCorners)
 { // write
+  PYLITH_METHOD_BEGIN;
+
   assert(coordinates.size() == numVertices * spaceDim);
   assert(cells.size() == numCells * numCorners);
   assert(materialIds.size() == numCells);
@@ -132,12 +139,16 @@
   _writeCells(cells);
   _writeMaterials(materialIds);
 #endif
+
+  PYLITH_METHOD_END;
 } // write
 
 // ----------------------------------------------------------------------
 void
 pylith::meshio::GMVFileBinary::_readHeader(std::ifstream& fin)
 { // _readHeader
+  PYLITH_METHOD_BEGIN;
+
   std::string header = BinaryIO::readString(fin, strlen(_HEADER));
   std::string headerE = _HEADER;
   headerE = headerE.substr(0, headerE.find_first_of(" "));
@@ -148,6 +159,8 @@
       << "' does not match anticipated header '" << headerE << "'.";
     throw std::runtime_error(msg.str());
   } // if
+
+  PYLITH_METHOD_END;
 } // _readHeader
 
 // ----------------------------------------------------------------------
@@ -157,10 +170,12 @@
 					     int* numVertices,
 					     int* spaceDim)
 { // _readVertices
-  assert(0 != coordinates);
-  assert(0 != numVertices);
-  assert(0 != spaceDim);
+  PYLITH_METHOD_BEGIN;
 
+  assert(coordinates);
+  assert(numVertices);
+  assert(spaceDim);
+
   *spaceDim = 3;
 
   journal::info_t info("gmvfile");
@@ -187,6 +202,8 @@
   
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readVertices
 
 // ----------------------------------------------------------------------
@@ -196,10 +213,12 @@
 					  int* numCells,
 					  int* numCorners)
 { // _readCells
-  assert(0 != cells);
-  assert(0 != numCells);
-  assert(0 != numCorners);
+  PYLITH_METHOD_BEGIN;
 
+  assert(cells);
+  assert(numCells);
+  assert(numCorners);
+
   journal::info_t info("gmvfile");
 
   fin.read((char*) numCells, sizeof(int));
@@ -217,7 +236,7 @@
     fin.read((char*) &numCornersCur, sizeof(int));
     if (_flipEndian)
       BinaryIO::swapByteOrder((char*) &numCornersCur, 1, sizeof(int));
-    if (0 != *numCorners) {
+    if (*numCorners) {
       if (cellStringCur != cellString) {
 	std::ostringstream msg;
 	msg 
@@ -243,6 +262,8 @@
   
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readCells
 
 // ----------------------------------------------------------------------
@@ -251,6 +272,8 @@
 					      const int numVertices,
 					      const int numCells)
 { // _readVariables
+  PYLITH_METHOD_BEGIN;
+
   journal::info_t info("gmvfile");
   info << journal::at(__HERE__)
        << "Reading variables..." << journal::endl;
@@ -274,6 +297,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readVariables
 
 // ----------------------------------------------------------------------
@@ -282,6 +307,8 @@
 					  const int numVertices,
 					  const int numCells)
 { // _readFlags
+  PYLITH_METHOD_BEGIN;
+
   journal::info_t info("gmvfile");
   info << journal::at(__HERE__)
        << "Reading flags..." << journal::endl;
@@ -313,6 +340,8 @@
   
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readFlags
 
 // ----------------------------------------------------------------------
@@ -322,8 +351,10 @@
 					      const int numVertices,
 					      const int numCells)
 { // _readMaterials
-  assert(0 != materialIds);
+  PYLITH_METHOD_BEGIN;
 
+  assert(materialIds);
+
   journal::info_t info("gmvfile");
   info << journal::at(__HERE__)
        << "Reading materials..." << journal::endl;
@@ -355,6 +386,8 @@
 
   info << journal::at(__HERE__)
        << "Done." << journal::endl;
+
+  PYLITH_METHOD_END;
 } // _readMaterials
 
 



More information about the CIG-COMMITS mailing list