[cig-commits] r20430 - in cs/spatialdata/trunk: libsrc/spatialdb tests/libtests/spatialdb tests/libtests/spatialdb/data

brad at geodynamics.org brad at geodynamics.org
Thu Jun 28 14:35:59 PDT 2012


Author: brad
Date: 2012-06-28 14:35:59 -0700 (Thu, 28 Jun 2012)
New Revision: 20430

Added:
   cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc
   cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh
   cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.cc
   cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.hh
   cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc
   cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh
   cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc
   cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh
Modified:
   cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc
   cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh
   cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc
   cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.cc
   cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.hh
   cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am
Log:
Started C++ unit tests for GeoProjGridDB.

Modified: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -21,8 +21,14 @@
 #include "spatialdata/geocoords/CSGeoProj.hh" // USES CSGeoProj
 #include "spatialdata/geocoords/Projector.hh" // USES Projector
 #include "spatialdata/geocoords/Converter.hh" // USES Converter
+#include "spatialdata/geocoords/CSPicklerAscii.hh" // USES CSPicklerAscii
+#include "spatialdata/utils/LineParser.hh" // USES LineParser
 
 #include <math.h> // USES pow()
+#include <algorithm> // USES std::sort()
+#include <vector> // USES std::vector
+
+#include <fstream> // USES std::ifstream
 #include <sstream> // USES std::ostringstream
 #include <stdexcept> // USES std::logic_error
 #include <string.h> // USES memcpy()
@@ -30,6 +36,9 @@
 #include <assert.h> // USES assert()
 
 // ----------------------------------------------------------------------
+const char* spatialdata::spatialdb::GeoProjGridDB::FILEHEADER = "#SPATIAL_GRID.ascii";
+
+// ----------------------------------------------------------------------
 // Constructor
 spatialdata::spatialdb::GeoProjGridDB::GeoProjGridDB(void) :
   _data(0),
@@ -69,11 +78,44 @@
 } // destructor
 
 // ----------------------------------------------------------------------
+// Set filename containing data.
+void
+spatialdata::spatialdb::GeoProjGridDB::filename(const char* value)
+{ // filename
+  _filename = value;
+} // filename
+ 
+// ----------------------------------------------------------------------
 // Open the database and prepare for querying.
 void
 spatialdata::spatialdb::GeoProjGridDB::open(void)
 { // open
-  // ADD STUFF HERE
+  try {
+    std::ifstream filein(_filename.c_str());
+    if (!filein.is_open() || !filein.good()) {
+      std::ostringstream msg;
+      msg << "Could not open spatial database file '" << _filename
+	  << "' for reading.\n";
+      throw std::runtime_error(msg.str());
+    } // if
+
+    _readHeader(filein);
+    _readData(filein);
+    
+    if (!filein.good())
+      throw std::runtime_error("Unknown error while reading.");
+  } catch (const std::exception& err) {
+    std::ostringstream msg;
+    msg << "Error occurred while reading spatial database file '"
+	<< _filename << "'.\n"
+	<< err.what();
+    throw std::runtime_error(msg.str());
+  } catch (...) {
+    std::ostringstream msg;
+    msg << "Unknown error occurred while reading spatial database file '"
+	<< _filename << "'.\n";
+    throw std::runtime_error(msg.str());
+  } // try/catch
 } // open
 
 // ----------------------------------------------------------------------
