[cig-commits] r8259 - in short/3D/PyLith/trunk: libsrc/meshio modulesrc/meshio pylith/meshio

brad at geodynamics.org brad at geodynamics.org
Fri Nov 9 15:46:10 PST 2007


Author: brad
Date: 2007-11-09 15:46:10 -0800 (Fri, 09 Nov 2007)
New Revision: 8259

Modified:
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.icc
   short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
   short/3D/PyLith/trunk/pylith/meshio/SolutionIOVTK.py
Log:
Added ability to specify format of time stamp in VTK files.

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2007-11-09 20:00:08 UTC (rev 8258)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2007-11-09 23:46:10 UTC (rev 8259)
@@ -26,6 +26,8 @@
 // ----------------------------------------------------------------------
 // Constructor
 pylith::meshio::SolutionIOVTK::SolutionIOVTK(void) :
+  _filename("output.vtk"),
+  _timeFormat("%f"),
   _viewer(0)
 { // constructor
 } // constructor
@@ -113,7 +115,10 @@
 
     std::ostringstream buffer;
     const int indexExt = _filename.find(".vtk");
-    buffer << std::string(_filename, 0, indexExt) << "_t" << t << ".vtk";
+    char timestamp[256];
+    sprintf(timestamp, _timeFormat.c_str(), t);
+    buffer
+      << std::string(_filename, 0, indexExt) << "_t" << timestamp << ".vtk";
 
     err = PetscViewerCreate(mesh->comm(), &_viewer);
     err = PetscViewerSetType(_viewer, PETSC_VIEWER_ASCII);
@@ -131,7 +136,7 @@
     err = VTKViewer::writeElements(mesh, _viewer);
 
     buffer.str("");
-    buffer << name << "_t" << t;
+    buffer << name << "_t" << timestamp;
 
     // Now we are enforcing a 3D solution
     //   Perhaps we need to push this argument higher
@@ -167,7 +172,10 @@
 
     std::ostringstream buffer;
     const int indexExt = _filename.find(".vtk");
-    buffer << std::string(_filename, 0, indexExt) << "_t" << t << ".vtk";
+    char timestamp[256];
+    sprintf(timestamp, _timeFormat.c_str(), t);
+    buffer
+      << std::string(_filename, 0, indexExt) << "_t" << timestamp << ".vtk";
 
     err = PetscViewerCreate(mesh->comm(), &_viewer);
     err = PetscViewerSetType(_viewer, PETSC_VIEWER_ASCII);
@@ -185,7 +193,7 @@
     err = VTKViewer::writeElements(mesh, _viewer);
 
     buffer.str("");
-    buffer << name << "_t" << t;
+    buffer << name << "_t" << timestamp;
 
    err = PetscViewerPushFormat(_viewer, PETSC_VIEWER_ASCII_VTK_CELL);
 

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2007-11-09 20:00:08 UTC (rev 8258)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2007-11-09 23:46:10 UTC (rev 8259)
@@ -47,6 +47,18 @@
    */
   const char* filename(void) const;
 
+  /** Set time format for time stamp in name of VTK file.
+   *
+   * @param format C style time format for filename.
+   */
+  void timeFormat(const char* format);
+
+  /** Get time format for time stamp in name of VTK file.
+   *
+   * @returns C Style time format for filename.
+   */
+  const char* timeFormat(void) const;
+
   /** Open output files.
    *
    * @param mesh PETSc mesh object
@@ -92,6 +104,7 @@
 public :
 
   std::string _filename; ///< Name of VTK file.
+  std::string _timeFormat; ///< C style time format for time stamp.
 
   PetscViewer _viewer; ///< Output file
 

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.icc	2007-11-09 20:00:08 UTC (rev 8258)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.icc	2007-11-09 23:46:10 UTC (rev 8259)
@@ -28,6 +28,20 @@
   return _filename.c_str();
 }
 
+// Set time format for time stamp in name of VTK file.
+inline
+void
+pylith::meshio::SolutionIOVTK::timeFormat(const char* format) {
+  _timeFormat = format;
+}
+
+// Get time format for time stamp in name of VTK file.
+inline
+const char*
+pylith::meshio::SolutionIOVTK::timeFormat(void) const {
+  return _timeFormat.c_str();
+}
+
 #endif
 
 // End of file

Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2007-11-09 20:00:08 UTC (rev 8258)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2007-11-09 23:46:10 UTC (rev 8259)
@@ -841,5 +841,26 @@
       #}embed
       return SolutionIOVTK_filename_get(self.thisptr)
 
+  property timeFormat:
+    def __set__(self, format):
+      """Set timeFormat."""
+      # create shim for method 'timeFormat'
+      #embed{ void SolutionIOVTK_timeFormat_set(void* objVptr, char* format)
+      try {
+        assert(0 != objVptr);
+        ((pylith::meshio::SolutionIOVTK*) objVptr)->timeFormat(format);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (const ALE::Exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.msg().c_str()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      SolutionIOVTK_timeFormat_set(self.thisptr, format)
 
+
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/meshio/SolutionIOVTK.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/SolutionIOVTK.py	2007-11-09 20:00:08 UTC (rev 8258)
+++ short/3D/PyLith/trunk/pylith/meshio/SolutionIOVTK.py	2007-11-09 23:46:10 UTC (rev 8259)
@@ -38,7 +38,8 @@
     ## Python object for managing SolutionIOVTK facilities and properties.
     ##
     ## \b Properties
-    ## @li \b filename Name of mesh file
+    ## @li \b filename Name of mesh file.
+    ## @li \b timeFormat C style format string for time stamp in filename.
     ##
     ## \b Facilities
     ## @li None
@@ -48,7 +49,10 @@
     filename = pyre.inventory.str("filename", default="output.vtk")
     filename.meta['tip'] = "Name of VTK file."
 
+    timeFormat = pyre.inventory.str("time_format", default="%f")
+    timeFormat.meta = "C style format string for time stamp in filename."
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="solutioniovtk"):
@@ -67,6 +71,7 @@
     """
     SolutionIO._configure(self)
     self.filename = self.inventory.filename
+    self.timeFormat = self.inventory.timeFormat
     return
 
 
@@ -76,6 +81,7 @@
     """
     SolutionIO._sync(self)
     self.cppHandle.filename = self.filename
+    self.cppHandle.timeFormat = self.timeFormat
     return
   
 



More information about the cig-commits mailing list