[cig-commits] r6790 - in short/3D/PyLith/trunk: . libsrc libsrc/meshio libsrc/utils

brad at geodynamics.org brad at geodynamics.org
Fri May 4 20:29:42 PDT 2007


Author: brad
Date: 2007-05-04 20:29:33 -0700 (Fri, 04 May 2007)
New Revision: 6790

Added:
   short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.cc
   short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.hh
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.hh
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.icc
   short/3D/PyLith/trunk/libsrc/meshio/PsetFile.cc
   short/3D/PyLith/trunk/libsrc/meshio/PsetFile.hh
   short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc
   short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.hh
   short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.icc
   short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc
   short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.hh
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/libsrc/Makefile.am
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh
   short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh
   short/3D/PyLith/trunk/libsrc/utils/Makefile.am
Log:
Initial implementation of C++ reader for Cubit Exodus files.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/TODO	2007-05-05 03:29:33 UTC (rev 6790)
@@ -50,12 +50,23 @@
 
    c. Add unit test for IntegratorElasticity::calcTotalStrain
 
-2. Implement HDF5 output
+2. Implement MeshIOLagrit
+   b. unit tests at C++ level
+     BinaryIO
+     GMVFileAscii
+     GMVFileBinary
+     PsetFileAscii
+     PsetFileBinary
+     MeshIOLagrit
+   e. unit tests at Python level
+     MeshIOLagrit
 
-3. Implement PML boundary conditions
+3. Implement HDF5 output
 
-4. Create suite of simple full test cases
+4. Implement PML boundary conditions
 
+5. Create suite of simple full test cases
+
 ======================================================================
 SECONDARY PRIORITIES
 ======================================================================
@@ -67,16 +78,9 @@
    d. bindings
    e. unit tests at Python level
 
-2. Implement MeshIOLagrit
+2. Implement MeshIOHDF5 & HDF5 (helper class)
    a. C++ objects
    b. unit tests at C++ level
-   c. Python object (MeshIOLagrit)
-   d. bindings
-   e. unit tests at Python level
-
-3. Implement MeshIOHDF5 & HDF5 (helper class)
-   a. C++ objects
-   b. unit tests at C++ level
    c. Python object (MeshIOHDF5)
    d. bindings
    e. unit tests at Python level
@@ -85,8 +89,13 @@
 UNRESOLVED ISSUES
 ======================================================================
 
-1. Integration of nemesis (pylithic.py as mpi/python application) [Leif?]
+0. Basis functions for Lagrange elements (quad4, hex8, plus quadratic cells)
+   [Matt]
 
+1. How to get orientation of faces at vertices? [discuss with Matt]
+
+2. Integration of nemesis (pylithic.py as mpi/python application) [Leif?]
+
 ======================================================================
 THINGS WE NEED SIEVE TO DO (Matt)
 ======================================================================
@@ -164,5 +173,3 @@
 QUESTIONS FOR LEIF
 ======================================================================
 
-How do we trap C++ exceptions in Pyrex?
-

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/configure.ac	2007-05-05 03:29:33 UTC (rev 6790)
@@ -36,6 +36,14 @@
 	[enable_testing=no])
 AM_CONDITIONAL([ENABLE_TESTING], [test "$enable_testing" = yes])
 
