[cig-commits] r12371 - in cs/spatialdata-0.1/trunk: . templates templates/spatialdb

brad at geodynamics.org brad at geodynamics.org
Thu Jul 3 13:43:02 PDT 2008


Author: brad
Date: 2008-07-03 13:43:02 -0700 (Thu, 03 Jul 2008)
New Revision: 12371

Added:
   cs/spatialdata-0.1/trunk/templates/
   cs/spatialdata-0.1/trunk/templates/Makefile.am
   cs/spatialdata-0.1/trunk/templates/spatialdb/
   cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.cc
   cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.hh
   cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.icc
   cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.py
   cs/spatialdata-0.1/trunk/templates/spatialdb/Makefile.am
   cs/spatialdata-0.1/trunk/templates/spatialdb/README
   cs/spatialdata-0.1/trunk/templates/spatialdb/__init__.py
   cs/spatialdata-0.1/trunk/templates/spatialdb/configure.ac
   cs/spatialdata-0.1/trunk/templates/spatialdb/spatialdb.pyxe.src
Modified:
   cs/spatialdata-0.1/trunk/Makefile.am
   cs/spatialdata-0.1/trunk/configure.ac
Log:
Started setting up template for example of extending spatialdata.

Modified: cs/spatialdata-0.1/trunk/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/Makefile.am	2008-07-03 17:29:56 UTC (rev 12370)
+++ cs/spatialdata-0.1/trunk/Makefile.am	2008-07-03 20:43:02 UTC (rev 12371)
@@ -13,7 +13,8 @@
 ACLOCAL_AMFLAGS = -I ./m4
 
 SUBDIRS = \
-	libsrc
+	libsrc \
+	templates
 
 if ENABLE_PYTHIA
   SUBDIRS += modulesrc spatialdata applications

Modified: cs/spatialdata-0.1/trunk/configure.ac
===================================================================
--- cs/spatialdata-0.1/trunk/configure.ac	2008-07-03 17:29:56 UTC (rev 12370)
+++ cs/spatialdata-0.1/trunk/configure.ac	2008-07-03 20:43:02 UTC (rev 12371)
@@ -169,6 +169,7 @@
 	tests/pytests/spatialdb/data/Makefile
 	tests/pytests/utils/Makefile
 	applications/Makefile
+	templates/Makefile
 	doc/Makefile])
 
 AC_OUTPUT

Added: cs/spatialdata-0.1/trunk/templates/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/templates/Makefile.am	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/Makefile.am	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,29 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+EXTRA_DIST = \
+	README \
+	spatialdb/README \
+	spatialdb/configure.ac \
+	spatialdb/Makefile.am \
+	spatialdb/aclocal.m4 \
+	spatialdb/Makefile.in \
+	spatialdb/portinfo.in \
+	spatialdb/configure \
+	spatialdb/GeoGridVelModel.hh \
+	spatialdb/GeoGridVelModel.icc \
+	spatialdb/GeoGridVelModel.cc \
+	spatialdb/__init__.py \
+	spatialdb/GeoGridVelModel.py \
+	spatialdb/geogridvelmodel.pyxe.src
+
+# End of file 


Property changes on: cs/spatialdata-0.1/trunk/templates/spatialdb
___________________________________________________________________
Name: svn:externals
   + m4 http://geodynamics.org/svn/cig/cs/autoconf/trunk