@@ -151,18 +193,20 @@
 					     const int numDims,
 					     const spatialdata::geocoords::CoordSys* csQuery)
 { // query
-  if (0 == _querySize) {
+  const int querySize = _querySize;
+
+  if (0 == querySize) {
     std::ostringstream msg;
     msg
       << "Values to be returned by spatial database " << label() << "\n"
       << "have not been set. Please call queryVals() before query().\n";
     throw std::runtime_error(msg.str());
-  } else if (numVals != _querySize) {
+  } else if (numVals != querySize) {
     std::ostringstream msg;
     msg
       << "Number of values to be returned by spatial database "
       << label() << "\n"
-      << "(" << _querySize << ") does not match size of array provided ("
+      << "(" << querySize << ") does not match size of array provided ("
       << numVals << ").\n";
     throw std::runtime_error(msg.str());
   } else if (3 != numDims) {
@@ -174,16 +218,390 @@
   } // if
 
   // Convert coordinates
+  assert(numDims <= 3);
   memcpy(_xyz, coords, numDims*sizeof(double));
   spatialdata::geocoords::Converter::convert(_xyz, 1, numDims, _cs, csQuery);
 
   int queryFlag = 0;
-  // ADD STUFF HERE
+  const int spaceDim = _spaceDim;
 
+  double indexX = 0.0;
+  double indexY = 0.0;
+  double indexZ = 0.0;
+  if (spaceDim > 2) {
+    indexX = _search(_xyz[0], _x, _numX);
+    indexY = _search(_xyz[1], _y, _numY);
+    indexZ = _search(_xyz[2], _z, _numZ);
+  } else if (spaceDim > 1) {
+    indexX = _search(_xyz[0], _x, _numX);
+    indexY = _search(_xyz[1], _y, _numY);
+  } else { // else
+    assert(1 == spaceDim);
+    indexX = _search(_xyz[0], _x, _numX);
+  } // if/else
+  if (-1.0 == indexX || -1.0 == indexY || -1.0 == indexZ) {
+    queryFlag = 1;
+    return queryFlag;
+  } // if
+  
+  switch (_queryType) {
+  case LINEAR : 
+    switch (_dataDim) {
+    case 1: {
+      assert(false);
+      throw std::logic_error("GeoProjGridDB::query(): 1 == _dataDim not implemented.");
+      break;
+    } // case 1
+    case 2: {
+      assert(false);
+      throw std::logic_error("GeoProjGridDB::query(): 2 == _dataDim not implemented.");
+      break;
+    } // case 2
+    case 3 : {
+      _interpolate3D(vals, numVals, indexX, indexY, indexZ);
+      break;
+    } // case 3
+    default :
+      assert(false);
+      throw std::logic_error("Unsupported data dimension in GeoProjGridDB::query().");
+    } // switch
+  case NEAREST : {
+    const int indexNearestX = int(floor(indexX+0.5));
+    const int indexNearestY = int(floor(indexY+0.5));
+    const int indexNearestZ = int(floor(indexZ+0.5));
+    const int indexData = _dataIndex(indexNearestX, indexNearestY, indexNearestZ);
+    for (int iVal=0; iVal < querySize; ++iVal) {
+      vals[iVal] = _data[indexData+_queryVals[iVal]];
+    } // for
+    break;
+  } // NEAREST
+  default :
+    assert(false);
+    throw std::logic_error("Unsupported query type in GeoProjGridDB::query().");
+  } // switch
+    
   return queryFlag;
 } // query
 
 // ----------------------------------------------------------------------
+// Read data file header.
+void
+spatialdata::spatialdb::GeoProjGridDB::_readHeader(std::istream& filein)
+{ // _readHeader
+  utils::LineParser parser(filein, "//");
+  parser.eatwhitespace(true);
+
+  std::istringstream buffer;
+
+  buffer.str(parser.next());
+  buffer.clear();
+
+  const int headerLen = strlen(FILEHEADER);
+  std::string hbuffer;
+  hbuffer.resize(headerLen+1);
+  buffer.read((char*) hbuffer.c_str(), sizeof(char)*headerLen);
+  hbuffer[headerLen] = '\0';
+  if (0 != strcasecmp(FILEHEADER, hbuffer.c_str())) {
+    std::ostringstream msg;
+    msg
+      << "Magic header '" << buffer << "' does not match expected header '"
+      << FILEHEADER << "' in spatial database file '" << _filename << "'.\n";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  std::string token;
+  const int maxIgnore = 256;
+
+  buffer.str(parser.next());
+  buffer.clear();
+  buffer >> token;
+  if (0 != strcasecmp(token.c_str(), "GeoProjGridDB")) {
+    std::ostringstream msg;
+    msg << "Could not parse '" << token << "' into 'GeoProjGridDB'.\n";
+    throw std::runtime_error(msg.str());
+  } // else
+
+  _numX = 0;
+  _numY = 0;
+  _numZ = 0;
+  delete[] _x; _x = 0;
+  delete[] _y; _y = 0;
+  delete[] _z; _z = 0;
+  
+  _numValues = 0;
+  delete[] _names; _names = 0;
+  delete[] _units; _units = 0;
+
+  buffer.str(parser.next());
+  buffer.clear();
+  buffer >> token;
+  while (buffer.good() && token != "}") {
+    if (0 == strcasecmp(token.c_str(), "num-x")) {
+      buffer.ignore(maxIgnore, '=');
+      buffer >> _numX;
+    } else if (0 == strcasecmp(token.c_str(), "num-y")) {
+      buffer.ignore(maxIgnore, '=');
+      buffer >> _numY;
+    } else if (0 == strcasecmp(token.c_str(), "num-z")) {
+      buffer.ignore(maxIgnore, '=');
+      buffer >> _numZ;
+    } else if (0 == strcasecmp(token.c_str(), "space-dim")) {
+      buffer.ignore(maxIgnore, '=');
+      buffer >> _spaceDim;
+    } else if (0 == strcasecmp(token.c_str(), "num-values")) {
+      buffer.ignore(maxIgnore, '=');
+      buffer >> _numValues;
+    } else if (0 == strcasecmp(token.c_str(), "value-names")) {
+      if (_numValues > 0) {
+	_names = new std::string[_numValues];
+      } else
+	throw std::runtime_error("Number of values must be specified BEFORE "
+				 "names of values in GeoProjGridDB file.");
+      buffer.ignore(maxIgnore, '=');
+      for (int iVal=0; iVal < _numValues; ++iVal)
+	buffer >> _names[iVal];
+    } else if (0 == strcasecmp(token.c_str(), "value-units")) {
+      if (_numValues > 0) {
+	_units = new std::string[_numValues];
+      } else
+	throw std::runtime_error("Number of values must be specified BEFORE "
+				 "units of values in GeoProjGridDB file.");
+      buffer.ignore(maxIgnore, '=');
+      for (int iVal=0; iVal < _numValues; ++iVal)
+	buffer >> _units[iVal];
+    } else if (0 == strcasecmp(token.c_str(), "cs-data")) {
+      buffer.ignore(maxIgnore, '=');
+      std::string rbuffer(buffer.str());
+      filein.putback('\n');
+      filein.clear();
+      int i = rbuffer.length()-1;
+      while (i >= 0) {
+	filein.putback(rbuffer[i]);
+	if ('=' == rbuffer[i--])
+	  break;
+      } // while
+      filein.clear();
+      spatialdata::geocoords::CSPicklerAscii::unpickle(filein, &_cs);
+    } else {
+      std::ostringstream msg;
+      msg << "Could not parse '" << token << "' into a GeoProjGridDB 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 GeoProjGridDB settings.");
+  
+  bool ok = true;
+  std::ostringstream msg;
+  if (_numValues <= 0) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'num-values'.\n";
+  } // if
+  if (_spaceDim > 0 && _numX <= 0) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'num-x'.\n";
+  } // if
+  if (_spaceDim > 1 && _numY <= 0) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'num-y' with 2-D and 3-D data.\n";
+  } // if
+  if (_spaceDim > 2 && _numZ <= 0) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'num-z' with 3-D data.\n";
+  } // if
+  if (!_names) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'value-names'.\n";
+  } // if
+  if (!_units) {
+    ok = false;
+    msg << "GeoProjGridDB settings must include 'value-units'.\n";
+  } // if
+  if (!ok)
+    throw std::runtime_error(msg.str());
+
+  assert(_cs);
+  _cs->initialize();
+} // _readHeader
+
+// ----------------------------------------------------------------------
+// Read data values.
+void
+spatialdata::spatialdb::GeoProjGridDB::_readData(std::istream& filein)
+{ // _readData
+  delete[] _x; _x = 0;
+  delete[] _y; _y = 0;
+  delete[] _z; _z = 0;
+  delete[] _data; _data = 0;
+
+  const int numX = _numX;
+  const int numY = _numY;
+  const int numZ = _numZ;
+  const int numValues = _numValues;
+  const int spaceDim = _spaceDim;
+
+  utils::LineParser parser(filein, "//");
+  parser.eatwhitespace(true);
+
+  std::istringstream buffer;
+
+  int numLocs = 1;
+  if (numX > 1) {
+    numLocs *= numX;
+    _x = new double[numX];
+    buffer.str(parser.next());
+    buffer.clear();
+    for (int i=0; i < numX; ++i) {
+      filein >> _x[i];
+    } // for
+    std::vector<double> xVec(numX);
+    for (int i=0; i < numX; ++i)
+      xVec[i] = _x[i];
+    std::sort(xVec.begin(), xVec.end());
+  } // if
+
+  if (numY > 1) {
+    numLocs *= numY;
+    _y = new double[numY];
+    buffer.str(parser.next());
+    buffer.clear();
+    for (int i=0; i < numY; ++i) {
+      filein >> _y[i];
+    } // for
+    std::vector<double> yVec(numY);
+    for (int i=0; i < numY; ++i)
+      yVec[i] = _y[i];
+    std::sort(yVec.begin(), yVec.end());
+  } // if
+
+  if (numZ > 1) {
+    numLocs *= numZ;
+    _z = new double[numZ];
+    buffer.str(parser.next());
+    buffer.clear();
+    for (int i=0; i < numZ; ++i) {
+      filein >> _z[i];
+    } // for
+    std::vector<double> zVec(numZ);
+    for (int i=0; i < numZ; ++i)
+      zVec[i] = _z[i];
+    std::sort(zVec.begin(), zVec.end());
+  } // if
+
+  assert(numLocs > 0);
+  assert(numValues > 0);
+  _data = new double[numLocs*_numValues];
+  assert(spaceDim > 0);
+  double* coords = new double[spaceDim];
+  for (int iLoc=0; iLoc < numLocs; ++iLoc) {
+    buffer.str(parser.next());
+    buffer.clear();
+    for (int iDim=0; iDim < spaceDim; ++iDim)
+      buffer >> coords[iDim];
+    
+    int indexX = 0;
+    int indexY = 0;
+    int indexZ = 0;
+    if (spaceDim > 2) {
+      indexX = int(floor(_search(coords[0], _x, numX)+0.5));
+      indexY = int(floor(_search(coords[1], _y, numY)+0.5));
+      indexZ = int(floor(_search(coords[2], _z, numZ)+0.5));
+    } else if (spaceDim > 1) {
+      indexX = int(floor(_search(coords[0], _x, numX)+0.5));
+      indexY = int(floor(_search(coords[1], _y, numY)+0.5));
+    } else {
+      assert(1 == spaceDim);
+      indexX = int(floor(_search(coords[0], _x, numX)+0.5));
+    } // if
+    
+    const int indexData = _dataIndex(indexX, indexY, indexZ);
+    for (int iVal=0; iVal < _numValues; ++iVal)
+      buffer >> _data[indexData+iVal];
+    if (buffer.bad()) {
+      throw std::runtime_error("Error reading points.");
+    } // if
+  } // for
+  if (!filein.good())
+    throw std::runtime_error("I/O error while reading GeoProjGridDB data.");
+
+  // Check compatibility of dimension of data, spatial dimension and
+  // number of points
+  _checkCompatibility();
+
+  // Convert to SI units
+  SpatialDB::_convertToSI(_data, _units, numLocs, _numValues);  
+} // _readData
+
+// ----------------------------------------------------------------------
+/// Check compatibility of spatial database parameters.
+void
+spatialdata::spatialdb::GeoProjGridDB::_checkCompatibility(void) const
+{ // _checkCompatibility
+  const int spaceDim = _spaceDim;
+  const int dataDim = _dataDim;
+  std::ostringstream msg;
+
+  const int numX = _numX;
+  const int numY = _numY;
+  const int numZ = _numZ;
+
+  int count1 = 0;
+  if (1 == numX) {
+    count1 += 1;
+  } // if
+  if (1 == numY) {
+    count1 += 1;
+  } // if
+  if (1 == numZ) {
+    count1 += 1;
+  } // if
+
+  if (0 == dataDim && 3 != count1) {
+    msg << "Dimension of data in spatial distribution (" << dataDim
+	<< ") is incompatible with dimensions of a 0-D grid  ("
+	<< numX << "," << numY << "," << numZ << ").";
+    throw std::runtime_error(msg.str());
+
+  } else if (1 == dataDim && 2 != count1) {
+    msg << "Dimension of data in spatial distribution (" << dataDim
+	<< ") is incompatible with dimensions of a 1-D grid  ("
+	<< numX << "," << numY << "," << numZ << ").";
+    throw std::runtime_error(msg.str());
+
+  } else if (2 == dataDim && 1 != count1) {
+    msg << "Dimension of data in spatial distribution (" << dataDim
+	<< ") is incompatible with dimensions of a 2-D grid  ("
+	<< numX << "," << numY << "," << numZ << ").";
+    throw std::runtime_error(msg.str());
+
+  } else if (3 == dataDim && 0 != count1) {
+    msg << "Dimension of data in spatial distribution (" << dataDim
+	<< ") is incompatible with dimensions of a 3-D grid  ("
+	<< numX << "," << numY << "," << numZ << ").";
+    throw std::runtime_error(msg.str());
+  } // if/else
+
+  if (dataDim > spaceDim) {
+    msg << "Dimension of data in spatial distribution (" << dataDim
+	<< ") exceeds the number of dimensions of the coordinates ("
+	<< spaceDim << ").";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  if (spaceDim != _cs->spaceDim()) {
+    msg << "Number of dimensions in coordinates of spatial distribution ("
+	<< spaceDim << ") does not match number of dimensions in coordinate "
+	<< "system (" << _cs->spaceDim() << ")";
+    throw std::runtime_error(msg.str());
+  } // if
+} // _checkCompatibility
+
+#include <iostream>
+// ----------------------------------------------------------------------
 // Bilinear search for coordinate.
 double
 spatialdata::spatialdb::GeoProjGridDB::_search(const double target,
@@ -194,55 +612,70 @@
   assert(nvals > 0);
 
   double index = -1.0;
+
+  if (1 == nvals) {
+    return 0.0;
+  } // if
+
   int indexL = 0;
-  int indexR = nvals-1;
-  if (target >= vals[indexL] && target <= vals[indexR]) {
-    while (indexL - indexR > 1) {
-      int indexM = indexL + (indexL-indexR) / 2;
+  int indexR = nvals - 1;
+  const double tolerance = 1.0e-6;
+  if (target >= vals[indexL]-tolerance && target <= vals[indexR]+tolerance) {
+    while (indexR - indexL > 1) {
+      int indexM = indexL + (indexR-indexL) / 2;
       if (target < vals[indexM]) {
 	indexR = indexM;
       } else {
 	indexL = indexM;
       } // if/else
     } // while
-    assert(target >= vals[indexL]);
+    assert(target >= vals[indexL]-tolerance);
     assert(vals[indexR] > vals[indexL]);
-    index = (target - vals[indexL]) / (vals[indexR] - vals[indexL]);
-  } // if
+    index = double(indexL) + (target - vals[indexL]) / (vals[indexR] - vals[indexL]);
+  } else if (_queryType == NEAREST) {
+    if (target <= vals[indexL]) {
+      index = 0.0;
+    } else {
+      index = double(nvals-1);
+    } // if/else
+  } // if/else
 
   return index;
 } // _search
 
 // ----------------------------------------------------------------------
-// Interpolate to get values at target location defined by indices.
+// Interpolate to get values at target location defined by indices in 3-D.
 void
-spatialdata::spatialdb::GeoProjGridDB::_interpolate(double* vals,
-						    const int numVals,
-						    const double indexX,
-						    const double indexY,
-						    const double indexZ)
-{ // _interpolate
+spatialdata::spatialdb::GeoProjGridDB::_interpolate3D(double* vals,
+						      const int numVals,
+						      const double indexX,
+						      const double indexY,
+						      const double indexZ) const
+{ // _interpolate3D
+  const int numX = _numX;
+  const int numY = _numY;
+  const int numZ = _numZ;
 
   const int indexX0 = int(floor(indexX));
   const double wtX0 = 1.0 - (indexX - indexX0);
   const int indexX1 = indexX0 + 1;
   const double wtX1 = 1.0 - wtX0;
-  assert(0 >= indexX0 && indexX0 < _numX);
-  assert(0 >= indexX1 && indexX1 < _numX);
+  assert(0 >= indexX0 && indexX0 < numX);
+  assert(0 >= indexX1 && indexX1 < numX);
 
   const int indexY0 = int(floor(indexY));
   const double wtY0 = 1.0 - (indexY - indexY0);
   const int indexY1 = indexY0 + 1;
   const double wtY1 = 1.0 - wtY0;
-  assert(0 >= indexY0 && indexY0 < _numY);
-  assert(0 >= indexY1 && indexY1 < _numY);
+  assert(0 >= indexY0 && indexY0 < numY);
+  assert(0 >= indexY1 && indexY1 < numY);
   
   const int indexZ0 = int(floor(indexZ));
   const double wtZ0 = 1.0 - (indexZ - indexZ0);
   const int indexZ1 = indexZ0 + 1;
   const double wtZ1 = 1.0 - wtZ0;
-  assert(0 >= indexZ0 && indexZ0 < _numZ);
-  assert(0 >= indexZ1 && indexZ1 < _numZ);
+  assert(0 >= indexZ0 && indexZ0 < numZ);
+  assert(0 >= indexZ1 && indexZ1 < numZ);
 
   const int index000 = _dataIndex(indexX0, indexY0, indexZ0);
   const int index001 = _dataIndex(indexX0, indexY0, indexZ1);
@@ -262,18 +695,20 @@
   const double wt110 = wtX1 * wtY1 * wtZ0;
   const double wt111 = wtX1 * wtY1 * wtZ1;
 
-  for (int iVal=0; iVal < numVals; ++iVal) {
+  const int querySize = _querySize;
+  for (int iVal=0; iVal < querySize; ++iVal) {
+    const int qVal = _queryVals[iVal];
     vals[iVal] = 
-      wt000 * _data[index000] +
-      wt001 * _data[index001] +
-      wt010 * _data[index010] +
-      wt011 * _data[index011] +
-      wt100 * _data[index100] +
-      wt101 * _data[index101] +
-      wt110 * _data[index110] +
-      wt111 * _data[index111];
+      wt000 * _data[index000+qVal] +
+      wt001 * _data[index001+qVal] +
+      wt010 * _data[index010+qVal] +
+      wt011 * _data[index011+qVal] +
+      wt100 * _data[index100+qVal] +
+      wt101 * _data[index101+qVal] +
+      wt110 * _data[index110+qVal] +
+      wt111 * _data[index111+qVal];
   } // for
-} // _interpolate
+} // _interpolate3D
 
 
 // End of file

Modified: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -26,6 +26,7 @@
 #include "SpatialDB.hh" // ISA SpatialDB
 
 #include <string> // HASA std::string
+#include <iosfwd> // USES std::istream
 
 class spatialdata::spatialdb::GeoProjGridDB : SpatialDB
 { // GeoProjGridDB
@@ -104,6 +105,21 @@
 // PRIVATE METHODS //////////////////////////////////////////////////////
 private :
 
+  /** Read data file header.
+   *
+   * @param filein Input stream.
+   */
+  void _readHeader(std::istream& filein);
+
+  /** Read data values.
+   *
+   * @param filein Input stream.
+   */
+  void _readData(std::istream& filein);
+
+  /// Check compatibility of spatial database parameters.
+  void _checkCompatibility(void) const;
+
   /** Bilinear search for coordinate.
    *
    * Returns index of target as a double.
@@ -125,11 +141,11 @@
    * @param indexY Index along y dimension.
    * @param indexZ Index along z dimension.
    */
-  void _interpolate(double* vals,
-		    const int numVals,
-		    const double indexX,
-		    const double indexY,
-		    const double indexZ);
+  void _interpolate3D(double* vals,
+		      const int numVals,
+		      const double indexX,
+		      const double indexY,
+		      const double indexZ) const;
 
   /** Get index into data array.
    *
@@ -146,29 +162,33 @@
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
   
-  double* _data; ///< Array of data values
-  double* _x; ///< Array of x coordinates
-  double* _y; ///< Array of y coordinates
-  double* _z; ///< Array of z coordinates
+  double* _data; ///< Array of data values.
+  double* _x; ///< Array of x coordinates.
+  double* _y; ///< Array of y coordinates.
+  double* _z; ///< Array of z coordinates.
 
   double _xyz[3];
 
   int* _queryVals; ///< Indices of values to be returned in queries.
   int _querySize; ///< Number of values requested to be returned in queries.
 
-  int _numX; ///< Number of points along x dimension
-  int _numY; ///< Number of points along y dimension
-  int _numZ; ///< Number of points along z dimension
+  int _numX; ///< Number of points along x dimension.
+  int _numY; ///< Number of points along y dimension.
+  int _numZ; ///< Number of points along z dimension.
+  int _dataDim; ///< Dimension of data topology.
+  int _spaceDim; ///< Spatial dimension of data.
 
   int _numValues; ///< Number of values in database.
   std::string* _names; ///< Names of data values.
   std::string* _units; ///< Units of values.  
 
-  std::string _filename;
-  geocoords::CSGeoProj* _cs;
+  std::string _filename; ///< Filename of data file
+  geocoords::CoordSys* _cs; ///< Coordinate system
 
   QueryEnum _queryType; ///< Query type
 
+  static const char* FILEHEADER;
+
 // NOT IMPLEMENTED //////////////////////////////////////////////////////
 private :
  

Modified: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -26,7 +26,8 @@
 						  const int indexY,
 						  const int indexZ) const
 { // _dataIndex
-  return indexX*_numY*_numZ + indexY*_numY + indexZ;
+  const int locIndex = indexX*_numY*_numZ + indexY*_numZ + indexZ;
+  return locIndex*_numValues;
 } // _dataIndex
 
 

Modified: cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.cc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.cc	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -126,4 +126,15 @@
 } // multiquery
 
 
+// ----------------------------------------------------------------------
+// Convert values to SI units.
+void
+spatialdata::spatialdb::SpatialDB::_convertToSI(double* vals,
+						std::string* units,
+						const int numLocs,
+						const int numVals)
+{ // _convertToSI
+  assert(false);
+} // _convertToSI
+
 // End of file 

Modified: cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.hh
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.hh	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SpatialDB.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -183,8 +183,24 @@
 		  const int numDimsC,
 		  const spatialdata::geocoords::CoordSys* csQuery);
 
+  // PROTECTED METHODS //////////////////////////////////////////////////
+protected :
+  
+  /** Convert values to SI units.
+   *
+   * @param data Array of data.
+   * @param units Units for values.
+   * @param numLocs Number of locations.
+   * @param numVals Number of values per location.
+   */
+  static
+  void _convertToSI(double* vals,
+		    std::string* units,
+		    const int numLocs,
+		    const int numVals);
+
+  // PRIVATE METHODS ////////////////////////////////////////////////////
  private :
-  // PRIVATE METHODS ////////////////////////////////////////////////////
   
   SpatialDB(const SpatialDB& data); ///< Not implemented
   const SpatialDB& operator=(const SpatialDB& data); ///< Not implemented

Modified: cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am	2012-06-28 16:52:31 UTC (rev 20429)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am	2012-06-28 21:35:59 UTC (rev 20430)
@@ -40,6 +40,7 @@
 	TestTimeHistory.cc \
 	TestTimeHistoryIO.cc \
 	TestUniformDB.cc \
+	TestGeoProjGridDB.cc \
 	testcquery.c \
 	testspatial.cc
 
@@ -59,6 +60,7 @@
 	TestTimeHistory.hh \
 	TestTimeHistoryIO.hh \
 	TestUniformDB.hh \
+	TestGeoProjGridDB.hh \
 	testcquery.h \
 	TestSpatialDB.hh
 
@@ -82,7 +84,9 @@
 	data/SimpleDBTestDataPoint3D.cc \
 	data/SimpleDBTestDataLine3D.cc \
 	data/SimpleDBTestDataArea3D.cc \
-	data/SimpleDBTestDataVolume3D.cc
+	data/SimpleDBTestDataVolume3D.cc \
+	data/GeoProjGridDBTestData.cc \
+	data/GeoProjGridDBTestDataVolume3D.cc
 
 noinst_HEADERS += \
 	data/SimpleDBQueryData.hh \
@@ -91,7 +95,9 @@
 	data/SimpleDBTestDataPoint3D.hh \
 	data/SimpleDBTestDataLine3D.hh \
 	data/SimpleDBTestDataArea3D.hh \
-	data/SimpleDBTestDataVolume3D.hh
+	data/SimpleDBTestDataVolume3D.hh \
+	data/GeoProjGridDBTestData.hh \
+	data/GeoProjGridDBTestDataVolume3D.hh
 
 
 # End of file 

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,259 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestGeoProjGridDB.hh" // Implementation of class methods
+
+#include "spatialdata/spatialdb/GeoProjGridDB.hh" // USES GeoProjGridDB
+
+#include "data/GeoProjGridDBTestData.hh" // USES GeoProjGridDBTestData
+
+#include "spatialdata/geocoords/CSCart.hh" // USE CSCart
+
+#include <string.h> // USES strcmp() and memcpy()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestGeoProjGridDB );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testConstructor(void)
+{ // testConstructor
+  GeoProjGridDB db;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test label()
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testLabel(void)
+{ // testLabel
+  GeoProjGridDB db;
+  const char* label = "database 2";
+  db.label(label);
+  CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testLabel
+
+// ----------------------------------------------------------------------
+// Test filename()
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testFilename(void)
+{ // testFilename
+  GeoProjGridDB db;
+  const std::string& filename = "mydb.spatialdb";
+  db.filename(filename.c_str());
+  CPPUNIT_ASSERT_EQUAL(filename, db._filename);
+} // testFilename
+
+// ----------------------------------------------------------------------
+// Test queryType()
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testQueryType(void)
+{ // testQueryType
+  GeoProjGridDB db;
+
+  // Test default (nearest)
+  CPPUNIT_ASSERT_EQUAL(GeoProjGridDB::NEAREST, db._queryType);
+
+  db.queryType(GeoProjGridDB::LINEAR);
+  CPPUNIT_ASSERT_EQUAL(GeoProjGridDB::LINEAR, db._queryType);
+  
+  db.queryType(GeoProjGridDB::NEAREST);
+  CPPUNIT_ASSERT_EQUAL(GeoProjGridDB::NEAREST, db._queryType);
+} // testQueryType
+
+// ----------------------------------------------------------------------
+// Test _search()
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testSearch(void)
+{ // testSearch
+  const int numX = 5;
+  const double x[numX] = {
+    -3.0, -1.0, 0.0, 5.0, 8.0,
+  };
+  const double tolerance = 1.0e-6;
+
+  GeoProjGridDB db;
+  
+  db.queryType(GeoProjGridDB::NEAREST);
+
+  // Test data and expected results
+  const double xA = -20.0;
+  const double indexA = 0.0;
+
+  const double xB = -1.0;
+  const double indexB = 1.0;
+
+  const double xC = +3.0;
+  const double indexC = 2.6;
+  
+  const double xD = -20.0;
+  const double indexD = 0.0;
+
+  double index = db._search(xA, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexA, index, tolerance);
+
+  index = db._search(xB, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexB, index, tolerance);
+
+  index = db._search(xC, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexC, index, tolerance);
+
+  index = db._search(xD, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexD, index, tolerance);
+
+  db.queryType(GeoProjGridDB::LINEAR);
+
+  // Test data and expected results
+  const double xE = -20.0;
+  const double indexE = -1.0;
+
+  const double xF = -1.0;
+  const double indexF = 1.0;
+
+  const double xG = +3.0;
+  const double indexG = 2.6;
+  
+  const double xH = -20.0;
+  const double indexH = -1.0;
+
+  index = db._search(xE, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexE, index, tolerance);
+
+  index = db._search(xF, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexF, index, tolerance);
+
+  index = db._search(xG, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexG, index, tolerance);
+
+  index = db._search(xH, x, numX);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(indexH, index, tolerance);
+} // testSearch
+
+// ----------------------------------------------------------------------
+// Test _dataIndex()
+void
+spatialdata::spatialdb::TestGeoProjGridDB::testDataIndex(void)
+{ // testDataIndex
+  GeoProjGridDB db;
+  db._numX = 4;
+  db._numY = 3;
+  db._numZ = 5;
+  db._numValues = 10;
+
+  CPPUNIT_ASSERT_EQUAL(0, db._dataIndex(0, 0, 0));
+  CPPUNIT_ASSERT_EQUAL(10, db._dataIndex(0, 0, 1));
+
+  CPPUNIT_ASSERT_EQUAL(50, db._dataIndex(0, 1, 0));
+  CPPUNIT_ASSERT_EQUAL(50+40, db._dataIndex(0, 1, 4));
+
+  CPPUNIT_ASSERT_EQUAL(150, db._dataIndex(1, 0, 0));
+  CPPUNIT_ASSERT_EQUAL(2*150+1*50+30, db._dataIndex(2, 1, 3));
+} // testDataIndex
+
+// ----------------------------------------------------------------------
+// Test query() using nearest neighbor
+void
+spatialdata::spatialdb::TestGeoProjGridDB::_testQueryNearest(const GeoProjGridDBTestData& data)
+{ // _testQueryNearest
+  GeoProjGridDB db;
+  _setupDB(&db, data);
+  db.queryType(GeoProjGridDB::NEAREST);
+  _checkQuery(db, data.names, data.queryNearest, 0,
+	      data.numQueries, data.spaceDim, data.numVals);
+} // _testQueryNearest
+
+// ----------------------------------------------------------------------
+// Test query() using linear interpolation
+void
+spatialdata::spatialdb::TestGeoProjGridDB::_testQueryLinear(const GeoProjGridDBTestData& data)
+{ // _testQueryLinear
+  GeoProjGridDB db;
+  _setupDB(&db, data);
+  db.queryType(GeoProjGridDB::LINEAR);
+  _checkQuery(db, data.names, data.queryLinear, data.errFlags,
+	      data.numQueries, data.spaceDim, data.numVals);
+} // _testQueryLinear
+
+// ----------------------------------------------------------------------
+// Populate database with data.
+void
+spatialdata::spatialdb::TestGeoProjGridDB::_setupDB(GeoProjGridDB* const db,
+						  const GeoProjGridDBTestData& data)
+{ // _setupDB
+#if 0
+  dbData->allocate(data.numLocs, data.numVals, data.spaceDim,
+		   data.dataDim);
+  dbData->data(data.dbData, data.numLocs, data.numVals);
+  dbData->coordinates(data.dbCoords, data.numLocs, data.spaceDim);
+  dbData->names(const_cast<const char**>(data.names), data.numVals);
+  dbData->units(const_cast<const char**>(data.units), data.numVals);
+
+  db->_data = dbData;
+  db->_cs = new spatialdata::geocoords::CSCart();
+#endif
+} // _setupDB
+
+// ----------------------------------------------------------------------
+// Test query method by doing query and checking values returned.
+void
+spatialdata::spatialdb::TestGeoProjGridDB::_checkQuery(GeoProjGridDB& db,
+						       char** const names,
+						       const double* queryData,
+						       const int* flagsE,
+						       const int numQueries,
+						       const int spaceDim,
+						       const int numVals)
+{ // _checkQuery
+  CPPUNIT_ASSERT(names);
+  CPPUNIT_ASSERT(queryData);
+  CPPUNIT_ASSERT(numQueries);
+  CPPUNIT_ASSERT(spaceDim);
+  CPPUNIT_ASSERT(numVals);
+
+  // reverse order of vals in queries
+  const char* valNames[numVals];
+  for (int i=0; i < numVals; ++i)
+    valNames[numVals-i-1] = names[i];
+  db.queryVals(valNames, numVals);
+  
+  double* vals = (0 < numVals) ? new double[numVals] : 0;
+  const double tolerance = 1.0e-06;
+  
+  const int locSize = spaceDim + numVals;
+  spatialdata::geocoords::CSCart csCart;
+  for (int iQuery=0; iQuery < numQueries; ++iQuery) {
+    const double* coords = &queryData[iQuery*locSize];
+    const double* valsE = &queryData[iQuery*locSize+spaceDim];
+    const int err = db.query(vals, numVals, coords, spaceDim, &csCart);
+    if (0 != flagsE)
+      CPPUNIT_ASSERT(err == flagsE[iQuery]);
+    else
+      CPPUNIT_ASSERT(0 == err);
+    for (int iVal=0; iVal < numVals; ++iVal)
+      if (valsE[numVals-iVal-1] > tolerance)
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[iVal]/valsE[numVals-iVal-1],
+				     tolerance);
+      else
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(valsE[numVals-iVal-1], vals[iVal],
+				     tolerance);
+  } // for
+  delete[] vals; vals = 0;
+} // _checkQuery
+
+
+// End of file 

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,126 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file tests/libtests/spatialdb/TestGeoProjGridDB.hh
+ *
+ * @brief C++ TestGeoProjGridDB object
+ *
+ * C++ unit testing for GeoProjGridDB. This object is an abstract base
+ * class with children classes specific to the type of data in the database.
+ */
+
+#if !defined(spatialdata_spatialdb_testgeoprojgriddb_hh)
+#define spatialdata_spatialdb_testgeoprojgriddb_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "spatialdata/spatialdb/spatialdbfwd.hh"
+
+/// Namespace for spatial package
+namespace spatialdata {
+  namespace spatialdb {
+    class TestGeoProjGridDB;
+    class GeoProjGridDBTestData; // USES GeoProjGridDBTestData
+  } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for GeoProjGridDB
+class spatialdata::spatialdb::TestGeoProjGridDB : public CppUnit::TestFixture
+{ // class TestGeoProjGridDB
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestGeoProjGridDB );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testLabel );
+  CPPUNIT_TEST( testFilename );
+  CPPUNIT_TEST( testQueryType );
+  CPPUNIT_TEST( testSearch );
+  CPPUNIT_TEST( testDataIndex );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor
+  void testConstructor(void);
+
+  /// Test label()
+  void testLabel(void);
+
+  /// Test filename()
+  void testFilename(void);
+
+  /// Test queryType()
+  void testQueryType(void);
+
+  /// Test _search()
+  void testSearch(void);
+
+  /// Test _dataIndex()
+  void testDataIndex(void);
+
+protected :
+  // PROTECTED METHODS //////////////////////////////////////////////////
+
+  /** Test query() using nearest neighbor
+   *
+   * @param data Data for database
+   */
+  void _testQueryNearest(const GeoProjGridDBTestData& data);
+
+  /** Test query() using linear interpolation
+   *
+   * @param data Data for database
+   */
+  void _testQueryLinear(const GeoProjGridDBTestData& data);
+
+  // PRIVATE METHODS ////////////////////////////////////////////////////
+private :
+
+  /** Populate database with data.
+   *
+   * @param db Database
+   * @param data Data for database
+   */
+  void _setupDB(GeoProjGridDB* const db,
+		const GeoProjGridDBTestData& data);
+
+  /** Test query method by doing query and checking values returned.
+   * 
+   * @param db Database to query
+   * @param names Names of values in database
+   * @param queryData Query locations and expected values
+   * @param flagsE Array of expected return values
+   * @param numQueries Number of queries
+   * @param spaceDim Number of coordinates per location
+   * @param numVals Number of values in database
+   */
+  void _checkQuery(GeoProjGridDB& db,
+		   char** const names,
+		   const double* queryData,
+		   const int* flagsE,
+		   const int numQueries,
+		   const int spaceDim,
+		   const int numVals);
+
+}; // class TestGeoProjGridDB
+
+#endif // spatialdata_spatialdb_testgeoprojgriddb_hh
+
+
+// End of file 

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.cc	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,47 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestSimpleDBVolume3D.hh" // Implementation of class methods
+
+#include "data/SimpleDBTestDataVolume3D.hh"
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestSimpleDBVolume3D );
+
+// ----------------------------------------------------------------------
+// Test queryLinear()
+void
+spatialdata::spatialdb::TestSimpleDBVolume3D::testQueryLinear(void)
+{ // testQueryLinear
+  SimpleDBTestDataVolume3D data;
+
+  _testQueryLinear(data);
+} // testQueryLinear
+
+// ----------------------------------------------------------------------
+// Test queryNearest()
+void
+spatialdata::spatialdb::TestSimpleDBVolume3D::testQueryNearest(void)
+{ // testQueryNearest
+  SimpleDBTestDataVolume3D data;
+
+  _testQueryNearest(data);
+} // testQueryNearest
+
+
+// End of file 

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.hh	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBVolume3D.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file tests/libtests/spatialdb/TestSimpleDBVolume3D.hh
+ *
+ * @brief C++ TestSimpleDBVolume3D object
+ *
+ * C++ unit testing for SimpleDB. This object tests the volumetric
+ * interpolation.
+ */
+
+#if !defined(spatialdata_spatialdb_testsimpledbvolume3d_hh)
+#define spatialdata_spatialdb_testsimpledbvolume3d_hh
+
+#include "TestSimpleDB.hh" // ISA TestSimpleDB
+
+/// Namespace for spatial package
+namespace spatialdata {
+  namespace spatialdb {
+    class TestSimpleDBVolume3D;
+  } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for SimpleDB
+class spatialdata::spatialdb::TestSimpleDBVolume3D : public TestSimpleDB
+{ // class TestSimpleDBVolume3D
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestSimpleDBVolume3D );
+  CPPUNIT_TEST( testQueryNearest );
+  CPPUNIT_TEST( testQueryLinear );
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test queryNearest()
+  void testQueryNearest(void);
+
+  /// Test queryLinear()
+  void testQueryLinear(void);
+
+}; // class TestSimpleDBVolume3D
+
+#endif // spatialdata_spatialdb_testsimpledbvolume3d_hh
+
+
+// End of file 

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,48 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#include "GeoProjGridDBTestData.hh"
+
+// ----------------------------------------------------------------------
+// Constructor
+spatialdata::spatialdb::GeoProjGridDBTestData::GeoProjGridDBTestData(void) :
+  numX(0),
+  numY(0),
+  numZ(0),
+  spaceDim(0),
+  numVals(0),
+  dataDim(0),
+  dbX(0),
+  dbY(0),
+  dbZ(0),
+  dbData(0),
+  errFlags(0),
+  names(0),
+  units(0),
+  numQueries(0),
+  queryNearest(0),
+  queryLinear(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+spatialdata::spatialdb::GeoProjGridDBTestData::~GeoProjGridDBTestData(void)
+{ // destructor
+} // destructor
+
+
+// End of file

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,70 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_geoprojgriddbtestdata_hh)
+#define spatialdata_spatialdb_geoprojgriddbtestdata_hh
+
+namespace spatialdata {
+  namespace spatialdb {
+     class GeoProjGridDBTestData;
+  } // spatialdb
+} // spatialdata
+
+class spatialdata::spatialdb::GeoProjGridDBTestData
+{
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+  
+  /// Constructor
+  GeoProjGridDBTestData(void);
+
+  /// Destructor
+  ~GeoProjGridDBTestData(void);
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public:
+  
+  /// @name Database information
+  //@{
+  int numX; ///< Number of locations in x dimension.
+  int numY; ///< Number of locations in x dimension.
+  int numZ; ///< Number of locations in x dimension.
+  int spaceDim; ///< Spatial dimension for coordinates of locations
+  int numVals; ///< Number of values per location in database
+  int dataDim; ///< Spatial dimension of data in database
+  double* dbX; ///< Coordinates along x dimension.
+  double* dbY; ///< Coordinates along x dimension.
+  double* dbZ; ///< Coordinates along x dimension.
+  double* dbData; ///< Database data
+  char** names; ///< Names of values in database
+  char** units; ///< Units of values in database
+  //@}
+
+  /// @name Query information
+  //@{
+  int numQueries; ///< Number of queries
+  double* queryNearest; ///< Data for nearest neighbor queries
+  double* queryLinear; ///< Data for linear interpolation queries
+  int* errFlags; ///< Expected return values for queries
+  //@}
+
+};
+
+#endif // spatialdata_spatialdb_geoprojgriddbtestdata_hh
+
+
+// End of file

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,105 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#include "GeoProjGridDBTestDataVolume3D.hh"
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numX = 2;
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numY = 3;
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numZ = 4;
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_spaceDim = 3;
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numVals = 2;
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dataDim = 3;
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numQueries = 5;
+
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbX[_numX] = {
+  0.0, 0.0,
+};
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbY[_numY] = {
+  0.0, 0.0, 0.0,
+};
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbZ[_numZ] = {
+  0.0, 0.0, 0.0, 0.0,
+};
+
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbData[] = {
+  1.00000000e-01,  1.10000000e+00,
+  3.00000000e-01,  3.30000000e+00,
+  2.00000000e-01,  2.20000000e+00,
+  1.00000000e-01,  1.10000000e+00,
+  4.00000000e-01,  4.60000000e+00,
+  3.00000000e-01,  3.20000000e+00,
+  7.00000000e-01,  5.20000000e+00,
+  5.00000000e-01,  4.60000000e+00,
+};
+
+const char* spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_names[] = {
+"One",
+"Two",
+};
+
+const char* spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_units[] = {
+"m",
+"m",
+};
+
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_queryNearest[] = {
+  4.38173419e+00,  8.36254772e+00,  8.74899281e+00,  1.00000000e-01,  1.10000000e+00,
+  2.35495601e+00,  1.00264422e+01,  9.00123360e+00,  5.00000000e-01,  4.60000000e+00,
+  3.91112675e+00,  1.07838373e+01,  9.69020768e+00,  7.00000000e-01,  5.20000000e+00,
+  3.87701461e+00,  1.04910673e+01,  9.08761157e+00,  7.00000000e-01,  5.20000000e+00,
+  3.01795532e+00,  8.84019490e+00,  8.79326896e+00,  3.00000000e-01,  3.30000000e+00,
+};
+
+const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_queryLinear[] = {
+  4.38173419e+00,  8.36254772e+00,  8.74899281e+00,  1.35000000e-01,  1.49500000e+00,
+  2.35495601e+00,  1.00264422e+01,  9.00123360e+00,  4.10000000e-01,  3.85500000e+00,
+  3.91112675e+00,  1.07838373e+01,  9.69020768e+00,  0.00000000e+00,  0.00000000e+00,
+  3.87701461e+00,  1.04910673e+01,  9.08761157e+00,  5.30000000e-01,  4.42000000e+00,
+  3.01795532e+00,  8.84019490e+00,  8.79326896e+00,  2.00000000e-01,  2.15500000e+00,
+};
+
+const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_errFlags[] = {
+ 0, 0, 1, 0, 0,};
+
+spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::GeoProjGridDBTestDataVolume3D(void)
+{ // constructor
+  numX = _numX;
+  numY = _numY;
+  numZ = _numZ;
+  spaceDim = _spaceDim;
+  numVals = _numVals;
+  dataDim = _dataDim;
+  numQueries = _numQueries;
+  dbX = const_cast<double*>(_dbX);
+  dbY = const_cast<double*>(_dbY);
+  dbZ = const_cast<double*>(_dbZ);
+  dbData = const_cast<double*>(_dbData);
+  names = const_cast<char**>(_names);
+  units = const_cast<char**>(_units);
+  queryNearest = const_cast<double*>(_queryNearest);
+  queryLinear = const_cast<double*>(_queryLinear);
+  errFlags = const_cast<int*>(_errFlags);
+} // constructor
+
+spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::~GeoProjGridDBTestDataVolume3D(void)
+{}
+
+
+// End of file

Added: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh	                        (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh	2012-06-28 21:35:59 UTC (rev 20430)
@@ -0,0 +1,77 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_geoprojgriddbtestdatavolume3d_hh)
+#define spatialdata_spatialdb_geoprojgriddbtestdatavolume3d_hh
+
+#include "GeoProjGridDBTestData.hh"
+
+namespace spatialdata {
+  namespace spatialdb {
+     class GeoProjGridDBTestDataVolume3D;
+  } // spatialdata
+} // spatialdb
+
+class spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D : public GeoProjGridDBTestData
+{
+
+public: 
+
+  /// Constructor
+  GeoProjGridDBTestDataVolume3D(void);
+
+  /// Destructor
+  ~GeoProjGridDBTestDataVolume3D(void);
+
+private:
+
+  static const int _numX;
+
+  static const int _numY;
+
+  static const int _numZ;
+
+  static const int _spaceDim;
+
+  static const int _numVals;
+
+  static const int _dataDim;
+
+  static const int _numQueries;
+
+  static const double _dbX[];
+
+  static const double _dbY[];
+
+  static const double _dbZ[];
+
+  static const double _dbData[];
+
+  static const char* _names[];
+
+  static const char* _units[];
+
+  static const double _queryNearest[];
+
+  static const double _queryLinear[];
+
+  static const int _errFlags[];
+
+};
+
+#endif // spatialdata_spatialdb_geoprojgriddbtestdatavolume3d_hh
+
+// End of file



More information about the CIG-COMMITS mailing list