[cig-commits] r15102 - in cs/spatialdata-0.1/trunk: libsrc libsrc/spatialdb modulesrc/geocoords modulesrc/spatialdb spatialdata/spatialdb

brad at geodynamics.org brad at geodynamics.org
Tue Jun 2 09:21:58 PDT 2009


Author: brad
Date: 2009-06-02 09:21:57 -0700 (Tue, 02 Jun 2009)
New Revision: 15102

Added:
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.hh
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.hh
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistoryIO.i
Modified:
   cs/spatialdata-0.1/trunk/libsrc/Makefile.am
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/spatialdbfwd.hh
   cs/spatialdata-0.1/trunk/modulesrc/geocoords/Converter.i
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.i
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDBObj.py
Log:
Added C++ TimeHistory object (not tested).

Modified: cs/spatialdata-0.1/trunk/libsrc/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/Makefile.am	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/libsrc/Makefile.am	2009-06-02 16:21:57 UTC (rev 15102)
@@ -38,6 +38,8 @@
 	spatialdb/SimpleDBQuery.cc \
 	spatialdb/SimpleIO.cc \
 	spatialdb/SimpleIOAscii.cc \
+	spatialdb/TimeHistory.cc \
+	spatialdb/TimeHistoryIO.cc \
 	spatialdb/UniformDB.cc \
 	spatialdb/cspatialdb.cc	\
 	units/Nondimensional.cc \

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am	2009-06-02 16:21:57 UTC (rev 15102)
@@ -34,6 +34,9 @@
 	SimpleDBQuery.hh \
 	SimpleDBData.hh \
 	SimpleDBData.icc \
+	TimeHistory.hh \
+	TimeHistory.icc \
+	TimeHistoryIO.hh \
 	UniformDB.hh \
 	UniformDB.icc \
 	spatialdbfwd.hh

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh	2009-06-02 16:21:57 UTC (rev 15102)
@@ -21,6 +21,8 @@
 #include "spatialdbfwd.hh"
 #include "spatialdata/geocoords/geocoordsfwd.hh"
 
+#include <string> // USES std::string
+
 /// C++ manager for spatial database.
 class spatialdata::spatialdb::SpatialDB
 { // class SpatialDB
@@ -104,7 +106,7 @@
  // PRIVATE MEMBERS ////////////////////////////////////////////////////
   
   /** Label of spatial database */
-  const char* _label;
+  std::string _label;
 
 }; // class SpatialDB
 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc	2009-06-02 16:21:57 UTC (rev 15102)
@@ -17,14 +17,16 @@
 // Set label of spatial database.
 inline
 void
-spatialdata::spatialdb::SpatialDB::label(const char* label)
-{ _label = label; }
+spatialdata::spatialdb::SpatialDB::label(const char* label) {
+  _label = label;
+}
   
 // Get label of spatial database.
 inline
 const char*
-spatialdata::spatialdb::SpatialDB::label(void) const
-{ return _label; }
+spatialdata::spatialdb::SpatialDB::label(void) const {
+  return _label.c_str();
+}
 
 
 // End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.cc	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.cc	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,113 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TimeHistory.hh" // Implementation of class methods
