[cig-commits] r20436 - in cs/spatialdata/trunk: libsrc libsrc/spatialdb modulesrc/spatialdb spatialdata spatialdata/spatialdb tests/libtests/spatialdb tests/libtests/spatialdb/data tests/pytests/spatialdb tests/pytests/spatialdb/data
brad at geodynamics.org
brad at geodynamics.org
Thu Jun 28 21:49:19 PDT 2012
Author: brad
Date: 2012-06-28 21:49:18 -0700 (Thu, 28 Jun 2012)
New Revision: 20436
Added:
cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc
cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.hh
cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.icc
cs/spatialdata/trunk/modulesrc/spatialdb/SimpleGridDB.i
cs/spatialdata/trunk/spatialdata/spatialdb/SimpleGridDB.py
cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.hh
cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.hh
cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.hh
cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.hh
cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py
cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb
cs/spatialdata/trunk/tests/pytests/spatialdb/data/simple.spatialdb
Removed:
cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc
cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh
cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc
cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh
cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.cc
cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.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
cs/spatialdata/trunk/tests/pytests/spatialdb/data/spatialdb.dat
Modified:
cs/spatialdata/trunk/libsrc/Makefile.am
cs/spatialdata/trunk/libsrc/spatialdb/Makefile.am
cs/spatialdata/trunk/libsrc/spatialdb/spatialdbfwd.hh
cs/spatialdata/trunk/modulesrc/spatialdb/Makefile.am
cs/spatialdata/trunk/modulesrc/spatialdb/spatialdb.i
cs/spatialdata/trunk/spatialdata/Makefile.am
cs/spatialdata/trunk/spatialdata/spatialdb/SpatialDBObj.py
cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am
cs/spatialdata/trunk/tests/pytests/spatialdb/Makefile.am
cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleDB.py
cs/spatialdata/trunk/tests/pytests/spatialdb/data/Makefile.am
cs/spatialdata/trunk/tests/pytests/spatialdb/testspatial.py
Log:
Changed GeoProjGridDB to SimpleGridDB since it works for any coordinate system. Started work on Python unit tests.
Modified: cs/spatialdata/trunk/libsrc/Makefile.am
===================================================================
--- cs/spatialdata/trunk/libsrc/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -36,7 +36,7 @@
spatialdb/GocadVoxet.cc \
spatialdb/GravityField.cc \
spatialdb/SCECCVMH.cc \
- spatialdb/GeoProjGridDB.cc \
+ spatialdb/SimpleGridDB.cc \
spatialdb/SimpleDB.cc \
spatialdb/SpatialDB.cc \
spatialdb/SimpleDBData.cc \
Deleted: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,731 +0,0 @@
-// -*- 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 "GeoProjGridDB.hh" // Implementation of class methods
-
-#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()
-#include <strings.h> // USES strcasecmp()
-#include <assert.h> // USES assert()
-
-// ----------------------------------------------------------------------
-const char* spatialdata::spatialdb::GeoProjGridDB::FILEHEADER = "#SPATIAL_GRID.ascii";
-
-// ----------------------------------------------------------------------
-// Constructor
-spatialdata::spatialdb::GeoProjGridDB::GeoProjGridDB(void) :
- _data(0),
- _x(0),
- _y(0),
- _z(0),
- _filename(""),
- _cs(new geocoords::CSGeoProj),
- _queryVals(0),
- _querySize(0),
- _numX(0),
- _numY(0),
- _numZ(0),
- _numValues(0),
- _names(0),
- _units(0),
- _queryType(NEAREST)
-{ // constructor
-} // constructor
-
-// ----------------------------------------------------------------------
-// Destructor
-spatialdata::spatialdb::GeoProjGridDB::~GeoProjGridDB(void)
-{ // destructor
- delete[] _data; _data = 0;
- delete[] _x; _x = 0;
- delete[] _y; _y = 0;
- delete[] _z; _z = 0;
- _numX = 0;
- _numY = 0;
- _numZ = 0;
- _numValues = 0;
- delete[] _names; _names = 0;
- delete[] _units; _units = 0;
- delete[] _queryVals; _queryVals = 0;
- _querySize = 0;
-} // 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
- 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
-
-// ----------------------------------------------------------------------
-// Close the database.
-void
-spatialdata::spatialdb::GeoProjGridDB::close(void)
-{ // close
- delete[] _data; _data = 0;
- delete[] _x; _x = 0;
- delete[] _y; _y = 0;
- delete[] _z; _z = 0;
- _numX = 0;
- _numY = 0;
- _numZ = 0;
-
- _numValues = 0;
- delete[] _names; _names = 0;
- delete[] _units; _units = 0;
-} // close
-
-// ----------------------------------------------------------------------
-// Set query type.
-void
-spatialdata::spatialdb::GeoProjGridDB::queryType(const QueryEnum value)
-{ // queryType
- _queryType = value;
-} // queryType
-
-// ----------------------------------------------------------------------
-// Set values to be returned by queries.
-void
-spatialdata::spatialdb::GeoProjGridDB::queryVals(const char* const* names,
- const int numVals)
-{ // queryVals
- assert(_data);
- if (0 == numVals) {
- std::ostringstream msg;
- msg
- << "Number of values for query in spatial database " << label()
- << "\n must be positive.\n";
- throw std::runtime_error(msg.str());
- } // if
- assert(names && 0 < numVals);
-
- _querySize = numVals;
- delete[] _queryVals; _queryVals = new int[numVals];
- for (int iVal=0; iVal < numVals; ++iVal) {
- int iName = 0;
- const int numNames = _numValues;
- while (iName < numNames) {
- if (0 == strcasecmp(names[iVal], _names[iName].c_str()))
- break;
- ++iName;
- } // while
- if (iName >= numNames) {
- std::ostringstream msg;
- msg
- << "Could not find value " << names[iVal] << " in spatial database "
- << label() << ". Available values are:";
- for (int iName=0; iName < numNames; ++iName)
- msg << "\n " << _names[iName];
- msg << "\n";
- throw std::runtime_error(msg.str());
- } // if
- _queryVals[iVal] = iName;
- } // for
-} // queryVals
-
-// ----------------------------------------------------------------------
-// Query the database.
-int
-spatialdata::spatialdb::GeoProjGridDB::query(double* vals,
- const int numVals,
- const double* coords,
- const int numDims,
- const spatialdata::geocoords::CoordSys* csQuery)
-{ // query
- 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) {
- std::ostringstream msg;
- msg
- << "Number of values to be returned by spatial database "
- << label() << "\n"
- << "(" << querySize << ") does not match size of array provided ("
- << numVals << ").\n";
- throw std::runtime_error(msg.str());
- } else if (3 != numDims) {
- std::ostringstream msg;
- msg
- << "Spatial dimension (" << numDims
- << ") when querying SCEC CVM-H must be 3.";
- throw std::runtime_error(msg.str());
- } // if
-
- // Convert coordinates
- assert(numDims <= 3);
- memcpy(_xyz, coords, numDims*sizeof(double));
- spatialdata::geocoords::Converter::convert(_xyz, 1, numDims, _cs, csQuery);
-
- int queryFlag = 0;
- 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
- break;
- 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
-
-// ----------------------------------------------------------------------
-// Bilinear search for coordinate.
-double
-spatialdata::spatialdb::GeoProjGridDB::_search(const double target,
- const double* vals,
- const int nvals)
-{ // _search
- assert(vals);
- assert(nvals > 0);
-
- double index = -1.0;
-
- if (1 == nvals) {
- return 0.0;
- } // if
-
- int indexL = 0;
- 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]-tolerance);
- assert(vals[indexR] > vals[indexL]);
- 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
-
-#include <iostream>
-// ----------------------------------------------------------------------
-// Interpolate to get values at target location defined by indices in 3-D.
-void
-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;
-
- assert(numX >= 2);
- const int indexX0 = std::min(numX-2, 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(numY >= 2);
- const int indexY0 = std::min(numY-2, 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(numZ >= 2);
- const int indexZ0 = std::min(numZ-2, 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);
-
- const int index000 = _dataIndex(indexX0, indexY0, indexZ0);
- const int index001 = _dataIndex(indexX0, indexY0, indexZ1);
- const int index010 = _dataIndex(indexX0, indexY1, indexZ0);
- const int index011 = _dataIndex(indexX0, indexY1, indexZ1);
- const int index100 = _dataIndex(indexX1, indexY0, indexZ0);
- const int index101 = _dataIndex(indexX1, indexY0, indexZ1);
- const int index110 = _dataIndex(indexX1, indexY1, indexZ0);
- const int index111 = _dataIndex(indexX1, indexY1, indexZ1);
-
- const double wt000 = wtX0 * wtY0 * wtZ0;
- const double wt001 = wtX0 * wtY0 * wtZ1;
- const double wt010 = wtX0 * wtY1 * wtZ0;
- const double wt011 = wtX0 * wtY1 * wtZ1;
- const double wt100 = wtX1 * wtY0 * wtZ0;
- const double wt101 = wtX1 * wtY0 * wtZ1;
- const double wt110 = wtX1 * wtY1 * wtZ0;
- const double wt111 = wtX1 * wtY1 * wtZ1;
-
- const int querySize = _querySize;
- for (int iVal=0; iVal < querySize; ++iVal) {
- const int qVal = _queryVals[iVal];
- vals[iVal] =
- 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];
-#if 0 // DEBUGGING
- std::cout << "val["<<iVal<<"]: " << vals[iVal]
- << ", wt000: " << wt000 << ", data: " << _data[index000+qVal]
- << ", wt001: " << wt001 << ", data: " << _data[index001+qVal]
- << ", wt010: " << wt010 << ", data: " << _data[index010+qVal]
- << ", wt011: " << wt011 << ", data: " << _data[index011+qVal]
- << ", wt100: " << wt100 << ", data: " << _data[index100+qVal]
- << ", wt101: " << wt101 << ", data: " << _data[index101+qVal]
- << ", wt110: " << wt110 << ", data: " << _data[index110+qVal]
- << ", wt111: " << wt111 << ", data: " << _data[index111+qVal]
- << std::endl;
-#endif
- } // for
-
-} // _interpolate3D
-
-
-// End of file
Deleted: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,205 +0,0 @@
-// -*- 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 libsrc/spatialdb/GeoProjGridDB.hh
- *
- * @brief C++ object for performing querying of data on a nonuniform
- * (or uniform) grid in a geographic projected coordinate system.
- */
-
-#if !defined(spatialdata_spatialdb_geoprojgriddb_hh)
-#define spatialdata_spatialdb_geoprojgriddb_hh
-
-#include "SpatialDB.hh" // ISA SpatialDB
-
-#include <string> // HASA std::string
-#include <iosfwd> // USES std::istream
-
-class spatialdata::spatialdb::GeoProjGridDB : SpatialDB
-{ // GeoProjGridDB
- friend class TestGeoProjGridDB; // unit testing
-
- public :
- // PUBLIC ENUM ////////////////////////////////////////////////////////
-
- /** Type of query */
- enum QueryEnum {
- NEAREST=0, ///< Nearest interpolation.
- LINEAR=1, ///< Linear interpolation.
- };
-
-// PUBLIC MEMBERS ///////////////////////////////////////////////////////
-public :
-
- /// Constructor
- GeoProjGridDB(void);
-
- /// Destructor
- ~GeoProjGridDB(void);
-
- /** Set filename containing data.
- *
- * @param dir Directory containing data files.
- */
- void filename(const char* value);
-
- /// Open the database and prepare for querying.
- void open(void);
-
- /// Close the database.
- void close(void);
-
- /** Set query type.
- *
- * @pre Must call Open() before QueryType()
- *
- * @param queryType Set type of query
- */
- void queryType(const QueryEnum queryType);
-
- /** Set values to be returned by queries.
- *
- * @pre Must call open() before queryVals()
- *
- * @param names Names of values to be returned in queries
- * @param numVals Number of values to be returned in queries
- */
- void queryVals(const char* const* names,
- const int numVals);
-
- /** Query the database.
- *
- * @note pVals should be preallocated to accommodate numVals values.
- *
- * @pre Must call open() before query()
- *
- * @param vals Array for computed values (output from query), must be
- * allocated BEFORE calling query().
- * @param numVals Number of values expected (size of pVals array)
- * @param coords Coordinates of point for query
- * @param numDims Number of dimensions for coordinates
- * @param pCSQuery Coordinate system of coordinates
- *
- * @returns 0 on success, 1 on failure (i.e., could not interpolate)
- */
- int query(double* vals,
- const int numVals,
- const double* coords,
- const int numDims,
- const spatialdata::geocoords::CoordSys* pCSQuery);
-
-
-// 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.
- *
- * @param target Coordinates of target.
- * @param vals Array of ordered values to search.
- * @param nvals Number of values.
- */
- double _search(const double target,
- const double* vals,
- const int nvals);
-
- /** Interpolate to get values at target location defined by indices.
- *
- * @param vals Array for computed values (output from query), must be
- * allocated BEFORE calling query().
- * @param numVals Number of values expected (size of pVals array)
- * @param indexX Index along x dimension.
- * @param indexY Index along y dimension.
- * @param indexZ Index along z dimension.
- */
- void _interpolate3D(double* vals,
- const int numVals,
- const double indexX,
- const double indexY,
- const double indexZ) const;
-
- /** Get index into data array.
- *
- * @param indexX Index along x dimension.
- * @param indexY Index along y dimension.
- * @param indexZ Index along z dimension.
- *
- * @returns Index into data array.
- */
- int _dataIndex(const int indexX,
- const int indexY,
- const int indexZ) const;
-
-// 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 _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 _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; ///< Filename of data file
- geocoords::CoordSys* _cs; ///< Coordinate system
-
- QueryEnum _queryType; ///< Query type
-
- static const char* FILEHEADER;
-
-// NOT IMPLEMENTED //////////////////////////////////////////////////////
-private :
-
- GeoProjGridDB(const GeoProjGridDB&); ///< Not implemented
- const GeoProjGridDB& operator=(const GeoProjGridDB&); ///< Not implemented
-
-}; // GeoProjGridDB
-
-#include "GeoProjGridDB.icc" // inline methods
-
-#endif // spatialdata_spatialdb_geoprojgriddb_hh
-
-
-// End of file
Deleted: cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,34 +0,0 @@
-// -*- 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 University of California, Davis
-//
-// See COPYING for license information.
-//
-// ----------------------------------------------------------------------
-//
-
-#if !defined(spatialdata_spatialdb_geoprojgriddb_hh)
-#error "GeoProjGridDB.icc must only be included from GeoProjGridDB.hh"
-#endif
-
-// ----------------------------------------------------------------------
-// Get index into data array.
-inline
-int
-spatialdata::spatialdb::GeoProjGridDB::_dataIndex(const int indexX,
- const int indexY,
- const int indexZ) const
-{ // _dataIndex
- const int locIndex = indexX*_numY*_numZ + indexY*_numZ + indexZ;
- return locIndex*_numValues;
-} // _dataIndex
-
-
-// End of file
Modified: cs/spatialdata/trunk/libsrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/spatialdb/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -34,8 +34,8 @@
SimpleDBQuery.hh \
SimpleDBData.hh \
SimpleDBData.icc \
- GeoProjGridDB.hh \
- GeoProjGridDB.icc \
+ SimpleGridDB.hh \
+ SimpleGridDB.icc \
GravityField.hh \
GravityField.icc \
SCECCVMH.hh \
Copied: cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc (from rev 20435, cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.cc)
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc (rev 0)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,736 @@
+// -*- 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 "SimpleGridDB.hh" // Implementation of class methods
+
+#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()
+#include <strings.h> // USES strcasecmp()
+#include <assert.h> // USES assert()
+
+// ----------------------------------------------------------------------
+const char* spatialdata::spatialdb::SimpleGridDB::FILEHEADER = "#SPATIAL_GRID.ascii";
+
+// ----------------------------------------------------------------------
+// Constructor
+spatialdata::spatialdb::SimpleGridDB::SimpleGridDB(void) :
+ _data(0),
+ _x(0),
+ _y(0),
+ _z(0),
+ _filename(""),
+ _cs(new geocoords::CSGeoProj),
+ _queryVals(0),
+ _querySize(0),
+ _numX(0),
+ _numY(0),
+ _numZ(0),
+ _numValues(0),
+ _names(0),
+ _units(0),
+ _queryType(NEAREST)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+spatialdata::spatialdb::SimpleGridDB::~SimpleGridDB(void)
+{ // destructor
+ delete[] _data; _data = 0;
+ delete[] _x; _x = 0;
+ delete[] _y; _y = 0;
+ delete[] _z; _z = 0;
+ _numX = 0;
+ _numY = 0;
+ _numZ = 0;
+ _numValues = 0;
+ delete[] _names; _names = 0;
+ delete[] _units; _units = 0;
+ delete[] _queryVals; _queryVals = 0;
+ _querySize = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set filename containing data.
+void
+spatialdata::spatialdb::SimpleGridDB::filename(const char* value)
+{ // filename
+ _filename = value;
+} // filename
+
+// ----------------------------------------------------------------------
+// Open the database and prepare for querying.
+void
+spatialdata::spatialdb::SimpleGridDB::open(void)
+{ // open
+ 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
+
+// ----------------------------------------------------------------------
+// Close the database.
+void
+spatialdata::spatialdb::SimpleGridDB::close(void)
+{ // close
+ delete[] _data; _data = 0;
+ delete[] _x; _x = 0;
+ delete[] _y; _y = 0;
+ delete[] _z; _z = 0;
+ _numX = 0;
+ _numY = 0;
+ _numZ = 0;
+
+ _numValues = 0;
+ delete[] _names; _names = 0;
+ delete[] _units; _units = 0;
+} // close
+
+// ----------------------------------------------------------------------
+// Set query type.
+void
+spatialdata::spatialdb::SimpleGridDB::queryType(const QueryEnum value)
+{ // queryType
+ _queryType = value;
+} // queryType
+
+// ----------------------------------------------------------------------
+// Set values to be returned by queries.
+void
+spatialdata::spatialdb::SimpleGridDB::queryVals(const char* const* names,
+ const int numVals)
+{ // queryVals
+ assert(_data);
+ if (0 == numVals) {
+ std::ostringstream msg;
+ msg
+ << "Number of values for query in spatial database " << label()
+ << "\n must be positive.\n";
+ throw std::runtime_error(msg.str());
+ } // if
+ assert(names && 0 < numVals);
+
+ _querySize = numVals;
+ delete[] _queryVals; _queryVals = new int[numVals];
+ for (int iVal=0; iVal < numVals; ++iVal) {
+ int iName = 0;
+ const int numNames = _numValues;
+ while (iName < numNames) {
+ if (0 == strcasecmp(names[iVal], _names[iName].c_str()))
+ break;
+ ++iName;
+ } // while
+ if (iName >= numNames) {
+ std::ostringstream msg;
+ msg
+ << "Could not find value " << names[iVal] << " in spatial database "
+ << label() << ". Available values are:";
+ for (int iName=0; iName < numNames; ++iName)
+ msg << "\n " << _names[iName];
+ msg << "\n";
+ throw std::runtime_error(msg.str());
+ } // if
+ _queryVals[iVal] = iName;
+ } // for
+} // queryVals
+
+// ----------------------------------------------------------------------
+// Query the database.
+int
+spatialdata::spatialdb::SimpleGridDB::query(double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* csQuery)
+{ // query
+ 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) {
+ std::ostringstream msg;
+ msg
+ << "Number of values to be returned by spatial database "
+ << label() << "\n"
+ << "(" << querySize << ") does not match size of array provided ("
+ << numVals << ").\n";
+ throw std::runtime_error(msg.str());
+ } else if (3 != numDims) {
+ std::ostringstream msg;
+ msg
+ << "Spatial dimension (" << numDims
+ << ") when querying SCEC CVM-H must be 3.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ // Convert coordinates
+ assert(numDims <= 3);
+ memcpy(_xyz, coords, numDims*sizeof(double));
+ spatialdata::geocoords::Converter::convert(_xyz, 1, numDims, _cs, csQuery);
+
+ int queryFlag = 0;
+ 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("SimpleGridDB::query(): 1 == _dataDim not implemented.");
+ break;
+ } // case 1
+ case 2: {
+ assert(false);
+ throw std::logic_error("SimpleGridDB::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 SimpleGridDB::query().");
+ } // switch
+ break;
+ 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 SimpleGridDB::query().");
+ } // switch
+
+ return queryFlag;
+} // query
+
+// ----------------------------------------------------------------------
+// Read data file header.
+void
+spatialdata::spatialdb::SimpleGridDB::_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(), "SimpleGridDB")) {
+ std::ostringstream msg;
+ msg << "Could not parse '" << token << "' into 'SimpleGridDB'.\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 SimpleGridDB 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 SimpleGridDB 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 SimpleGridDB 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 SimpleGridDB settings.");
+
+ bool ok = true;
+ std::ostringstream msg;
+ if (_numValues <= 0) {
+ ok = false;
+ msg << "SimpleGridDB settings must include 'num-values'.\n";
+ } // if
+ if (_spaceDim <= 0) {
+ ok = false;
+ msg << "SimpleGridDB settings must include positive 'space-dim'.\n";
+ } // if
+
+ if (_spaceDim > 0 && _numX <= 0) {
+ ok = false;
+ msg << "SimpleGridDB settings must include 'num-x'.\n";
+ } // if
+ if (_spaceDim > 1 && _numY <= 0) {
+ ok = false;
+ msg << "SimpleGridDB settings must include 'num-y' with 2-D and 3-D data.\n";
+ } // if
+ if (_spaceDim > 2 && _numZ <= 0) {
+ ok = false;
+ msg << "SimpleGridDB settings must include 'num-z' with 3-D data.\n";
+ } // if
+ if (!_names) {
+ ok = false;
+ msg << "SimpleGridDB settings must include 'value-names'.\n";
+ } // if
+ if (!_units) {
+ ok = false;
+ msg << "SimpleGridDB 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::SimpleGridDB::_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 SimpleGridDB 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::SimpleGridDB::_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
+
+// ----------------------------------------------------------------------
+// Bilinear search for coordinate.
+double
+spatialdata::spatialdb::SimpleGridDB::_search(const double target,
+ const double* vals,
+ const int nvals)
+{ // _search
+ assert(vals);
+ assert(nvals > 0);
+
+ double index = -1.0;
+
+ if (1 == nvals) {
+ return 0.0;
+ } // if
+
+ int indexL = 0;
+ 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]-tolerance);
+ assert(vals[indexR] > vals[indexL]);
+ 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
+
+#include <iostream>
+// ----------------------------------------------------------------------
+// Interpolate to get values at target location defined by indices in 3-D.
+void
+spatialdata::spatialdb::SimpleGridDB::_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;
+
+ assert(numX >= 2);
+ const int indexX0 = std::min(numX-2, 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(numY >= 2);
+ const int indexY0 = std::min(numY-2, 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(numZ >= 2);
+ const int indexZ0 = std::min(numZ-2, 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);
+
+ const int index000 = _dataIndex(indexX0, indexY0, indexZ0);
+ const int index001 = _dataIndex(indexX0, indexY0, indexZ1);
+ const int index010 = _dataIndex(indexX0, indexY1, indexZ0);
+ const int index011 = _dataIndex(indexX0, indexY1, indexZ1);
+ const int index100 = _dataIndex(indexX1, indexY0, indexZ0);
+ const int index101 = _dataIndex(indexX1, indexY0, indexZ1);
+ const int index110 = _dataIndex(indexX1, indexY1, indexZ0);
+ const int index111 = _dataIndex(indexX1, indexY1, indexZ1);
+
+ const double wt000 = wtX0 * wtY0 * wtZ0;
+ const double wt001 = wtX0 * wtY0 * wtZ1;
+ const double wt010 = wtX0 * wtY1 * wtZ0;
+ const double wt011 = wtX0 * wtY1 * wtZ1;
+ const double wt100 = wtX1 * wtY0 * wtZ0;
+ const double wt101 = wtX1 * wtY0 * wtZ1;
+ const double wt110 = wtX1 * wtY1 * wtZ0;
+ const double wt111 = wtX1 * wtY1 * wtZ1;
+
+ const int querySize = _querySize;
+ for (int iVal=0; iVal < querySize; ++iVal) {
+ const int qVal = _queryVals[iVal];
+ vals[iVal] =
+ 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];
+#if 0 // DEBUGGING
+ std::cout << "val["<<iVal<<"]: " << vals[iVal]
+ << ", wt000: " << wt000 << ", data: " << _data[index000+qVal]
+ << ", wt001: " << wt001 << ", data: " << _data[index001+qVal]
+ << ", wt010: " << wt010 << ", data: " << _data[index010+qVal]
+ << ", wt011: " << wt011 << ", data: " << _data[index011+qVal]
+ << ", wt100: " << wt100 << ", data: " << _data[index100+qVal]
+ << ", wt101: " << wt101 << ", data: " << _data[index101+qVal]
+ << ", wt110: " << wt110 << ", data: " << _data[index110+qVal]
+ << ", wt111: " << wt111 << ", data: " << _data[index111+qVal]
+ << std::endl;
+#endif
+ } // for
+
+} // _interpolate3D
+
+
+// End of file
Copied: cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.hh (from rev 20433, cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.hh)
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.hh (rev 0)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,205 @@
+// -*- 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 libsrc/spatialdb/SimpleGridDB.hh
+ *
+ * @brief C++ object for performing querying of data on a nonuniform
+ * (or uniform) grid in a geographic projected coordinate system.
+ */
+
+#if !defined(spatialdata_spatialdb_simplegriddb_hh)
+#define spatialdata_spatialdb_simplegriddb_hh
+
+#include "SpatialDB.hh" // ISA SpatialDB
+
+#include <string> // HASA std::string
+#include <iosfwd> // USES std::istream
+
+class spatialdata::spatialdb::SimpleGridDB : SpatialDB
+{ // SimpleGridDB
+ friend class TestSimpleGridDB; // unit testing
+
+ public :
+ // PUBLIC ENUM ////////////////////////////////////////////////////////
+
+ /** Type of query */
+ enum QueryEnum {
+ NEAREST=0, ///< Nearest interpolation.
+ LINEAR=1, ///< Linear interpolation.
+ };
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ SimpleGridDB(void);
+
+ /// Destructor
+ ~SimpleGridDB(void);
+
+ /** Set filename containing data.
+ *
+ * @param dir Directory containing data files.
+ */
+ void filename(const char* value);
+
+ /// Open the database and prepare for querying.
+ void open(void);
+
+ /// Close the database.
+ void close(void);
+
+ /** Set query type.
+ *
+ * @pre Must call Open() before QueryType()
+ *
+ * @param queryType Set type of query
+ */
+ void queryType(const QueryEnum queryType);
+
+ /** Set values to be returned by queries.
+ *
+ * @pre Must call open() before queryVals()
+ *
+ * @param names Names of values to be returned in queries
+ * @param numVals Number of values to be returned in queries
+ */
+ void queryVals(const char* const* names,
+ const int numVals);
+
+ /** Query the database.
+ *
+ * @note pVals should be preallocated to accommodate numVals values.
+ *
+ * @pre Must call open() before query()
+ *
+ * @param vals Array for computed values (output from query), must be
+ * allocated BEFORE calling query().
+ * @param numVals Number of values expected (size of pVals array)
+ * @param coords Coordinates of point for query
+ * @param numDims Number of dimensions for coordinates
+ * @param pCSQuery Coordinate system of coordinates
+ *
+ * @returns 0 on success, 1 on failure (i.e., could not interpolate)
+ */
+ int query(double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* pCSQuery);
+
+
+// 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.
+ *
+ * @param target Coordinates of target.
+ * @param vals Array of ordered values to search.
+ * @param nvals Number of values.
+ */
+ double _search(const double target,
+ const double* vals,
+ const int nvals);
+
+ /** Interpolate to get values at target location defined by indices.
+ *
+ * @param vals Array for computed values (output from query), must be
+ * allocated BEFORE calling query().
+ * @param numVals Number of values expected (size of pVals array)
+ * @param indexX Index along x dimension.
+ * @param indexY Index along y dimension.
+ * @param indexZ Index along z dimension.
+ */
+ void _interpolate3D(double* vals,
+ const int numVals,
+ const double indexX,
+ const double indexY,
+ const double indexZ) const;
+
+ /** Get index into data array.
+ *
+ * @param indexX Index along x dimension.
+ * @param indexY Index along y dimension.
+ * @param indexZ Index along z dimension.
+ *
+ * @returns Index into data array.
+ */
+ int _dataIndex(const int indexX,
+ const int indexY,
+ const int indexZ) const;
+
+// 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 _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 _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; ///< Filename of data file
+ geocoords::CoordSys* _cs; ///< Coordinate system
+
+ QueryEnum _queryType; ///< Query type
+
+ static const char* FILEHEADER;
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+ SimpleGridDB(const SimpleGridDB&); ///< Not implemented
+ const SimpleGridDB& operator=(const SimpleGridDB&); ///< Not implemented
+
+}; // SimpleGridDB
+
+#include "SimpleGridDB.icc" // inline methods
+
+#endif // spatialdata_spatialdb_simplegriddb_hh
+
+
+// End of file
Copied: cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.icc (from rev 20433, cs/spatialdata/trunk/libsrc/spatialdb/GeoProjGridDB.icc)
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.icc (rev 0)
+++ cs/spatialdata/trunk/libsrc/spatialdb/SimpleGridDB.icc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,34 @@
+// -*- 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 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_simplegriddb_hh)
+#error "SimpleGridDB.icc must only be included from SimpleGridDB.hh"
+#endif
+
+// ----------------------------------------------------------------------
+// Get index into data array.
+inline
+int
+spatialdata::spatialdb::SimpleGridDB::_dataIndex(const int indexX,
+ const int indexY,
+ const int indexZ) const
+{ // _dataIndex
+ const int locIndex = indexX*_numY*_numZ + indexY*_numZ + indexZ;
+ return locIndex*_numValues;
+} // _dataIndex
+
+
+// End of file
Modified: cs/spatialdata/trunk/libsrc/spatialdb/spatialdbfwd.hh
===================================================================
--- cs/spatialdata/trunk/libsrc/spatialdb/spatialdbfwd.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/libsrc/spatialdb/spatialdbfwd.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -36,7 +36,7 @@
class SimpleIO;
class SimpleIOAscii;
class UniformDB;
- class GeoProjGridDB;
+ class SimpleGridDB;
class CompositeDB;
class SCECCVMH;
class GocadVoxet;
Modified: cs/spatialdata/trunk/modulesrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata/trunk/modulesrc/spatialdb/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/modulesrc/spatialdb/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -29,6 +29,7 @@
SimpleIO.i \
SimpleIOAscii.i \
UniformDB.i \
+ SimpleGridDB.i \
CompositeDB.i \
SCECCVMH.i \
GravityField.i \
Added: cs/spatialdata/trunk/modulesrc/spatialdb/SimpleGridDB.i
===================================================================
--- cs/spatialdata/trunk/modulesrc/spatialdb/SimpleGridDB.i (rev 0)
+++ cs/spatialdata/trunk/modulesrc/spatialdb/SimpleGridDB.i 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,118 @@
+// -*- 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 modulesrc/spatialdb/SimpleGridDB.i
+ *
+ * @brief SWIG interface to C++ SimpleGridDB object.
+ */
+
+namespace spatialdata {
+ namespace spatialdb {
+ class SimpleIO; // USES SimpleIO
+
+ class SimpleGridDB : public SpatialDB
+ { // class SimpleGridDB
+
+ public :
+ // PUBLIC ENUM ////////////////////////////////////////////////////
+
+ /** Type of query */
+ enum QueryEnum {
+ NEAREST=0,
+ LINEAR=1
+ };
+
+ public :
+ // PUBLIC METHODS /////////////////////////////////////////////////
+
+ /// Default constructor.
+ SimpleGridDB(void);
+
+ /// Default destructor.
+ ~SimpleGridDB(void);
+
+ /** Set filename containing data.
+ *
+ * @param dir Directory containing data files.
+ */
+ void filename(const char* value);
+
+ /// Open the database and prepare for querying.
+ void open(void);
+
+ /// Close the database.
+ void close(void);
+
+ /** Set query type.
+ *
+ * @pre Must call Open() before QueryType()
+ *
+ * @param queryType Set type of query
+ */
+ void queryType(const SimpleGridDB::QueryEnum queryType);
+
+ /** Set values to be returned by queries.
+ *
+ * @pre Must call open() before queryVals()
+ *
+ * @param names Names of values to be returned in queries
+ * @param numVals Number of values to be returned in queries
+ */
+ %apply(const char* const* string_list, const int list_len){
+ (const char* const* names,
+ const int numVals)
+ };
+ void queryVals(const char* const* names,
+ const int numVals);
+ %clear(const char* const* names, const int numVals);
+
+ /** Query the database.
+ *
+ * @pre Must call open() before query()
+ *
+ * @param vals Array for computed values (output from query), vals
+ * must be allocated BEFORE calling query().
+ * @param numVals Number of values expected (size of pVals array)
+ * @param coords Coordinates of point for query
+ * @param numDims Number of dimensions for coordinates
+ * @param pCSQuery Coordinate system of coordinates
+ *
+ * @returns 0 on success, 1 on failure (i.e., could not interpolate
+ * so values set to 0)
+ */
+ %apply(double* INPLACE_ARRAY1, int DIM1) {
+ (double* vals,
+ const int numVals)
+ };
+ %apply(double* IN_ARRAY1, int DIM1) {
+ (const double* coords,
+ const int numDims)
+ };
+ int query(double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* pCSQuery);
+ %clear(double* vals, const int numVals);
+ %clear(const double* coords, const int numDims);
+
+ }; // class SimpleGridDB
+
+ } // spatialdb
+} // spatialdata
+
+
+// End of file
Modified: cs/spatialdata/trunk/modulesrc/spatialdb/spatialdb.i
===================================================================
--- cs/spatialdata/trunk/modulesrc/spatialdb/spatialdb.i 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/modulesrc/spatialdb/spatialdb.i 2012-06-29 04:49:18 UTC (rev 20436)
@@ -30,6 +30,7 @@
#include "spatialdata/spatialdb/SimpleIO.hh"
#include "spatialdata/spatialdb/SimpleIOAscii.hh"
#include "spatialdata/spatialdb/UniformDB.hh"
+#include "spatialdata/spatialdb/SimpleGridDB.hh"
#include "spatialdata/spatialdb/CompositeDB.hh"
#include "spatialdata/spatialdb/SCECCVMH.hh"
#include "spatialdata/spatialdb/GravityField.hh"
@@ -67,6 +68,7 @@
%include "SimpleIO.i"
%include "SimpleIOAscii.i"
%include "UniformDB.i"
+%include "SimpleGridDB.i"
%include "CompositeDB.i"
%include "SCECCVMH.i"
%include "GravityField.i"
Modified: cs/spatialdata/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata/trunk/spatialdata/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/spatialdata/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -34,6 +34,7 @@
spatialdb/TimeHistory.py \
spatialdb/TimeHistoryIO.py \
spatialdb/UniformDB.py \
+ spatialdb/SimpleGridDB.py \
spatialdb/__init__.py \
spatialdb/generator/Shaper.py \
spatialdb/generator/Shapers.py \
Added: cs/spatialdata/trunk/spatialdata/spatialdb/SimpleGridDB.py
===================================================================
--- cs/spatialdata/trunk/spatialdata/spatialdb/SimpleGridDB.py (rev 0)
+++ cs/spatialdata/trunk/spatialdata/spatialdb/SimpleGridDB.py 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# 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 spatialdata/spatialdb/SimpleGridDB.py
+##
+## @brief Python manager for simple spatial database.
+##
+## Factory: spatial_database
+
+from SpatialDBObj import SpatialDBObj
+from spatialdb import SimpleGridDB as ModuleSimpleGridDB
+
+# Validator for filename
+def validateFilename(value):
+ """
+ Validate filename.
+ """
+ if 0 == len(value):
+ raise ValueError("Name of SimpleGridDB file must be specified.")
+ return value
+
+
+# SimpleGridDB class
+class SimpleGridDB(SpatialDBObj, ModuleSimpleGridDB):
+ """
+ Python manager for simple spatial database.
+
+ Factory: spatial_database
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(SpatialDBObj.Inventory):
+ """
+ Python object for managing SimpleGridDB facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing SimpleGridDB facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Name for data file.
+ ## @li \b query_type Type of query to perform
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="", validator=validateFilename)
+ filename.meta['tip'] = "Name for data file."
+
+ queryType = pyre.inventory.str("query_type", default="nearest")
+ queryType.validator = pyre.inventory.choice(["nearest", "linear"])
+ queryType.meta['tip'] = "Type of query to perform."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="simplegriddb"):
+ """
+ Constructor.
+ """
+ SpatialDBObj.__init__(self, name)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based on inventory.
+ """
+ SpatialDBObj._configure(self)
+ ModuleSimpleGridDB.filename(self, self.inventory.filename)
+ ModuleSimpleGridDB.queryType(self, self._parseQueryString(self.inventory.queryType))
+ return
+
+
+ def _createModuleObj(self):
+ """
+ Create Python module object.
+ """
+ ModuleSimpleGridDB.__init__(self)
+ return
+
+
+ def _parseQueryString(self, label):
+ if label.lower() == "nearest":
+ value = ModuleSimpleGridDB.NEAREST
+ elif label.lower() == "linear":
+ value = ModuleSimpleGridDB.LINEAR
+ else:
+ raise ValueError("Unknown value for query type '%s'." % label)
+ return value
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+ """
+ Factory associated with SimpleGridDB.
+ """
+ return SimpleGridDB()
+
+
+# End of file
Modified: cs/spatialdata/trunk/spatialdata/spatialdb/SpatialDBObj.py
===================================================================
--- cs/spatialdata/trunk/spatialdata/spatialdb/SpatialDBObj.py 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/spatialdata/spatialdb/SpatialDBObj.py 2012-06-29 04:49:18 UTC (rev 20436)
@@ -26,7 +26,7 @@
# Validator for label
def validateLabel(value):
"""
- Validate label for group/nodeset/pset.
+ Validate label for spatial database.
"""
if 0 == len(value):
raise ValueError("Descriptive label for spatial database not specified.")
Modified: cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -40,8 +40,8 @@
TestTimeHistory.cc \
TestTimeHistoryIO.cc \
TestUniformDB.cc \
- TestGeoProjGridDB.cc \
- TestGeoProjGridDBCases.cc \
+ TestSimpleGridDB.cc \
+ TestSimpleGridDBCases.cc \
testcquery.c \
testspatial.cc
@@ -61,8 +61,8 @@
TestTimeHistory.hh \
TestTimeHistoryIO.hh \
TestUniformDB.hh \
- TestGeoProjGridDB.hh \
- TestGeoProjGridDBCases.hh \
+ TestSimpleGridDB.hh \
+ TestSimpleGridDBCases.hh \
testcquery.h \
TestSpatialDB.hh
@@ -87,8 +87,8 @@
data/SimpleDBTestDataLine3D.cc \
data/SimpleDBTestDataArea3D.cc \
data/SimpleDBTestDataVolume3D.cc \
- data/GeoProjGridDBTestData.cc \
- data/GeoProjGridDBTestDataVolume3D.cc
+ data/SimpleGridDBTestData.cc \
+ data/SimpleGridDBTestDataVolume3D.cc
noinst_HEADERS += \
data/SimpleDBQueryData.hh \
@@ -98,8 +98,8 @@
data/SimpleDBTestDataLine3D.hh \
data/SimpleDBTestDataArea3D.hh \
data/SimpleDBTestDataVolume3D.hh \
- data/GeoProjGridDBTestData.hh \
- data/GeoProjGridDBTestDataVolume3D.hh
+ data/SimpleGridDBTestData.hh \
+ data/SimpleGridDBTestDataVolume3D.hh
# End of file
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,310 +0,0 @@
-// -*- 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
- CPPUNIT_ASSERT(db);
- CPPUNIT_ASSERT(data.numVals > 0);
-
- delete[] db->_x; db->_x = 0;
- delete[] db->_y; db->_y = 0;
- delete[] db->_z; db->_z = 0;
- delete[] db->_data; db->_data = 0;
- delete[] db->_names; db->_names = 0;
- delete[] db->_units; db->_units = 0;
-
- db->label("GeoProjGrid test database");
- db->_numValues = data.numVals;
- db->_spaceDim = data.spaceDim;
- db->_dataDim = data.dataDim;
- db->_numX = data.numX;
- db->_numY = data.numY;
- db->_numZ = data.numZ;
-
- int numLocs = 1;
- if (data.numX > 1) {
- numLocs *= data.numX;
- db->_x = new double[data.numX];
- for (int i=0; i < data.numX; ++i) {
- db->_x[i] = data.dbX[i];
- } // for
- } // if
- if (data.numY > 1) {
- numLocs *= data.numY;
- db->_y = new double[data.numY];
- for (int i=0; i < data.numY; ++i) {
- db->_y[i] = data.dbY[i];
- } // for
- } // if
- if (data.numZ > 1) {
- numLocs *= data.numZ;
- db->_z = new double[data.numZ];
- for (int i=0; i < data.numZ; ++i) {
- db->_z[i] = data.dbZ[i];
- } // for
- } // if
-
- db->_data = (numLocs > 0) ? new double[numLocs*data.numVals] : 0;
- for (int i=0; i < numLocs*data.numVals; ++i) {
- db->_data[i] = data.dbData[i];
- } // for
-
- db->_names = (data.numVals > 0) ? new std::string[data.numVals] : 0;
- for (int i=0; i < data.numVals; ++i) {
- db->_names[i] = data.names[i];
- } // for
-
- db->_units = (data.numVals > 0) ? new std::string[data.numVals] : 0;
- for (int i=0; i < data.numVals; ++i) {
- db->_units[i] = data.units[i];
- } // for
-
- db->_cs = new spatialdata::geocoords::CSCart();
- db->_cs->setSpaceDim(data.spaceDim);
-} // _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;
- csCart.setSpaceDim(spaceDim);
- 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);
- } // if/else
- } // for
- } // if/else
- } // for
- delete[] vals; vals = 0;
-} // _checkQuery
-
-
-// End of file
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,126 +0,0 @@
-// -*- 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
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.cc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,47 +0,0 @@
-// -*- 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 "TestGeoProjGridDBCases.hh" // Implementation of class methods
-
-#include "data/GeoProjGridDBTestDataVolume3D.hh"
-
-// ----------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestGeoProjGridDBVolume3D );
-
-// ----------------------------------------------------------------------
-// Test queryLinear()
-void
-spatialdata::spatialdb::TestGeoProjGridDBVolume3D::testQueryLinear(void)
-{ // testQueryLinear
- GeoProjGridDBTestDataVolume3D data;
-
- _testQueryLinear(data);
-} // testQueryLinear
-
-// ----------------------------------------------------------------------
-// Test queryNearest()
-void
-spatialdata::spatialdb::TestGeoProjGridDBVolume3D::testQueryNearest(void)
-{ // testQueryNearest
- GeoProjGridDBTestDataVolume3D data;
-
- _testQueryNearest(data);
-} // testQueryNearest
-
-
-// End of file
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,62 +0,0 @@
-// -*- 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/TestGeoProjGridDBCases.hh
- *
- * @brief C++ TestGeoProjGridDBVolume3D object
- *
- * C++ unit testing for GeoProjGridDB.
- */
-
-#if !defined(spatialdata_spatialdb_testgeoprojgriddbcases_hh)
-#define spatialdata_spatialdb_testgeoprojgriddbcases_hh
-
-#include "TestGeoProjGridDB.hh" // ISA TestGeoProjGridDB
-
-/// Namespace for spatial package
-namespace spatialdata {
- namespace spatialdb {
- class TestGeoProjGridDBVolume3D;
- } // spatialdb
-} // spatialdata
-
-/// C++ unit testing for GeoProjGridDB with volume data.
-class spatialdata::spatialdb::TestGeoProjGridDBVolume3D : public TestGeoProjGridDB
-{ // class TestGeoProjGridDBVolume3D
-
- // CPPUNIT TEST SUITE /////////////////////////////////////////////////
- CPPUNIT_TEST_SUITE( TestGeoProjGridDBVolume3D );
-
- CPPUNIT_TEST( testQueryNearest );
- CPPUNIT_TEST( testQueryLinear );
-
- CPPUNIT_TEST_SUITE_END();
-
- // PUBLIC METHODS /////////////////////////////////////////////////////
-public :
-
- /// Test queryNearest()
- void testQueryNearest(void);
-
- /// Test queryLinear()
- void testQueryLinear(void);
-
-}; // class TestGeoProjGridDBVolume3D
-
-#endif // spatialdata_spatialdb_testgeoprojgriddbvolume3d_hh
-
-
-// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.cc (from rev 20435, cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.cc)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.cc (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,310 @@
+// -*- 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 "TestSimpleGridDB.hh" // Implementation of class methods
+
+#include "spatialdata/spatialdb/SimpleGridDB.hh" // USES SimpleGridDB
+
+#include "data/SimpleGridDBTestData.hh" // USES SimpleGridDBTestData
+
+#include "spatialdata/geocoords/CSCart.hh" // USE CSCart
+
+#include <string.h> // USES strcmp() and memcpy()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestSimpleGridDB );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+spatialdata::spatialdb::TestSimpleGridDB::testConstructor(void)
+{ // testConstructor
+ SimpleGridDB db;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test label()
+void
+spatialdata::spatialdb::TestSimpleGridDB::testLabel(void)
+{ // testLabel
+ SimpleGridDB db;
+ const char* label = "database 2";
+ db.label(label);
+ CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testLabel
+
+// ----------------------------------------------------------------------
+// Test filename()
+void
+spatialdata::spatialdb::TestSimpleGridDB::testFilename(void)
+{ // testFilename
+ SimpleGridDB db;
+ const std::string& filename = "mydb.spatialdb";
+ db.filename(filename.c_str());
+ CPPUNIT_ASSERT_EQUAL(filename, db._filename);
+} // testFilename
+
+// ----------------------------------------------------------------------
+// Test queryType()
+void
+spatialdata::spatialdb::TestSimpleGridDB::testQueryType(void)
+{ // testQueryType
+ SimpleGridDB db;
+
+ // Test default (nearest)
+ CPPUNIT_ASSERT_EQUAL(SimpleGridDB::NEAREST, db._queryType);
+
+ db.queryType(SimpleGridDB::LINEAR);
+ CPPUNIT_ASSERT_EQUAL(SimpleGridDB::LINEAR, db._queryType);
+
+ db.queryType(SimpleGridDB::NEAREST);
+ CPPUNIT_ASSERT_EQUAL(SimpleGridDB::NEAREST, db._queryType);
+} // testQueryType
+
+// ----------------------------------------------------------------------
+// Test _search()
+void
+spatialdata::spatialdb::TestSimpleGridDB::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;
+
+ SimpleGridDB db;
+
+ db.queryType(SimpleGridDB::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(SimpleGridDB::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::TestSimpleGridDB::testDataIndex(void)
+{ // testDataIndex
+ SimpleGridDB 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::TestSimpleGridDB::_testQueryNearest(const SimpleGridDBTestData& data)
+{ // _testQueryNearest
+ SimpleGridDB db;
+ _setupDB(&db, data);
+ db.queryType(SimpleGridDB::NEAREST);
+ _checkQuery(db, data.names, data.queryNearest, 0,
+ data.numQueries, data.spaceDim, data.numVals);
+} // _testQueryNearest
+
+// ----------------------------------------------------------------------
+// Test query() using linear interpolation
+void
+spatialdata::spatialdb::TestSimpleGridDB::_testQueryLinear(const SimpleGridDBTestData& data)
+{ // _testQueryLinear
+ SimpleGridDB db;
+ _setupDB(&db, data);
+ db.queryType(SimpleGridDB::LINEAR);
+ _checkQuery(db, data.names, data.queryLinear, data.errFlags,
+ data.numQueries, data.spaceDim, data.numVals);
+} // _testQueryLinear
+
+// ----------------------------------------------------------------------
+// Populate database with data.
+void
+spatialdata::spatialdb::TestSimpleGridDB::_setupDB(SimpleGridDB* const db,
+ const SimpleGridDBTestData& data)
+{ // _setupDB
+ CPPUNIT_ASSERT(db);
+ CPPUNIT_ASSERT(data.numVals > 0);
+
+ delete[] db->_x; db->_x = 0;
+ delete[] db->_y; db->_y = 0;
+ delete[] db->_z; db->_z = 0;
+ delete[] db->_data; db->_data = 0;
+ delete[] db->_names; db->_names = 0;
+ delete[] db->_units; db->_units = 0;
+
+ db->label("GeoProjGrid test database");
+ db->_numValues = data.numVals;
+ db->_spaceDim = data.spaceDim;
+ db->_dataDim = data.dataDim;
+ db->_numX = data.numX;
+ db->_numY = data.numY;
+ db->_numZ = data.numZ;
+
+ int numLocs = 1;
+ if (data.numX > 1) {
+ numLocs *= data.numX;
+ db->_x = new double[data.numX];
+ for (int i=0; i < data.numX; ++i) {
+ db->_x[i] = data.dbX[i];
+ } // for
+ } // if
+ if (data.numY > 1) {
+ numLocs *= data.numY;
+ db->_y = new double[data.numY];
+ for (int i=0; i < data.numY; ++i) {
+ db->_y[i] = data.dbY[i];
+ } // for
+ } // if
+ if (data.numZ > 1) {
+ numLocs *= data.numZ;
+ db->_z = new double[data.numZ];
+ for (int i=0; i < data.numZ; ++i) {
+ db->_z[i] = data.dbZ[i];
+ } // for
+ } // if
+
+ db->_data = (numLocs > 0) ? new double[numLocs*data.numVals] : 0;
+ for (int i=0; i < numLocs*data.numVals; ++i) {
+ db->_data[i] = data.dbData[i];
+ } // for
+
+ db->_names = (data.numVals > 0) ? new std::string[data.numVals] : 0;
+ for (int i=0; i < data.numVals; ++i) {
+ db->_names[i] = data.names[i];
+ } // for
+
+ db->_units = (data.numVals > 0) ? new std::string[data.numVals] : 0;
+ for (int i=0; i < data.numVals; ++i) {
+ db->_units[i] = data.units[i];
+ } // for
+
+ db->_cs = new spatialdata::geocoords::CSCart();
+ db->_cs->setSpaceDim(data.spaceDim);
+} // _setupDB
+
+// ----------------------------------------------------------------------
+// Test query method by doing query and checking values returned.
+void
+spatialdata::spatialdb::TestSimpleGridDB::_checkQuery(SimpleGridDB& 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;
+ csCart.setSpaceDim(spaceDim);
+ 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);
+ } // if/else
+ } // for
+ } // if/else
+ } // for
+ delete[] vals; vals = 0;
+} // _checkQuery
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.hh (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDB.hh)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.hh (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDB.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -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/TestSimpleGridDB.hh
+ *
+ * @brief C++ TestSimpleGridDB object
+ *
+ * C++ unit testing for SimpleGridDB. This object is an abstract base
+ * class with children classes specific to the type of data in the database.
+ */
+
+#if !defined(spatialdata_spatialdb_testsimplegriddb_hh)
+#define spatialdata_spatialdb_testsimplegriddb_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "spatialdata/spatialdb/spatialdbfwd.hh"
+
+/// Namespace for spatial package
+namespace spatialdata {
+ namespace spatialdb {
+ class TestSimpleGridDB;
+ class SimpleGridDBTestData; // USES SimpleGridDBTestData
+ } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for SimpleGridDB
+class spatialdata::spatialdb::TestSimpleGridDB : public CppUnit::TestFixture
+{ // class TestSimpleGridDB
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestSimpleGridDB );
+
+ 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 SimpleGridDBTestData& data);
+
+ /** Test query() using linear interpolation
+ *
+ * @param data Data for database
+ */
+ void _testQueryLinear(const SimpleGridDBTestData& data);
+
+ // PRIVATE METHODS ////////////////////////////////////////////////////
+private :
+
+ /** Populate database with data.
+ *
+ * @param db Database
+ * @param data Data for database
+ */
+ void _setupDB(SimpleGridDB* const db,
+ const SimpleGridDBTestData& 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(SimpleGridDB& db,
+ char** const names,
+ const double* queryData,
+ const int* flagsE,
+ const int numQueries,
+ const int spaceDim,
+ const int numVals);
+
+}; // class TestSimpleGridDB
+
+#endif // spatialdata_spatialdb_testsimplegriddb_hh
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.cc (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.cc)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.cc (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -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 "TestSimpleGridDBCases.hh" // Implementation of class methods
+
+#include "data/SimpleGridDBTestDataVolume3D.hh"
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestSimpleGridDBVolume3D );
+
+// ----------------------------------------------------------------------
+// Test queryLinear()
+void
+spatialdata::spatialdb::TestSimpleGridDBVolume3D::testQueryLinear(void)
+{ // testQueryLinear
+ SimpleGridDBTestDataVolume3D data;
+
+ _testQueryLinear(data);
+} // testQueryLinear
+
+// ----------------------------------------------------------------------
+// Test queryNearest()
+void
+spatialdata::spatialdb::TestSimpleGridDBVolume3D::testQueryNearest(void)
+{ // testQueryNearest
+ SimpleGridDBTestDataVolume3D data;
+
+ _testQueryNearest(data);
+} // testQueryNearest
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.hh (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/TestGeoProjGridDBCases.hh)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.hh (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/TestSimpleGridDBCases.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,62 @@
+// -*- 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/TestSimpleGridDBCases.hh
+ *
+ * @brief C++ TestSimpleGridDBVolume3D object
+ *
+ * C++ unit testing for SimpleGridDB.
+ */
+
+#if !defined(spatialdata_spatialdb_testsimplegriddbcases_hh)
+#define spatialdata_spatialdb_testsimplegriddbcases_hh
+
+#include "TestSimpleGridDB.hh" // ISA TestSimpleGridDB
+
+/// Namespace for spatial package
+namespace spatialdata {
+ namespace spatialdb {
+ class TestSimpleGridDBVolume3D;
+ } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for SimpleGridDB with volume data.
+class spatialdata::spatialdb::TestSimpleGridDBVolume3D : public TestSimpleGridDB
+{ // class TestSimpleGridDBVolume3D
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestSimpleGridDBVolume3D );
+
+ CPPUNIT_TEST( testQueryNearest );
+ CPPUNIT_TEST( testQueryLinear );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Test queryNearest()
+ void testQueryNearest(void);
+
+ /// Test queryLinear()
+ void testQueryLinear(void);
+
+}; // class TestSimpleGridDBVolume3D
+
+#endif // spatialdata_spatialdb_testsimplegriddbvolume3d_hh
+
+
+// End of file
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,48 +0,0 @@
-// -*- 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
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,70 +0,0 @@
-// -*- 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
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,121 +0,0 @@
-// -*- 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 = 3;
-const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_numY = 2;
-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] = {
- -3.0, 1.0, 2.0,
-};
-const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbY[_numY] = {
- 2.0, 4.0,
-};
-const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbZ[_numZ] = {
- -0.5, 0.0, 1.0, 4.0,
-};
-
-const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_dbData[_numX*_numY*_numZ*_numVals] = {
- 1.00000000e-01, 1.10000000e+00, // 0,0,0
- 3.00000000e-01, 3.30000000e+00, // 0,0,1
- 2.00000000e-01, 2.20000000e+00, // 0,0,2
- 1.00000000e-01, 1.10000000e+00, // 0,0,3
- 4.00000000e-01, 4.60000000e+00, // 0,1,0
- 3.00000000e-01, 3.20000000e+00, // 0,1,1
- 7.00000000e-01, 5.20000000e+00, // 0,1,2
- 5.00000000e-01, 4.60000000e+00, // 0,1,3
- 0.00000000e-01, 1.20000000e+00, // 1,0,0
- 1.00000000e-01, 3.40000000e+00, // 1,0,1
- 2.00000000e-01, 2.10000000e+00, // 1,0,2
- 6.00000000e-01, 1.40000000e+00, // 1,0,3
- 9.00000000e-01, 4.70000000e+00, // 1,1,0
- 4.00000000e-01, 3.30000000e+00, // 1,1,1
- 7.00000000e-01, 5.50000000e+00, // 1,1,2
- 6.00000000e-01, 4.70000000e+00, // 1,1,3
- 5.00000000e-01, 1.60000000e+00, // 2,0,0
- 3.00000000e-01, 3.30000000e+00, // 2,0,1
- 8.00000000e-01, 2.80000000e+00, // 2,0,2
- 3.00000000e-01, 1.50000000e+00, // 2,0,3
- 7.00000000e-01, 4.80000000e+00, // 2,1,0
- 4.00000000e-01, 3.40000000e+00, // 2,1,1
- 3.00000000e-01, 5.70000000e+00, // 2,1,2
- 4.00000000e-01, 4.50000000e+00, // 2,1,3
-};
-
-const char* spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_names[_numVals] = {
- "One",
- "Two",
-};
-
-const char* spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_units[_numVals] = {
- "m",
- "m",
-};
-
-const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_queryNearest[_numQueries*(_spaceDim+_numVals)] = {
- -3.2, 3.8, 2.0, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
- 1.1, 1.3, -0.1, 1.00000000e-01, 3.40000000e+00, // (1,0,1)
- 0.0, -6.0, 5.0, 6.00000000e-01, 1.40000000e+00, // (1,0,3)
- 1.6, 3.4, -0.6, 7.00000000e-01, 4.80000000e+00, // (2,1,0)
- -2.0, 3.5, 0.9, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
-};
-
-const double spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_queryLinear[_numQueries*(_spaceDim+_numVals)] = {
- -3.0, 4.0, 1.0, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
- -1.0, 2.5, 2.5, 3.62500000e-01, 2.52500000e+00, // (0,5, 0.25, 2.5)
- 1.25, 3.0, 0.25, 3.25000000e-01, 3.49062500e+00, // (1.25, 0.5, 1.25)
- 0.0, 4.1, 0.0, 0.0, 0.0, // not found
- 1.0, 2.0, -0.6, 0.0, 0.0, // not fount
-};
-
-const int spatialdata::spatialdb::GeoProjGridDBTestDataVolume3D::_errFlags[_numQueries] = {
- 0, 0, 0, 1, 1,};
-
-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
Deleted: cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,77 +0,0 @@
-// -*- 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
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.cc (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.cc)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.cc (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -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 "SimpleGridDBTestData.hh"
+
+// ----------------------------------------------------------------------
+// Constructor
+spatialdata::spatialdb::SimpleGridDBTestData::SimpleGridDBTestData(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::SimpleGridDBTestData::~SimpleGridDBTestData(void)
+{ // destructor
+} // destructor
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.hh (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestData.hh)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.hh (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestData.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -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_simplegriddbtestdata_hh)
+#define spatialdata_spatialdb_simplegriddbtestdata_hh
+
+namespace spatialdata {
+ namespace spatialdb {
+ class SimpleGridDBTestData;
+ } // spatialdb
+} // spatialdata
+
+class spatialdata::spatialdb::SimpleGridDBTestData
+{
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ SimpleGridDBTestData(void);
+
+ /// Destructor
+ ~SimpleGridDBTestData(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_simplegriddbtestdata_hh
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.cc (from rev 20435, cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.cc)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.cc (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.cc 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,121 @@
+// -*- 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 "SimpleGridDBTestDataVolume3D.hh"
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_numX = 3;
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_numY = 2;
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_numZ = 4;
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_spaceDim = 3;
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_numVals = 2;
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_dataDim = 3;
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_numQueries = 5;
+
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_dbX[_numX] = {
+ -3.0, 1.0, 2.0,
+};
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_dbY[_numY] = {
+ 2.0, 4.0,
+};
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_dbZ[_numZ] = {
+ -0.5, 0.0, 1.0, 4.0,
+};
+
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_dbData[_numX*_numY*_numZ*_numVals] = {
+ 1.00000000e-01, 1.10000000e+00, // 0,0,0
+ 3.00000000e-01, 3.30000000e+00, // 0,0,1
+ 2.00000000e-01, 2.20000000e+00, // 0,0,2
+ 1.00000000e-01, 1.10000000e+00, // 0,0,3
+ 4.00000000e-01, 4.60000000e+00, // 0,1,0
+ 3.00000000e-01, 3.20000000e+00, // 0,1,1
+ 7.00000000e-01, 5.20000000e+00, // 0,1,2
+ 5.00000000e-01, 4.60000000e+00, // 0,1,3
+ 0.00000000e-01, 1.20000000e+00, // 1,0,0
+ 1.00000000e-01, 3.40000000e+00, // 1,0,1
+ 2.00000000e-01, 2.10000000e+00, // 1,0,2
+ 6.00000000e-01, 1.40000000e+00, // 1,0,3
+ 9.00000000e-01, 4.70000000e+00, // 1,1,0
+ 4.00000000e-01, 3.30000000e+00, // 1,1,1
+ 7.00000000e-01, 5.50000000e+00, // 1,1,2
+ 6.00000000e-01, 4.70000000e+00, // 1,1,3
+ 5.00000000e-01, 1.60000000e+00, // 2,0,0
+ 3.00000000e-01, 3.30000000e+00, // 2,0,1
+ 8.00000000e-01, 2.80000000e+00, // 2,0,2
+ 3.00000000e-01, 1.50000000e+00, // 2,0,3
+ 7.00000000e-01, 4.80000000e+00, // 2,1,0
+ 4.00000000e-01, 3.40000000e+00, // 2,1,1
+ 3.00000000e-01, 5.70000000e+00, // 2,1,2
+ 4.00000000e-01, 4.50000000e+00, // 2,1,3
+};
+
+const char* spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_names[_numVals] = {
+ "One",
+ "Two",
+};
+
+const char* spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_units[_numVals] = {
+ "m",
+ "m",
+};
+
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_queryNearest[_numQueries*(_spaceDim+_numVals)] = {
+ -3.2, 3.8, 2.0, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
+ 1.1, 1.3, -0.1, 1.00000000e-01, 3.40000000e+00, // (1,0,1)
+ 0.0, -6.0, 5.0, 6.00000000e-01, 1.40000000e+00, // (1,0,3)
+ 1.6, 3.4, -0.6, 7.00000000e-01, 4.80000000e+00, // (2,1,0)
+ -2.0, 3.5, 0.9, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
+};
+
+const double spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_queryLinear[_numQueries*(_spaceDim+_numVals)] = {
+ -3.0, 4.0, 1.0, 7.00000000e-01, 5.20000000e+00, // (0,1,2)
+ -1.0, 2.5, 2.5, 3.62500000e-01, 2.52500000e+00, // (0,5, 0.25, 2.5)
+ 1.25, 3.0, 0.25, 3.25000000e-01, 3.49062500e+00, // (1.25, 0.5, 1.25)
+ 0.0, 4.1, 0.0, 0.0, 0.0, // not found
+ 1.0, 2.0, -0.6, 0.0, 0.0, // not fount
+};
+
+const int spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::_errFlags[_numQueries] = {
+ 0, 0, 0, 1, 1,};
+
+spatialdata::spatialdb::SimpleGridDBTestDataVolume3D::SimpleGridDBTestDataVolume3D(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::SimpleGridDBTestDataVolume3D::~SimpleGridDBTestDataVolume3D(void)
+{}
+
+
+// End of file
Copied: cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.hh (from rev 20433, cs/spatialdata/trunk/tests/libtests/spatialdb/data/GeoProjGridDBTestDataVolume3D.hh)
===================================================================
--- cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.hh (rev 0)
+++ cs/spatialdata/trunk/tests/libtests/spatialdb/data/SimpleGridDBTestDataVolume3D.hh 2012-06-29 04:49:18 UTC (rev 20436)
@@ -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_simplegriddbtestdatavolume3d_hh)
+#define spatialdata_spatialdb_simplegriddbtestdatavolume3d_hh
+
+#include "SimpleGridDBTestData.hh"
+
+namespace spatialdata {
+ namespace spatialdb {
+ class SimpleGridDBTestDataVolume3D;
+ } // spatialdata
+} // spatialdb
+
+class spatialdata::spatialdb::SimpleGridDBTestDataVolume3D : public SimpleGridDBTestData
+{
+
+public:
+
+ /// Constructor
+ SimpleGridDBTestDataVolume3D(void);
+
+ /// Destructor
+ ~SimpleGridDBTestDataVolume3D(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_simplegriddbtestdatavolume3d_hh
+
+// End of file
Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -34,6 +34,7 @@
TestSimpleIOAscii.py \
TestSimpleDB.py \
TestUniformDB.py \
+ TestGeoProjGridDB.py \
TestTimeHistory.py \
TestTimeHistoryIO.py
Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleDB.py
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleDB.py 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleDB.py 2012-06-29 04:49:18 UTC (rev 20436)
@@ -26,7 +26,7 @@
db = SimpleDB()
db.inventory.label = "test"
db.inventory.queryType = "nearest"
- db.inventory.iohandler.inventory.filename = "data/spatialdb.dat"
+ db.inventory.iohandler.inventory.filename = "data/simple.spatialdb"
db.inventory.iohandler._configure()
db._configure()
self._db = db
Added: cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py (rev 0)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/TestSimpleGridDB.py 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# 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.
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+from spatialdata.geocoords.CSCart import CSCart
+
+class TestSimpleGridDB(unittest.TestCase):
+
+ def setUp(self):
+ from spatialdata.spatialdb.SimpleGridDB import SimpleGridDB
+ db = SimpleGridDB()
+ db.inventory.label = "test"
+ db.inventory.queryType = "nearest"
+ db.inventory.filename = "data/grid.spatialdb"
+ db._configure()
+ self._db = db
+ return
+
+
+ def test_database(self):
+ locs = numpy.array( [[1.0, 2.0, 3.0],
+ [5.6, 4.2, 8.6]],
+ numpy.float64)
+ cs = CSCart()
+ cs._configure()
+ queryVals = ["two", "one"]
+ dataE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
+ errE = [0, 0]
+
+ db = self._db
+ db.open()
+ db.queryVals(queryVals)
+ data = numpy.zeros(dataE.shape, dtype=numpy.float64)
+ err = []
+ nlocs = locs.shape[0]
+ for i in xrange(nlocs):
+ e = db.query(data[i,:], locs[i,:], cs)
+ err.append(e)
+ db.close()
+
+ self.assertEqual(len(errE), len(err))
+ for vE, v in zip(errE, err):
+ self.assertEqual(vE, v)
+
+ self.assertEqual(len(dataE.shape), len(data.shape))
+ for dE, d in zip(dataE.shape, data.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ return
+
+
+ def test_databasemulti(self):
+ locs = numpy.array( [[1.0, 2.0, 3.0],
+ [5.6, 4.2, 8.6]],
+ numpy.float64)
+ cs = CSCart()
+ cs._configure()
+ queryVals = ["two", "one"]
+ dataE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
+ errE = numpy.array([0, 0], numpy.int32)
+
+ db = self._db
+ db.open()
+ db.queryVals(queryVals)
+ data = numpy.zeros(dataE.shape, dtype=numpy.float64)
+ err = numpy.zeros(errE.shape, dtype=numpy.int32)
+ db.multiquery(data, err, locs, cs)
+ db.close()
+
+ self.assertEqual(len(errE), len(err))
+ for vE, v in zip(errE, err):
+ self.assertEqual(vE, v)
+
+ self.assertEqual(len(dataE.shape), len(data.shape))
+ for dE, d in zip(dataE.shape, data.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ return
+
+
+# End of file
Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/data/Makefile.am
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/data/Makefile.am 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/data/Makefile.am 2012-06-29 04:49:18 UTC (rev 20436)
@@ -15,7 +15,8 @@
#
data_DATA = \
- spatialdb.dat \
+ simple.spatialdb \
+ grid.spatialdb \
test_okay.timedb \
timehistory.timedb \
gen1Din2D_one_bg.spatialdb \
Added: cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb (rev 0)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/data/grid.spatialdb 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,45 @@
+#SPATIAL_GRID.ascii 1
+SimpleGridDB {
+ num-x = 2
+ num-y = 4
+ num-z = 3
+ num-values = 2
+ space-dim = 3
+ value-names = One Two
+ value-units = m cm
+ cs-data = cartesian {
+ to-meters = 1.0
+ }
+}
+// x
+2.0 4.0
+// y
+4.0 -0.5 1.0 0.0
+// z
+1.0 -3.0 2.0
+
+// data
+4.0 -0.5 -3.0 1.00 2.24
+4.0 -0.5 1.0 1.01 2.23
+4.0 -0.5 2.0 1.02 2.22
+4.0 0.0 -3.0 1.03 2.21
+4.0 0.0 1.0 1.04 2.20
+4.0 0.0 2.0 1.05 2.19
+4.0 1.0 -3.0 1.06 2.18
+4.0 1.0 1.0 1.07 2.17
+4.0 1.0 2.0 1.08 2.16
+4.0 4.0 -3.0 1.09 2.15
+4.0 4.0 1.0 1.10 2.14
+4.0 4.0 2.0 1.11 2.13
+2.0 -0.5 -3.0 1.12 2.12
+2.0 -0.5 1.0 1.13 2.11
+2.0 -0.5 2.0 1.14 2.10
+2.0 0.0 -3.0 1.15 2.09
+2.0 0.0 1.0 1.16 2.08
+2.0 0.0 2.0 1.17 2.07
+2.0 1.0 -3.0 1.18 2.06
+2.0 1.0 1.0 1.19 2.05
+2.0 1.0 2.0 1.20 2.04
+2.0 4.0 -3.0 1.21 2.03
+2.0 4.0 1.0 1.22 2.02
+2.0 4.0 2.0 1.23 2.01
Copied: cs/spatialdata/trunk/tests/pytests/spatialdb/data/simple.spatialdb (from rev 20433, cs/spatialdata/trunk/tests/pytests/spatialdb/data/spatialdb.dat)
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/data/simple.spatialdb (rev 0)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/data/simple.spatialdb 2012-06-29 04:49:18 UTC (rev 20436)
@@ -0,0 +1,12 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 2
+ value-names = One Two
+ value-units = m m
+ num-locs = 1
+ data-dim = 0
+ cs-data = cartesian {
+ to-meters = 1.0
+ }
+}
+ 6.000000e-01 1.000000e-01 2.000000e-01 6.300000e+00 4.700000e+00
Deleted: cs/spatialdata/trunk/tests/pytests/spatialdb/data/spatialdb.dat
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/data/spatialdb.dat 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/data/spatialdb.dat 2012-06-29 04:49:18 UTC (rev 20436)
@@ -1,12 +0,0 @@
-#SPATIAL.ascii 1
-SimpleDB {
- num-values = 2
- value-names = One Two
- value-units = m m
- num-locs = 1
- data-dim = 0
- cs-data = cartesian {
- to-meters = 1.0
- }
-}
- 6.000000e-01 1.000000e-01 2.000000e-01 6.300000e+00 4.700000e+00
Modified: cs/spatialdata/trunk/tests/pytests/spatialdb/testspatial.py
===================================================================
--- cs/spatialdata/trunk/tests/pytests/spatialdb/testspatial.py 2012-06-29 03:04:11 UTC (rev 20435)
+++ cs/spatialdata/trunk/tests/pytests/spatialdb/testspatial.py 2012-06-29 04:49:18 UTC (rev 20436)
@@ -29,6 +29,9 @@
from TestUniformDB import TestUniformDB
suite.addTest(unittest.makeSuite(TestUniformDB))
+ from TestSimpleGridDB import TestSimpleGridDB
+ suite.addTest(unittest.makeSuite(TestSimpleGridDB))
+
from TestCompositeDB import TestCompositeDB
suite.addTest(unittest.makeSuite(TestCompositeDB))
More information about the CIG-COMMITS
mailing list