+# CUBIT I/O w/netcdf
+AC_ARG_ENABLE([cubit],
+    [AC_HELP_STRING([--enable-cubit],
+        [enable reading/writing Cubit EXODUS files (requires netcdf) @<:@default=no@:>@])],
+	[enable_cubit=yes],
+	[enable_cubit=no])
+AM_CONDITIONAL([ENABLE_CUBIT], [test "$enable_cubit" = yes])
+
 # DOCUMENTATION w/doxygen
 AC_ARG_ENABLE([documentation],
     [AC_HELP_STRING([--enable-documentation],
@@ -104,6 +112,23 @@
   ])
 fi
 
+# CUBIT (netcdf)
+if test "$enable_cubit" = "yes" ; then
+  AC_LANG(C++)
+  AC_CHECK_HEADER([netcdfcpp.h], [], [
+    AC_MSG_ERROR([netcdf C++ header not found; try CPPFLAGS="-I<netcdf include dir>"])
+  ])
+  AC_MSG_CHECKING([for NcFile in -lnetcdfc++])
+  AC_REQUIRE_CPP
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[#include <netcdfcpp.h>]],
+	             [[NcFile ncfile("filename");]])],
+    [AC_MSG_RESULT(yes)],
+    [AC_MSG_RESULT(no)
+     AC_MSG_ERROR([netcdfc++ library not found; try LDFLAGS="-L<netcdf lib dir>"])
+  ])
+fi
+
 # PROJ4
 AC_CHECK_LIB(proj, pj_init_plus, [
   AC_CHECK_HEADER([proj_api.h], [], [

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2007-05-05 03:29:33 UTC (rev 6790)
@@ -47,15 +47,23 @@
 	materials/ElasticMaterial.cc \
 	materials/ElasticPlaneStrain.cc \
 	materials/ElasticPlaneStress.cc \
+	meshio/BinaryIO.cc \
 	meshio/GMVFile.cc \
 	meshio/GMVFileAscii.cc \
 	meshio/GMVFileBinary.cc \
 	meshio/MeshIO.cc \
 	meshio/MeshIOAscii.cc \
 	meshio/MeshIOLagrit.cc \
-	utils/Endian.cc
+	meshio/PsetFile.cc \
+	meshio/PsetFileAscii.cc \
+	meshio/PsetFileBinary.cc
 
+if ENABLE_CUBIT
+  libpylith_la_SOURCES += \
+	meshio/MeshIOCubit.cc
+endif
 
+
 INCLUDES = -I$(top_builddir)/include
 INCLUDES += $(PETSC_INCLUDE)
 

Added: short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,66 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "BinaryIO.hh" // implementation of class methods
+
+#include <fstream> // USES std::ifstream
+#include <assert.h> // USES assert()
+
+#if defined(WORDS_BIGENDIAN)
+#define NATIVE_BIG_ENDIAN
+#else
+#define NATIVE_LITTLE_ENDIAN
+#endif
+
+// ----------------------------------------------------------------------
+// Read fixed length string from file.
+std::string
+pylith::meshio::BinaryIO::readString(std::ifstream& fin,
+				     const int numChars)
+{ // readString
+  char* buffer = (numChars > 0) ? new char[numChars+1] : 0;
+  fin.read(buffer, sizeof(char)*numChars);
+  buffer[numChars] = '\0';
+
+  // get string from buffer
+  std::string bufstring(buffer);
+  delete[] buffer; buffer = 0;
+
+  // remove whitespace
+  const int iLast = bufstring.find_first_of(" ");
+
+  return bufstring.substr(0, iLast);
+} // readString
+
+// ----------------------------------------------------------------------
+// Change endian type by swapping byte order.
+void
+pylith::meshio::BinaryIO::swapByteOrder(char* vals,
+					const int numVals,
+					const int typesize)
+{ // swapByteOrder
+  assert(0 != vals);
+  const int numSwaps = sizeof(typesize) / 2;
+  for (int iVal=0; iVal < numVals; ++iVal) {
+    char* buf = (char*) (vals + iVal*typesize);
+    for (int iSwap=0, jSwap=typesize-1; iSwap < numSwaps; ++iSwap, --jSwap) {
+      char tmp = buf[iSwap];
+      buf[iSwap] = buf[jSwap];
+      buf[jSwap] = tmp;
+    } // for
+  } // for
+} // swapByteOrder
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/BinaryIO.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_binaryio_hh)
+#define pylith_meshio_binaryio_hh
+
+#include <iosfwd>
+
+namespace pylith {
+  namespace meshio {
+    class BinaryIO;
+  } // meshio
+} // pylith
+
+class pylith::meshio::BinaryIO
+{ // BinaryIO
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Read fixed length string from binary file.
+   *
+   * @param fin Input file stream
+   * @param numChars Number of characters in string.
+   */
+  static
+  std::string readString(std::ifstream& fin,
+			 const int numChars);
+
+  /** Change endian type by swapping byte order.
+   *
+   * @param vals Array of values
+   * @param numVals Number of values
+   * @param typesize Size of each value in bytes
+   */
+  static
+  void swapByteOrder(char* vals,
+		     const int numVals,
+		     const int typesize);
+
+}; // BinaryIO
+
+#endif // pylith_meshio_binaryio_hh
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -18,10 +18,9 @@
 
 #include <fstream> // USES std::ifstream
 #include <iomanip> // USES std::setw()
-#include <string> // USES std::string
+#include <assert.h> // USES assert()
 #include <sstream> // USES std::ostringstream
 #include <stdexcept> // USES std::exception
-#include <iostream> // USES std::cout
 
 // ----------------------------------------------------------------------
 const char* pylith::meshio::GMVFileAscii::_HEADER = "gmvinput ascii";

Modified: short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -27,8 +27,8 @@
 class pylith::meshio::GMVFileAscii : public GMVFile
 { // GMVFileAscii
 
+// PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
-  // PUBLIC METHODS ///////////////////////////////////////////////
 
   /** Constructor with name of GMV file.
    *
@@ -84,8 +84,8 @@
 	     const int numCells,
 	     const int numCorners);
 
+// PRIVATE METHODS //////////////////////////////////////////////////////
  private :
-  // PRIVATE METHODS //////////////////////////////////////////////
   
   /** Read header.
    *
@@ -148,8 +148,8 @@
 		      const int numVertices,
 		      const int numCells);
 
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
-  // PRIVATE METHODS //////////////////////////////////////////////
   
   /** Header in ascii GMV file */
   static const char* _HEADER;

Modified: short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -12,6 +12,8 @@
 
 #include "GMVFileBinary.hh" // implementation of class methods
 
+#include "BinaryIO.hh" // USES readString()
+
 #include "pylith/utils/array.hh" // USES double_array, int_array
 #include "pylith/utils/Endian.hh" // USES Endian
 
@@ -19,10 +21,9 @@
 
 #include <fstream> // USES std::ifstream
 #include <iomanip> // USES std::setw()
-#include <string> // USES std::string
+#include <assert.h> // USES assert()
 #include <sstream> // USES std::ostringstream
 #include <stdexcept> // USES std::exception
-#include <iostream> // USES std::cout
 
 // ----------------------------------------------------------------------
 const char* pylith::meshio::GMVFileBinary::_HEADER = "gmvinputieee    ";
@@ -127,7 +128,7 @@
 void
 pylith::meshio::GMVFileBinary::_readHeader(std::ifstream& fin)
 { // _readHeader
-  std::string header = _readString(fin, strlen(_HEADER));
+  std::string header = BinaryIO::readString(fin, strlen(_HEADER));
   std::string headerE = _HEADER;
   headerE = headerE.substr(0, headerE.find_first_of(" "));
   if (headerE != header) {
@@ -156,8 +157,8 @@
 
   fin.read((char*) numVertices, sizeof(int));
   if (_flipEndian)
-    utils::Endian::swapByteOrder((char*) numVertices, 1, sizeof(int));
-      
+    BinaryIO::swapByteOrder((char*) numVertices, 1, sizeof(int));
+  assert(*numVertices > 0);
   info << "Reading " << *numVertices << " nodes." << journal::endl;
 
   const int size = (*numVertices) * (*spaceDim);
@@ -165,7 +166,7 @@
 
   fin.read((char*) &buffer[0], size*sizeof(float));
   if (_flipEndian)
-    utils::Endian::swapByteOrder((char*) &buffer[0], size, sizeof(float));
+    BinaryIO::swapByteOrder((char*) &buffer[0], size, sizeof(float));
 
   coordinates->resize(size);
   // switch from column major to row major order
@@ -191,7 +192,7 @@
 
   fin.read((char*) numCells, sizeof(int));
   if (_flipEndian)
-    utils::Endian::swapByteOrder((char*) numCells, 1, sizeof(int));
+    BinaryIO::swapByteOrder((char*) numCells, 1, sizeof(int));
   info << "Reading " << *numCells << " cells." << journal::endl;
   std::string cellString = "";
   for (int iCell=0; iCell < *numCells; ++iCell) {
@@ -202,7 +203,7 @@
     cellStringCur[stringLen] = '\0';
     fin.read((char*) &numCornersCur, sizeof(int));
     if (_flipEndian)
-      utils::Endian::swapByteOrder((char*) numCornersCur, 1, sizeof(int));
+      BinaryIO::swapByteOrder((char*) numCornersCur, 1, sizeof(int));
     if (0 != *numCorners) {
       if (cellStringCur != cellString) {
 	std::ostringstream msg;
@@ -222,7 +223,7 @@
 	     sizeof(int)*numCornersCur);
   } // for
   if (_flipEndian)
-    utils::Endian::swapByteOrder((char*) &(*cells)[0], 
+    BinaryIO::swapByteOrder((char*) &(*cells)[0], 
 				 (*numCells)*(*numCorners), sizeof(int));
   info << "Done." << journal::endl;
 } // readCells
@@ -237,7 +238,7 @@
   info << "Reading variables..." << journal::endl;
   
   const int varNameLen = 8;
-  std::string varName = _readString(fin, varNameLen);
+  std::string varName = BinaryIO::readString(fin, varNameLen);
   while("endvars" != varName && !fin.eof() && fin.good()) {
     int varType = 0;
     fin.read((char*) &varType, sizeof(int));
@@ -248,10 +249,10 @@
       float_array vals(numCells);
       fin.read((char*) &vals[0], sizeof(float)*numCells);
     } // else
-    varName = _readString(fin, varNameLen);
+    varName = BinaryIO::readString(fin, varNameLen);
   } // while
 
-  std::cout << "Done." << std::endl;
+  info << "Done." << journal::endl;
 } // _readVariables
 
 // ----------------------------------------------------------------------
@@ -264,7 +265,7 @@
   info << "Reading flags..." << journal::endl;
 
   const int varNameLen = 8;
-  std::string varName = _readString(fin, varNameLen);
+  std::string varName = BinaryIO::readString(fin, varNameLen);
   while("endflag" != varName && !fin.eof() && fin.good()) {
     int numFlags = 0;
     fin.read((char*) &numFlags, sizeof(int));
@@ -272,7 +273,7 @@
     fin.read((char*) &varType, sizeof(int));
     for (int iFlag=0; iFlag < numFlags; ++iFlag) {
       const int flagNameLen = 8;
-      std::string flagName = _readString(fin, flagNameLen);
+      std::string flagName = BinaryIO::readString(fin, flagNameLen);
     } // for
     if (1 == varType) { // flag associated with vertices
       int_array buffer(numVertices);
@@ -281,10 +282,10 @@
       int_array buffer(numVertices);
       fin.read((char*) &buffer[0], sizeof(int)*numCells);
     } // else
-    varName = _readString(fin, varNameLen);
+    varName = BinaryIO::readString(fin, varNameLen);
   } // while
   
-  std::cout << "Done." << std::endl;
+  info << "Done." << journal::endl;
 } // _readFlags
 
 // ----------------------------------------------------------------------
@@ -306,42 +307,22 @@
 
   for (int iMat=0; iMat < numMaterials; ++iMat) {
     const int nameLen = 8;
-    std::string name = _readString(fin, nameLen);
+    std::string name = BinaryIO::readString(fin, nameLen);
   } // for
 
   if (0 == dataType) { // materials associated with cells
     materialIds->resize(numCells);
     fin.read((char*) &(*materialIds)[0], sizeof(int)*numCells);
     if (_flipEndian)
-      utils::Endian::swapByteOrder((char*) &(*materialIds)[0], numCells,
+      BinaryIO::swapByteOrder((char*) &(*materialIds)[0], numCells,
 				   sizeof(int));
   } else { // materials associated with vertices
     int_array buffer(numVertices);
     fin.read((char*) &buffer[0], sizeof(int)*numVertices);
   } // else
 
-  std::cout << "Done." << std::endl;
+  info << "Done." << journal::endl;
 } // _readMaterials
 
-// ----------------------------------------------------------------------
-// Read fixed length string from file.
-std::string
-pylith::meshio::GMVFileBinary::_readString(std::ifstream& fin,
-					   const int numChars)
-{ // _readString
-  char* buffer = (numChars > 0) ? new char[numChars+1] : 0;
-  fin.read(buffer, sizeof(char)*numChars);
-  buffer[numChars] = '\0';
 
-  // get string from buffer
-  std::string bufstring(buffer);
-  delete[] buffer; buffer = 0;
-
-  // remove whitespace
-  const int iLast = bufstring.find_first_of(" ");
-
-  return bufstring.substr(0, iLast);
-} // _readString
-
-
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -151,15 +151,6 @@
 		      const int numVertices,
 		      const int numCells);
 
-  /** Read fixed length string from file.
-   *
-   * @param fin Input file stream
-   * @param numChars Number of characters in string.
-   */
-  static
-  std::string _readString(std::ifstream& fin,
-			  const int numChars);
-  
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
   

Modified: short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Makefile.am	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/Makefile.am	2007-05-05 03:29:33 UTC (rev 6790)
@@ -21,11 +21,21 @@
 	MeshIOLagrit.hh \
 	MeshIOLagrit.icc
 
+if ENABLE_CUBIT
+  subpkginclude_HEADERS += \
+	MeshIOCubit.hh \
+	MeshIOCubit.icc
+endif
+
 noinst_HEADERS = \
+	BinaryIO.hh \
 	GMVFile.hh \
 	GMVFileAscii.hh \
 	GMVFileAscii.icc \
-	GMVFileBinary.hh
+	GMVFileBinary.hh \
+	PsetFile.hh \
+	PsetFileAscii.hh \
+	PsetFileBinary.hh
 
 # export
 clean-local: clean-subpkgincludeHEADERS

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -16,11 +16,13 @@
 
 #include "pylith/utils/array.hh" // USES double_array, int_array, string_vector
 
+#include "journal/info.h" // USES journal::info_t
+
+#include <iomanip> // USES setw(), setiosflags(), resetiosflags()
+#include <assert.h> // USES assert()
 #include <fstream> // USES std::ifstream, std::ofstream
 #include <stdexcept> // USES std::runtime_error
 #include <sstream> // USES std::ostringstream
-#include <assert.h> // USES assert()
-#include <iomanip> // USES setw(), setiosflags(), resetiosflags()
 
 // ----------------------------------------------------------------------
 const char* pylith::meshio::MeshIOAscii::groupTypeNames[] = 

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -26,7 +26,8 @@
 
 class pylith::meshio::MeshIOAscii : public MeshIO
 { // MeshIOAscii
-// PUBLIC METHODS -------------------------------------------------------
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
   static const char *groupTypeNames[];
 
@@ -48,7 +49,7 @@
    */
   const char* filename(void) const;
 
-// PROTECTED METHODS ----------------------------------------------------
+// PROTECTED METHODS ////////////////////////////////////////////////////
 protected :
 
   /// Write mesh
@@ -57,7 +58,7 @@
   /// Read mesh
   void _read(void);
 
-// PRIVATE METHODS ------------------------------------------------------
+// PRIVATE METHODS //////////////////////////////////////////////////////
 private :
 
   /** Read mesh vertices.
@@ -119,7 +120,7 @@
   void _writeGroup(std::ostream& fileout,
 		   const char* name) const;
 
-  // PRIVATE MEMBERS ----------------------------------------------------
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
   std::string _filename; ///< Name of file

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,302 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "MeshIOCubit.hh" // implementation of class methods
+
+#include "pylith/utils/array.hh" // USES double_array, int_array, string_vector
+
+#include "journal/info.h" // USES journal::info_t
+
+#include <netcdfcpp.h> // USES netcdf
+
+#include <assert.h> // USES assert()
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::MeshIOCubit::MeshIOCubit(void) :
+  _filename("")
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::MeshIOCubit::~MeshIOCubit(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Unpickle mesh
+void
+pylith::meshio::MeshIOCubit::_read(void)
+{ // _read
+  try {
+    NcFile ncfile(_filename.c_str());
+    if (!ncfile.is_valid()) {
+      std::ostringstream msg;
+      msg << "Could not open Cubit Exodus file '" << _filename
+	  << "' for reading.\n";
+      throw std::runtime_error(msg.str());
+    } // if
+
+    int meshDim = 0;
+    int spaceDim = 0;
+    int numVertices = 0;
+    int numCells = 0;
+    int numCorners = 0;
+    double_array coordinates;
+    int_array cells;
+    int_array materialIds;
+
+    NcDim* num_dim = ncfile.get_dim("num_dim");
+    if (0 == num_dim)
+      throw std::runtime_error("Could not get dimension 'num_dim'.");
+    meshDim = num_dim->size();
+
+    _readVertices(ncfile, &coordinates, &numVertices, &spaceDim);
+    _readCells(ncfile, &cells, &materialIds, &numCells, &numCorners);
+    _buildMesh(coordinates, numVertices, spaceDim,
+	       cells, numCells, numCorners, meshDim);
+    _setMaterials(materialIds);
+
+    _readGroups(ncfile);
+  } catch (std::exception& err) {
+    std::ostringstream msg;
+    msg << "Error while reading Cubit Exodus file '" << _filename << "'.\n"
+	<< err.what();
+    throw std::runtime_error(msg.str());
+  } catch (...) {
+    std::ostringstream msg;
+    msg << "Unknown error while reading Cubit Exodus file '" << _filename
+	<< "'.";
+    throw std::runtime_error(msg.str());
+  } // try/catch
+} // read
+
+// ----------------------------------------------------------------------
+// Write mesh to file.
+void
+pylith::meshio::MeshIOCubit::_write(void) const
+{ // write
+  NcFile ncfile(_filename.c_str());
+  if (!ncfile.is_valid()) {
+    std::ostringstream msg;
+    msg << "Could not open Cubit Exodus file '" << _filename
+	<< "' for writing.\n";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  _writeDimensions(ncfile);
+  _writeVariables(ncfile);
+  _writeAttributes(ncfile);
+} // write
+
+// ----------------------------------------------------------------------
+// Read mesh vertices.
+void
+pylith::meshio::MeshIOCubit::_readVertices(NcFile& ncfile,
+					   double_array* coordinates,
+					   int* numVertices, 
+					   int* numDims) const
+{ // _readVertices
+  assert(0 != coordinates);
+  assert(0 != numVertices);
+  assert(0 != numDims);
+
+  journal::info_t info("meshiocubit");
+    
+  NcDim* num_nodes = ncfile.get_dim("num_nodes");
+  if (0 == num_nodes)
+    throw std::runtime_error("Could not get dimension 'num_nodes'.");
+  *numVertices = num_nodes->size();
+  info << "Reading " << *numVertices << " vertices." << journal::endl;
+
+  NcVar* coord = ncfile.get_var("coord");
+  if (0 == coord)
+    throw std::runtime_error("Could not get variable 'coord'.");
+  if (2 != coord->num_dims())
+    throw std::runtime_error("Number of dimensions of variable 'coord' "
+			     "must be 2.");
+  const int size = coord->num_vals();
+
+  NcDim* space_dim = coord->get_dim(0);
+  if (0 == space_dim)
+    throw std::runtime_error("Could not get dimensions of coordinates.");
+  *numDims = space_dim->size();
+
+  assert((*numVertices)*(*numDims) == size);
+  coordinates->resize(size);
+  long* counts = coord->edges();
+  bool ok = coord->get(&(*coordinates)[0], counts);
+  delete[] counts; counts = 0;
+  if (!ok)
+    throw std::runtime_error("Could not get coordinate values.");
+} // _readVertices
+
+// ----------------------------------------------------------------------
+// Read mesh cells.
+void
+pylith::meshio::MeshIOCubit::_readCells(NcFile& ncfile,
+					int_array* cells,
+					int_array* materialIds,
+					int* numCells, 
+					int* numCorners) const
+{ // _readCells
+  assert(0 != cells);
+  assert(0 != materialIds);
+  assert(0 != numCells);
+  assert(0 != numCorners);
+
+  journal::info_t info("meshiocubit");
+
+  NcDim* num_elem = ncfile.get_dim("num_elem");
+  if (0 == num_elem)
+    throw std::runtime_error("Could not get dimension 'num_elem'.");
+  *numCells = num_elem->size();
+  NcDim* num_el_blk = ncfile.get_dim("num_el_blk");
+  if (0 == num_el_blk)
+    throw std::runtime_error("Could not get dimension 'num_el_blk'.");
+  const int numMaterials = num_el_blk->size();
+
+  info << "Reading " << numCells << " cells in " << numMaterials 
+       << " blocks." << journal::endl;
+
+  NcVar* eb_prop1 = ncfile.get_var("eb_prop1");
+  if (0 == eb_prop1) 
+    throw std::runtime_error("Could not get variable 'eb_prop1'.");
+  std::valarray<int> blockIds(numMaterials);
+  long* counts = eb_prop1->edges();
+  bool ok = eb_prop1->get(&blockIds[0], counts);
+  delete[] counts; counts = 0;
+  materialIds->resize(*numCells);
+
+  *numCorners = 0;
+  for (int iMaterial=0, index=0; iMaterial < numMaterials; ++iMaterial) {
+    std::ostringstream varname;
+    varname << "num_nod_per_el" << iMaterial+1;
+    NcDim* num_nod_per_el = ncfile.get_dim(varname.str().c_str());
+    if (0 == num_nod_per_el)
+      throw std::runtime_error("Could not get dimension 'num_nod_per_el'.");
+    if (0 == *numCorners) {
+      *numCorners = num_nod_per_el->size();
+      const int size = (*numCells) * (*numCorners);
+      cells->resize(size);
+    } else
+      assert(num_nod_per_el->size() == *numCorners);
+
+    varname.str("");
+    varname << "num_el_in_blk" << iMaterial+1;
+    NcDim* num_el_in_blk = ncfile.get_dim(varname.str().c_str());
+    if (0 == num_el_in_blk)
+      throw std::runtime_error("Could not get dimension 'num_el_in_blk'.");
+    const int blockSize = num_el_in_blk->size();
+	
+    varname.str("");
+    varname << "connect" << iMaterial+1;
+    NcVar* connect = ncfile.get_var(varname.str().c_str());
+    if (0 == connect)
+      throw std::runtime_error("Could not get variable 'connect'.");
+    if (2 != connect->num_dims())
+      throw std::runtime_error("Number of dimensions of variable "
+			       "'connect' must be 2.");
+    const int size = connect->num_vals();
+    assert(blockSize * (*numCorners) == size);
+    long* counts = connect->edges();
+    bool ok = connect->get(&(*cells)[index * (*numCorners)], counts);
+    delete[] counts; counts = 0;
+    if (!ok)
+      throw std::runtime_error("Could not get cell values.");
+	
+    for (int i=0; i < blockSize; ++i)
+      materialIds[index+i] = blockIds[iMaterial];
+    
+    index += blockSize;
+  } // for
+  cells -= 1; // use zero index
+} // _readCells
+
+// ----------------------------------------------------------------------
+// Read mesh groups.
+void
+pylith::meshio::MeshIOCubit::_readGroups(NcFile& ncfile)
+{ // _readGroups
+  journal::info_t info("meshiocubit");
+
+  NcDim* num_node_sets = ncfile.get_dim("num_node_sets");
+  if (0 == num_node_sets)
+    throw std::runtime_error("Could not get dimension 'num_node_sets'.");
+  const int numGroups = num_node_sets->size();
+  info << "Found " << numGroups << " node sets." << journal::endl;
+      
+  NcVar* ns_prop1 = ncfile.get_var("ns_prop1");
+  if (0 == ns_prop1) 
+    throw std::runtime_error("Could not get variable 'ns_prop1'.");
+  std::valarray<int> ids(numGroups);
+  long* counts = ns_prop1->edges();
+  bool ok = ns_prop1->get(&ids[0], counts);
+  delete[] counts; counts = 0;
+      
+  for (int iGroup=0; iGroup < numGroups; ++iGroup) {
+    std::valarray<int> points;
+	
+    std::ostringstream varname;
+    varname << "node_ns" << iGroup+1;
+    NcVar* node_ns = ncfile.get_var(varname.str().c_str());
+    if (0 == node_ns)
+      throw std::runtime_error("Could not get node set.");
+    const int size = node_ns->num_vals();
+    info << "Reading node set " << ids[iGroup] << " with "
+	 << size << " nodes." << journal::endl;
+
+    points.resize(size);
+    long* counts = node_ns->edges();
+    bool ok = node_ns->get(&points[0], counts);
+    delete[] counts; counts = 0;
+    if (!ok)
+      throw std::runtime_error("Could not get node set.");
+    std::sort(&points[0], &points[size]);
+
+    GroupPtType type = VERTEX;
+    std::string name = "";
+    _setGroup(name, type, points);
+  } // for  
+} // _readGroups
+
+// ----------------------------------------------------------------------
+// Write mesh dimensions.
+void
+pylith::meshio::MeshIOCubit::_writeDimensions(NcFile& ncfile) const
+{ // _writeDimensions
+  throw std::logic_error("MeshIOCubit::_writeDimensions() not implemented.");
+} // _writeDimensions
+  
+// ----------------------------------------------------------------------
+// Write mesh variables.
+void
+pylith::meshio::MeshIOCubit::_writeVariables(NcFile& ncfile) const
+{ // _writeVariables
+  throw std::logic_error("MeshIOCubit::_writeVariables() not implemented.");
+} // _writeVariables
+  
+// ----------------------------------------------------------------------
+// Write mesh attributes.
+void
+pylith::meshio::MeshIOCubit::_writeAttributes(NcFile& ncfile) const
+{ // _writeAttributes
+  throw std::logic_error("MeshIOCubit::_writeAttributes() not implemented.");
+} // _writeAttributes
+
+  
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,125 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_meshiocubit_hh)
+#define pylith_meshio_meshiocubit_hh
+
+#include <string> // HASA std::string
+
+#include "MeshIO.hh"
+
+namespace pylith {
+  namespace meshio {
+    class MeshIOCubit;
+  } // meshio
+} // pylith
+
+class NcFile; // netcdf file
+
+class pylith::meshio::MeshIOCubit : public MeshIO
+{ // MeshIOCubit
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /// Constructor
+  MeshIOCubit(void);
+
+  /// Destructor
+  ~MeshIOCubit(void);
+
+  /** Set filename for Cubit file.
+   *
+   * @param filename Name of file
+   */
+  void filename(const char* name);
+
+  /** Get filename of Cubit file.
+   *
+   * @returns Name of file
+   */
+  const char* filename(void) const;
+
+// PROTECTED METHODS ////////////////////////////////////////////////////
+protected :
+
+  /// Write mesh
+  void _write(void) const;
+
+  /// Read mesh
+  void _read(void);
+
+// PRIVATE METHODS //////////////////////////////////////////////////////
+private :
+
+  /** Read mesh vertices.
+   *
+   * @param ncfile Cubit Exodus file.
+   * @param coordinates Pointer to array of vertex coordinates.
+   * @param numVertices Pointer to number of vertices.
+   * @param spaceDim Pointer to dimension of coordinates vector space.
+   */
+  void _readVertices(NcFile& filein,
+		     double_array* coordinates,
+		     int* numVertices,
+		     int* spaceDim) const;
+  
+  /** Read mesh cells.
+   *
+   * @param ncfile Cubit Exodus file.
+   * @param pCells Pointer to array of indices of cell vertices
+   * @param pMaterialIds Pointer to array of material identifiers
+   * @param pNumCells Pointer to number of cells
+   * @param pNumCorners Pointer to number of corners
+   */
+  void _readCells(NcFile& filein,
+		  int_array* pCells,
+		  int_array* pMaterialIds,
+		  int* numCells,
+		  int* numCorners) const;
+  
+  /** Read point groups.
+   *
+   * @param ncfile Cubit Exodus file.
+   */
+  void _readGroups(NcFile& filein);
+  
+  /** Write mesh dimensions.
+   *
+   * @param ncfile Cubit Exodus file.
+   */
+  void _writeDimensions(NcFile& ncfile) const;
+  
+  /** Write mesh variables.
+   *
+   * @param ncfile Cubit Exodus file.
+   */
+  void _writeVariables(NcFile& ncfile) const;
+  
+  /** Write mesh attributes.
+   *
+   * @param ncfile Cubit Exodus file.
+   */
+  void _writeAttributes(NcFile& ncfile) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  std::string _filename; ///< Name of file
+
+}; // MeshIOCubit
+
+#include "MeshIOCubit.icc" // inline methods
+
+#endif // pylith_meshio_meshiocubit_hh
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.icc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.icc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,33 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_meshiocubit_hh)
+#error "MeshIOCubit.icc must be included only from MeshIOCubit.icc"
+#else
+
+// Set filename for CUBIT file.
+inline
+void
+pylith::meshio::MeshIOCubit::filename(const char* name) {
+  _filename = name;
+}
+
+// Get filename of CUBIT file.
+inline
+const char* 
+pylith::meshio::MeshIOCubit::filename(void) const {
+  return _filename.c_str();
+}
+
+#endif
+
+// End of file

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -16,9 +16,12 @@
 
 #include "GMVFileAscii.hh" // USES GMVFileAscii
 #include "GMVFileBinary.hh" // USES GMVFileBinary
+#include "PsetFileAscii.hh" // USES PsetFileAscii
 
 #include "pylith/utils/array.hh" // USES double_array, int_array
 
+#include <stdexcept> // TEMPORARY
+
 // ----------------------------------------------------------------------
 // Constructor
 pylith::meshio::MeshIOLagrit::MeshIOLagrit(void) :
@@ -62,15 +65,28 @@
   _setMaterials(materialIds);
 
 #if 0
-  if (PsetFile::_isPsetAscii(_filenamePset)) {
-    PsetFileAscii filein(_filenamePset);
-    filein.read();
+  std::vector<PsetFile::Pset> groups;
+  if (PsetFile::isAscii(_filenamePset.c_str())) {
+    PsetFileAscii filein(_filenamePset.c_str());
+    filein.read(&groups);
   } else {
-    PsetFileBinary filein(_filenamePset);
-    filein.read();
+    PsetFileBinary filein(_filenamePset.c_str());
+    filein.read(&groups);
   } // if/else
+  GroupPtType type = VERTEX;
+  const int numGroups = groups.size();
+  for (int iGroup=0; iGroup < numGroups; ++iGroup)
+    _setGroup(groups[iGroup].name, type, groups[iGroup].points);
 #endif
 } // _read
 
+// ----------------------------------------------------------------------
+// Pickle mesh
+void
+pylith::meshio::MeshIOLagrit::_write(void) const
+{ // _write
+  throw std::logic_error("MeshIOLagrit::_write not implemented.");
+} // _write
+
   
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -25,7 +25,8 @@
 
 class pylith::meshio::MeshIOLagrit : public MeshIO
 { // MeshIOLagrit
-// PUBLIC METHODS -------------------------------------------------------
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
 
   /// Constructor
@@ -82,7 +83,7 @@
    */
   bool flipEndian(void) const;
 
-// PROTECTED METHODS ----------------------------------------------------
+// PROTECTED METHODS ////////////////////////////////////////////////////
 protected :
 
   /// Write mesh
@@ -91,52 +92,10 @@
   /// Read mesh
   void _read(void);
 
-// PRIVATE METHODS ------------------------------------------------------
+// PRIVATE METHODS //////////////////////////////////////////////////////
 private :
 
-  /** Header in ascii GMV file */
-  static const char* GMVASCIIHEADER;
-
-  /** Header in binary GMV file */
-  static const char* GMVBINARYHEADER;
-
-  /** Is GMV file an ASCII file?
-   *
-   * @returns true if GMV file is ASCII, false if binary
-   */
-  bool _isGmvAscii(void) const;
-
-  /// Read ASCII GMV file.
-  void _readGmvAscii(void);
-
-  /// Read binary GMV file.
-  void _readGmvBinary(void);
-
-  /// Write ASCII GMV file.
-  void _writeGmvAscii(void) const;
-
-  /// Read binary GMV file.
-  void _writeGmvBinary(void) const;
-
-  /** Is PSET file an ASCII file?
-   *
-   * @returns true if PSET file is ASCII, false if binary
-   */
-  bool _isPsetAscii(void) const;
-
-  /// Read ASCII PSET file.
-  void _readPsetAscii(void);
-
-  /// Read binary PSET file.
-  void _readPsetBinary(void);
-
-  /// Write ASCII PSET file.
-  void _writePsetAscii(void) const;
-
-  /// Write binary PSET file.
-  void _writePsetBinary(void) const;
-
-  // PRIVATE MEMBERS ----------------------------------------------------
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
   std::string _filenameGmv; ///< Name of GMV file

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFile.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFile.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFile.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "PsetFile.hh" // implementation of class methods
+
+#include "PsetFileAscii.hh"
+
+#include <fstream> // uses std::fstream
+#include <sstream> // uses std::ostringstream
+#include <stdexcept> // USES std::runtime_error
+
+// ----------------------------------------------------------------
+pylith::meshio::PsetFile::PsetFile(const char* filename) :
+  _filename(filename)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------
+pylith::meshio::PsetFile::~PsetFile(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------
+bool
+pylith::meshio::PsetFile::isAscii(const char* filename)
+{ // isAscii
+  std::ifstream fin(filename);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg << "Could not open Pset file '" << filename << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+  const int headerLen = strlen(PsetFileAscii::header())+1;
+  char buffer[headerLen];
+  fin.get(buffer, headerLen, '\n');
+  fin.close();
+  return (0 == strcmp(PsetFileAscii::header(), buffer)) ? true : false;
+} // isAscii
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFile.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFile.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFile.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,68 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_psetfile_hh)
+#define pylith_meshio_psetfile_hh
+
+#include "pylith/utils/array.hh" // USES int_array
+#include <string> // HASA std::string
+
+namespace pylith {
+  namespace meshio {
+  class PsetFile;
+  } // meshio
+} // pylith
+
+class pylith::meshio::PsetFile
+{ // PsetFile
+
+// PUBLIC TYPES /////////////////////////////////////////////////////////
+public :
+
+  struct Pset {
+    int_array points; ///< Indices of vertices in group
+    std::string name; ///< Name of group
+    int id; ///< Id of group
+  }; // Pset
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with name of Pset file.
+   *
+   * @param filename Name of Pset file
+   */
+  PsetFile(const char* name);
+
+  /// Default destructor.
+  ~PsetFile(void);
+
+  /** Is Pset file ascii?
+   *
+   * @param filename Name of Pset file.
+   *
+   * @returns True if Pset file is ascii, false otherwise
+   */
+  static
+  bool isAscii(const char* filename);
+
+// PROTECTED MEMBERS ////////////////////////////////////////////////////
+protected :
+
+  std::string _filename; ///< Name of Pset file
+  
+}; // PsetFile
+
+#endif // pylith_meshio_psetfile_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,174 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "PsetFileAscii.hh" // implementation of class methods
+
+#include "pylith/utils/array.hh" // USES double_array, int_array
+
+#include "journal/info.h" // USES journal::info_t
+
+#include <fstream> // USES std::ifstream
+#include <iomanip> // USES std::setw()
+#include <assert.h> // USES assert()
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::exception
+
+// ----------------------------------------------------------------------
+const char* pylith::meshio::PsetFileAscii::_HEADER = "pset ascii";
+
+// ----------------------------------------------------------------------
+// Constructor with name of Pset file.
+pylith::meshio::PsetFileAscii::PsetFileAscii(const char* filename) :
+  PsetFile(filename)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor 
+pylith::meshio::PsetFileAscii::~PsetFileAscii(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Read ASCII Pset file.
+void
+pylith::meshio::PsetFileAscii::read(std::vector<Pset>* groups)
+{ // read
+  assert(0 != groups);
+
+  journal::info_t info("psetfile");
+
+  std::ifstream fin(_filename.c_str(), std::ios::in);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open ASCII Pset file '" << _filename
+      << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Reading ASCII Pset file '" << _filename << "'." << journal::endl;
+
+  _readHeader(fin);
+
+  // Read number of psets
+  int numGroups = 0;
+  fin >> numGroups;
+  groups->resize(numGroups);
+
+  // Read groups
+  info << "Reading " << numGroups << " point sets from file." << journal::endl;
+  for (int iGroup=0; iGroup < numGroups; ++iGroup)
+    _readPset(fin, &(*groups)[iGroup]);
+} // read
+
+// ----------------------------------------------------------------------
+// Write ASCII Pset file.
+void
+pylith::meshio::PsetFileAscii::write(const std::vector<Pset>& groups)
+{ // write
+  journal::info_t info("psetfile");
+
+  std::ofstream fout(_filename.c_str(), std::ios::out);
+  if (!(fout.is_open() && fout.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open ASCII Pset file '" << _filename
+      << "' for writing.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Writing ASCII Pset file '" << _filename << "'." << journal::endl;
+
+  _writeHeader(fout);
+
+  // Write number of groups
+  const int numGroups = groups.size();
+  fout << std::setw(4) << numGroups << std::endl;
+
+  // Write groups
+  info << "Writing " << numGroups << " point sets to file." << journal::endl;
+  for (int iGroup=0; iGroup < numGroups; ++iGroup)
+    _writePset(fout, groups[iGroup]);
+} // write
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileAscii::_readHeader(std::ifstream& fin)
+{ // _readHeader
+  const int headerLen = strlen(_HEADER)+1;
+  char buffer[headerLen];
+  fin.get(buffer, headerLen, '\n');
+  if (0 != strcmp(_HEADER, buffer)) {
+    std::ostringstream msg;
+    msg
+      << "Header in ASCII Pset file '" << buffer
+      << "' does not match anticipated header '"
+      << _HEADER << "'";
+    throw std::runtime_error(msg.str());
+  } // if
+} // _readHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileAscii::_writeHeader(std::ofstream& fout)
+{ // _writeHeader
+  fout << _HEADER << std::endl;
+} // _writeHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileAscii::_readPset(std::ifstream& fin,
+					 Pset* group)
+{ // _readPset
+  assert(0 != group);
+
+  journal::info_t info("psetfile");
+
+  int size = 0;
+  fin >> group->id >> group->name >> size;
+  info << "Reading point set '" << group->name << "' with " << size
+       << " points." << journal::endl;
+
+  group->points.resize(size);
+  for (int i=0; i < size; ++i)
+    fin >> group->points[i];
+
+  info << "Done." << journal::endl;
+} // _readPset
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileAscii::_writePset(std::ofstream& fout,
+					  const Pset& group)
+{ // _writePset
+  journal::info_t info("psetfile");
+  const int size = group.points.size();
+  info << "Writing point set '" << group.name << "' with " << size
+       << " points." << journal::endl;
+
+  fout << group.id << "  " << group.name << " " << size << std::endl;
+
+  const int numCols = 10;
+  for (int i=0, iCol=0; i < size; ++i) {
+    fout << std::setw(8) << group.points[i];
+    if (++iCol == numCols) {
+      fout << std::endl;
+      iCol = 0;
+    } // if
+  } // for
+
+  info << "Done." << journal::endl;
+} // _writePset
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,104 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_psetfileascii_hh)
+#define pylith_meshio_psetfileascii_hh
+
+#include "PsetFile.hh" // ISA PsetFile
+
+#include "pylith/utils/array.hh" // USES int_array, string_array, std::vector
+#include <iosfwd>
+
+namespace pylith {
+  namespace meshio {
+    class PsetFileAscii;
+  } // meshio
+} // pylith
+
+class pylith::meshio::PsetFileAscii : public PsetFile
+{ // PsetFileAscii
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with name of Pset file.
+   *
+   * @param filename Name of Pset file
+   */
+  PsetFileAscii(const char* name);
+
+  /// Default destructor 
+  ~PsetFileAscii(void);
+
+  /** Get header.
+   *
+   * @returns Header that appears in ASCII Pset file
+   */
+  static const char* header(void);
+
+  /** Read ASCII Pset file.
+   *
+   * @param groups Array of point sets.
+   */
+  void read(std::vector<Pset>* groups);
+
+  /** Write ASCII Pset file.
+   *
+   * @param groups Array of point sets.
+   */
+  void write(const std::vector<Pset>& groups);
+
+// PRIVATE METHODS //////////////////////////////////////////////////////
+private :
+  
+  /** Read header.
+   *
+   * @param fin Input file stream
+   */
+  void _readHeader(std::ifstream& fin);
+
+  /** Write header.
+   *
+   * @param fout Output file stream
+   */
+  void _writeHeader(std::ofstream& fout);
+
+  /** Read point set.
+   *
+   * @param fin Input file stream.
+   * @param group Point set
+   */
+  void _readPset(std::ifstream& fin,
+		 Pset* group);
+
+  /** Write point set.
+   *
+   * @param fout Output file stream.
+   * @param group Point set
+   */
+  void _writePset(std::ofstream& fout,
+		  const Pset& group);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+  
+  /** Header in ascii Pset file */
+  static const char* _HEADER;
+
+}; // PsetFileInAscii
+
+#include "PsetFileAscii.icc" // inline methods
+
+#endif // pylith_meshio_psetfileascii
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.icc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.icc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_psetfileascii_hh)
+#error "PsetFileAscii.icc must be included only from PsetFileAscii.icc"
+#else
+
+// ----------------------------------------------------------------
+// Get header.
+inline
+const char*
+pylith::meshio::PsetFileAscii::header(void)
+{ // header
+  return _HEADER;
+} // header
+
+#endif
+
+// End of file

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,198 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "PsetFileBinary.hh" // implementation of class methods
+
+#include "BinaryIO.hh" // USES readString()
+
+#include "pylith/utils/array.hh" // USES double_array, int_array
+
+#include "journal/info.h" // USES journal::info_t
+
+#include <fstream> // USES std::ifstream
+#include <iomanip> // USES std::setw()
+#include <assert.h> // USES assert()
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::exception
+
+// ----------------------------------------------------------------------
+const char* pylith::meshio::PsetFileBinary::_HEADER = "pset binary";
+
+// ----------------------------------------------------------------------
+// Constructor with name of Pset file.
+pylith::meshio::PsetFileBinary::PsetFileBinary(const char* filename,
+					       const bool flipEndian) :
+  PsetFile(filename),
+  _flipEndian(flipEndian)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor 
+pylith::meshio::PsetFileBinary::~PsetFileBinary(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Read binary Pset file.
+void
+pylith::meshio::PsetFileBinary::read(std::vector<Pset>* groups)
+{ // read
+  assert(0 != groups);
+
+  journal::info_t info("psetfile");
+
+  std::ifstream fin(_filename.c_str(), std::ios::in);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open binary Pset file '" << _filename
+      << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Reading binary Pset file '" << _filename << "'." << journal::endl;
+
+  _readHeader(fin);
+
+  // Read number of psets
+  int numGroups = 0;
+  fin.read((char*) numGroups, sizeof(int));
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &numGroups, 1, sizeof(int));
+  assert(numGroups >= 0);
+  groups->resize(numGroups);
+
+  // Read groups
+  info << "Reading " << numGroups << " point sets from file." << journal::endl;
+  for (int iGroup=0; iGroup < numGroups; ++iGroup)
+    _readPset(fin, &(*groups)[iGroup]);
+} // read
+
+// ----------------------------------------------------------------------
+// Write binary Pset file.
+void
+pylith::meshio::PsetFileBinary::write(const std::vector<Pset>& groups)
+{ // write
+  journal::info_t info("psetfile");
+
+  std::ofstream fout(_filename.c_str(), std::ios::out);
+  if (!(fout.is_open() && fout.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open binary Pset file '" << _filename
+      << "' for writing.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Writing binary Pset file '" << _filename << "'." << journal::endl;
+
+  _writeHeader(fout);
+
+  // Write number of groups
+  int numGroups = groups.size();
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &numGroups, 1, sizeof(numGroups));
+  fout.write((char*) &numGroups, sizeof(numGroups));
+
+  // Write groups
+  info << "Writing " << numGroups << " point sets to file." << journal::endl;
+  for (int iGroup=0; iGroup < numGroups; ++iGroup)
+    _writePset(fout, groups[iGroup]);
+} // write
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileBinary::_readHeader(std::ifstream& fin)
+{ // _readHeader
+  std::string header = BinaryIO::readString(fin, strlen(_HEADER));
+  std::string headerE = _HEADER;
+  headerE = headerE.substr(0, headerE.find_first_of(" "));
+  if (headerE != header) {
+    std::ostringstream msg;
+    msg
+      << "Header in binary Pset file '" << header
+      << "' does not match anticipated header '" << headerE << "'.";
+    throw std::runtime_error(msg.str());
+  } // if
+} // _readHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileBinary::_writeHeader(std::ofstream& fout)
+{ // _writeHeader
+  fout.write((char*) _HEADER, strlen(_HEADER));
+} // _writeHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileBinary::_readPset(std::ifstream& fin,
+					 Pset* group)
+{ // _readPset
+  assert(0 != group);
+
+  journal::info_t info("psetfile");
+
+  int id = 0;
+  fin.read((char*) &id, sizeof(int));
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &id, 1, sizeof(id));
+  group->name = BinaryIO::readString(fin, 8);
+  int size = 0;
+  fin.read((char*) &size, sizeof(int));
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &size, 1, sizeof(size));
+  assert(size >= 0);
+
+  info << "Reading point set '" << group->name << "' with " << size
+       << " points." << journal::endl;
+
+  group->points.resize(size);
+  fin.read((char*) &group->points[0], size*sizeof(int));
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &group->points[0], size, sizeof(int));
+
+  info << "Done." << journal::endl;
+} // _readPset
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::PsetFileBinary::_writePset(std::ofstream& fout,
+					   const Pset& group)
+{ // _writePset
+  journal::info_t info("psetfile");
+  const int size = group.points.size();
+  info << "Writing point set '" << group.name << "' with " << size
+       << " points." << journal::endl;
+
+  int id = group.id;
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &id, 1, sizeof(id));
+  fout.write((char*) &id, sizeof(int));
+
+  fout.write((char*) group.name.c_str(), 8);
+
+  int sizeIO = size;
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &sizeIO, 1, sizeof(sizeIO));
+  fout.write((char*) &sizeIO, sizeof(int));
+
+  int_array pointsIO(group.points);
+  if (_flipEndian)
+    BinaryIO::swapByteOrder((char*) &pointsIO[0], size, sizeof(int));
+  fout.write((char*) &pointsIO[0], size*sizeof(int));
+
+  info << "Done." << journal::endl;
+} // _writePset
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.hh	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.hh	2007-05-05 03:29:33 UTC (rev 6790)
@@ -0,0 +1,106 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_psetfilebinary_hh)
+#define pylith_meshio_psetfilebinary_hh
+
+#include "PsetFile.hh" // ISA PsetFile
+
+#include "pylith/utils/array.hh" // USES int_array, string_array, std::vector
+#include <iosfwd>
+
+namespace pylith {
+  namespace meshio {
+    class PsetFileBinary;
+  } // meshio
+} // pylith
+
+class pylith::meshio::PsetFileBinary : public PsetFile
+{ // PsetFileBinary
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with name of Pset file.
+   *
+   * @param filename Name of Pset file
+   * @param flipEndian Flip endian type when reading/writing.
+   */
+  PsetFileBinary(const char* name,
+		 const bool flipEndian);
+
+  /// Default destructor 
+  ~PsetFileBinary(void);
+
+  /** Get header.
+   *
+   * @returns Header that appears in binary Pset file
+   */
+  static const char* header(void);
+
+  /** Read binary Pset file.
+   *
+   * @param groups Array of point sets.
+   */
+  void read(std::vector<Pset>* groups);
+
+  /** Write binary Pset file.
+   *
+   * @param groups Array of point sets.
+   */
+  void write(const std::vector<Pset>& groups);
+
+// PRIVATE METHODS //////////////////////////////////////////////////////
+private :
+  
+  /** Read header.
+   *
+   * @param fin Input file stream
+   */
+  void _readHeader(std::ifstream& fin);
+
+  /** Write header.
+   *
+   * @param fout Output file stream
+   */
+  void _writeHeader(std::ofstream& fout);
+
+  /** Read point set.
+   *
+   * @param fin Input file stream.
+   * @param group Point set
+   */
+  void _readPset(std::ifstream& fin,
+		 Pset* group);
+
+  /** Write point set.
+   *
+   * @param fout Output file stream.
+   * @param group Point set
+   */
+  void _writePset(std::ofstream& fout,
+		  const Pset& group);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+  
+  /** Header in binary Pset file */
+  static const char* _HEADER;
+
+  bool _flipEndian; ///< True if need to change endian when reading/writing
+
+}; // PsetFileInBinary
+
+#endif // pylith_meshio_psetfilebinary
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/libsrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/Makefile.am	2007-05-04 21:36:52 UTC (rev 6789)
+++ short/3D/PyLith/trunk/libsrc/utils/Makefile.am	2007-05-05 03:29:33 UTC (rev 6790)
@@ -14,7 +14,6 @@
 include $(top_srcdir)/subpackage.am
 
 subpkginclude_HEADERS = \
-	Endian.hh \
 	array.hh \
 	arrayfwd.hh \
 	petscfwd.h \



More information about the cig-commits mailing list