+
+#include "TimeHistoryIO.hh" // USES TimeHistory
+
+#include <cassert> // USES assert()
+
+// ----------------------------------------------------------------------
+/// Default constructor
+spatialdata::spatialdb::TimeHistory::TimeHistory(void) :
+  _label(""),
+  _filename(""),
+  _time(0),
+  _amplitude(0),
+  _npts(0),
+  _ilower(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+/// Constructor with label
+spatialdata::spatialdb::TimeHistory::TimeHistory(const char* label) :
+  _label(label),
+  _filename(""),
+  _time(0),
+  _amplitude(0),
+  _npts(0),
+  _ilower(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+/// Default destructor
+spatialdata::spatialdb::TimeHistory::~TimeHistory(void)
+{ // destructor
+  delete[] _time; _time = 0;
+  delete[] _amplitude; _amplitude = 0;
+  _npts = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Open the time history and prepare for querying.
+void
+spatialdata::spatialdb::TimeHistory::open(void)
+{ // open
+  TimeHistoryIO::read(&_time, &_amplitude, &_npts, _filename.c_str());
+  _ilower = 0;
+} // open
+
+// ----------------------------------------------------------------------
+// Close the time history.
+void
+spatialdata::spatialdb::TimeHistory::close(void)
+{ // close
+  delete[] _time; _time = 0;
+  delete[] _amplitude; _amplitude = 0;
+  _npts = 0;
+} // close
+
+// ----------------------------------------------------------------------
+// Query the database.
+int
+spatialdata::spatialdb::TimeHistory::query(double* value,
+      const double t)
+{ // query
+  assert(0 != _npts);
+  
+  if (_npts > 1) {
+    if (t < _time[_ilower]) {
+      const int imax = _npts-1;
+      while(_ilower < imax) {
+	if (t >= _time[_ilower])
+	  break;
+	++_ilower;
+      } // while
+    } else if (t > _time[_ilower+1]) {
+      while (_ilower > 0) {
+	if (t <= _time[_ilower+1])
+	  break;
+	--_ilower;
+      } // while
+    } // if/else
+    if (t >= _time[_ilower] && t <= _time[_ilower+1]) {
+      const double tL = _time[_ilower];
+      const double tU = _time[_ilower+1];
+      const double wtL = (tU - t) / (tU - tL);
+      const double wtU = (t - tL) / (tU - tL);
+      *value = wtL * _amplitude[_ilower] + wtU * _amplitude[_ilower+1];
+    } else {
+      return 1;
+    } // else
+  } else {
+    *value = _amplitude[0];
+  } // else
+
+  return 0;
+} // query
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.hh	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.hh	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,110 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file libsrc/spatialdb/TimeHistory.h
+ *
+ * @brief C++ object for time dependence in spatial databases. Time
+ * history is applied independently of the spatial variation.
+ */
+
+#if !defined(spatialdata_spatialdb_timehistory_hh)
+#define spatialdata_spatialdb_timehistory_hh
+
+#include "spatialdbfwd.hh"
+
+#include <string> // HASA std::string
+
+/// C++ object for time dependence in spatial databases.
+class spatialdata::spatialdb::TimeHistory
+{ // class TimeHistory
+
+ public :
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+  
+  /// Default constructor.
+  TimeHistory(void);
+  
+  /** Constructor with label.
+   *
+   * @param label Label for database
+   */
+  TimeHistory(const char* label);
+  
+  /// Default destructor.
+  ~TimeHistory(void);
+
+  /** Set label of time history.
+   *
+   * @param label Label for time history.
+   */
+  void label(const char* label);
+  
+  /** Get label of time history.
+   *
+   * @returns Label for time history.
+   */
+  const char* label(void) const;
+
+  /** Set filename for time history.
+   *
+   * @param name Name of file.
+   */
+  void filename(const char* name);
+  
+  /** Set filename for time history.
+   *
+   * @return Name of file.
+   */
+  const char* filename(void);
+  
+  /// Open the time history and prepare for querying.
+  void open(void);
+
+  /// Close the time history.
+  void close(void);
+
+  /** Query the database.
+   *
+   * @pre Must call open() before query()
+   *
+   * @param value Value in time history.
+   * @param t Time for query.
+   *
+   * @returns 0 on success, 1 on failure (i.e., could not interpolate)
+   */
+  int query(double* value,
+	    const double t);
+
+private :
+ // PRIVATE MEMBERS ////////////////////////////////////////////////////
+  
+  std::string _label; ///< Label of time history.
+  std::string _filename; ///< Name of time history file
+  double* _time; ///< Time stamps for points in time history.
+  double* _amplitude; ///< Amplitude at points in time history.
+  int _npts; ///< Number of points in time history.
+  int _ilower; ///< Current index for point preceding current time.
+  
+private :
+  // NOT IMPLEMENTED ////////////////////////////////////////////////////
+  
+  TimeHistory(const TimeHistory&); ///< Not implemented
+  const TimeHistory& operator=(const TimeHistory&); ///< Not implemented
+  
+}; // class TimeHistory
+
+#include "TimeHistory.icc" // inline methods
+
+#endif // spatialdata_spatialdb_timehistory_hh
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.icc	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistory.icc	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_timehistory_hh)
+#error "TimeHistory.icc must only be included from TimeHistory.hh"
+#endif
+
+// Set label of time history.
+inline
+void
+spatialdata::spatialdb::TimeHistory::label(const char* label) {
+  _label = label;
+}
+  
+// Get label of time history.
+inline
+const char*
+spatialdata::spatialdb::TimeHistory::label(void) const {
+  return _label.c_str();
+}
+
+// Set filename for time history.
+void
+spatialdata::spatialdb::TimeHistory::filename(const char* name) {
+  _filename = name;
+}
+  
+// Set filename for time history.
+const char*
+spatialdata::spatialdb::TimeHistory::filename(void) {
+  return _filename.c_str();
+}
+  
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.cc	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.cc	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,216 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TimeHistoryIO.hh" // Implementation of class methods
+
+#include "spatialdata/utils/LineParser.hh" // USES LineParser
+
+#include <fstream> // USES std::ifstream, std::ofstream
+#include <iomanip> // USES setw(), setiosflags(), resetiosflags()
+
+#include <cassert> // USES assert()
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+
+// ----------------------------------------------------------------------
+const char* spatialdata::spatialdb::TimeHistoryIO::HEADER =
+  "#TIME HISTORY ascii";
+
+// ----------------------------------------------------------------------
+// Read time history file.
+void
+spatialdata::spatialdb::TimeHistoryIO::read(double** time,
+					    double** amplitude,
+					    int* npts,
+					    const char* filename)
+{ // read
+  assert(0 != time);
+  assert(0 != amplitude);
+  assert(0 != npts);
+
+  try {
+    std::ifstream filein(filename);
+    if (!filein.is_open() || !filein.good()) {
+      std::ostringstream msg;
+      msg << "Could not open time history file '" << filename
+	  << "' for reading.\n";
+      throw std::runtime_error(msg.str());
+    } // if
+
+    utils::LineParser parser(filein, "//");
+    parser.eatwhitespace(true);
+
+    const int maxIgnore = 256;
+    std::string token;
+    std::istringstream buffer;
+    buffer.str(parser.next());
+    buffer.clear();
+
+    const int headerLen = strlen(HEADER);
+    std::string hbuffer;
+    hbuffer.resize(headerLen+1);
+    buffer.read((char*) hbuffer.c_str(), sizeof(char)*headerLen);
+    hbuffer[headerLen] = '\0';
+    if (0 != strcasecmp(HEADER, hbuffer.c_str())) {
+      std::ostringstream msg;
+      msg
+	<< "Magic header '" << buffer << "' does not match expected header '"
+	<< HEADER << "' in time history file '" << filename << "'.\n";
+      throw std::runtime_error(msg.str());
+    } // if
+
+    buffer.str(parser.next());
+    buffer.clear();
+    buffer >> token;
+    if (0 != strcasecmp(token.c_str(), "TimeHistory")) {
+      std::ostringstream msg;
+      msg << "Could not parse '" << token << "' into 'TimeHistory'.\n";
+      throw std::runtime_error(msg.str());
+    } // else
+
+    std::string timeUnits = "second";
+    buffer.str(parser.next());
+    buffer.clear();
+    buffer >> token;
+    while (buffer.good() && token != "}") {
+      if (0 == strcasecmp(token.c_str(), "num-points")) {
+	buffer.ignore(maxIgnore, '=');
+	buffer >> *npts;
+      } else if (0 == strcasecmp(token.c_str(), "time-units")) {
+	buffer.ignore(maxIgnore, '=');
+	buffer >> timeUnits;
+      } else {
+	std::ostringstream msg;
+	msg << "Could not parse '" << token
+	    << "' into a TimeHistory setting.";
+	throw std::runtime_error(msg.str());
+      } // else
+      
+      buffer.str(parser.next());
+      buffer.clear();
+      buffer >> token;
+    } // while
+    if (token != "}" || !filein.good())
+      throw std::runtime_error("I/O error while parsing TimeHistory "
+			       "settings.");
+    
+    bool ok = true;
+    std::ostringstream msg;
+    if (0 == *npts) {
+      ok = false;
+      msg << "TimeHistory settings must include 'num-points'.\n";
+    } // if
+    if (*npts <= 0) {
+      ok = false;
+      msg << "TimeHistory must contain at least one point.\n";
+    } // if
+    if (!ok)
+      throw std::runtime_error(msg.str());
+    
+    const int size = *npts;
+    delete[] *time; *time = (size > 0) ? new double[size] : 0;
+    delete[] *amplitude; *amplitude = (size > 0) ? new double[size] : 0;
+    
+    for (int i=0; i < size; ++i) {
+      buffer.str(parser.next());
+      buffer.clear();
+      buffer >> (*time[i]);
+      buffer >> (*amplitude[i]);
+    } // for
+    
+    if (!filein.good())
+      throw std::runtime_error("Unknown error while reading.");
+  } catch (const std::exception& err) {
+    std::ostringstream msg;
+    msg << "Error occurred while reading time history file '"
+	<< filename << "'.\n"
+	<< err.what();
+    throw std::runtime_error(msg.str());
+  } catch (...) {
+    std::ostringstream msg;
+    msg << "Unknown error occurred while reading time history file '"
+	<< filename << "'.\n";
+    throw std::runtime_error(msg.str());
+  } // try/catch
+} // read
+  
+// ----------------------------------------------------------------------
+// Read time history file.
+void
+spatialdata::spatialdb::TimeHistoryIO::write(const double* time,
+					     const int nptsT,
+					     const double* amplitude,
+					     const int nptsA,
+					     const char* timeUnits,
+					     const char* filename)
+{ // write
+  assert( (0 == nptsT && 0 == time) ||
+	  (0 < nptsT && 0 != time) );
+  assert( (0 == nptsA && 0 == amplitude) ||
+	  (0 < nptsA && 0 != amplitude) );
+
+  try {
+    if (nptsT != nptsA) {
+      std::ostringstream msg;
+      msg << "Number of time stamps (" << nptsT << ") does not match the "
+	  << "number of amplitude points (" << nptsA << ").";
+      throw std::runtime_error(msg.str());
+    } // if
+
+    std::ofstream fileout(filename);
+    if (!fileout.is_open() || !fileout.good()) {
+      std::ostringstream msg;
+      msg << "Could not open time history file " << filename
+	  << "for writing.\n";
+      throw std::runtime_error(msg.str());
+    } // if
+    
+    const int npts = nptsA;
+    
+    fileout
+      << HEADER << "\n"
+      << "TimeHistory {\n"
+      << "  num-points = " << std::setw(6) << npts << "\n"
+      << "  time-units =" << timeUnits << "\n"
+      << "}\n";
+    if (!fileout.good())
+      throw std::runtime_error("I/O error while writing TimeHistory "
+			       "settings.");
+
+    fileout
+      << std::resetiosflags(std::ios::fixed)
+      << std::setiosflags(std::ios::scientific)
+      << std::setprecision(6);
+    for (int i=0; i < npts; ++i)
+      fileout << std::setw(14) << time[i]
+	      << std::setw(14) << amplitude[i]
+	      << "\n";
+    if (!fileout.good())
+      throw std::runtime_error("I/O error while writing TimeHistory data.");
+  } catch (const std::exception& err) {
+    std::ostringstream msg;
+    msg << "Error occurred while writing time history file '"
+	<< filename << "'.\n" 
+	<< err.what();
+    throw std::runtime_error(msg.str());
+  } catch (...) {
+    std::ostringstream msg;
+    msg << "Unknown error occurred while writing time history file '"
+	<< filename << "'.";
+    throw std::runtime_error(msg.str());
+  } // try/catch
+} // write
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.hh	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/TimeHistoryIO.hh	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file libsrc/spatialdb/TimeHistoryIO.h
+ *
+ * @brief C++ object for reading/writing time history files.
+ */
+
+#if !defined(spatialdata_spatialdb_timehistoryio_hh)
+#define spatialdata_spatialdb_timehistoryio_hh
+
+#include "spatialdbfwd.hh"
+
+/// C++ object for reading/writing time history files.
+class spatialdata::spatialdb::TimeHistoryIO
+{ // class TimeHistoryIO
+
+ public :
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+  
+  /** Read time history file.
+   *
+   * @param time Time stamps.
+   * @param amplitude Amplitude values in time history.
+   * @param npts Number of points in time history.
+   * @param filename Filename for time history.
+   */
+  static
+  void read(double** time,
+	    double** amplitude,
+	    int* npts,
+	    const char* filename);
+  
+  /** Read time history file. Number of time history points given by
+   * nptsT must equal nptsA.
+   *
+   * @param time Time stamps.
+   * @param nptsT Number of points in time history.
+   * @param amplitude Amplitude values in time history.
+   * @param nptsA Number of points in time history.
+   * @param timeUnits Units associated with time stamps.
+   * @param filename Filename for time history.
+   */
+  static
+  void write(const double* time,
+	     const int nptsT,
+	     const double* amplitude,
+	     const int nptsA,
+	     const char* timeUnits,
+	     const char* filename);
+
+private :
+  // PRIVATE MEMBERS ////////////////////////////////////////////////////
+
+  static const char* HEADER; ///< Header for time history files.
+  
+}; // class TimeHistoryIO
+
+#endif // spatialdata_spatialdb_timehistoryio_hh
+
+
+// End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/spatialdbfwd.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/spatialdbfwd.hh	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/spatialdbfwd.hh	2009-06-02 16:21:57 UTC (rev 15102)
@@ -37,6 +37,9 @@
     class GocadVoxet;
 
     class GravityField;
+
+    class TimeHistory;
+    class TimeHistoryIO;
     
   } // spatialdb
 } // spatialdata

