[cig-commits] r8254 - in cs/spatialdata-0.1/trunk: . libsrc/geocoords libsrc/spatialdb modulesrc/spatialdb spatialdata spatialdata/spatialdb tests/libtests/geocoords tests/libtests/spatialdb

brad at geodynamics.org brad at geodynamics.org
Thu Nov 8 16:40:51 PST 2007


Author: brad
Date: 2007-11-08 16:40:50 -0800 (Thu, 08 Nov 2007)
New Revision: 8254

Added:
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/GravityField.py
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.cc
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.hh
Modified:
   cs/spatialdata-0.1/trunk/TODO
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleDB.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIO.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
   cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
   cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc
   cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh
   cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc
   cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh
   cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestGeoid.cc
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc
Log:
Finished implementation of GravityField. Added radialDir() to CSGeo and CSGeoLocalCart. Finished C++ unit tests for GravityField.

Modified: cs/spatialdata-0.1/trunk/TODO
===================================================================
--- cs/spatialdata-0.1/trunk/TODO	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/TODO	2007-11-09 00:40:50 UTC (rev 8254)
@@ -4,6 +4,10 @@
 
 GEOCOORDS
 
+  Add local origin and rotation to coordinate systems.
+    Local origin should be straightforward.
+    Meaning of rotation (orientation) will depend upon coordinate system.
+
   Make it possible to pickle/unpickle to/from file like in C++?
 
 SPATIALDB

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -176,6 +176,54 @@
 } // fromProjForm
 
 // ----------------------------------------------------------------------
+// Get outward radial direction.
+void
+spatialdata::geocoords::CSGeo::radialDir(double* dir,
+					 const double* coords,
+					 const int numLocs,
+					 const int numDims) const
+{ // radialDir
+  assert( (0 < numLocs && 0 != dir) ||
+	  (0 == numLocs && 0 == dir) );
+  assert( (0 < numLocs && 0 != coords) ||
+	  (0 == numLocs && 0 == coords) );
+
+  if (numDims != spaceDim()) {
+    std::ostringstream msg;
+    msg
+      << "Number of spatial dimensions of coordinates ("
+      << numDims << ") does not match number of spatial dimensions ("
+      << spaceDim() << ") of coordinate system.";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  if (!isGeocentric())
+    if (numDims > 2)
+      for (int iLoc=0, i=0; iLoc < numLocs; ++iLoc) {
+	dir[i++] = 0.0;
+	dir[i++] = 0.0;
+	dir[i++] = 1.0;
+      } // for
+    else {
+      const int size = numLocs*numDims;
+      for (int i=0; i < size; ++i)
+	dir[i] = 0.0;
+    } // else
+  else { // else geocentric
+    assert(3 == numDims);
+    for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc, index+=numDims) {
+      const double x = coords[index  ];
+      const double y = coords[index+1];
+      const double z = coords[index+2];
+      const double mag = sqrt(x*x + y*y + z*z);
+      dir[index  ] = x / mag;
+      dir[index+1] = y / mag;
+      dir[index+2] = z / mag;
+    } // for
+  } // else geocentric
+} // radialDir
+
+// ----------------------------------------------------------------------
 // Get the PROJ4 string associated with the coordinate system.
 std::string
 spatialdata::geocoords::CSGeo::_projCSString(void) const

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh	2007-11-09 00:40:50 UTC (rev 8254)
@@ -153,6 +153,23 @@
   virtual void fromProjForm(double* coords,
 			    const int numLocs,
 			    const int numDims) const;
