[packages/gridfields] - updated to 1.0.3 from svn (clib-svn and py-svn patches) - added python patch (fixes python module
qboosh
qboosh at pld-linux.org
Sat May 17 20:37:37 CEST 2014
commit 7ecd07713d1f7be6247711f631dc9c4fa047afc0
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date: Sat May 17 20:40:18 2014 +0200
- updated to 1.0.3 from svn (clib-svn and py-svn patches)
- added python patch (fixes python module build)
gridfields-clib-svn.patch | 37435 ++++++++++++++++++++++++++++++++++++++++++++
gridfields-py-svn.patch | 2808 ++++
gridfields-python.patch | 41 +
gridfields.spec | 38 +-
4 files changed, 40311 insertions(+), 11 deletions(-)
---
diff --git a/gridfields.spec b/gridfields.spec
index aaf96aa..ea063c1 100644
--- a/gridfields.spec
+++ b/gridfields.spec
@@ -1,16 +1,27 @@
Summary: GridFields - convenient, algebraic manipulation of unstructured grids
Summary(pl.UTF-8): GridFields - wygodne operacje algebraiczne na tablicach bez struktury
Name: gridfields
-Version: 0.7
-Release: 1
-# according to project page
-License: MIT
+%define snap 20140423
+Version: 1.0.3
+Release: 0.%{snap}.1
+# project page says "MIT", but included spec and COPYING say LGPL v2+
+License: LGPL v2+
Group: Libraries
#Source0Download: https://code.google.com/p/gridfields/downloads/list
Source0: https://gridfields.googlecode.com/files/tag.tgz
# Source0-md5: 05e1aeb82fac693e57ed9e16c6a09556
+# released source is too old, so:
+# svn checkout http://gridfields.googlecode.com/svn/trunk/ gridfields
+# diff -Nur -x .svn tag/gridfieldsclib-0.7 gridfields/clib
+Patch0: %{name}-clib-svn.patch
+# diff -Nur -x .svn tag/pygridfields-0.7 gridfields/pygridfields
+Patch1: %{name}-py-svn.patch
+Patch2: %{name}-python.patch
URL: https://code.google.com/p/gridfields/
+BuildRequires: autoconf >= 2.68
+BuildRequires: automake
BuildRequires: libstdc++-devel
+BuildRequires: libtool >= 2:1.5
BuildRequires: netcdf-devel >= 4
BuildRequires: netcdf-cxx-devel >= 4
BuildRequires: python-devel >= 1:2.4
@@ -72,19 +83,23 @@ tablicach bez struktury z poziomu C++ i Pythona.
Ten pakiet zawiera bibliotekę dla Pythona.
%prep
-%setup -q -n tag
+%setup -q -c
+cd tag
+%patch0 -p1
+%patch1 -p1
+%patch2 -p1
%build
-cd gridfieldsclib-%{version}
+cd tag/gridfieldsclib-0.7
%{__libtoolize}
-%{__aclocal}
+%{__aclocal} -I conf
%{__autoconf}
%{__autoheader}
%{__automake}
%configure
%{__make}
-cd ../pygridfields-%{version}
+cd ../pygridfields-0.7
CC="%{__cc}" \
CFLAGS="%{rpmcflags}" \
%{__python} setup.py build
@@ -92,10 +107,10 @@ CFLAGS="%{rpmcflags}" \
%install
rm -rf $RPM_BUILD_ROOT
-%{__make} -C gridfieldsclib-%{version} install \
+%{__make} -C tag/gridfieldsclib-0.7 install \
DESTDIR=$RPM_BUILD_ROOT
-cd pygridfields-%{version}
+cd tag/pygridfields-0.7
%{__python} setup.py install \
--skip-build \
--optimize=2 \
@@ -110,12 +125,13 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(644,root,root,755)
-%doc gridfieldsclib-%{version}/README
+%doc tag/gridfieldsclib-0.7/README
%attr(755,root,root) %{_libdir}/libgridfields.so.*.*.*
%attr(755,root,root) %ghost %{_libdir}/libgridfields.so.1
%files devel
%defattr(644,root,root,755)
+%attr(755,root,root) %{_bindir}/gridfields-config
%attr(755,root,root) %{_libdir}/libgridfields.so
%{_libdir}/libgridfields.la
%{_includedir}/gridfields
diff --git a/gridfields-clib-svn.patch b/gridfields-clib-svn.patch
new file mode 100644
index 0000000..ad61a9a
--- /dev/null
+++ b/gridfields-clib-svn.patch
@@ -0,0 +1,37435 @@
+diff -Nur -x .svn tag/gridfieldsclib-0.7/ChangeLog gridfields/clib/ChangeLog
+--- tag/gridfieldsclib-0.7/ChangeLog 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/ChangeLog 2014-05-16 22:59:45.900055090 +0200
+@@ -0,0 +1,178 @@
++2014-04-04 jgallagher at opendap.org
++
++ Removed warnings except for cast-align, deprecated and
++ sign-compare which seem like more work.
++
++2014-04-04 jgallagher at opendap.org
++
++ svn ignores
++
++2014-04-04 jgallagher at opendap.org
++
++ Changed from using a header named config.h to config_gridfields.h
++ so that it can be used by library headers that are installed
++ without causing too much grief for other packages. Ideally this
++ header would not be installed or used by any of the library's
++ headers...
++
++ M CmdLine.cpp
++ M Makefile.am
++ M NEWS
++ M configure.ac
++ M src/access.h
++ M src/accumulate.cc
++ M src/accumulate.h
++ M src/aggregate.cc
++ M src/aggregate.h
++ M src/aggregations.cc
++ M src/apply.cc
++ M src/apply.h
++ M src/array.cc
++ M src/array.h
++ M src/arrayreader.cc
++ M src/arrayreader.h
++ M src/arraywriter.cc
++ M src/assignments.cc
++ M src/bind.cc
++ M src/bindconstant.cc
++ M src/cell.cc
++ M src/cellarray.cc
++ M src/cellarray.h
++ M src/constarray.cc
++ M src/cross.cc
++ M src/datadump.cc
++ M src/dataset.cc
++ M src/elcircfile.cc
++ M src/elio.c
++ M src/expr.cc
++ M src/fparser.cc
++ M src/grid.cc
++ M src/grid.h
++ M src/gridfield.cc
++ M src/gridfieldoperator.cc
++ M src/implicit0cells.cc
++ M src/merge.cc
++ M src/netcdfadaptor.cc
++ M src/output.cc
++ M src/outputtuples.cc
++ M src/project.cc
++ M src/project.h
++ M src/rankeddataset.cc
++ M src/refrestrict.cc
++ M src/restrict.cc
++ M src/scaninternal.cc
++ M src/sift.cc
++ M src/timing.cc
++ M src/tonetcdf.cc
++ M src/tuple.cc
++ M src/type.cc
++ M src/unarynodemap.cc
++ M src/util.cc
++ M src/util.h
++
++2014-02-13 jgallagher at opendap.org
++
++ Updates for C++-11. See NEWS. I bumbed the version to 1.0.2.
++
++ M Makefile.am
++ M NEWS
++ M configure.ac
++ M src/accumulate.h
++ M src/aggregate.h
++ M src/apply.h
++ M src/array.cc
++ M src/cell.cc
++ M src/cellarray.cc
++ M src/cellarray.h
++ M src/expr.cc
++ M src/expr.h
++ M src/grid.cc
++ M src/grid.h
++ M src/implicit0cells.cc
++ M src/normnodemap.h
++ M src/project.h
++
++2012-12-11 jgallagher at opendap.org
++
++ Added a --disable-netcdf option. This lets us build the library
++ and use it with run-time loaded modules, some of which also use
++ netcdf, without conflicts due to different versions of the
++ library.
++
++ M configure.ac
++ M INSTALL
++ M NEWS
++ M README
++
++2012-10-29 jgallagher at opendap.org
++
++ Fixed syntax errors on lines with both libnetcdf and libnetcdf++.
++
++ M conf/netcdf.m4
++
++2012-10-26 jgallagher at opendap.org
++
++ Some fixes for distcheck - it's closer now but still not there yet. And
++ Fixes for elio.c where fprintf() was called using mis-matched format
++ control chars and srguments.
++
++ M tests/Makefile.am
++ M src/elio.c
++ M Makefile.am
++
++2012-10-26 jgallagher at opendap.org
++
++ Fixes so that the dist target builds a good distribution.
++
++ D tests/Makefile.in
++ D tests/Makefile
++ M tests/Makefile.am
++ M Makefile.am
++
++2012-08-16 smeest1 at gmail.com
++
++ updated Makefile.am
++
++2012-08-10 smeest1 at gmail.com
++
++ fixed cell array
++
++2012-08-10 smeest1 at gmail.com
++
++ fixed array.cc
++
++2012-08-09 smeest1 at gmail.com
++
++ updated clib
++
++2012-08-09 smeest1 at gmail.com
++
++ added triangulate.h
++
++2012-08-09 smeest1 at gmail.com
++
++ added triangulate.cc
++
++2012-08-09 smeest1 at gmail.com
++
++ added remesh.h
++
++2012-08-09 smeest1 at gmail.com
++
++ added remesh.cc
++
++2012-08-09 billhowe
++
++ added tests
++
++2012-08-09 billhowe
++
++ Attempting to commit namespace changes
++
++2012-04-09 smeest1 at gmail.com
++
++ added new stuff to tags and trunk
++
++;; Local Variables:
++;; coding: utf-8
++;; End:
+diff -Nur -x .svn tag/gridfieldsclib-0.7/CmdLine.cpp gridfields/clib/CmdLine.cpp
+--- tag/gridfieldsclib-0.7/CmdLine.cpp 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/CmdLine.cpp 2014-05-16 22:59:45.903388424 +0200
+@@ -81,7 +81,7 @@
+ cmd.m_strings.push_back(arg);
+
+ // add the CCmdParam to 'this'
+- pair<CCmdLine::iterator, bool> res = insert(CCmdLine::value_type(curParam, cmd));
++ // Unused. jhrg 4/4/14 pair<CCmdLine::iterator, bool> res = insert(CCmdLine::value_type(curParam, cmd));
+
+ }
+ else
+diff -Nur -x .svn tag/gridfieldsclib-0.7/conf/netcdf.m4 gridfields/clib/conf/netcdf.m4
+--- tag/gridfieldsclib-0.7/conf/netcdf.m4 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/conf/netcdf.m4 2014-05-16 22:56:56.463391955 +0200
+@@ -56,7 +56,7 @@
+ AC_PATH_PROG([NC_CONFIG], [nc-config], [no])
+ if test "$NC_CONFIG" != "no" ; then
+ nc_ready=yes
+- NC_LIBS="`$NC_CONFIG --libs` -lnetcdf_c++"
++ NC_LIBS="`$NC_CONFIG --libs` -lnetcdf_c++ -lnetcdf"
+ NC_CPPFLAGS="`$NC_CONFIG --cflags`"
+ NC_LDFLAGS="`$NC_CONFIG --cflags`"
+ NC_VERSION="`$NC_CONFIG --version`"
+@@ -121,11 +121,11 @@
+ NC_LDFLAGS="-L$ac_netcdf_libdir"
+ ])
+ LDFLAGS="$LDFLAGS $NC_LDFLAGS"
+- LIBS="$LIBS-lnetcdf_c++- lnetcdf"
++ LIBS="$LIBS-lnetcdf_c++ -lnetcdf"
+ dnl we have to avoid the autoconf internal cache in that case
+ AC_LINK_IFELSE([AC_LANG_CALL([],[$ac_check_nc_func_checked])],
+ [
+- NC_LIBS='-lnetcdf_c++- lnetcdf'
++ NC_LIBS='-lnetcdf_c++ -lnetcdf'
+ ac_netcdf_ok='yes'
+ AS_IF([test "z$ac_netcdf_libdir" != 'z'],[AC_MSG_RESULT([yes])])
+ ],
+diff -Nur -x .svn tag/gridfieldsclib-0.7/configure.ac gridfields/clib/configure.ac
+--- tag/gridfieldsclib-0.7/configure.ac 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/configure.ac 2014-05-16 22:59:46.443388412 +0200
+@@ -2,9 +2,13 @@
+ # Process this file with autoconf to produce a configure script.
+
+ AC_PREREQ([2.68])
+-AC_INIT([gridfields], [1.0.0], [Bill Howe <billhowe at cs.washington.edu>])
++AC_INIT([gridfields], [1.0.3], [Bill Howe <billhowe at cs.washington.edu>])
+ AC_CONFIG_SRCDIR([src/abstractcellarray.h])
+-AM_CONFIG_HEADER([config.h])
++# This has to be named specially since it's included in headers that
++# are installed. The config header defines compile-time switches that
++# select between older (deprecated) versions of hash map and C++'s new
++# unordered_map. jhrg 4/4/14
++AM_CONFIG_HEADER([config_gridfields.h])
+
+ # This provides a place to keep all the autotools stuff (m4 files, etc.)
+ AC_CONFIG_AUX_DIR(conf)
+@@ -32,30 +36,22 @@
+ AC_PROG_LIBTOOL
+
+ dnl echo "CC = $CC"
+-if test "$CC" = "g++"
++if test "$CC" = "g++" -o "$CC" == "gcc"
+ then
+ AM_CONDITIONAL([COMPILER_IS_GCC],[true])
+ else
+ AM_CONDITIONAL([COMPILER_IS_GCC],[false])
+ fi
+
+-# Checks for libraries.
+-# These appear to be used by test code
+-# FIXME: Replace `main' with a function in `-lefence':
+-# AC_CHECK_LIB([efence], [main])
+-# FIXME: Replace `main' with a function in `-lnetcdf':
+-# AC_CHECK_LIB([netcdf], [main])
+-# FIXME: Replace `main' with a function in `-lvtkCommon':
+-# AC_CHECK_LIB([vtkCommon], [main])
+-# FIXME: Replace `main' with a function in `-lvtkFiltering':
+-# AC_CHECK_LIB([vtkFiltering], [main])
+-# FIXME: Replace `main' with a function in `-lvtkIO':
+-# AC_CHECK_LIB([vtkIO], [main])
+-# FIXME: Replace `main' with a function in `-lvtkRendering':
+-# AC_CHECK_LIB([vtkRendering], [main])
+-# FIXME: Replace `main' with a function in `-lwayne':
+-# AC_CHECK_LIB([wayne], [main])
++AC_ARG_ENABLE([netcdf], [AS_HELP_STRING([--enable/disable-netcdf],
++ [use netcdf (default is yes)])], [], [])
++# $enable_netcdf will be 'no' if --disable-netcdf is used, 'yes' if
++# --enable-netcdf is used and '' if neither is used
+
++netcdf_found_ac=false
++
++if test -z "$enable_netcdf" -o "$enable_netcdf" = "yes"
++then
+ AC_CHECK_NETCDF(
+ [
+ LIBS="$LIBS $NC_LIBS"
+@@ -67,10 +63,10 @@
+ echo "*** Use --with-netcdf for the root netcdf directory."
+ echo "*** Otherwise use --with-netcdf-include switch for includes directory"
+ echo "*** and --with-netcdf-libdir switch for libraries directory."
+- netcdf_found_ac=false
+ AC_MSG_WARN([netcdf library and netcdf headers not found.])
+ ],[3]
+ )
++fi
+
+ AM_CONDITIONAL([NETCDF_FOUND], [$netcdf_found_ac])
+
+@@ -97,6 +93,51 @@
+
+ # Checks for typedefs, structures, and compiler characteristics.
+ AC_HEADER_STDBOOL
++
++AC_LANG_PUSH([C++])
++dnl # Do the checks for C++ headers
++
++# <functional> is not needed...
++# AC_HEADER_TR1_FUNCTIONAL
++
++# Look for the old versions, then the new ones and use them in roughly
++# that order. It seems that older compiers include the tr1 or standard
++# headers but they don't always work. It might be that explicitly using
++# C++ 2011 is needed to get the standard headers.
++AC_CHECK_HEADER(ext/hash_map, [AC_DEFINE([HAVE_EXT_HASH_MAP],[],["Have ext"])
++ have_ext_hash_map="yes"
++ AC_MSG_WARN([Found ext/hash map])], [], [])
++
++AC_CHECK_HEADER(tr1/unordered_map, [AC_DEFINE([HAVE_TR1_UNORDERED_MAP],[],["Have tr1"])
++ have_tr1_unordered_map="yes"
++ AC_MSG_WARN([Found tr1/unordered map])], [], [])
++
++AC_CHECK_HEADER(unordered_map, [AC_DEFINE([HAVE_UNORDERED_MAP],[],["Have C++0x"])
++ have_unordered_map="yes"
++ AC_MSG_WARN([Found plain unordered map])], [], [])
++
++AC_LANG_POP([C++])
++
++# These AC_DEFINE calls set values used by a 'glue' header. See
++# gridfields_hash_map.h.in
++if test "x$have_unordered_map" == "xyes"
++then
++ AC_SUBST([GF_UNORDERED_MAP_HEADER], ["<unordered_map>"])
++ AC_SUBST([GF_HASH_MAP], ["std::unordered_map"])
++elif test "x$have_ext_hash_map" == "xyes"
++then
++ AC_SUBST([GF_UNORDERED_MAP_HEADER], ["<ext/hash_map>"])
++ AC_SUBST([GF_HASH_MAP], ["hash_map"])
++ AC_SUBST([GF_HASH_MAP_NAMESPACE], ["namespace GF { using namespace __gnu_cxx; }"])
++ AC_SUBST([GF_USE_REHASH], ["#define USE_HASH_MAP_RESIZE"])
++elif test "x$have_tr1_unordered_map" == "xyes"
++then
++ AC_SUBST([GF_UNORDERED_MAP_HEADER], ["<tr1/unordered_map>"])
++ AC_SUBST([GF_HASH_MAP], ["std::tr1::unordered_map"])
++else
++ AC_MSG_ERROR([Could not find a suitable 'unordered map' c++ class.])
++fi
++
+ AC_C_INLINE
+ AC_TYPE_OFF_T
+ AC_C_RESTRICT
+@@ -110,5 +151,8 @@
+ AC_FUNC_STRTOD
+ AC_CHECK_FUNCS([floor gettimeofday pow putenv sqrt strtol])
+
+-AC_CONFIG_FILES([Makefile tests/Makefile])
++AC_CONFIG_FILES([Makefile src/gridfields_hash_map.h])
++AC_CONFIG_FILES([gridfields-config], [chmod 755 gridfields-config])
++AC_CONFIG_FILES([tests/Makefile tests/testarrayreader.cc \
++ tests/testcross.cc tests/testbind.cc tests/testoutput.cc])
+ AC_OUTPUT
+diff -Nur -x .svn tag/gridfieldsclib-0.7/gridfields-config.in gridfields/clib/gridfields-config.in
+--- tag/gridfieldsclib-0.7/gridfields-config.in 1970-01-01 01:00:00.000000000 +0100
++++ gridfields/clib/gridfields-config.in 2014-05-16 22:56:56.463391955 +0200
+@@ -0,0 +1,83 @@
++#! /bin/sh
++#
++# Borrowed the idea for this script (and some code) from libcurl.
++#
++prefix=@prefix@
++exec_prefix=${prefix}
++libdir=${exec_prefix}/lib
++libdir64=${exec_prefix}/lib64
++includedir=${prefix}/include
++
++usage()
++{
++ cat <<EOF
++Usage: dap-config [OPTION]
++
++Available values for OPTION include:
++
++ --help display this help message and exit
++ --cc C compiler
++ --cxx C++ compiler
++ --cflags pre-processor and compiler flags
++ --libs library linking information for libdap (both clients and servers)
++ --server-libs libraries for servers
++ --client-libs libraries for clients
++ --prefix OPeNDAP install prefix
++ --version Library version
++EOF
++
++ exit $1
++}
++
++if test $# -eq 0; then
++ usage 1
++fi
++
++while test $# -gt 0; do
++ case "$1" in
++ # this deals with options in the style
++ # --option=value and extracts the value part
++ # [not currently used]
++ -*=*) value=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
++ *) value= ;;
++ esac
++
++ case "$1" in
++ --help)
++ usage 0
++ ;;
++
++ --cc)
++ echo "@CC@"
++ ;;
++
++ --cxx)
++ echo "@CXX@"
++ ;;
++
++ --cflags)
++ echo "-I${includedir}/libgridfields"
++ ;;
++
++ --libs)
++ echo "-L${libdir64} -L${libdir} -lgridfields @LIBS@"
++ ;;
++
++ --prefix)
++ echo "${prefix}"
++ ;;
++
++ --version)
++ echo "gridfields @PACKAGE_VERSION@"
++ ;;
++
++ *)
++ echo "unknown option: $1"
++ usage
++ exit 1
++ ;;
++ esac
++ shift
++done
++
++exit 0
+diff -Nur -x .svn tag/gridfieldsclib-0.7/gridfields.spec gridfields/clib/gridfields.spec
+--- tag/gridfieldsclib-0.7/gridfields.spec 1970-01-01 01:00:00.000000000 +0100
++++ gridfields/clib/gridfields.spec 2014-05-16 22:59:46.443388412 +0200
+@@ -0,0 +1,55 @@
++Name: gridfields
++Version: 1.0.3
++Release: 1%{?dist}
++Summary: The Gridfield library implements an algreba for irregular meshes.
++
++Group: Development/Libraries
++License: LGPLv2+
++URL: http://www.opendap.org/
++Source0: http://www.opendap.org/pub/source/gridfields-%{version}.tar.gz
++
++BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
++
++%description
++Written by Bill Howe. Packaged by James Gallagher.
++
++%package devel
++Summary: Development and header files for teh gridfields library
++Group: Development/Libraries
++Requires: %{name} = %{version}-%{release}
++
++%description devel
++This package contains all the files needed to develop applications that
++will use libgridfields.
++
++%prep
++%setup -q
++
++%build
++%configure --disable-static --disable-dependency-tracking
++make %{?_smp_mflags}
++
++%install
++rm -rf $RPM_BUILD_ROOT
++make install DESTDIR=$RPM_BUILD_ROOT INSTALL="%{__install} -p"
++rm $RPM_BUILD_ROOT%{_libdir}/*.la
++
++%clean
++rm -rf $RPM_BUILD_ROOT
++
++%post -p /sbin/ldconfig
++
++%postun -p /sbin/ldconfig
++
++%files
++%defattr(-,root,root,-)
++%{_libdir}/libgridfields.so.*
++%doc README NEWS COPYING
++
++%files devel
++%defattr(-,root,root,-)
++%{_libdir}/libgridfields.so
++%{_includedir}/gridfields/
++%{_bindir}/gridfields-config
++
++%changelog
+diff -Nur -x .svn tag/gridfieldsclib-0.7/Makefile.am gridfields/clib/Makefile.am
+--- tag/gridfieldsclib-0.7/Makefile.am 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/Makefile.am 2014-05-16 22:59:46.446721746 +0200
+@@ -9,19 +9,25 @@
+ AM_CPPFLAGS =
+ AM_CXXFLAGS =
+ if COMPILER_IS_GCC
+-AM_CXXFLAGS += -Wall -W -Wcast-align
++# jhrg 2/13/14
++# I got tired of the sign compare warnings, but they should be
++# addressed. jhrg 4/3/14
++AM_CXXFLAGS += -Wall -Wno-deprecated
++# -Wno-cast-align
++# -Wno-deprecated
++# -Wno-sign-compare
+ endif
+
+ # These are not used by automake but are often useful for certain types of
+ # debugging. The best way to use these is to run configure as:
+ # export CXXFLAGS='...'; ./configure --disable-shared
+ # the --disable-shared is not required, but it seems to help with debuggers.
+-CXXFLAGS_DEBUG = -g3 -O0 -fno-defer-pop -Wall -W -Wcast-align -Werror
++CXXFLAGS_DEBUG = -g3 -O0 -Wall -Wcast-align
+ TEST_COV_FLAGS = -ftest-coverage -fprofile-arcs
+
+-SUBDIRS = tests
++SUBDIRS = . tests
+ # vis
+-DIST_SUBDIRS = tests
++# DIST_SUBDIRS = tests
+ # vis
+
+ # noinst_LTLIBRARIES = libparsers.la
+@@ -29,7 +35,9 @@
+
+ # bin_PROGRAMS =
+
+-# BUILT_SOURCES =
++BUILT_SOURCES = src/gridfields_hash_map.h
++
++bin_SCRIPTS = gridfields-config
+
+ libgridfields_la_SOURCES = $(SRCS)
+ libgridfields_la_LDFLAGS = -version-info $(LIBGF_VERSION)
+@@ -37,11 +45,11 @@
+ libgridfields_la_LIBADD =
+
+ # really?
+-pkginclude_HEADERS = src/$(HDRS)
++pkginclude_HEADERS = $(HDRS)
+
+-noinst_HEADERS = config.h
++# noinst_HEADERS = config.h
+
+-# EXTRA_DIST =
++EXTRA_DIST = gridfields.spec NEWS README INSTALL COPYING
+
+ # At some point write a m4 macro that can be used to test for the
+ # gridfields library; same for pkg config
+@@ -58,39 +66,43 @@
+
+ # MAINTAINERCLEANFILE
+
+-SRCS = CmdLine.cpp src/accumulate.cc src/aggregate.cc src/aggregations.cc src/apply.cc \
+-src/array.cc src/arrayreader.cc src/arraywriter.cc src/assignments.cc src/bind.cc \
+-src/bindconstant.cc src/cell.cc src/cellarray.cc src/constarray.cc src/cross.cc \
+-src/datadump.cc src/dataset.cc src/elcircfile.cc src/elio.c src/expr.cc src/fparser.cc src/grid.cc \
+-src/gridfield.cc src/gridfieldoperator.cc src/implicit0cells.cc \
+-src/merge.cc src/output.cc src/outputtuples.cc src/project.cc \
+-src/rankeddataset.cc src/refrestrict.cc src/restrict.cc src/scaninternal.cc src/sift.cc \
+-src/timing.cc src/tuple.cc src/type.cc src/unarynodemap.cc \
+-src/util.cc
++SRCS = CmdLine.cpp src/accumulate.cc src/aggregate.cc \
++src/aggregations.cc src/apply.cc src/array.cc src/arrayreader.cc \
++src/arraywriter.cc src/assignments.cc src/bind.cc src/bindconstant.cc \
++src/cell.cc src/cellarray.cc src/constarray.cc src/cross.cc \
++src/datadump.cc src/dataset.cc src/elcircfile.cc src/elio.c \
++src/expr.cc src/fparser.cc src/grid.cc src/gridfield.cc \
++src/gridfieldoperator.cc src/implicit0cells.cc src/merge.cc \
++src/output.cc src/outputtuples.cc src/project.cc src/rankeddataset.cc \
++src/refrestrict.cc src/restrict.cc src/scaninternal.cc src/sift.cc \
++src/timing.cc src/tuple.cc src/type.cc src/unarynodemap.cc src/util.cc
+
+ if NETCDF_FOUND
+ SRCS += src/tonetcdf.cc src/netcdfadaptor.cc
+ endif
+
+-HDRS = CmdLine.h src/RTree.h src/abstractcellarray.h src/access.h src/accumulate.h \
+-src/aggregate.h src/aggregations.h src/apply.h src/array.h src/arrayreader.h src/arraywriter.h \
+-src/assignments.h src/binarynodemap.h src/bind.h src/bindconstant.h src/cell.h src/cellarray.h \
+-config.h src/constarray.h src/counted_ptr.h src/cross.h src/crossnodemap.h \
+-src/crossordmap.h src/datadump.h src/dataset.h src/elcircfile.h src/elio.h src/expr.h src/grid.h \
+-src/gridfield.h src/gridfieldoperator.h src/idnodemap.h src/idordmap.h \
+-src/implicit0cells.h src/implicitcrossnodemap.h src/leftnodemap.h src/merge.h \
+-src/nodemap.h src/normnodemap.h src/object.h src/onegrid.h src/ordmap.h \
+-src/output.h src/outputtuples.h src/partition.h src/project.h src/rankeddataset.h \
+-src/refrestrict.h src/restrict.h src/scan.h src/scaninternal.h src/sift.h \
+-src/subgridordmap.h src/timing.h src/tuple.h src/type.h src/unarynodemap.h \
+-src/util.h
++HDRS = config_gridfields.h src/CmdLine.h src/RTree.h \
++src/abstractcellarray.h src/access.h src/accumulate.h src/aggregate.h \
++src/aggregations.h src/apply.h src/array.h src/arrayreader.h \
++src/arraywriter.h src/assignments.h src/binarynodemap.h src/bind.h \
++src/bindconstant.h src/cell.h src/cellarray.h src/constarray.h \
++src/counted_ptr.h src/cross.h src/crossnodemap.h src/crossordmap.h \
++src/datadump.h src/dataset.h src/elcircfile.h src/elio.h src/expr.h \
++src/fparser.hh src/fptypes.hh src/fpconfig.hh src/grid.h \
++src/gridfield.h src/gridfieldoperator.h src/idnodemap.h src/idordmap.h \
++src/implicit0cells.h src/implicitcrossnodemap.h src/leftnodemap.h \
++src/merge.h src/nodemap.h src/normnodemap.h src/object.h src/onegrid.h \
++src/ordmap.h src/output.h src/outputtuples.h src/partition.h \
++src/project.h src/rankeddataset.h src/refrestrict.h src/restrict.h \
++src/scan.h src/scaninternal.h src/sift.h src/subgridordmap.h \
++src/timing.h src/tuple.h src/type.h src/unarynodemap.h src/util.h \
++src/gridfields_hash_map.h
+
+ if NETCDF_FOUND
+ HDRS += src/tonetcdf.h src/netcdfadaptor.h
+ endif
+
+ OLD_REMOVED_SRCS = stuebe.cc
+-
+ OLD_REMOVED_HDRS = stuebe.h
+
+ ###########################################################################
+@@ -103,6 +115,20 @@
+ doxygen $(srcdir)/doxy.conf
+ (cd docs && tar -czf html.tar.gz html)
+
++###########################################################################
++
++# Fortify targets.
++
++.PHONY: fortify
++fortify:
++ sourceanalyzer -b @PACKAGE@ $(MAKE)
++ sourceanalyzer -b @PACKAGE@ -scan -f @PACKAGE at -@PACKAGE_VERSION at .fpr
++
++# Use this to clean the fortify project.
++.PHONY: fortifyclean
++fortifyclean:
++ sourceanalyzer -b @PACKAGE@ -clean
++
+ # cccc computes metrics like Lines of code and McCabe. It'a available
+ # on the web...
+ .PHONY: cccc
+@@ -166,8 +192,8 @@
+ (cd test-coverage; \
+ cov_dat="coverage-data-`date +%m.%d.%y`"; \
+ touch $$cov_dat; \
+- for f in $(ALLSRCS); do \
++ for f in $(libgridfields_la_SOURCES); do \
+ echo "\n*** Coverage data for $$f ***\n" >> $$cov_dat; \
+- gcov -l -o ../ $$f >> $$cov_dat; \
++ gcov -a -o ../ $$f >> $$cov_dat; \
+ done)
+
+diff -Nur -x .svn tag/gridfieldsclib-0.7/NEWS gridfields/clib/NEWS
+--- tag/gridfieldsclib-0.7/NEWS 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/NEWS 2014-05-16 22:59:46.446721746 +0200
+@@ -1 +1,37 @@
+-Version 1.0.0
++Version 1.0.3
++
++Fixed the warnings (many many) that were issued when code used this
++library. Because the library had headers that included the library's
++private 'config.h' header - and many other programs/libraries also
++have a similarly named header with the same symbols defined
++(differently), including that in an installed header often results in
++warnings. I fixed this by adding a special 'glue' header the defined
++just what was needed by the installed header and thus avoided
++including the config.h header in it.
++
++I fixed a number of other 'warning' problems.
++
++Fixed a bug in cellarray.cc where an iterator was used after it was
++invalidated (by calling erase()).
++
++I removed useless includes of the <functional> header (aka
++<tr1/functional) and four instances if "config.h" in headers that are
++installed. Removed the test for tr1/functional in configure.ac.
++
++Version 1.0.2
++
++Updated a handful of files so that a C++-11 compiler won't gag. This
++mostly means adding a compiler check for tr1/functional or functional.
++There is still a problem with etc/hash_map versus the new
++unordered_map. I added a test for unordered_map and use it if
++available. It appears that unordered_map::rehash() is the same as
++hash_map::resize(). the Grid class is abstract but did not declare its
++destructor 'virtual'. All but one test pass and that test fails
++without these changes (testaggregate) with an odd message from the
++linking loader.
++
++Version 1.0.1
++
++Fixed configure.ac so it's possible to suppress building/linking with
++netCDF. To do this, use --disable-netcdf.
++
+diff -Nur -x .svn tag/gridfieldsclib-0.7/README gridfields/clib/README
+--- tag/gridfieldsclib-0.7/README 2012-02-13 17:47:11.000000000 +0100
++++ gridfields/clib/README 2014-05-16 22:59:45.906721757 +0200
+@@ -1,20 +1,60 @@
+ What is Gridfields?
+
+-Scientists' ability to generate and store simulation results is outpacing their ability to analyze them via ad hoc programs. We observe that these programs exhibit an algebraic structure that can be used to facilitate reasoning and improve performance.
++Scientists' ability to generate and store simulation results is
++outpacing their ability to analyze them via ad hoc programs. We
++observe that these programs exhibit an algebraic structure that can be
++used to facilitate reasoning and improve performance.
+
+ GridFields separate topology from data attributes
+
+-In our work on GridFields, we present a formal data model that exposes this algebraic structure, then implement the model, evaluate it, and use it to express, optimize, and reason about data transformations in a variety of scientific domains.
+-
+-Simulation results are defined over a logical grid structure that allows a continuous domain to be represented discretely in the computer. Existing approaches for manipulating these gridded datasets are incomplete. The performance of SQL queries that manipulate large numeric datasets is not competitive with that of specialized tools, and the up-front effort required to deploy a relational database makes them unpopular for dynamic scientific applications. Tools for processing multidimensional arrays can only capture regular, rectilinear grids. Visualization libraries accommodate some forms of unstructured grid, but no algebra has been developed to organize the library of raw algorithms and afford optimization. Further, these libraries are data dependent---physical changes to data characteristics break user programs.
+-
+-The GridFields library exposes 1) topological equivalences among gridded datasets and 2) logical equivalences among grid-oriented programs. These equivalences offer optimization opportunities and simplify programming.
+-
+-We adopt the grid as a first-class citizen, separating topology from geometry and separating structure from data. Our model is agnostic with respect to dimension, uniformly capturing, for example, particle trajectories (1-D), sea-surface temperatures (2-D), and blood flow in the heart (3-D). Equipped with data, a grid becomes a gridfield. We provide operators for constructing, transforming, and aggregating gridfields that admit algebraic laws useful for optimization. We implement the model by analyzing several candidate data structures and incorporating their best features. We then show how to deploy gridfields in practice by injecting the model as middleware between heterogeneous, ad hoc file formats and a popular visualization library.
+-
+-In this project, we define, develop, implement, evaluate and deploy a model of gridded datasets that accommodates a variety of complex grid structures and a variety of complex data products. We evaluate the applicability and performance of the model using datasets from oceanography, seismology, and medicine and conclude that our model-driven approach offers significant advantages over the status quo.
+-
+-Here at CMOP, we use GridFields to implement query services over ocean circulation model results, and we have added a GridFields plugin module for the VisTrails provenance and visualization system.
++In our work on GridFields, we present a formal data model that exposes
++this algebraic structure, then implement the model, evaluate it, and
++use it to express, optimize, and reason about data transformations in
++a variety of scientific domains.
++
++Simulation results are defined over a logical grid structure that
++allows a continuous domain to be represented discretely in the
++computer. Existing approaches for manipulating these gridded datasets
++are incomplete. The performance of SQL queries that manipulate large
++numeric datasets is not competitive with that of specialized tools,
++and the up-front effort required to deploy a relational database makes
++them unpopular for dynamic scientific applications. Tools for
++processing multidimensional arrays can only capture regular,
++rectilinear grids. Visualization libraries accommodate some forms of
++unstructured grid, but no algebra has been developed to organize the
++library of raw algorithms and afford optimization. Further, these
++libraries are data dependent---physical changes to data
++characteristics break user programs.
++
++The GridFields library exposes 1) topological equivalences among
++gridded datasets and 2) logical equivalences among grid-oriented
++programs. These equivalences offer optimization opportunities and
++simplify programming.
++
++We adopt the grid as a first-class citizen, separating topology from
++geometry and separating structure from data. Our model is agnostic
++with respect to dimension, uniformly capturing, for example, particle
++trajectories (1-D), sea-surface temperatures (2-D), and blood flow in
++the heart (3-D). Equipped with data, a grid becomes a gridfield. We
++provide operators for constructing, transforming, and aggregating
++gridfields that admit algebraic laws useful for optimization. We
++implement the model by analyzing several candidate data structures and
++incorporating their best features. We then show how to deploy
++gridfields in practice by injecting the model as middleware between
++heterogeneous, ad hoc file formats and a popular visualization
++library.
++
++In this project, we define, develop, implement, evaluate and deploy a
++model of gridded datasets that accommodates a variety of complex grid
++structures and a variety of complex data products. We evaluate the
++applicability and performance of the model using datasets from
++oceanography, seismology, and medicine and conclude that our
++model-driven approach offers significant advantages over the status
++quo.
++
++Here at CMOP, we use GridFields to implement query services over ocean
++circulation model results, and we have added a GridFields plugin
++module for the VisTrails provenance and visualization system.
+
+
+ Directory Structure:
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/abstractcellarray.h gridfields/clib/src/abstractcellarray.h
+--- tag/gridfieldsclib-0.7/src/abstractcellarray.h 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/abstractcellarray.h 2014-05-16 22:57:00.733391866 +0200
+@@ -1,5 +1,5 @@
+ #ifndef _ABSTRACTCELLARRAY_H
+-#define _ABSTRACTCELLARRAY_H
++#define _ABSTRACTCELLARRAY_H
+
+ #include <vector>
+ #include <set>
+@@ -8,52 +8,67 @@
+ #include "util.h"
+ #include "object.h"
+
+-
+-using namespace __gnu_cxx;
+ using namespace std;
+
++namespace GF {
++
+ class UnaryNodeMap;
+ class CrossNodeMap;
+
+-class AbstractCellArray : public Object {
+- public:
+-
+- virtual idx getsize()=0;
+- virtual ~AbstractCellArray() {};
+-
+- virtual int whoami()=0;
+-
+- virtual Cell *getCell(idx i)=0;
+- virtual Cell getCellCopy(idx i)=0;
+- virtual Node *getCellNodes(idx i)=0;
+-
+- virtual bool contains(const Cell &c)=0;
+- virtual idx getOrd(const Cell &c)=0;
+- virtual idx getOrd(Node n)=0;
+- virtual unsigned int getNodeCount()=0;
+-
+- virtual void getIncidentCells(Node n, set<CellId> &out)=0;
+- virtual void getIncidentCells(const Cell &c, set<CellId> &out)=0;
+- virtual void getAdjacentCells(CellId cid, vector<CellId> &out)=0;
+-
+- virtual void print(size_t indent)=0;
+- virtual void print()=0;
+-
+- virtual void toNodeSet(set<Node> &outset)=0;
+- virtual CrossNodeMap makeCrossNodeMap(AbstractCellArray *other)=0;
+-
+- virtual void mapNodes(UnaryNodeMap &h)=0;
+- bool implicit() { return false; };
+- virtual int bytes()=0;
+-
+- virtual AbstractCellArray *Intersection(AbstractCellArray *othercells)=0;
+- virtual AbstractCellArray *Cross(AbstractCellArray *othercells, CrossNodeMap &h)=0;
++class AbstractCellArray: public Object {
++public:
+
+- virtual void ref() { };
+- virtual void unref() { };
++ virtual idx getsize()=0;
++ virtual ~AbstractCellArray()
++ {
++ }
++ ;
++
++ virtual int whoami()=0;
++
++ virtual Cell *getCell(idx i)=0;
++ virtual Cell getCellCopy(idx i)=0;
++ virtual Node *getCellNodes(idx i)=0;
++
++ virtual bool contains(const Cell &c)=0;
++ virtual idx getOrd(const Cell &c)=0;
++ virtual idx getOrd(Node n)=0;
++ virtual unsigned int getNodeCount()=0;
++
++ virtual void getIncidentCells(Node n, set<CellId> &out)=0;
++ virtual void getIncidentCells(const Cell &c, set<CellId> &out)=0;
++ virtual void getAdjacentCells(CellId cid, vector<CellId> &out)=0;
++
++ virtual void print(size_t indent)=0;
++ virtual void print()=0;
++
++ virtual void toNodeSet(set<Node> &outset)=0;
++ virtual CrossNodeMap makeCrossNodeMap(AbstractCellArray *other)=0;
++
++ virtual void mapNodes(UnaryNodeMap &h)=0;
++ bool implicit()
++ {
++ return false;
++ }
++ ;
++ virtual int bytes()=0;
++
++ virtual AbstractCellArray *Intersection(AbstractCellArray *othercells)=0;
++ virtual AbstractCellArray *Cross(AbstractCellArray *othercells, CrossNodeMap &h)=0;
++
++ virtual void ref()
++ {
++ }
++ ;
++ virtual void unref()
++ {
++ }
++ ;
+
+- virtual void buildInvertedIndex()=0;
+- virtual vector<Cell> *getCellVector()=0;
++ virtual void buildInvertedIndex()=0;
++ virtual vector<Cell> *getCellVector()=0;
+ };
+
+-#endif
++} // namespace GF
++
++#endif
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/access.h gridfields/clib/src/access.h
+--- tag/gridfieldsclib-0.7/src/access.h 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/access.h 2014-05-16 22:57:00.763391866 +0200
+@@ -4,160 +4,223 @@
+ #include "object.h"
+ #include "util.h"
+ #include <fcntl.h>
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/mman.h>
+
++namespace GF {
++
+ typedef char Byte;
+
+ template<class T>
+ class DatumIterator {
+- public:
+- typedef T Datum_t;
+- virtual void Open()=0;
+- virtual Datum_t Next()=0;
+- virtual bool Done()=0;
+- //virtual ~DatumIterator()=0;
++public:
++ typedef T Datum_t;
++ virtual void Open()=0;
++ virtual Datum_t Next()=0;
++ virtual bool Done()=0;
++ //virtual ~DatumIterator()=0;
++ virtual ~DatumIterator()
++ {
++ } // jhrg 4/8/14
+ };
+
+ template<class T>
+-class CArrayIterator : public DatumIterator<T> {
+- public:
+- CArrayIterator(T *s, size_t sz) : source(s), size(sz), i(0) {};
+- void Open() {};
+- T Next() { return source[i++]; }
+- bool Done() { return (i>=size); }
+-
+- private:
+- T *source;
+- size_t size;
+- idx i;
++class CArrayIterator: public DatumIterator<T> {
++public:
++ CArrayIterator(T *s, size_t sz) :
++ source(s), size(sz), i(0)
++ {
++ }
++ ;
++ void Open()
++ {
++ }
++ ;
++ T Next()
++ {
++ return source[i++];
++ }
++ bool Done()
++ {
++ return (i >= size);
++ }
++
++private:
++ T *source;
++ size_t size;
++ idx i;
+ };
+
+ template<class T>
+-class SliceIterator : public DatumIterator<T> {
+- public:
+- SliceIterator(DatumIterator<T> &b, idx start, idx stop, idx step=1)
+- : _start(start), _step(step), _stop(stop), i(0), base(b) {};
+-
+- virtual void Open() {
+- base.Open();
+- for (int j=_start; j>0; j--) base.Next();
+- };
+-
+- virtual T Next() {
+- T d = base.Next();
+-
+- // advance to just before first element
+- idx next = MIN(_start+i*_step, _stop);
+- for (int j=_step-1; j>0; j--) base.Next();
+- i++;
+- return d;
+- };
+-
+- virtual bool Done() {
+- return (_start + i*_step >= _stop) || (base.Done());
+- };
+-
+- private:
+- idx _start, _step, _stop;
+- idx i;
+- DatumIterator<T> &base;
++class SliceIterator: public DatumIterator<T> {
++public:
++ SliceIterator(DatumIterator<T> &b, idx start, idx stop, idx step = 1) :
++ _start(start), _step(step), _stop(stop), i(0), base(b)
++ {
++ }
++ ;
++
++ virtual void Open()
++ {
++ base.Open();
++ for (int j = _start; j > 0; j--)
++ base.Next();
++ }
++ ;
++
++ virtual T Next()
++ {
++ T d = base.Next();
++
++ // advance to just before first element
++ // Unused. jhrg 4/4/14 idx next = MIN(_start+i*_step, _stop);
++ for (int j = _step - 1; j > 0; j--)
++ base.Next();
++ i++;
++ return d;
++ }
++ ;
++
++ virtual bool Done()
++ {
++ return (_start + i * _step >= _stop) || (base.Done());
++ }
++ ;
++
++private:
++ idx _start, _step, _stop;
++ idx i;
++ DatumIterator<T> &base;
+ };
+
+ template<class T>
+-class PrimitiveIterator : public DatumIterator<T> {
+- public:
+- PrimitiveIterator(DatumIterator<Byte> &b) : base(b) {};
+-
+- void Open() { base.Open(); }
+-
+- T Next() {
+- for (int i=0; i<sizeof(T); i++) {
+- buf[i] = base.Next();
+- }
+- return *(T *) buf;
+- };
+-
+- bool Done() { return base.Done(); };
+-
+- private:
+- Byte buf[sizeof(T)];
+- DatumIterator<Byte> &base;
++class PrimitiveIterator: public DatumIterator<T> {
++public:
++ PrimitiveIterator(DatumIterator<Byte> &b) :
++ base(b)
++ {
++ }
++ ;
++
++ void Open()
++ {
++ base.Open();
++ }
++
++ T Next()
++ {
++ for (int i = 0; i < sizeof(T); i++) {
++ buf[i] = base.Next();
++ }
++ return *(T *) buf;
++ }
++ ;
++
++ bool Done()
++ {
++ return base.Done();
++ }
++ ;
++
++private:
++ Byte buf[sizeof(T)];
++ DatumIterator<Byte> &base;
+ };
+ /*
+-template
+-class ProjectIterator : public DatumIterator<Byte *> {
+- public:
+- ProjectIterator(DatumIterator
+-}
+-*/
+-
+-class MMapIterator : public DatumIterator<Byte> {
+- public:
+- MMapIterator(const std::string &fname, int off, int len)
+- : i(off), end(len), filename(fname) {};
+-
+- MMapIterator(const std::string &fname, int off=0)
+- : i(off), end(-1), filename(fname) {}
+-
+- void Open() {
+-
+- struct stat sbuf;
+- if ((fd = open(filename.c_str(), O_RDONLY)) == -1) {
+- perror("Open");
+- exit(1);
+- }
+-
+- if (stat(filename.c_str(), &sbuf) == -1) {
+- perror("Stat");
+- exit(1);
+- }
+-
++ template
++ class ProjectIterator : public DatumIterator<Byte *> {
++ public:
++ ProjectIterator(DatumIterator
++ }
++ */
++
++class MMapIterator: public DatumIterator<Byte> {
++public:
++ MMapIterator(const std::string &fname, int off, int len) :
++ i(off), end(len), filename(fname)
++ {
++ }
++
++ MMapIterator(const std::string &fname, int off = 0) :
++ i(off), end(-1), filename(fname)
++ {
++ }
++
++ ~MMapIterator()
++ {
++ }
++
++ void Open()
++ {
++
++ struct stat sbuf;
++ if ((fd = open(filename.c_str(), O_RDONLY)) == -1) {
++ perror("Open");
++ exit(1);
++ }
++
++ if (stat(filename.c_str(), &sbuf) == -1) {
++ perror("Stat");
++ exit(1);
++ }
++
+ #if 0
+- // 'end' is unsigned. jhrg 10/5/11
+- if (end<0) end = sbuf.st_size;
++ // 'end' is unsigned. jhrg 10/5/11
++ if (end<0) end = sbuf.st_size;
+ #endif
+- if ((data = (char *) mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED,
+- fd, 0)) == (caddr_t)(-1)) {
+- perror("mmap");
+- exit(1);
+- }
+-
+- }
+-
+- void Advance(idx n) { i+=n; }
+-
+- Byte Next() { return data[i++]; }
+-
+- bool Done() { return i>=end; }
+-
+- private:
+- idx i;
+- idx end;
+- const std::string filename;
+- int fd;
+- Byte *data;
++ if ((data = (char *) mmap((caddr_t) 0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t) (-1)) {
++ perror("mmap");
++ exit(1);
++ }
++
++ }
++
++ void Advance(idx n)
++ {
++ i += n;
++ }
++
++ Byte Next()
++ {
++ return data[i++];
++ }
++
++ bool Done()
++ {
++ return i >= end;
++ }
++
++private:
++ idx i;
++ idx end;
++ const std::string filename;
++ int fd;
++ Byte *data; // Assuming this is a weak pointer and should not be freed. jhrg 4/8/14
+ };
+ /*
+-template<class T>
+-class ElcircSurfIterator : public DatumIterator<T> {
+- public:
+- ElcircSurfIterator(MMapIterator mi, ElcircHeader &h) : hdr(h), rdr(mi) {};
+- void Open() {
+- offset = this->h.hsize + timestep*this->h.ssize + sizeof(int) + sizeof(float);
+- end =
+- rdr.Advance(offset);
+- // pi = new PrimitiveIterator<T>(rdr)
+- }
+-
+- T Next() { return rdr.Next(); };
+- bool Done() { return (i>=end); }
+-
+- private:
+- idx end,offset;
+- ElcircHeader &hdr;
+- MMapIterator &rdr;
+-}
+-*/
++ template<class T>
++ class ElcircSurfIterator : public DatumIterator<T> {
++ public:
++ ElcircSurfIterator(MMapIterator mi, ElcircHeader &h) : hdr(h), rdr(mi) {};
++ void Open() {
++ offset = this->h.hsize + timestep*this->h.ssize + sizeof(int) + sizeof(float);
++ end =
++ rdr.Advance(offset);
++ // pi = new PrimitiveIterator<T>(rdr)
++ }
++
++ T Next() { return rdr.Next(); };
++ bool Done() { return (i>=end); }
++
++ private:
++ idx end,offset;
++ ElcircHeader &hdr;
++ MMapIterator &rdr;
++ }
++ */
++
++} // namespace GF
++
+ #endif
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/accumulate.cc gridfields/clib/src/accumulate.cc
+--- tag/gridfieldsclib-0.7/src/accumulate.cc 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/accumulate.cc 2014-05-16 22:57:00.803391865 +0200
+@@ -1,3 +1,5 @@
++#include "config_gridfields.h"
++
+ #include "accumulate.h"
+ #include "fparser.hh"
+ #include "gridfield.h"
+@@ -8,195 +10,188 @@
+ #include <vector>
+ #include <math.h>
+
+-AccumulateOp::AccumulateOp(GridFieldOperator *op, Dim_t k,
+- string acc,
+- string ex,
+- string sdex)
+- : UnaryGridFieldOperator(op), position_offset(0), _k(k)
+-{
+- this->PreviousOp = op;
+- this->_accumulator = acc;
+- this->unparsedExpr = ex;
+- this->seedExpr = sdex;
+- this->GF = NULL;
+- // this->cleanup = false;
+-}
+-
+-void AccumulateOp::SetOffset(int off) {
+- this->position_offset = off;
+-}
+-
+-void AccumulateOp::Execute() {
+- this->PrepareForExecution();
+- this->Result = Accumulate(this->GF, this->_k,
+- this->_accumulator,
+- this->unparsedExpr,
+- this->seedExpr,
+- this->position_offset);
+-}
+-
+-
+-GridField *AccumulateOp::Accumulate(GridField *Gg, Dim_t k,
+- string accumulator,
+- string expr,
+- string seedexpr,
+- int offset) {
+-
+- FunctionParser fp;
+- FunctionParser seedfp;
+- expr = remove_whitespace(expr);
+-
+- vector<string> vars = getVars(expr);
+- vector<string> seedvars = getVars(seedexpr);
+- int card = Gg->Size(k);
+-
+- // check existence of the variables in the expression
+- for (unsigned int j=0; j<vars.size(); j++) {
+- if ( !Gg->IsAttribute(k, vars[j]) &&
+- !(vars[j] == accumulator)) {
+- Warning("Accumulate(%s): %s is not an attribute of this Gridfield.",
+- expr.c_str(), vars[j].c_str());
+- Gg->GetScheme(k).print();
+- return Gg;
+- }
+- }
+-
+- // check the seed expression
+- for (unsigned int j=0; j<seedvars.size(); j++) {
+- if ( !Gg->IsAttribute(k, seedvars[j])) {
+- Warning("Accumulate(%s): %s is not an attribute of this Gridfield.",
+- expr.c_str(), seedvars[j].c_str());
+- Gg->GetScheme(k).print();
+- return Gg;
+- }
+- }
+-
+- // parse the expression
+- string varstr = getVarStr(vars);
+- if (fp.Parse(expr, varstr) != -1) {
+- Warning("Parse error: %s: '%s' \% (%s) ",
+- fp.ErrorMsg(),
+- expr.c_str(),
+- varstr.c_str());
+- return Gg;
+- }
+-
+- //parse the seed expression
+- string seedvarstr = getVarStr(seedvars);
+- if (seedfp.Parse(seedexpr, seedvarstr) != -1) {
+- Warning("Parse error: %s: %s",
+- seedexpr.c_str(), seedfp.ErrorMsg());
+- return Gg;
+- }
+-
+- // Evaluate the expression on the GF's attributes
+- double *varVals = new double[vars.size()];
+- double *seedVarVals = new double[seedvars.size()];
+- float *accumulated = new float[card];
+-
+- //set the initial value of the new attribute
+- for (unsigned int j=0; j<seedvars.size(); j++) {
+- seedVarVals[j] = AccumulateOp::bindVar(Gg, k, vars[j], 0);
+- }
+-
+- int start = MIN(card, MAX(-offset, 1));
+- int end = MIN(-offset+card, card);
+-
+- //set the first -<offset> values to the seed (if offset negative)
+- float seed = (float) seedfp.Eval(seedVarVals);
+- for (int i=0; i<start; i++) {
+- accumulated[i] = seed;
+- }
+-
+- //set the last |offset| values to the seed (if offset positive)
+- for (int i=end; i<card; i++) {
+- accumulated[i] = seed;
+- }
+-
+- Scheme s = Gg->GetScheme(k);
+- //Tuple t(&s);
+- //set the rest of the values
+- for (int i=start; i<end; i++) {
+- //Gg->FastBindTuple(i, t);
+-
+- for (unsigned int j=0; j<vars.size(); j++) {
+-
+- if (vars[j] == accumulator) {
+- //previous accumulated value
+- varVals[j] = accumulated[i-1];
+- } else {
+- //regular value from the gridfield
+- varVals[j] = AccumulateOp::bindVar(Gg, k, vars[j], i+offset);
+- }
+-
+- }
+- accumulated[i] = (float) fp.Eval(varVals);
+- }
+-
+- //append the new attribute to the output gridfield
+- Array *arrResult = new Array(
+- (const char *) accumulator.c_str(), FLOAT);
+- arrResult->copyFloatData(accumulated, card);
+- delete [] accumulated;
+- Gg->Bind(k, arrResult);
+- arrResult->unref();
+- Gg->ref();
+- return Gg;
+-
+-}
+-
+-double AccumulateOp::bindVar(GridField *Gg, Dim_t k, string var, int i) {
+- //bind a variable to the ith value of the gridfield
+- //attribute with the same name
+- Scheme sch = Gg->GetScheme(k);
+- double val = 0;
+- if (sch.getType(var) == INT) {
+- val = double(*(int *)
+- Gg->GetAttributeValue(k, var, i));
+- } else {
+- val = double(*(float *)
+- Gg->GetAttributeValue(k, var, i));
+-
+- }
+- return val;
+-}
+-string AccumulateOp::getVarStr(vector<string> varlist) {
+- if (varlist.size() == 0) return "";
+- string retval(varlist[0]);
+- for (size_t i=1; i<varlist.size(); i++) {
+- retval = retval + "," + varlist[i];
+- }
+- return retval;
+-}
+-
+-string getVar(string &expr, size_t &i) {
+- string var = "";
+- while (isalpha(expr[i]) || expr[i] == '_' || isdigit(expr[i])) {
+- var = var + expr[i++];
+- }
+- return var;
+-}
+-
+-vector<string> AccumulateOp::getVars(string expr) {
+- set<string> vars;
+- size_t i=0;
+-
+- while (i<expr.length()) {
+- if (isalpha(expr[i])) {
+- vars.insert(getVar(expr, i));
+- } else if (expr[i] == '_') {
+-
+- }
+- i++;
+- }
+-
+- vector<string> retval(vars.size());
+- set<string>::iterator p;
+-
+- for (p=vars.begin(), i=0; p!=vars.end(); i++,p++) {
+- retval[i] = *p;
+- }
++namespace GF {
++
++AccumulateOp::AccumulateOp(GridFieldOperator *op, Dim_t k, string acc, string ex, string sdex) :
++ UnaryGridFieldOperator(op), position_offset(0), _k(k)
++{
++ this->PreviousOp = op;
++ this->_accumulator = acc;
++ this->unparsedExpr = ex;
++ this->seedExpr = sdex;
++ this->GF = NULL;
++ // this->cleanup = false;
++}
++
++void AccumulateOp::SetOffset(int off)
++{
++ this->position_offset = off;
++}
++
++void AccumulateOp::Execute()
++{
++ this->PrepareForExecution();
++ this->Result = Accumulate(this->GF, this->_k, this->_accumulator, this->unparsedExpr, this->seedExpr,
++ this->position_offset);
++}
++
++GridField *AccumulateOp::Accumulate(GridField *Gg, Dim_t k, string accumulator, string expr, string seedexpr,
++ int offset)
++{
++
++ FunctionParser fp;
++ FunctionParser seedfp;
++ expr = remove_whitespace(expr);
++
++ vector<string> vars = getVars(expr);
++ vector<string> seedvars = getVars(seedexpr);
++ int card = Gg->Size(k);
++
++ // check existence of the variables in the expression
++ for (unsigned int j = 0; j < vars.size(); j++) {
++ if (!Gg->IsAttribute(k, vars[j]) && !(vars[j] == accumulator)) {
++ Warning("Accumulate(%s): %s is not an attribute of this Gridfield.", expr.c_str(), vars[j].c_str());
++ Gg->GetScheme(k).print();
++ return Gg;
++ }
++ }
++
++ // check the seed expression
++ for (unsigned int j = 0; j < seedvars.size(); j++) {
++ if (!Gg->IsAttribute(k, seedvars[j])) {
++ Warning("Accumulate(%s): %s is not an attribute of this Gridfield.", expr.c_str(), seedvars[j].c_str());
++ Gg->GetScheme(k).print();
++ return Gg;
++ }
++ }
++
++ // parse the expression
++ string varstr = getVarStr(vars);
++ if (fp.Parse(expr, varstr) != -1) {
++ Warning("Parse error: %s: '%s' \% (%s) ", fp.ErrorMsg(), expr.c_str(), varstr.c_str());
++ return Gg;
++ }
++
++ //parse the seed expression
++ string seedvarstr = getVarStr(seedvars);
++ if (seedfp.Parse(seedexpr, seedvarstr) != -1) {
++ Warning("Parse error: %s: %s", seedexpr.c_str(), seedfp.ErrorMsg());
++ return Gg;
++ }
++
++ // Evaluate the expression on the GF's attributes
++ double *varVals = new double[vars.size()];
++ double *seedVarVals = new double[seedvars.size()];
++ float *accumulated = new float[card];
++
++ //set the initial value of the new attribute
++ for (unsigned int j = 0; j < seedvars.size(); j++) {
++ seedVarVals[j] = AccumulateOp::bindVar(Gg, k, vars[j], 0);
++ }
++
++ int start = MIN(card, MAX(-offset, 1));
++ int end = MIN(-offset+card, card);
++
++ //set the first -<offset> values to the seed (if offset negative)
++ float seed = (float) seedfp.Eval(seedVarVals);
++ for (int i = 0; i < start; i++) {
++ accumulated[i] = seed;
++ }
++
++ //set the last |offset| values to the seed (if offset positive)
++ for (int i = end; i < card; i++) {
++ accumulated[i] = seed;
++ }
++
++ Scheme s = Gg->GetScheme(k);
++ //Tuple t(&s);
++ //set the rest of the values
++ for (int i = start; i < end; i++) {
++ //Gg->FastBindTuple(i, t);
++
++ for (unsigned int j = 0; j < vars.size(); j++) {
++
++ if (vars[j] == accumulator) {
++ //previous accumulated value
++ varVals[j] = accumulated[i - 1];
++ }
++ else {
++ //regular value from the gridfield
++ varVals[j] = AccumulateOp::bindVar(Gg, k, vars[j], i + offset);
++ }
++
++ }
++ accumulated[i] = (float) fp.Eval(varVals);
++ }
++
++ //append the new attribute to the output gridfield
++ Array *arrResult = new Array((const char *) accumulator.c_str(), FLOAT);
++ arrResult->copyFloatData(accumulated, card);
++ delete[] accumulated;
++ Gg->Bind(k, arrResult);
++ arrResult->unref();
++ Gg->ref();
++ return Gg;
++
++}
++
++double AccumulateOp::bindVar(GridField *Gg, Dim_t k, string var, int i)
++{
++ //bind a variable to the ith value of the gridfield
++ //attribute with the same name
++ Scheme sch = Gg->GetScheme(k);
++ double val = 0;
++ if (sch.getType(var) == INT) {
++ val = double(*(int *) Gg->GetAttributeValue(k, var, i));
++ }
++ else {
++ val = double(*(float *) Gg->GetAttributeValue(k, var, i));
++
++ }
++ return val;
++}
++string AccumulateOp::getVarStr(vector<string> varlist)
++{
++ if (varlist.size() == 0) return "";
++ string retval(varlist[0]);
++ for (size_t i = 1; i < varlist.size(); i++) {
++ retval = retval + "," + varlist[i];
++ }
++ return retval;
++}
++
++string getVar(string &expr, size_t &i)
++{
++ string var = "";
++ while (isalpha(expr[i]) || expr[i] == '_' || isdigit(expr[i])) {
++ var = var + expr[i++];
++ }
++ return var;
++}
++
++vector<string> AccumulateOp::getVars(string expr)
++{
++ set<string> vars;
++ size_t i = 0;
++
++ while (i < expr.length()) {
++ if (isalpha(expr[i])) {
++ vars.insert(getVar(expr, i));
++ }
++ else if (expr[i] == '_') {
++
++ }
++ i++;
++ }
++
++ vector<string> retval(vars.size());
++ set<string>::iterator p;
++
++ for (p = vars.begin(), i = 0; p != vars.end(); i++, p++) {
++ retval[i] = *p;
++ }
+
+- return retval;
++ return retval;
+ }
+
++} // namespace GF
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/accumulate.h gridfields/clib/src/accumulate.h
+--- tag/gridfieldsclib-0.7/src/accumulate.h 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/accumulate.h 2014-05-16 22:57:00.810058531 +0200
+@@ -4,38 +4,42 @@
+ #include "gridfieldoperator.h"
+ #include <string>
+ #include <vector>
+-#include <ext/functional>
++// #include <functional>
++// Replaced tr1 functional. Removed include of config.h in a header.
++// jhrg 4/3/14
++// #ifdef HAVE_TR1_FUNCTIONAL
++// #include <tr1/functional>
++// #endif
++// old code jhrg #include <ext/functional>
+ #include "cell.h"
+
++namespace GF {
++
+ class FunctionParser;
+ class GridField;
+
+-class AccumulateOp : public UnaryGridFieldOperator {
+- public:
+-
+- AccumulateOp(GridFieldOperator *op, Dim_t k,
+- std::string acc,
+- std::string ex,
+- std::string sdex);
+-
+- void Execute();
+- static GridField *Accumulate(GridField *Gg, Dim_t k,
+- std::string resultname,
+- std::string expr,
+- std::string seedexpr,
+- int offset);
+-
+- void SetOffset(int off);
+- int position_offset;
+- private:
+- Dim_t _k;
+- std::string unparsedExpr;
+- std::string _accumulator;
+- std::string seedExpr;
+-
+- static std::vector<std::string> getVars(std::string expr);
+- static std::string getVarStr(std::vector<std::string> varlist);
+- static double bindVar(GridField *Gg, Dim_t k, std::string var, int i);
++class AccumulateOp: public UnaryGridFieldOperator {
++public:
++
++ AccumulateOp(GridFieldOperator *op, Dim_t k, std::string acc, std::string ex, std::string sdex);
++
++ void Execute();
++ static GridField *Accumulate(GridField *Gg, Dim_t k, std::string resultname, std::string expr, std::string seedexpr,
++ int offset);
++
++ void SetOffset(int off);
++ int position_offset;
++private:
++ Dim_t _k;
++ std::string unparsedExpr;
++ std::string _accumulator;
++ std::string seedExpr;
++
++ static std::vector<std::string> getVars(std::string expr);
++ static std::string getVarStr(std::vector<std::string> varlist);
++ static double bindVar(GridField *Gg, Dim_t k, std::string var, int i);
+ };
+
++} // namespace GF
++
+ #endif /* ACCUMULATE_H */
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/aggregate.cc gridfields/clib/src/aggregate.cc
+--- tag/gridfieldsclib-0.7/src/aggregate.cc 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/aggregate.cc 2014-05-16 22:57:00.753391866 +0200
+@@ -1,109 +1,110 @@
++#include "config_gridfields.h"
++
+ #include "aggregate.h"
+ #include "timing.h"
+ #include <math.h>
+ #include "array.h"
+
+-void debug_set(UnTypedPtr p) {
+- vector<Tuple *> *vec = (vector<Tuple *> *) p;
+- cout << "debug_set: " << vec << ", " << vec->size() << endl;
+- vector<Tuple *>::iterator i;
+- for (i=vec->begin(); i!=vec->end(); i++) {
+- (*i)->print();
+- }
++namespace GF {
++
++void debug_set(UnTypedPtr p)
++{
++ vector<Tuple *> *vec = (vector<Tuple *> *) p;
++ cout << "debug_set: " << vec << ", " << vec->size() << endl;
++ vector<Tuple *>::iterator i;
++ for (i = vec->begin(); i != vec->end(); i++) {
++ (*i)->print();
++ }
+ }
+
+-AggregateOp::AggregateOp(GridFieldOperator *T, Dim_t i,
+- AssignmentFunction *m,
+- AggregationFunction *f,
+- GridFieldOperator *S, Dim_t j) {
+- this->A = NULL;
+- this->B = NULL;
+- this->LeftOp = T;
+- this->RightOp = S;
+- this->_i = i;
+- this->_j = j;
+- this->m = m;
+- this->f = f;
++AggregateOp::AggregateOp(GridFieldOperator *T, Dim_t i, AssignmentFunction *m, AggregationFunction *f,
++ GridFieldOperator *S, Dim_t j)
++{
++ this->A = NULL;
++ this->B = NULL;
++ this->LeftOp = T;
++ this->RightOp = S;
++ this->_i = i;
++ this->_j = j;
++ this->m = m;
++ this->f = f;
+ }
+
+-void AggregateOp::Execute() {
+- this->PrepareForExecution();
+- Result = Aggregate(this->A,
+- this->_i,
+- *this->m,
+- *this->f,
+- this->B,
+- this->_j);
++void AggregateOp::Execute()
++{
++ this->PrepareForExecution();
++ Result = Aggregate(this->A, this->_i, *this->m, *this->f, this->B, this->_j);
+ }
+
+-GridField *AggregateOp::Aggregate(GridField *Tt, Dim_t _i,
+- AssignmentFunction &m,
+- AggregationFunction &f,
+- GridField *Ss, Dim_t _j) {
+- Grid *T = Tt->GetGrid();
+- Grid *S = Ss->GetGrid();
+- int j;
+-
+- string gname = newName(T->name, S->name);
+-
+- GridField *Out;
+- Out = new GridField(Tt);
+-
+- Scheme *ssch = new Scheme(Ss->GetScheme(_j));
+-
+- f.setScheme(ssch);
+-
+- //allocate space for any new attributes being created.
+- Scheme *outscheme = f.getOutScheme();
+- //cout << "scheme: " << Tt->GetGrid()->Size(_i) << endl;
+- Out->CoerceScheme(_i, outscheme, Tt->GetGrid()->Size(_i));
+- Scheme finalscheme = Out->GetScheme(_i);
+-
+- m.setEnvironment(Out, _i, Ss, _j);
+-
+- vector<CellId> cs;
+- vector<Tuple> vs;
+-
+- vector<Tuple>::iterator tp;
+- vector<CellId>::iterator cp;
+-
+- //target tuple holder
+- Tuple t(&finalscheme);
+- //source tuple holder
+- Tuple s(ssch);
+-
+- const Dataset &ds = Out->GetDataset(_i);
+- const Dataset &sourceds = Ss->GetDataset(_j);
+-
+- for (size_t i=0; i<Out->Size(_i); i++) {
+- m(i, cs);
+-
+- if (vs.size() != cs.size()) {
+- vs.resize(cs.size(), s);
+- }
+-
+- j=0;
+- FOR(vector<CellId>, c, cs) {
+- sourceds.FastBindTuple(*c, vs[j++]);
+- }
++GridField *AggregateOp::Aggregate(GridField *Tt, Dim_t _i, AssignmentFunction &m, AggregationFunction &f, GridField *Ss,
++ Dim_t _j)
++{
++ Grid *T = Tt->GetGrid();
++ Grid *S = Ss->GetGrid();
++ int j;
++
++ string gname = newName(T->name, S->name);
++
++ GridField *Out;
++ Out = new GridField(Tt);
++
++ Scheme *ssch = new Scheme(Ss->GetScheme(_j));
++
++ f.setScheme(ssch);
++
++ //allocate space for any new attributes being created.
++ Scheme *outscheme = f.getOutScheme();
++ //cout << "scheme: " << Tt->GetGrid()->Size(_i) << endl;
++ Out->CoerceScheme(_i, outscheme, Tt->GetGrid()->Size(_i));
++ Scheme finalscheme = Out->GetScheme(_i);
++
++ m.setEnvironment(Out, _i, Ss, _j);
++
++ vector<CellId> cs;
++ vector<Tuple> vs;
++
++ vector<Tuple>::iterator tp;
++ vector<CellId>::iterator cp;
++
++ //target tuple holder
++ Tuple t(&finalscheme);
++ //source tuple holder
++ Tuple s(ssch);
++
++ const Dataset &ds = Out->GetDataset(_i);
++ const Dataset &sourceds = Ss->GetDataset(_j);
++
++ for (size_t i = 0; i < Out->Size(_i); i++) {
++ m(i, cs);
++
++ if (vs.size() != cs.size()) {
++ vs.resize(cs.size(), s);
++ }
++
++ j = 0;
++ FOR(vector<CellId>, c, cs) {
++ sourceds.FastBindTuple(*c, vs[j++]);
++ }
+ #if 0
+- Ss->BindTuples(cs, vs);
++ Ss->BindTuples(cs, vs);
+ #endif
+- ds.FastBindTuple(i, t);
+- f(vs, t);
++ ds.FastBindTuple(i, t);
++ f(vs, t);
+ #if 0
+- //t.print();
+- //getchar();
++ //t.print();
++ //getchar();
+ #endif
+- cs.clear();
+- }
++ cs.clear();
++ }
+
+- return Out;
++ return Out;
+ }
+
+-string AggregateOp::newName(string Tname, string Sname) {
++string AggregateOp::newName(string Tname, string Sname)
++{
+
+- string gname = "a(" + Tname + ", " + Sname + ")";
+- return gname;
++ string gname = "a(" + Tname + ", " + Sname + ")";
++ return gname;
+ }
+
++} // namespace GF
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/aggregate.h gridfields/clib/src/aggregate.h
+--- tag/gridfieldsclib-0.7/src/aggregate.h 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/aggregate.h 2014-05-16 22:57:00.783391865 +0200
+@@ -1,84 +1,101 @@
+ #ifndef _AGGREGATE_H
+ #define _AGGREGATE_H
+
++// #include "config.h"
++
+ #include <iostream>
++//#include <functional>
+ #include "tuple.h"
+ #include "gridfield.h"
+ #include "gridfieldoperator.h"
+-#include <ext/functional>
++// #ifdef HAVE_TR1_FUNCTIONAL
++// #include <tr1/functional>
++// #endif
++// old code jhrg #include <ext/functional>
+ #include <string>
+
++namespace GF {
++
+ //typedef pointer_to_unary_function<Cell, Tuple *> GridFunction;
+
+ void debug_set(UnTypedPtr p);
+-class AssignmentFunction :
+- virtual public unary_function<CellId&, vector<Cell>&> {
+- public:
+-
+- virtual ~AssignmentFunction() {};
+- GridField *T;
+- GridField *S;
+- Dim_t _i, _j;
+- const Dataset *dstarget, *dssource;
+- Scheme schtarget;
+- Scheme schsource;
+-
+- virtual void setEnvironment(GridField *t, Dim_t i, GridField *s, Dim_t j) {
+- T=t; S=s; _i=i; _j=j;
+- dstarget = &T->GetDataset(_i);
+- dssource = &S->GetDataset(_j);
+- schtarget = dstarget->GetScheme();
+- schsource = dssource->GetScheme();
+- }
+- virtual void operator()(const CellId &, vector<CellId> &) = 0;
+-
++class AssignmentFunction: virtual public unary_function<CellId&, vector<Cell>&> {
++public:
++
++ virtual ~AssignmentFunction()
++ {
++ }
++ ;
++ GridField *T;
++ GridField *S;
++ Dim_t _i, _j;
++ const Dataset *dstarget, *dssource;
++ Scheme schtarget;
++ Scheme schsource;
++
++ virtual void setEnvironment(GridField *t, Dim_t i, GridField *s, Dim_t j)
++ {
++ T = t;
++ S = s;
++ _i = i;
++ _j = j;
++ dstarget = &T->GetDataset(_i);
++ dssource = &S->GetDataset(_j);
++ schtarget = dstarget->GetScheme();
++ schsource = dssource->GetScheme();
++ }
++ virtual void operator()(const CellId &, vector<CellId> &) = 0;
++
+ };
+
+-class AggregationFunction :
+- virtual public unary_function<vector<Tuple>&, Tuple> {
+- public:
+-
+- virtual ~AggregationFunction() {};
+- void setScheme(Scheme *sch) {
+- inscheme = sch;
+- outscheme = getOutScheme(inscheme);
+- }
+- Scheme *getOutScheme() { return outscheme; }
+- virtual Scheme *getOutScheme(Scheme *inscheme) = 0;
+-
+- virtual void operator()(vector<Tuple> &, Tuple &) = 0;
+-/*
+- ~AggregationFunction() {
+- delete outscheme;
+- }
+-*/
+- private:
+- Scheme *inscheme;
+- Scheme *outscheme;
++class AggregationFunction: virtual public unary_function<vector<Tuple>&, Tuple> {
++public:
++
++ virtual ~AggregationFunction()
++ {
++ }
++ ;
++ void setScheme(Scheme *sch)
++ {
++ inscheme = sch;
++ outscheme = getOutScheme(inscheme);
++ }
++ Scheme *getOutScheme()
++ {
++ return outscheme;
++ }
++ virtual Scheme *getOutScheme(Scheme *inscheme) = 0;
++
++ virtual void operator()(vector<Tuple> &, Tuple &) = 0;
++ /*
++ ~AggregationFunction() {
++ delete outscheme;
++ }
++ */
++private:
++ Scheme *inscheme;
++ Scheme *outscheme;
+ };
+
+-class AggregateOp : public BinaryGridFieldOperator {
+- public:
+-
+- AggregateOp(GridFieldOperator *T, Dim_t i,
+- AssignmentFunction *m,
+- AggregationFunction *f,
+- GridFieldOperator *S,
+- Dim_t j);
+-
+- static GridField *Aggregate(GridField *T, Dim_t i,
+- AssignmentFunction &m,
+- AggregationFunction &f,
+- GridField *S, Dim_t j);
+- protected:
+- AssignmentFunction *m;
+- AggregationFunction *f;
+- Dim_t _i,_j;
+-
+- void Execute();
+- private:
+- static string newName(string Aname, string Bname);
++class AggregateOp: public BinaryGridFieldOperator {
++public:
++
++ AggregateOp(GridFieldOperator *T, Dim_t i, AssignmentFunction *m, AggregationFunction *f, GridFieldOperator *S,
++ Dim_t j);
++
++ static GridField *Aggregate(GridField *T, Dim_t i, AssignmentFunction &m, AggregationFunction &f, GridField *S,
++ Dim_t j);
++protected:
++ AssignmentFunction *m;
++ AggregationFunction *f;
++ Dim_t _i, _j;
++
++ void Execute();
++private:
++ static string newName(string Aname, string Bname);
+
+ };
+
++} // namespace GF
++
+ #endif /* AGGREGATE_H */
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/aggregations.cc gridfields/clib/src/aggregations.cc
+--- tag/gridfieldsclib-0.7/src/aggregations.cc 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/aggregations.cc 2014-05-16 22:57:00.736725199 +0200
+@@ -1,60 +1,58 @@
++#include "config_gridfields.h"
+
+ #include <math.h>
+ #include "aggregations.h"
+
+-
+-float Aggregate::euclid(float x1, float y1, float x2, float y2) {
+- return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
++float Aggregate::euclid(float x1, float y1, float x2, float y2)
++{
++ return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ }
+
+-float Aggregate::euclid3D(float x1, float y1, float z1, float x2, float y2, float z2) {
+- return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1));
++float Aggregate::euclid3D(float x1, float y1, float z1, float x2, float y2, float z2)
++{
++ return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
+ }
+
+-
+-void Aggregate::interpolate3D::operator()(vector<Tuple> &tupset, Tuple &out) {
+- int s = tupset.size();
+- float dist[s];
+- float x, y, z, v[s][attrs.size()];
+- float px, py, pz, *val;
+- float sum = 0;
+-
+-
+-
+- Tuple *t = &out;
+- px = *(float *) t->get("x");
+- py = *(float *) t->get("y");
+- pz = *(float *) t->get("z");
+-
+-
+- val = new float[attrs.size()];
+- float null = -9999.0;
+- if (s==0) {
+- for (size_t j=0; j<attrs.size(); j++) {
+- out.set(attrs[j], &null);
+- }
+- }
+-
+- for (int i=0; i<s; i++) {
+- x = *(float *)tupset[i].get("x");
+- y = *(float *)tupset[i].get("y");
+- z = *(float *)tupset[i].get("z");
+- for (size_t j=0; j<attrs.size(); j++) {
+- v[i][j] = *(float *)tupset[i].get(attrs[j]);
+- }
+- dist[i] = euclid3D(x,y,z,px,py,pz);
+- sum += dist[i];
+- }
+-
+- //cout << "s=" << s << endl;
+- for (size_t j=0; j< attrs.size(); j++) {
+- val[j] = 0;
+- for (int i=0; i<s; i++) {
+- val[j] += (dist[i]/sum) * v[i][j];
+- }
+- (*(float *) out.get(attrs[j])) = val[j];
+- //out.set(attrs[j], &val[j]);
+- //cout << "val: " << attrs[j] << "=" << *(float*) &val[j] << endl;
+- }
+-
++void Aggregate::interpolate3D::operator()(vector<Tuple> &tupset, Tuple &out)
++{
++ int s = tupset.size();
++ float dist[s];
++ float x, y, z, v[s][attrs.size()];
++ float px, py, pz, *val;
++ float sum = 0;
++
++ Tuple *t = &out;
++ px = *(float *) t->get("x");
++ py = *(float *) t->get("y");
++ pz = *(float *) t->get("z");
++
++ val = new float[attrs.size()];
++ float null = -9999.0;
++ if (s == 0) {
++ for (size_t j = 0; j < attrs.size(); j++) {
++ out.set(attrs[j], &null);
++ }
++ }
++
++ for (int i = 0; i < s; i++) {
++ x = *(float *) tupset[i].get("x");
++ y = *(float *) tupset[i].get("y");
++ z = *(float *) tupset[i].get("z");
++ for (size_t j = 0; j < attrs.size(); j++) {
++ v[i][j] = *(float *) tupset[i].get(attrs[j]);
++ }
++ dist[i] = euclid3D(x, y, z, px, py, pz);
++ sum += dist[i];
++ }
++
++ //cout << "s=" << s << endl;
++ for (size_t j = 0; j < attrs.size(); j++) {
++ val[j] = 0;
++ for (int i = 0; i < s; i++) {
++ val[j] += (dist[i] / sum) * v[i][j];
++ }
++ (*(float *) out.get(attrs[j])) = val[j];
++ //out.set(attrs[j], &val[j]);
++ //cout << "val: " << attrs[j] << "=" << *(float*) &val[j] << endl;
++ }
+ }
+diff -Nur -x .svn tag/gridfieldsclib-0.7/src/aggregations.h gridfields/clib/src/aggregations.h
+--- tag/gridfieldsclib-0.7/src/aggregations.h 2012-02-13 17:47:10.000000000 +0100
++++ gridfields/clib/src/aggregations.h 2014-05-16 22:57:00.770058532 +0200
+@@ -6,1176 +6,1272 @@
+
+ namespace Aggregate {
+
++using namespace GF;
++
+ float euclid(float x1, float y1, float x2, float y2);
+ float euclid3D(float x1, float y1, float z1, float x2, float y2, float z2);
+
+-class dotwo : public AggregationFunction {
+- private:
+- AggregationFunction &left;
+- AggregationFunction &right;
+- Scheme *leftsch;
+- Scheme *rightsch;
+- Scheme outsch;
+-
+- public:
+- dotwo(AggregationFunction &left, AggregationFunction &right) :
+- left(left), right(right) {};
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+-
+- Tuple lefttup(leftsch);
+- Tuple righttup(rightsch);
+-
+- mergeTuples(out, lefttup, leftsch, "left_");
+- mergeTuples(out, righttup, rightsch, "right_");
+-
+- left(tupset, lefttup);
+- right(tupset, righttup);
+-
+- };
+-
+- void mergeTuples(Tuple &out, Tuple &lefttup,
+- Scheme *leftsch, string prefix) {
+-
+- for (unsigned int i=0; i<leftsch->size(); i++) {
+- string attr = leftsch->getAttribute(i);
+- if (outsch.isAttribute(attr))
+- lefttup.set(attr, out.get(attr));
+- else
+- lefttup.set(attr, out.get(prefix + attr));
+- }
+-
+- }
+-
+- void mergeSchemes(Scheme *sch, Scheme *leftsch,
+- Scheme *rightsch, string prefix) {
+-
+- for (unsigned int i=0; i<leftsch->size(); i++) {
+- string attr = leftsch->getAttribute(i);
+- Type type = leftsch->getType(i);
+-
+- if (rightsch->isAttribute(attr))
+- sch->addAttribute(prefix + attr, type);
+- else
+- sch->addAttribute(attr, type);
+- }
+- };
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- leftsch = left.getOutScheme(insch);
+- rightsch = right.getOutScheme(insch);
++class dotwo: public AggregationFunction {
++private:
++ AggregationFunction &left;
++ AggregationFunction &right;
++ Scheme *leftsch;
++ Scheme *rightsch;
++ Scheme outsch;
++
++public:
++ dotwo(AggregationFunction &left, AggregationFunction &right) :
++ left(left), right(right)
++ {
++ }
++ ;
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++
++ Tuple lefttup(leftsch);
++ Tuple righttup(rightsch);
++
++ mergeTuples(out, lefttup, leftsch, "left_");
++ mergeTuples(out, righttup, rightsch, "right_");
++
++ left(tupset, lefttup);
++ right(tupset, righttup);
++
++ }
++ ;
++
++ void mergeTuples(Tuple &out, Tuple &lefttup, Scheme *leftsch, string prefix)
++ {
++
++ for (unsigned int i = 0; i < leftsch->size(); i++) {
++ string attr = leftsch->getAttribute(i);
++ if (outsch.isAttribute(attr))
++ lefttup.set(attr, out.get(attr));
++ else
++ lefttup.set(attr, out.get(prefix + attr));
++ }
++
++ }
+
+- mergeSchemes(&outsch, leftsch, rightsch, "left_");
+- mergeSchemes(&outsch, rightsch, leftsch, "right_");
++ void mergeSchemes(Scheme *sch, Scheme *leftsch, Scheme *rightsch, string prefix)
++ {
+
+- return &outsch;
+- };
++ for (unsigned int i = 0; i < leftsch->size(); i++) {
++ string attr = leftsch->getAttribute(i);
++ Type type = leftsch->getType(i);
++
++ if (rightsch->isAttribute(attr))
++ sch->addAttribute(prefix + attr, type);
++ else
++ sch->addAttribute(attr, type);
++ }
++ }
++ ;
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ leftsch = left.getOutScheme(insch);
++ rightsch = right.getOutScheme(insch);
++
++ mergeSchemes(&outsch, leftsch, rightsch, "left_");
++ mergeSchemes(&outsch, rightsch, leftsch, "right_");
++
++ return &outsch;
++ }
++ ;
+ };
+ /*
+-class AggregationFunction {
+- public:
+- constructor(string, null_value=NULL_VALUE)
+- initialize()=0
+- step()=0
+- finalize()=0
+- getscheme()
+-}
+-*/
++ class AggregationFunction {
++ public:
++ constructor(string, null_value=NULL_VALUE)
++ initialize()=0
++ step()=0
++ finalize()=0
++ getscheme()
++ }
++ */
+
+ template<typename NumericType>
+-class triGradient : public AggregationFunction {
+- public:
+- triGradient(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+- triGradient(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- if (tupset.size() != 3) {
+- Fatal("triGrad Aggregation function only works on triangles; %i vertices were passed in.", tupset.size());
+- }
+-
+- float *area = (float *) out.get("area");
+- *area = 0;
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("gradx"+attrs[i])) {
+- float *gradx = (float *) out.get("gradx"+attrs[i]);
+- float *grady = (float *) out.get("grady"+attrs[i]);
+-
+- this->trigrad(tupset, attrs[i], area, gradx, grady);
+- }
+- }
+- }
+-
+- void trigrad(vector<Tuple> &tupset, string &attr,
+- float *area, float *gradx, float *grady) {
+- float x[3];
+- float y[3];
+- NumericType u[3];
+-
+- for (unsigned int i=0; i<3; i++) {
+- x[i] = *(float*) tupset[i].get("x");
+- y[i] = *(float*) tupset[i].get("y");
+- u[i] = *(NumericType*) tupset[i].get(attr);
+- }
+-
+- float tmp_x = (y[1]-y[2])*u[0] + (y[2]-y[0])*u[1] + (y[0]-y[1])*u[2];
+- float tmp_y = (x[2]-x[1])*u[0] + (x[0]-x[2])*u[1] + (x[1]-x[0])*u[2];
+-
+- *area = (x[1]*(y[2] - y[0]) + x[0]*(y[1] - y[2]) + x[2]*(y[0] - y[1])) / 2;
+-
+- *gradx = tmp_x; // / ( 2 * (*area) * (*area) );
+- *grady = tmp_y; // / ( 2 * (*area) * (*area) );
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- outsch.addAttribute("area", FLOAT);
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("gradx"+attrs[i], FLOAT);
+- outsch.addAttribute("grady"+attrs[i], FLOAT);
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
++class triGradient: public AggregationFunction {
++public:
++ triGradient(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++ triGradient(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ if (tupset.size() != 3) {
++ Fatal("triGrad Aggregation function only works on triangles; %i vertices were passed in.", tupset.size());
++ }
++
++ float *area = (float *) out.get("area");
++ *area = 0;
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("gradx" + attrs[i])) {
++ float *gradx = (float *) out.get("gradx" + attrs[i]);
++ float *grady = (float *) out.get("grady" + attrs[i]);
++
++ this->trigrad(tupset, attrs[i], area, gradx, grady);
++ }
++ }
++ }
++
++ void trigrad(vector<Tuple> &tupset, string &attr, float *area, float *gradx, float *grady)
++ {
++ float x[3];
++ float y[3];
++ NumericType u[3];
++
++ for (unsigned int i = 0; i < 3; i++) {
++ x[i] = *(float*) tupset[i].get("x");
++ y[i] = *(float*) tupset[i].get("y");
++ u[i] = *(NumericType*) tupset[i].get(attr);
++ }
++
++ float tmp_x = (y[1] - y[2]) * u[0] + (y[2] - y[0]) * u[1] + (y[0] - y[1]) * u[2];
++ float tmp_y = (x[2] - x[1]) * u[0] + (x[0] - x[2]) * u[1] + (x[1] - x[0]) * u[2];
++
++ *area = (x[1] * (y[2] - y[0]) + x[0] * (y[1] - y[2]) + x[2] * (y[0] - y[1])) / 2;
++
++ *gradx = tmp_x; // / ( 2 * (*area) * (*area) );
++ *grady = tmp_y; // / ( 2 * (*area) * (*area) );
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ outsch.addAttribute("area", FLOAT);
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("gradx" + attrs[i], FLOAT);
++ outsch.addAttribute("grady" + attrs[i], FLOAT);
++ }
++ }
++ return &outsch;
++ }
++
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+
+ };
+
+-class Any : public AggregationFunction {
+- public:
+- Any(string acheck, string aset, int tag)
+- : tag(tag), setattr(aset), checkattr(acheck) {}
+-
+- Any(string a, int tag=1)
+- : tag(tag), setattr(a), checkattr(a) {}
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- int *valptr;
+- valptr = (int *) out.get(setattr);
+-
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- int val = *(int *) tupset[0].get(checkattr);
+- cout << val << endl;
+- if (val) {
+- *valptr = tag;
+- return;
+- }
+- }
+- *valptr = 0;
++class Any: public AggregationFunction {
++public:
++ Any(string acheck, string aset, int tag) :
++ tag(tag), setattr(aset), checkattr(acheck)
++ {
++ }
++
++ Any(string a, int tag = 1) :
++ tag(tag), setattr(a), checkattr(a)
++ {
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ int *valptr;
++ valptr = (int *) out.get(setattr);
++
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ int val = *(int *) tupset[0].get(checkattr);
++ cout << val << endl;
++ if (val) {
++ *valptr = tag;
++ return;
++ }
++ }
++ *valptr = 0;
+ #if 0
+- cout << "none" << endl;
++ cout << "none" << endl;
+ #endif
+- return;
+- }
+- Scheme *getOutScheme(Scheme * /*insch unused jhrg 10/5/11*/) {
+- outsch.clear();
+- outsch.addAttribute(setattr, INT);
+- return &outsch;
+- }
+- private:
+- Scheme outsch;
+- int tag;
+- string setattr, checkattr;
++ return;
++ }
++ Scheme *getOutScheme(Scheme * /*insch unused jhrg 10/5/11*/)
++ {
++ outsch.clear();
++ outsch.addAttribute(setattr, INT);
++ return &outsch;
++ }
++private:
++ Scheme outsch;
++ int tag;
++ string setattr, checkattr;
+ };
+
+ template<typename NumericType>
+-class gradient : public AggregationFunction {
+- public:
+- gradient(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+- gradient(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- float x = *(float *) out.get("x");
+- float y = *(float *) out.get("y");
+-
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("gradx"+attrs[i])) {
+- float *gradx = (float *) out.get("gradx"+attrs[i]);
+- float *grady = (float *) out.get("grady"+attrs[i]);
+- NumericType u =
+- *(NumericType *) out.get(attrs[i]);
+-
+- this->gradLeastSquares(x, y, u,
+- attrs[i], tupset,
+- gradx, grady);
+- }
+- }
+- }
+-
+-
+- void gradLeastSquares(float x0, float y0, NumericType u0,
+- string attr, vector<Tuple> &tupset,
+- float *gradx, float *grady) {
+- // based on
+- // "Revisiting the Leaset Squares Procedure
+- // for gradient estimation on unstructured meshes"
+- // Dmitri Mavriplis
+- // NASA Technical Report, NIA Report No. 2003-06
+-
+- // weights are euclidean distance (or 1 if fast)
+-
+- bool fast = false;
+-
+- float a=0, b=0, c=0, d=0, e=0;
+-
+- if (tupset.empty()) {
+- *gradx = 0;
+- *grady = 0;
+- return;
+- }
+-
+- float w2 = 1;
+-
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- float xi = *(float *) tupset[i].get("x");
+- float yi = *(float *) tupset[i].get("y");
+- NumericType ui = *(NumericType *) tupset[i].get(attr);
+- NumericType du = ui - u0;
+-
+- float dx = xi - x0;
+- float dy = yi - y0;
+- if (dx==0 || dy==0) continue;
+-
+- // (inverse distance)^2 = weight^2
+- if (!fast)
+- w2 = 1 / (pow( dx, 2 ) + pow( dy, 2 ));
+-
+- a += w2 * pow(dx, 2);
+- b += w2 * dx * dy;
+- c += w2 * pow(dy, 2);
+- d += w2 * du * dx;
+- e += w2 * du * dy;
+-
+- }
+-
+- // Cramer's rule
+- float det = a*c - pow(b,2);
+- assert(det != 0);
+-
+- *gradx = (d*c - b*e) / det;
+- *grady = (a*e - d*b) / det;
+-
+- }
+-
+- void gradnorm(float x0, float y0, NumericType f0,
+- string attr, vector<Tuple> &tupset,
+- float *gradx, float *grady) {
+-
+- float maxdfdu = 0;
+-
+- *gradx = float(null_value);
+- *grady = float(null_value);
+-
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- float xi = *(float *) tupset[i].get("x");
+- float yi = *(float *) tupset[i].get("y");
+- NumericType fi = *(NumericType *) tupset[i].get(attr);
+-
+- float norm = sqrt( pow( (xi-x0), 2 ) + pow( (yi-y0), 2 ) );
+-
+- float dfdu = (fi - f0) / norm;
+-
+-
+- if (i==0) {
+- *gradx = dfdu * ( (xi - x0) / norm );
+- *grady = dfdu * ( (yi - y0) / norm );
+- maxdfdu = dfdu;
+- } else {
+- if ( (dfdu > maxdfdu) ) {
+- *gradx = dfdu * ( (xi - x0) / norm );
+- *grady = dfdu * ( (yi - y0) / norm );
+- maxdfdu = dfdu;
+- }
+- }
+- }
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("gradx"+attrs[i], FLOAT);
+- outsch.addAttribute("grady"+attrs[i], FLOAT);
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
++class gradient: public AggregationFunction {
++public:
++ gradient(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++ gradient(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ float x = *(float *) out.get("x");
++ float y = *(float *) out.get("y");
++
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("gradx" + attrs[i])) {
++ float *gradx = (float *) out.get("gradx" + attrs[i]);
++ float *grady = (float *) out.get("grady" + attrs[i]);
++ NumericType u = *(NumericType *) out.get(attrs[i]);
++
++ this->gradLeastSquares(x, y, u, attrs[i], tupset, gradx, grady);
++ }
++ }
++ }
++
++ void gradLeastSquares(float x0, float y0, NumericType u0, string attr, vector<Tuple> &tupset, float *gradx,
++ float *grady)
++ {
++ // based on
++ // "Revisiting the Leaset Squares Procedure
++ // for gradient estimation on unstructured meshes"
++ // Dmitri Mavriplis
++ // NASA Technical Report, NIA Report No. 2003-06
++
++ // weights are euclidean distance (or 1 if fast)
++
++ bool fast = false;
++
++ float a = 0, b = 0, c = 0, d = 0, e = 0;
++
++ if (tupset.empty()) {
++ *gradx = 0;
++ *grady = 0;
++ return;
++ }
++
++ float w2 = 1;
++
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ float xi = *(float *) tupset[i].get("x");
++ float yi = *(float *) tupset[i].get("y");
++ NumericType ui = *(NumericType *) tupset[i].get(attr);
++ NumericType du = ui - u0;
++
++ float dx = xi - x0;
++ float dy = yi - y0;
++ if (dx == 0 || dy == 0) continue;
++
++ // (inverse distance)^2 = weight^2
++ if (!fast) w2 = 1 / (pow(dx, 2) + pow(dy, 2));
++
++ a += w2 * pow(dx, 2);
++ b += w2 * dx * dy;
++ c += w2 * pow(dy, 2);
++ d += w2 * du * dx;
++ e += w2 * du * dy;
++
++ }
++
++ // Cramer's rule
++ float det = a * c - pow(b, 2);
++ assert(det != 0);
++
++ *gradx = (d * c - b * e) / det;
++ *grady = (a * e - d * b) / det;
++
++ }
++
++ void gradnorm(float x0, float y0, NumericType f0, string attr, vector<Tuple> &tupset, float *gradx, float *grady)
++ {
++
++ float maxdfdu = 0;
++
++ *gradx = float(null_value);
++ *grady = float(null_value);
++
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ float xi = *(float *) tupset[i].get("x");
++ float yi = *(float *) tupset[i].get("y");
++ NumericType fi = *(NumericType *) tupset[i].get(attr);
++
++ float norm = sqrt(pow((xi - x0), 2) + pow((yi - y0), 2));
++
++ float dfdu = (fi - f0) / norm;
++
++ if (i == 0) {
++ *gradx = dfdu * ((xi - x0) / norm);
++ *grady = dfdu * ((yi - y0) / norm);
++ maxdfdu = dfdu;
++ }
++ else {
++ if ((dfdu > maxdfdu)) {
++ *gradx = dfdu * ((xi - x0) / norm);
++ *grady = dfdu * ((yi - y0) / norm);
++ maxdfdu = dfdu;
++ }
++ }
++ }
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("gradx" + attrs[i], FLOAT);
++ outsch.addAttribute("grady" + attrs[i], FLOAT);
++ }
++ }
++ return &outsch;
++ }
++
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+ };
+
+ template<typename NumericType>
+-class gradient3D : public AggregationFunction {
+- public:
+- gradient3D(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+- gradient3D(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- float x = *(float *) out.get("x");
+- float y = *(float *) out.get("y");
+- float z = *(float *) out.get("z");
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- float *gradx = (float *) out.get("gradx"+attrs[i]);
+- float *grady = (float *) out.get("grady"+attrs[i]);
+- float *gradz = (float *) out.get("gradz"+attrs[i]);
+- NumericType u =
+- *(NumericType *) out.get(attrs[i]);
+-
+- this->gradLeastSquares(x, y, z, u,
+- v_poss[i], tupset,
+- gradx, grady, gradz);
+- }
+- }
+-
+-
+- void gradLeastSquares(float x0, float y0, float z0, NumericType u0,
+- int attr_pos, vector<Tuple> &tupset,
+- float *gradx, float *grady, float *gradz) {
+- // based on
+- // "Revisiting the Leaset Squares Procedure
+- // for gradient estimation on unstructured meshes"
+- // Dmitri Mavriplis
+- // NASA Technical Report, NIA Report No. 2003-06
+-
+- // weights are euclidean distance (or 1 if fast)
+-
+- bool fast = false;
+-
+- float a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;
+-
+- if (tupset.empty()) {
+- *gradx = 0;
+- *grady = 0;
+- *gradz = 0;
+- return;
+- }
+-
+- float w2 = 1;
+- for (unsigned int k=0; k<tupset.size(); k++) {
+- float xk = *(float *) tupset[k].get(x_pos);
+- float yk = *(float *) tupset[k].get(y_pos);
+- float zk = *(float *) tupset[k].get(z_pos);
+- //cout << xk << ", " << yk << ", " << zk << endl;
+- NumericType uk = *(NumericType *) tupset[k].get(attr_pos);
+- NumericType du = uk - u0;
+-
+- float dx = xk - x0;
+- float dy = yk - y0;
+- float dz = zk - z0;
+-
+- // inverse distance weights
+- if (!fast)
+- w2 = 1 / pow( pow(dx, 2) + pow(dy, 2) + pow(dz, 2), 2 );
+-
+-
+- // | a b c | | ux | | g |
+- // | b d e | | uy | = | h |
+- // | c e f | | uz | | i |
+-
+- a += w2 * pow(dx, 2);
+- b += w2 * dx * dy;
+- c += w2 * dx * dz;
+-
+- d += w2 * pow(dy, 2);
+- e += w2 * dy * dz;
+-
+- f += w2 * pow(dz, 2);
+-
+- g += w2 * du * dx;
+- h += w2 * du * dy;
+- i += w2 * du * dz;
+- }
+-
+- // Cramer's rule
+- float det = a*d*f - a*e*e + b*e*c - b*b*f + c*b*e - c*d*c;
+- assert(det != 0);
+-
+-
+- // g b c
+- // h d e
+- // i e f
+-
+- *gradx = (g*d*f - g*e*e + b*e*i - b*h*f + c*h*e - c*d*i) / det;
+-
+-
+- // a g c
+- // b h e
+- // c i f
+-
+- *grady = (a*h*f - a*e*i + g*e*c - g*b*f + c*b*i - c*h*c) / det;
+-
+-
+- // a b g
+- // b d h
+- // c e i
+-
+- *gradz = (a*d*i - a*h*e + b*h*c - b*b*i + g*b*e - g*d*c) / det;
+-
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+-
+- v_poss.clear();
+- x_pos = insch->getPosition("x");
+- y_pos = insch->getPosition("y");
+- z_pos = insch->getPosition("z");
+-
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- v_poss.push_back(insch->getPosition(attrs[i]));
+- outsch.addAttribute("gradx"+attrs[i], FLOAT);
+- outsch.addAttribute("grady"+attrs[i], FLOAT);
+- outsch.addAttribute("gradz"+attrs[i], FLOAT);
+- } else {
+- Fatal("%s is not an attribute of the source gridfield's scheme: %s",
+- attrs[i].c_str(), insch->asString().c_str());
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- int x_pos, y_pos, z_pos;
+- vector<int> v_poss;
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
+-};
++class gradient3D: public AggregationFunction {
++public:
++ gradient3D(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++ gradient3D(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
+
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ float x = *(float *) out.get("x");
++ float y = *(float *) out.get("y");
++ float z = *(float *) out.get("z");
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ float *gradx = (float *) out.get("gradx" + attrs[i]);
++ float *grady = (float *) out.get("grady" + attrs[i]);
++ float *gradz = (float *) out.get("gradz" + attrs[i]);
++ NumericType u = *(NumericType *) out.get(attrs[i]);
+
++ this->gradLeastSquares(x, y, z, u, v_poss[i], tupset, gradx, grady, gradz);
++ }
++ }
+
+-template<typename NumericType>
+-class _sum : public AggregationFunction {
+- public:
+- _sum(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+- _sum(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- NumericType *valptr;
+- vector<string>::iterator a;
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("sum"+attrs[i])) {
+- valptr = (NumericType *) out.get("sum"+attrs[i]);
+- *valptr = sum(attrs[i], tupset);
+- }
+- }
+- }
+-
+- NumericType sum(string attr, vector<Tuple> &tupset) {
+- //cout << tupset.size() << endl;
+- if (tupset.size() == 0) return null_value;
+- NumericType total=0;
+- NumericType val;
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- val = *(NumericType *) tupset[i].get(attr);
+- if (val == null_value) continue; // return null_value;
+- total += val;
+- }
+- return total;
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("sum"+attrs[i], insch->getType(attrs[i]));
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
++ void gradLeastSquares(float x0, float y0, float z0, NumericType u0, int attr_pos, vector<Tuple> &tupset,
++ float *gradx, float *grady, float *gradz)
++ {
++ // based on
++ // "Revisiting the Leaset Squares Procedure
++ // for gradient estimation on unstructured meshes"
++ // Dmitri Mavriplis
++ // NASA Technical Report, NIA Report No. 2003-06
++
++ // weights are euclidean distance (or 1 if fast)
++
++ bool fast = false;
++
++ float a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0;
++
++ if (tupset.empty()) {
++ *gradx = 0;
++ *grady = 0;
++ *gradz = 0;
++ return;
++ }
++
++ float w2 = 1;
++ for (unsigned int k = 0; k < tupset.size(); k++) {
++ float xk = *(float *) tupset[k].get(x_pos);
++ float yk = *(float *) tupset[k].get(y_pos);
++ float zk = *(float *) tupset[k].get(z_pos);
++ //cout << xk << ", " << yk << ", " << zk << endl;
++ NumericType uk = *(NumericType *) tupset[k].get(attr_pos);
++ NumericType du = uk - u0;
++
++ float dx = xk - x0;
++ float dy = yk - y0;
++ float dz = zk - z0;
++
++ // inverse distance weights
++ if (!fast) w2 = 1 / pow(pow(dx, 2) + pow(dy, 2) + pow(dz, 2), 2);
++
++ // | a b c | | ux | | g |
++ // | b d e | | uy | = | h |
++ // | c e f | | uz | | i |
++
++ a += w2 * pow(dx, 2);
++ b += w2 * dx * dy;
++ c += w2 * dx * dz;
++
++ d += w2 * pow(dy, 2);
++ e += w2 * dy * dz;
++
++ f += w2 * pow(dz, 2);
++
++ g += w2 * du * dx;
++ h += w2 * du * dy;
++ i += w2 * du * dz;
++ }
++
++ // Cramer's rule
++ float det = a * d * f - a * e * e + b * e * c - b * b * f + c * b * e - c * d * c;
++ assert(det != 0);
++
++ // g b c
++ // h d e
++ // i e f
++
++ *gradx = (g * d * f - g * e * e + b * e * i - b * h * f + c * h * e - c * d * i) / det;
++
++ // a g c
++ // b h e
++ // c i f
++
++ *grady = (a * h * f - a * e * i + g * e * c - g * b * f + c * b * i - c * h * c) / det;
++
++ // a b g
++ // b d h
++ // c e i
++
++ *gradz = (a * d * i - a * h * e + b * h * c - b * b * i + g * b * e - g * d * c) / det;
++
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++
++ v_poss.clear();
++ x_pos = insch->getPosition("x");
++ y_pos = insch->getPosition("y");
++ z_pos = insch->getPosition("z");
++
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ v_poss.push_back(insch->getPosition(attrs[i]));
++ outsch.addAttribute("gradx" + attrs[i], FLOAT);
++ outsch.addAttribute("grady" + attrs[i], FLOAT);
++ outsch.addAttribute("gradz" + attrs[i], FLOAT);
++ }
++ else {
++ Fatal("%s is not an attribute of the source gridfield's scheme: %s", attrs[i].c_str(),
++ insch->asString().c_str());
++ }
++ }
++ return &outsch;
++ }
++
++private:
++ int x_pos, y_pos, z_pos;
++ vector<int> v_poss;
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+ };
+
+ template<typename NumericType>
+-class _average : public AggregationFunction {
++class _sum: public AggregationFunction {
++public:
++ _sum(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++ _sum(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ NumericType *valptr;
++ vector<string>::iterator a;
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("sum" + attrs[i])) {
++ valptr = (NumericType *) out.get("sum" + attrs[i]);
++ *valptr = sum(attrs[i], tupset);
++ }
++ }
++ }
+
+- public:
+- _average(string as) {
+- split(as, " ;,", attrs);
+- }
+- _average(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out){
+- float *valptr;
+- vector<string>::iterator a;
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("avg"+attrs[i])) {
+- valptr = (float *) out.get("avg"+attrs[i]);
+- *valptr = average(attrs[i], tupset);
+- }
+- }
+- }
+-
+- float average(string attr, vector<Tuple> &tupset) {
+- NumericType total=0;
+- NumericType val;
+- int count=0;
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- val = *(NumericType *) tupset[i].get(attr);
+- if (val == null_value) {
+- continue; //return null_value;
+- }
+- count = count + 1;
+- total += val;
+- }
+- if (count > 0) {
+- return total/count;
+- } else {
+- return null_value;
+- }
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("avg" + attrs[i], FLOAT);
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
++ NumericType sum(string attr, vector<Tuple> &tupset)
++ {
++ //cout << tupset.size() << endl;
++ if (tupset.size() == 0) return null_value;
++ NumericType total = 0;
++ NumericType val;
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ val = *(NumericType *) tupset[i].get(attr);
++ if (val == null_value) continue; // return null_value;
++ total += val;
++ }
++ return total;
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("sum" + attrs[i], insch->getType(attrs[i]));
++ }
++ }
++ return &outsch;
++ }
++
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+ };
+
+ template<typename NumericType>
+-class _min : public AggregationFunction {
++class _average: public AggregationFunction {
+
+- public:
+- _min(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+- _min(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- NumericType *valptr;
+- vector<string>::iterator a;
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("min"+attrs[i])) {
+- valptr = (NumericType *) out.get("min"+attrs[i]);
+- *valptr = min(attrs[i], tupset);
+- }
+- }
+- }
+-
+- NumericType min(string attr, vector<Tuple> &tupset) {
+- if (tupset.size() == 0) return null_value;
+- NumericType minv = *(NumericType *) tupset[0].get(attr);
+- NumericType v;
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- v = *(NumericType *) tupset[i].get(attr);
+- if (v == null_value) continue; //return null_value;
+- if (minv > v) minv = v;
+- }
+- return minv;
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("min" + attrs[i], FLOAT);
+- }
+- }
+- return &outsch;
+- }
+-
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
+-};
++public:
++ _average(string as)
++ {
++ split(as, " ;,", attrs);
++ }
++ _average(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
+
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ float *valptr;
++ vector<string>::iterator a;
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("avg" + attrs[i])) {
++ valptr = (float *) out.get("avg" + attrs[i]);
++ *valptr = average(attrs[i], tupset);
++ }
++ }
++ }
+
+-template<typename NumericType>
+-class _max : public AggregationFunction {
++ float average(string attr, vector<Tuple> &tupset)
++ {
++ NumericType total = 0;
++ NumericType val;
++ int count = 0;
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ val = *(NumericType *) tupset[i].get(attr);
++ if (val == null_value) {
++ continue; //return null_value;
++ }
++ count = count + 1;
++ total += val;
++ }
++ if (count > 0) {
++ return total / count;
++ }
++ else {
++ return null_value;
++ }
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("avg" + attrs[i], FLOAT);
++ }
++ }
++ return &outsch;
++ }
+
+- public:
+- _max(string as) : null_value(NULL_VALUE) {
+- split(as, " ;,", attrs);
+- }
+-
+- _max(string as, NumericType nv) : null_value(nv) {
+- split(as, " ;,", attrs);
+- }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- NumericType *valptr;
+- vector<string>::iterator a;
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (outsch.isAttribute("max"+attrs[i])) {
+- valptr = (NumericType *) out.get("max"+attrs[i]);
+- *valptr = max(attrs[i], tupset);
+- }
+- }
+- }
+-
+- NumericType max(string attr, vector<Tuple> &tupset) {
+- if (tupset.size() == 0) return null_value;
+- NumericType maxv = *(NumericType *) tupset[0].get(attr);
+- NumericType v;
+- for (unsigned int i=0; i<tupset.size(); i++) {
+- v = *(NumericType *) tupset[i].get(attr);
+- if (v == null_value) continue; //return null_value;
+- if (maxv < v) maxv = v;
+- }
+- return maxv;
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- outsch.clear();
+- for (unsigned int i=0; i<attrs.size(); i++) {
+- if (insch->isAttribute(attrs[i])) {
+- outsch.addAttribute("max"+attrs[i], insch->getType(attrs[i]));
+- }
+- }
+- return &outsch;
+- }
+- private:
+- Scheme outsch;
+- NumericType null_value;
+- vector<string> attrs;
+- vector<NumericType> totals;
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+ };
+
+-class Count : public AggregationFunction {
++template<typename NumericType>
++class _min: public AggregationFunction {
++
++public:
++ _min(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++ _min(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
+
+- public:
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ NumericType *valptr;
++ vector<string>::iterator a;
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("min" + attrs[i])) {
++ valptr = (NumericType *) out.get("min" + attrs[i]);
++ *valptr = min(attrs[i], tupset);
++ }
++ }
++ }
+
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- int *valptr;
+- valptr = (int *) out.get("count");
+- *valptr = tupset.size();
+- }
+-
+- Scheme *getOutScheme(Scheme */*insch*/) {
+- outsch.clear();
+- outsch.addAttribute("count", INT);
+- return &outsch;
+- }
+- private:
+- Scheme outsch;
+- vector<string> attrs;
+-
++ NumericType min(string attr, vector<Tuple> &tupset)
++ {
++ if (tupset.size() == 0) return null_value;
++ NumericType minv = *(NumericType *) tupset[0].get(attr);
++ NumericType v;
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ v = *(NumericType *) tupset[i].get(attr);
++ if (v == null_value) continue; //return null_value;
++ if (minv > v) minv = v;
++ }
++ return minv;
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("min" + attrs[i], FLOAT);
++ }
++ }
++ return &outsch;
++ }
++
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
+ };
+
+-/*
+-class makepolygf : public AggregationFunction {
+-
+- public:
+- int dim;
+- makegridfield(int d) { dim = d; }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- int s = tupset.size();
+-
+- if (s==0) return;
+- Grid *g = new Grid();
+- g->setImplicit0Cells(s);
+-
+- for (int i=0; i<tupset.size(); i++) {
+- }
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- Scheme *outsch = new Scheme(*insch);
+- outsch->addAttribute("gf", FLOAT);
+- return outsch;
+- }
++template<typename NumericType>
++class _max: public AggregationFunction {
+
+-}
+-*/
++public:
++ _max(string as) :
++ null_value(NULL_VALUE)
++ {
++ split(as, " ;,", attrs);
++ }
++
++ _max(string as, NumericType nv) :
++ null_value(nv)
++ {
++ split(as, " ;,", attrs);
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ NumericType *valptr;
++ vector<string>::iterator a;
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (outsch.isAttribute("max" + attrs[i])) {
++ valptr = (NumericType *) out.get("max" + attrs[i]);
++ *valptr = max(attrs[i], tupset);
++ }
++ }
++ }
++
++ NumericType max(string attr, vector<Tuple> &tupset)
++ {
++ if (tupset.size() == 0) return null_value;
++ NumericType maxv = *(NumericType *) tupset[0].get(attr);
++ NumericType v;
++ for (unsigned int i = 0; i < tupset.size(); i++) {
++ v = *(NumericType *) tupset[i].get(attr);
++ if (v == null_value) continue; //return null_value;
++ if (maxv < v) maxv = v;
++ }
++ return maxv;
++ }
++
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ outsch.clear();
++ for (unsigned int i = 0; i < attrs.size(); i++) {
++ if (insch->isAttribute(attrs[i])) {
++ outsch.addAttribute("max" + attrs[i], insch->getType(attrs[i]));
++ }
++ }
++ return &outsch;
++ }
++private:
++ Scheme outsch;
++ NumericType null_value;
++ vector<string> attrs;
++ vector<NumericType> totals;
++};
++
++class Count: public AggregationFunction {
++
++public:
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ int *valptr;
++ valptr = (int *) out.get("count");
++ *valptr = tupset.size();
++ }
++
++ Scheme *getOutScheme(Scheme */*insch*/)
++ {
++ outsch.clear();
++ outsch.addAttribute("count", INT);
++ return &outsch;
++ }
++private:
++ Scheme outsch;
++ vector<string> attrs;
+
+-class area : public AggregationFunction {
+- public:
+- area(string a) { attr = a; }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- float *area = (float *) out.get(attr);
+- if (tupset.size() < 3) *area = 0;
+- *area = 0;
+- unsigned int i, j;
+- for (i=0, j=tupset.size()-1; i<tupset.size(); j = i++) {
+- float x1 = *(float *) tupset[j].get("x");
+- float y1 = *(float *) tupset[j].get("y");
+- float x2 = *(float *) tupset[i].get("x");
+- float y2 = *(float *) tupset[i].get("y");
+- *area += x1*y2 - x2*y1;
+- }
+- *area =*area/2;
+- }
+-
+- Scheme *getOutScheme(Scheme */*insch*/) {
+- outsch.clear();
+- outsch.addAttribute(attr, FLOAT);
+- return &outsch;
+- }
+-
+- private:
+- string attr;
+- Scheme outsch;
+ };
+
+-class mkvector : public AggregationFunction {
+- public:
+- string attr;
+- mkvector(string a) { attr = a; }
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- //if (tupset.size() > 0) {
+- // tupset[0].print();
+- //}
+-
+- vector<Tuple> **val = (vector<Tuple> **) out.get(attr);
+- if (val == NULL) {
+- Fatal("Attribute %s not found during aggregation", attr.c_str());
+- }
+-
+- // how can I clean up this vector?
+- *val = new vector<Tuple>(tupset);
+- //counted_ptr<vector<Tuple> > p(*val);
+ /*
+- if ((**val).size() > 4) getchar();
+- Tuple *t = &(**val)[0];
+- cout << "tuple: ";
+- cout << *val << endl;
+- t->print();
+- */
+- //cout << "tuple: " << *(float *) (((*val)[0]).get("x")) << endl;
+- }
+-
+- Scheme *getOutScheme(Scheme */*insch*/) {
+- outsch.clear();
+- outsch.addAttribute(attr, OBJ);
+- return &outsch;
+- }
+- private:
+- Scheme outsch;
++ class makepolygf : public AggregationFunction {
++
++ public:
++ int dim;
++ makegridfield(int d) { dim = d; }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out) {
++ int s = tupset.size();
++
++ if (s==0) return;
++ Grid *g = new Grid();
++ g->setImplicit0Cells(s);
++
++ for (int i=0; i<tupset.size(); i++) {
++ }
++ }
++
++ Scheme *getOutScheme(Scheme *insch) {
++ Scheme *outsch = new Scheme(*insch);
++ outsch->addAttribute("gf", FLOAT);
++ return outsch;
++ }
++
++ }
++ */
++
++class area: public AggregationFunction {
++public:
++ area(string a)
++ {
++ attr = a;
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ float *area = (float *) out.get(attr);
++ if (tupset.size() < 3) *area = 0;
++ *area = 0;
++ unsigned int i, j;
++ for (i = 0, j = tupset.size() - 1; i < tupset.size(); j = i++) {
++ float x1 = *(float *) tupset[j].get("x");
++ float y1 = *(float *) tupset[j].get("y");
++ float x2 = *(float *) tupset[i].get("x");
++ float y2 = *(float *) tupset[i].get("y");
++ *area += x1 * y2 - x2 * y1;
++ }
++ *area = *area / 2;
++ }
++
++ Scheme *getOutScheme(Scheme */*insch*/)
++ {
++ outsch.clear();
++ outsch.addAttribute(attr, FLOAT);
++ return &outsch;
++ }
++
++private:
++ string attr;
++ Scheme outsch;
+ };
+
++class mkvector: public AggregationFunction {
++public:
++ string attr;
++ mkvector(string a)
++ {
++ attr = a;
++ }
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ //if (tupset.size() > 0) {
++ // tupset[0].print();
++ //}
++
++ vector<Tuple> **val = (vector<Tuple> **) out.get(attr);
++ if (val == NULL) {
++ Fatal("Attribute %s not found during aggregation", attr.c_str());
++ }
++
++ // how can I clean up this vector?
++ *val = new vector<Tuple>(tupset);
++ //counted_ptr<vector<Tuple> > p(*val);
++ /*
++ if ((**val).size() > 4) getchar();
++ Tuple *t = &(**val)[0];
++ cout << "tuple: ";
++ cout << *val << endl;
++ t->print();
++ */
++ //cout << "tuple: " << *(float *) (((*val)[0]).get("x")) << endl;
++ }
+
+-class triweights : public AggregationFunction {
+- // UNTESTED
+- public:
+-
+- void operator()(vector<Tuple> &tupset, Tuple &out) {
+- unsigned int s = tupset.size();
+- float dist[s];
+- float x, y;
+- float px, py, w[s];
+- float sum = 0;
+-
+- Tuple *t = &out;
+- px = *(float *) t->get("x");
+- py = *(float *) t->get("y");
+-
+- for (unsigned int i=0; i<s; i++) {
+- x = *(float *)tupset[i].get("x");
+- y = *(float *)tupset[i].get("y");
+- dist[i] = euclid(x,y,px,py);
+- sum += dist[i];
+- }
+- for (unsigned int i=0; i<s; i++) {
+- w[i] = (dist[i]/sum);
+- }
+- out.set("w1", *(UnTypedPtr*) &w[0]);
+- out.set("w2", *(UnTypedPtr*) &w[1]);
+- out.set("w3", *(UnTypedPtr*) &w[2]);
+- }
+-
+- Scheme *getOutScheme(Scheme *insch) {
+- Scheme *outsch = new Scheme(*insch);
+- outsch->addAttribute("w1", FLOAT);
+- outsch->addAttribute("w2", FLOAT);
+- outsch->addAttribute("w3", FLOAT);
+- return outsch;
+- }
++ Scheme *getOutScheme(Scheme */*insch*/)
++ {
++ outsch.clear();
++ outsch.addAttribute(attr, OBJ);
++ return &outsch;
++ }
++private:
++ Scheme outsch;
+ };
+
++class triweights: public AggregationFunction {
++ // UNTESTED
++public:
++
++ void operator()(vector<Tuple> &tupset, Tuple &out)
++ {
++ unsigned int s = tupset.size();
++ float dist[s];
++ float x, y;
++ float px, py, w[s];
++ float sum = 0;
++
++ Tuple *t = &out;
++ px = *(float *) t->get("x");
++ py = *(float *) t->get("y");
++
++ for (unsigned int i = 0; i < s; i++) {
++ x = *(float *) tupset[i].get("x");
++ y = *(float *) tupset[i].get("y");
++ dist[i] = euclid(x, y, px, py);
++ sum += dist[i];
++ }
++ for (unsigned int i = 0; i < s; i++) {
++ w[i] = (dist[i] / sum);
++ }
++ out.set("w1", (UnTypedPtr) &w[0]);
++ out.set("w2", (UnTypedPtr) &w[1]);
++ out.set("w3", (UnTypedPtr) &w[2]);
++ }
+
++ Scheme *getOutScheme(Scheme *insch)
++ {
++ Scheme *outsch = new Scheme(*insch);
++ outsch->addAttribute("w1", FLOAT);
++ outsch->addAttribute("w2", FLOAT);
++ outsch->addAttribute("w3", FLOAT);
++ return outsch;
++ }
++};
+
+ template<typename ValueType>
+-class setunion : public AggregationFunction {
+- private:
+- Scheme *outsch;
+- Scheme *sch;
<Skipped 36423 lines>
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/gridfields.git/commitdiff/7ecd07713d1f7be6247711f631dc9c4fa047afc0
More information about the pld-cvs-commit
mailing list