Modified: cs/spatialdata-0.1/trunk/modulesrc/geocoords/Converter.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/geocoords/Converter.i	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/modulesrc/geocoords/Converter.i	2009-06-02 16:21:57 UTC (rev 15102)
@@ -38,11 +38,12 @@
 	 const int numLocs,
 	 const int numDims)
 	  };
-      static void convert(double* coords,
-			  const int numLocs,
-			  const int numDims,
-			  const CoordSys* pCSDest,
-			  const CoordSys* pCSSrc);
+      static
+      void convert(double* coords,
+		   const int numLocs,
+		   const int numDims,
+		   const CoordSys* pCSDest,
+		   const CoordSys* pCSSrc);
       %clear(double* coords, const int numLocs, const int numDims);
 
     }; // class Converter

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/Makefile.am	2009-06-02 16:21:57 UTC (rev 15102)
@@ -27,7 +27,9 @@
 	UniformDB.i \
 	CompositeDB.i \
 	SCECCVMH.i \
-	GravityField.i
+	GravityField.i \
+	TimeHistory.i \
+	TimeHistoryIO.i
 
 swig_generated = \
 	spatialdb_wrap.cxx \

Added: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistory.i	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,87 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/spatialdb/TimeHistory.i
+ *
+ * @brief SWIG interface to C++ TimeHistory object.
+ */
+
+namespace spatialdata {
+  namespace spatialdb {
+
+    class TimeHistory
+    { // class TimeHistory
+
+    public :
+      // PUBLIC METHODS /////////////////////////////////////////////////
+  
+      /// Default constructor.
+      TimeHistory(void);
+  
+      /** Constructor with label.
+       *
+       * @param label Label for database
+       */
+      TimeHistory(const char* label);
+      
+      /// Default destructor.
+      ~TimeHistory(void);
+
+      /** Set label of time history.
+       *
+       * @param label Label for time history.
+       */
+      void label(const char* label);
+  
+      /** Get label of time history.
+       *
+       * @returns Label for time history.
+       */
+      const char* label(void) const;
+      
+      /** Set filename for time history.
+       *
+       * @param name Name of file.
+       */
+      void filename(const char* name);
+      
+      /** Set filename for time history.
+       *
+       * @return Name of file.
+       */
+      const char* filename(void);
+      
+      /// Open the time history and prepare for querying.
+      void open(void);
+      
+      /// Close the time history.
+      void close(void);
+      
+      /** Query the database.
+       *
+       * @pre Must call open() before query()
+       *
+       * @param value Value in time history.
+       * @param t Time for query.
+       *
+       * @returns 0 on success, 1 on failure (i.e., could not interpolate)
+       */
+      int query(double* value,
+		const double t);
+        
+    }; // class TimeHistory
+
+  } // spatialdb
+} // spatialdata
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistoryIO.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistoryIO.i	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/TimeHistoryIO.i	2009-06-02 16:21:57 UTC (rev 15102)
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/spatialdb/TimeHistory.i
+ *
+ * @brief SWIG interface to C++ TimeHistory object.
+ */
+
+namespace spatialdata {
+  namespace spatialdb {
+
+    class TimeHistoryIO
+    { // class TimeHistoryIO
+
+    public :
+      // PUBLIC METHODS /////////////////////////////////////////////////
+  
+      /** Read time history file. Number of time history points given by
+       * nptsT must equal nptsA.
+       *
+       * @param time Time stamps.
+       * @param nptsT Number of points in time history.
+       * @param amplitude Amplitude values in time history.
+       * @param nptsA Number of points in time history.
+       * @param timeUnits Units associated with time stamps.
+       * @param filename Filename for time history.
+       */
+      %apply(double* IN_ARRAY1, int DIM1) {
+	(const double* time,
+	 const int nptsT)
+	  };
+      %apply(double* IN_ARRAY1, int DIM1) {
+	(const double* amplitude,
+	 const int nptsA)
+	  };
+      static
+      void write(const double* time,
+		 const int nptsT,
+		 const double* amplitude,
+		 const int nptsA,
+		 const char* timeUnits,
+		 const char* filename);
+      %clear(const double* time, const int nptsT);
+      %clear(const double* amplitude, const int nptsA);
+
+    }; // class TimeHistoryIO
+
+  } // spatialdb
+} // spatialdata
+
+
+// End of file 

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.i	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.i	2009-06-02 16:21:57 UTC (rev 15102)
@@ -29,6 +29,8 @@
 #include "spatialdata/spatialdb/CompositeDB.hh"
 #include "spatialdata/spatialdb/SCECCVMH.hh"
 #include "spatialdata/spatialdb/GravityField.hh"
+#include "spatialdata/spatialdb/TimeHistory.hh"
+#include "spatialdata/spatialdb/TimeHistoryIO.hh"
 
 %}
 
@@ -64,6 +66,8 @@
 %include "CompositeDB.i"
 %include "SCECCVMH.i"
 %include "GravityField.i"
+%include "TimeHistory.i"
+%include "TimeHistoryIO.i"
 
 
 // End of file

Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDBObj.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDBObj.py	2009-06-02 02:33:28 UTC (rev 15101)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDBObj.py	2009-06-02 16:21:57 UTC (rev 15102)
@@ -83,9 +83,10 @@
 
 def spatial_database():
   """
-  Factory associated with SimpleDB.
+  Factory associated with SpatialDB.
   """
-  return SpatialDBObj()
+  # Abstract object (so return None).
+  return None
 
 
 # End of file 



More information about the CIG-COMMITS mailing list