+
+  /** Get radial outward direction.
+   *
+   * dir and coords
+   *   size = numLocs * numDims
+   *   index = iLoc*numDims + iDim
+   *
+   * @param dir Array of direction cosines for outward radial direction.
+   * @param coords Array of coordinates for locations.
+   * @param numLocs Number of locations.
+   * @param numDims Number of dimensions in coordinates.
+   */
+  virtual void radialDir(double* dir,
+			 const double* coords,
+			 const int numLocs,
+			 const int numDims) const;
+
   /** Get geoid.
    *
    * @returns Geoid

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -22,7 +22,7 @@
 
 #include "spatialdata/utils/LineParser.hh" // USES LineParser
 
-#include <math.h> // USES M_PI, sin(), cos()
+#include <math.h> // USES M_PI, sin(), cos(), sqrt()
 #include <iostream> // USES std::istream, std::ostream
 
 #include <stdexcept> // USES std::runtime_error, std::exception
@@ -37,8 +37,7 @@
   _originElev(0),
   _originX(0),
   _originY(0),
-  _originZ(0),
-  _localOrientation(0)
+  _originZ(0)
 { // constructor
   CSGeo::isGeocentric(true);
   CSGeo::setSpaceDim(3);
@@ -48,7 +47,6 @@
 // Default destructor
 spatialdata::geocoords::CSGeoLocalCart::~CSGeoLocalCart(void)
 { // destructor
-  delete[] _localOrientation; _localOrientation = 0;
 } // destructor
 
 // ----------------------------------------------------------------------
@@ -60,8 +58,7 @@
   _originElev(cs._originElev),
   _originX(cs._originX),
   _originY(cs._originY),
-  _originZ(cs._originZ),
-  _localOrientation(0)
+  _originZ(cs._originZ)
 { // copy constructor
 } // copy constructor
 
@@ -145,7 +142,6 @@
   const double y1 = z2*x0 - x2*z0;
   const double y2 = z0*x1 - x0*z1;
 
-  delete[] _localOrientation; _localOrientation = new double[9];
   _localOrientation[0] = x0;
   _localOrientation[1] = x1;
   _localOrientation[2] = x2;
@@ -211,7 +207,7 @@
       _localOrientation[7]*zOld;
     coords[index++] = 
       _localOrientation[2]*xOld +
-	_localOrientation[5]*yOld +
+      _localOrientation[5]*yOld +
       _localOrientation[8]*zOld;
   } // for
 } // toProjForm
@@ -259,8 +255,72 @@
   for (int i=0; i < size; ++i)
     coords[i] /= scale;
 } // fromProjForm
-  
+
 // ----------------------------------------------------------------------
+// Get outward radial direction.
+void
+spatialdata::geocoords::CSGeoLocalCart::radialDir(double* dir,
+						  const double* coords,
+						  const int numLocs,
+						  const int numDims) const
+{ // radialDir
+  assert( (0 < numLocs && 0 != dir) ||
+	  (0 == numLocs && 0 == dir) );
+  assert( (0 < numLocs && 0 != coords) ||
+	  (0 == numLocs && 0 == coords) );
+
+  if (numDims != spaceDim()) {
+    std::ostringstream msg;
+    msg
+      << "Number of spatial dimensions of coordinates ("
+      << numDims << ") does not match number of spatial dimensions ("
+      << spaceDim() << ") of coordinate system.";
+    throw std::runtime_error(msg.str());
+  } // if
+  assert(3 == spaceDim());
+
+  const double scale = toMeters();
+  for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc, index+=numDims) {
+    // Convert to ECEF
+    // Get coordinates relative to origin
+    const double x = coords[index  ]*scale + _originX;
+    const double y = coords[index+1]*scale + _originY;
+    const double z = coords[index+2]*scale + _originZ;
+    // Rotate into ECEF
+    const double xECEF = 
+      _localOrientation[0]*x +
+      _localOrientation[3]*y +
+      _localOrientation[6]*z;
+    const double yECEF = 
+      _localOrientation[1]*x +
+      _localOrientation[4]*y +
+      _localOrientation[7]*z;
+    const double zECEF = 
+      _localOrientation[2]*x +
+      _localOrientation[5]*y +
+      _localOrientation[8]*z;
+
+    const double mag = sqrt(xECEF*xECEF + yECEF*yECEF + zECEF*zECEF);
+    const double dirX = xECEF / mag;
+    const double dirY = yECEF / mag;
+    const double dirZ = zECEF / mag;
+
+    dir[index  ] = 
+      _localOrientation[0]*dirX +
+      _localOrientation[1]*dirY +
+      _localOrientation[2]*dirZ;
+    dir[index+1] = 
+      _localOrientation[3]*dirX +
+      _localOrientation[4]*dirY +
+      _localOrientation[5]*dirZ;
+    dir[index+2] = 
+      _localOrientation[6]*dirX +
+      _localOrientation[7]*dirY +
+      _localOrientation[8]*dirZ;
+  } // for
+} // radialDir
+
+// ----------------------------------------------------------------------
 // Convert coordinates to WGS84.
 void
 spatialdata::geocoords::CSGeoLocalCart::_geoToWGS84(double* pLonWGS84,

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh	2007-11-09 00:40:50 UTC (rev 8254)
@@ -104,6 +104,22 @@
 		    const int numLocs,
 		    const int numDims) const;
   
+  /** Get radial outward direction.
+   *
+   * dir and coords
+   *   size = numLocs * numDims
+   *   index = iLoc*numDims + iDim
+   *
+   * @param dir Array of direction cosines for outward radial direction.
+   * @param coords Array of coordinates for locations.
+   * @param numLocs Number of locations.
+   * @param numDims Number of dimensions in coordinates.
+   */
+  void radialDir(double* dir,
+		 const double* coords,
+		 const int numLocs,
+		 const int numDims) const;
+
   /** Pickle coordinate system to ascii stream.
    *
    * @param s Output stream
@@ -182,7 +198,7 @@
   double _originX; ///< X coordinate of origin in rotated ECEF (meters)
   double _originY; ///< Y coordinate of origin in rotated ECEF (meters)
   double _originZ; ///< Z coordinate of origin in rotated ECEF (meters)
-  double* _localOrientation; ///< Direction cosines for local orientation
+  double _localOrientation[9]; ///< Direction cosines for local orientation
 
 }; // class CSGeoLocalCart
 

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -87,6 +87,8 @@
 					    const CSGeo& csDest,
 					    const CSGeo& csSrc)
 { // convert
+  assert(0 != csSrc.projCoordSys());
+  assert(0 != csDest.projCoordSys());
   assert( (0 < numLocs && 0 != coords) ||
 	  (0 == numLocs && 0 == coords));
 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -30,17 +30,23 @@
   SpatialDB("Gravity field"),
   _acceleration(9.80665), // m/s^2
   _csECEF(new geocoords::CSGeo),
-  _queryVals(0),
-  _querySize(0)
+  _queryVals(new int[3]),
+  _querySize(3)
 { // constructor
   _upDir[0] = 0.0;
   _upDir[1] = 0.0;
-  _upDir[2] = 0.0;
+  _upDir[2] = 1.0;
 
   if (0 == _csECEF)
     throw std::runtime_error("Error while initializing ECEF coordinate "
 			     "system.");
   _csECEF->isGeocentric(true);
+  _csECEF->initialize();
+
+  assert(0 != _queryVals);
+  _queryVals[0] = 0;
+  _queryVals[1] = 1;
+  _queryVals[2] = 2;
 } // constructor
 
 // ----------------------------------------------------------------------
@@ -53,6 +59,19 @@
 } // destructor
 
 // ----------------------------------------------------------------------
+// Set up direction (direction opposite of gravity) in database.
+void
+spatialdata::spatialdb::GravityField::upDir(const double x,
+					    const double y,
+					    const double z)
+{ // upDir
+  const double mag = sqrt(x*x + y*y + z*z);
+  _upDir[0] = x / mag;
+  _upDir[1] = y / mag;
+  _upDir[2] = z / mag;
+} // upDir
+
+// ----------------------------------------------------------------------
 // Set values to be returned by queries.
 void
 spatialdata::spatialdb::GravityField::queryVals(const char** names,
@@ -120,29 +139,11 @@
       vals[i] = -_acceleration*_upDir[_queryVals[i]];
   else {
     const geocoords::CSGeo* csGeo = dynamic_cast<const geocoords::CSGeo*>(cs);
-    if (!csGeo->isGeocentric())
-      for (int i=0; i < _querySize; ++i)
-	vals[i] = -_acceleration*_upDir[_queryVals[i]];
-    else {
-      // cs is either CSGeo (geocentric) or CSGeoLocalCart
-      const int numLocs = 1;
-      const int spaceDim = 3;
-      assert(spaceDim == csGeo->spaceDim());
-
-      // Convert coordinates to Earth-centered/Earth-fixed (ECEF)
-      double xyzECEF[spaceDim];
-      for (int i=0; i < spaceDim; ++i)
-	xyzECEF[i] = coords[i];
-      geocoords::Converter::convert(xyzECEF, numLocs, spaceDim,
-				    _csECEF, csGeo);
-
-      // Compute outward radial direction by computing
-      const double mag = sqrt(xyzECEF[0]*xyzECEF[0] +
-			      xyzECEF[1]*xyzECEF[1] +
-			      xyzECEF[2]*xyzECEF[2]);
-      for (int i=0; i < _querySize; ++i)
-	vals[i] = -_acceleration*xyzECEF[i] / mag;
-    } // else
+    double upDir[3];
+    const int numLocs = 1;
+    csGeo->radialDir(upDir, coords, numLocs, numDims);
+    for (int i=0; i < _querySize; ++i)
+      vals[i] = -_acceleration*upDir[_queryVals[i]];
   } // if/else
 
   return 0;

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -14,17 +14,8 @@
 #error "GravityField.icc must only be included from GravityField.hh"
 #endif
 
-// Set up direction (direction opposite of gravity) in database.
-void
-spatialdata::spatialdb::GravityField::upDir(const double x,
-					    const double y,
-					    const double z) {
-  _upDir[0] = x;
-  _upDir[1] = y;
-  _upDir[2] = z;
-}
-
 // Set gravitational acceleration.
+inline
 void
 spatialdata::spatialdb::GravityField::gravAcceleration(
 					       const double acceleration) {
@@ -32,11 +23,13 @@
 }
 
 // Open the database and prepare for querying.
+inline
 void
 spatialdata::spatialdb::GravityField::open(void) {
 }
 
 // Close the database.
+inline
 void
 spatialdata::spatialdb::GravityField::close(void) {
 }

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleDB.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleDB.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleDB.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -14,7 +14,5 @@
 #error "SimpleDB.icc must only be included from SimpleDB.hh"
 #endif
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIO.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIO.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIO.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -26,7 +26,5 @@
 spatialdata::spatialdb::SimpleIO::filename(void) const
 { return _filename.c_str(); }
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SimpleIOAscii.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -21,7 +21,5 @@
 spatialdata::spatialdb::SimpleIOAscii::clone(void) const
 { return new SimpleIOAscii(*this); }
   
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -26,7 +26,5 @@
 spatialdata::spatialdb::SpatialDB::label(void) const
 { return _label; }
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -15,11 +15,13 @@
 #endif
 
 // Open the database and prepare for querying.
+inline
 void
 spatialdata::spatialdb::UniformDB::open(void) {
 }
 
 // Close the database.
+inline
 void
 spatialdata::spatialdb::UniformDB::close(void) {
 }

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-11-09 00:40:50 UTC (rev 8254)
@@ -16,6 +16,7 @@
 #include "spatialdata/spatialdb/SimpleIO.hh"
 #include "spatialdata/spatialdb/SimpleIOAscii.hh"
 #include "spatialdata/spatialdb/SimpleDBTypes.hh"
+#include "spatialdata/spatialdb/GravityField.hh"
 #include "spatialdata/spatialdb/UniformDB.hh"
 
 #include "spatialdata/geocoords/CoordSys.hh"
@@ -481,7 +482,57 @@
     free(<void*> unitsArray)
     return
 
+
 # ----------------------------------------------------------------------
+cdef class GravityField(SpatialDB):
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    # create shim for constructor
+    #embed{ void* GravityField_constructor()
+      return (void*)(new spatialdata::spatialdb::GravityField);
+    #}embed
+
+    SpatialDB.__init__(self)
+    self.thisptr = GravityField_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  def upDir(self, up):
+    """
+    Set up direction (direction opposite of gravity).
+    """
+    # create shim for method 'upDir'
+    #embed{ void GravityField_upDir(void* pObj, double x, double y, double z)
+    assert(0 != pObj);
+    ((spatialdata::spatialdb::GravityField*) pObj)->upDir(x, y, z);
+    #}embed
+    if len(up) != 3:
+      raise ValueError("Up direction must be a 3 component list or tuple.")
+    (x, y, z) = map(float, up)
+
+    GravityField_upDir(self.thisptr, x, y, z)
+    return
+
+
+  def gravAcceleration(self, value):
+    """
+    Set gravitational acceleration.
+    """
+    # create shim for method 'gravAcceleration'
+    #embed{ void GravityField_gravAcceleration(void* pObj, double value)
+    assert(0 != pObj);
+    ((spatialdata::spatialdb::GravityField*) pObj)->gravAcceleration(value);
+    #}embed
+
+    GravityField_gravAcceleration(self.thisptr, value)
+    return
+
+
+# ----------------------------------------------------------------------
 cdef class UniformDB(SpatialDB):
 
   def __init__(self):
@@ -505,6 +556,7 @@
     """
     # create shim for method 'setData'
     #embed{ void UniformDB_setData(void* pObj, char** names, double* values, int size)
+    assert(0 != pObj);
     ((spatialdata::spatialdb::UniformDB*) pObj)->setData(
       const_cast<const char**>(names), values, size);
     #}embed
@@ -534,5 +586,4 @@
     return
 
 
-
 # End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am	2007-11-09 00:40:50 UTC (rev 8254)
@@ -20,6 +20,7 @@
 	geocoords/CSGeo.py \
 	geocoords/Projector.py \
 	geocoords/__init__.py \
+	spatialdb/GravityField.py \
 	spatialdb/SimpleDB.py \
 	spatialdb/SimpleIOAscii.py \
 	spatialdb/SimpleIO.py \

Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/GravityField.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/GravityField.py	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/GravityField.py	2007-11-09 00:40:50 UTC (rev 8254)
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/GravityField.py
+##
+## @brief Python manager for spatial database with gravity field information.
+##
+## Factory: spatial_database
+
+from SpatialDB import SpatialDB
+
+# GravityField class
+class GravityField(SpatialDB):
+  """
+  Python manager for spatial database with gravity field information.
+
+  Factory: spatial_database
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(SpatialDB.Inventory):
+    """
+    Python object for managing GravityField facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing GravityField facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b up_dir Direction opposite of gravity ("up").
+    ## @li \b acceleration Gravitational acceleration.
+    ##
+    ## \b Facilities
+    ## @li none
+
+    import pyre.inventory
+
+    upDir = pyre.inventory.list("up_dir", default=[0,0,1])
+    upDir.meta['tip'] = "Direction opposite of gravity ('up')."
+
+    from pyre.units.length import meter
+    from pyre.units.time import second
+    acceleration = pyre.inventory.dimensional("acceleration",
+                                              default=9.80665*meter/second**2)
+    acceleration.meta['tip'] = "Gravitational acceleration."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="uniformdb"):
+    """
+    Constructor.
+    """
+    SpatialDB.__init__(self, name)
+    import spatialdb as bindings
+    self.cppHandle = bindings.GravityField()
+    return
+
+
+  def initialize(self):
+    """
+    Initialize database.
+    """
+    SpatialDB.initialize(self)
+    self.cppHandle.upDir(self.upDir)
+    self.cppHandle.acceleration(self.acceleration.value)
+    return
+  
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based on inventory.
+    """
+    SpatialDB._configure(self)
+    self._validate(self.inventory)
+    self.upDir = self.inventory.upDir
+    self.acceleration = self.inventory.acceleration
+    return
+
+
+  def _validate(self, data):
+    """
+    Validate parameters.
+    """
+    if (len(data.upDir) != 3):
+      raise ValueError("Up direction must be a 3 component list or tuple.")
+    try:
+      dataFloat = map(float, data.upDir)
+    except:
+        raise ValueError, \
+              "'upDir' must contain floating point values."
+    return
+  
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+  """
+  Factory associated with GravityField.
+  """
+  return GravityField()
+
+
+# End of file 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -247,6 +247,92 @@
 } // testFromProjForm
 
 // ----------------------------------------------------------------------
+// Test radialDir() with geographic coordinates.
+void
+spatialdata::geocoords::TestCSGeo::testRadialDirGeographic(void)
+{ // testRadialDirGeographic
+  CSGeo cs;
+
+  const double tolerance = 1.0e-6;
+
+  { // 2D
+    const int numLocs = 1;
+    const int numDims = 2;
+    const double coords[] = { 28.0, 23.0,
+			      42.0, 34.0,
+			      -12.0, 65.7,
+			      64.3, -163.0 };
+
+    const int size = numLocs * numDims;
+    double* dirs = new double[size];
+    cs.setSpaceDim(numDims);
+    cs.initialize();
+    cs.radialDir(dirs, coords, numLocs, numDims);
+    for (int i=0; i < size; ++i)
+      CPPUNIT_ASSERT_EQUAL(0.0, dirs[i]);
+    delete[] dirs; dirs = 0;
+  } // 2D
+
+  { // 3D
+    const int numLocs = 4;
+    const int numDims = 3;
+    const double coords[] = { 28.0, 23.0, 3.4,
+			      42.0, 34.0, 3.5,
+			       -12.0, 65.7, 12.6,
+			       64.3, -163.0, -1.5 };
+    const int size = numLocs * numDims;
+    double* dirs = new double[size];
+    cs.setSpaceDim(numDims);
+    cs.initialize();
+    cs.radialDir(dirs, coords, numLocs, numDims);
+    for (int iLoc=0, i=0; iLoc < numLocs; ++iLoc) {
+      CPPUNIT_ASSERT_EQUAL(dirs[i++], 0.0);
+      CPPUNIT_ASSERT_EQUAL(dirs[i++], 0.0);
+      CPPUNIT_ASSERT_EQUAL(dirs[i++], 1.0);
+    } // for
+    delete[] dirs; dirs = 0;
+  } // 3D
+} // testRadialDirGeographic
+
+// ----------------------------------------------------------------------
+// Test radialDir() with geocentric coordinates.
+void
+spatialdata::geocoords::TestCSGeo::testRadialDirGeocentric(void)
+{ // testRadialDirGeocentric
+  CSGeo cs;
+  cs.isGeocentric(true);
+
+  const int numLocs = 5;
+  const int numDims = 3;
+  const double coords[] = { 
+    0.0, 0.0, 6356752.31, // (lon=0.0, lat=90.0)
+    6378137.00, 0.0, 0.0, // (lon=0.0, lat=0.0)
+    0.0, -6378137.00, 0.0, // (lon=-90.0, lat=0.0)
+    -2684785.48, -4296554.90, 3861564.10, // (lon=-122.0, lat=37.5)
+    -2680581.35, -4289826.89, 3855476.48, // (lon=-122.0, lat=37.5, elev=-10km)
+  };
+  const double dirsE[] = {
+    0.0, 0.0, 1.0,
+    1.0, 0.0, 0.0,
+    0.0, -1.0, 0.0,
+    -0.4214565909579322, -0.67447153394825399, 0.6061868456438223,
+    -0.42145822808804162, -0.67447415459479865, 0.60618279154106625,
+  };
+  const int size = numLocs * numDims;
+  double* dirs = new double[size];
+  cs.initialize();
+  cs.radialDir(dirs, coords, numLocs, numDims);
+
+  const double tolerance = 1.0e-6;
+  for (int i=0; i < size; ++i)
+    if (fabs(dirsE[i]) > tolerance)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, dirs[i]/dirsE[i], tolerance);
+    else
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(dirsE[i], dirs[i], tolerance);
+  delete[] dirs; dirs = 0;
+} // testRadialDirGeocentric
+
+// ----------------------------------------------------------------------
 // Test pickle() and unpickle()
 void
 spatialdata::geocoords::TestCSGeo::testPickle(void)
@@ -256,7 +342,7 @@
   const char* datumVert = "mean sea level";
   const bool isGeocentric = true;
   const double toMeters = 7.3;
-  const int spaceDim = 2;
+  const int numDims = 2;
 
   CSGeo csA;
   csA.ellipsoid(ellipsoid);
@@ -264,7 +350,7 @@
   csA.datumVert(datumVert);
   csA.isGeocentric(isGeocentric);
   csA.toMeters(toMeters);
-  csA.setSpaceDim(spaceDim);
+  csA.setSpaceDim(numDims);
 
   std::stringstream s;
   csA.pickle(s);
@@ -278,7 +364,7 @@
   CPPUNIT_ASSERT(0 == strcasecmp(datumVert, csB.datumVert()));
   CPPUNIT_ASSERT(isGeocentric == csB.isGeocentric());
   CPPUNIT_ASSERT_DOUBLES_EQUAL(toMeters, csB.toMeters(), tolerance);
-  CPPUNIT_ASSERT_EQUAL(spaceDim, csB.spaceDim());
+  CPPUNIT_ASSERT_EQUAL(numDims, csB.spaceDim());
 } // testPickle
 
 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh	2007-11-09 00:40:50 UTC (rev 8254)
@@ -35,6 +35,7 @@
 
   // CPPUNIT TEST SUITE /////////////////////////////////////////////////
   CPPUNIT_TEST_SUITE( TestCSGeo );
+
   CPPUNIT_TEST( testConstructor );
   CPPUNIT_TEST( testEllipsoid );
   CPPUNIT_TEST( testDatumHoriz );
@@ -45,7 +46,10 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testToProjForm );
   CPPUNIT_TEST( testFromProjForm );
+  CPPUNIT_TEST( testRadialDirGeographic );
+  CPPUNIT_TEST( testRadialDirGeocentric );
   CPPUNIT_TEST( testPickle );
+
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////
@@ -81,6 +85,12 @@
   /// Test fromProjForm()
   void testFromProjForm(void);
 
+  /// Test radialDir() with geographic coordinates.
+  void testRadialDirGeographic(void);
+
+  /// Test radialDir() with geocentric coordinates.
+  void testRadialDirGeocentric(void);
+
   /// Test pickle() & unpickle()
   void testPickle(void);
 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -18,6 +18,7 @@
 #include "spatialdata/geocoords/CSGeo.hh" // USES CSGeoLocalCart
 #include "spatialdata/geocoords/CSGeoLocalCart.hh" // USES CSGeoLocalCart
 
+#include <math.h> // USES fabs()
 #include <sstream> // USES std::stringstream
 
 // ----------------------------------------------------------------------
@@ -116,6 +117,42 @@
 } // testFromProjForm
 
 // ----------------------------------------------------------------------
+// Test radialDir().
+void
+spatialdata::geocoords::TestCSGeoLocalCart::testRadialDir(void)
+{ // testRadialDir
+  CSGeoLocalCart cs;
+
+  cs.origin(-122.0, 37.75, 0.0);
+  cs.initialize();
+
+  const int numLocs = 3;
+  const int numDims = 3;
+  const double coords[] = {
+    0.0, 0.0, 0.0,
+    0.0, 0.0, -20e+3,
+    10.0e+3, -25e+3, -5e+3,
+  };
+  const double dirsE[] = {
+    0.0, -0.0032487084, 0.99999472,
+    0.0, -0.0032589402, 0.99999469,
+    0.0015710173, -0.0071787331, 0.999973,
+  };
+  
+  const int size = numLocs * numDims;
+  double* dirs = new double[size];
+  cs.radialDir(dirs, coords, numLocs, numDims);
+
+  const double tolerance = 1.0e-6;
+  for (int i=0; i < size; ++i)
+    if (fabs(dirsE[i]) > tolerance)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, dirs[i]/dirsE[i], tolerance);
+    else
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(dirsE[i], dirs[i], tolerance);
+  delete[] dirs; dirs = 0;
+} // testRadialDir
+
+// ----------------------------------------------------------------------
 // Test pickle() and unpickle()
 void
 spatialdata::geocoords::TestCSGeoLocalCart::testPickle(void)

Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh	2007-11-09 00:40:50 UTC (rev 8254)
@@ -35,12 +35,15 @@
 
   // CPPUNIT TEST SUITE /////////////////////////////////////////////////
   CPPUNIT_TEST_SUITE( TestCSGeoLocalCart );
+
   CPPUNIT_TEST( testConstructor );
   CPPUNIT_TEST( testOrigin );
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testToProjForm );
   CPPUNIT_TEST( testFromProjForm );
+  CPPUNIT_TEST( testRadialDir );
   CPPUNIT_TEST( testPickle );
+
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////
@@ -61,6 +64,9 @@
   /// Test fromProjForm()
   void testFromProjForm(void);
 
+  /// Test radialDir()
+  void testRadialDir(void);
+
   /// Test pickle() and unpickle()
   void testPickle(void);
 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestGeoid.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestGeoid.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestGeoid.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -52,7 +52,5 @@
   } // for
 } // testElevation
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am	2007-11-09 00:40:50 UTC (rev 8254)
@@ -20,6 +20,7 @@
 check_PROGRAMS = testspatial
 
 testspatial_SOURCES = \
+	TestGravityField.cc \
 	TestSimpleDBQuery.cc \
 	TestSimpleDBQuery3D.cc \
 	TestSimpleDB.cc \
@@ -34,6 +35,7 @@
 	testspatial.cc
 
 noinst_HEADERS = \
+	TestGravityField.cc \
 	TestSimpleDBQuery.hh \
 	TestSimpleDBQuery3D.cc \
 	TestSimpleDB.hh \

Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -0,0 +1,315 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestGravityField.hh" // Implementation of class methods
+
+#include "spatialdata/spatialdb/GravityField.hh" // USES GravityField
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+#include "spatialdata/geocoords/CSGeo.hh" // USES CSGeo
+#include "spatialdata/geocoords/CSGeoProj.hh" // USES CSGeoProj
+#include "spatialdata/geocoords/CSGeoLocalCart.hh" // USES CSGeoLocalCart
+
+#include <math.h> // USES sqrt()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestGravityField );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+spatialdata::spatialdb::TestGravityField::testConstructor(void)
+{ // testConstructor
+  GravityField db;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test label().
+void
+spatialdata::spatialdb::TestGravityField::testLabel(void)
+{ // testLabel
+  GravityField db;
+  const char* label = "database 2";
+  db.label(label);
+  CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testLabel
+
+// ----------------------------------------------------------------------
+// Test upDir().
+void
+spatialdata::spatialdb::TestGravityField::testUpDir(void)
+{ // testUpDir
+  GravityField db;
+
+  const double tolerance = 1.0e-06;
+
+  { // Test default
+    const double upDir[] = { 0.0, 0.0, 1.0 };
+    for (int i=0; i < 3; ++i)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(upDir[i], db._upDir[i], tolerance);
+  } // Test default
+  
+  { // Test user-specified
+    const double upDir[] = { 1.1, 2.2, 3.3 };
+    const double mag = 1.1*sqrt(1 + 4 + 9);
+    db.upDir(upDir[0], upDir[1], upDir[2]);
+    for (int i=0; i < 3; ++i)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(upDir[i]/mag, db._upDir[i], tolerance);
+  } // Test user-specified
+} // testUpDir
+
+// ----------------------------------------------------------------------
+// Test acceleration().
+void
+spatialdata::spatialdb::TestGravityField::testAcceleration(void)
+{ // testAcceleration
+  GravityField db;
+
+  const double tolerance = 1.0e-06;
+  const double gSI = 9.80665;
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(gSI, db._acceleration, tolerance);
+
+  const double g = 4.5;
+  db.gravAcceleration(g);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(g, db._acceleration, tolerance);
+} // testAcceleration
+
+// ----------------------------------------------------------------------
+// Test queryVals().
+void
+spatialdata::spatialdb::TestGravityField::testQueryVals(void)
+{ // testQueryVals
+  GravityField db;
+
+  const int querySize = 2;
+  const char* queryNames[] = { "z", "y" };
+  const int queryVals[] = { 2, 1 };
+
+  db.queryVals(queryNames, querySize);
+
+  CPPUNIT_ASSERT_EQUAL(querySize, db._querySize);
+  for (int i=0; i < querySize; ++i)
+    CPPUNIT_ASSERT_EQUAL(queryVals[i], db._queryVals[i]);
+} // testQueryVals
+
+// ----------------------------------------------------------------------
+// Test query() with 2-D Cartesian coordinates.
+void
+spatialdata::spatialdb::TestGravityField::testQueryCart2(void)
+{ // testQueryCart2
+  const int spaceDim = 2;
+  const double gacc = 2.0;
+  const double upDir[] = { 0.6, 0.8, 0.0 };
+  const double gravityE[] = { -1.2, -1.6 };
+  const int querySize = spaceDim;
+  const char* queryNames[] = { "x", "y" };
+  
+  GravityField db;
+  db.upDir(upDir[0], upDir[1], upDir[2]);
+  db.gravAcceleration(gacc);
+  db.open();
+  db.queryVals(queryNames, querySize);
+
+  geocoords::CSCart cs;
+  cs.setSpaceDim(spaceDim);
+  
+  double gravity[querySize];
+  const double coords[] = { 2.5, 6.3 };
+  const int err = db.query(gravity, querySize, coords, spaceDim, &cs);
+  CPPUNIT_ASSERT_EQUAL(0, err);
+  db.close();
+
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < querySize; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[i], gravity[i], tolerance);
+} // testQueryCart2
+
+// ----------------------------------------------------------------------
+// Test query() with 3-D Cartesian coordinates.
+void
+spatialdata::spatialdb::TestGravityField::testQueryCart3(void)
+{ // testQueryCart3
+  const int spaceDim = 3;
+  const double gacc = 2.0;
+  const double upDir[] = { 0.3, 0.4, -0.5 };
+  const double sqrt2 = sqrt(2.0);
+  const double gravityE[] = { -0.6*sqrt2, -0.8*sqrt2, 1.0*sqrt2 };
+  
+  GravityField db;
+  db.upDir(upDir[0], upDir[1], upDir[2]);
+  db.gravAcceleration(gacc);
+  db.open();
+
+  geocoords::CSCart cs;
+  cs.setSpaceDim(spaceDim);
+  
+  double gravity[spaceDim];
+  const double coords[] = { 2.5, 6.3, -2.4 };
+  const int err = db.query(gravity, spaceDim, coords, spaceDim, &cs);
+  CPPUNIT_ASSERT_EQUAL(0, err);
+  db.close();
+
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < spaceDim; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[i], gravity[i], tolerance);
+} // testQueryCart3
+
+// ----------------------------------------------------------------------
+// Test query() with geographic coordinates.
+void
+spatialdata::spatialdb::TestGravityField::testQueryGeographic(void)
+{ // testQueryGeographic
+  const int spaceDim = 3;
+  const double gacc = 2.0;
+  const double gravityE[] = { 0.0, 0.0, -gacc };
+  
+  GravityField db;
+  db.gravAcceleration(gacc);
+  db.open();
+
+  geocoords::CSGeo cs;
+  
+  double gravity[spaceDim];
+  const double coords[] = { 2.5, 6.3, -2.4 };
+  const int err = db.query(gravity, spaceDim, coords, spaceDim, &cs);
+  CPPUNIT_ASSERT_EQUAL(0, err);
+  db.close();
+
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < spaceDim; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[i], gravity[i], tolerance);
+} // testQueryGeographic
+
+// ----------------------------------------------------------------------
+// Test query() with projected geographic coordinates.
+void
+spatialdata::spatialdb::TestGravityField::testQueryGeoProj(void)
+{ // testQueryGeoProj
+  const int spaceDim = 3;
+  const double gacc = 2.0;
+  const double gravityE[] = { 0.0, 0.0, -gacc };
+  
+  GravityField db;
+  db.gravAcceleration(gacc);
+  db.open();
+
+  geocoords::CSGeoProj cs;
+  
+  double gravity[spaceDim];
+  const double coords[] = { 2.5, 6.3, -2.4 };
+  const int err = db.query(gravity, spaceDim, coords, spaceDim, &cs);
+  CPPUNIT_ASSERT_EQUAL(0, err);
+  db.close();
+
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < spaceDim; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[i], gravity[i], tolerance);
+} // testQueryGeoProj
+
+// ----------------------------------------------------------------------
+// Test query() with geocentric coordinates.
+void
+spatialdata::spatialdb::TestGravityField::testQueryGeocentric(void)
+{ // testQueryGeocentric
+  const int spaceDim = 3;
+
+  GravityField db;
+  db.open();
+
+  geocoords::CSGeo cs;
+  cs.isGeocentric(true);
+  cs.initialize();
+
+  const double tolerance = 1.0e-06;
+  const double gacc = 9.80665;
+
+  const int numLocs = 5;
+  const double coords[] = { 
+    0.0, 0.0, 6356752.31, // (lon=0.0, lat=90.0)
+    6378137.00, 0.0, 0.0, // (lon=0.0, lat=0.0)
+    0.0, -6378137.00, 0.0, // (lon=-90.0, lat=0.0)
+    -2684785.48, -4296554.90, 3861564.10, // (lon=-122.0, lat=37.5)
+    -2680581.35, -4289826.89, 3855476.48, // (lon=-122.0, lat=37.5, elev=-10km)
+  };
+  const double gravityE[] = {
+    0.0, 0.0, -gacc,
+    -gacc, 0.0, 0.0,
+    0.0, gacc, 0.0,
+    4.1330772777176055, 6.6143062683936451, -5.9446622298329901,
+    4.1330933324795938, 6.6143319681570834, -5.9446224726661976,
+  };
+  
+  double gravity[spaceDim];
+  for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc, index+=spaceDim) {
+    const int err = db.query(gravity, spaceDim, &coords[index], spaceDim, &cs);
+    CPPUNIT_ASSERT_EQUAL(0, err);
+
+    for (int i=0; i < spaceDim; ++i)
+      if (fabs(gravityE[index+i]) > tolerance)
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, gravity[i]/gravityE[index+i], 
+				     tolerance);
+      else
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[index+i], gravity[i], tolerance);
+  } // for
+
+  db.close();
+} // testQueryGeocentric
+
+// ----------------------------------------------------------------------
+// Test query() with geocentric coordinates and local origin.
+void
+spatialdata::spatialdb::TestGravityField::testQueryGeoLocal(void)
+{ // testQueryGeoLocal
+  const int spaceDim = 3;
+
+  GravityField db;
+  db.open();
+
+  geocoords::CSGeoLocalCart cs;
+  cs.origin(-122.0, 37.75, 0.0);
+  cs.initialize();
+
+  const double gacc = 9.80665;
+
+  const int numLocs = 3;
+  const double coords[] = {
+    0.0, 0.0, 0.0,
+    0.0, 0.0, -20e+3,
+    10.0e+3, -25e+3, -5e+3,
+  };
+  const double gravityE[] = {
+    0.0, 0.0032487084*gacc, -0.99999472*gacc,
+    0.0, 0.0032589402*gacc, -0.99999469*gacc,
+    -0.0015710173*gacc, 0.0071787331*gacc, -0.999973*gacc,
+  };
+  const double tolerance = 1.0e-06;
+  
+  double gravity[spaceDim];
+  for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc, index+=spaceDim) {
+    const int err = db.query(gravity, spaceDim, &coords[index], spaceDim, &cs);
+    CPPUNIT_ASSERT_EQUAL(0, err);
+
+    for (int i=0; i < spaceDim; ++i)
+      if (fabs(gravityE[index+i]) > tolerance)
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, gravity[i]/gravityE[index+i], 
+				     tolerance);
+      else
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(gravityE[index+i], gravity[i], tolerance);
+  } // for
+
+  db.close();
+} // testQueryGeoLocal
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.hh	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestGravityField.hh	2007-11-09 00:40:50 UTC (rev 8254)
@@ -0,0 +1,95 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file tests/libtests/spatialdb/TestGravityField.hh
+ *
+ * @brief C++ TestGravityField object
+ *
+ * C++ unit testing for GravityField.
+ */
+
+#if !defined(spatialdata_spatialdb_testgravityfield_hh)
+#define spatialdata_spatialdb_testgravityfield_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for spatial package
+namespace spatialdata {
+  namespace spatialdb {
+    class TestGravityField;
+    class GravityField; // USES GravityField
+  } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for GravityField
+class spatialdata::spatialdb::TestGravityField : public CppUnit::TestFixture
+{ // class TestGravityField
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestGravityField );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testLabel );
+  CPPUNIT_TEST( testUpDir );
+  CPPUNIT_TEST( testAcceleration );
+  CPPUNIT_TEST( testQueryVals );
+  CPPUNIT_TEST( testQueryCart2 );
+  CPPUNIT_TEST( testQueryCart3 );
+  CPPUNIT_TEST( testQueryGeographic );
+  CPPUNIT_TEST( testQueryGeoProj );
+  CPPUNIT_TEST( testQueryGeocentric );
+  CPPUNIT_TEST( testQueryGeoLocal );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor
+  void testConstructor(void);
+
+  /// Test label()
+  void testLabel(void);
+
+  /// Test upDir()
+  void testUpDir(void);
+
+  /// Test acceleration()
+  void testAcceleration(void);
+
+  /// Test queryVals()
+  void testQueryVals(void);
+
+  /// Test query() with 2-D Cartesian coordinates.
+  void testQueryCart2(void);
+
+  /// Test query() with 3-D Cartesian coordinates.
+  void testQueryCart3(void);
+
+  /// Test query() with geographic coordinates.
+  void testQueryGeographic(void);
+
+  /// Test query() with projected geographic coordinates.
+  void testQueryGeoProj(void);
+
+  /// Test query() with geocentric coordinates.
+  void testQueryGeocentric(void);
+
+  /// Test query() with geocentric coordinates and local origin.
+  void testQueryGeoLocal(void);
+
+}; // class TestGravityField
+
+#endif // spatialdata_spatialdb_testgravityfield_hh
+
+
+// End of file 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc	2007-11-08 23:35:32 UTC (rev 8253)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestUniformDB.cc	2007-11-09 00:40:50 UTC (rev 8254)
@@ -72,7 +72,7 @@
 } // testSetData
 
 // ----------------------------------------------------------------------
-// Test setData().
+// Test queryVals().
 void
 spatialdata::spatialdb::TestUniformDB::testQueryVals(void)
 { // testQueryVals



More information about the cig-commits mailing list