[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203

Stephane Popinet popinet at users.sf.net
Fri May 15 02:55:10 UTC 2009


The following commit has been merged in the upstream branch:
commit 8c0b3c1a8022a5dbba82b2490afbac47b4365d2b
Author: Stephane Popinet <popinet at users.sf.net>
Date:   Fri Mar 28 13:26:35 2008 +1100

    New Map module for cartographic projections
    
    darcs-hash:20080328022635-d4795-2b07e1e6171455652e59fa4e3048a2c8ac48025c.gz

diff --git a/configure.in b/configure.in
index 1471a3d..3452841 100644
--- a/configure.in
+++ b/configure.in
@@ -287,6 +287,12 @@ AC_SUBST(CFLAGS)
 AC_SUBST(CPPFLAGS)
 AC_SUBST(LDFLAGS)
 
+# checks for libproj
+AC_CHECK_LIB(proj, pj_fwd, proj="true",
+  AC_MSG_WARN([libproj not found. Map module will not be available.]), [-lm])
+AC_CHECK_HEADERS(proj_api.h, proj="true", proj="false")
+AM_CONDITIONAL(HAS_LIBPROJ, test x$proj = xtrue)
+
 dnl header file checks
 AC_CHECK_HEADERS(fpu_control.h,
   AC_CHECK_DECL(_FPU_SETCW, 
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 004b5e9..65d4ceb 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -3,6 +3,32 @@
 INCLUDES = -I$(top_srcdir)/src -I$(includedir) \
            -DG_LOG_DOMAIN=\"Gfs-modules\" $(GTS_CFLAGS)
 
+if HAS_LIBPROJ
+MAP = libmap2D.la libmap3D.la libmap2D3.la
+endif
+
+pkglib_LTLIBRARIES = \
+	$(MAP)
+
+EXTRA_DIST = \
+	map.mod
+
+BUILT_SOURCES = \
+	map.c
+
+AM_LDFLAGS = $(NO_UNDEFINED)\
+        -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)\
+	-release $(LT_RELEASE) -export-dynamic
+
+libmap3D_la_SOURCES = map.c
+libmap3D_la_LIBADD = -lproj
+libmap2D_la_SOURCES = map.c
+libmap2D_la_CFLAGS = $(AM_CFLAGS) -DFTT_2D=1
+libmap2D_la_LIBADD = -lproj
+libmap2D3_la_SOURCES = map.c
+libmap2D3_la_CFLAGS = $(AM_CFLAGS) -DFTT_2D3=1
+libmap2D3_la_LIBADD = -lproj
+
 if HAVE_MODULES
 %.c : %.mod
 	@echo "/* $@" > $@
diff --git a/modules/map.mod b/modules/map.mod
new file mode 100644
index 0000000..fc7e503
--- /dev/null
+++ b/modules/map.mod
@@ -0,0 +1,181 @@
+/* Gerris - The GNU Flow Solver                       (-*-C-*-)
+ * Copyright (C) 2001-2008 National Institute of Water and Atmospheric Research
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.  
+ */
+
+#include <proj_api.h>
+#include "map.h"
+
+/* GfsMapProjection: Header */
+
+typedef struct _GfsMapProjection         GfsMapProjection;
+
+struct _GfsMapProjection {
+  /*< private >*/
+  GfsMap parent;
+  projPJ pj;
+  gdouble cosa, sina;
+
+  /*< public >*/
+  gdouble lon, lat, scale, angle;
+};
+
+#define GFS_MAP_PROJECTION(obj)            GTS_OBJECT_CAST (obj,\
+					         GfsMapProjection,\
+					         gfs_map_projection_class ())
+#define GFS_IS_MAP_PROJECTION(obj)         (gts_object_is_from_class (obj,\
+						 gfs_map_projection_class ()))
+
+GfsMapClass * gfs_map_projection_class  (void);
+
+/* GfsMapProjection: Object */
+
+static void gfs_map_projection_read (GtsObject ** o, GtsFile * fp)
+{
+  (* GTS_OBJECT_CLASS (gfs_map_projection_class ())->parent_class->read) (o, fp);
+  if (fp->type == GTS_ERROR)
+    return;
+
+  GtsFileVariable var[] = {
+    {GTS_DOUBLE, "lon",   TRUE},
+    {GTS_DOUBLE, "lat",   TRUE},
+    {GTS_DOUBLE, "scale", TRUE},
+    {GTS_DOUBLE, "angle", TRUE},
+    {GTS_NONE}
+  };
+  GfsMapProjection * map = GFS_MAP_PROJECTION (*o);
+  var[0].data = &map->lon;
+  var[1].data = &map->lat;
+  var[2].data = &map->scale;
+  var[3].data = &map->angle;
+
+  gts_file_assign_variables (fp, var);
+  if (fp->type == GTS_ERROR)
+    return;
+
+  map->cosa = cos (map->angle*DEG_TO_RAD);
+  map->sina = sin (map->angle*DEG_TO_RAD);
+
+  char * parms[] = {
+    "proj=lcc", /* Lambert Conformal Conic */
+    NULL, NULL, NULL, NULL
+  };
+  parms[1] = g_strdup_printf ("lon_0=%lf", map->lon);
+  parms[2] = g_strdup_printf ("lat_0=%lf", map->lat);
+  parms[3] = g_strdup_printf ("lat_1=%lf", map->lat);
+  parms[4] = g_strdup_printf ("lat_2=%lf", map->lat);
+  map->pj = pj_init (sizeof(parms)/sizeof(char *), parms);
+  if (!map->pj)
+    gts_file_error (fp, "cannot initialise projection");
+  g_free (parms[1]);
+  g_free (parms[2]);
+  g_free (parms[3]);
+  g_free (parms[4]);
+}
+
+static void gfs_map_projection_write (GtsObject * o, FILE * fp)
+{
+  (* GTS_OBJECT_CLASS (gfs_map_projection_class ())->parent_class->write) (o, fp);
+  GfsMapProjection * map = GFS_MAP_PROJECTION (o);
+  fprintf (fp, " { lon = %.8g lat = %.8g scale = %.8g angle = %.8g }",
+	   map->lon, map->lat, map->scale, map->angle);
+}
+
+static void gfs_map_projection_destroy (GtsObject * object)
+{
+  if (GFS_MAP_PROJECTION (object)->pj)
+    pj_free (GFS_MAP_PROJECTION (object)->pj);
+  (* GTS_OBJECT_CLASS (gfs_map_projection_class ())->parent_class->destroy) (object);
+}
+
+static void projection_transform (GfsMap * map, const FttVector * src, FttVector * dest)
+{
+  projLP idata;
+  projXY odata;
+  GfsMapProjection * m = GFS_MAP_PROJECTION (map);
+  idata.u = src->x*DEG_TO_RAD;
+  idata.v = src->y*DEG_TO_RAD;
+  odata = pj_fwd (idata, m->pj);
+  odata.u /= m->scale;
+  odata.v /= m->scale;
+  dest->x = odata.u*m->cosa - odata.v*m->sina;
+  dest->y = odata.v*m->cosa + odata.u*m->sina;
+}
+
+static void projection_inverse (GfsMap * map, const FttVector * src, FttVector * dest)
+{
+  projLP odata;
+  projXY idata;
+  GfsMapProjection * m = GFS_MAP_PROJECTION (map);
+  idata.u = src->x*m->cosa + src->y*m->sina;
+  idata.v = src->y*m->cosa - src->x*m->sina;
+  idata.u *= m->scale;
+  idata.v *= m->scale;
+  odata = pj_inv (idata, GFS_MAP_PROJECTION (map)->pj);
+  dest->x = odata.u*RAD_TO_DEG;
+  dest->y = odata.v*RAD_TO_DEG;
+}
+
+static void gfs_map_projection_class_init (GfsMapClass * klass)
+{
+  GTS_OBJECT_CLASS (klass)->read = gfs_map_projection_read;
+  GTS_OBJECT_CLASS (klass)->write = gfs_map_projection_write;
+  GTS_OBJECT_CLASS (klass)->destroy = gfs_map_projection_destroy;
+  GFS_MAP_CLASS (klass)->transform = projection_transform;
+  GFS_MAP_CLASS (klass)->inverse = projection_inverse;
+}
+
+static void gfs_map_projection_init (GfsMapProjection * object)
+{
+  /* Wellington */
+  object->lon = 174.777222;
+  object->lat = -41.288889;
+  object->scale = 5e5;
+  object->angle = 0.; object->cosa = 1.; object->sina = 0.;
+  object->pj = NULL;
+}
+
+GfsMapClass * gfs_map_projection_class (void)
+{
+  static GfsMapClass * klass = NULL;
+
+  if (klass == NULL) {
+    GtsObjectClassInfo gfs_map_projection_info = {
+      "GfsMapProjection",
+      sizeof (GfsMapProjection),
+      sizeof (GfsMapClass),
+      (GtsObjectClassInitFunc) gfs_map_projection_class_init,
+      (GtsObjectInitFunc) gfs_map_projection_init,
+      (GtsArgSetFunc) NULL,
+      (GtsArgGetFunc) NULL
+    };
+    klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_map_class ()),
+				  &gfs_map_projection_info);
+  }
+
+  return klass;
+}
+
+/* Initialize module */
+
+const gchar * g_module_check_init (void);
+
+const gchar * g_module_check_init (void)
+{
+  gfs_map_projection_class ();
+  return NULL;
+}
diff --git a/src/simulation.c b/src/simulation.c
index 63c6feb..01a2897 100644
--- a/src/simulation.c
+++ b/src/simulation.c
@@ -210,7 +210,15 @@ static void simulation_read (GtsObject ** object, GtsFile * fp)
 
 	module = g_module_open (fp->token->str, 0);
 	if (module == NULL) {
-	  gchar * name = g_strconcat (fp->token->str, FTT_DIMENSION == 2 ? "2D" : "3D", NULL);
+	  gchar * name = g_strconcat (fp->token->str, 
+#if FTT_2D
+				      "2D"
+#elif FTT_2D3
+				      "2D3"
+#else
+				      "3D"
+#endif
+				      , NULL);
 	  gchar * path = g_module_build_path (GFS_MODULES_DIR, name);
 	  g_free (name);
 	  module = g_module_open (path, 0);

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list