Added: cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.cc
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.cc	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.cc	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,144 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "GeoGridVelModel.hh" // Implementation of class methods
+
+#include "spatialdata/geocoords/CSGeo.hh" // USES CSGeo
+#include "spatialdata/geocoords/Converter.hh" // USES Converter
+
+#include <math.h> // USES pow()
+#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()
+
+// ----------------------------------------------------------------------
+// Constructor
+yourname::spatialdb::GeoGridVelModel::GeoGridVelModel(void) :
+  SpatialDB("My velocity model"),
+  _filename(""),
+  _csGeo(new spatialdata::geocoords::CSGeo),
+  _queryVals(0),
+  _querySize(0)
+{ // constructor
+  _csGeo->datumHoriz("WGS84");
+  _csGeo->datumVert("mean sea level");
+  _csGeo->ellipsoid("WGS84");
+  _csGeo->initialize();
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+yourname::spatialdb::GeoGridVelModel::~GeoGridVelModel(void)
+{ // destructor
+  // Deallocate all data
+  delete _csGeo; _csGeo = 0;
+
+  delete[] _queryVals; _queryVals = 0;
+  _querySize = 0;
+
+} // destructor
+
+// ----------------------------------------------------------------------
+// Open the database and prepare for querying.
+void
+yourname::spatialdb::GeoGridVelModel::open(void)
+{ // open
+  // Read the velocity model and do any necessary pre-query stuff.
+} // open
+
+// ----------------------------------------------------------------------
+// Close the database.
+void
+yourname::spatialdb::GeoGridVelModel::close(void)
+{ // close
+  // Deallocate all data allocated in open() and query().
+} // close
+
+// ----------------------------------------------------------------------
+// Set values to be returned by queries.
+void
+yourname::spatialdb::GeoGridVelModel::queryVals(const char** names,
+					    const int numVals)
+{ // queryVals
+  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(0 != names && 0 < numVals);
+  
+  _querySize = numVals;
+  delete[] _queryVals; _queryVals = new int[numVals];
+  for (int iVal=0; iVal < numVals; ++iVal) {
+    // Set the values to be returned in a query.
+    if (0 == strcasecmp(names[iVal], "vp"))
+      _queryVals[iVal] = QUERY_VP;
+    else if (0 == strcasecmp(names[iVal], "vs"))
+      _queryVals[iVal] = QUERY_VS;
+    else if (0 == strcasecmp(names[iVal], "density")) {
+      _queryVals[iVal] = QUERY_DENSITY;
+      std::ostringstream msg;
+      msg
+	<< "Could not find value " << names[iVal] << " in spatial database\n"
+	<< label() << ". Available values are:\n"
+	<< "vp, vs, density, topo-elev, basement-depth, moho-depth, vp-tag.";
+      throw std::runtime_error(msg.str());
+    } // else
+  } // for
+} // queryVals
+
+// ----------------------------------------------------------------------
+// Query the database.
+int
+yourname::spatialdb::GeoGridVelModel::query(double* vals,
+					const int numVals,
+					const double* coords,
+					const int numDims,
+					const spatialdata::geocoords::CoordSys* csQuery)
+{ // query
+  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());
+  } // if
+  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());
+  } // if
+
+  // Convert coordinates to local coordinate system
+  memcpy(_xyzGeo, coords, numDims*sizeof(double));
+  spatialdata::geocoords::Converter::convert(_xyzGeo, 1, numDims, 
+					     _csGeo, csQuery);
+
+  int queryFlag = 0;
+  
+  // ADD QUERY STUFF HERE
+
+  return queryFlag;
+} // query
+
+
+// End of file

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.hh
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.hh	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.hh	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,128 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(yourname_spatialdb_geogridvelmodel_hh)
+#define yourname_spatialdb_geogridvelmodel_hh
+
+#include "spatialdata/spatialdb/SpatialDB.hh" // ISA SpatialDB
+
+#include <string> // HASA std::string
+
+namespace yourname {
+  namespace spatialdb {
+    class GeoGridVelModel;
+
+    class TestGeoGridVelModel; // unit testing
+  } // spatialdb
+} // yourname
+
+namespace spatialdata {
+  namespace geocoords {
+    class CSGeo; // HASA CSGeo
+  } // geocoords
+} // spatialdata
+
+class yourname::spatialdb::GeoGridVelModel : spatialdata::spatialdb::SpatialDB
+{ // GeoGridVelModel
+  friend class TestGeoGridVelModel; // unit testing
+ 
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+ 
+  /// Constructor
+  GeoGridVelModel(void);
+ 
+  /// Destructor
+  ~GeoGridVelModel(void);
+ 
+  /** Set filename of velocity model.
+   *
+   * @param name Filename of velocity model.
+   */
+  void filename(const char* name);
+ 
+  /// Open the database and prepare for querying.
+  void open(void);
+ 
+  /// Close the database.
+  void close(void);
+ 
+  /** 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** 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);
+ 
+ 
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+ 
+  GeoGridVelModel(const GeoGridVelModel&); ///< Not implemented
+  const GeoGridVelModel& operator=(const GeoGridVelModel&); ///< Not implemented
+ 
+// PRIVATE ENUMS ////////////////////////////////////////////////////////
+private :
+ 
+  // Indices of values in database (used in queryVals to indicate
+  // which values to return in a query).
+  enum QueryValsEnum {
+    QUERY_VP=0, // vp
+    QUERY_VS=1, // vs
+    QUERY_DENSITY=2, // density
+  }; // ValsEnum
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  double _xyzGeo[3];
+
+  // Add members for holding velocity model information.
+
+  std::string _filename;
+  spatialdata::geocoords::CSGeo* _csGeo;
+
+  int* _queryVals; ///< Indices of values to be returned in queries.
+  int _querySize; ///< Number of values requested to be returned in queries.
+
+}; // GeoGridVelModel
+
+#include "GeoGridVelModel.icc" // inline methods
+
+#endif // yourname_spatialdb_geogridvelmodel_hh
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.icc
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.icc	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.icc	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,23 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(yourname_spatialdb_geogridvelmodel_hh)
+#error "GeoGridVelModel.icc must only be included from GeoGridVelModel.hh"
+#endif
+
+// Set filename of velocity model.
+void
+yourname::spatialdb::GeoGridVelModel::filename(const char* name) {
+  _filename = name;
+} // filename
+
+// End of file

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.py
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.py	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/GeoGridVelModel.py	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+# 1. Rename the MyVelModel class to something appropriate (do a
+#    search/replace on MyVelModel).
+# 2. Add the necessary Pyre properties and facilities for user parameters.
+# 3. Update the constructor, __init__().
+# 4. Update initialize().
+# 5. Update _configure().
+
+## @brief Python manager for spatial database interface to a new velocity
+## model.
+##
+## Factory: spatial_database
+
+from spatialdata.spatialdb.SpatialDB import SpatialDB
+
+# MyVelModel class
+class MyVelModel(SpatialDB):
+  """
+  Python manager for spatial database to a new velocity model.
+
+  Factory: spatial_database
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(SpatialDB.Inventory):
+    """
+    Python object for managing MyVelModel facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing MyVelModel facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b filename Filename for seismic velocity model.
+    ##
+    ## \b Facilities
+    ## @li none
+
+    import pyre.inventory
+
+    filename = pyre.inventory.str("filename", default="model.txt")
+    filename.meta['tip'] = "Filename for seismic velocity model."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  # Change this name.
+  def __init__(self, name="myvelmodel"):
+    """
+    Constructor.
+    """
+    SpatialDB.__init__(self, name)
+    import spatialdb as bindings
+    self.cppHandle = bindings.MyVelModel() # Change this
+    self.cppHandle.label = "My velocity model" # Change this
+    return
+
+
+  def initialize(self):
+    """
+    Initialize database.
+    """
+    SpatialDB.initialize(self)
+
+    # Transfer Pyre properties/facilities to C++
+    self.cppHandle.filename(self.filename)
+    return
+  
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based on inventory.
+    """
+    SpatialDB._configure(self)
+    # Transfer inventory to object
+    self.filename = self.inventory.filename
+    return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+  """
+  Factory associated with MyVelModel.
+  """
+  return MyVelModel()
+
+
+# End of file 

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/Makefile.am	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/Makefile.am	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,68 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+# LIBRARY --------------------------------------------------------------
+lib_LTLIBRARIES = libyournamespatialdb.la
+
+libyournamespatialdb_la_SOURCES = \
+	GeoGridVelModel.cc
+
+libyournamespatialdb_la_LDFLAGS = $(AM_LDFLAGS)
+
+libyournamespatialdb_la_LIBADD = \
+	-lspatialdata \
+	-lproj
+
+INCLUDES = 
+
+# MODULE ---------------------------------------------------------------
+
+pkgpyexec_LTLIBRARIES = yournamespatialdbmodule.la
+
+yournamespatialdbmodule_la_LDFLAGS = -module -avoid-version \
+	$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+dist_yournamespatialdbmodule_la_SOURCES = spatialdb.pyxe.src
+nodist_yournamespatialdbmodule_la_SOURCES = \
+	spatialdb.pyxe \
+	spatialdb.c spatialdb_embed.cpp spatialdb_embed.h
+
+yournamespatialdbmodule_la_LIBADD = libyournamespatialdb.la
+if NO_UNDEFINED
+yournamespatialdbmodule_la_LIBADD += \
+	$(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+endif
+
+INCLUDES += -I$(PYTHON_INCDIR)
+
+spatialdb.pyx spatialdb_embed.cpp  spatialdb_embed.h: spatialdb.pyxe
+	pyrexembed spatialdb.pyxe
+spatialdb.pyxe: $(srcdir)/spatialdb.pyxe.src
+	cp $(srcdir)/spatialdb.pyxe.src $@
+spatialdb_embed.cpp: spatialdb_embed.h
+spatialdb_embed.h: spatialdb.pyx
+
+.pyx.c:
+	pyrexc $<
+
+CLEANFILES = spatialdb.pyx spatialdb.pyxe spatialdb.c *_embed.*
+
+
+
+# PYTHON ---------------------------------------------------------------
+
+nobase_pkgpyexec_PYTHON = \
+	__init__.py \
+	GeoGridVelModel.py
+
+
+# End of file 

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/README
===================================================================

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/__init__.py
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/__init__.py	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/__init__.py	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file __init__.py
+##
+## @brief Python top-level SpatialData module initialization
+
+__all__ = ['GeoGridVelModel',
+           ]
+
+
+# End of file

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/configure.ac
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/configure.ac	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/configure.ac	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,106 @@
+# -*- autoconf -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+AC_PREREQ(2.59)
+AC_INIT([yourname], [0.0.1], [youremail at here])
+AC_CONFIG_HEADER([portinfo])
+AC_CONFIG_AUX_DIR([./aux-config])
+AM_INIT_AUTOMAKE([foreign])
+
+# ----------------------------------------------------------------------
+# TESTING w/cppunit
+AC_ARG_ENABLE([testing],
+	[  --enable-testing        Enable unit testing with cppunit (requires cppunit) [[default=no]]],
+	[enable_testing=yes],
+	[enable_testing=no])
+
+# ----------------------------------------------------------------------
+# C/C++/libtool/install
+AC_PROG_CXX
+AC_PROG_CC
+AC_DISABLE_STATIC
+
+AC_PROG_LIBTOOL
+if test "$allow_undefined_flag" = unsupported; then
+    # See issue119.
+    AM_LDFLAGS="-no-undefined $AM_LDFLAGS"
+fi
+AM_CONDITIONAL([NO_UNDEFINED], [test "$allow_undefined_flag" = unsupported])
+AC_SUBST(AM_LDFLAGS)
+
+AC_PROG_INSTALL
+
+# PYTHON
+AM_PATH_PYTHON([2.3])
+CIT_PYTHON_SYSCONFIG
+
+# Check for Python modules and packages.
+#CIT_PYTHON_EGG_SETUP
+
+# PYREX/PYREXEMBED
+AC_CHECK_PROG([have_pyrex],
+  [pyrexc],
+  [yes],
+  [no])
+if test "$have_pyrex" = "no"; then
+  AC_MSG_ERROR([Pyrex not found in current path.])
+fi
+AC_CHECK_PROG([have_pyrexembed],
+  [pyrexembed],
+  [yes],
+  [no])
+if test "$have_pyrexembed" = "no"; then
+  AC_MSG_ERROR([Pyrexembed not found in current path.])
+fi
+
+# CPPUNIT
+if test "$enable_testing" = "yes" ; then
+  AC_LANG(C++)
+  AC_CHECK_HEADER([cppunit/TestRunner.h], [], [
+    AC_MSG_ERROR([CppUnit header not found; try CPPFLAGS="-I<CppUnit include dir>"])
+  ])
+  AC_MSG_CHECKING([for CppUnit::TestRunner in -lcppunit])
+  AC_REQUIRE_CPP
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[#include <cppunit/TestRunner.h>]],
+	             [[CppUnit::TestRunner runner;]])],
+    [AC_MSG_RESULT(yes)],
+    [AC_MSG_RESULT(no)
+     AC_MSG_ERROR([CppUnit library not found; try LDFLAGS="-L<CppUnit lib dir>"])
+  ])
+fi
+
+# SPATIALDATA
+AC_LANG(C++)
+AC_CHECK_HEADER([spatialdata/spatialdb/SpatialDB.hh], [], [
+  AC_MSG_ERROR([SpatialDB header not found; try CPPFLAGS="-I<Spatialdata include dir>"])
+])
+AC_MSG_CHECKING([for spatialdb::SimpleDB in -lspatialdata])
+AC_REQUIRE_CPP
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([[#include <spatialdata/spatialdb/SpatialDB.hh>]
+                    [#include <spatialdata/spatialdb/SimpleDB.hh>]],
+                   [[spatialdata::spatialdb::SimpleDB db;]])],
+  [AC_MSG_RESULT(yes)],
+  [AC_MSG_RESULT(no)
+   AC_MSG_ERROR([Spatialdata library not found; try LDFLAGS="-L<Spatialdata lib dir>"])
+])
+
+# ENDIANNESS
+AC_C_BIGENDIAN
+
+# ----------------------------------------------------------------------
+AC_CONFIG_FILES([Makefile])
+
+AC_OUTPUT
+
+dnl end of configure.ac

Added: cs/spatialdata-0.1/trunk/templates/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/templates/spatialdb/spatialdb.pyxe.src	                        (rev 0)
+++ cs/spatialdata-0.1/trunk/templates/spatialdb/spatialdb.pyxe.src	2008-07-03 20:43:02 UTC (rev 12371)
@@ -0,0 +1,338 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+#header{
+#include "spatialdata/spatialdb/SpatialDB.hh"
+#include "spatialdata/spatialdb/GeoVelModel.hh"
+
+#include "spatialdata/geocoords/CoordSys.hh"
+
+#include <stdexcept>
+#include <Python.h>
+#}header
+
+# ----------------------------------------------------------------------
+cdef extern from "Python.h":
+  object PyCObject_FromVoidPtr(void*, void (*destruct)(void*))
+  void* PyCObject_AsVoidPtr(object)
+
+
+cdef extern from "stdlib.h":
+  ctypedef unsigned long size_t
+  void* malloc(size_t size)
+  void free(void* mem)
+  void strcpy(char*, char*)
+
+
+cdef void* ptrFromHandle(obj):
+  """
+  Extract pointer from PyCObject.
+  """
+  return PyCObject_AsVoidPtr(obj.handle)
+
+cdef double* doubleArray(size):
+  """
+  Allocate C++ double array.
+  """
+  # create shim
+  #embed{ double* doubleArray_cpp(int size)
+  double* result = (size > 0) ? new double[size] : 0;
+  return result;
+  #}embed
+  return doubleArray_cpp(size)
+
+
+cdef float* floatArray(size):
+  """
+  Allocate C++ float array.
+  """
+  # create shim
+  #embed{ float* floatArray_cpp(int size)
+  float* result = (size > 0) ? new float[size] : 0;
+  return result;
+  #}embed
+  return floatArray_cpp(size)
+
+
+cdef int* intArray(size):
+  """
+  Allocate C++ int array.
+  """
+  # create shim
+  #embed{ int* intArray_cpp(int size)
+  int* result = (size > 0) ? new int[size] : 0;
+  return result;
+  #}embed
+  return intArray_cpp(size)
+
+
+# ----------------------------------------------------------------------
+cdef void SpatialDB_destructor(void* obj):
+  """
+  Destroy SpatialDB object.
+  """
+  # create shim for destructor
+  #embed{ void SpatialDB_destructor_cpp(void* pObj)
+  spatialdata::spatialdb::SpatialDB* pDB =
+    (spatialdata::spatialdb::SpatialDB*) pObj;
+  delete pDB;
+  #}embed
+  SpatialDB_destructor_cpp(obj)
+  return
+
+cdef class SpatialDB:
+
+  cdef void* thisptr # Pointer to C++ object
+  cdef readonly object handle # PyCObject holding pointer to C++ object
+  cdef readonly object name # Identifier for type of object
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    self.handle = None
+    self.thisptr = NULL
+    self.name = "spatialdata_spatialdb_SpatialDB"
+    return
+
+
+  property label:
+    def __set__(self, name):
+      """
+      Set label of spatial database.
+      """
+      # create shim for method 'label'
+      #embed{ void SpatialDB_label_set(void* pObj, char* name)
+      try {
+        ((spatialdata::spatialdb::SpatialDB*) pObj)->label(name);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+
+      SpatialDB_label_set(self.thisptr, name)
+
+    def __get__(self):
+      """
+      Get label of spatial database.
+      """
+      # create shim for method 'label'
+      #embed{ char* SpatialDB_label_get(void* pObj)
+      char* label = 0;
+      try {
+        label = (char*) ((spatialdata::spatialdb::SpatialDB*) pObj)->label();
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      return label;
+      #}embed
+
+      return SpatialDB_label_get(self.thisptr)
+
+      
+  def open(self):
+    """
+    Open database and prepare for querying.
+    """
+    # create shim for method 'open'
+    #embed{ void SpatialDB_open(void* pObj)
+    try {
+      ((spatialdata::spatialdb::SpatialDB*) pObj)->open();
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    #}embed
+
+    SpatialDB_open(self.thisptr)
+    return
+
+
+  def close(self):
+    """
+    Close the database.
+    """
+    # create shim for method 'close'
+    #embed{ void SpatialDB_close(void* pObj)
+    try {
+      ((spatialdata::spatialdb::SpatialDB*) pObj)->close();
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    #}embed
+
+    SpatialDB_close(self.thisptr)
+    return
+
+
+  def queryVals(self, names):
+    """
+    Set values to be returned by queries.
+    """
+    # create shim for method 'queryVals'
+    #embed{ void SpatialDB_queryVals(void* pObj, char** names, int numVals)
+    try {
+      ((spatialdata::spatialdb::SpatialDB*) pObj)->queryVals((const char**) names, numVals);
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    #}embed
+
+    cdef char** pNames
+    pNames = NULL
+    numVals = len(names)
+    if numVals > 0:
+      pNames = <char**> malloc(numVals*sizeof(char*))
+    for i from 0 <= i < numVals:
+      strsize = len(names[i])
+      pNames[i] = <char*> malloc(1+strsize*sizeof(char))
+      tmp = names[i]
+      strcpy(pNames[i], tmp)
+
+    SpatialDB_queryVals(self.thisptr, pNames, numVals)
+
+    # memory cleanup
+    for i from 0 <= i < numVals:
+      free(<void*> pNames[i])
+    free(<void*> pNames)
+    
+    return
+
+
+  def query(self, locs, cs, nvals):
+    """
+    Query db to get values at locations.
+    """
+    # create shim for method 'query'
+    #embed{ int SpatialDB_query(void* pObj, double* vals, int nvals, double* coords, int spaceDim, void* csObj)
+    int err = 0;
+    try {
+      spatialdata::geocoords::CoordSys* pCS =
+        (spatialdata::geocoords::CoordSys*) csObj;
+        err = ((spatialdata::spatialdb::SpatialDB*) pObj)->query(vals, nvals,
+                                                            coords, spaceDim,
+                                                            pCS);
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    return err;
+    #}embed
+
+    import spatialdata.utils.simplearray
+    locs = spatialdata.utils.simplearray.objAsSimpleArray(locs)
+    if not locs.isCompatible(nd=2,
+                             simpletype="double",
+                             contiguous=True,
+                             notswapped=True):
+      raise TypeError, \
+            "Argument 'locs' must be a contiguous, 2-D array of type double."
+
+    if not cs.name == "spatialdata_geocoords_CoordSys":
+      raise TypeError, \
+            "Argument 'cs' must be extension module type 'CoordSys'."
+    if nvals < 1:
+      raise TypeError, \
+              "Argument 'nvals' must be a positive integer."
+
+    (nlocs, spaceDim) = locs.shape
+    
+    cdef double* pLocs
+    pLocs = <double*> PyCObject_AsVoidPtr(locs.data)
+
+    cdef double* pVals
+    pVals = doubleArray(nlocs*nvals)
+
+    cdef int* pErr
+    pErr = <int*> intArray(nlocs)
+
+    cdef double* valbuffer
+    valbuffer = <double*> malloc(nvals*sizeof(double))
+
+    for iloc from 0 <= iloc < nlocs:
+      pErr[iloc] = SpatialDB_query(self.thisptr, valbuffer, nvals,
+                                  &pLocs[spaceDim*iloc], spaceDim,
+                                  ptrFromHandle(cs))
+      for ival from 0 <= ival < nvals:
+        pVals[nvals*iloc+ival] = valbuffer[ival]
+    free(<void*> valbuffer)
+
+    dims = [nlocs, nvals]
+    import spatialdata.utils.simplearray
+    pValsObj = PyCObject_FromVoidPtr(pVals, NULL);
+    pErrObj = PyCObject_FromVoidPtr(pErr, NULL);
+    return (spatialdata.utils.simplearray.SimpleCppArray(pValsObj, dims, "double"),
+            spatialdata.utils.simplearray.SimpleCppArray(pErrObj, [nlocs], "int"))
+
+
+  def _createHandle(self):
+    """
+    Wrap pointer to C++ object in PyCObject.
+    """
+    return PyCObject_FromVoidPtr(self.thisptr, SpatialDB_destructor)
+
+
+# ----------------------------------------------------------------------
+cdef class GeoGridVelModel(SpatialDB):
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    # create shim for constructor
+    #embed{ void* GeoGridVelModel_constructor()
+      return (void*)(new spatialdata::spatialdb::GeoGridVelModel);
+    #}embed
+
+    SpatialDB.__init__(self)
+    self.thisptr = GeoGridVelModel_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  def filename(self, name):
+    """
+    Set the filename for velocity model data file.
+    """
+    # create shim for method 'filename'
+    #embed{ void GeoGridVelModel_filename(void* pObj, char* name)
+    assert(0 != pObj);
+    ((spatialdata::spatialdb::GeoGridVelModel*) pObj)->filename(name);
+    #}embed
+
+    GeoGridVelModel_filename(self.thisptr, name)
+    return
+
+
+# End of file 



More information about the cig-commits mailing list