[GRASS-SVN] r47532 - grass/trunk/lib/raster3d

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 10 12:45:09 EDT 2011


Author: martinl
Date: 2011-08-10 09:45:08 -0700 (Wed, 10 Aug 2011)
New Revision: 47532

Added:
   grass/trunk/lib/raster3d/alloc.c
   grass/trunk/lib/raster3d/cache.c
   grass/trunk/lib/raster3d/cache1.c
   grass/trunk/lib/raster3d/cats.c
   grass/trunk/lib/raster3d/close.c
   grass/trunk/lib/raster3d/color.c
   grass/trunk/lib/raster3d/defaults.c
   grass/trunk/lib/raster3d/doubleio.c
   grass/trunk/lib/raster3d/error.c
   grass/trunk/lib/raster3d/fpxdr.c
   grass/trunk/lib/raster3d/getvalue.c
   grass/trunk/lib/raster3d/history.c
   grass/trunk/lib/raster3d/intio.c
   grass/trunk/lib/raster3d/keys.c
   grass/trunk/lib/raster3d/lib.dox
   grass/trunk/lib/raster3d/long.c
   grass/trunk/lib/raster3d/mapset.c
   grass/trunk/lib/raster3d/mask.c
   grass/trunk/lib/raster3d/misc.c
   grass/trunk/lib/raster3d/null.c
   grass/trunk/lib/raster3d/open.c
   grass/trunk/lib/raster3d/open2.c
   grass/trunk/lib/raster3d/param.c
   grass/trunk/lib/raster3d/putvalue.c
   grass/trunk/lib/raster3d/range.c
   grass/trunk/lib/raster3d/region.c
   grass/trunk/lib/raster3d/resample.c
   grass/trunk/lib/raster3d/volume.c
   grass/trunk/lib/raster3d/volume_layout.png
   grass/trunk/lib/raster3d/volume_layout.xcf
   grass/trunk/lib/raster3d/window.c
   grass/trunk/lib/raster3d/windowio.c
Removed:
   grass/trunk/lib/raster3d/cache.c
   grass/trunk/lib/raster3d/g3d_volume_layout.png
   grass/trunk/lib/raster3d/g3d_volume_layout.xcf
   grass/trunk/lib/raster3d/g3dalloc.c
   grass/trunk/lib/raster3d/g3dcache.c
   grass/trunk/lib/raster3d/g3dcats.c
   grass/trunk/lib/raster3d/g3dclose.c
   grass/trunk/lib/raster3d/g3dcolor.c
   grass/trunk/lib/raster3d/g3ddefaults.c
   grass/trunk/lib/raster3d/g3ddoubleio.c
   grass/trunk/lib/raster3d/g3derror.c
   grass/trunk/lib/raster3d/g3dfpxdr.c
   grass/trunk/lib/raster3d/g3dgetvalue.c
   grass/trunk/lib/raster3d/g3dhistory.c
   grass/trunk/lib/raster3d/g3dintio.c
   grass/trunk/lib/raster3d/g3dkeys.c
   grass/trunk/lib/raster3d/g3dlib.dox
   grass/trunk/lib/raster3d/g3dlong.c
   grass/trunk/lib/raster3d/g3dmapset.c
   grass/trunk/lib/raster3d/g3dmask.c
   grass/trunk/lib/raster3d/g3dmisc.c
   grass/trunk/lib/raster3d/g3dnull.c
   grass/trunk/lib/raster3d/g3dopen.c
   grass/trunk/lib/raster3d/g3dopen2.c
   grass/trunk/lib/raster3d/g3dparam.c
   grass/trunk/lib/raster3d/g3dputvalue.c
   grass/trunk/lib/raster3d/g3drange.c
   grass/trunk/lib/raster3d/g3dregion.c
   grass/trunk/lib/raster3d/g3dresample.c
   grass/trunk/lib/raster3d/g3dvolume.c
   grass/trunk/lib/raster3d/g3dwindow.c
   grass/trunk/lib/raster3d/g3dwindowio.c
Log:
raster3d: files renamed (no need for `g3d` prefix)


Copied: grass/trunk/lib/raster3d/alloc.c (from rev 47531, grass/trunk/lib/raster3d/g3dalloc.c)
===================================================================
--- grass/trunk/lib/raster3d/alloc.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/alloc.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Same as <em>malloc (nBytes)</em>, except that in case of error
+ * <tt>G3d_error()</tt> is invoked.
+ *
+ *  \param nBytes
+ *  \return void *: a pointer ... if successful,
+ * NULL ... otherwise.
+
+ */
+
+void *G3d_malloc(int nBytes)
+{
+    void *buf;
+
+    if (nBytes <= 0)
+	nBytes = 1;
+    if ((buf = malloc(nBytes)) != NULL)
+	return buf;
+
+    G3d_error("G3d_malloc: out of memory");
+    return (void *)NULL;
+}
+
+
+/*!
+ * \brief 
+ *
+ *  Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
+ *  <tt>G3d_error()</tt> is invoked. 
+ *
+ *  \param ptr
+ *  \param nBytes
+ *  \return void *: a pointer ... if successful,
+ *         NULL ... otherwise.
+ */
+
+void *G3d_realloc(void *ptr, int nBytes)
+{
+    if (nBytes <= 0)
+	nBytes = 1;
+    if ((ptr = realloc(ptr, nBytes)) != NULL)
+	return ptr;
+
+    G3d_error("G3d_realloc: out of memory");
+    return (void *)NULL;
+}
+
+
+/*!
+ * \brief 
+ *
+ *  Same as <em>free (ptr)</em>.
+ *
+ *  \param ptr
+ *  \return void
+ */
+
+void G3d_free(void *buf)
+{
+    free(buf);
+}

Deleted: grass/trunk/lib/raster3d/cache.c
===================================================================
--- grass/trunk/lib/raster3d/cache.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/cache.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,696 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <grass/G3d.h>
-#include "G3d_intern.h"
-#include "cachehash.h"
-
-/*---------------------------------------------------------------------------*/
-
-#define IS_ACTIVE_ELT(elt) (c->locks[elt] != 2)
-#define IS_NOT_ACTIVE_ELT(elt) (c->locks[elt] == 2)
-#define IS_LOCKED_ELT(elt) (c->locks[elt] == 1)
-#define IS_UNLOCKED_ELT(elt) (c->locks[elt] == 0)
-#define IS_NOT_IN_QUEUE_ELT(elt) (IS_LOCKED_ELT (elt))
-#define IS_IN_QUEUE_ELT(elt) (! IS_NOT_IN_QUEUE_ELT (elt))
-
-#define DEACTIVATE_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
-			      (c->nofUnlocked)++ : (0)), \
-			     c->locks[elt] = 2)
-#define LOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
-			(0) : (c->nofUnlocked)--), \
-		       (c->locks[elt] = 1))
-#define UNLOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
-			  (c->nofUnlocked)++ : (0)), \
-                         (c->locks[elt] = 0))
-
-#define ONE_UNLOCKED_ELT_ONLY (c->first == c->last)
-#define ARE_MIN_UNLOCKED (c->nofUnlocked <= c->minUnlocked)
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_reset(G3D_cache * c)
-{
-    int i;
-
-    for (i = 0; i < c->nofElts; i++) {
-	DEACTIVATE_ELT(i);
-	c->next[i] = i + 1;
-	c->prev[i] = i - 1;
-	c->names[i] = -1;
-    }
-
-    c->prev[0] = c->next[c->nofElts - 1] = -1;
-    c->first = 0;
-    c->last = c->nofElts - 1;
-
-    c->autoLock = 0;
-    c->nofUnlocked = c->nofElts;
-    c->minUnlocked = 1;
-
-    G3d_cache_hash_reset(c->hash);
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int cache_dummy_fun(int tileIndex, const void *tileBuf, void *map)
-{
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_dispose(G3D_cache * c)
-{
-    if (c == NULL)
-	return;
-
-    G3d_cache_hash_dispose(c->hash);
-
-    if (c->elts != NULL)
-	G3d_free(c->elts);
-    if (c->names != NULL)
-	G3d_free(c->names);
-    if (c->locks != NULL)
-	G3d_free(c->locks);
-    if (c->next != NULL)
-	G3d_free(c->next);
-    if (c->prev != NULL)
-	G3d_free(c->prev);
-
-    G3d_free(c);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void *G3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
-		    int (*eltRemoveFun) (), void *eltRemoveFunData,
-		    int (*eltLoadFun) (), void *eltLoadFunData)
-{
-    G3D_cache *tmp;
-
-    tmp = G3d_malloc(sizeof(G3D_cache));
-    if (tmp == NULL) {
-	G3d_error("G3d_cache_new: error in G3d_malloc");
-	return (void *)NULL;
-    }
-
-    tmp->hash = NULL;
-
-    tmp->nofElts = nofElts;
-    tmp->eltSize = sizeOfElts;
-    tmp->elts = G3d_malloc(tmp->eltSize * tmp->nofElts);
-    tmp->names = G3d_malloc(sizeof(int) * tmp->nofElts);
-    tmp->locks = G3d_malloc(tmp->nofElts);
-    tmp->next = G3d_malloc(sizeof(int) * tmp->nofElts);
-    tmp->prev = G3d_malloc(sizeof(int) * tmp->nofElts);
-
-    if ((tmp->elts == NULL) || (tmp->names == NULL) || (tmp->locks == NULL) ||
-	(tmp->next == NULL) || (tmp->prev == NULL)) {
-
-	G3d_cache_dispose(tmp);
-	G3d_error("G3d_cache_new: error in G3d_malloc");
-	return (void *)NULL;
-    }
-
-    tmp->eltRemoveFun = eltRemoveFun;
-    tmp->eltRemoveFunData = eltRemoveFunData;
-    tmp->eltLoadFun = eltLoadFun;
-    tmp->eltLoadFunData = eltLoadFunData;
-
-    tmp->hash = G3d_cache_hash_new(nofNames);
-    if (tmp->hash == NULL) {
-	G3d_cache_dispose(tmp);
-	G3d_error("G3d_cache_new: error in G3d_cache_hash_new");
-	return (void *)NULL;
-    }
-
-    G3d_cache_reset(tmp);
-
-    return tmp;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_cache_set_removeFun(G3D_cache * c, int (*eltRemoveFun) (),
-			void *eltRemoveFunData)
-{
-    c->eltRemoveFun = eltRemoveFun;
-    c->eltRemoveFunData = eltRemoveFunData;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_cache_set_loadFun(G3D_cache * c, int (*eltLoadFun) (),
-		      void *eltLoadFunData)
-{
-    c->eltLoadFun = eltLoadFun;
-    c->eltLoadFunData = eltLoadFunData;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void *G3d_cache_new_read(int nofElts, int sizeOfElts, int nofNames,
-			 read_fn * eltLoadFun, void *eltLoadFunData)
-{
-    return G3d_cache_new(nofElts, sizeOfElts, nofNames,
-			 cache_dummy_fun, NULL, eltLoadFun, eltLoadFunData);
-}
-
-/*---------------------------------------------------------------------------*/
-
-static void cache_queue_dequeue(G3D_cache * c, int index)
-{
-    if (IS_NOT_IN_QUEUE_ELT(index))
-	G3d_fatalError("cache_queue_dequeue: index not in queue");
-
-    if (index == c->first)
-	c->first = c->next[index];
-    if (index == c->last)
-	c->last = c->prev[index];
-
-    if (c->next[index] != -1)
-	c->prev[c->next[index]] = c->prev[index];
-    if (c->prev[index] != -1)
-	c->next[c->prev[index]] = c->next[index];
-
-    c->next[index] = c->prev[index] = -1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static void cache_queue_enqueue(G3D_cache * c, int left, int index)
-{
-    if (IS_IN_QUEUE_ELT(index))
-	G3d_fatalError("cache_queue_enqueue: index already in queue");
-
-    if (c->first == -1) {
-	if (left != c->last)
-	    G3d_fatalError("cache_queue_enqueue: position out of range");
-
-	c->first = c->last = index;
-	return;
-    }
-
-    if (IS_NOT_IN_QUEUE_ELT(left))
-	G3d_fatalError("cache_queue_enqueue: position not in queue");
-
-
-    if (left == -1) {
-	c->next[index] = c->first;
-	c->prev[c->first] = index;
-	c->first = index;
-
-	return;
-    }
-
-    c->prev[index] = left;
-
-    if (c->next[left] == -1) {
-	c->next[left] = index;
-	c->last = index;
-
-	return;
-    }
-
-    c->prev[c->next[left]] = index;
-    c->next[index] = c->next[left];
-    c->next[left] = index;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int cache_queue_get_top(G3D_cache * c)
-{
-    int top;
-
-    top = c->first;
-
-    cache_queue_dequeue(c, c->first);
-
-    return top;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static void cache_queue_append(G3D_cache * c, int index)
-{
-    cache_queue_enqueue(c, c->last, index);
-}
-
-/*---------------------------------------------------------------------------*/
-
-static void cache_queue_preppend(G3D_cache * c, int index)
-{
-    cache_queue_enqueue(c, -1, index);
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/
-
-			/* EXPORTED FUNCTIONS */
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_lock(G3D_cache * c, int name)
-{
-    int index;
-
-    index = G3d_cache_hash_name2index(c->hash, name);
-    if (index == -1) {
-	G3d_error("G3d_cache_lock: name not in cache");
-	return 0;
-    }
-
-    if (IS_LOCKED_ELT(index))
-	return 1;
-    if (ONE_UNLOCKED_ELT_ONLY)
-	return -1;
-    if (ARE_MIN_UNLOCKED)
-	return -1;
-
-    cache_queue_dequeue(c, index);
-    LOCK_ELT(index);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_lock_intern(G3D_cache * c, int index)
-{
-    if (IS_LOCKED_ELT(index))
-	return;
-
-    cache_queue_dequeue(c, index);
-    LOCK_ELT(index);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_unlock(G3D_cache * c, int name)
-{
-    int index;
-
-    index = G3d_cache_hash_name2index(c->hash, name);
-    if (index == -1) {
-	G3d_error("G3d_cache_unlock: name not in cache");
-	return 0;
-    }
-
-    if (IS_UNLOCKED_ELT(index))
-	return 1;
-
-    cache_queue_append(c, index);
-    UNLOCK_ELT(index);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_unlock_all(G3D_cache * c)
-{
-    int index;
-
-    for (index = 0; index < c->nofElts; index++)
-	if (IS_LOCKED_ELT(index))
-	    if (!G3d_cache_unlock(c, c->names[index])) {
-		G3d_error("G3d_cache_unlock_all: error in G3d_cache_unlock");
-		return 0;
-	    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_lock_all(G3D_cache * c)
-{
-    int index;
-
-    for (index = 0; index < c->nofElts; index++)
-	if (IS_UNLOCKED_ELT(index))
-	    G3d_cache_lock_intern(c, index);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_autolock_on(G3D_cache * c)
-{
-    c->autoLock = 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_autolock_off(G3D_cache * c)
-{
-    c->autoLock = 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_cache_set_minUnlock(G3D_cache * c, int nofMinUnLocked)
-{
-    c->minUnlocked = nofMinUnLocked;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int cache_remove_elt(G3D_cache * c, int name, int doFlush)
-{
-    int index;
-
-    index = G3d_cache_hash_name2index(c->hash, name);
-    if (index == -1) {
-	G3d_error("G3d_cache_deactivate_elt : name not in cache");
-	return 0;
-    }
-
-    if (IS_NOT_ACTIVE_ELT(index))
-	return 1;
-
-    if (IS_IN_QUEUE_ELT(index)) {
-	cache_queue_dequeue(c, index);
-	LOCK_ELT(index);
-    }
-
-    if (doFlush)
-	if (!c->eltRemoveFun(name, c->elts + c->eltSize * index,
-			     c->eltRemoveFunData)) {
-	    G3d_error("cache_remove_elt: error in c->eltRemoveFun");
-	    return 0;
-	}
-
-    cache_queue_preppend(c, index);
-    DEACTIVATE_ELT(index);
-
-    G3d_cache_hash_remove_name(c->hash, name);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_remove_elt(G3D_cache * c, int name)
-{
-    if (!cache_remove_elt(c, name, 0)) {
-	G3d_error("G3d_cache_remove_elt: error in cache_remove_elt");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_flush(G3D_cache * c, int name)
-{
-    if (!cache_remove_elt(c, name, 1)) {
-	G3d_error("G3d_cache_flush: error in cache_remove_elt");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_remove_all(G3D_cache * c)
-{
-    int index;
-
-    for (index = 0; index < c->nofElts; index++)
-	if (IS_ACTIVE_ELT(index))
-	    if (!G3d_cache_remove_elt(c, c->names[index])) {
-		G3d_error
-		    ("G3d_cache_remove_all: error in G3d_cache_remove_elt");
-		return 0;
-	    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_flush_all(G3D_cache * c)
-{
-    int index;
-
-    for (index = 0; index < c->nofElts; index++)
-	if (IS_ACTIVE_ELT(index))
-	    if (!G3d_cache_flush(c, c->names[index])) {
-		G3d_error("G3d_cache_flush_all: error in G3d_cache_flush");
-		return 0;
-	    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void *G3d_cache_elt_ptr(G3D_cache * c, int name)
-{
-    int index, oldName, doUnlock;
-
-    index = G3d_cache_hash_name2index(c->hash, name);
-
-    if (index != -1) {
-	if (c->autoLock)
-	    if (IS_UNLOCKED_ELT(index) && (!ONE_UNLOCKED_ELT_ONLY) &&
-		(!ARE_MIN_UNLOCKED))
-		G3d_cache_lock_intern(c, index);
-
-	return c->elts + c->eltSize * index;
-    }
-
-    index = c->first;
-    if (IS_ACTIVE_ELT(index)) {
-	oldName = c->names[index];
-	G3d_cache_hash_remove_name(c->hash, oldName);
-	if (!c->eltRemoveFun(oldName, c->elts + c->eltSize * index,
-			     c->eltRemoveFunData)) {
-	    G3d_error("G3d_cache_elt_ptr: error in c->eltRemoveFun");
-	    return NULL;
-	}
-    }
-
-    G3d_cache_hash_load_name(c->hash, name, index);
-
-    doUnlock = ((!c->autoLock) || ONE_UNLOCKED_ELT_ONLY || ARE_MIN_UNLOCKED);
-
-    UNLOCK_ELT(index);
-    c->names[index] = name;
-    G3d_cache_lock_intern(c, index);
-
-    if (doUnlock)
-	if (!G3d_cache_unlock(c, name)) {
-	    G3d_error("G3d_cache_elt_ptr: error in G3d_cache_unlock");
-	    return NULL;
-	}
-
-    if (!c->eltLoadFun(name, c->elts + c->eltSize * index, c->eltLoadFunData)) {
-	G3d_error("G3d_cache_elt_ptr: error in c->eltLoadFun");
-	return NULL;
-    }
-
-    return c->elts + c->eltSize * index;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_load(G3D_cache * c, int name)
-{
-    if (G3d_cache_elt_ptr(c, name) == NULL) {
-	G3d_error("G3d_cache_load: error in G3d_cache_elt_ptr");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_get_elt(G3D_cache * c, int name, void *dst)
-{
-    const void *elt;
-
-    elt = G3d_cache_elt_ptr(c, name);
-    if (elt == NULL) {
-	G3d_error("G3d_cache_get_elt: error in G3d_cache_elt_ptr");
-	return 0;
-    }
-
-    memcpy(dst, elt, c->eltSize);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_cache_put_elt(G3D_cache * c, int name, const void *src)
-{
-    void *elt;
-
-    elt = G3d_cache_elt_ptr(c, name);
-    if (elt == NULL) {
-	G3d_error("G3d_cache_put_elt: error in G3d_cache_elt_ptr");
-	return 0;
-    }
-
-    memcpy(elt, src, c->eltSize);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/
-
-			/* TEST FUNCTIONS */
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/
-
-static void cache_test_print(G3D_cache * c)
-{
-    int i, al;
-    int *a;
-
-    al = c->autoLock;
-    G3d_cache_autolock_off(c);
-
-    printf("\n--------------------------------\n");
-    for (i = 0; i < c->nofElts; i++) {
-	printf("elt %d: ", i);
-	if (IS_NOT_ACTIVE_ELT(i)) {
-	    printf("na\n");
-	    continue;
-	}
-
-	a = (int *)G3d_cache_elt_ptr(c, c->names[i]);
-	/*G3d_cache_get_elt (c, c->names[i], a); */
-	printf("name %d val %d %s\n", c->names[i], a[17],
-	       (IS_LOCKED_ELT(i) ? "locked" :
-		IS_UNLOCKED_ELT(i) ? "unlocked" : ""));
-    }
-    printf("\n--------------------------------\n");
-
-    if (al)
-	G3d_cache_autolock_on(c);
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int cache_test_flush_fun(int name, const void *eltPtr, void *data)
-{
-    printf("flushing name %d value %d\n", name, ((const int *)eltPtr)[17]);
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-typedef struct
-{
-
-    int *value;
-    int size;
-
-} cache_test_data_type;
-
-static int cache_test_load_fun(int name, void *eltPtr, void *data)
-{
-    const void *src;
-
-    printf("loading name %d value %d\n", name,
-	   ((cache_test_data_type *) data)->value[17]);
-
-    src = ((cache_test_data_type *) data)->value;
-    memcpy(eltPtr, src, ((cache_test_data_type *) data)->size);
-
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static cache_test_data_type ctd;
-
-static void cache_test_add(void *c, int name, int val)
-{
-    static int firstTime = 1;
-
-    if (firstTime) {
-	ctd.value = G3d_malloc(((G3D_cache *) c)->eltSize * sizeof(int));
-	firstTime = 0;
-    }
-
-    ctd.value[17] = val;
-    ctd.size = ((G3D_cache *) c)->eltSize;
-
-    G3d_cache_load(c, name);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int MAIN()
-{
-    void *c;
-
-    c = G3d_cache_new(3, 76 * sizeof(int), 100000,
-		      cache_test_flush_fun, NULL, cache_test_load_fun, &ctd);
-
-    G3d_cache_autolock_on(c);
-    cache_test_print(c);
-    cache_test_add(c, 1111, -11);
-    cache_test_print(c);
-    cache_test_add(c, 2222, -22);
-    cache_test_print(c);
-    cache_test_add(c, 3333, -33);
-    cache_test_print(c);
-    cache_test_add(c, 4444, -44);
-    cache_test_print(c);
-    G3d_cache_unlock_all(c);
-    cache_test_print(c);
-    G3d_cache_load(c, 2222);
-    cache_test_print(c);
-    cache_test_add(c, 5555, -55);
-    cache_test_print(c);
-    cache_test_add(c, 6666, -66);
-    cache_test_print(c);
-    cache_test_add(c, 7777, -77);
-    cache_test_print(c);
-    cache_test_add(c, 8888, -88);
-    cache_test_print(c);
-    cache_test_add(c, 9999, -99);
-    cache_test_print(c);
-    G3d_cache_flush(c, 9999);
-    cache_test_print(c);
-    G3d_cache_flush_all(c);
-    cache_test_print(c);
-    cache_test_add(c, 1111, -11);
-    cache_test_print(c);
-    cache_test_add(c, 2222, -22);
-    cache_test_print(c);
-    cache_test_add(c, 3333, -33);
-    cache_test_print(c);
-    G3d_cache_reset(c);
-    cache_test_print(c);
-    cache_test_add(c, 1111, -11);
-    cache_test_print(c);
-    cache_test_add(c, 2222, -22);
-    cache_test_print(c);
-    cache_test_add(c, 3333, -33);
-    cache_test_print(c);
-
-    return 0;
-}

Copied: grass/trunk/lib/raster3d/cache.c (from rev 47531, grass/trunk/lib/raster3d/g3dcache.c)
===================================================================
--- grass/trunk/lib/raster3d/cache.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/cache.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,330 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+static int cacheRead_readFun(int tileIndex, void *tileBuf, void *closure)
+{
+    G3D_Map *map = closure;
+
+    if (!G3d_readTile(map, tileIndex, tileBuf, map->typeIntern)) {
+	G3d_error("cacheRead_readFun: error in G3d_readTile");
+	return 0;
+    }
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int initCacheRead(G3D_Map * map, int nCached)
+{
+    map->cache = G3d_cache_new_read(nCached,
+				    map->tileSize * map->numLengthIntern,
+				    map->nTiles, cacheRead_readFun, map);
+    if (map->cache == NULL) {
+	G3d_error("initCacheRead: error in G3d_cache_new_read");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*
+   the map->index array is (ab)used to store the positions of the tiles in the 
+   file-cash. we can do this since we maintain the invariant for every tile 
+   that it is either in no file (index == -1) or in either the output-file
+   (index >= 0) or the cash-file (index <= -2). to convert the file-position in 
+   the cash-file into an index we use the following function:
+
+   index = - (fileposition + 2)
+
+   symmetrically, we use
+
+   fileposition = - (index + 2)
+
+   to convert from index to the fileposition.
+ */
+
+/*---------------------------------------------------------------------------*/
+
+static int cacheWrite_readFun(int tileIndex, void *tileBuf, void *closure)
+{
+    G3D_Map *map = closure;
+    int index, nBytes;
+    long pos, offs, offsLast;
+
+    pos = map->index[tileIndex];
+
+    /* tile has already been flushed onto output file or does not exist yet */
+    if (pos >= -1) {		/* note, G3d_readTile takes care of the case pos == -1 */
+	G3d_readTile(map, tileIndex, tileBuf, map->typeIntern);
+	return 1;
+    }
+
+    /* tile is in cache file */
+
+    pos = -pos - 2;		/* pos is shifted by 2 to avoid 0 and -1 */
+
+    nBytes = map->tileSize * map->numLengthIntern;
+    offs = pos * (nBytes + sizeof(int));
+
+    /* seek tile and read it into buffer */
+
+    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
+	G3d_error("cacheWrite_readFun: can't position file");
+	return 0;
+    }
+    if (read(map->cacheFD, tileBuf, nBytes) != nBytes) {
+	G3d_error("cacheWrite_readFun: can't read file");
+	return 0;
+    }
+
+    /* remove it from index */
+
+    map->index[tileIndex] = -1;
+
+    /* if it is the last tile in the file we are done */
+    /* map->cachePosLast tells us the position of the last tile in the file */
+
+    if (map->cachePosLast == pos) {
+	map->cachePosLast--;
+	return 1;
+    }
+
+    /* otherwise we move the last tile in the file into the position of */
+    /* the tile we just read and update the hash information */
+
+    offsLast = map->cachePosLast * (nBytes + sizeof(int));
+
+    if (lseek(map->cacheFD, offsLast, SEEK_SET) == -1) {
+	G3d_error("cacheWrite_readFun: can't position file");
+	return 0;
+    }
+    if (read(map->cacheFD, xdr, nBytes + sizeof(int)) != nBytes + sizeof(int)) {
+	G3d_error("cacheWrite_readFun: can't read file");
+	return 0;
+    }
+
+    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
+	G3d_error("cacheWrite_readFun: can't position file");
+	return 0;
+    }
+    if (write(map->cacheFD, xdr, nBytes + sizeof(int)) !=
+	nBytes + sizeof(int)) {
+	G3d_error("cacheWrite_readFun: can't write file");
+	return 0;
+    }
+
+    index = *((int *)((unsigned char *)xdr + nBytes));
+    map->index[index] = -pos - 2;
+
+    map->cachePosLast--;
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int
+cacheWrite_writeFun(int tileIndex, const void *tileBuf, void *closure)
+{
+    G3D_Map *map = closure;
+    int nBytes;
+    long offs;
+
+    if (map->index[tileIndex] != -1)
+	return 1;
+
+    map->cachePosLast++;
+    nBytes = map->tileSize * map->numLengthIntern;
+    offs = map->cachePosLast * (nBytes + sizeof(int));
+
+    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
+	G3d_error("cacheWrite_writeFun: can't position file");
+	return 0;
+    }
+    if (write(map->cacheFD, tileBuf, nBytes) != nBytes) {
+	G3d_error("cacheWrite_writeFun: can't write file");
+	return 0;
+    }
+    if (write(map->cacheFD, &tileIndex, sizeof(int)) != sizeof(int)) {
+	G3d_error("cacheWrite_writeFun: can't write file");
+	return 0;
+    }
+
+    map->index[tileIndex] = -map->cachePosLast - 2;
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int disposeCacheWrite(G3D_Map * map)
+{
+    if (map->cacheFD >= 0) {
+	if (close(map->cacheFD) != 0) {
+	    G3d_error("disposeCacheWrite: could not close file");
+	    return 0;
+	}
+	remove(map->cacheFileName);
+	G3d_free(map->cacheFileName);
+    }
+
+    G3d_cache_dispose(map->cache);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int initCacheWrite(G3D_Map * map, int nCached)
+{
+    map->cacheFileName = G_tempfile();
+    map->cacheFD = open(map->cacheFileName, O_RDWR | O_CREAT | O_TRUNC, 0666);
+
+    if (map->cacheFD < 0) {
+	G3d_error("initCacheWrite: could not open file");
+	return 0;
+    }
+
+    map->cachePosLast = -1;
+
+    map->cache = G3d_cache_new(nCached,
+			       map->tileSize * map->numLengthIntern,
+			       map->nTiles,
+			       cacheWrite_writeFun, map,
+			       cacheWrite_readFun, map);
+
+    if (map->cache == NULL) {
+	disposeCacheWrite(map);
+	G3d_error("initCacheWrite: error in G3d_cache_new");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_initCache(G3D_Map * map, int nCached)
+{
+    if (map->operation == G3D_READ_DATA) {
+	if (!initCacheRead(map, nCached)) {
+	    G3d_error("G3d_initCache: error in initCacheRead");
+	    return 0;
+	}
+	return 1;
+    }
+
+    if (!initCacheWrite(map, nCached)) {
+	G3d_error("G3d_initCache: error in initCacheWrite");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int disposeCacheRead(G3D_Map * map)
+{
+    G3d_cache_dispose(map->cache);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_disposeCache(G3D_Map * map)
+{
+    if (map->operation == G3D_READ_DATA) {
+	if (!disposeCacheRead(map)) {
+	    G3d_error("G3d_disposeCache: error in disposeCacheRead");
+	    return 0;
+	}
+	return 1;
+    }
+
+    if (!disposeCacheWrite(map)) {
+	G3d_error("G3d_disposeCache: error in disposeCacheWrite");
+	return 0;
+    }
+
+    return 1;
+}
+
+
+/*---------------------------------------------------------------------------*/
+
+static int cacheFlushFun(int tileIndex, const void *tileBuf, void *closure)
+{
+    G3D_Map *map = closure;
+
+    if (!G3d_writeTile(map, tileIndex, tileBuf, map->typeIntern)) {
+	G3d_error("cacheFlushFun: error in G3d_writeTile");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_flushAllTiles(G3D_Map * map)
+{
+    int tileIndex, nBytes;
+    long offs;
+
+    if (map->operation == G3D_READ_DATA) {
+	if (!G3d_cache_remove_all(map->cache)) {
+	    G3d_error("G3d_flushAllTiles: error in G3d_cache_remove_all");
+	    return 0;
+	}
+	return 1;
+    }
+
+    /* make cache write into output file instead of cache file */
+    G3d_cache_set_removeFun(map->cache, cacheFlushFun, map);
+
+    /* first flush all the tiles which are in the file cache */
+
+    nBytes = map->tileSize * map->numLengthIntern;
+
+    while (map->cachePosLast >= 0) {
+	offs = map->cachePosLast * (nBytes + sizeof(int)) + nBytes;
+
+	if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
+	    G3d_error("G3d_flushAllTiles: can't position file");
+	    return 0;
+	}
+	if (read(map->cacheFD, &tileIndex, sizeof(int)) != sizeof(int)) {
+	    G3d_error("G3d_flushAllTiles: can't read file");
+	    return 0;
+	}
+
+	if (!G3d_cache_load(map->cache, tileIndex)) {
+	    G3d_error("G3d_flushAllTiles: error in G3d_cache_load");
+	    return 0;
+	}
+	if (!G3d_cache_flush(map->cache, tileIndex)) {
+	    G3d_error("G3d_flushAllTiles: error in G3d_cache_flush");
+	    return 0;
+	}
+    }
+
+    /* then flush all the tiles which remain in the non-file cache */
+    if (!G3d_cache_flush_all(map->cache)) {
+	G3d_error("G3d_flushAllTiles: error in G3d_cache_flush_all");
+	return 0;
+    }
+
+    /* now the cache should write into the cache file again */
+    G3d_cache_set_removeFun(map->cache, cacheWrite_writeFun, map);
+
+    return 1;
+}

Copied: grass/trunk/lib/raster3d/cache1.c (from rev 47531, grass/trunk/lib/raster3d/cache.c)
===================================================================
--- grass/trunk/lib/raster3d/cache1.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/cache1.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,696 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <grass/G3d.h>
+#include "G3d_intern.h"
+#include "cachehash.h"
+
+/*---------------------------------------------------------------------------*/
+
+#define IS_ACTIVE_ELT(elt) (c->locks[elt] != 2)
+#define IS_NOT_ACTIVE_ELT(elt) (c->locks[elt] == 2)
+#define IS_LOCKED_ELT(elt) (c->locks[elt] == 1)
+#define IS_UNLOCKED_ELT(elt) (c->locks[elt] == 0)
+#define IS_NOT_IN_QUEUE_ELT(elt) (IS_LOCKED_ELT (elt))
+#define IS_IN_QUEUE_ELT(elt) (! IS_NOT_IN_QUEUE_ELT (elt))
+
+#define DEACTIVATE_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
+			      (c->nofUnlocked)++ : (0)), \
+			     c->locks[elt] = 2)
+#define LOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
+			(0) : (c->nofUnlocked)--), \
+		       (c->locks[elt] = 1))
+#define UNLOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
+			  (c->nofUnlocked)++ : (0)), \
+                         (c->locks[elt] = 0))
+
+#define ONE_UNLOCKED_ELT_ONLY (c->first == c->last)
+#define ARE_MIN_UNLOCKED (c->nofUnlocked <= c->minUnlocked)
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_reset(G3D_cache * c)
+{
+    int i;
+
+    for (i = 0; i < c->nofElts; i++) {
+	DEACTIVATE_ELT(i);
+	c->next[i] = i + 1;
+	c->prev[i] = i - 1;
+	c->names[i] = -1;
+    }
+
+    c->prev[0] = c->next[c->nofElts - 1] = -1;
+    c->first = 0;
+    c->last = c->nofElts - 1;
+
+    c->autoLock = 0;
+    c->nofUnlocked = c->nofElts;
+    c->minUnlocked = 1;
+
+    G3d_cache_hash_reset(c->hash);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int cache_dummy_fun(int tileIndex, const void *tileBuf, void *map)
+{
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_dispose(G3D_cache * c)
+{
+    if (c == NULL)
+	return;
+
+    G3d_cache_hash_dispose(c->hash);
+
+    if (c->elts != NULL)
+	G3d_free(c->elts);
+    if (c->names != NULL)
+	G3d_free(c->names);
+    if (c->locks != NULL)
+	G3d_free(c->locks);
+    if (c->next != NULL)
+	G3d_free(c->next);
+    if (c->prev != NULL)
+	G3d_free(c->prev);
+
+    G3d_free(c);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void *G3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
+		    int (*eltRemoveFun) (), void *eltRemoveFunData,
+		    int (*eltLoadFun) (), void *eltLoadFunData)
+{
+    G3D_cache *tmp;
+
+    tmp = G3d_malloc(sizeof(G3D_cache));
+    if (tmp == NULL) {
+	G3d_error("G3d_cache_new: error in G3d_malloc");
+	return (void *)NULL;
+    }
+
+    tmp->hash = NULL;
+
+    tmp->nofElts = nofElts;
+    tmp->eltSize = sizeOfElts;
+    tmp->elts = G3d_malloc(tmp->eltSize * tmp->nofElts);
+    tmp->names = G3d_malloc(sizeof(int) * tmp->nofElts);
+    tmp->locks = G3d_malloc(tmp->nofElts);
+    tmp->next = G3d_malloc(sizeof(int) * tmp->nofElts);
+    tmp->prev = G3d_malloc(sizeof(int) * tmp->nofElts);
+
+    if ((tmp->elts == NULL) || (tmp->names == NULL) || (tmp->locks == NULL) ||
+	(tmp->next == NULL) || (tmp->prev == NULL)) {
+
+	G3d_cache_dispose(tmp);
+	G3d_error("G3d_cache_new: error in G3d_malloc");
+	return (void *)NULL;
+    }
+
+    tmp->eltRemoveFun = eltRemoveFun;
+    tmp->eltRemoveFunData = eltRemoveFunData;
+    tmp->eltLoadFun = eltLoadFun;
+    tmp->eltLoadFunData = eltLoadFunData;
+
+    tmp->hash = G3d_cache_hash_new(nofNames);
+    if (tmp->hash == NULL) {
+	G3d_cache_dispose(tmp);
+	G3d_error("G3d_cache_new: error in G3d_cache_hash_new");
+	return (void *)NULL;
+    }
+
+    G3d_cache_reset(tmp);
+
+    return tmp;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_cache_set_removeFun(G3D_cache * c, int (*eltRemoveFun) (),
+			void *eltRemoveFunData)
+{
+    c->eltRemoveFun = eltRemoveFun;
+    c->eltRemoveFunData = eltRemoveFunData;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_cache_set_loadFun(G3D_cache * c, int (*eltLoadFun) (),
+		      void *eltLoadFunData)
+{
+    c->eltLoadFun = eltLoadFun;
+    c->eltLoadFunData = eltLoadFunData;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void *G3d_cache_new_read(int nofElts, int sizeOfElts, int nofNames,
+			 read_fn * eltLoadFun, void *eltLoadFunData)
+{
+    return G3d_cache_new(nofElts, sizeOfElts, nofNames,
+			 cache_dummy_fun, NULL, eltLoadFun, eltLoadFunData);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void cache_queue_dequeue(G3D_cache * c, int index)
+{
+    if (IS_NOT_IN_QUEUE_ELT(index))
+	G3d_fatalError("cache_queue_dequeue: index not in queue");
+
+    if (index == c->first)
+	c->first = c->next[index];
+    if (index == c->last)
+	c->last = c->prev[index];
+
+    if (c->next[index] != -1)
+	c->prev[c->next[index]] = c->prev[index];
+    if (c->prev[index] != -1)
+	c->next[c->prev[index]] = c->next[index];
+
+    c->next[index] = c->prev[index] = -1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void cache_queue_enqueue(G3D_cache * c, int left, int index)
+{
+    if (IS_IN_QUEUE_ELT(index))
+	G3d_fatalError("cache_queue_enqueue: index already in queue");
+
+    if (c->first == -1) {
+	if (left != c->last)
+	    G3d_fatalError("cache_queue_enqueue: position out of range");
+
+	c->first = c->last = index;
+	return;
+    }
+
+    if (IS_NOT_IN_QUEUE_ELT(left))
+	G3d_fatalError("cache_queue_enqueue: position not in queue");
+
+
+    if (left == -1) {
+	c->next[index] = c->first;
+	c->prev[c->first] = index;
+	c->first = index;
+
+	return;
+    }
+
+    c->prev[index] = left;
+
+    if (c->next[left] == -1) {
+	c->next[left] = index;
+	c->last = index;
+
+	return;
+    }
+
+    c->prev[c->next[left]] = index;
+    c->next[index] = c->next[left];
+    c->next[left] = index;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int cache_queue_get_top(G3D_cache * c)
+{
+    int top;
+
+    top = c->first;
+
+    cache_queue_dequeue(c, c->first);
+
+    return top;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void cache_queue_append(G3D_cache * c, int index)
+{
+    cache_queue_enqueue(c, c->last, index);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void cache_queue_preppend(G3D_cache * c, int index)
+{
+    cache_queue_enqueue(c, -1, index);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+
+			/* EXPORTED FUNCTIONS */
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_lock(G3D_cache * c, int name)
+{
+    int index;
+
+    index = G3d_cache_hash_name2index(c->hash, name);
+    if (index == -1) {
+	G3d_error("G3d_cache_lock: name not in cache");
+	return 0;
+    }
+
+    if (IS_LOCKED_ELT(index))
+	return 1;
+    if (ONE_UNLOCKED_ELT_ONLY)
+	return -1;
+    if (ARE_MIN_UNLOCKED)
+	return -1;
+
+    cache_queue_dequeue(c, index);
+    LOCK_ELT(index);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_lock_intern(G3D_cache * c, int index)
+{
+    if (IS_LOCKED_ELT(index))
+	return;
+
+    cache_queue_dequeue(c, index);
+    LOCK_ELT(index);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_unlock(G3D_cache * c, int name)
+{
+    int index;
+
+    index = G3d_cache_hash_name2index(c->hash, name);
+    if (index == -1) {
+	G3d_error("G3d_cache_unlock: name not in cache");
+	return 0;
+    }
+
+    if (IS_UNLOCKED_ELT(index))
+	return 1;
+
+    cache_queue_append(c, index);
+    UNLOCK_ELT(index);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_unlock_all(G3D_cache * c)
+{
+    int index;
+
+    for (index = 0; index < c->nofElts; index++)
+	if (IS_LOCKED_ELT(index))
+	    if (!G3d_cache_unlock(c, c->names[index])) {
+		G3d_error("G3d_cache_unlock_all: error in G3d_cache_unlock");
+		return 0;
+	    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_lock_all(G3D_cache * c)
+{
+    int index;
+
+    for (index = 0; index < c->nofElts; index++)
+	if (IS_UNLOCKED_ELT(index))
+	    G3d_cache_lock_intern(c, index);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_autolock_on(G3D_cache * c)
+{
+    c->autoLock = 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_autolock_off(G3D_cache * c)
+{
+    c->autoLock = 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_cache_set_minUnlock(G3D_cache * c, int nofMinUnLocked)
+{
+    c->minUnlocked = nofMinUnLocked;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int cache_remove_elt(G3D_cache * c, int name, int doFlush)
+{
+    int index;
+
+    index = G3d_cache_hash_name2index(c->hash, name);
+    if (index == -1) {
+	G3d_error("G3d_cache_deactivate_elt : name not in cache");
+	return 0;
+    }
+
+    if (IS_NOT_ACTIVE_ELT(index))
+	return 1;
+
+    if (IS_IN_QUEUE_ELT(index)) {
+	cache_queue_dequeue(c, index);
+	LOCK_ELT(index);
+    }
+
+    if (doFlush)
+	if (!c->eltRemoveFun(name, c->elts + c->eltSize * index,
+			     c->eltRemoveFunData)) {
+	    G3d_error("cache_remove_elt: error in c->eltRemoveFun");
+	    return 0;
+	}
+
+    cache_queue_preppend(c, index);
+    DEACTIVATE_ELT(index);
+
+    G3d_cache_hash_remove_name(c->hash, name);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_remove_elt(G3D_cache * c, int name)
+{
+    if (!cache_remove_elt(c, name, 0)) {
+	G3d_error("G3d_cache_remove_elt: error in cache_remove_elt");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_flush(G3D_cache * c, int name)
+{
+    if (!cache_remove_elt(c, name, 1)) {
+	G3d_error("G3d_cache_flush: error in cache_remove_elt");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_remove_all(G3D_cache * c)
+{
+    int index;
+
+    for (index = 0; index < c->nofElts; index++)
+	if (IS_ACTIVE_ELT(index))
+	    if (!G3d_cache_remove_elt(c, c->names[index])) {
+		G3d_error
+		    ("G3d_cache_remove_all: error in G3d_cache_remove_elt");
+		return 0;
+	    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_flush_all(G3D_cache * c)
+{
+    int index;
+
+    for (index = 0; index < c->nofElts; index++)
+	if (IS_ACTIVE_ELT(index))
+	    if (!G3d_cache_flush(c, c->names[index])) {
+		G3d_error("G3d_cache_flush_all: error in G3d_cache_flush");
+		return 0;
+	    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void *G3d_cache_elt_ptr(G3D_cache * c, int name)
+{
+    int index, oldName, doUnlock;
+
+    index = G3d_cache_hash_name2index(c->hash, name);
+
+    if (index != -1) {
+	if (c->autoLock)
+	    if (IS_UNLOCKED_ELT(index) && (!ONE_UNLOCKED_ELT_ONLY) &&
+		(!ARE_MIN_UNLOCKED))
+		G3d_cache_lock_intern(c, index);
+
+	return c->elts + c->eltSize * index;
+    }
+
+    index = c->first;
+    if (IS_ACTIVE_ELT(index)) {
+	oldName = c->names[index];
+	G3d_cache_hash_remove_name(c->hash, oldName);
+	if (!c->eltRemoveFun(oldName, c->elts + c->eltSize * index,
+			     c->eltRemoveFunData)) {
+	    G3d_error("G3d_cache_elt_ptr: error in c->eltRemoveFun");
+	    return NULL;
+	}
+    }
+
+    G3d_cache_hash_load_name(c->hash, name, index);
+
+    doUnlock = ((!c->autoLock) || ONE_UNLOCKED_ELT_ONLY || ARE_MIN_UNLOCKED);
+
+    UNLOCK_ELT(index);
+    c->names[index] = name;
+    G3d_cache_lock_intern(c, index);
+
+    if (doUnlock)
+	if (!G3d_cache_unlock(c, name)) {
+	    G3d_error("G3d_cache_elt_ptr: error in G3d_cache_unlock");
+	    return NULL;
+	}
+
+    if (!c->eltLoadFun(name, c->elts + c->eltSize * index, c->eltLoadFunData)) {
+	G3d_error("G3d_cache_elt_ptr: error in c->eltLoadFun");
+	return NULL;
+    }
+
+    return c->elts + c->eltSize * index;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_load(G3D_cache * c, int name)
+{
+    if (G3d_cache_elt_ptr(c, name) == NULL) {
+	G3d_error("G3d_cache_load: error in G3d_cache_elt_ptr");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_get_elt(G3D_cache * c, int name, void *dst)
+{
+    const void *elt;
+
+    elt = G3d_cache_elt_ptr(c, name);
+    if (elt == NULL) {
+	G3d_error("G3d_cache_get_elt: error in G3d_cache_elt_ptr");
+	return 0;
+    }
+
+    memcpy(dst, elt, c->eltSize);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_cache_put_elt(G3D_cache * c, int name, const void *src)
+{
+    void *elt;
+
+    elt = G3d_cache_elt_ptr(c, name);
+    if (elt == NULL) {
+	G3d_error("G3d_cache_put_elt: error in G3d_cache_elt_ptr");
+	return 0;
+    }
+
+    memcpy(elt, src, c->eltSize);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+
+			/* TEST FUNCTIONS */
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+
+static void cache_test_print(G3D_cache * c)
+{
+    int i, al;
+    int *a;
+
+    al = c->autoLock;
+    G3d_cache_autolock_off(c);
+
+    printf("\n--------------------------------\n");
+    for (i = 0; i < c->nofElts; i++) {
+	printf("elt %d: ", i);
+	if (IS_NOT_ACTIVE_ELT(i)) {
+	    printf("na\n");
+	    continue;
+	}
+
+	a = (int *)G3d_cache_elt_ptr(c, c->names[i]);
+	/*G3d_cache_get_elt (c, c->names[i], a); */
+	printf("name %d val %d %s\n", c->names[i], a[17],
+	       (IS_LOCKED_ELT(i) ? "locked" :
+		IS_UNLOCKED_ELT(i) ? "unlocked" : ""));
+    }
+    printf("\n--------------------------------\n");
+
+    if (al)
+	G3d_cache_autolock_on(c);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int cache_test_flush_fun(int name, const void *eltPtr, void *data)
+{
+    printf("flushing name %d value %d\n", name, ((const int *)eltPtr)[17]);
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+typedef struct
+{
+
+    int *value;
+    int size;
+
+} cache_test_data_type;
+
+static int cache_test_load_fun(int name, void *eltPtr, void *data)
+{
+    const void *src;
+
+    printf("loading name %d value %d\n", name,
+	   ((cache_test_data_type *) data)->value[17]);
+
+    src = ((cache_test_data_type *) data)->value;
+    memcpy(eltPtr, src, ((cache_test_data_type *) data)->size);
+
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static cache_test_data_type ctd;
+
+static void cache_test_add(void *c, int name, int val)
+{
+    static int firstTime = 1;
+
+    if (firstTime) {
+	ctd.value = G3d_malloc(((G3D_cache *) c)->eltSize * sizeof(int));
+	firstTime = 0;
+    }
+
+    ctd.value[17] = val;
+    ctd.size = ((G3D_cache *) c)->eltSize;
+
+    G3d_cache_load(c, name);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int MAIN()
+{
+    void *c;
+
+    c = G3d_cache_new(3, 76 * sizeof(int), 100000,
+		      cache_test_flush_fun, NULL, cache_test_load_fun, &ctd);
+
+    G3d_cache_autolock_on(c);
+    cache_test_print(c);
+    cache_test_add(c, 1111, -11);
+    cache_test_print(c);
+    cache_test_add(c, 2222, -22);
+    cache_test_print(c);
+    cache_test_add(c, 3333, -33);
+    cache_test_print(c);
+    cache_test_add(c, 4444, -44);
+    cache_test_print(c);
+    G3d_cache_unlock_all(c);
+    cache_test_print(c);
+    G3d_cache_load(c, 2222);
+    cache_test_print(c);
+    cache_test_add(c, 5555, -55);
+    cache_test_print(c);
+    cache_test_add(c, 6666, -66);
+    cache_test_print(c);
+    cache_test_add(c, 7777, -77);
+    cache_test_print(c);
+    cache_test_add(c, 8888, -88);
+    cache_test_print(c);
+    cache_test_add(c, 9999, -99);
+    cache_test_print(c);
+    G3d_cache_flush(c, 9999);
+    cache_test_print(c);
+    G3d_cache_flush_all(c);
+    cache_test_print(c);
+    cache_test_add(c, 1111, -11);
+    cache_test_print(c);
+    cache_test_add(c, 2222, -22);
+    cache_test_print(c);
+    cache_test_add(c, 3333, -33);
+    cache_test_print(c);
+    G3d_cache_reset(c);
+    cache_test_print(c);
+    cache_test_add(c, 1111, -11);
+    cache_test_print(c);
+    cache_test_add(c, 2222, -22);
+    cache_test_print(c);
+    cache_test_add(c, 3333, -33);
+    cache_test_print(c);
+
+    return 0;
+}

Copied: grass/trunk/lib/raster3d/cats.c (from rev 47531, grass/trunk/lib/raster3d/g3dcats.c)
===================================================================
--- grass/trunk/lib/raster3d/cats.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/cats.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,198 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Writes the
+ * categories stored in the <em>cats</em> structure into the categories file for
+ * map <em>name</em> in the current mapset.  See <em>Rast_write_cats</em>
+ * (Raster_Category_File) for details and return values.
+ *
+ *  \param name
+ *  \param cats
+ *  \return int
+ */
+
+int G3d_writeCats(const char *name, struct Categories *cats)
+ /* adapted from Rast_write_cats */
+{
+    FILE *fd;
+    int i;
+    const char *descr;
+    DCELL val1, val2;
+    char str1[100], str2[100];
+
+    fd = G_fopen_new_misc(G3D_DIRECTORY, G3D_CATS_ELEMENT, name);
+    if (!fd)
+	return -1;
+
+    /* write # cats - note # indicate 3.0 or later */
+    fprintf(fd, "# %ld categories\n", (long)cats->num);
+
+    /* title */
+    fprintf(fd, "%s\n", cats->title != NULL ? cats->title : "");
+
+    /* write format and coefficients */
+    fprintf(fd, "%s\n", cats->fmt != NULL ? cats->fmt : "");
+    fprintf(fd, "%.2f %.2f %.2f %.2f\n",
+	    cats->m1, cats->a1, cats->m2, cats->a2);
+
+    /* write the cat numbers:label */
+    for (i = 0; i < Rast_quant_nof_rules(&cats->q); i++) {
+	descr = Rast_get_ith_d_cat(cats, i, &val1, &val2);
+	if ((cats->fmt && cats->fmt[0]) || (descr && descr[0])) {
+	    if (val1 == val2) {
+		sprintf(str1, "%.10f", val1);
+		G_trim_decimal(str1);
+		fprintf(fd, "%s:%s\n", str1, descr != NULL ? descr : "");
+	    }
+	    else {
+		sprintf(str1, "%.10f", val1);
+		G_trim_decimal(str1);
+		sprintf(str2, "%.10f", val2);
+		G_trim_decimal(str2);
+		fprintf(fd, "%s:%s:%s\n", str1, str2,
+			descr != NULL ? descr : "");
+	    }
+	}
+    }
+    fclose(fd);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int
+read_cats(const char *name, const char *mapset, struct Categories *pcats)
+ /* adapted from G__read_cats */
+{
+    FILE *fd;
+    char buff[1024];
+    CELL cat;
+    DCELL val1, val2;
+    int old;
+    long num = -1;
+
+    fd = G_fopen_old_misc(G3D_DIRECTORY, G3D_CATS_ELEMENT, name, mapset);
+    if (!fd)
+	return -2;
+
+    /* Read the number of categories */
+    if (G_getl(buff, sizeof(buff), fd) == 0)
+	goto error;
+
+    if (sscanf(buff, "# %ld", &num) == 1)
+	old = 0;
+    else if (sscanf(buff, "%ld", &num) == 1)
+	old = 1;
+
+    /* Read the title for the file */
+    if (G_getl(buff, sizeof(buff), fd) == 0)
+	goto error;
+    G_strip(buff);
+
+    Rast_init_cats(buff, pcats);
+    if (num >= 0)
+	pcats->num = num;
+
+    if (!old) {
+	char fmt[256];
+	float m1, a1, m2, a2;
+
+	if (G_getl(fmt, sizeof(fmt), fd) == 0)
+	    goto error;
+	/* next line contains equation coefficients */
+	if (G_getl(buff, sizeof(buff), fd) == 0)
+	    goto error;
+	if (sscanf(buff, "%f %f %f %f", &m1, &a1, &m2, &a2) != 4)
+	    goto error;
+	Rast_set_cats_fmt(fmt, m1, a1, m2, a2, pcats);
+    }
+
+    /* Read all category names */
+    for (cat = 0;; cat++) {
+	char label[1024];
+
+	if (G_getl(buff, sizeof(buff), fd) == 0)
+	    break;
+
+	if (old)
+	    Rast_set_c_cat(&cat, &cat, buff, pcats);
+	else {
+	    *label = 0;
+	    if (sscanf(buff, "%1s", label) != 1)
+		continue;
+	    if (*label == '#')
+		continue;
+	    *label = 0;
+
+	    /* try to read a range of data */
+	    if (sscanf(buff, "%lf:%lf:%[^\n]", &val1, &val2, label) == 3)
+		Rast_set_cat(&val1, &val2, label, pcats, DCELL_TYPE);
+	    else if (sscanf(buff, "%d:%[^\n]", &cat, label) >= 1)
+		Rast_set_cat(&cat, &cat, label, pcats, CELL_TYPE);
+	    else if (sscanf(buff, "%lf:%[^\n]", &val1, label) >= 1)
+		Rast_set_cat(&val1, &val1, label, pcats, DCELL_TYPE);
+	    else
+		goto error;
+	}
+    }
+
+    fclose(fd);
+    return 0;
+
+  error:
+    fclose(fd);
+    return -1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Reads the categories file for map <em>name</em> in <em>mapset</em> and
+ * stores the categories in the <em>pcats</em> structure.  See <em>Rast_read_cats</em>
+ * (Raster_Category_File) for details and return values.
+ *
+ *  \param name
+ *  \param mapset
+ *  \param pcats
+ *  \return int
+ */
+
+int
+G3d_readCats(const char *name, const char *mapset, struct Categories *pcats)
+ /* adapted from Rast_read_cats */
+{
+    const char *type;
+
+    switch (read_cats(name, mapset, pcats)) {
+    case -2:
+	type = "missing";
+	break;
+    case -1:
+	type = "invalid";
+	break;
+    default:
+	return 0;
+    }
+
+    G_warning("category support for [%s] in mapset [%s] %s",
+	      name, mapset, type);
+    return -1;
+}

Copied: grass/trunk/lib/raster3d/close.c (from rev 47531, grass/trunk/lib/raster3d/g3dclose.c)
===================================================================
--- grass/trunk/lib/raster3d/close.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/close.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,196 @@
+#ifdef __MINGW32__
+#  include <windows.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <grass/raster.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+static int G3d_closeNew(G3D_Map * map)
+{
+    char path[GPATH_MAX];
+    struct Categories cats;
+    struct History hist;
+
+    G3d_removeColor(map->fileName);
+
+    /* create empty cats file */
+    Rast_init_cats(NULL, &cats);
+    G3d_writeCats(map->fileName, &cats);
+    Rast_free_cats(&cats);
+
+    /*genrate the history file, use the normal G_ functions */
+    Rast_short_history(map->fileName, "raster3d", &hist);
+    Rast_command_history(&hist);
+    /*Use the G3d function to write the history file,
+     * otherwise the path is wrong */
+    if (!G3d_writeHistory(map->fileName, &hist)) {
+	G3d_error("G3d_closeNew: can't write raster3d history");
+    }
+
+
+    G3d_range_write(map);
+
+    close(map->data_fd);
+
+    /* finally move tempfile to data file */
+    G3d_filename(path, G3D_CELL_ELEMENT, map->fileName, map->mapset);
+#ifdef __MINGW32__
+    if (CopyFile(map->tempName, path, FALSE) == 0) {
+#else
+    if (link(map->tempName, path) < 0) {
+#endif
+	if (rename(map->tempName, path)) {
+	    G3d_error
+		("G3d_closeNew: can't move temp raster map %s\nto 3d data file %s",
+		 map->tempName, path);
+	    return 0;
+	}
+    }
+    else
+	remove(map->tempName);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int G3d_closeCellNew(G3D_Map * map)
+{
+    long ltmp;
+
+    if (map->useCache)
+	if (!G3d_flushAllTiles(map)) {
+	    G3d_error("G3d_closeCellNew: error in G3d_flushAllTiles");
+	    return 0;
+	}
+
+    if (!G3d_flushIndex(map)) {
+	G3d_error("G3d_closeCellNew: error in G3d_flushIndex");
+	return 0;
+    }
+
+    /* write the header info which was filled with dummy values at the */
+    /* opening time */
+
+    if (lseek(map->data_fd,
+	      (long)(map->offset - sizeof(int) - sizeof(long)),
+	      SEEK_SET) == -1) {
+	G3d_error("G3d_closeCellNew: can't position file");
+	return 0;
+    }
+
+    if (!G3d_writeInts(map->data_fd, map->useXdr, &(map->indexNbytesUsed), 1)) {
+	G3d_error("G3d_closeCellNew: can't write header");
+	return 0;
+    }
+
+    G3d_longEncode(&(map->indexOffset), (unsigned char *)&ltmp, 1);
+    if (write(map->data_fd, &ltmp, sizeof(long)) != sizeof(long)) {
+	G3d_error("G3d_closeCellNew: can't write header");
+	return 0;
+    }
+
+    if (!G3d_closeNew(map) != 0) {
+	G3d_error("G3d_closeCellNew: error in G3d_closeNew");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int G3d_closeOld(G3D_Map * map)
+{
+    if (close(map->data_fd) != 0) {
+	G3d_error("G3d_closeOld: could not close file");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int G3d_closeCellOld(G3D_Map * map)
+{
+    if (!G3d_closeOld(map) != 0) {
+	G3d_error("G3d_closeCellOld: error in G3d_closeOld");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Closes g3d-file. If <em>map</em> is new
+ * and cache-mode is used for <em>map</em> then every tile which is not flushed
+ * before closing is flushed.  
+ *
+ *  \param map
+ *  \return 1 ... if successful,
+ *          0 ...  otherwise.
+ */
+
+int G3d_closeCell(G3D_Map * map)
+{
+    if (map->operation == G3D_WRITE_DATA) {
+	if (!G3d_closeCellNew(map)) {
+	    G3d_error("G3d_closeCell: error in G3d_closeCellNew");
+	    return 0;
+	}
+    }
+    else {
+	if (!G3d_closeCellOld(map) != 0) {
+	    G3d_error("G3d_closeCell: error in G3d_closeCellOld");
+	    return 0;
+	}
+    }
+
+    G3d_free(map->index);
+    G3d_free(map->tileLength);
+
+    if (map->useCache) {
+	if (!G3d_disposeCache(map)) {
+	    G3d_error("G3d_closeCell: error in G3d_disposeCache");
+	    return 0;
+	}
+    }
+    else
+	G3d_free(map->data);
+
+    if (map->operation == G3D_WRITE_DATA)
+	if (!G3d_writeHeader(map,
+			     map->region.proj, map->region.zone,
+			     map->region.north, map->region.south,
+			     map->region.east, map->region.west,
+			     map->region.top, map->region.bottom,
+			     map->region.rows, map->region.cols,
+			     map->region.depths,
+			     map->region.ew_res, map->region.ns_res,
+			     map->region.tb_res,
+			     map->tileX, map->tileY, map->tileZ,
+			     map->type,
+			     map->compression, map->useRle, map->useLzw,
+			     map->precision, map->offset, map->useXdr,
+			     map->hasIndex, map->unit)) {
+	    G3d_error("G3d_closeCell: error in G3d_writeHeader");
+	    return 0;
+	}
+
+    G3d_free(map->unit);
+    G3d_free(map);
+    return 1;
+}

Copied: grass/trunk/lib/raster3d/color.c (from rev 47531, grass/trunk/lib/raster3d/g3dcolor.c)
===================================================================
--- grass/trunk/lib/raster3d/color.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/color.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,351 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+#include "G3d_intern.h"
+
+static int read_colors(const char *, const char *, struct Colors *);
+static int read_new_colors(FILE *, struct Colors *);
+static int read_old_colors(FILE *, struct Colors *);
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_removeColor(const char *name)
+ /* adapted from G_remove_colr */
+{
+    return G_remove_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_readColors(const char *name, const char *mapset, struct Colors *colors)
+ /* adapted from Rast_read_colors */
+{
+    const char *err;
+    struct FPRange drange;
+    DCELL dmin, dmax;
+
+    Rast_init_colors(colors);
+
+    Rast_mark_colors_as_fp(colors);
+
+    switch (read_colors(name, mapset, colors)) {
+    case -2:
+	if (G3d_readRange(name, mapset, &drange) >= 0) {
+	    Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
+	    if (!Rast_is_d_null_value(&dmin) && !Rast_is_d_null_value(&dmax))
+		Rast_make_rainbow_fp_colors(colors, dmin, dmax);
+	    return 0;
+	}
+	err = "missing";
+	break;
+    case -1:
+	err = "invalid";
+	break;
+    default:
+	return 1;
+    }
+
+    G_warning("color support for [%s] in mapset [%s] %s", name, mapset, err);
+    return -1;
+}
+
+static int read_colors(const char *name, const char *mapset,
+		       struct Colors *colors)
+{
+    FILE *fd;
+    int stat;
+    char buf[1024];
+
+    fd = G_fopen_old_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name, mapset);
+    if (!fd)
+	return -2;
+
+    /*
+     * first line in 4.0 color files is %
+     * otherwise it is pre 4.0
+     */
+    if (fgets(buf, sizeof buf, fd) == NULL) {
+	fclose(fd);
+	return -1;
+    }
+    G_fseek(fd, 0L, 0);
+
+    G_strip(buf);
+    if (*buf == '%') {		/* 4.0 format */
+	stat = read_new_colors(fd, colors);
+	colors->version = 0;	/* 4.0 format */
+    }
+    else {
+	stat = read_old_colors(fd, colors);
+	colors->version = -1;	/* pre 4.0 format */
+    }
+    fclose(fd);
+    return stat;
+}
+
+/* parse input lines with the following formats
+ *   val1:r:g:b val2:r:g:b
+ *   val:r:g:b          (implies cat1==cat2)
+ *
+ * r:g:b can be just a single grey level
+ *   cat1:x cat2:y
+ *   cat:x
+ *
+ * optional lines are
+ *    invert            invert color table
+ *    shift:n           where n is the amount to shift the color table
+ */
+static int read_new_colors(FILE * fd, struct Colors *colors)
+{
+    double val1, val2;
+    long cat1, cat2;
+    int r1, g1, b1;
+    int r2, g2, b2;
+    char buf[1024];
+    char word1[256], word2[256];
+    int n, fp_rule;
+    int null, undef;
+    int modular;
+    DCELL shift;
+
+    if (fgets(buf, sizeof buf, fd) == NULL)
+	return -1;
+    G_strip(buf);
+
+    if (sscanf(buf + 1, "%lf %lf", &val1, &val2) == 2)
+	Rast_set_d_color_range((DCELL) val1, (DCELL) val2, colors);
+
+    modular = 0;
+    while (fgets(buf, sizeof buf, fd)) {
+	null = undef = fp_rule = 0;
+	*word1 = *word2 = 0;
+	n = sscanf(buf, "%s %s", word1, word2);
+	if (n < 1)
+	    continue;
+
+	if (sscanf(word1, "shift:%lf", &shift) == 1
+	    || (strcmp(word1, "shift:") == 0 &&
+		sscanf(word2, "%lf", &shift) == 1)) {
+	    Rast_shift_d_colors(shift, colors);
+	    continue;
+	}
+	if (strcmp(word1, "invert") == 0) {
+	    Rast_invert_colors(colors);
+	    continue;
+	}
+	if (strcmp(word1, "%%") == 0) {
+	    modular = !modular;
+	    continue;
+	}
+
+	switch (sscanf(word1, "nv:%d:%d:%d", &r1, &g1, &b1)) {
+	case 1:
+	    null = 1;
+	    b1 = g1 = r1;
+	    break;
+	case 3:
+	    null = 1;
+	    break;
+	}
+	if (!null)
+	    switch (sscanf(word1, "*:%d:%d:%d", &r1, &g1, &b1)) {
+	    case 1:
+		undef = 1;
+		b1 = g1 = r1;
+		break;
+	    case 3:
+		undef = 1;
+		break;
+	    }
+	if (!null && !undef)
+	    switch (sscanf(word1, "%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
+	    case 2:
+		b1 = g1 = r1;
+		break;
+	    case 4:
+		break;
+	    default:
+		if (sscanf(word1, "%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
+		    fp_rule = 1;
+		else if (sscanf(word1, "%lf:%d", &val1, &r1) == 2) {
+		    fp_rule = 1;
+		    b1 = g1 = r1;
+		}
+		else
+		    continue;	/* other lines are ignored */
+	    }
+	if (n == 2) {
+	    switch (sscanf(word2, "%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
+	    case 2:
+		b2 = g2 = r2;
+		if (fp_rule)
+		    val2 = (DCELL) cat2;
+		break;
+	    case 4:
+		if (fp_rule)
+		    val2 = (DCELL) cat2;
+		break;
+	    default:
+		if (sscanf(word2, "%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
+		    if (!fp_rule)
+			val1 = (DCELL) cat1;
+		    fp_rule = 1;
+		}
+		else if (sscanf(word2, "%lf:%d", &val2, &r2) == 2) {
+		    if (!fp_rule)
+			val1 = (DCELL) cat1;
+		    fp_rule = 1;
+		    b2 = g2 = r2;
+		}
+		else
+		    continue;	/* other lines are ignored */
+	    }
+	}
+	else {
+	    if (!fp_rule)
+		cat2 = cat1;
+	    else
+		val2 = val1;
+	    r2 = r1;
+	    g2 = g1;
+	    b2 = b1;
+	}
+	if (null)
+	    Rast_set_null_value_color(r1, g1, b1, colors);
+	else if (undef)
+	    Rast_set_default_color(r1, g1, b1, colors);
+
+	else if (modular) {
+	    if (fp_rule)
+		Rast_add_modular_d_color_rule((DCELL *) & val1, r1, g1,
+						  b1, (DCELL *) & val2, r2,
+						  g2, b2, colors);
+	    else
+		Rast_add_modular_c_color_rule((CELL *) &cat1, r1, g1, b1,
+					      (CELL *) &cat2, r2, g2, b2, colors);
+	}
+	else {
+	    if (fp_rule)
+		Rast_add_d_color_rule((DCELL *) & val1, r1, g1, b1,
+				      (DCELL *) & val2, r2, g2, b2,
+				      colors);
+	    else
+		Rast_add_c_color_rule((CELL *) &cat1, r1, g1, b1,
+				      (CELL *) &cat2, r2, g2, b2, colors);
+	}
+	/*
+	   fprintf (stderr, "adding rule %d=%.2lf %d %d %d  %d=%.2lf %d %d %d\n", cat1,val1,  r1, g1, b1, cat2, val2, r2, g2, b2);
+	 */
+    }
+    return 1;
+}
+
+static int read_old_colors(FILE * fd, struct Colors *colors)
+{
+    char buf[256];
+    long n;
+    long min;
+    float red_f, grn_f, blu_f;
+    int red, grn, blu;
+    int old;
+    int zero;
+
+    Rast_init_colors(colors);
+    /*
+     * first line in pre 3.0 color files is number of colors - ignore
+     * otherwise it is #min first color, and the next line is for color 0
+     */
+    if (fgets(buf, sizeof buf, fd) == NULL)
+	return -1;
+
+    G_strip(buf);
+    if (*buf == '#') {		/* 3.0 format */
+	old = 0;
+	if (sscanf(buf + 1, "%ld", &min) != 1)	/* first color */
+	    return -1;
+	zero = 1;
+    }
+    else {
+	old = 1;
+	min = 0;
+	zero = 0;
+    }
+
+    colors->cmin = min;
+    n = min;
+    while (fgets(buf, sizeof buf, fd)) {
+	if (old) {
+	    if (sscanf(buf, "%f %f %f", &red_f, &grn_f, &blu_f) != 3)
+		return -1;
+
+	    red = 256 * red_f;
+	    grn = 256 * grn_f;
+	    blu = 256 * blu_f;
+	}
+	else {
+	    switch (sscanf(buf, "%d %d %d", &red, &grn, &blu)) {
+	    case 1:
+		blu = grn = red;
+		break;
+	    case 2:
+		blu = grn;
+		break;
+	    case 3:
+		break;
+	    default:
+		return -1;
+	    }
+	}
+	if (zero) {
+	    Rast__insert_color_into_lookup((CELL) 0, red, grn, blu,
+					&colors->fixed);
+	    zero = 0;
+	}
+	else
+	    Rast__insert_color_into_lookup((CELL) n++, red, grn, blu,
+					&colors->fixed);
+    }
+    colors->cmax = n - 1;
+
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_writeColors(const char *name, const char *mapset, struct Colors *colors)
+ /* adapted from Rast_write_colors */
+{
+    FILE *fd;
+
+    if (strcmp(mapset, G_mapset()) != 0) {
+	G_warning(_("mapset <%s> is not the current mapset"), mapset);
+	return -1;
+    }
+
+    fd = G_fopen_new_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name);
+    if (!fd)
+	return -1;
+
+    Rast__write_colors(fd, colors);
+    fclose(fd);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/

Copied: grass/trunk/lib/raster3d/defaults.c (from rev 47531, grass/trunk/lib/raster3d/g3ddefaults.c)
===================================================================
--- grass/trunk/lib/raster3d/defaults.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/defaults.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,556 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <grass/G3d.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+#define G3D_NO_DEFAULT -10
+
+#define G3D_COMPRESSION_DEFAULT G3D_COMPRESSION
+#define G3D_USE_LZW_DEFAULT G3D_NO_LZW
+#define G3D_USE_RLE_DEFAULT G3D_USE_RLE
+#define G3D_PRECISION_DEFAULT G3D_MAX_PRECISION
+#define G3D_CACHE_SIZE_DEFAULT 1000
+#define G3D_CACHE_SIZE_MAX_DEFAULT 16777216
+#define G3D_FILE_TYPE_DEFAULT DCELL_TYPE
+#define G3D_TILE_X_DEFAULT 16
+#define G3D_TILE_Y_DEFAULT 16
+#define G3D_TILE_Z_DEFAULT 8
+#define G3D_ERROR_FUN_DEFAULT G3d_skipError
+#define G3D_UNIT_DEFAULT "none"
+
+/*---------------------------------------------------------------------------*/
+
+#define G3D_COMPRESSION_ENV_VAR_YES "G3D_USE_COMPRESSION"
+#define G3D_COMPRESSION_ENV_VAR_NO "G3D_NO_COMPRESSION"
+
+#define G3D_LZW_ENV_VAR_YES "G3D_USE_LZW"
+#define G3D_LZW_ENV_VAR_NO "G3D_NO_LZW"
+
+#define G3D_RLE_ENV_VAR_YES "G3D_USE_RLE"
+#define G3D_RLE_ENV_VAR_NO "G3D_NO_RLE"
+
+#define G3D_PRECISION_ENV_VAR "G3D_PRECISION"
+#define G3D_PRECISION_ENV_VAR_MAX "G3D_MAX_PRECISION"
+
+#define G3D_CACHE_SIZE_ENV_VAR "G3D_DEFAULT_CACHE_SIZE"
+#define G3D_CACHE_SIZE_MAX_ENV_VAR "G3D_MAX_CACHE_SIZE"
+
+#define G3D_FILE_FLOAT_ENV_VAR "G3D_WRITE_FLOAT"
+#define G3D_FILE_DOUBLE_ENV_VAR "G3D_WRITE_DOUBLE"
+
+#define G3D_TILE_DIM_X_ENV_VAR "G3D_TILE_DIMENSION_X"
+#define G3D_TILE_DIM_Y_ENV_VAR "G3D_TILE_DIMENSION_Y"
+#define G3D_TILE_DIM_Z_ENV_VAR "G3D_TILE_DIMENSION_Z"
+
+#define G3D_FATAL_ERROR_ENV_VAR "G3D_USE_FATAL_ERROR"
+#define G3D_PRINT_ERROR_ENV_VAR "G3D_USE_PRINT_ERROR"
+
+#define G3D_DEFAULT_WINDOW3D "G3D_DEFAULT_WINDOW3D"
+
+/*---------------------------------------------------------------------------*/
+
+int g3d_do_compression = G3D_NO_DEFAULT;
+int g3d_do_lzw_compression = G3D_NO_DEFAULT;
+int g3d_do_rle_compression = G3D_NO_DEFAULT;
+int g3d_precision = G3D_NO_DEFAULT;
+int g3d_cache_default = G3D_NO_DEFAULT;
+int g3d_cache_max = G3D_NO_DEFAULT;
+int g3d_file_type = G3D_NO_DEFAULT;
+int g3d_tile_dimension[3] =
+    { G3D_NO_DEFAULT, G3D_NO_DEFAULT, G3D_NO_DEFAULT };
+void (*g3d_error_fun) (const char *) = NULL;
+char *g3d_unit_default = NULL;
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * <em>doCompress</em> should be one of G3D_NO_COMPRESSION and
+ * G3D_COMPRESSION, <em>doRle</em> should be either G3D_NO_RLE or
+ * G3D_USE_RLE, and <em>precision</em> should be either G3D_MAX_PRECISION or
+ * a positive integer.
+ *
+ *  \param doCompress
+ *  \param doLzw
+ *  \param doRle
+ *  \param precision
+ *  \return void
+ */
+
+void
+G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int precision)
+{
+    if ((doCompress != G3D_NO_COMPRESSION) && (doCompress != G3D_COMPRESSION))
+	G3d_fatalError("G3d_setCompressionMode: wrong value for doCompress.");
+
+    g3d_do_compression = doCompress;
+
+    if (doCompress == G3D_NO_COMPRESSION)
+	return;
+
+    if ((doLzw != G3D_NO_LZW) && (doLzw != G3D_USE_LZW))
+	G3d_fatalError("G3d_setCompressionMode: wrong value for doLzw.");
+
+    if ((doRle != G3D_NO_RLE) && (doRle != G3D_USE_RLE))
+	G3d_fatalError("G3d_setCompressionMode: wrong value for doRle.");
+
+    if (precision < -1)
+	G3d_fatalError("G3d_setCompressionMode: wrong value for precision.");
+
+    g3d_do_lzw_compression = doLzw;
+    g3d_do_rle_compression = doRle;
+    g3d_precision = precision;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * 
+ *
+ *  \param doCompress
+ *  \param doLzw
+ *  \param doRle
+ *  \param precision
+ *  \return void
+ */
+
+void
+G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
+		       int *precision)
+{
+    if (doCompress != NULL)
+	*doCompress = g3d_do_compression;
+    if (doLzw != NULL)
+	*doLzw = g3d_do_lzw_compression;
+    if (doRle != NULL)
+	*doRle = g3d_do_rle_compression;
+    if (precision != NULL)
+	*precision = g3d_precision;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  set cache size
+ *
+ *  \param nTiles
+ *  \return void
+ */
+
+void G3d_setCacheSize(int nTiles)
+{
+    if (nTiles < 0)
+	G3d_fatalError("G3d_setCacheSize: size out of range.");
+
+    g3d_cache_default = nTiles;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  get cache size
+ *
+ *  \return int
+ */
+
+int G3d_getCacheSize()
+{
+    return g3d_cache_default;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief Set cache limit
+ *
+ *  set cache limit
+ *
+ *  \param nBytes
+ *  \return void
+ */
+
+void G3d_setCacheLimit(int nBytes)
+{
+    if (nBytes <= 0)
+	G3d_fatalError("G3d_setCacheLimit: size out of range.");
+
+    g3d_cache_max = nBytes;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief Get cache limit
+ *
+ *  get cache limit
+ *
+ *  \param nBytes
+ *  \return int
+ */
+
+int G3d_getCacheLimit()
+{
+    return g3d_cache_max;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  set G3d file type
+ *
+ *  \param type
+ *  \return void
+ */
+
+void G3d_setFileType(int type)
+{
+    if ((type != FCELL_TYPE) && (type != DCELL_TYPE))
+	G3d_fatalError("G3d_setFileTypeDefault: invalid type");
+
+    g3d_file_type = type;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * get G3d file type
+ *
+ *  \param type
+ *  \return int
+ */
+
+int G3d_getFileType()
+{
+    return g3d_file_type;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * set Tile Dimension
+ *
+ *  \param tileX
+ *  \param tileY
+ *  \param tileZ
+ *  \return void
+ */
+
+void G3d_setTileDimension(int tileX, int tileY, int tileZ)
+{
+    if ((g3d_tile_dimension[0] = tileX) <= 0)
+	G3d_fatalError
+	    ("G3d_setTileDimension: value for tile x environment variable out of range");
+
+    if ((g3d_tile_dimension[1] = tileY) <= 0)
+	G3d_fatalError
+	    ("G3d_setTileDimension: value for tile y environment variable out of range");
+
+    if ((g3d_tile_dimension[2] = tileZ) <= 0)
+	G3d_fatalError
+	    ("G3d_setTileDimension: value for tile z environment variable out of range");
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  get Tile Dimension
+ *
+ *  \param tileX
+ *  \param tileY
+ *  \param tileZ
+ *  \return void
+ */
+
+void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
+{
+    *tileX = g3d_tile_dimension[0];
+    *tileY = g3d_tile_dimension[1];
+    *tileZ = g3d_tile_dimension[2];
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  set error function
+ *
+ *  \param 
+ *  \return void
+ */
+
+void G3d_setErrorFun(void (*fun) (const char *))
+{
+    g3d_error_fun = fun;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  set G3d unit
+ *
+ *  \param unit
+ *  \return void
+ */
+
+void G3d_setUnit(const char *unit)
+{
+    G3d_free(g3d_unit_default);
+    g3d_unit_default = G_store(unit);
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Initializes the default values described
+ * in G3D Defaults.  Applications have to use this function only if they need to
+ * query the default values before the first file (either old or new) has been
+ * opened.
+ *
+ *  \return void
+ */
+
+void G3d_initDefaults(void)
+{
+    static int firstTime = 1;
+    const char *value, *windowName;
+    G3D_Region window;
+
+    if (!firstTime)
+	return;
+    firstTime = 0;
+
+    if (g3d_do_compression == G3D_NO_DEFAULT) {
+	if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_YES)) {
+	    g3d_do_compression = G3D_COMPRESSION;
+	}
+	else {
+	    if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_NO)) {
+		g3d_do_compression = G3D_NO_COMPRESSION;
+	    }
+	    else {
+		g3d_do_compression = G3D_COMPRESSION_DEFAULT;
+	    }
+	}
+    }
+
+    if (g3d_do_lzw_compression == G3D_NO_DEFAULT) {
+	if (NULL != getenv(G3D_LZW_ENV_VAR_YES)) {
+	    g3d_do_lzw_compression = G3D_USE_LZW;
+	}
+	else {
+	    if (NULL != getenv(G3D_LZW_ENV_VAR_NO)) {
+		g3d_do_lzw_compression = G3D_NO_LZW;
+	    }
+	    else {
+		g3d_do_lzw_compression = G3D_USE_LZW_DEFAULT;
+	    }
+	}
+    }
+
+    if (g3d_do_rle_compression == G3D_NO_DEFAULT) {
+	if (NULL != getenv(G3D_RLE_ENV_VAR_YES)) {
+	    g3d_do_rle_compression = G3D_USE_RLE;
+	}
+	else {
+	    if (NULL != getenv(G3D_RLE_ENV_VAR_NO)) {
+		g3d_do_rle_compression = G3D_NO_RLE;
+	    }
+	    else {
+		g3d_do_rle_compression = G3D_USE_RLE_DEFAULT;
+	    }
+	}
+    }
+
+    if (g3d_precision == G3D_NO_DEFAULT) {
+	if (NULL != getenv(G3D_PRECISION_ENV_VAR_MAX)) {
+	    g3d_precision = G3D_MAX_PRECISION;
+	}
+	else {
+	    value = getenv(G3D_PRECISION_ENV_VAR);
+	    if (value == NULL) {
+		g3d_precision = G3D_PRECISION_DEFAULT;
+	    }
+	    else {
+		if (sscanf(value, "%d", &g3d_precision) != 1) {
+		    G3d_fatalError
+			("G3d_initDefaults: precision environment variable has invalid value");
+		}
+		else {
+		    if (g3d_precision < -1) {
+			G3d_fatalError
+			    ("G3d_initDefaults: value for cache environment variable out of range");
+		    }
+		}
+	    }
+	}
+    }
+
+    if (g3d_file_type == G3D_NO_DEFAULT) {
+	if (NULL != getenv(G3D_FILE_FLOAT_ENV_VAR)) {
+	    g3d_file_type = FCELL_TYPE;
+	}
+	else {
+	    if (NULL != getenv(G3D_FILE_DOUBLE_ENV_VAR)) {
+		g3d_file_type = DCELL_TYPE;
+	    }
+	    else {
+		g3d_file_type = G3D_FILE_TYPE_DEFAULT;
+	    }
+	}
+    }
+
+    if (g3d_cache_default == G3D_NO_DEFAULT) {
+	value = getenv(G3D_CACHE_SIZE_ENV_VAR);
+
+	if (value == NULL) {
+	    g3d_cache_default = G3D_CACHE_SIZE_DEFAULT;
+	}
+	else {
+	    if (sscanf(value, "%d", &g3d_cache_default) != 1) {
+		G3d_fatalError
+		    ("G3d_initDefaults: cache environment variable has invalid value");
+	    }
+	    if (g3d_cache_default < 0) {
+		G3d_fatalError
+		    ("G3d_initDefaults: value for cache environment variable out of range");
+	    }
+	}
+    }
+
+    if (g3d_cache_max == G3D_NO_DEFAULT) {
+	value = getenv(G3D_CACHE_SIZE_MAX_ENV_VAR);
+
+	if (value == NULL) {
+	    g3d_cache_max = G3D_CACHE_SIZE_MAX_DEFAULT;
+	}
+	else {
+	    if (sscanf(value, "%d", &g3d_cache_max) != 1) {
+		G3d_fatalError
+		    ("G3d_initDefaults: cache environment variable has invalid value");
+	    }
+	    if (g3d_cache_max < 0) {
+		G3d_fatalError
+		    ("G3d_initDefaults: value for cache environment variable out of range");
+	    }
+	}
+    }
+
+    if (g3d_tile_dimension[0] == G3D_NO_DEFAULT) {
+	value = getenv(G3D_TILE_DIM_X_ENV_VAR);
+
+	if (value == NULL) {
+	    g3d_tile_dimension[0] = G3D_TILE_X_DEFAULT;
+	}
+	else {
+	    if (sscanf(value, "%d", g3d_tile_dimension) != 1) {
+		G3d_fatalError
+		    ("G3d_initDefaults: tile dimension x environment variable has invalid value");
+	    }
+	    if (g3d_tile_dimension[0] <= 0) {
+		G3d_fatalError
+		    ("G3d_initDefaults: value for tile x environment variable out of range");
+	    }
+	}
+
+	value = getenv(G3D_TILE_DIM_Y_ENV_VAR);
+
+	if (value == NULL) {
+	    g3d_tile_dimension[1] = G3D_TILE_Y_DEFAULT;
+	}
+	else {
+	    if (sscanf(value, "%d", g3d_tile_dimension + 1) != 1) {
+		G3d_fatalError
+		    ("G3d_initDefaults: tile dimension y environment variable has invalid value");
+	    }
+	    if (g3d_tile_dimension[1] <= 0) {
+		G3d_fatalError
+		    ("G3d_initDefaults: value for tile y environment variable out of range");
+	    }
+	}
+
+	value = getenv(G3D_TILE_DIM_Z_ENV_VAR);
+
+	if (value == NULL) {
+	    g3d_tile_dimension[2] = G3D_TILE_Z_DEFAULT;
+	}
+	else {
+	    if (sscanf(value, "%d", g3d_tile_dimension + 2) != 1) {
+		G3d_fatalError
+		    ("G3d_initDefaults: tile dimension z environment variable has invalid value");
+	    }
+	    if (g3d_tile_dimension[2] <= 0) {
+		G3d_fatalError
+		    ("G3d_initDefaults: value for tile z environment variable out of range");
+	    }
+	}
+    }
+
+    if (g3d_error_fun == NULL) {
+	value = getenv(G3D_FATAL_ERROR_ENV_VAR);
+
+	if (value != NULL) {
+	    g3d_error_fun = G3d_fatalError_noargs;
+	}
+	else {
+	    value = getenv(G3D_PRINT_ERROR_ENV_VAR);
+
+	    if (value != NULL) {
+		g3d_error_fun = G3d_printError;
+	    }
+	    else {
+		g3d_error_fun = G3D_ERROR_FUN_DEFAULT;
+	    }
+	}
+    }
+
+    if (g3d_unit_default == NULL)
+	g3d_unit_default = G_store(G3D_UNIT_DEFAULT);
+
+    windowName = G3d_getWindowParams();
+    if (windowName == NULL) {
+	value = getenv(G3D_DEFAULT_WINDOW3D);
+	if (value != NULL)
+	    if (*value != 0)
+		windowName = value;
+    }
+
+    if (!G3d_readWindow(&window, windowName))
+	G3d_fatalError("G3d_initDefaults: Error reading window");
+    G3d_setWindow(&window);
+
+}

Copied: grass/trunk/lib/raster3d/doubleio.c (from rev 47531, grass/trunk/lib/raster3d/g3ddoubleio.c)
===================================================================
--- grass/trunk/lib/raster3d/doubleio.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/doubleio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,122 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_writeDoubles(int fd, int useXdr, const double *i, int nofNum)
+{
+    int firstTime = 1;
+    XDR xdrEncodeStream;
+    char xdrDoubleBuf[G3D_XDR_DOUBLE_LENGTH * 1024];
+    u_int n;
+
+    if (nofNum <= 0)
+	G3d_fatalError("G3d_writeDoubles: nofNum out of range");
+
+    if (useXdr == G3D_NO_XDR) {
+	if (write(fd, i, sizeof(double) * nofNum) != sizeof(double) * nofNum) {
+	    G3d_error("G3d_writeDoubles: writing to file failed");
+	    return 0;
+	}
+	else {
+	    return 1;
+	}
+    }
+
+
+    if (firstTime) {
+	xdrmem_create(&xdrEncodeStream, xdrDoubleBuf,
+		      G3D_XDR_DOUBLE_LENGTH * 1024, XDR_ENCODE);
+	firstTime = 1;
+    }
+
+    do {
+	n = nofNum % 1024;
+	if (n == 0)
+	    n = 1024;
+
+	if (!xdr_setpos(&xdrEncodeStream, 0)) {
+	    G3d_error("G3d_writeDoubles: positioning xdr failed");
+	    return 0;
+	}
+
+	if (!xdr_vector(&xdrEncodeStream, (char *)i, n, sizeof(double),
+			(xdrproc_t) xdr_double)) {
+	    G3d_error("G3d_writeDoubles: writing xdr failed");
+	    return 0;
+	}
+
+	if (write(fd, xdrDoubleBuf, G3D_XDR_DOUBLE_LENGTH * n) !=
+	    G3D_XDR_DOUBLE_LENGTH * n) {
+	    G3d_error("G3d_writeDoubles: writing xdr to file failed");
+	    return 0;
+	}
+
+	nofNum -= n;
+	i += n;
+    } while (nofNum);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_readDoubles(int fd, int useXdr, double *i, int nofNum)
+{
+    int firstTime = 1;
+    XDR xdrDecodeStream;
+    char xdrDoubleBuf[G3D_XDR_DOUBLE_LENGTH * 1024];
+    u_int n;
+
+    if (nofNum <= 0)
+	G3d_fatalError("G3d_readDoubles: nofNum out of range");
+
+    if (useXdr == G3D_NO_XDR) {
+	if (read(fd, i, sizeof(double) * nofNum) != sizeof(double) * nofNum) {
+	    G3d_error("G3d_readDoubles: reading from file failed");
+	    return 0;
+	}
+	else {
+	    return 1;
+	}
+    }
+
+    if (firstTime) {
+	xdrmem_create(&xdrDecodeStream, xdrDoubleBuf,
+		      G3D_XDR_DOUBLE_LENGTH * 1024, XDR_DECODE);
+	firstTime = 1;
+    }
+
+    do {
+	n = nofNum % 1024;
+	if (n == 0)
+	    n = 1024;
+
+	if (read(fd, xdrDoubleBuf, G3D_XDR_DOUBLE_LENGTH * n) !=
+	    G3D_XDR_DOUBLE_LENGTH * n) {
+	    G3d_error("G3d_readDoubles: reading xdr from file failed");
+	    return 0;
+	}
+
+	if (!xdr_setpos(&xdrDecodeStream, 0)) {
+	    G3d_error("G3d_readDoubles: positioning xdr failed");
+	    return 0;
+	}
+
+	if (!xdr_vector(&xdrDecodeStream, (char *)i, n, sizeof(double),
+			(xdrproc_t) xdr_double)) {
+	    G3d_error("G3d_readDoubles: reading xdr failed");
+	    return 0;
+	}
+
+	nofNum -= n;
+	i += n;
+    } while (nofNum);
+
+    return 1;
+}

Copied: grass/trunk/lib/raster3d/error.c (from rev 47531, grass/trunk/lib/raster3d/g3derror.c)
===================================================================
--- grass/trunk/lib/raster3d/error.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/error.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdarg.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <grass/gis.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  This function ignores the error.
+ *
+ *  \param 
+ *  \return void
+ */
+
+void G3d_skipError(const char *msg)
+{
+}
+
+
+/*!
+ * \brief 
+ *
+ *  This function prints the
+ * error message <em>msg</em> to <em>stderr</em> and returns.
+ *
+ *  \param 
+ *  \return void
+ */
+
+void G3d_printError(const char *msg)
+{
+    fprintf(stderr, "ERROR: ");
+    fprintf(stderr, msg);
+    fprintf(stderr, "\n");
+}
+
+
+/*!
+ * \brief 
+ *
+ *  This function prints the
+ * error message <em>msg</em>, and terminates the program with an error status.
+ *
+ *  \param 
+ *  \return void
+ */
+
+void G3d_fatalError(const char *msg, ...)
+{
+    char buffer[2000];		/* No novels to the error logs, OK? */
+    va_list ap;
+
+    va_start(ap, msg);
+    vsprintf(buffer, msg, ap);
+    va_end(ap);
+
+    G_fatal_error("%s", buffer);
+}
+
+void G3d_fatalError_noargs(const char *msg)
+{
+    G_fatal_error("%s", msg);
+}
+
+void G3d_error(const char *msg, ...)
+{
+    char buffer[2000];		/* No novels to the error logs, OK? */
+    va_list ap;
+
+    va_start(ap, msg);
+    vsprintf(buffer, msg, ap);
+    va_end(ap);
+
+    (*g3d_error_fun) (buffer);
+}

Copied: grass/trunk/lib/raster3d/fpxdr.c (from rev 47531, grass/trunk/lib/raster3d/g3dfpxdr.c)
===================================================================
--- grass/trunk/lib/raster3d/fpxdr.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/fpxdr.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,267 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#include <grass/raster.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_isXdrNullNum(const void *num, int isFloat)
+{
+    static const char null_bytes[8] = {
+	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+    };
+
+    return memcmp(num, null_bytes, isFloat ? 4 : 8) == 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_isXdrNullFloat(const float *f)
+{
+    return G3d_isXdrNullNum(f, 1);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_isXdrNullDouble(const double *d)
+{
+    return G3d_isXdrNullNum(d, 0);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_setXdrNullNum(void *num, int isFloat)
+{
+    static const char null_bytes[8] = {
+	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+    };
+
+    memcpy(num, null_bytes, isFloat ? 4 : 8);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_setXdrNullDouble(double *d)
+{
+    G3d_setXdrNullNum(d, 0);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_setXdrNullFloat(float *f)
+{
+    G3d_setXdrNullNum(f, 1);
+}
+
+/*---------------------------------------------------------------------------*/
+
+XDR xdrEncodeStream, xdrDecodeStream;	/* xdr support structures */
+
+int G3d_initFpXdr(G3D_Map * map, int misuseBytes)
+
+
+
+ /* nof addtl bytes allocated for the xdr array so that */
+		      /* the array can also be (mis)used for other purposes */
+{
+    int doAlloc;
+
+    doAlloc = 0;
+
+    if (xdr == NULL) {
+	xdrLength = map->tileSize * G3D_MAX(map->numLengthExtern,
+					    map->numLengthIntern) +
+	    misuseBytes;
+	xdr = G3d_malloc(xdrLength);
+	if (xdr == NULL) {
+	    G3d_error("G3d_initFpXdr: error in G3d_malloc");
+	    return 0;
+	}
+
+	doAlloc = 1;
+    }
+    else if (map->tileSize * G3D_MAX(map->numLengthExtern,
+				     map->numLengthIntern) + misuseBytes
+	     > xdrLength) {
+	xdrLength = map->tileSize * G3D_MAX(map->numLengthExtern,
+					    map->numLengthIntern) +
+	    misuseBytes;
+	xdr = G3d_realloc(xdr, xdrLength);
+	if (xdr == NULL) {
+	    G3d_error("G3d_initFpXdr: error in G3d_realloc");
+	    return 0;
+	}
+
+	doAlloc = 1;
+    }
+
+    if (doAlloc) {
+	xdrmem_create(&(xdrEncodeStream), xdr, (u_int) xdrLength, XDR_ENCODE);
+	xdrmem_create(&(xdrDecodeStream), xdr, (u_int) xdrLength, XDR_DECODE);
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void *xdrTmp;
+static int dstType, srcType, type, externLength, eltLength, isFloat, useXdr;
+static int (*xdrFun) ();
+static XDR *xdrs;
+static double tmpValue, *tmp;
+
+int G3d_initCopyToXdr(G3D_Map * map, int sType)
+{
+    xdrTmp = xdr;
+    useXdr = map->useXdr;
+    srcType = sType;
+
+    if (map->useXdr == G3D_USE_XDR) {
+	if (!xdr_setpos(&(xdrEncodeStream), 0)) {
+	    G3d_error("G3d_InitCopyToXdr: positioning xdr failed");
+	    return 0;
+	}
+	xdrs = &(xdrEncodeStream);
+    }
+
+    type = map->type;
+    isFloat = (type == FCELL_TYPE);
+    externLength = G3d_externLength(type);
+    eltLength = G3d_length(srcType);
+    if (isFloat)
+	xdrFun = xdr_float;
+    else
+	xdrFun = xdr_double;
+    tmp = &tmpValue;
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_copyToXdr(const void *src, int nofNum)
+{
+    int i;
+
+    if (useXdr == G3D_NO_XDR) {
+	G3d_copyValues(src, 0, srcType, xdrTmp, 0, type, nofNum);
+	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * G3d_externLength(type));
+	return 1;
+    }
+
+    for (i = 0; i < nofNum; i++, src = G_incr_void_ptr(src, eltLength)) {
+
+	if (G3d_isNullValueNum(src, srcType)) {
+	    G3d_setXdrNullNum(xdrTmp, isFloat);
+	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
+		G3d_error("G3d_copyToXdr: positioning xdr failed");
+		return 0;
+	    }
+	}
+	else {
+	    if (type == srcType) {
+		if (xdrFun(xdrs, src) < 0) {
+		    G3d_error("G3d_copyToXdr: writing xdr failed");
+		    return 0;
+		}
+	    }
+	    else {
+		if (type == FCELL_TYPE)
+		    *((float *)tmp) = (float)*((double *)src);
+		else
+		    *((double *)tmp) = (double)*((float *)src);
+		if (xdrFun(xdrs, tmp) < 0) {
+		    G3d_error("G3d_copyToXdr: writing xdr failed");
+		    return 0;
+		}
+	    }
+	}
+
+	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_initCopyFromXdr(G3D_Map * map, int dType)
+{
+    xdrTmp = xdr;
+    useXdr = map->useXdr;
+    dstType = dType;
+
+    if (useXdr == G3D_USE_XDR) {
+	if (!xdr_setpos(&(xdrDecodeStream), 0)) {
+	    G3d_error("G3d_initCopyFromXdr: positioning xdr failed");
+	    return 0;
+	}
+	xdrs = &(xdrDecodeStream);
+    }
+
+    type = map->type;
+    isFloat = (type == FCELL_TYPE);
+    externLength = G3d_externLength(type);
+    eltLength = G3d_length(dstType);
+    if (isFloat)
+	xdrFun = xdr_float;
+    else
+	xdrFun = xdr_double;
+    tmp = &tmpValue;
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_copyFromXdr(int nofNum, void *dst)
+{
+    int i;
+
+    if (useXdr == G3D_NO_XDR) {
+	G3d_copyValues(xdrTmp, 0, type, dst, 0, dstType, nofNum);
+	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * G3d_externLength(type));
+	return 1;
+    }
+
+    for (i = 0; i < nofNum; i++, dst = G_incr_void_ptr(dst, eltLength)) {
+
+	if (G3d_isXdrNullNum(xdrTmp, isFloat)) {
+	    G3d_setNullValue(dst, 1, dstType);
+	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
+		G3d_error("G3d_copyFromXdr: positioning xdr failed");
+		return 0;
+	    }
+	}
+	else {
+	    if (type == dstType) {
+		if (xdrFun(xdrs, dst) < 0) {
+		    G3d_error("G3d_copyFromXdr: reading xdr failed");
+		    return 0;
+		}
+	    }
+	    else {
+		if (xdrFun(xdrs, tmp) < 0) {
+		    G3d_error("G3d_copyFromXdr: reading xdr failed");
+		    return 0;
+		}
+		if (type == FCELL_TYPE)
+		    *((double *)dst) = (double)*((float *)tmp);
+		else
+		    *((float *)dst) = (float)*((double *)tmp);
+	    }
+	}
+
+	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
+    }
+
+    return 1;
+}

Deleted: grass/trunk/lib/raster3d/g3d_volume_layout.png
===================================================================
(Binary files differ)

Deleted: grass/trunk/lib/raster3d/g3d_volume_layout.xcf
===================================================================
(Binary files differ)

Deleted: grass/trunk/lib/raster3d/g3dalloc.c
===================================================================
--- grass/trunk/lib/raster3d/g3dalloc.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dalloc.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,74 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Same as <em>malloc (nBytes)</em>, except that in case of error
- * <tt>G3d_error()</tt> is invoked.
- *
- *  \param nBytes
- *  \return void *: a pointer ... if successful,
- * NULL ... otherwise.
-
- */
-
-void *G3d_malloc(int nBytes)
-{
-    void *buf;
-
-    if (nBytes <= 0)
-	nBytes = 1;
-    if ((buf = malloc(nBytes)) != NULL)
-	return buf;
-
-    G3d_error("G3d_malloc: out of memory");
-    return (void *)NULL;
-}
-
-
-/*!
- * \brief 
- *
- *  Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
- *  <tt>G3d_error()</tt> is invoked. 
- *
- *  \param ptr
- *  \param nBytes
- *  \return void *: a pointer ... if successful,
- *         NULL ... otherwise.
- */
-
-void *G3d_realloc(void *ptr, int nBytes)
-{
-    if (nBytes <= 0)
-	nBytes = 1;
-    if ((ptr = realloc(ptr, nBytes)) != NULL)
-	return ptr;
-
-    G3d_error("G3d_realloc: out of memory");
-    return (void *)NULL;
-}
-
-
-/*!
- * \brief 
- *
- *  Same as <em>free (ptr)</em>.
- *
- *  \param ptr
- *  \return void
- */
-
-void G3d_free(void *buf)
-{
-    free(buf);
-}

Deleted: grass/trunk/lib/raster3d/g3dcache.c
===================================================================
--- grass/trunk/lib/raster3d/g3dcache.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dcache.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,330 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-static int cacheRead_readFun(int tileIndex, void *tileBuf, void *closure)
-{
-    G3D_Map *map = closure;
-
-    if (!G3d_readTile(map, tileIndex, tileBuf, map->typeIntern)) {
-	G3d_error("cacheRead_readFun: error in G3d_readTile");
-	return 0;
-    }
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int initCacheRead(G3D_Map * map, int nCached)
-{
-    map->cache = G3d_cache_new_read(nCached,
-				    map->tileSize * map->numLengthIntern,
-				    map->nTiles, cacheRead_readFun, map);
-    if (map->cache == NULL) {
-	G3d_error("initCacheRead: error in G3d_cache_new_read");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*
-   the map->index array is (ab)used to store the positions of the tiles in the 
-   file-cash. we can do this since we maintain the invariant for every tile 
-   that it is either in no file (index == -1) or in either the output-file
-   (index >= 0) or the cash-file (index <= -2). to convert the file-position in 
-   the cash-file into an index we use the following function:
-
-   index = - (fileposition + 2)
-
-   symmetrically, we use
-
-   fileposition = - (index + 2)
-
-   to convert from index to the fileposition.
- */
-
-/*---------------------------------------------------------------------------*/
-
-static int cacheWrite_readFun(int tileIndex, void *tileBuf, void *closure)
-{
-    G3D_Map *map = closure;
-    int index, nBytes;
-    long pos, offs, offsLast;
-
-    pos = map->index[tileIndex];
-
-    /* tile has already been flushed onto output file or does not exist yet */
-    if (pos >= -1) {		/* note, G3d_readTile takes care of the case pos == -1 */
-	G3d_readTile(map, tileIndex, tileBuf, map->typeIntern);
-	return 1;
-    }
-
-    /* tile is in cache file */
-
-    pos = -pos - 2;		/* pos is shifted by 2 to avoid 0 and -1 */
-
-    nBytes = map->tileSize * map->numLengthIntern;
-    offs = pos * (nBytes + sizeof(int));
-
-    /* seek tile and read it into buffer */
-
-    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
-	G3d_error("cacheWrite_readFun: can't position file");
-	return 0;
-    }
-    if (read(map->cacheFD, tileBuf, nBytes) != nBytes) {
-	G3d_error("cacheWrite_readFun: can't read file");
-	return 0;
-    }
-
-    /* remove it from index */
-
-    map->index[tileIndex] = -1;
-
-    /* if it is the last tile in the file we are done */
-    /* map->cachePosLast tells us the position of the last tile in the file */
-
-    if (map->cachePosLast == pos) {
-	map->cachePosLast--;
-	return 1;
-    }
-
-    /* otherwise we move the last tile in the file into the position of */
-    /* the tile we just read and update the hash information */
-
-    offsLast = map->cachePosLast * (nBytes + sizeof(int));
-
-    if (lseek(map->cacheFD, offsLast, SEEK_SET) == -1) {
-	G3d_error("cacheWrite_readFun: can't position file");
-	return 0;
-    }
-    if (read(map->cacheFD, xdr, nBytes + sizeof(int)) != nBytes + sizeof(int)) {
-	G3d_error("cacheWrite_readFun: can't read file");
-	return 0;
-    }
-
-    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
-	G3d_error("cacheWrite_readFun: can't position file");
-	return 0;
-    }
-    if (write(map->cacheFD, xdr, nBytes + sizeof(int)) !=
-	nBytes + sizeof(int)) {
-	G3d_error("cacheWrite_readFun: can't write file");
-	return 0;
-    }
-
-    index = *((int *)((unsigned char *)xdr + nBytes));
-    map->index[index] = -pos - 2;
-
-    map->cachePosLast--;
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int
-cacheWrite_writeFun(int tileIndex, const void *tileBuf, void *closure)
-{
-    G3D_Map *map = closure;
-    int nBytes;
-    long offs;
-
-    if (map->index[tileIndex] != -1)
-	return 1;
-
-    map->cachePosLast++;
-    nBytes = map->tileSize * map->numLengthIntern;
-    offs = map->cachePosLast * (nBytes + sizeof(int));
-
-    if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
-	G3d_error("cacheWrite_writeFun: can't position file");
-	return 0;
-    }
-    if (write(map->cacheFD, tileBuf, nBytes) != nBytes) {
-	G3d_error("cacheWrite_writeFun: can't write file");
-	return 0;
-    }
-    if (write(map->cacheFD, &tileIndex, sizeof(int)) != sizeof(int)) {
-	G3d_error("cacheWrite_writeFun: can't write file");
-	return 0;
-    }
-
-    map->index[tileIndex] = -map->cachePosLast - 2;
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int disposeCacheWrite(G3D_Map * map)
-{
-    if (map->cacheFD >= 0) {
-	if (close(map->cacheFD) != 0) {
-	    G3d_error("disposeCacheWrite: could not close file");
-	    return 0;
-	}
-	remove(map->cacheFileName);
-	G3d_free(map->cacheFileName);
-    }
-
-    G3d_cache_dispose(map->cache);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int initCacheWrite(G3D_Map * map, int nCached)
-{
-    map->cacheFileName = G_tempfile();
-    map->cacheFD = open(map->cacheFileName, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-    if (map->cacheFD < 0) {
-	G3d_error("initCacheWrite: could not open file");
-	return 0;
-    }
-
-    map->cachePosLast = -1;
-
-    map->cache = G3d_cache_new(nCached,
-			       map->tileSize * map->numLengthIntern,
-			       map->nTiles,
-			       cacheWrite_writeFun, map,
-			       cacheWrite_readFun, map);
-
-    if (map->cache == NULL) {
-	disposeCacheWrite(map);
-	G3d_error("initCacheWrite: error in G3d_cache_new");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_initCache(G3D_Map * map, int nCached)
-{
-    if (map->operation == G3D_READ_DATA) {
-	if (!initCacheRead(map, nCached)) {
-	    G3d_error("G3d_initCache: error in initCacheRead");
-	    return 0;
-	}
-	return 1;
-    }
-
-    if (!initCacheWrite(map, nCached)) {
-	G3d_error("G3d_initCache: error in initCacheWrite");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int disposeCacheRead(G3D_Map * map)
-{
-    G3d_cache_dispose(map->cache);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_disposeCache(G3D_Map * map)
-{
-    if (map->operation == G3D_READ_DATA) {
-	if (!disposeCacheRead(map)) {
-	    G3d_error("G3d_disposeCache: error in disposeCacheRead");
-	    return 0;
-	}
-	return 1;
-    }
-
-    if (!disposeCacheWrite(map)) {
-	G3d_error("G3d_disposeCache: error in disposeCacheWrite");
-	return 0;
-    }
-
-    return 1;
-}
-
-
-/*---------------------------------------------------------------------------*/
-
-static int cacheFlushFun(int tileIndex, const void *tileBuf, void *closure)
-{
-    G3D_Map *map = closure;
-
-    if (!G3d_writeTile(map, tileIndex, tileBuf, map->typeIntern)) {
-	G3d_error("cacheFlushFun: error in G3d_writeTile");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_flushAllTiles(G3D_Map * map)
-{
-    int tileIndex, nBytes;
-    long offs;
-
-    if (map->operation == G3D_READ_DATA) {
-	if (!G3d_cache_remove_all(map->cache)) {
-	    G3d_error("G3d_flushAllTiles: error in G3d_cache_remove_all");
-	    return 0;
-	}
-	return 1;
-    }
-
-    /* make cache write into output file instead of cache file */
-    G3d_cache_set_removeFun(map->cache, cacheFlushFun, map);
-
-    /* first flush all the tiles which are in the file cache */
-
-    nBytes = map->tileSize * map->numLengthIntern;
-
-    while (map->cachePosLast >= 0) {
-	offs = map->cachePosLast * (nBytes + sizeof(int)) + nBytes;
-
-	if (lseek(map->cacheFD, offs, SEEK_SET) == -1) {
-	    G3d_error("G3d_flushAllTiles: can't position file");
-	    return 0;
-	}
-	if (read(map->cacheFD, &tileIndex, sizeof(int)) != sizeof(int)) {
-	    G3d_error("G3d_flushAllTiles: can't read file");
-	    return 0;
-	}
-
-	if (!G3d_cache_load(map->cache, tileIndex)) {
-	    G3d_error("G3d_flushAllTiles: error in G3d_cache_load");
-	    return 0;
-	}
-	if (!G3d_cache_flush(map->cache, tileIndex)) {
-	    G3d_error("G3d_flushAllTiles: error in G3d_cache_flush");
-	    return 0;
-	}
-    }
-
-    /* then flush all the tiles which remain in the non-file cache */
-    if (!G3d_cache_flush_all(map->cache)) {
-	G3d_error("G3d_flushAllTiles: error in G3d_cache_flush_all");
-	return 0;
-    }
-
-    /* now the cache should write into the cache file again */
-    G3d_cache_set_removeFun(map->cache, cacheWrite_writeFun, map);
-
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3dcats.c
===================================================================
--- grass/trunk/lib/raster3d/g3dcats.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dcats.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,198 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Writes the
- * categories stored in the <em>cats</em> structure into the categories file for
- * map <em>name</em> in the current mapset.  See <em>Rast_write_cats</em>
- * (Raster_Category_File) for details and return values.
- *
- *  \param name
- *  \param cats
- *  \return int
- */
-
-int G3d_writeCats(const char *name, struct Categories *cats)
- /* adapted from Rast_write_cats */
-{
-    FILE *fd;
-    int i;
-    const char *descr;
-    DCELL val1, val2;
-    char str1[100], str2[100];
-
-    fd = G_fopen_new_misc(G3D_DIRECTORY, G3D_CATS_ELEMENT, name);
-    if (!fd)
-	return -1;
-
-    /* write # cats - note # indicate 3.0 or later */
-    fprintf(fd, "# %ld categories\n", (long)cats->num);
-
-    /* title */
-    fprintf(fd, "%s\n", cats->title != NULL ? cats->title : "");
-
-    /* write format and coefficients */
-    fprintf(fd, "%s\n", cats->fmt != NULL ? cats->fmt : "");
-    fprintf(fd, "%.2f %.2f %.2f %.2f\n",
-	    cats->m1, cats->a1, cats->m2, cats->a2);
-
-    /* write the cat numbers:label */
-    for (i = 0; i < Rast_quant_nof_rules(&cats->q); i++) {
-	descr = Rast_get_ith_d_cat(cats, i, &val1, &val2);
-	if ((cats->fmt && cats->fmt[0]) || (descr && descr[0])) {
-	    if (val1 == val2) {
-		sprintf(str1, "%.10f", val1);
-		G_trim_decimal(str1);
-		fprintf(fd, "%s:%s\n", str1, descr != NULL ? descr : "");
-	    }
-	    else {
-		sprintf(str1, "%.10f", val1);
-		G_trim_decimal(str1);
-		sprintf(str2, "%.10f", val2);
-		G_trim_decimal(str2);
-		fprintf(fd, "%s:%s:%s\n", str1, str2,
-			descr != NULL ? descr : "");
-	    }
-	}
-    }
-    fclose(fd);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int
-read_cats(const char *name, const char *mapset, struct Categories *pcats)
- /* adapted from G__read_cats */
-{
-    FILE *fd;
-    char buff[1024];
-    CELL cat;
-    DCELL val1, val2;
-    int old;
-    long num = -1;
-
-    fd = G_fopen_old_misc(G3D_DIRECTORY, G3D_CATS_ELEMENT, name, mapset);
-    if (!fd)
-	return -2;
-
-    /* Read the number of categories */
-    if (G_getl(buff, sizeof(buff), fd) == 0)
-	goto error;
-
-    if (sscanf(buff, "# %ld", &num) == 1)
-	old = 0;
-    else if (sscanf(buff, "%ld", &num) == 1)
-	old = 1;
-
-    /* Read the title for the file */
-    if (G_getl(buff, sizeof(buff), fd) == 0)
-	goto error;
-    G_strip(buff);
-
-    Rast_init_cats(buff, pcats);
-    if (num >= 0)
-	pcats->num = num;
-
-    if (!old) {
-	char fmt[256];
-	float m1, a1, m2, a2;
-
-	if (G_getl(fmt, sizeof(fmt), fd) == 0)
-	    goto error;
-	/* next line contains equation coefficients */
-	if (G_getl(buff, sizeof(buff), fd) == 0)
-	    goto error;
-	if (sscanf(buff, "%f %f %f %f", &m1, &a1, &m2, &a2) != 4)
-	    goto error;
-	Rast_set_cats_fmt(fmt, m1, a1, m2, a2, pcats);
-    }
-
-    /* Read all category names */
-    for (cat = 0;; cat++) {
-	char label[1024];
-
-	if (G_getl(buff, sizeof(buff), fd) == 0)
-	    break;
-
-	if (old)
-	    Rast_set_c_cat(&cat, &cat, buff, pcats);
-	else {
-	    *label = 0;
-	    if (sscanf(buff, "%1s", label) != 1)
-		continue;
-	    if (*label == '#')
-		continue;
-	    *label = 0;
-
-	    /* try to read a range of data */
-	    if (sscanf(buff, "%lf:%lf:%[^\n]", &val1, &val2, label) == 3)
-		Rast_set_cat(&val1, &val2, label, pcats, DCELL_TYPE);
-	    else if (sscanf(buff, "%d:%[^\n]", &cat, label) >= 1)
-		Rast_set_cat(&cat, &cat, label, pcats, CELL_TYPE);
-	    else if (sscanf(buff, "%lf:%[^\n]", &val1, label) >= 1)
-		Rast_set_cat(&val1, &val1, label, pcats, DCELL_TYPE);
-	    else
-		goto error;
-	}
-    }
-
-    fclose(fd);
-    return 0;
-
-  error:
-    fclose(fd);
-    return -1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Reads the categories file for map <em>name</em> in <em>mapset</em> and
- * stores the categories in the <em>pcats</em> structure.  See <em>Rast_read_cats</em>
- * (Raster_Category_File) for details and return values.
- *
- *  \param name
- *  \param mapset
- *  \param pcats
- *  \return int
- */
-
-int
-G3d_readCats(const char *name, const char *mapset, struct Categories *pcats)
- /* adapted from Rast_read_cats */
-{
-    const char *type;
-
-    switch (read_cats(name, mapset, pcats)) {
-    case -2:
-	type = "missing";
-	break;
-    case -1:
-	type = "invalid";
-	break;
-    default:
-	return 0;
-    }
-
-    G_warning("category support for [%s] in mapset [%s] %s",
-	      name, mapset, type);
-    return -1;
-}

Deleted: grass/trunk/lib/raster3d/g3dclose.c
===================================================================
--- grass/trunk/lib/raster3d/g3dclose.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dclose.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,196 +0,0 @@
-#ifdef __MINGW32__
-#  include <windows.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <grass/raster.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-static int G3d_closeNew(G3D_Map * map)
-{
-    char path[GPATH_MAX];
-    struct Categories cats;
-    struct History hist;
-
-    G3d_removeColor(map->fileName);
-
-    /* create empty cats file */
-    Rast_init_cats(NULL, &cats);
-    G3d_writeCats(map->fileName, &cats);
-    Rast_free_cats(&cats);
-
-    /*genrate the history file, use the normal G_ functions */
-    Rast_short_history(map->fileName, "raster3d", &hist);
-    Rast_command_history(&hist);
-    /*Use the G3d function to write the history file,
-     * otherwise the path is wrong */
-    if (!G3d_writeHistory(map->fileName, &hist)) {
-	G3d_error("G3d_closeNew: can't write raster3d history");
-    }
-
-
-    G3d_range_write(map);
-
-    close(map->data_fd);
-
-    /* finally move tempfile to data file */
-    G3d_filename(path, G3D_CELL_ELEMENT, map->fileName, map->mapset);
-#ifdef __MINGW32__
-    if (CopyFile(map->tempName, path, FALSE) == 0) {
-#else
-    if (link(map->tempName, path) < 0) {
-#endif
-	if (rename(map->tempName, path)) {
-	    G3d_error
-		("G3d_closeNew: can't move temp raster map %s\nto 3d data file %s",
-		 map->tempName, path);
-	    return 0;
-	}
-    }
-    else
-	remove(map->tempName);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int G3d_closeCellNew(G3D_Map * map)
-{
-    long ltmp;
-
-    if (map->useCache)
-	if (!G3d_flushAllTiles(map)) {
-	    G3d_error("G3d_closeCellNew: error in G3d_flushAllTiles");
-	    return 0;
-	}
-
-    if (!G3d_flushIndex(map)) {
-	G3d_error("G3d_closeCellNew: error in G3d_flushIndex");
-	return 0;
-    }
-
-    /* write the header info which was filled with dummy values at the */
-    /* opening time */
-
-    if (lseek(map->data_fd,
-	      (long)(map->offset - sizeof(int) - sizeof(long)),
-	      SEEK_SET) == -1) {
-	G3d_error("G3d_closeCellNew: can't position file");
-	return 0;
-    }
-
-    if (!G3d_writeInts(map->data_fd, map->useXdr, &(map->indexNbytesUsed), 1)) {
-	G3d_error("G3d_closeCellNew: can't write header");
-	return 0;
-    }
-
-    G3d_longEncode(&(map->indexOffset), (unsigned char *)&ltmp, 1);
-    if (write(map->data_fd, &ltmp, sizeof(long)) != sizeof(long)) {
-	G3d_error("G3d_closeCellNew: can't write header");
-	return 0;
-    }
-
-    if (!G3d_closeNew(map) != 0) {
-	G3d_error("G3d_closeCellNew: error in G3d_closeNew");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int G3d_closeOld(G3D_Map * map)
-{
-    if (close(map->data_fd) != 0) {
-	G3d_error("G3d_closeOld: could not close file");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static int G3d_closeCellOld(G3D_Map * map)
-{
-    if (!G3d_closeOld(map) != 0) {
-	G3d_error("G3d_closeCellOld: error in G3d_closeOld");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Closes g3d-file. If <em>map</em> is new
- * and cache-mode is used for <em>map</em> then every tile which is not flushed
- * before closing is flushed.  
- *
- *  \param map
- *  \return 1 ... if successful,
- *          0 ...  otherwise.
- */
-
-int G3d_closeCell(G3D_Map * map)
-{
-    if (map->operation == G3D_WRITE_DATA) {
-	if (!G3d_closeCellNew(map)) {
-	    G3d_error("G3d_closeCell: error in G3d_closeCellNew");
-	    return 0;
-	}
-    }
-    else {
-	if (!G3d_closeCellOld(map) != 0) {
-	    G3d_error("G3d_closeCell: error in G3d_closeCellOld");
-	    return 0;
-	}
-    }
-
-    G3d_free(map->index);
-    G3d_free(map->tileLength);
-
-    if (map->useCache) {
-	if (!G3d_disposeCache(map)) {
-	    G3d_error("G3d_closeCell: error in G3d_disposeCache");
-	    return 0;
-	}
-    }
-    else
-	G3d_free(map->data);
-
-    if (map->operation == G3D_WRITE_DATA)
-	if (!G3d_writeHeader(map,
-			     map->region.proj, map->region.zone,
-			     map->region.north, map->region.south,
-			     map->region.east, map->region.west,
-			     map->region.top, map->region.bottom,
-			     map->region.rows, map->region.cols,
-			     map->region.depths,
-			     map->region.ew_res, map->region.ns_res,
-			     map->region.tb_res,
-			     map->tileX, map->tileY, map->tileZ,
-			     map->type,
-			     map->compression, map->useRle, map->useLzw,
-			     map->precision, map->offset, map->useXdr,
-			     map->hasIndex, map->unit)) {
-	    G3d_error("G3d_closeCell: error in G3d_writeHeader");
-	    return 0;
-	}
-
-    G3d_free(map->unit);
-    G3d_free(map);
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3dcolor.c
===================================================================
--- grass/trunk/lib/raster3d/g3dcolor.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dcolor.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,351 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-
-#include "G3d_intern.h"
-
-static int read_colors(const char *, const char *, struct Colors *);
-static int read_new_colors(FILE *, struct Colors *);
-static int read_old_colors(FILE *, struct Colors *);
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_removeColor(const char *name)
- /* adapted from G_remove_colr */
-{
-    return G_remove_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_readColors(const char *name, const char *mapset, struct Colors *colors)
- /* adapted from Rast_read_colors */
-{
-    const char *err;
-    struct FPRange drange;
-    DCELL dmin, dmax;
-
-    Rast_init_colors(colors);
-
-    Rast_mark_colors_as_fp(colors);
-
-    switch (read_colors(name, mapset, colors)) {
-    case -2:
-	if (G3d_readRange(name, mapset, &drange) >= 0) {
-	    Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
-	    if (!Rast_is_d_null_value(&dmin) && !Rast_is_d_null_value(&dmax))
-		Rast_make_rainbow_fp_colors(colors, dmin, dmax);
-	    return 0;
-	}
-	err = "missing";
-	break;
-    case -1:
-	err = "invalid";
-	break;
-    default:
-	return 1;
-    }
-
-    G_warning("color support for [%s] in mapset [%s] %s", name, mapset, err);
-    return -1;
-}
-
-static int read_colors(const char *name, const char *mapset,
-		       struct Colors *colors)
-{
-    FILE *fd;
-    int stat;
-    char buf[1024];
-
-    fd = G_fopen_old_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name, mapset);
-    if (!fd)
-	return -2;
-
-    /*
-     * first line in 4.0 color files is %
-     * otherwise it is pre 4.0
-     */
-    if (fgets(buf, sizeof buf, fd) == NULL) {
-	fclose(fd);
-	return -1;
-    }
-    G_fseek(fd, 0L, 0);
-
-    G_strip(buf);
-    if (*buf == '%') {		/* 4.0 format */
-	stat = read_new_colors(fd, colors);
-	colors->version = 0;	/* 4.0 format */
-    }
-    else {
-	stat = read_old_colors(fd, colors);
-	colors->version = -1;	/* pre 4.0 format */
-    }
-    fclose(fd);
-    return stat;
-}
-
-/* parse input lines with the following formats
- *   val1:r:g:b val2:r:g:b
- *   val:r:g:b          (implies cat1==cat2)
- *
- * r:g:b can be just a single grey level
- *   cat1:x cat2:y
- *   cat:x
- *
- * optional lines are
- *    invert            invert color table
- *    shift:n           where n is the amount to shift the color table
- */
-static int read_new_colors(FILE * fd, struct Colors *colors)
-{
-    double val1, val2;
-    long cat1, cat2;
-    int r1, g1, b1;
-    int r2, g2, b2;
-    char buf[1024];
-    char word1[256], word2[256];
-    int n, fp_rule;
-    int null, undef;
-    int modular;
-    DCELL shift;
-
-    if (fgets(buf, sizeof buf, fd) == NULL)
-	return -1;
-    G_strip(buf);
-
-    if (sscanf(buf + 1, "%lf %lf", &val1, &val2) == 2)
-	Rast_set_d_color_range((DCELL) val1, (DCELL) val2, colors);
-
-    modular = 0;
-    while (fgets(buf, sizeof buf, fd)) {
-	null = undef = fp_rule = 0;
-	*word1 = *word2 = 0;
-	n = sscanf(buf, "%s %s", word1, word2);
-	if (n < 1)
-	    continue;
-
-	if (sscanf(word1, "shift:%lf", &shift) == 1
-	    || (strcmp(word1, "shift:") == 0 &&
-		sscanf(word2, "%lf", &shift) == 1)) {
-	    Rast_shift_d_colors(shift, colors);
-	    continue;
-	}
-	if (strcmp(word1, "invert") == 0) {
-	    Rast_invert_colors(colors);
-	    continue;
-	}
-	if (strcmp(word1, "%%") == 0) {
-	    modular = !modular;
-	    continue;
-	}
-
-	switch (sscanf(word1, "nv:%d:%d:%d", &r1, &g1, &b1)) {
-	case 1:
-	    null = 1;
-	    b1 = g1 = r1;
-	    break;
-	case 3:
-	    null = 1;
-	    break;
-	}
-	if (!null)
-	    switch (sscanf(word1, "*:%d:%d:%d", &r1, &g1, &b1)) {
-	    case 1:
-		undef = 1;
-		b1 = g1 = r1;
-		break;
-	    case 3:
-		undef = 1;
-		break;
-	    }
-	if (!null && !undef)
-	    switch (sscanf(word1, "%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
-	    case 2:
-		b1 = g1 = r1;
-		break;
-	    case 4:
-		break;
-	    default:
-		if (sscanf(word1, "%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
-		    fp_rule = 1;
-		else if (sscanf(word1, "%lf:%d", &val1, &r1) == 2) {
-		    fp_rule = 1;
-		    b1 = g1 = r1;
-		}
-		else
-		    continue;	/* other lines are ignored */
-	    }
-	if (n == 2) {
-	    switch (sscanf(word2, "%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
-	    case 2:
-		b2 = g2 = r2;
-		if (fp_rule)
-		    val2 = (DCELL) cat2;
-		break;
-	    case 4:
-		if (fp_rule)
-		    val2 = (DCELL) cat2;
-		break;
-	    default:
-		if (sscanf(word2, "%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
-		    if (!fp_rule)
-			val1 = (DCELL) cat1;
-		    fp_rule = 1;
-		}
-		else if (sscanf(word2, "%lf:%d", &val2, &r2) == 2) {
-		    if (!fp_rule)
-			val1 = (DCELL) cat1;
-		    fp_rule = 1;
-		    b2 = g2 = r2;
-		}
-		else
-		    continue;	/* other lines are ignored */
-	    }
-	}
-	else {
-	    if (!fp_rule)
-		cat2 = cat1;
-	    else
-		val2 = val1;
-	    r2 = r1;
-	    g2 = g1;
-	    b2 = b1;
-	}
-	if (null)
-	    Rast_set_null_value_color(r1, g1, b1, colors);
-	else if (undef)
-	    Rast_set_default_color(r1, g1, b1, colors);
-
-	else if (modular) {
-	    if (fp_rule)
-		Rast_add_modular_d_color_rule((DCELL *) & val1, r1, g1,
-						  b1, (DCELL *) & val2, r2,
-						  g2, b2, colors);
-	    else
-		Rast_add_modular_c_color_rule((CELL *) &cat1, r1, g1, b1,
-					      (CELL *) &cat2, r2, g2, b2, colors);
-	}
-	else {
-	    if (fp_rule)
-		Rast_add_d_color_rule((DCELL *) & val1, r1, g1, b1,
-				      (DCELL *) & val2, r2, g2, b2,
-				      colors);
-	    else
-		Rast_add_c_color_rule((CELL *) &cat1, r1, g1, b1,
-				      (CELL *) &cat2, r2, g2, b2, colors);
-	}
-	/*
-	   fprintf (stderr, "adding rule %d=%.2lf %d %d %d  %d=%.2lf %d %d %d\n", cat1,val1,  r1, g1, b1, cat2, val2, r2, g2, b2);
-	 */
-    }
-    return 1;
-}
-
-static int read_old_colors(FILE * fd, struct Colors *colors)
-{
-    char buf[256];
-    long n;
-    long min;
-    float red_f, grn_f, blu_f;
-    int red, grn, blu;
-    int old;
-    int zero;
-
-    Rast_init_colors(colors);
-    /*
-     * first line in pre 3.0 color files is number of colors - ignore
-     * otherwise it is #min first color, and the next line is for color 0
-     */
-    if (fgets(buf, sizeof buf, fd) == NULL)
-	return -1;
-
-    G_strip(buf);
-    if (*buf == '#') {		/* 3.0 format */
-	old = 0;
-	if (sscanf(buf + 1, "%ld", &min) != 1)	/* first color */
-	    return -1;
-	zero = 1;
-    }
-    else {
-	old = 1;
-	min = 0;
-	zero = 0;
-    }
-
-    colors->cmin = min;
-    n = min;
-    while (fgets(buf, sizeof buf, fd)) {
-	if (old) {
-	    if (sscanf(buf, "%f %f %f", &red_f, &grn_f, &blu_f) != 3)
-		return -1;
-
-	    red = 256 * red_f;
-	    grn = 256 * grn_f;
-	    blu = 256 * blu_f;
-	}
-	else {
-	    switch (sscanf(buf, "%d %d %d", &red, &grn, &blu)) {
-	    case 1:
-		blu = grn = red;
-		break;
-	    case 2:
-		blu = grn;
-		break;
-	    case 3:
-		break;
-	    default:
-		return -1;
-	    }
-	}
-	if (zero) {
-	    Rast__insert_color_into_lookup((CELL) 0, red, grn, blu,
-					&colors->fixed);
-	    zero = 0;
-	}
-	else
-	    Rast__insert_color_into_lookup((CELL) n++, red, grn, blu,
-					&colors->fixed);
-    }
-    colors->cmax = n - 1;
-
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_writeColors(const char *name, const char *mapset, struct Colors *colors)
- /* adapted from Rast_write_colors */
-{
-    FILE *fd;
-
-    if (strcmp(mapset, G_mapset()) != 0) {
-	G_warning(_("mapset <%s> is not the current mapset"), mapset);
-	return -1;
-    }
-
-    fd = G_fopen_new_misc(G3D_DIRECTORY, G3D_COLOR_ELEMENT, name);
-    if (!fd)
-	return -1;
-
-    Rast__write_colors(fd, colors);
-    fclose(fd);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------------*/

Deleted: grass/trunk/lib/raster3d/g3ddefaults.c
===================================================================
--- grass/trunk/lib/raster3d/g3ddefaults.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3ddefaults.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,556 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <grass/G3d.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-#define G3D_NO_DEFAULT -10
-
-#define G3D_COMPRESSION_DEFAULT G3D_COMPRESSION
-#define G3D_USE_LZW_DEFAULT G3D_NO_LZW
-#define G3D_USE_RLE_DEFAULT G3D_USE_RLE
-#define G3D_PRECISION_DEFAULT G3D_MAX_PRECISION
-#define G3D_CACHE_SIZE_DEFAULT 1000
-#define G3D_CACHE_SIZE_MAX_DEFAULT 16777216
-#define G3D_FILE_TYPE_DEFAULT DCELL_TYPE
-#define G3D_TILE_X_DEFAULT 16
-#define G3D_TILE_Y_DEFAULT 16
-#define G3D_TILE_Z_DEFAULT 8
-#define G3D_ERROR_FUN_DEFAULT G3d_skipError
-#define G3D_UNIT_DEFAULT "none"
-
-/*---------------------------------------------------------------------------*/
-
-#define G3D_COMPRESSION_ENV_VAR_YES "G3D_USE_COMPRESSION"
-#define G3D_COMPRESSION_ENV_VAR_NO "G3D_NO_COMPRESSION"
-
-#define G3D_LZW_ENV_VAR_YES "G3D_USE_LZW"
-#define G3D_LZW_ENV_VAR_NO "G3D_NO_LZW"
-
-#define G3D_RLE_ENV_VAR_YES "G3D_USE_RLE"
-#define G3D_RLE_ENV_VAR_NO "G3D_NO_RLE"
-
-#define G3D_PRECISION_ENV_VAR "G3D_PRECISION"
-#define G3D_PRECISION_ENV_VAR_MAX "G3D_MAX_PRECISION"
-
-#define G3D_CACHE_SIZE_ENV_VAR "G3D_DEFAULT_CACHE_SIZE"
-#define G3D_CACHE_SIZE_MAX_ENV_VAR "G3D_MAX_CACHE_SIZE"
-
-#define G3D_FILE_FLOAT_ENV_VAR "G3D_WRITE_FLOAT"
-#define G3D_FILE_DOUBLE_ENV_VAR "G3D_WRITE_DOUBLE"
-
-#define G3D_TILE_DIM_X_ENV_VAR "G3D_TILE_DIMENSION_X"
-#define G3D_TILE_DIM_Y_ENV_VAR "G3D_TILE_DIMENSION_Y"
-#define G3D_TILE_DIM_Z_ENV_VAR "G3D_TILE_DIMENSION_Z"
-
-#define G3D_FATAL_ERROR_ENV_VAR "G3D_USE_FATAL_ERROR"
-#define G3D_PRINT_ERROR_ENV_VAR "G3D_USE_PRINT_ERROR"
-
-#define G3D_DEFAULT_WINDOW3D "G3D_DEFAULT_WINDOW3D"
-
-/*---------------------------------------------------------------------------*/
-
-int g3d_do_compression = G3D_NO_DEFAULT;
-int g3d_do_lzw_compression = G3D_NO_DEFAULT;
-int g3d_do_rle_compression = G3D_NO_DEFAULT;
-int g3d_precision = G3D_NO_DEFAULT;
-int g3d_cache_default = G3D_NO_DEFAULT;
-int g3d_cache_max = G3D_NO_DEFAULT;
-int g3d_file_type = G3D_NO_DEFAULT;
-int g3d_tile_dimension[3] =
-    { G3D_NO_DEFAULT, G3D_NO_DEFAULT, G3D_NO_DEFAULT };
-void (*g3d_error_fun) (const char *) = NULL;
-char *g3d_unit_default = NULL;
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * <em>doCompress</em> should be one of G3D_NO_COMPRESSION and
- * G3D_COMPRESSION, <em>doRle</em> should be either G3D_NO_RLE or
- * G3D_USE_RLE, and <em>precision</em> should be either G3D_MAX_PRECISION or
- * a positive integer.
- *
- *  \param doCompress
- *  \param doLzw
- *  \param doRle
- *  \param precision
- *  \return void
- */
-
-void
-G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int precision)
-{
-    if ((doCompress != G3D_NO_COMPRESSION) && (doCompress != G3D_COMPRESSION))
-	G3d_fatalError("G3d_setCompressionMode: wrong value for doCompress.");
-
-    g3d_do_compression = doCompress;
-
-    if (doCompress == G3D_NO_COMPRESSION)
-	return;
-
-    if ((doLzw != G3D_NO_LZW) && (doLzw != G3D_USE_LZW))
-	G3d_fatalError("G3d_setCompressionMode: wrong value for doLzw.");
-
-    if ((doRle != G3D_NO_RLE) && (doRle != G3D_USE_RLE))
-	G3d_fatalError("G3d_setCompressionMode: wrong value for doRle.");
-
-    if (precision < -1)
-	G3d_fatalError("G3d_setCompressionMode: wrong value for precision.");
-
-    g3d_do_lzw_compression = doLzw;
-    g3d_do_rle_compression = doRle;
-    g3d_precision = precision;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * 
- *
- *  \param doCompress
- *  \param doLzw
- *  \param doRle
- *  \param precision
- *  \return void
- */
-
-void
-G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
-		       int *precision)
-{
-    if (doCompress != NULL)
-	*doCompress = g3d_do_compression;
-    if (doLzw != NULL)
-	*doLzw = g3d_do_lzw_compression;
-    if (doRle != NULL)
-	*doRle = g3d_do_rle_compression;
-    if (precision != NULL)
-	*precision = g3d_precision;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  set cache size
- *
- *  \param nTiles
- *  \return void
- */
-
-void G3d_setCacheSize(int nTiles)
-{
-    if (nTiles < 0)
-	G3d_fatalError("G3d_setCacheSize: size out of range.");
-
-    g3d_cache_default = nTiles;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  get cache size
- *
- *  \return int
- */
-
-int G3d_getCacheSize()
-{
-    return g3d_cache_default;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief Set cache limit
- *
- *  set cache limit
- *
- *  \param nBytes
- *  \return void
- */
-
-void G3d_setCacheLimit(int nBytes)
-{
-    if (nBytes <= 0)
-	G3d_fatalError("G3d_setCacheLimit: size out of range.");
-
-    g3d_cache_max = nBytes;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief Get cache limit
- *
- *  get cache limit
- *
- *  \param nBytes
- *  \return int
- */
-
-int G3d_getCacheLimit()
-{
-    return g3d_cache_max;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  set G3d file type
- *
- *  \param type
- *  \return void
- */
-
-void G3d_setFileType(int type)
-{
-    if ((type != FCELL_TYPE) && (type != DCELL_TYPE))
-	G3d_fatalError("G3d_setFileTypeDefault: invalid type");
-
-    g3d_file_type = type;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * get G3d file type
- *
- *  \param type
- *  \return int
- */
-
-int G3d_getFileType()
-{
-    return g3d_file_type;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * set Tile Dimension
- *
- *  \param tileX
- *  \param tileY
- *  \param tileZ
- *  \return void
- */
-
-void G3d_setTileDimension(int tileX, int tileY, int tileZ)
-{
-    if ((g3d_tile_dimension[0] = tileX) <= 0)
-	G3d_fatalError
-	    ("G3d_setTileDimension: value for tile x environment variable out of range");
-
-    if ((g3d_tile_dimension[1] = tileY) <= 0)
-	G3d_fatalError
-	    ("G3d_setTileDimension: value for tile y environment variable out of range");
-
-    if ((g3d_tile_dimension[2] = tileZ) <= 0)
-	G3d_fatalError
-	    ("G3d_setTileDimension: value for tile z environment variable out of range");
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  get Tile Dimension
- *
- *  \param tileX
- *  \param tileY
- *  \param tileZ
- *  \return void
- */
-
-void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
-{
-    *tileX = g3d_tile_dimension[0];
-    *tileY = g3d_tile_dimension[1];
-    *tileZ = g3d_tile_dimension[2];
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  set error function
- *
- *  \param 
- *  \return void
- */
-
-void G3d_setErrorFun(void (*fun) (const char *))
-{
-    g3d_error_fun = fun;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  set G3d unit
- *
- *  \param unit
- *  \return void
- */
-
-void G3d_setUnit(const char *unit)
-{
-    G3d_free(g3d_unit_default);
-    g3d_unit_default = G_store(unit);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Initializes the default values described
- * in G3D Defaults.  Applications have to use this function only if they need to
- * query the default values before the first file (either old or new) has been
- * opened.
- *
- *  \return void
- */
-
-void G3d_initDefaults(void)
-{
-    static int firstTime = 1;
-    const char *value, *windowName;
-    G3D_Region window;
-
-    if (!firstTime)
-	return;
-    firstTime = 0;
-
-    if (g3d_do_compression == G3D_NO_DEFAULT) {
-	if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_YES)) {
-	    g3d_do_compression = G3D_COMPRESSION;
-	}
-	else {
-	    if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_NO)) {
-		g3d_do_compression = G3D_NO_COMPRESSION;
-	    }
-	    else {
-		g3d_do_compression = G3D_COMPRESSION_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_do_lzw_compression == G3D_NO_DEFAULT) {
-	if (NULL != getenv(G3D_LZW_ENV_VAR_YES)) {
-	    g3d_do_lzw_compression = G3D_USE_LZW;
-	}
-	else {
-	    if (NULL != getenv(G3D_LZW_ENV_VAR_NO)) {
-		g3d_do_lzw_compression = G3D_NO_LZW;
-	    }
-	    else {
-		g3d_do_lzw_compression = G3D_USE_LZW_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_do_rle_compression == G3D_NO_DEFAULT) {
-	if (NULL != getenv(G3D_RLE_ENV_VAR_YES)) {
-	    g3d_do_rle_compression = G3D_USE_RLE;
-	}
-	else {
-	    if (NULL != getenv(G3D_RLE_ENV_VAR_NO)) {
-		g3d_do_rle_compression = G3D_NO_RLE;
-	    }
-	    else {
-		g3d_do_rle_compression = G3D_USE_RLE_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_precision == G3D_NO_DEFAULT) {
-	if (NULL != getenv(G3D_PRECISION_ENV_VAR_MAX)) {
-	    g3d_precision = G3D_MAX_PRECISION;
-	}
-	else {
-	    value = getenv(G3D_PRECISION_ENV_VAR);
-	    if (value == NULL) {
-		g3d_precision = G3D_PRECISION_DEFAULT;
-	    }
-	    else {
-		if (sscanf(value, "%d", &g3d_precision) != 1) {
-		    G3d_fatalError
-			("G3d_initDefaults: precision environment variable has invalid value");
-		}
-		else {
-		    if (g3d_precision < -1) {
-			G3d_fatalError
-			    ("G3d_initDefaults: value for cache environment variable out of range");
-		    }
-		}
-	    }
-	}
-    }
-
-    if (g3d_file_type == G3D_NO_DEFAULT) {
-	if (NULL != getenv(G3D_FILE_FLOAT_ENV_VAR)) {
-	    g3d_file_type = FCELL_TYPE;
-	}
-	else {
-	    if (NULL != getenv(G3D_FILE_DOUBLE_ENV_VAR)) {
-		g3d_file_type = DCELL_TYPE;
-	    }
-	    else {
-		g3d_file_type = G3D_FILE_TYPE_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_cache_default == G3D_NO_DEFAULT) {
-	value = getenv(G3D_CACHE_SIZE_ENV_VAR);
-
-	if (value == NULL) {
-	    g3d_cache_default = G3D_CACHE_SIZE_DEFAULT;
-	}
-	else {
-	    if (sscanf(value, "%d", &g3d_cache_default) != 1) {
-		G3d_fatalError
-		    ("G3d_initDefaults: cache environment variable has invalid value");
-	    }
-	    if (g3d_cache_default < 0) {
-		G3d_fatalError
-		    ("G3d_initDefaults: value for cache environment variable out of range");
-	    }
-	}
-    }
-
-    if (g3d_cache_max == G3D_NO_DEFAULT) {
-	value = getenv(G3D_CACHE_SIZE_MAX_ENV_VAR);
-
-	if (value == NULL) {
-	    g3d_cache_max = G3D_CACHE_SIZE_MAX_DEFAULT;
-	}
-	else {
-	    if (sscanf(value, "%d", &g3d_cache_max) != 1) {
-		G3d_fatalError
-		    ("G3d_initDefaults: cache environment variable has invalid value");
-	    }
-	    if (g3d_cache_max < 0) {
-		G3d_fatalError
-		    ("G3d_initDefaults: value for cache environment variable out of range");
-	    }
-	}
-    }
-
-    if (g3d_tile_dimension[0] == G3D_NO_DEFAULT) {
-	value = getenv(G3D_TILE_DIM_X_ENV_VAR);
-
-	if (value == NULL) {
-	    g3d_tile_dimension[0] = G3D_TILE_X_DEFAULT;
-	}
-	else {
-	    if (sscanf(value, "%d", g3d_tile_dimension) != 1) {
-		G3d_fatalError
-		    ("G3d_initDefaults: tile dimension x environment variable has invalid value");
-	    }
-	    if (g3d_tile_dimension[0] <= 0) {
-		G3d_fatalError
-		    ("G3d_initDefaults: value for tile x environment variable out of range");
-	    }
-	}
-
-	value = getenv(G3D_TILE_DIM_Y_ENV_VAR);
-
-	if (value == NULL) {
-	    g3d_tile_dimension[1] = G3D_TILE_Y_DEFAULT;
-	}
-	else {
-	    if (sscanf(value, "%d", g3d_tile_dimension + 1) != 1) {
-		G3d_fatalError
-		    ("G3d_initDefaults: tile dimension y environment variable has invalid value");
-	    }
-	    if (g3d_tile_dimension[1] <= 0) {
-		G3d_fatalError
-		    ("G3d_initDefaults: value for tile y environment variable out of range");
-	    }
-	}
-
-	value = getenv(G3D_TILE_DIM_Z_ENV_VAR);
-
-	if (value == NULL) {
-	    g3d_tile_dimension[2] = G3D_TILE_Z_DEFAULT;
-	}
-	else {
-	    if (sscanf(value, "%d", g3d_tile_dimension + 2) != 1) {
-		G3d_fatalError
-		    ("G3d_initDefaults: tile dimension z environment variable has invalid value");
-	    }
-	    if (g3d_tile_dimension[2] <= 0) {
-		G3d_fatalError
-		    ("G3d_initDefaults: value for tile z environment variable out of range");
-	    }
-	}
-    }
-
-    if (g3d_error_fun == NULL) {
-	value = getenv(G3D_FATAL_ERROR_ENV_VAR);
-
-	if (value != NULL) {
-	    g3d_error_fun = G3d_fatalError_noargs;
-	}
-	else {
-	    value = getenv(G3D_PRINT_ERROR_ENV_VAR);
-
-	    if (value != NULL) {
-		g3d_error_fun = G3d_printError;
-	    }
-	    else {
-		g3d_error_fun = G3D_ERROR_FUN_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_unit_default == NULL)
-	g3d_unit_default = G_store(G3D_UNIT_DEFAULT);
-
-    windowName = G3d_getWindowParams();
-    if (windowName == NULL) {
-	value = getenv(G3D_DEFAULT_WINDOW3D);
-	if (value != NULL)
-	    if (*value != 0)
-		windowName = value;
-    }
-
-    if (!G3d_readWindow(&window, windowName))
-	G3d_fatalError("G3d_initDefaults: Error reading window");
-    G3d_setWindow(&window);
-
-}

Deleted: grass/trunk/lib/raster3d/g3ddoubleio.c
===================================================================
--- grass/trunk/lib/raster3d/g3ddoubleio.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3ddoubleio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,122 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_writeDoubles(int fd, int useXdr, const double *i, int nofNum)
-{
-    int firstTime = 1;
-    XDR xdrEncodeStream;
-    char xdrDoubleBuf[G3D_XDR_DOUBLE_LENGTH * 1024];
-    u_int n;
-
-    if (nofNum <= 0)
-	G3d_fatalError("G3d_writeDoubles: nofNum out of range");
-
-    if (useXdr == G3D_NO_XDR) {
-	if (write(fd, i, sizeof(double) * nofNum) != sizeof(double) * nofNum) {
-	    G3d_error("G3d_writeDoubles: writing to file failed");
-	    return 0;
-	}
-	else {
-	    return 1;
-	}
-    }
-
-
-    if (firstTime) {
-	xdrmem_create(&xdrEncodeStream, xdrDoubleBuf,
-		      G3D_XDR_DOUBLE_LENGTH * 1024, XDR_ENCODE);
-	firstTime = 1;
-    }
-
-    do {
-	n = nofNum % 1024;
-	if (n == 0)
-	    n = 1024;
-
-	if (!xdr_setpos(&xdrEncodeStream, 0)) {
-	    G3d_error("G3d_writeDoubles: positioning xdr failed");
-	    return 0;
-	}
-
-	if (!xdr_vector(&xdrEncodeStream, (char *)i, n, sizeof(double),
-			(xdrproc_t) xdr_double)) {
-	    G3d_error("G3d_writeDoubles: writing xdr failed");
-	    return 0;
-	}
-
-	if (write(fd, xdrDoubleBuf, G3D_XDR_DOUBLE_LENGTH * n) !=
-	    G3D_XDR_DOUBLE_LENGTH * n) {
-	    G3d_error("G3d_writeDoubles: writing xdr to file failed");
-	    return 0;
-	}
-
-	nofNum -= n;
-	i += n;
-    } while (nofNum);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_readDoubles(int fd, int useXdr, double *i, int nofNum)
-{
-    int firstTime = 1;
-    XDR xdrDecodeStream;
-    char xdrDoubleBuf[G3D_XDR_DOUBLE_LENGTH * 1024];
-    u_int n;
-
-    if (nofNum <= 0)
-	G3d_fatalError("G3d_readDoubles: nofNum out of range");
-
-    if (useXdr == G3D_NO_XDR) {
-	if (read(fd, i, sizeof(double) * nofNum) != sizeof(double) * nofNum) {
-	    G3d_error("G3d_readDoubles: reading from file failed");
-	    return 0;
-	}
-	else {
-	    return 1;
-	}
-    }
-
-    if (firstTime) {
-	xdrmem_create(&xdrDecodeStream, xdrDoubleBuf,
-		      G3D_XDR_DOUBLE_LENGTH * 1024, XDR_DECODE);
-	firstTime = 1;
-    }
-
-    do {
-	n = nofNum % 1024;
-	if (n == 0)
-	    n = 1024;
-
-	if (read(fd, xdrDoubleBuf, G3D_XDR_DOUBLE_LENGTH * n) !=
-	    G3D_XDR_DOUBLE_LENGTH * n) {
-	    G3d_error("G3d_readDoubles: reading xdr from file failed");
-	    return 0;
-	}
-
-	if (!xdr_setpos(&xdrDecodeStream, 0)) {
-	    G3d_error("G3d_readDoubles: positioning xdr failed");
-	    return 0;
-	}
-
-	if (!xdr_vector(&xdrDecodeStream, (char *)i, n, sizeof(double),
-			(xdrproc_t) xdr_double)) {
-	    G3d_error("G3d_readDoubles: reading xdr failed");
-	    return 0;
-	}
-
-	nofNum -= n;
-	i += n;
-    } while (nofNum);
-
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3derror.c
===================================================================
--- grass/trunk/lib/raster3d/g3derror.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3derror.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,85 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <time.h>
-#include <stdarg.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include <grass/gis.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  This function ignores the error.
- *
- *  \param 
- *  \return void
- */
-
-void G3d_skipError(const char *msg)
-{
-}
-
-
-/*!
- * \brief 
- *
- *  This function prints the
- * error message <em>msg</em> to <em>stderr</em> and returns.
- *
- *  \param 
- *  \return void
- */
-
-void G3d_printError(const char *msg)
-{
-    fprintf(stderr, "ERROR: ");
-    fprintf(stderr, msg);
-    fprintf(stderr, "\n");
-}
-
-
-/*!
- * \brief 
- *
- *  This function prints the
- * error message <em>msg</em>, and terminates the program with an error status.
- *
- *  \param 
- *  \return void
- */
-
-void G3d_fatalError(const char *msg, ...)
-{
-    char buffer[2000];		/* No novels to the error logs, OK? */
-    va_list ap;
-
-    va_start(ap, msg);
-    vsprintf(buffer, msg, ap);
-    va_end(ap);
-
-    G_fatal_error("%s", buffer);
-}
-
-void G3d_fatalError_noargs(const char *msg)
-{
-    G_fatal_error("%s", msg);
-}
-
-void G3d_error(const char *msg, ...)
-{
-    char buffer[2000];		/* No novels to the error logs, OK? */
-    va_list ap;
-
-    va_start(ap, msg);
-    vsprintf(buffer, msg, ap);
-    va_end(ap);
-
-    (*g3d_error_fun) (buffer);
-}

Deleted: grass/trunk/lib/raster3d/g3dfpxdr.c
===================================================================
--- grass/trunk/lib/raster3d/g3dfpxdr.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dfpxdr.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,267 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#include <grass/raster.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_isXdrNullNum(const void *num, int isFloat)
-{
-    static const char null_bytes[8] = {
-	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
-    };
-
-    return memcmp(num, null_bytes, isFloat ? 4 : 8) == 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_isXdrNullFloat(const float *f)
-{
-    return G3d_isXdrNullNum(f, 1);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_isXdrNullDouble(const double *d)
-{
-    return G3d_isXdrNullNum(d, 0);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_setXdrNullNum(void *num, int isFloat)
-{
-    static const char null_bytes[8] = {
-	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
-    };
-
-    memcpy(num, null_bytes, isFloat ? 4 : 8);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_setXdrNullDouble(double *d)
-{
-    G3d_setXdrNullNum(d, 0);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_setXdrNullFloat(float *f)
-{
-    G3d_setXdrNullNum(f, 1);
-}
-
-/*---------------------------------------------------------------------------*/
-
-XDR xdrEncodeStream, xdrDecodeStream;	/* xdr support structures */
-
-int G3d_initFpXdr(G3D_Map * map, int misuseBytes)
-
-
-
- /* nof addtl bytes allocated for the xdr array so that */
-		      /* the array can also be (mis)used for other purposes */
-{
-    int doAlloc;
-
-    doAlloc = 0;
-
-    if (xdr == NULL) {
-	xdrLength = map->tileSize * G3D_MAX(map->numLengthExtern,
-					    map->numLengthIntern) +
-	    misuseBytes;
-	xdr = G3d_malloc(xdrLength);
-	if (xdr == NULL) {
-	    G3d_error("G3d_initFpXdr: error in G3d_malloc");
-	    return 0;
-	}
-
-	doAlloc = 1;
-    }
-    else if (map->tileSize * G3D_MAX(map->numLengthExtern,
-				     map->numLengthIntern) + misuseBytes
-	     > xdrLength) {
-	xdrLength = map->tileSize * G3D_MAX(map->numLengthExtern,
-					    map->numLengthIntern) +
-	    misuseBytes;
-	xdr = G3d_realloc(xdr, xdrLength);
-	if (xdr == NULL) {
-	    G3d_error("G3d_initFpXdr: error in G3d_realloc");
-	    return 0;
-	}
-
-	doAlloc = 1;
-    }
-
-    if (doAlloc) {
-	xdrmem_create(&(xdrEncodeStream), xdr, (u_int) xdrLength, XDR_ENCODE);
-	xdrmem_create(&(xdrDecodeStream), xdr, (u_int) xdrLength, XDR_DECODE);
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-static void *xdrTmp;
-static int dstType, srcType, type, externLength, eltLength, isFloat, useXdr;
-static int (*xdrFun) ();
-static XDR *xdrs;
-static double tmpValue, *tmp;
-
-int G3d_initCopyToXdr(G3D_Map * map, int sType)
-{
-    xdrTmp = xdr;
-    useXdr = map->useXdr;
-    srcType = sType;
-
-    if (map->useXdr == G3D_USE_XDR) {
-	if (!xdr_setpos(&(xdrEncodeStream), 0)) {
-	    G3d_error("G3d_InitCopyToXdr: positioning xdr failed");
-	    return 0;
-	}
-	xdrs = &(xdrEncodeStream);
-    }
-
-    type = map->type;
-    isFloat = (type == FCELL_TYPE);
-    externLength = G3d_externLength(type);
-    eltLength = G3d_length(srcType);
-    if (isFloat)
-	xdrFun = xdr_float;
-    else
-	xdrFun = xdr_double;
-    tmp = &tmpValue;
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_copyToXdr(const void *src, int nofNum)
-{
-    int i;
-
-    if (useXdr == G3D_NO_XDR) {
-	G3d_copyValues(src, 0, srcType, xdrTmp, 0, type, nofNum);
-	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * G3d_externLength(type));
-	return 1;
-    }
-
-    for (i = 0; i < nofNum; i++, src = G_incr_void_ptr(src, eltLength)) {
-
-	if (G3d_isNullValueNum(src, srcType)) {
-	    G3d_setXdrNullNum(xdrTmp, isFloat);
-	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
-		G3d_error("G3d_copyToXdr: positioning xdr failed");
-		return 0;
-	    }
-	}
-	else {
-	    if (type == srcType) {
-		if (xdrFun(xdrs, src) < 0) {
-		    G3d_error("G3d_copyToXdr: writing xdr failed");
-		    return 0;
-		}
-	    }
-	    else {
-		if (type == FCELL_TYPE)
-		    *((float *)tmp) = (float)*((double *)src);
-		else
-		    *((double *)tmp) = (double)*((float *)src);
-		if (xdrFun(xdrs, tmp) < 0) {
-		    G3d_error("G3d_copyToXdr: writing xdr failed");
-		    return 0;
-		}
-	    }
-	}
-
-	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_initCopyFromXdr(G3D_Map * map, int dType)
-{
-    xdrTmp = xdr;
-    useXdr = map->useXdr;
-    dstType = dType;
-
-    if (useXdr == G3D_USE_XDR) {
-	if (!xdr_setpos(&(xdrDecodeStream), 0)) {
-	    G3d_error("G3d_initCopyFromXdr: positioning xdr failed");
-	    return 0;
-	}
-	xdrs = &(xdrDecodeStream);
-    }
-
-    type = map->type;
-    isFloat = (type == FCELL_TYPE);
-    externLength = G3d_externLength(type);
-    eltLength = G3d_length(dstType);
-    if (isFloat)
-	xdrFun = xdr_float;
-    else
-	xdrFun = xdr_double;
-    tmp = &tmpValue;
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_copyFromXdr(int nofNum, void *dst)
-{
-    int i;
-
-    if (useXdr == G3D_NO_XDR) {
-	G3d_copyValues(xdrTmp, 0, type, dst, 0, dstType, nofNum);
-	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * G3d_externLength(type));
-	return 1;
-    }
-
-    for (i = 0; i < nofNum; i++, dst = G_incr_void_ptr(dst, eltLength)) {
-
-	if (G3d_isXdrNullNum(xdrTmp, isFloat)) {
-	    G3d_setNullValue(dst, 1, dstType);
-	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
-		G3d_error("G3d_copyFromXdr: positioning xdr failed");
-		return 0;
-	    }
-	}
-	else {
-	    if (type == dstType) {
-		if (xdrFun(xdrs, dst) < 0) {
-		    G3d_error("G3d_copyFromXdr: reading xdr failed");
-		    return 0;
-		}
-	    }
-	    else {
-		if (xdrFun(xdrs, tmp) < 0) {
-		    G3d_error("G3d_copyFromXdr: reading xdr failed");
-		    return 0;
-		}
-		if (type == FCELL_TYPE)
-		    *((double *)dst) = (double)*((float *)tmp);
-		else
-		    *((float *)dst) = (float)*((double *)tmp);
-	    }
-	}
-
-	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
-    }
-
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3dgetvalue.c
===================================================================
--- grass/trunk/lib/raster3d/g3dgetvalue.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dgetvalue.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,245 +0,0 @@
-#include <grass/raster.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Returns in <em>*value</em> the resampled cell-value of the cell with
- * window-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
- * This function invokes a fatal error if an error occurs.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \param type
- *  \return void
- */
-
-void G3d_getValue(G3D_Map * map, int x, int y, int z, void *value, int type)
-{
-    /* get the resampled value */
-    map->resampleFun(map, x, y, z, value, type);
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Is equivalent to
- * <tt>G3d_getValue (map, x, y, z, &value, FCELL_TYPE);</tt> return value.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \return float
- */
-
-float G3d_getFloat(G3D_Map * map, int x, int y, int z)
-{
-    float value;
-
-    G3d_getValue(map, x, y, z, &value, FCELL_TYPE);
-    return value;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Is equivalent
- * to <tt>G3d_getValue (map, x, y, z, &value, DCELL_TYPE);</tt> return value.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \return double
- */
-
-double G3d_getDouble(G3D_Map * map, int x, int y, int z)
-{
-    double value;
-
-    G3d_getValue(map, x, y, z, &value, DCELL_TYPE);
-    return value;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
- * window coordinates <em>(north, east, top)</em>.  The
- * value is resampled using the resampling function specified for <em>map</em>. The
- * <em>value</em> is of <em>type</em>.
- *
- *  \param map
- *  \param north
- *  \param east
- *  \param top
- *  \param value
- *  \param type
- *  \return void
- */
-
-void
-G3d_getWindowValue(G3D_Map * map, double north, double east, double top,
-		   void *value, int type)
-{
-    int col, row, depth;
-
-    G3d_location2coord(&(map->window), north, east, top, &col, &row, &depth);
-
-    /* if (row, col, depth) outside window return NULL value */
-    if ((row < 0) || (row >= map->window.rows) ||
-	(col < 0) || (col >= map->window.cols) ||
-	(depth < 0) || (depth >= map->window.depths)) {
-	G3d_setNullValue(value, 1, type);
-	return;
-    }
-
-    /* Get the value from the map in map-region resolution */
-	map->resampleFun(map, col, row, depth, value, type);
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
- * region coordinates <em>(north, east, top)</em>.
- *
- *  \param map
- *  \param north
- *  \param east
- *  \param top
- *  \param value
- *  \param type
- *  \return void
- */
-
-void
-G3d_getRegionValue(G3D_Map * map, double north, double east, double top,
-		   void *value, int type)
-{
-    int row, col, depth;
-
-    G3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
-
-    /* if (row, col, depth) outside region return NULL value */
-    if ((row < 0) || (row >= map->region.rows) ||
-	(col < 0) || (col >= map->region.cols) ||
-	(depth < 0) || (depth >= map->region.depths)) {
-	G3d_setNullValue(value, 1, type);
-	return;
-    }
-
-    /* Get the value from the map in map-region resolution */
-	G3d_getValueRegion(map, col, row, depth, value, type);
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Is equivalent to <tt>G3d_getValueRegion (map, x, y, z, &value, FCELL_TYPE);</tt>
- * return value.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \return float
- */
-
-float G3d_getFloatRegion(G3D_Map * map, int x, int y, int z)
-{
-    int tileIndex, offs;
-    float *tile;
-
-    if (map->typeIntern == DCELL_TYPE)
-	return (float)G3d_getDoubleRegion(map, x, y, z);
-
-    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
-    tile = (float *)G3d_getTilePtr(map, tileIndex);
-
-    if (tile == NULL)
-	G3d_fatalError("G3d_getFloatRegion: error in G3d_getTilePtr");
-
-    return tile[offs];
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Is equivalent to <tt>G3d_getValueRegion (map, x, y, z, &value,
- * DCELL_TYPE);</tt> return value.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \return double
- */
-
-double G3d_getDoubleRegion(G3D_Map * map, int x, int y, int z)
-{
-    int tileIndex, offs;
-    double *tile;
-
-    if (map->typeIntern == FCELL_TYPE)
-	return (double)G3d_getFloatRegion(map, x, y, z);
-
-    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
-    tile = (double *)G3d_getTilePtr(map, tileIndex);
-
-    if (tile == NULL)
-	G3d_fatalError("G3d_getDoubleRegion: error in G3d_getTilePtr");
-
-    return tile[offs];
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Returns in <em>*value</em> the cell-value of the cell with
- * region-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
- * Here <em>region</em> means the coordinate in the cube of data in the file, i.e.
- * ignoring geographic coordinates.
- * This function invokes a fatal error if an error occurs.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \param type
- *  \return void
- */
-
-void
-G3d_getValueRegion(G3D_Map * map, int x, int y, int z, void *value, int type)
-{
-    if (type == FCELL_TYPE) {
-	*((float *)value) = G3d_getFloatRegion(map, x, y, z);
-	return;
-    }
-
-    *((double *)value) = G3d_getDoubleRegion(map, x, y, z);
-}

Deleted: grass/trunk/lib/raster3d/g3dhistory.c
===================================================================
--- grass/trunk/lib/raster3d/g3dhistory.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dhistory.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,106 +0,0 @@
-
-/**********************************************************************
- *
- *  G3d_readHistory (name, mapset, hist)
- *      char *name                   name of map
- *      char *mapset                 mapset that map belongs to
- *      struct History *hist        structure to hold history info
- *
- *  Reads the history information associated with map layer "map"
- *  in mapset "mapset" into the structure "hist".
- *
- *   returns:    0  if successful
- *              -1  on fail
- *
- *  note:   a warning message is printed if the file is incorrect
- *
- **********************************************************************
- *
- *  G3d_writeHistory (name, hist)
- *      char *name                   name of map
- *      struct History *hist        structure holding history info
- *
- *  Writes the history information associated with map layer "map"
- *  into current from the structure "hist".
- *
- *   returns:    0  if successful
- *              -1  on fail
- **********************************************************************/
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <grass/glocale.h>
-#include "G3d_intern.h"
-#include <grass/raster.h>
-
-/*simple error message */
-void SimpleErrorMessage(FILE * fd, const char *name, const char *mapset)
-{
-    if (fd != NULL)
-	fclose(fd);
-
-    G_warning(_("can't get history information for [%s] in mapset [%s]"),
-	      name, mapset);
-    return;
-}
-
-/*!
- * \brief read raster3d History file
- *
- * This routine reads the History file for
- * the raster3d file <b>name</b> in <b>mapset</b> into the <b>History</b>
- * structure.
- * A diagnostic message is printed and -1 is returned if there is an error
- * reading the History file. Otherwise, 0 is returned.
- * A warning message is printed if the file is incorrect.
- *
- *  \param name
- *  \param mapset
- *  \param history
- *  \return int
- */
-
-int G3d_readHistory(const char *name, const char *mapset, struct History *hist)
-{
-    FILE *fp;
-
-    G_zero(hist, sizeof(struct History));
-
-    fp = G_fopen_old_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name, mapset);
-    if (!fp)
-	return -2;
-
-    if (Rast__read_history(hist, fp) == 0)
-	return 0;
-
-    SimpleErrorMessage(fp, name, mapset);
-    return -1;
-}
-
-
-/*!
- * \brief write raster3d History file
- *
- * This routine writes the History file for the raster3d file
- * <b>name</b> in the current mapset from the <b>History</b> structure.
- * A diagnostic message is printed and -1 is returned if there is an error
- * writing the History file. Otherwise, 0 is returned.
- * <b>Note.</b> The <b>history</b> structure should first be initialized
- * using <i>Rast_short_history.</i>
- *
- *  \param name
- *  \param history
- *  \return int
- */
-
-int G3d_writeHistory(const char *name, struct History *hist)
-/* This function is adapted from Rast_write_history */
-{
-    FILE *fp = G_fopen_new_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name);
-    if (!fp)
-	return -1;
-
-    Rast__write_history(hist, fp);
-    return 0;
-}

Deleted: grass/trunk/lib/raster3d/g3dintio.c
===================================================================
--- grass/trunk/lib/raster3d/g3dintio.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dintio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,121 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_writeInts(int fd, int useXdr, const int *i, int nofNum)
-{
-    int firstTime = 1;
-    XDR xdrEncodeStream;
-    char xdrIntBuf[G3D_XDR_INT_LENGTH * 1024];
-    u_int n;
-
-    if (nofNum <= 0)
-	G3d_fatalError("G3d_writeInts: nofNum out of range");
-
-    if (useXdr == G3D_NO_XDR) {
-	if (write(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
-	    G3d_error("G3d_writeInts: writing to file failed");
-	    return 0;
-	}
-	else {
-	    return 1;
-	}
-    }
-
-    if (firstTime) {
-	xdrmem_create(&xdrEncodeStream, xdrIntBuf, G3D_XDR_INT_LENGTH * 1024,
-		      XDR_ENCODE);
-	firstTime = 1;
-    }
-
-    do {
-	n = nofNum % 1024;
-	if (n == 0)
-	    n = 1024;
-
-	if (!xdr_setpos(&xdrEncodeStream, 0)) {
-	    G3d_error("G3d_writeInts: positioning xdr failed");
-	    return 0;
-	}
-
-	if (!xdr_vector(&xdrEncodeStream, (char *)i, n, sizeof(int),
-			(xdrproc_t) xdr_int)) {
-	    G3d_error("G3d_writeInts: writing xdr failed");
-	    return 0;
-	}
-
-	if (write(fd, xdrIntBuf, G3D_XDR_INT_LENGTH * n) !=
-	    G3D_XDR_INT_LENGTH * n) {
-	    G3d_error("G3d_writeInts: writing xdr to file failed");
-	    return 0;
-	}
-
-	nofNum -= n;
-	i += n;
-    } while (nofNum);
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_readInts(int fd, int useXdr, int *i, int nofNum)
-{
-    int firstTime = 1;
-    XDR xdrDecodeStream;
-    char xdrIntBuf[G3D_XDR_INT_LENGTH * 1024];
-    u_int n;
-
-    if (nofNum <= 0)
-	G3d_fatalError("G3d_readInts: nofNum out of range");
-
-    if (useXdr == G3D_NO_XDR) {
-	if (read(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
-	    G3d_error("G3d_readInts: reading from file failed");
-	    return 0;
-	}
-	else {
-	    return 1;
-	}
-    }
-
-    if (firstTime) {
-	xdrmem_create(&xdrDecodeStream, xdrIntBuf, G3D_XDR_INT_LENGTH * 1024,
-		      XDR_DECODE);
-	firstTime = 1;
-    }
-
-    do {
-	n = nofNum % 1024;
-	if (n == 0)
-	    n = 1024;
-
-	if (read(fd, xdrIntBuf, G3D_XDR_INT_LENGTH * n) !=
-	    G3D_XDR_INT_LENGTH * n) {
-	    G3d_error("G3d_readInts: reading xdr from file failed");
-	    return 0;
-	}
-
-	if (!xdr_setpos(&xdrDecodeStream, 0)) {
-	    G3d_error("G3d_readInts: positioning xdr failed");
-	    return 0;
-	}
-
-	if (!xdr_vector(&xdrDecodeStream, (char *)i, n, sizeof(int),
-			(xdrproc_t) xdr_int)) {
-	    G3d_error("G3d_readInts: reading xdr failed");
-	    return 0;
-	}
-
-	nofNum -= n;
-	i += n;
-    } while (nofNum);
-
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3dkeys.c
===================================================================
--- grass/trunk/lib/raster3d/g3dkeys.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dkeys.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,140 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_keyGetInt(struct Key_Value *keys, const char *key, int *i)
-{
-    const char *str;
-
-    if ((str = G_find_key_value(key, keys)) == NULL) {
-	G3d_error("G3d_keyGetInt: cannot find field %s in key structure",
-		  key);
-	return 0;
-    }
-
-    if (sscanf(str, "%d", i) == 1)
-	return 1;
-
-    G3d_error("G3d_keyGetInt: invalid value: field %s in key structure", key);
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_keyGetDouble(struct Key_Value *keys, const char *key, double *d)
-{
-    const char *str;
-
-    if ((str = G_find_key_value(key, keys)) == NULL) {
-	G3d_error("G3d_keyGetDouble: cannot find field %s in key structure",
-		  key);
-	return 0;
-    }
-
-    if (sscanf(str, "%lf", d) == 1)
-	return 1;
-
-    G3d_error("G3d_keyGetDouble: invalid value: field %s in key structure",
-	      key);
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_keyGetString(struct Key_Value *keys, const char *key, char **returnStr)
-{
-    const char *str;
-
-    if ((str = G_find_key_value(key, keys)) == NULL) {
-	G3d_error("G3d_keyGetString: cannot find field %s in key structure",
-		  key);
-	return 0;
-    }
-
-    *returnStr = G_store(str);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_keyGetValue(struct Key_Value *keys, const char *key, char *val1,
-		char *val2, int result1, int result2, int *resultVar)
-{
-    const char *str;
-
-    if ((str = G_find_key_value(key, keys)) == NULL) {
-	G3d_error("G3d_keyGetValue: cannot find field %s in key structure",
-		  key);
-	return 0;
-    }
-
-    if (strcmp(str, val1) == 0) {
-	*resultVar = result1;
-	return 1;
-    }
-    if (strcmp(str, val2) == 0) {
-	*resultVar = result2;
-	return 1;
-    }
-
-    G3d_error("G3d_keyGetValue: invalid type: field %s in key structure",
-	      key);
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_keySetInt(struct Key_Value *keys, const char *key, const int *i)
-{
-    char keyValStr[200];
-
-    sprintf(keyValStr, "%d", *i);
-    G_set_key_value(key, keyValStr, keys);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_keySetDouble(struct Key_Value *keys, const char *key, const double *d)
-{
-    char keyValStr[200];
-
-    sprintf(keyValStr, "%.50f", *d);
-    G_set_key_value(key, keyValStr, keys);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_keySetString(struct Key_Value *keys, const char *key,
-		 char *const *keyValStr)
-{
-    G_set_key_value(key, *keyValStr, keys);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_keySetValue(struct Key_Value *keys, const char *key, const char *val1,
-		const char *val2, int keyval1, int keyval2,
-		const int *keyvalVar)
-{
-    if (*keyvalVar == keyval1) {
-	G_set_key_value(key, val1, keys);
-	return 1;
-    }
-
-    if (*keyvalVar == keyval2) {
-	G_set_key_value(key, val2, keys);
-	return 1;
-    }
-
-    G3d_error("G3d_keySetValue: wrong key value");
-    return 0;
-}

Deleted: grass/trunk/lib/raster3d/g3dlib.dox
===================================================================
--- grass/trunk/lib/raster3d/g3dlib.dox	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dlib.dox	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,1758 +0,0 @@
-/*! \page g3dlib GRASS Grid3D raster volume Library
-<!-- doxygenized from "GRASS 5 Programmer's Manual" 
-     by M. Neteler 5/2004, 8/2005
-  -->
-
-\section g3dintro Grid3D raster volume Library
-
-
-<P>
-Authors: Roman Waupotitsch and Michael Shapiro, Helena Mitasova, 
-         Bill Brown, Lubos Mitas, Jaro Hofierka, 
-         Minor modification, code cleanup and test suite by Soeren Gebbert
-         
-
-
-<b>Overview</b>
-
-The Grid3D raster volume Library is used for the r3.* and vector
-volume tools. The G3D library uses a tile cache based approach to store floating point
- values in abritrary order in a volume. The coordinate system of a volume is 
-column and row compatible to the raster library and counts from the bottom to the top
-of the cube.
-
-<center>
-<img src=g3d_volume_layout.png border=0><BR>
-<table border=0 width=700>
-<tr><td><center>
-<i>The volume coordinate system and tile layout of the G3D library</i>
-</center></td></tr>
-</table>
-</center>
-
-
-\section Directory_Structure Directory Structure
-
-<P>
-The file format consists of a mapset element <EM>grid3</EM> which contains a
-directory for every map. The elements for each map are
-
-<P>
-\verbatim 
-        3d region file
-        color file (color)
-        categories file (cats)
-        range file (range)
-        timestamp file /* not yet implemented */
-        cell file (cell)
-        header file (cellhd)
-        a directory containing display files (dsp)
-\endverbatim 
-
-<P>
-There is also a <EM>colr2</EM> mechanism provided. <EM>colr2</EM> color tables
-are stored in <EM>grid3/colr2/MAPSET/MAP</EM>.
-
-<P>
-Note: color, categories, and the range can be used in the same way as in <EM>2d</EM> 
-GRASS with the exception of reading and writng. <EM>3d</EM> read and write
-functions have to be used for this purpose.
-
-
-\section Data_File_Format Data File Format
-
-
-<UL>
-<LI>Cell-values can be either double or float.
-</LI>
-<LI>Values are written in XDR-format.
-</LI>
-<LI>NULL-values are stored in an embedded fashion.
-</LI>
-<LI>The cell-values are organized in <EM>3d</EM>-tiles.
-</LI>
-<LI>The tile dimensions can be chosen when a new map is opened.
-</LI>
-<LI>Every tile of a map has the same dimension except those which overlap the
-  region boundaries.
-</LI>
-<LI>Compression is used to store tiles.
-</LI>
-</UL>
-
-<P>
-The data file has the following format:
-
-<P>
-\verbatim 
-        xdr_int nofBytesLong;
-        xdr_int nofBytesUsed;
-        encoded_long indexOffset;
-        compressed_tile[] tiles;
-        compressed_encoded_long[] index;
-\endverbatim 
-
-<P>
-
-\section Transportability_of_data_file Transportability of data file
-
-<P>
-All numbers stored in the data file are either XDR-encoded or encoded by some
-other method (for variables of type long only).
-
-<P>
-
-\section Tile_Data_NULL_values Tile Data NULL-values
-
-<P>
-G3D uses the same functions as <EM>2d</EM> GRASS to set and test NULL-values.  The
-storage in the file is different though.  NULL-values are stored with a special
-bit-pattern if maximum precision is chosen.  They are stored by adding an
-additional bit if the precision is smaller.
-
-<P>
-
-\section Tile_Data_Compression Tile Data Compression
-
-<P>
-There are three methods of compression provided. The compression
-methods can either be those defined by default, set by environment
-variables or explicitly set at run-time.
-
-\verbatim 
-        Precision
-        RLE
-\endverbatim 
-
-<P>
-Precision indicates how many of the mantissa bits should be stored on
-file. This number can be any value between 0 and 23 for floats and
-between 0 and 52 for doubles. Choosing a small precision is the most
-effective way to achieve good compression.
-
-<P>
-RLE takes advantage of possible repetitions of the
-exponents and the NULL-bit structure. Using RLE does not significantly
-increase the running time. If for some tile the non-RLEed version is
-smaller in size, RLE is not used for this tile.
-
-<P>
-The default and suggested setting is to use precision and RLE. 
-
-<P>
-Additional compression is achieved by storing the extra NULL-bit in a
-separate bit-array. Using this scheme NULL-values need not actually be
-represented in the array of cell values. This array is stored together
-with the cell-values of the tile.
-
-
-\section Tile_Cache Tile Cache 
-
-<P>
-Tiles can either be read and written directly or use an intermediate
-cache instead.
-
-<P>
-In non-cache mode the application should only use the functions
-
-<P>
-int G3d_readTile() 
-
-<P>
-and 
-
-<P>
-int G3d_writeTile() 
-
-<P>
-to read and write tiles.  The application can use one tile provided by the map
-structure as buffer. See <TT>G3d_getTilePtr()</TT>.
-
-<P>
-In cache mode the application can access cell-values directly by their
-coordinates. The corresponding functions are
-
-<P>
-int G3d_getValue() 
-
-<P>
-and
-
-<P>
-int G3d_putValue() 
-
-<P>
-and their corresponding typed versions.
-<BR>
-<P>
-If the map is new then in addition to the memory-cache a file-cache is provided.
-This allows the application to write the cell-values in any arbitrary order.
-Tiles are written (flushed) to the data-file either at closing time or if
-explicitly requested.
-<BR>
-<P>
-If the map is new <TT>G3d_getValue()</TT> can be used even if the tile which
-contains the cell has already been flushed to the data file. In this case the
-tile is simply read back into the memory-cache from the data file.
-<BR>
-<P>
-Explicitly flushing tiles can have the advantage that less disk space is
-occupied since tiles are stored in a uncompressed fashion in the file-cache.
-Flushing tiles explicitly can cause problems with accuracy though if precision
-is less than the maximum precision and an already flushed value is used for
-computations later in the program.
-<BR>
-<P>
-The type of the cell-values of the tiles in memory can be chosen independently
-of the type of the tiles in the file. Here, once again one has to consider
-possible problems arising from mixing different precisions.
-<BR>
-<P>
-As an example consider the case where the data is stored in the file with double
-precision and the tiles are stored in memory in single precision.  Then using
-<TT>G3d_getValue()</TT> will actually return a double precision number whose precision
-is only 23 bits.  It is therefore a good idea to use the types in the memory
-consistently.
-<BR>
-<P>
-
-\section Header_File Header File
-
-<P>
-The header file has the following format:
-
-<P>
-\verbatim 
-Proj: 1
-Zone: 1
-North: 2.0000000000000
-South: 0.5000000000000
-East: 4.0000000000000
-West: 3.0000000000000
-Top: 6.0000000000000
-Bottom: 5.0000000000000
-nofRows: 30
-nofCols: 20
-nofDepths: 14
-e-w resol: 0.05
-n-s resol: 0.05
-t-b resol: 0.071428571
-TileDimensionX: 8
-TileDimensionY: 8
-TileDimensionZ: 8
-CellType: double
-useCompression: 1
-useRle: 1
-Precision: -1
-nofHeaderBytes: 12
-useXdr: 1
-hasIndex: 1
-Units: none
-\endverbatim
-
-<P>
-Except for the first 14 fields the entries of the header file should
-not be modified. The precision value -1 indicates that maximum
-precision is used.
-<BR>
-<P>
-Binary files not in G3D format can be read by the library. The
-following actions have to be taken: 
-
-<P>
-Make a new map directory in the <EM>grid3</EM> element of the mapset (say <EM>mymap</EM>).
-  Copy the file into <EM>mymap/cell</EM> and generate a header file <EM>mymap/cellhd</EM>.
-
-<P>
-In the following example the relevant values of <EM>mymap/cellhd</EM> are shown:
-
-<P>
-\verbatim 
-TileDimensionX: A
-TileDimensionY: B
-TileDimensionZ: C
-useCompression: 0
-useRle: 0
-Precision: -1
-nofHeaderBytes: X
-useXdr: 0
-hasIndex: 0
-\endverbatim
-
-<P>
-The values of <EM>A</EM>, <EM>B</EM>, and <EM>C</EM> have to be chosen
-according to one of the following patterns:
-
-<P>
-\verbatim 
-A &gt;= 1, B == 1, C == 1, or
-A &gt;= nofRows, B &gt;= 1, C == 1, or
-A &gt;= nofRows, B &gt;= nofCols, C &gt;= 1.
-\endverbatim
-
-<P>
-A larger tile size reduces the number of tile-reads. If in the third pattern
-<EM>C</EM> is chosen larger than or equal to <EM>nofDepths</EM>, the entire region is
-considered one large tile.
-
-<P>
-The value <EM>nofHeaderBytes</EM> indicates the offset in the file to the first
-data entry.
-
-<P>
-For performance reasons it is a good idea to use function
-<TT>G3d_retile()</TT> before using the file in other applications.
-
-<P>
-
-\section Region_Structure Region Structure
-
-<P>
-\verbatim 
-typedef struct{
-
-    double north, south;
-    double east, west;
-    double top, bottom;
-  
-    int rows, cols, depths;/* data dimensions in cells */
-
-    double ns_res, ew_res, tb_res;
-
-    int proj;  /* Projection (see gis.h) */
-    int zone;  /* Projection zone (see gis.h) */
-
-} G3D\_Region;
-\endverbatim
-
-<P>
-
-\section Windows Windows
-
-<P>
-Window capability similar to that of <EM>2d</EM> GRASS is provided (compare
-Region).  Additional features are the window for the third dimension
-as well as the possibility to choose a different window for every map. The
-window can be specified at the time of opening an old map. It can be modified
-at any time later in the program. The resampling method can be the default
-nearest neighbor method as well as an application provided method.
-<BR>
-<P>
-The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the mapset.
-Application programs should use <TT>G3d_useWindowParams()</TT> to allow the
-user to overwrite this default.
-
-<P>
-The window file has the following format:
-
-<P>
-\verbatim 
-Proj: 1
-Zone: 1
-North: 2.0
-South: 0.5
-East: 4.0
-West: 3.0
-Top: 5.0
-Bottom: 6.0
-nofRows: 30
-nofCols: 20
-nofDepths: 14
-e-w resol: 0.05000000000000000
-n-s resol: 0.05000000000000000
-t-b resol: 0.07142857142857142
-\endverbatim
-
-<P>
-Note: after reading the window file the fields <EM>e-w</EM>, <EM>n-s</EM>, and <EM>t-b</EM>
- are recomputed internally.
-
-<P>
-A note about windows and caching. Caching is performed on the level of tiles
-read from the file. There is no caching performed on resampled data.  This is
-different from <EM>2d</EM> GRASS since resampling for a specific value is
-performed every time it is being accessed.
-
-<P>
-
-\section Masks Masks
-
-<P>
-G3D provides a mask for the <EM>3d</EM> region.  The mask structure is
-automatically initialized at the time the first file is opened. The same
-structure is used for all the files. The default for every file is that the
-mask is turned off. If masking should be performed, the application program has
-to turn on masking explicitly. If masking is turned on for a file, the
-cell-values of a tile are automatically checked against the mask. Values which
-are masked out, are set to NULL.
-
-<P>
-Note: changing the status of masking after one or more tiles have already
-been read does not affect the tiles which are already stored in the cache.
-
-<P>
-Any arbitrary 3d raster map can be used as mask file: NULL-values are interpreted as
- <TT>"mask-out"</TT>, all other values are interpreted as  <TT>"don't mask
-  out"</TT>. Using <EM>r3.mask</EM> to convert a 3d raster map into a mask file instead of
-simply copying (or renaming) the directory will significantly reduce to amount
-of disk space and the access time for the mask.
-
-<P>
-
-\section Include_File Include File
-
-<P>
-Exported G3D constants and structures can be found in <EM>G3d.h</EM>.
-
-<P>
-
-\section G3D_Defaults G3D Defaults
-
-<P>
-There are three methods to set default variables. First, the default can be set
-at compile time in <EM>g3ddefault.c</EM>. This value has lowest priority.
-
-<P>
-Second, the default can be set via an environment variable.  Third, the value
-can be set explicitly set at run time. This value has highest priority.
-
-<P>
-There are also functions provided to query the value.
-
-<P>
-
-\section Cache_Mode Cache Mode
-
-<P>
-
-\subsection Limiting_the_maximum_cache_size Limiting the maximum cache size
-
-<P>
-The limit is specified in bytes. It is a limit on the size of cell-data stored
-in the cache and does not include the support structure.
-
-<P>
-Default G3D_CACHE_SIZE_MAX_DEFAULT. This is currently set to 16meg and can
-be changed at compilation time of the library.
-
-<P>
-Environment variable G3D_MAX_CACHE_SIZE.
-
-<P>
-void G3d_setCacheLimit(int nBytes)Set cache limit
-
-<P>
-int G3d_getCacheLimit(int nBytes)Get cache limit
-
-<P>
-
-\subsection Setting_the_cache_size Setting the cache size
-
-<P>
-This value specifies the number of tiles stored in the cache. It is the value
-used if at opening time of a map G3D_USE_CACHE_DEFAULT is used for the cache
-mode. Any other value used at opening time will supersede the default value. A
-default value of 0 indicates that non-cache mode should be used by default.
-
-<P>
-Default G3D_CACHE_SIZE_DEFAULT. This is currently set to 1000 and can be
-changed at compilation time of the library.
-
-<P>
-Environment variable G3D_DEFAULT_CACHE_SIZE.
-
-<P>
-void G3d_setCacheSize(int nTiles)
-
-<P>
-int G3d_getCacheSize()
-
-<P>
-
-\section Compression Compression
-
-\subsection Toggling_compression_mode Toggling compression mode
-
-<P>
-This value specifies whether compression should be used while writing a new
-map. It does not have any effect on old maps.
-
-<P>
-Default G3D_COMPRESSION_DEFAULT. This is set to G3D_COMPRESSION. This
-default should not be changed.
-
-<P>
-Environment variables G3D_USE_COMPRESSION and G3D_NO_COMPRESSION.
-
-<P>
-See functions G3d_setCompressionMode() (cf. 
-Section 22.3.2.3 ) and G3d_getCompressionMode() (cf. Section 22.3.2.3 ).
-
-<P>
-
-\subsection Toggling_RLE_compression Toggling RLE compression
-
-<P>
-This value specifies whether RLE compression should be used (in addition to
-precision).
-
-<P>
-Default G3D_USE_RLE_DEFAULT. This is currently set to G3D_USE_RLE and can
-be changed at compilation time of the library.
-
-<P>
-Environment variables G3D_USE_RLE and G3D_NO_RLE.
-
-<P>
-See functions G3d_setCompressionMode() (cf. 
-Section 22.3.2.3) and G3d_getCompressionMode() (cf. Section 22.3.2.3).
-
-\section Setting_the_precision Setting the precision
-
-<P>
-This number specifies how many mantissa bits should be used when writing a cell
-value. The minimum value is 0. The maximum value is 23 or G3D_MAX_PRECISION
-for type FCELL_TYPE, it is 52 or G3D_MAX_PRECISION for type DCELL_TYPE.
-
-<P>
-Default G3D_PRECISION_DEFAULT. This is set to G3D_MAX_PRECISION. This
-default should not be changed.
-
-<P>
-Environment variables G3D_PRECISION and G3D_MAX_PRECISION.
-
-<P>
-void G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int
-  precision) <EM>doCompress</EM> should be one of G3D_NO_COMPRESSION and
-  G3D_COMPRESSION, <EM>doRle</EM> should be either G3D_NO_RLE or
-  G3D_USE_RLE, and <EM>precision</EM> should be either G3D_MAX_PRECISION or
-  a positive integer.
-
-<P>
-void G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
-  int *precision)
-
-<P>
-
-\section Tiles Tiles
-
-\subsection Setting_the_tile_dimensions Setting the tile dimensions
-
-<P>
-The dimensions are specified in number of cell.
-
-<P>
-Defaults G3D_TILE_X_DEFAULT, G3D_TILE_Y_DEFAULT, and
-G3D_TILE_Z_DEFAULT. These are currently set to 8 and can be changed at
-compilation time of the library.
-
-<P>
-Environment variables G3D_TILE_DIMENSION_X, G3D_TILE_DIMENSION_Y, and
-G3D_TILE_DIMENSION_Z.
-
-<P>
-void G3d_setTileDimension(int tileX, int tileY, int tileZ)
-
-<P>
-void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
-
-<P>
-
-\section Setting_the_tile_cell_value_type Setting the tile cell-value type
-
-<P>
-Specifies which type is used to write cell-values on file. This type can be
-chosen independently of the type used to store cell-values in memory.
-
-<P>
-Default G3D_FILE_TYPE_DEFAULT. This is set to DCELL_TYPE. This default
-should not be changed.
-
-<P>
-Environment variables G3D_WRITE_FLOAT and G3D_WRITE_DOUBLE.
-
-<P>
-void G3d_setFileType(int type)
-
-<P>
-int G3d_getFileType(int type)
-
-<P>
-
-\section Setting_the_window Setting the window
-
-<P>
-The window is set from a <EM>3d</EM> window file.
-
-<P>
-The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the current mapset.
-
-<P>
-Possible choices for <EM>3d</EM> window files are <EM>name</EM> which refers to a
-window file in the <EM>3d</EM> window database located at <EM>windows3d</EM> of the
-current mapset; or file names which are identified by a leading <EM><TT>"/"</TT></EM> 
-or <EM><TT>"."</TT></EM>; or fully qualified
-names, i.e. <EM>file at mapset</EM> which refer to window files in the <EM>3d</EM> window 
-database of mapset.  Note, that names <EM>WIND3</EM> and <EM>WIND3 at mapset</EM> do not 
-specify the default window name in the (current)
-mapset but rather a window file in the window database of the (current) mapset.
-
-<P>
-Environment variable G3D_DEFAULT_WINDOW3D.
-
-<P>
-See functions 
-
-<P>
-<TT>G3d_useWindowParams()</TT>,
-
-<P>
-<TT>G3d_setWindow()</TT>, and
-
-<P>
-<TT>G3d_setWindowMap()</TT>.
-
-<P>
-
-\section Setting_the_Units Setting the Units
-
-<P>
-Default <TT>"none"</TT>.
-
-<P>
-No environment variable.
-
-<P>
-void G3d_setUnit (unit)
-        char *unit;
-
-<P>
-
-\section Error_Handling Error Handling: Setting the error function
-
-<P>
-This variable specifies the function which is invoked when an error
-(not a fatal error) occurs. For example setting the error function to
-<TT>G3d_fatalError</TT> simplifies debugging with dbx and also might show
-errors which are missed because the application does not check the
-return value.
-
-<P>
-Default <TT>G3d_skipError</TT>.
-
-<P>
-Environment variables G3D_USE_FATAL_ERROR and G3D_USE_PRINT_ERROR.
-
-<P>
-void G3d_setErrorFun(void (*fun)(char *))
-
-<P>
-The following 3 functions are possible choices for error functions.
-
-<P>
-void G3d_skipError(char (*msg)(char *)) This function ignores the
-  error.
-
-<P>
-void G3d_printError(char (*msg)(char *)) This function prints the
-  error message <EM>msg</EM> to <EM>stderr</EM> and returns.
-
-<P>
-void G3d_fatalError(char (*msg)(char *)) This function prints the
-  error message <EM>msg</EM> to <EM>stderr</EM>, flushes <EM>stdout</EM> 
-  and <EM>stderr</EM>, and terminates the program with a segementation fault.
-
-<P>
-
-\section G3D_Function_Index G3D Function Index
-
-\subsection Opening_and_Closing_G3D_Files Opening and Closing G3D Files
-
-<P>
-void  *G3d_openCellOld(char *name, char *mapset, G3D_Region *window,
-  int type, int cache)Opens existing g3d-file <EM>name</EM> in <EM>mapset</EM>.
-
-<P>
-Tiles are stored in memory with <EM>type</EM> which must be any of FCELL_TYPE,
-  DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
-  cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
-  G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
-  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
-  G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf. 
-  Section 22.4.6), or any positive integer which
-  specifies the number of tiles buffered in the cache.  <EM>window</EM> sets the
-  window-region for the map. It is either a pointer to a window structure or
-  G3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
-  set via <TT>G3d_setWindow()</TT> (cf. Section 22.4.16).
-  To modify the window for the map after it has already been opened use
-  <TT>G3d_setWindowMap()</TT> (cf. Section 22.4.16).
-
-<P>
-Returns a pointer to the cell structure ... if successful, NULL ...
-  otherwise.
-
-<P>
-void  *G3d_openCellNew(char *name, int type, int cache, G3D_Region
-  *region)Opens new g3d-file with <EM>name</EM> in the current mapset. Tiles
-  are stored in memory with <EM>type</EM> which must be one of FCELL_TYPE,
-  DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
-  cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
-  G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
-  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
-  G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf. 
-  Section 22.4.6), or any positive integer which
-  specifies the number of tiles buffered in the cache.  <EM>region</EM> specifies
-  the 3d region.  
-
-<P>
-Returns a pointer to the cell structure ... if successful,
-  NULL ... otherwise.
-
-<P>
-void  *G3d_openCellNewParam(char *name, int typeIntern, int cache,
-  G3D_Region *region, int type, int doLzw, int doRle, int precision, int tileX,
-  int tileY, int tileZ)Opens new g3d-file with <EM>name</EM> in the current
-  mapset. Tiles are stored in memory with <EM>typeIntern</EM> which must be one of
-  FCELL_TYPE, DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies
-  the cache-mode used and must be either G3D_NO_CACHE,
-  G3D_USE_CACHE_DEFAULT, G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
-  G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
-  G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of
-  <TT>G3d_cacheSizeEncode()</TT> (cf. 
-  Section 22.4.6), or any positive integer which
-  specifies the number of tiles buffered in the cache.  <EM>region</EM> specifies
-  the 3d region.
-
-<P>
-In addition the properties of the new file have to be specified. It is
-  assumed by default that compression is used. This function first sets the
-  global default values to the specified values, and then restores the original
-  global defaults. This function can be used in conjunction with
-  <TT>G3d_setStandard3dInputParams()</TT> (cf. 
-  Section 22.4.18) and
-  <TT>G3d_getStandard3dParams()</TT>.
-
-<P>
-Returns a pointer to the cell structure ... if successful, NULL ...
-  otherwise.
-
-<P>
-int G3d_closeCell(void *map)Closes g3d-file. If <EM>map</EM> is new
-  and cache-mode is used for <EM>map</EM> then every tile which is not flushed
-  before closing is flushed.  
-
-<P>
-Returns 1 ... if successful, 0 ...  otherwise.
-
-<P>
-
-\subsection Reading_and_Writing_Tiles Reading and Writing Tiles
-
-<P>
-These functions read or write data directly to the file (after performing the
-appropriate compression) without going through the cache. In order to avoid 
-unexpected side-effects the use of these functions in cache mode is
-discouraged.
-
-<P>
-int G3d_readTile(void *map, char *tileIndex, int tile, int type)
-  Reads tile with index <EM>tileIndex</EM> into the <EM>tile</EM> buffer. The cells
-  are stored with type <EM>type</EM> which must be one of FCELL_TYPE and
-  DCELL_TYPE. If the tile with <EM>tileIndex</EM> is not stored on the file
-  corresponding to <EM>map</EM>, and <EM>tileIndex</EM> is a valid index <EM>tile</EM>
-  is filled with NULL-values.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_readTileFloat(void *map, char *tileIndex, int tile)
-Is equivalent to G3d_readTile (map, tileIndex, tile, FCELL_TYPE).
-
-<P>
-int G3d_readTileDouble(void *map, char *tileIndex, int tile)
-Is equivalent to G3d_readTile (map, tileIndex, tile, DCELL_TYPE).
-
-<P>
-int G3d_writeTile(void *map, char *tileIndex, int tile, int type)
-  Writes tile with index <EM>tileIndex</EM> to the file corresponding to <EM>map</EM>. It is assumed that the cells in <EM>tile</EM> are of <EM>type</EM> which
-  must be one of FCELL_TYPE and DCELL_TYPE.  The actual type used to write the
-  tile depends on the type specified at the time when <EM>map</EM> is initialized.
-
-<P>
-A tile can only be written once. Subsequent attempts to write the same tile
-  are ignored.
-
-<P>
-Returns 
-        1 ... if successful,
-        2 ... if write request was ignored,
-        0 ... otherwise.
-
-<P>
-int G3d_writeTileFloat(void *map, char *tileIndex, int tile)
-Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, FCELL_TYPE).</TT>
-
-<P>
-int G3d_writeTileDouble(void *map, char *tileIndex, int tile)
-Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, DCELL_TYPE).</TT>
-
-<P>
-
-\subsection Reading_and_Writing_Cells Reading and Writing Cells
-
-<P>
-void G3d_getValue(void *map, int x, int y, int z, char *value, int
-  type) Returns in <EM>*value</EM> the cell-value of the cell with
-  window-coordinate <EM>(x, y, z)</EM>.  The value returned is of <EM>type</EM>.
-
-<P>
-This function invokes a fatal error if an error occurs.
-
-<P>
-float G3d_getFloat(void *map, int x, int y, int z)Is equivalent to
-  <TT>G3d_getValue (map, x, y, z, &amp;value, FCELL_TYPE);</TT> return value.
-
-<P>
-double G3d_getDouble(void *map, int x, int y, int z)Is equivalent
-  to <TT>G3d_getValue (map, x, y, z, &amp;value, DCELL_TYPE);</TT> return value.
-
-<P>
-void G3d_getValueRegion(void *map, int x, int y, int z, char*value,
-  int type) Returns in <EM>*value</EM> the cell-value of the cell with
-  region-coordinate <EM>(x, y, z)</EM>.  The value returned is of <EM>type</EM>.
-  Here <EM>region</EM> means the coordinate in the cube of data in the file, i.e.
-  ignoring geographic coordinates.
-
-<P>
-This function invokes a fatal error if an error occurs.
-
-<P>
-float G3d_getFloatRegion(void *map, int x, int y, int z)Is
-  equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value, FCELL_TYPE);</TT>
-  return value.
-
-<P>
-double G3d_getDoubleRegion(void *map, int x, int y, int z)Is
-  equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value,
-    DCELL_TYPE);</TT> return value.
-
-<P>
-int G3d_putValue(void *map, int x, int y, int z, char *value, int
-  type)After converting <EM>*value</EM> of <EM>type</EM> into the type specified
-  at the initialization time (i.e. <EM>typeIntern</EM>) this function writes the
-  value into the tile buffer corresponding to cell-coordinate <EM>(x, y, z)</EM>.
-
-<P>
-Returns
-
-<P>
-  1 ... if successful,  
-  0 ... otherwise.
-
-<P>
-int G3d_putFloat(void *map, int x, int y, int z, char *value)Is
-  equivalent to G3d_putValue (map, x, y, z, &amp;value, FCELL_TYPE).
-
-<P>
-int G3d_putDouble(void *map, int x, int y, int z, char *value) Is
-  equivalent to G3d_putValue (map, x, y, z, &amp;value, DCELL_TYPE).
-
-<P>
-
-\subsection Loading_and_Removing_TilesLoading and Removing Tiles
-
-<P>
-char *G3d_getTilePtr(void *map, int tileIndex) This function
-  returns a pointer to a tile which contains the data for the tile with index
-  <EM>tileIndex</EM>.  The type of the data stored in the tile depends on the type
-  specified at the initialization time of <EM>map</EM>.  The functionality is
-  different depending on whether <EM>map</EM> is old or new and depending on the
-  cache-mode of <EM>map</EM>.
-<BR>
-<P>
-If <EM>map</EM> is old and the cache is not used the tile with <EM>tileIndex</EM>
-  is read from file and stored in the buffer provided by the map structure.
-  The pointer to this buffer is returned. If the buffer already contains the
-  tile with <EM>tileIndex</EM> reading is skipped. Data which was stored in
-  earlier calls to <TT>G3d_getTilePtr</TT> is destroyed.  If the tile with 
-  <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and 
-  <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.
-<BR>
-<P>
-If <EM>map</EM> is old and the cache is used the tile with <EM>tileIndex</EM> is
-  read from file and stored in one of the cache buffers.  The pointer to buffer
-  is returned.  If no free cache buffer is available an unlocked cache-buffer
-  is freed up and the new tile is stored in its place.  If the tile with 
-  <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and 
-  <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.  If one
-  of the cache buffers already contains the tile with <EM>tileIndex</EM> reading
-  is skipped and the pointer to this buffer is returned.
-<BR>
-<P>
-If <EM>map</EM> is new and the cache is not used the functionality is the same
-  as if <EM>map</EM> is old and the cache is not used.  If the tile with 
-  <EM>tileIndex</EM> is already stored on file, it is read into the buffer, if not,
-  the cells are set to null-values.  If the buffer corresponding to the pointer
-  is used for writing, subsequent calls to <TT>G3d_getTilePtr</TT> may destroy the
-  values already stored in the buffer.  Use <TT>G3d_flushTile</TT> to write the buffer
-  to the file before reusing it for a different index.  The use of this buffer
-  as write buffer is discouraged.
-<BR>
-<P>
-If <EM>map</EM> is new and the cache is used the functionality is the same as if
-  <EM>map</EM> is old and the cache is used with the following exception.  If 
-  <EM>tileIndex</EM> is a valid index and the tile with this index is not found in
-  the cache and is not stored on the file corresponding to <EM>map</EM>, then the
-  file cache is queried next. If the file-cache contains the tile it is loaded
-  into the cache (memory-cache). Only if the file-cache does not contain the
-  tile it is filled with NULL-values.  Tile contents of buffers are never
-  destroyed. If a cache buffer needs to be freed up, and the tile stored in the
-  buffer has not been written to the file corresponding to <EM>map</EM> yet, the
-  tile is copied into the file-cache.
-<BR>
-<P>
-Care has to be taken if this function is used in non-cache mode since it is
-  implicitly invoked every time a read or write request is issued.  The only
-  I/O-functions for which it is safe to assume that they do not invoke
-  <TT>G3d_getTilePtr</TT> are <TT>G3d_readTile()</TT> and
-  <TT>G3d_writeTile()</TT> and their corresponding type-specific versions.
-
-<P>
-Returns 
-        a pointer to a buffer ... if successful,
-        NULL ... otherwise.
-
-<P>
-int G3d_tileLoad(void *map, int tileIndex)
-Same functionality as <TT>G3d_getTilePtr()</TT> but does not return the
-pointer.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_removeTile(void *map, inttileIndex) Removes a tile
-        from memory-cache if tile is in memory-cache.  For new maps the
-        application does not know whether the tile is in the memory-cache or in
-        the file-cache. Therefore, for new maps this function should be
-        preceded by <TT>G3d_tileLoad()</TT>.
-
-<P>
-<EM>(Question: Is this a useful function?)</EM>
-
-<P>
-Returns 1 ... if successful, 0 ... otherwise.
-
-<P>
-
-\subsection Write_Functions_used_in_Cache_Mode Write Functions used in Cache Mode
-
-<P>
-int G3d_flushTile(void *map, int tileIndex) Writes the tile with
-  <EM>tileIndex</EM> to the file corresponding to <EM>map</EM> and removes the tile
-  from the cache (in non-cache mode the buffer provided by the map-structure is
-  written).
-
-<P>
-If this tile has already been written before the write request is ignored.
-  If the tile was never referred to before the invokation of G3d_flushTile, a
-  tile filled with NULL-values is written.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_flushTileCube(void *map, int xMin, int yMin, int zMin, int
-  xMax, int yMax, int zMax) Writes the tiles with tile-coordinates
-  contained in the axis-parallel cube with vertices <EM>(xMin, yMin, zMin)</EM>
-  and <EM>(xMax, yMax, zMax</EM>).  Tiles which are not stored in the cache are
-  written as NULL-tiles.  Write attempts for tiles which have already been
-  written earlier are ignored.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_flushTilesInCube(void *map, int xMin, int yMin, int
-        zMin, int xMax, int yMax, int zMax) Writes those tiles for which
-        <EM>every</EM> cell has coordinate contained in the axis-parallel cube
-        defined by the vertices with cell-coordinates <EM>(xMin, yMin, zMin)</EM>
-        and <EM>(xMax, yMax, zMax)</EM>.
-
-<P>
-Tiles which are not stored in the cache are written as NULL-tiles.
-        Write attempts for tiles which have already been written earlier are
-        ignored.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-
-\subsection Locking_and_Unlocking_Tiles_and_CyclesLocking and Unlocking Tiles, and Cycles
-
-<P>
-int G3d_lockTile(void *map, int tileIndex) Locks tile with <EM>tileIndex</EM> in cache. 
-If after locking fewer than the minimum number of
-  unlocked tiles are unlocked, the lock request is ignored.
-
-<P>
-Returns 
-         1 ... if successful,
-        -1 ... if request is ignored,
-         0 ... otherwise.
-
-<P>
-int G3d_unlockTile(void *map, int tileIndex)
-Unlocks tile with <EM>tileIndex</EM>.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_unlockAll(void *map)
-Unlocks every tile in cache of <EM>map</EM>.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-void G3d_autolockOn(void *map)
-Turns autolock mode on.
-
-<P>
-void G3d_autolockOff(void *map)
-Turns autolock mode Off.
-
-<P>
-void G3d_minUnlocked(void *map, int minUnlocked) Sets the minimum
-  number of unlocked tiles to <EM>minUnlocked</EM>.  This function should be used
-  in combination with <TT>G3d_unlockAll()</TT> in order to avoid  situations where the
-  new minimum is larger than the actual number of unlocked tiles.
-
-<P>
-<EM>minUnlocked</EM> must be one of G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
-  G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
-  G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of G3d_cacheSizeEncode()
-  (cf. Section 22.4.6), or any positive integer
-  which explicitly specifies the number of tiles.
-
-<P>
-int G3d_beginCycle(void *map)
-Starts a new cycle.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_endCycle(void *map)
-Ends a cycle.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_cacheSizeEncode(int cacheCode, int n) Returns a number
-  which encodes multiplicity <EM>n</EM> of <EM>cacheCode</EM>. This value can be used
-  to specify the size of the cache.
-
-<P>
-If <EM>cacheCode</EM> is the size (in tiles) of the cache the function returns
-  <EM>cacheCode * n</EM>.
-
-<P>
-If <EM>cacheCode</EM> is G3D_USE_CACHE_DEFAULT the function returns
-  G3D_USE_CACHE_DEFAULT.
-
-<P>
-If <EM>cacheCode</EM> is G3D_USE_CACHE_??? the function returns a value
-  encoding G3D_USE_CACHE_??? and <EM>n</EM>. Here G3D_USE_CACHE_??? is one
-  of G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
-  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ, or
-  G3D_USE_CACHE_XYZ, where e.g.  G3D_USE_CACHE_X specifies that the cache
-  should store as many tiles as there exist in one row along the x-axis of the
-  tile cube, and G3D_USE_CACHE_XY specifies that the cache should store as
-  many tiles as there exist in one slice of the tile cube with constant Z
-  coordinate.
-
-<P>
-
-\subsection Reading_Volumes Reading Volumes
-
-<P>
-int G3d_getVolume(void *map, double originNorth, double originWest,
-  double originBottom, double vxNorth, double vxWest, double vxBottom, double
-  vyNorth, double vyWest, double vyBottom, double vzNorth, double vzWest,
-  double vzBottom, int nx, int ny, int nz, char *volumeBuf, int type)
-  Resamples the cube defined by <EM>origin</EM> and the 3 vertices <EM>vx</EM>, 
-  <EM>vy</EM>, and <EM>vz</EM> which are incident to the 3 edges adjacent to
-   <EM>origin</EM>.  The resampled cube is stored in <EM>volumeBuf</EM> which is a cube
-  with dimensions <EM>(nx, ny, nz)</EM>.
-
-<P>
-The method of sampling is nearest neighbor sampling.
-
-<P>
-The values stored are of <EM>type</EM>. 
-
-<P>
-Returns 1 ... if successful, 0 ... otherwise.
-
-<P>
-int G3d_getAllignedVolume(void *map, double originNorth, double
-  originWest, double originBottom, double lengthNorth, double lengthWest,
-  double lengthBottom, int nx, int ny, int nz, char *volumeBuf, int type)
-  Resamples the axis-parallel cube defined by <EM>origin</EM> and the lengths of
-  the 3 edges adjacent to <EM>origin</EM>.  The resampled cube is stored in
-   <EM>volumeBuf</EM> which is a cube with dimensions <EM>(nx, ny, nz)</EM>.  The method
-  of sampling is nearest neighbor sampling.  The values stored are of <EM>type</EM>.  
-
-<P>
-Returns 1 ... if successful, 0 ... otherwise.
-
-<P>
-
-\subsection Allocating_and_Freeing_Memory Allocating and Freeing Memory
-
-<P>
-void  *G3d_malloc(int nBytes)
-Same as <EM>malloc (nBytes)</EM>, except that in case of error
-<TT>G3d_error()</TT> is invoked.
-
-<P>
-Returns 
-        a pointer ... if successful,
-        NULL ... otherwise.
-
-<P>
-void  *G3d_realloc(void *ptr, int nBytes)
-Same as <EM>realloc (ptr, nBytes)</EM>, except that in case of error
-<TT>G3d_error()</TT> is invoked. 
-
-<P>
-Returns 
-        a pointer ... if successful,
-        NULL ... otherwise.
-
-<P>
-void G3d_free(void *ptr) Same as <EM>free (ptr)</EM>.
-
-<P>
-char *G3d_allocTilesType(void *map, int nofTiles, int type)
-Allocates a vector of <EM>nofTiles</EM> tiles with the same dimensions
-as the tiles of <EM>map</EM> and large enough to store cell-values of
-<EM>type</EM>.
-
-<P>
-Returns 
-        a pointer to the vector ... if successful,
-        NULL ... otherwise.
-
-<P>
-char *G3d_allocTiles(void *map, int nofTiles)
-Is equivalent to G3d_allocTilesType (map, nofTiles, G3d_fileTypeMap (map)).
-
-<P>
-void G3d_freeTiles(char *tiles)
-Is equivalent to <TT>G3d_free (tiles);</TT>
-
-<P>
-
-\subsection G3D_Null_Value_Support G3D Null Value Support
-
-<P>
-void G3d_isNullValueNum(void *n, int type)
-Returns 1 if the value of <EM>*n</EM> is a NULL-value. Returns 0
-otherwise.
-
-<P>
-void G3d_setNullValue(void *c, int nofElts, int type)
-Fills the vector pointed to by <EM>c</EM> with <EM>nofElts</EM> NULL-values
-of <EM>type</EM>.
-
-<P>
-void G3d_setNullTileType(void *map, int tile, int type)
-Assumes that <EM>tile</EM> is a tile with the same dimensions as the
-tiles of <EM>map</EM>. Fills <EM>tile</EM> with NULL-values of
-<EM>type</EM>.
-
-<P>
-void G3d_setNullTile(void *map, int tile)
-Is equivalent to G3d_setNullTileType (map, tile, G3d_fileTypeMap (map)).
-
-<P>
-
-\subsection G3D_Map_Header_Information G3D Map Header Information
-
-<P>
-void G3d_getCoordsMap(void *map, int *rows, int *cols, int *depths)
-Returns the size of the region of <EM>map</EM> in cells.
-
-<P>
-void G3d_getRegionMap(void *map, int *north, int *south, int *east,
-  int *west, int *top, int *bottom)Returns the size of the region.
-
-<P>
-void G3d_getRegionStructMap(void *map, G3D_Region *region)
-Returns in <EM>region</EM> the region of <EM>map</EM>.
-
-<P>
-void G3d_getTileDimensionsMap(void *map, int *x, int *y, int *z)
-Returns the tile dimensions used for <EM>map</EM>.
-
-<P>
-void G3d_getNofTilesMap(void *map, int *nx, int *ny, int *nz)
-  Returns the dimensions of the tile-cube used to tile the region of <EM>map</EM>.
-  These numbers include partial tiles.
-
-<P>
-int G3d_tileTypeMap(void *map)
-Returns the type in which tiles of <EM>map</EM> are stored in memory.
-
-<P>
-int G3d_fileTypeMap(void *map)
-Returns the type with which tiles of <EM>map</EM> are stored on file.
-
-<P>
-int G3d_tilePrecisionMap(void *map)
-Returns the precision used to store <EM>map</EM>.
-
-<P>
-int G3d_tileUseCacheMap(void *map)
-Returns 1 if <EM>map</EM> uses cache, returns 0 otherwise.
-
-<P>
-void G3d_printHeader(void *map)
-Prints the header information of <EM>map</EM>.
-
-<P>
-
-\subsection G3D_Tile_Math G3D Tile Math
-
-<P>
-void G3d_tileIndex2tile(void *map, int tileIndex, int *xTile, int
-  *yTile, int *zTile) Converts index <EM>tileIndex</EM> into tile-coordinates
-  <EM>(xTile, yTile, zTile)</EM>.
-
-<P>
-int G3d_tile2tileIndex(void *map, int xTile, int yTile, int
-  zTile) Returns tile-index corresponding to tile-coordinates <EM>(xTile,
-    yTile, zTile)</EM>.
-
-<P>
-void G3d_coord2tileCoord(void *map, int x, int y, int z, int *xTile,
-  int *yTile, int *zTile, int *xOffs, int *yOffs, int *zOffs) Converts
-  cell-coordinates <EM>(x, y, z)</EM> into tile-coordinates <EM>(xTile, yTile,
-    zTile)</EM> and the coordinate of the cell <EM>(xOffs, yOffs, zOffs)</EM> within
-  the tile.
-
-<P>
-void G3d_tileCoordOrigin(void *map, int xTile, int yTile, int zTile,
-  int *x, int *y, int *z) Computes the cell-coordinates <EM>(x, y, z)</EM>
-  which correspond to the origin of the tile with tile-coordinates <EM>(xTile,
-    yTile, zTile)</EM>.
-
-<P>
-void G3d_tileIndexOrigin(void *map, int tileIndex, int *x, int *y,
-  int *z) Computes the cell-coordinates <EM>(x, y, z)</EM> which correspond to
-  the origin of the tile with <EM>tileIndex</EM>.
-
-<P>
-void G3d_coord2tileIndex(void *map, int x, int y, int z, int
-  *tileIndex, int *offset) Converts cell-coordinates <EM>(x, y, z)</EM> into
-  <EM>tileIndex</EM> and the <EM>offset</EM> of the cell within the tile.
-
-<P>
-int G3d_coordInRange(void *map, int x, int y, int z) Returns 1 if
-  cell-coordinate <EM>(x, y, z)</EM> is a coordinate inside the region. Returns 0
-  otherwise.
-
-<P>
-int G3d_tileInRange(void *map, int x, int y, int z) Returns 1 if
-  tile-coordinate <EM>(x, y, z)</EM> is a coordinate inside tile cube. Returns 0
-  otherwise.
-
-<P>
-int G3d_tileIndexInRange(void *map, int tileIndex)
-Returns 1 if <EM>tileIndex</EM> is a valid index for <EM>map</EM>.
-Returns 0 otherwise.
-
-<P>
-int G3d_isValidLocation(void *map, double north, double west, double
-  bottom) Returns 1 if region-coordinates <EM>(north, west, bottom)</EM> are
-  inside the region of <EM>map</EM>. Returns 0 otherwise.
-
-<P>
-void G3d_location2coord(void *map, double north, double west, double
-  bottom, int *x, *y, *z) Converts region-coordinates <EM>(north, west,
-    bottom)</EM> into cell-coordinates <EM>(x, y, z)</EM>.
-
-<P>
-int G3d_computeClippedTileDimensions(void *map, int tileIndex, int
-  *rows, int *cols, int *depths, int *xRedundant, int *yRedundant, int
-  *zRedundant) Computes the dimensions of the tile when clipped to fit the
-  region of <EM>map</EM>. The clipped dimensions are returned in <EM>rows</EM>, 
-  <EM>cols</EM>, <EM>depths</EM>.  The complement is returned in <EM>xRedundant</EM>,
-   <EM>yRedundant</EM>, and <EM>zRedundant</EM>. This function returns the number of
-  cells in the clipped tile.
-
-<P>
-
-\subsection G3D_Range_Support G3D Range Support
-
-<P>
-The map structure of G3D provides storage for the range.  The range of a map is
-updated every time a cell is written to the file. When an old map is opened the
-range is not automatically loaded. The application has to invoke
-<TT>G3d_range_load()</TT> (cf. Section 22.4.12)
- explicitly.  In
-addition to these function the application can also use the standard grass
-functions to manipulate the range.
-
-<P>
-int G3d_range_load(void *map)
-Loads the range into the range structure of <EM>map</EM>.
-
-<P>
-Returns
-        1 ... if successful
-        0 ... otherwise.
-
-<P>
-void G3d_range_min_max(void *map, double *min, double *max)
-        Returns in <EM>min</EM> and <EM>max</EM> the minimum and maximum values of
-        the range.
-
-<P>
-int G3d_range_write(void *map)
-Writes the range which is stored in the range structure of <EM>map</EM>. 
-(This function is invoked automatically when a new file is closed).
-
-<P>
-Returns
-        1 ... if successful
-        0 ... otherwise.
-
-<P>
-
-\subsection G3D_Color_Support G3D Color Support
-
-<P>
-Applications can use the standard grass functions to work with colors, except
-for the file manipulations.
-
-<P>
-int G3d_removeColor(char *name)
-Removes the primary and/or secondary color file. See <EM>G_remove_colr</EM> for
-details.
-
-<P>
-Returns always 0.
-
-<P>
-int G3d_readColors(char *name, char *mapset, struct Colors
-   *colors) Reads color file for map <EM>name</EM> in <EM>mapset</EM> into the
-   <EM>colors</EM> structure.  See <EM>G_read_colors</EM>
-   (Raster_Color_Table) for details and return values.
-
-<P>
-int G3d_writeColors(char *name, char *mapset, struct Colors
-   *colors)Writes colors stored in <EM>colors</EM> structure into the color
-   file for map <EM>name</EM> in <EM>mapset</EM>.  See <EM>G_write_colors</EM>
-   (Raster_Color_Table) for
-   details and return values.
-
-<P>
-
-\subsection G3D_Categories_Support G3D Categories Support
-
-<P>
-Applications can use the standard grass functions to work with categories, 
-except for the file manipulations.
-
-<P>
-int G3d_readCats(char *name, char *mapset, struct Categories *cats)
-Reads the categories file for map <EM>name</EM> in <EM>mapset</EM> and
-stores the categories in the <EM>cats</EM> structure.  See <EM>G_read_cats</EM>
-(Raster_Category_File) for details and return values.
-
-<P>
-int G3d_writeCats(char *name, struct Categories *cats) Writes the
-  categories stored in the <EM>cats</EM> structure into the categories file for
-  map <EM>name</EM> in the current mapset.  See <EM>G_write_cats</EM>
-  (Raster_Category_File) for details and return values.
-
-<P>
-
-
-\subsection G3D_History_Support G3D History Support
-
-<P>
-Applications can use the standard grass functions to work with histories, 
-except for the file manipulations.
-
-<P>
-int G3d_readHistory(char *name, char *mapset, struct History *hist)
-  Reads the history file for map <EM>name</EM> in <EM>mapset</EM> and
-  stores the history in the <EM>hist</EM> structure.  See <EM>G_read_history</EM>
-  (Raster_History_File) for details and return values.
-
-<P>
-int G3d_writeHistory(char *name, struct History *hist) 
-  Writes the
-  history stored in the <EM>hist</EM> structure into the categories file for
-  map <EM>name</EM> in the current mapset.  See <EM>G_write_history</EM>
-  (Raster_History_File) for details and return values.
-
-<P>
-
-\subsection G3D_Mask_Support G3D Mask Support
-
-<P>
-void G3d_maskOn(void *map) Turns on the mask for <EM>map</EM>. Do
-  not invoke this function after the first tile has been read since the result
-  might be inconsistent cell-values.
-
-<P>
-void G3d_maskOff(void *map) Turns off the mask for <EM>map</EM>.
-  This is the default.  Do not invoke this function after the first tile has
-  been read since the result might be inconsistent cell-values.
-
-<P>
-int G3d_maskIsOn(void *map) Returns 1 if the mask for <EM>map</EM>
-  is turned on. Returns 0 otherwise.
-
-<P>
-int G3d_maskIsOff(void *map)
-Returns 1 if the mask for <EM>map</EM> is turned off. Returns 0 otherwise.
-
-<P>
-The remaining functions in this section are for the explicit query of the mask
-and the masking of individual cells or tiles. These functions are used in the
-library and might have applications in situations where both the masked and
-non-masked value of a cell has to be known.  
-
-<P>
-int G3d_maskReopen(int cache)
-This function should be used to adjust the cache size used for the
-3d-mask. First the open 3d-mask is closed and then opened again with 
-a cache size as specified with <EM>cache</EM>.
-
-<P>
-Returns
-        1 ... if successful
-        0 ... otherwise.
-
-<P>
-int G3d_maskFileExists() Returns 1 if the 3d mask file
-        exists.
-
-<P>
-int G3d_maskMapExists()
-Returns 1 if the 3d mask is loaded.
-
-<P>
-char *G3d_maskFile()
-Returns the name of the 3d mask file.
-
-<P>
-int G3d_isMasked(int x, int y, int z)
-Returns 1 if the cell with cell-coordinates <EM>(x, y, z)</EM> is masked
-out. Returns 0 otherwise.
-
-<P>
-void G3d_maskNum(int x, int y, int z, void  *value, int type)
-Replaces the value stored in <EM>value</EM> with the NULL-value if 
-<EM>G3d_isMasked (x, y, z)</EM> returns 1. Does nothing otherwise.
-<EM>value</EM> is assumed to be of<EM>type</EM>.
-
-<P>
-void G3d_maskFloat(int x, int y, int z, float *value)
-Same as <EM>G3d_maskNum (x, y, z, value, FCELL_TYPE)</EM>.
-
-<P>
-void G3d_maskDouble(int x, int y, int z, double *value)
-Same as <EM>G3d_maskNum (x, y, z, value, DCELL_TYPE)</EM>.
-
-<P>
-void G3d_maskTile(void *map, int tileIndex, char *tile, int type)
-Replaces the values stored in <EM>tile</EM> (with <EM>tileIndex</EM>) for 
-which <EM>G3d_isMasked</EM> returns 1 with NULL-values. Does not change
-the remaining values. The values are assumed to be of <EM>type</EM>. 
-Whether replacement is performed or not only depends on location of the
-cells of the tile and not on the status of the mask for <EM>map</EM>
-(i.e. turned on or off).
-
-<P>
-
-\subsection G3D_Window_Support G3D Window Support
-
-<P>
-void G3d_setWindowMap(void *map, G3D_Region *window)
-Sets the window for <EM>map</EM> to <EM>window</EM>.
-Can be used multiple times for the same map.
-
-<P>
-void G3d_setWindow(G3D_Region *window)
-Sets the default window used for every map opened later in the program.
-Can be used multiple times in the same program.
-
-<P>
-void G3d_getWindow(G3D_Region *window)
-Stores the current default window in <EM>window</EM>.
-
-<P>
-void  *G3d_windowPtr()
-Returns a pointer to the current default window. This pointer should not be
-(ab)used to modify the current window structure directly. It is
-provided to pass a window pointer when opening a map.
-
-<P>
-int G3d_readWindow(G3D_Region *window, char *windowName) Reads
-  <EM>window</EM> from the file specified by <EM>windowName</EM>. The name is
-  converted by the rules defined in window defaults. A NULL pointer indicates
-  the <EM>WIND3</EM> file in the current mapset.
-
-<P>
-Returns
-        1 ... if successful
-        0 ... otherwise.
-
-<P>
-int G3d_writeWindow(G3D_Region *window, char *windowName)
-        Writes <EM>window</EM> to the file specified by <EM>windowName</EM>. The name
-        is converted by the rules defined in window defaults. A NULL pointer
-        indicates the <EM>WIND3</EM> file in the current mapset.
-
-<P>
-Returns
-        1 ... if successful
-        0 ... otherwise.
-
-<P>
-void G3d_useWindowParams()
-Allows the window to be set at run-time via the <EM>region3</EM>
-command line argument. This function has to be called before
-<EM>G_parser()</EM>. See also
- window defaults.
-
-<P>
-void G3d_setResamplingFun(void *map, void  (*resampleFun)())
-Sets the resampling function to be used by
-G3d_getValue() (cf. Section 22.4.3). This function is defined
-as follows:
-
-<P>
-void G3d_customResampleFun(void *map, int row, int col, int depth,
-  char *value, int type) <EM>row</EM>, <EM>col</EM>, and <EM>depth</EM> are in
-  region coordinates. The result is returned in <EM>value</EM> as <EM>type</EM> which
-  is one of FCELL_TYPE or DCELL_TYPE. Possible choices include
-  G3d_nearestNeighbor() (cf. Section22.4.16) and
-  G3d_getValueRegion() (cf. Section 22.4.3).
-
-<P>
-void G3d_nearestNeighbor(void *map, int row, int col, int depth, char
-  *value, int type) The default resampling function which uses nearest
-  neighbor resampling.
-
-<P>
-void G3d_getResamplingFun(void *map, void  (**resampleFun)())
-  Returns in <EM>resampleFun</EM> a pointer to the resampling function used by
-  <EM>map</EM>.
-
-<P>
-void G3d_getNearestNeighborFunPtr(void (**nnFunPtr)()) Returns
-  in <EM>nnFunPtr</EM> a pointer to G3d_nearestNeighbor() (cf. 
-  Section&nbsp;<A HREF="#g3d:G3d.nearestNeighbor">22.4.16</A>).
-
-<P>
-
-\subsection G3D_Region G3D Region
-
-<P>
-void G3d_extract2dRegion(G3D_Region *region3d, struct Cell_head
-  *region2d) Returns in <EM>region2d</EM> the <EM>2d</EM> portion of <EM>region3d</EM>.
-
-<P>
-void G3d_incorporate2dRegion(struct Cell_head *region2d, G3D_Region
-  *region3d) Replaces the <EM>2d</EM> portion of <EM>region3d</EM> with the
-  values stored in <EM>region2d</EM>.
-
-<P>
-void G3d_adjustRegion(G3D_Region *region)
-Computes an adjusts the resolutions in the region structure from the region
-boundaries and number of cells per dimension.
-
-<P>
-void G3d_adjustRegionRes(G3D_Region *region)
-Computes an adjusts the number of cells per dimension in the region
-structure from the region boundaries and resolutions.
-
-<P>
-void G3d_regionCopy(G3D_Region *regionDest, G3D_Region *regionSrc)
-Copies the values of <EM>regionSrc</EM> into <EM>regionDst</EM>.
-(The unfortunate order of parameters was chosen in order to conform to the
-order used in <EM>G_copy()</EM>).
-
-<P>
-void G3d_getRegionValue(void *map, double north, double east, double
-  top, char *value, int type) Returns in <EM>value</EM> the value of the <EM>map</EM>
-   which corresponds to region coordinates <EM>(north, east, top)</EM>.  The
-  value is resampled using the resampling function specified for <EM>map</EM>. The
-  <EM>value</EM> is of <EM>type</EM>.
-
-<P>
-void G3d_readRegionMap(char *name, char *mapset, G3D_Region *region)
-Returns in <EM>region</EM> the region information for 3d cell <EM>name at mapset</EM>.
-
-<P>
-
-\subsection Miscellaneous_Functions Miscellaneous Functions
-
-<P>
-void G3d_g3dType2cellType(int g3dType) Returns the GRASS floating
-  point type which is equivalent to the G3D type of <EM>g3dType</EM>.
-
-<P>
-void G3d_initDefaults() Initializes the default values described
-  in G3D Defaults.  Applications have to use this function only if they need to
-  query the default values before the first file (either old or new) has been
-  opened.
-
-<P>
-void G3d_setStandard3dInputParams() 
- Initializes a parameter
-  structure for the subset of command line arguments which lets the user
-  overwrite the default properties of the new file.  Applications are
-  encouraged to use this function in order to provide a uniform style.  The
-  command line arguments provided are the <EM>type</EM> of the cell values, the
-  <EM>precision</EM>, the properties of the <EM>compression</EM>, and the dimension
-  of the tiles (<EM>tiledimension</EM>). Every of these values defaults to the
-  value described in G3D Defaults.
-
-<P>
-This function has to be used in conjunction with
-  G3d_getStandard3dInputParams() (cf. 
-  Section 22.4.18).
-
-<P>
-int G3d_getStandard3dInputParams(int *useTypeDefault, *type, *useLzwDefault, *doLzw,
-        int *useRleDefault, *doRle, *usePrecisionDefault, *precision,
-        int *useDimensionDefault, *tileX, *tileY, *tileZ
-Returns the properties of the new file as chosen by the user via command
-line arguments. If the default is chosen the values of
-<EM>useXxxxDefault</EM> is 1, it is 0 otherwise. In addition, the
-corresponding parameters contain the default value if 
-<EM>useXxxxDefault</EM> is 1, or the value specified by the user if 
-<EM>useXxxxDefault</EM> is 0.
-
-<P>
-Function 
-G3d_setStandard3dInputParams() (cf. Section 22.4.18)
-has to be used to initialize the internal parameter structure.
-
-<P>
-Returns 
-        1 ... if successful,
-        0 ... otherwise.
-
-<P>
-int G3d_makeMapsetMapDirectory(char *mapName)
-Creates the 3d mapset element for map <EM>mapName</EM>.
-
-<P>
-int G3d_filename(char *path, *elementName, *mapName, *mapset)
-Returns in <EM>path</EM> the path for element <EM>elementName</EM> for map
-<EM>mapName</EM> in <EM>mapset</EM>. Note, an error occurs if <EM>mapName</EM>
-is fully qualified.
-
-<P>
-See TimeStamp_functions for a complete discussion of GRASS datetime
-routines (reading, writing grid3d timestamps).
-
-<P>
-
-\section Sample_G3D_Applications Sample G3D Applications
-
-<P>
-These functions were implemented to test the library. They are not very
-efficient but can be used as starting point for other
-applications. Some of them might actually be useful. They are available from
-GRASS 7 source code in lib/g3d/.
-
-<P>
-void G3d_retile(void *map, char *nameOut, int tileX, int tileY, int tileZ)
-Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which has
-tile dimensions <EM>tileX</EM>, <EM>tileY</EM>, <EM>tileZ</EM>.
-
-<P>
-The source code can be found in <EM>retile.c</EM>.
-
-<P>
-void G3d_changePrecision(void *map, int precision, char *nameOut)
-Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which is
-written with <EM>precision</EM>.
-
-<P>
-The source code can be found in <EM>changeprecision.c</EM>.
-
-<P>
-void G3d_changeType(void *map, char *nameOut)
-Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> in which the
-cells are of type FCELL_TYPE if they are DCELL_TYPE in <EM>map</EM>,
-and in DCELL_TYPE otherwise.
-
-<P>
-The source code can be found in <EM>changetype.c</EM>.
-
-<P>
-void G3d_compareFiles(char *f1, char *mapset1, char *f2, char *mapset2)
-Compares the cell-values of file <EM>f1</EM> in mapset
-<EM>mapset1</EM> and file <EM>f2</EM> in mapset <EM>mapset2</EM>.
-The values are compared up to precision.
-Terminates in error if the files don't match.
-This function uses the more advanced features of the cache.
-
-<P>
-The source code can be found in <EM>filecompare.c</EM>.
-
-<P>
-void G3d_getBlock(void *map, int x0, int y0, int z0, int nx, int ny,
-int nz, char *block,  int type)
-Copies the cells contained in the block (cube) with vertices 
-<EM>(x0, y0, z0)</EM> and <EM>(x0 + nx - 1, y0 + ny - 1, z0 + nz - 1)</EM>
-into <EM>block</EM>. The cell-values in <EM>block</EM> are of <EM>type</EM>.
-
-<P>
-The source code can be found in <EM>getblock.c</EM>.
-
-<P>
-void G3d_writeAscii(void *map, char *fname)
-Writes the cell-values of <EM>map</EM> in ascii format to file 
-<EM>fname</EM>. The values are organized by horizontal slices.
-
-
-<P>
-See \ref Compiling_and_Installing_GRASS_Modules for a complete 
-discussion of Makefiles.
-
-*/

Deleted: grass/trunk/lib/raster3d/g3dlong.c
===================================================================
--- grass/trunk/lib/raster3d/g3dlong.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dlong.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,69 +0,0 @@
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_longEncode(long *source, unsigned char *dst, int nofNums)
-{
-    long *src, d;
-    int eltLength, nBytes;
-    unsigned char *dstStop, tmp;
-
-    eltLength = G3D_LONG_LENGTH;
-    nBytes = 8;
-
-    d = 1;
-
-    while (eltLength--) {
-	dstStop = dst + nofNums;
-	src = source;
-
-	while (dst != dstStop) {
-	    tmp = ((*src++ / d) % 256);
-	    if (tmp != 0)
-		nBytes = G3D_MIN(nBytes, eltLength);
-	    *dst++ = tmp;
-	}
-
-	d *= 256;
-    }
-
-    return G3D_LONG_LENGTH - nBytes;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_longDecode(unsigned char *source, long *dst, int nofNums, int longNbytes)
-{
-    long *dest;
-    int eltLength;
-    unsigned char *srcStop;
-
-    eltLength = longNbytes;
-
-    source += nofNums * eltLength - 1;
-
-    eltLength--;
-    srcStop = source - nofNums;
-    dest = dst;
-    dest += nofNums - 1;
-    while (source != srcStop) {
-	*dest = *source--;
-	if ((eltLength >= G3D_LONG_LENGTH) && (*dest != 0))
-	    G3d_fatalError("G3d_longDecode: decoded long too long");
-	dest--;
-    }
-
-    while (eltLength--) {
-	srcStop = source - nofNums;
-	dest = dst;
-	dest += nofNums - 1;
-	while (source != srcStop) {
-	    *dest *= 256;
-	    *dest += *source--;
-	    if ((eltLength >= G3D_LONG_LENGTH) && (*dest != 0))
-		G3d_fatalError("G3d_longDecode: decoded long too long");
-	    dest--;
-	}
-    }
-}

Deleted: grass/trunk/lib/raster3d/g3dmapset.c
===================================================================
--- grass/trunk/lib/raster3d/g3dmapset.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dmapset.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,15 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-void G3d_makeMapsetMapDirectory(const char *mapName)
-{
-    char buf[GNAME_MAX + sizeof(G3D_DIRECTORY) + 2];
-
-    sprintf(buf, "%s/%s", G3D_DIRECTORY, mapName);
-    G__make_mapset_element(buf);
-}

Deleted: grass/trunk/lib/raster3d/g3dmask.c
===================================================================
--- grass/trunk/lib/raster3d/g3dmask.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dmask.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,411 +0,0 @@
-#include <stdio.h>
-#include <grass/gis.h>
-#include "G3d_intern.h"
-
-/*--------------------------------------------------------------------------*/
-
-/* the standard g3d file format is used to store the mask values. a NULL-value
-   is stored for values which are masked out and a "0." is stored for values 
-   which are not masked out. to improve compression, the precision is set to 
-   0 and RLE encoding is used.
- */
-
-/*--------------------------------------------------------------------------*/
-
-static int G3d_maskMapExistsVar = 0;
-static G3D_Map *G3d_maskMap;
-
-/*--------------------------------------------------------------------------*/
-static void dummy(void)
-{
-    return;
-}
-
-
-static float G3D_MASKNUMmaskValue;
-
-/* Call to dummy() to match void return type of G3d_setNullValue() */
-#define G3D_MASKNUM(map,Xmask,Ymask,Zmask,VALUEmask,TYPEmask) \
-\
-   (G3D_MASKNUMmaskValue = G3d_getMaskFloat (map, Xmask, Ymask, Zmask), \
-    ((G3d_isNullValueNum (&G3D_MASKNUMmaskValue, FCELL_TYPE)) ? \
-      G3d_setNullValue (VALUEmask, 1, TYPEmask) : dummy()))
-
-/*--------------------------------------------------------------------------*/
-
-int G3d_maskClose()
-{
-    /* No Idea if this is correct return value */
-    if (!G3d_maskMapExistsVar)
-	return 1;
-
-    G3d_maskMapExistsVar = 0;
-
-    if (!G3d_closeCell(G3d_maskMap)) {
-	G3d_error("G3d_maskClose: error closing mask");
-
-	return 0;
-    }
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns 1 if the 3d mask file exists.
- *
- *  \return int
- */
-
-int G3d_maskFileExists(void)
-{
-    return G_find_file_misc(G3D_DIRECTORY, G3D_CELL_ELEMENT, G3D_MASK_MAP, G_mapset()) != NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-
-static int maskOpenOldCacheDefault = G3D_USE_CACHE_DEFAULT;
-
-int G3d_maskOpenOld(void)
-{
-    G3D_Region region;
-
-    /* No Idea if this is correct return value */
-    if (G3d_maskMapExistsVar)
-	return 1;
-
-    G3d_maskMapExistsVar = G3d_maskFileExists();
-
-    if (!G3d_maskMapExistsVar)
-	return 1;
-
-    if ((G3d_maskMap = G3d_openCellOld(G3D_MASK_MAP, G_mapset(),
-				       G3D_DEFAULT_WINDOW, FCELL_TYPE,
-				       maskOpenOldCacheDefault))
-	== NULL) {
-	G3d_error("G3d_maskOpenOld: cannot open mask");
-
-	return 0;
-    }
-
-    G3d_getRegionStructMap(G3d_maskMap, &region);
-    G3d_setWindowMap(G3d_maskMap, &region);
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-static float G3d_getMaskFloat(G3D_Map * map, int x, int y, int z)
-{
-    double north, east, top;
-    float value;
-
-    north = ((double)map->window.rows - y - 0.5) / (double)map->window.rows *
-	(map->window.north - map->window.south) + map->window.south;
-    east = ((double)x + 0.5) / (double)map->window.cols *
-	(map->window.east - map->window.west) + map->window.west;
-    top = ((double)z + 0.5) / (double)map->window.depths *
-	(map->window.top - map->window.bottom) + map->window.bottom;
-
-    G3d_getRegionValue(G3d_maskMap, north, east, top, &value, FCELL_TYPE);
-    return value;
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  This function should be used to adjust the cache size used for the
- * 3d-mask. First the open 3d-mask is closed and then opened again with 
- * a cache size as specified with <em>cache</em>.
- *  
- *  \param cache
- *  \return 1 ... if successful
- *          0 ... otherwise.
- */
-
-int G3d_maskReopen(int cache)
-{
-    int tmp;
-
-    if (G3d_maskMapExistsVar)
-	if (!G3d_maskClose()) {
-	    G3d_error("G3d_maskReopen: error closing mask");
-
-	    return 0;
-	}
-
-    tmp = maskOpenOldCacheDefault;
-    maskOpenOldCacheDefault = cache;
-
-    if (!G3d_maskOpenOld()) {
-	G3d_error("G3d_maskReopen: error opening mask");
-
-	return 0;
-    }
-
-    maskOpenOldCacheDefault = tmp;
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns 1 if the cell with cell-coordinates <em>(x, y, z)</em> is masked
- *  out. Returns 0 otherwise.
- *
- *  \param x
- *  \param y
- *  \param z
- *  \return int
- */
-
-int G3d_isMasked(G3D_Map * map, int x, int y, int z)
-{
-    if (!G3d_maskMapExistsVar)
-	return 0;
-
-    G3D_MASKNUMmaskValue = G3d_getMaskFloat(map, x, y, z);
-    return (G3d_isNullValueNum(&G3D_MASKNUMmaskValue, FCELL_TYPE));
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Replaces the value stored in <em>value</em> with the NULL-value if 
- * <em>G3d_isMasked (x, y, z)</em> returns 1. Does nothing otherwise.
- * <em>value</em> is assumed to be of<em>type</em>.
- *
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \param type
- *  \return void
- */
-
-void G3d_maskNum(G3D_Map * map, int x, int y, int z, void *value, int type)
-{
-    if (!G3d_maskMapExistsVar)
-	return;
-    G3D_MASKNUM(map, x, y, z, value, type);
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Same as <em>G3d_maskNum (x, y, z, value, FCELL_TYPE)</em>.
- *
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \return void
- */
-
-void G3d_maskFloat(G3D_Map * map, int x, int y, int z, float *value)
-{
-    if (!G3d_maskMapExistsVar)
-	return;
-    G3D_MASKNUM(map, x, y, z, value, FCELL_TYPE);
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Same as <em>G3d_maskNum (x, y, z, value, DCELL_TYPE)</em>.
- *
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \return void
- */
-
-void G3d_maskDouble(G3D_Map * map, int x, int y, int z, double *value)
-{
-    if (!G3d_maskMapExistsVar)
-	return;
-    G3D_MASKNUM(map, x, y, z, value, DCELL_TYPE);
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Replaces the values stored in <em>tile</em> (with <em>tileIndex</em>) for 
- *  which <em>G3d_isMasked</em> returns 1 with NULL-values. Does not change
- *  the remaining values. The values are assumed to be of <em>type</em>. 
- *  Whether replacement is performed or not only depends on location of the
- *  cells of the tile and not on the status of the mask for <em>map</em>
- *  (i.e. turned on or off).
- *
- *  \param map
- *  \param tileIndex
- *  \param tile
- *  \param type
- *  \return void
- */
-
-void G3d_maskTile(G3D_Map * map, int tileIndex, void *tile, int type)
-{
-    int nofNum, rows, cols, depths, xRedundant, yRedundant, zRedundant;
-    int x, y, z, xLength, yLength, dx, dy, dz, length;
-
-    if (!G3d_maskMapExistsVar)
-	return;
-
-    nofNum = G3d_computeClippedTileDimensions(map, tileIndex,
-					      &rows, &cols, &depths,
-					      &xRedundant, &yRedundant,
-					      &zRedundant);
-    G3d_tileIndexOrigin(map, tileIndex, &x, &y, &z);
-
-    if (nofNum == map->tileSize) {
-	 /*AV*/
-	    /* BEGIN OF ORIGINAL CODE */
-	    /*
-	     *    G3d_getTileDimensionsMap (map, &rows, &cols, &depths);
-	     */
-	     /*AV*/
-	    /* BEGIN OF MY CODE */
-	    G3d_getTileDimensionsMap(map, &cols, &rows, &depths);
-	/* END OF MY CODE */
-	xRedundant = yRedundant = 0;
-    }
-
-    rows += y;
-    cols += x;
-    depths += z;
-    length = G3d_length(type);
-    xLength = xRedundant * length;
-    yLength = map->tileX * yRedundant * length;
-
-    for (dz = z; dz < depths; dz++) {
-	for (dy = y; dy < rows; dy++) {
-	    for (dx = x; dx < cols; dx++) {
-		G3D_MASKNUM(map, dx, dy, dz, tile, type);
-		tile += length;
-	    }
-
-	    tile += xLength;
-	}
-	tile += yLength;
-    }
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Turns on the mask for <em>map</em>. Do
- * not invoke this function after the first tile has been read since the result
- * might be inconsistent cell-values.
- *
- *  \param map
- *  \return void
- */
-
-void G3d_maskOn(G3D_Map * map)
-{
-    map->useMask = 1;
-}
-
-
-/*!
- * \brief 
- *
- *  Turns off the mask for <em>map</em>.
- * This is the default.  Do not invoke this function after the first tile has
- * been read since the result might be inconsistent cell-values.
- *
- *  \param map
- *  \return void
- */
-
-void G3d_maskOff(G3D_Map * map)
-{
-    map->useMask = 0;
-}
-
-
-/*!
- * \brief 
- *
- *  Returns 1 if the mask for <em>map</em>
- * is turned on. Returns 0 otherwise.
- *
- *  \param map
- *  \return int
- */
-
-int G3d_maskIsOn(G3D_Map * map)
-{
-    return map->useMask;
-}
-
-
-/*!
- * \brief 
- *
- * Returns 1 if the mask for <em>map</em> is turned off. Returns 0 otherwise.
- *
- *  \param map
- *  \return int
- */
-
-int G3d_maskIsOff(G3D_Map * map)
-{
-    return !map->useMask;
-}
-
-
-/*!
- * \brief 
- *
- * Returns the name of the 3d mask file.
- *
- *  \return char * 
- */
-
-const char *G3d_maskFile(void)
-{
-    return G3D_MASK_MAP;
-}
-
-
-/*!
- * \brief 
- *
- * Returns 1 if the 3d mask is loaded.
- *
- *  \return int
- */
-
-int G3d_maskMapExists(void)
-{
-    return G3d_maskMapExistsVar;
-}

Deleted: grass/trunk/lib/raster3d/g3dmisc.c
===================================================================
--- grass/trunk/lib/raster3d/g3dmisc.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dmisc.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,102 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#include <grass/raster.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_g3dType2cellType(int g3dType)
-{
-    if (g3dType == FCELL_TYPE)
-	return FCELL_TYPE;
-    return DCELL_TYPE;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_copyFloat2Double(const float *src, int offsSrc, double *dst, int offsDst,
-		     int nElts)
-{
-    int i;
-
-    src += offsSrc;
-    dst += offsDst;
-
-    for (i = 0; i < nElts; i++)
-	dst[i] = (double)src[i];
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_copyDouble2Float(const double *src, int offsSrc, float *dst, int offsDst,
-		     int nElts)
-{
-    int i;
-
-    src += offsSrc;
-    dst += offsDst;
-
-    for (i = 0; i < nElts; i++)
-	dst[i] = (float)src[i];
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst,
-	       int offsDst, int typeDst, int nElts)
-{
-    int eltLength;
-
-    if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
-	G3d_copyFloat2Double(src, offsSrc, dst, offsDst, nElts);
-	return;
-    }
-
-    if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
-	G3d_copyDouble2Float(src, offsSrc, dst, offsDst, nElts);
-	return;
-    }
-
-    eltLength = G3d_length(typeSrc);
-
-    src = G_incr_void_ptr(src, eltLength * offsSrc);
-    dst = G_incr_void_ptr(dst, eltLength * offsDst);
-
-    memcpy(dst, src, nElts * eltLength);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_length(int t)
-{
-    if (!G3D_IS_CORRECT_TYPE(t))
-	G3d_fatalError("G3d_length: invalid type");
-
-    if (t == FCELL_TYPE)
-	return sizeof(FCELL);
-    if (t == DCELL_TYPE)
-	return sizeof(DCELL);
-    return 0;
-}
-
-int G3d_externLength(int t)
-{
-    if (!G3D_IS_CORRECT_TYPE(t))
-	G3d_fatalError("G3d_externLength: invalid type");
-
-    if (t == FCELL_TYPE)
-	return G3D_XDR_FLOAT_LENGTH;
-    if (t == DCELL_TYPE)
-	return G3D_XDR_DOUBLE_LENGTH;
-    return 0;
-}

Deleted: grass/trunk/lib/raster3d/g3dnull.c
===================================================================
--- grass/trunk/lib/raster3d/g3dnull.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dnull.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,43 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <grass/raster.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_isNullValueNum(const void *n, int type)
-{
-    if (type == FCELL_TYPE)
-	return Rast_is_f_null_value(n);
-    else
-	return Rast_is_d_null_value(n);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Fills the vector pointed to by <em>c</em> with <em>nofElts</em> NULL-values
- * of <em>type</em>.
- *
- *  \param c
- *  \param nofElts
- *  \param type
- *  \return void
- */
-
-void G3d_setNullValue(void *c, int nofElts, int type)
-{
-    if (type == FCELL_TYPE) {
-	Rast_set_f_null_value((float *)c, nofElts);
-	return;
-    }
-
-    Rast_set_d_null_value((double *)c, nofElts);
-}

Deleted: grass/trunk/lib/raster3d/g3dopen.c
===================================================================
--- grass/trunk/lib/raster3d/g3dopen.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dopen.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,324 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <grass/G3d.h>
-#include <grass/glocale.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-void *G3d_openCellOldNoHeader(const char *name, const char *mapset)
-{
-    G3D_Map *map;
-    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
-    G3d_initDefaults();
-
-    if (!G3d_maskOpenOld()) {
-	G3d_error(_("G3d_openCellOldNoHeader: error in G3d_maskOpenOld"));
-	return (void *)NULL;
-    }
-
-    map = G3d_malloc(sizeof(G3D_Map));
-    if (map == NULL) {
-	G3d_error(_("G3d_openCellOldNoHeader: error in G3d_malloc"));
-	return (void *)NULL;
-    }
-
-    G_unqualified_name(name, mapset, xname, xmapset);
-
-    map->fileName = G_store(xname);
-    map->mapset = G_store(xmapset);
-
-    map->data_fd = G_open_old_misc(G3D_DIRECTORY, G3D_CELL_ELEMENT, xname, xmapset);
-    if (map->data_fd < 0) {
-	G3d_error(_("G3d_openCellOldNoHeader: error in G_open_old"));
-	return (void *)NULL;
-    }
-
-    G3d_range_init(map);
-    G3d_maskOff(map);
-
-    return map;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Opens existing g3d-file <em>name</em> in <em>mapset</em>.
- * Tiles are stored in memory with <em>type</em> which must be any of FCELL_TYPE,
- * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
- * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
- * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
- * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
- * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt> (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
- * specifies the number of tiles buffered in the cache.  <em>window</em> sets the
- * window-region for the map. It is either a pointer to a window structure or
- * G3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
- * set via <tt>G3d_setWindow ()</tt> (cf.{g3d:G3d.setWindow}).
- * To modify the window for the map after it has already been opened use
- * <tt>G3d_setWindowMap ()</tt> (cf.{g3d:G3d.setWindowMap}).
- * Returns a pointer to the cell structure ... if successful, NULL ...
- * otherwise.
- *
- *  \param name
- *  \param mapset
- *  \param window
- *  \param type
- *  \param cache
- *  \return void * 
- */
-
-void *G3d_openCellOld(const char *name, const char *mapset,
-		      G3D_Region * window, int typeIntern, int cache)
-{
-    G3D_Map *map;
-    int proj, zone;
-    int compression, useRle, useLzw, type, tileX, tileY, tileZ;
-    int rows, cols, depths, precision;
-    double ew_res, ns_res, tb_res;
-    int nofHeaderBytes, dataOffset, useXdr, hasIndex;
-    char *ltmp, *unit;
-    double north, south, east, west, top, bottom;
-
-    map = G3d_openCellOldNoHeader(name, mapset);
-    if (map == NULL) {
-	G3d_error(_("G3d_openCellOld: error in G3d_openCellOldNoHeader"));
-	return (void *)NULL;
-    }
-
-    if (lseek(map->data_fd, (long)0, SEEK_SET) == -1) {
-	G3d_error(_("G3d_openCellOld: can't rewind file"));
-	return (void *)NULL;
-    }
-
-    if (!G3d_readHeader(map,
-			&proj, &zone,
-			&north, &south, &east, &west, &top, &bottom,
-			&rows, &cols, &depths,
-			&ew_res, &ns_res, &tb_res,
-			&tileX, &tileY, &tileZ,
-			&type, &compression, &useRle, &useLzw,
-			&precision, &dataOffset, &useXdr, &hasIndex, &unit)) {
-	G3d_error(_("G3d_openCellOld: error in G3d_readHeader"));
-	return 0;
-    }
-
-    if (window == G3D_DEFAULT_WINDOW)
-	window = G3d_windowPtr();
-
-    if (proj != window->proj) {
-	G3d_error(_("G3d_openCellOld: projection does not match window projection"));
-	return (void *)NULL;
-    }
-    if (zone != window->zone) {
-	G3d_error(_("G3d_openCellOld: zone does not match window zone"));
-	return (void *)NULL;
-    }
-
-    map->useXdr = useXdr;
-
-    if (hasIndex) {
-	/* see G3D_openCell_new () for format of header */
-	if ((!G3d_readInts(map->data_fd, map->useXdr,
-			   &(map->indexLongNbytes), 1)) ||
-	    (!G3d_readInts(map->data_fd, map->useXdr,
-			   &(map->indexNbytesUsed), 1))) {
-	    G3d_error(_("G3d_openCellOld: can't read header"));
-	    return (void *)NULL;
-	}
-
-	/* if our long is to short to store offsets we can't read the file */
-	if (map->indexNbytesUsed > sizeof(long))
-	    G3d_fatalError(_("G3d_openCellOld: index does not fit into long"));
-
-	ltmp = G3d_malloc(map->indexLongNbytes);
-	if (ltmp == NULL) {
-	    G3d_error(_("G3d_openCellOld: error in G3d_malloc"));
-	    return (void *)NULL;
-	}
-
-	/* convert file long to long */
-	if (read(map->data_fd, ltmp, map->indexLongNbytes) !=
-	    map->indexLongNbytes) {
-	    G3d_error(_("G3d_openCellOld: can't read header"));
-	    return (void *)NULL;
-	}
-	G3d_longDecode(ltmp, &(map->indexOffset), 1, map->indexLongNbytes);
-	G3d_free(ltmp);
-    }
-
-    nofHeaderBytes = dataOffset;
-
-    if (typeIntern == G3D_TILE_SAME_AS_FILE)
-	typeIntern = type;
-
-    if (!G3d_fillHeader(map, G3D_READ_DATA, compression, useRle, useLzw,
-			type, precision, cache,
-			hasIndex, map->useXdr, typeIntern,
-			nofHeaderBytes, tileX, tileY, tileZ,
-			proj, zone,
-			north, south, east, west, top, bottom,
-			rows, cols, depths, ew_res, ns_res, tb_res, unit)) {
-	G3d_error(_("G3d_openCellOld: error in G3d_fillHeader"));
-	return (void *)NULL;
-    }
-
-    G3d_regionCopy(&(map->window), window);
-    G3d_adjustRegion(&(map->window));
-    G3d_getNearestNeighborFunPtr(&(map->resampleFun));
-
-    return map;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
- * are stored in memory with <em>type</em> which must be one of FCELL_TYPE,
- * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
- * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
- * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
- * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
- * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
- * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
- * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
- * the 3d region.  
- * Returns a pointer to the cell structure ... if successful,
- * NULL ... otherwise.
- *
- *  \param name
- *  \param type
- *  \param cache
- *  \param region
- *  \return void * 
- */
-
-void *G3d_openCellNew(const char *name, int typeIntern, int cache,
-		      G3D_Region * region)
-{
-    G3D_Map *map;
-    int nofHeaderBytes, dummy = 0, compression, precision;
-    long ldummy = 0;
-    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
-    G3d_initDefaults();
-    if (!G3d_maskOpenOld()) {
-	G3d_error(_("G3d_openCellNew: error in G3d_maskOpenOld"));
-	return (void *)NULL;
-    }
-
-    compression = g3d_do_compression;
-    precision = g3d_precision;
-
-    map = G3d_malloc(sizeof(G3D_Map));
-    if (map == NULL) {
-	G3d_error(_("G3d_openCellNew: error in G3d_malloc"));
-	return (void *)NULL;
-    }
-
-    if (G_unqualified_name(name, G_mapset(), xname, xmapset) < 0) {
-	G_warning(_("map <%s> is not in the current mapset"), name);
-	return (void *)NULL;
-    }
-
-    map->fileName = G_store(xname);
-    map->mapset = G_store(xmapset);
-
-    map->tempName = G_tempfile();
-    map->data_fd = open(map->tempName, O_RDWR | O_CREAT | O_TRUNC, 0666);
-    if (map->data_fd < 0) {
-	G3d_error(_("G3d_openCellNew: could not open file"));
-	return (void *)NULL;
-    }
-
-    G3d_makeMapsetMapDirectory(map->fileName);
-
-    map->useXdr = G3D_USE_XDR;
-
-    if (g3d_file_type == FCELL_TYPE) {
-	if (precision > 23)
-	    precision = 23;	/* 32 - 8 - 1 */
-	else if (precision < -1)
-	    precision = 0;
-    }
-    else if (precision > 52)
-	precision = 52;		/* 64 - 11 - 1 */
-    else if (precision < -1)
-	precision = 0;
-
-    /* no need to write trailing zeros */
-    if ((typeIntern == FCELL_TYPE) && (g3d_file_type == DCELL_TYPE)) {
-	if (precision == -1)
-	    precision = 23;
-	else
-	    precision = G3D_MIN(precision, 23);
-    }
-
-    if (compression == G3D_NO_COMPRESSION)
-	precision = G3D_MAX_PRECISION;
-    if (compression == G3D_COMPRESSION)
-	map->useXdr = G3D_USE_XDR;
-
-    if (G3D_HAS_INDEX) {
-	map->indexLongNbytes = sizeof(long);
-
-	/* at the beginning of the file write */
-	/*      nof bytes of "long" */
-	/*      max nof bytes used for index */
-	/*      position of index in file */
-	/* the index is appended at the end of the file at closing time. since */
-	/* we do not know this position yet we write dummy values */
-
-	if ((!G3d_writeInts(map->data_fd, map->useXdr,
-			    &(map->indexLongNbytes), 1)) ||
-	    (!G3d_writeInts(map->data_fd, map->useXdr, &dummy, 1))) {
-	    G3d_error(_("G3d_openCellNew: can't write header"));
-	    return (void *)NULL;
-	}
-	if (write(map->data_fd, &ldummy, map->indexLongNbytes) !=
-	    map->indexLongNbytes) {
-	    G3d_error(_("G3d_openCellNew: can't write header"));
-	    return (void *)NULL;
-	}
-    }
-
-    /* can't use a constant since this depends on sizeof (long) */
-    nofHeaderBytes = lseek(map->data_fd, (long)0, SEEK_CUR);
-
-    G3d_range_init(map);
-    G3d_adjustRegion(region);
-
-    if (!G3d_fillHeader(map, G3D_WRITE_DATA, compression,
-			g3d_do_rle_compression, g3d_do_lzw_compression,
-			g3d_file_type, precision, cache, G3D_HAS_INDEX,
-			map->useXdr, typeIntern, nofHeaderBytes,
-			g3d_tile_dimension[0], g3d_tile_dimension[1],
-			g3d_tile_dimension[2],
-			region->proj, region->zone,
-			region->north, region->south, region->east,
-			region->west, region->top, region->bottom,
-			region->rows, region->cols, region->depths,
-			region->ew_res, region->ns_res, region->tb_res,
-			g3d_unit_default)) {
-	G3d_error(_("G3d_openCellNew: error in G3d_fillHeader"));
-	return (void *)NULL;
-    }
-
-    /*Set the map window to the map region */
-    G3d_regionCopy(&(map->window), region);
-    /*Set the resampling function to nearest neighbor for data access */
-    G3d_getNearestNeighborFunPtr(&(map->resampleFun));
-
-    G3d_maskOff(map);
-
-    return (void *)map;
-}

Deleted: grass/trunk/lib/raster3d/g3dopen2.c
===================================================================
--- grass/trunk/lib/raster3d/g3dopen2.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dopen2.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,122 +0,0 @@
-#include <grass/gis.h>
-#include <grass/G3d.h>
-
-/*----------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
- * are stored in memory with <em>typeIntern</em> which must be one of FCELL_TYPE,
- * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
- * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
- * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
- * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
- * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
- * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
- * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
- * the 3d region.  
- * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
- * The methods for compression can be specified LZW or RLE. The digits of the floating point mantissa
- * can be specified. In case of FCELL_TYPE 0-23 and 0-52 in case of DCELL_TYPE. 
- * The number cells in X, Y and Z direction defines the size of each tile.
- * Returns a pointer to the cell structure ... if successful,
- * NULL ... otherwise.
- *
- *  \param name The name of the map
- *  \param typeIntern The internal storage type for in memory chached tiles
- *  \param cache The type of the caching
- *  \param region The region of the map
- *  \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
- *  \param doLzw Use the LZW compression algorithm  
- *  \param doRle Use the Run-Length-Encoding algroithm for compression
- *  \param precision The precision used for the mantissa (0 - 52) or G3D_MAX_PRECISION
- *  \param tileX The number of cells in X direction of a tile
- *  \param tileY The number of cells in Y direction of a tile
- *  \param tileZ The number of cells in Z direction of a tile
- *  \return void * 
- */
-
-
-void *G3d_openNewParam(const char *name, int typeIntern, int cache,
-		       G3D_Region * region, int type, int doLzw, int doRle,
-		       int precision, int tileX, int tileY, int tileZ)
-{
-    void *map;
-    int oldCompress, oldLzw, oldRle, oldPrecision, oldTileX, oldTileY,
-	oldTileZ;
-    int oldType;
-
-    G3d_initDefaults();
-
-    G3d_getCompressionMode(&oldCompress, &oldLzw, &oldRle, &oldPrecision);
-    G3d_setCompressionMode(oldCompress, doLzw, doRle, precision);
-
-    G3d_getTileDimension(&oldTileX, &oldTileY, &oldTileZ);
-    G3d_setTileDimension(tileX, tileY, tileZ);
-
-    oldType = G3d_getFileType();
-    G3d_setFileType(type);
-
-    map = G3d_openCellNew(name, typeIntern, cache, region);
-
-    G3d_setCompressionMode(oldCompress, oldLzw, oldRle, oldPrecision);
-    G3d_setTileDimension(oldTileX, oldTileY, oldTileZ);
-    G3d_setFileType(oldType);
-
-    return map;
-}
-
-/*----------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * Opens new g3d-file with <em>name</em> in the current mapset. This method tries to compute 
- * optimal tile size based on the number of rows, cols and depths and the maximum allowed tile size in KB. 
- * Tiles are stored in memory using G3D_TILE_SAME_AS_FILE method. <em>cache</em> specifies the
- * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
- * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
- * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
- * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
- * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
- * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
- * the 3d region.  
- * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
- * Returns a pointer to the cell structure ... if successful,
- * NULL ... otherwise.
- *
- *  \param name The name of the map
- *  \param cache The type of the caching
- *  \param region The region of the map
- *  \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
- *  \param maxSize The maximum size of a tile in kilo bytes
- *  \return void * 
- */
-
-
-void *G3d_openNewOptTileSize(const char *name, int cache, G3D_Region * region, int type, int maxSize)
-{
-    void *map;
-    int oldTileX, oldTileY, oldTileZ, oldType;
-    int tileX, tileY, tileZ;
-
-    G3d_initDefaults();
-
-
-    G3d_getTileDimension(&oldTileX, &oldTileY, &oldTileZ);
-    
-    G3d_computeOptimalTileDimension(region, type, &tileX, &tileY, &tileZ, maxSize);
-
-    G3d_setTileDimension(tileX, tileY, tileZ);
-
-    oldType = G3d_getFileType();
-    G3d_setFileType(type);
-
-    map = G3d_openCellNew(name, G3D_TILE_SAME_AS_FILE, cache, region);
-
-    G3d_setTileDimension(oldTileX, oldTileY, oldTileZ);
-    G3d_setFileType(oldType);
-
-    return map;
-}

Deleted: grass/trunk/lib/raster3d/g3dparam.c
===================================================================
--- grass/trunk/lib/raster3d/g3dparam.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dparam.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,157 +0,0 @@
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "G3d_intern.h"
-
-/*----------------------------------------------------------------------------*/
-
-typedef struct
-{
-
-    struct Option *type;
-    struct Option *precision;
-    struct Option *compression;
-    struct Option *dimension;
-    struct Option *cache;
-
-} G3d_paramType;
-
-/*----------------------------------------------------------------------------*/
-
-static G3d_paramType *param;
-
-
-/*!
- * \brief 
- *
- * Initializes a parameter
- * structure for the subset of command line arguments which lets the user
- * overwrite the default properties of the new file.  Applications are
- * encouraged to use this function in order to provide a uniform style.  The
- * command line arguments provided are the <em>type</em> of the cell values, the
- * <em>precision</em>, the properties of the <em>compression</em>, and the dimension
- * of the tiles (<em>tiledimension</em>). Every of these values defaults to the
- * value described in G3D Defaults.
- * This function has to be used in conjunction with
- * G3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
- *
- *  \return void
- */
-
-void G3d_setStandard3dInputParams()
-{
-    param = G3d_malloc(sizeof(G3d_paramType));
-
-    param->type = G_define_standard_option(G_OPT_R3_TYPE);
-
-    param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
-
-    param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
-
-    param->dimension = G_define_standard_option(G_OPT_R3_TILE_DIMENSION);
-}
-
-/*----------------------------------------------------------------------------*/
-
-int G3d_getStandard3dParams(int *useTypeDefault, int *type,
-			    int *useLzwDefault, int *doLzw,
-			    int *useRleDefault, int *doRle,
-			    int *usePrecisionDefault, int *precision,
-			    int *useDimensionDefault, int *tileX, int *tileY,
-			    int *tileZ)
-{
-    int doCompress;
-
-    *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
-    *usePrecisionDefault = *useDimensionDefault = 0;
-
-    G3d_initDefaults();
-
-    if (strcmp(param->type->answer, "double") == 0)
-	*type = DCELL_TYPE;
-    else if (strcmp(param->type->answer, "float") == 0)
-	*type = FCELL_TYPE;
-    else {
-	*type = G3d_getFileType();
-	*useTypeDefault = 1;
-    }
-
-    G3d_getCompressionMode(&doCompress, doLzw, doRle, precision);
-
-    if (strcmp(param->precision->answer, "default") != 0) {
-	if (strcmp(param->precision->answer, "max") == 0)
-	    *precision = -1;
-	else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
-		 (*precision < 0)) {
-	    G3d_error(_("G3d_getStandard3dParams: precision value invalid"));
-	    return 0;
-	}
-    }
-    else
-	*usePrecisionDefault = 1;
-
-
-    if (strcmp(param->compression->answer, "default") != 0) {
-	if (strcmp(param->compression->answer, "rle") == 0) {
-	    *doRle = G3D_USE_RLE;
-	    *doLzw = G3D_NO_LZW;
-	}
-	else if (strcmp(param->compression->answer, "lzw") == 0) {
-	    *doRle = G3D_NO_RLE;
-	    *doLzw = G3D_USE_LZW;
-	}
-	else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
-	    *doRle = G3D_USE_RLE;
-	    *doLzw = G3D_USE_LZW;
-	}
-	else {
-	    *doRle = G3D_NO_RLE;
-	    *doLzw = G3D_NO_LZW;
-	}
-    }
-    else
-	*useLzwDefault = *useRleDefault = 1;
-
-    G3d_getTileDimension(tileX, tileY, tileZ);
-    if (strcmp(param->dimension->answer, "default") != 0) {
-	if (sscanf(param->dimension->answer, "%dx%dx%d",
-		   tileX, tileY, tileZ) != 3) {
-	    G3d_error(_("G3d_getStandard3dParams: tile dimension value invalid"));
-	    return 0;
-	}
-    }
-    else
-	*useDimensionDefault = 1;
-
-    G3d_free(param);
-
-    return 1;
-}
-
-/*----------------------------------------------------------------------------*/
-
-static struct Option *windowParam = NULL;
-
-void G3d_setWindowParams(void)
-{
-    windowParam = G_define_option();
-    windowParam->key = "region3";
-    windowParam->type = TYPE_STRING;
-    windowParam->required = NO;
-    windowParam->multiple = NO;
-    windowParam->answer = NULL;
-    windowParam->description = _("Window replacing the default");
-}
-
-/*----------------------------------------------------------------------------*/
-
-char *G3d_getWindowParams(void)
-{
-    if (windowParam == NULL)
-	return NULL;
-    if (windowParam->answer == NULL)
-	return NULL;
-    if (strcmp(windowParam->answer, G3D_WINDOW_ELEMENT) == 0)
-	return G_store(G3D_WINDOW_ELEMENT);
-    return G_store(windowParam->answer);
-}

Deleted: grass/trunk/lib/raster3d/g3dputvalue.c
===================================================================
--- grass/trunk/lib/raster3d/g3dputvalue.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dputvalue.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,117 +0,0 @@
-#include <grass/raster.h>
-#include "G3d_intern.h"
-
-
-/*!
- * \brief 
- *
- * Is equivalent to G3d_putValue (map, x, y, z, &value, FCELL_TYPE).
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \return int
- */
-
-int G3d_putFloat(G3D_Map * map, int x, int y, int z, float value)
-{
-    int tileIndex, offs;
-    float *tile;
-
-    if (map->typeIntern == DCELL_TYPE) {
-	if (!G3d_putDouble(map, x, y, z, (double)value)) {
-	    G3d_error("G3d_putFloat: error in G3d_putDouble");
-	    return 0;
-	}
-	return 1;
-    }
-
-    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
-    tile = (float *)G3d_getTilePtr(map, tileIndex);
-    if (tile == NULL) {
-	G3d_error("G3d_putFloat: error in G3d_getTilePtr");
-	return 0;
-    }
-
-    tile[offs] = value;
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Is equivalent to G3d_putValue (map, x, y, z, &value, DCELL_TYPE).
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \return int
- */
-
-int G3d_putDouble(G3D_Map * map, int x, int y, int z, double value)
-{
-    int tileIndex, offs;
-    double *tile;
-
-    if (map->typeIntern == FCELL_TYPE) {
-	if (!G3d_putFloat(map, x, y, z, (float)value)) {
-	    G3d_error("G3d_putDouble: error in G3d_putFloat");
-	    return 0;
-	}
-	return 1;
-    }
-
-    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
-    tile = (double *)G3d_getTilePtr(map, tileIndex);
-    if (tile == NULL) {
-	G3d_error("G3d_putDouble: error in G3d_getTilePtr");
-	return 0;
-    }
-
-    tile[offs] = value;
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- * After converting <em>*value</em> of <em>type</em> into the type specified
- * at the initialization time (i.e. <em>typeIntern</em>) this function writes the
- * value into the tile buffer corresponding to cell-coordinate <em>(x, y, z)</em>.
- *
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param value
- *  \param type
- *  \return 1 ... if successful,  
- *          0 ... otherwise.
- */
-
-int
-G3d_putValue(G3D_Map * map, int x, int y, int z, const void *value, int type)
-{
-    if (type == FCELL_TYPE) {
-	if (!G3d_putFloat(map, x, y, z, *((float *)value))) {
-	    G3d_error("G3d_putValue: error in G3d_putFloat");
-	    return 0;
-	}
-	return 1;
-    }
-
-    if (!G3d_putDouble(map, x, y, z, *((double *)value))) {
-	G3d_error("G3d_putValue: error in G3d_putDouble");
-	return 0;
-    }
-    return 1;
-}

Deleted: grass/trunk/lib/raster3d/g3drange.c
===================================================================
--- grass/trunk/lib/raster3d/g3drange.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3drange.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,222 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_range_updateFromTile(G3D_Map * map, const void *tile, int rows, int cols,
-			 int depths, int xRedundant, int yRedundant,
-			 int zRedundant, int nofNum, int type)
-{
-    int y, z, cellType;
-    struct FPRange *range;
-
-    range = &(map->range);
-    cellType = G3d_g3dType2cellType(type);
-
-    if (nofNum == map->tileSize) {
-	Rast_row_update_fp_range(tile, map->tileSize, range, cellType);
-	return;
-    }
-
-    if (xRedundant) {
-	for (z = 0; z < depths; z++) {
-	    for (y = 0; y < rows; y++) {
-		Rast_row_update_fp_range(tile, cols, range, cellType);
-		tile = G_incr_void_ptr(tile, map->tileX * G3d_length(type));
-	    }
-	    if (yRedundant)
-		tile =
-		    G_incr_void_ptr(tile,
-				    map->tileX * yRedundant *
-				    G3d_length(type));
-	}
-	return;
-    }
-
-    if (yRedundant) {
-	for (z = 0; z < depths; z++) {
-	    Rast_row_update_fp_range(tile, map->tileX * rows, range, cellType);
-	    tile = G_incr_void_ptr(tile, map->tileXY * G3d_length(type));
-	}
-	return;
-    }
-
-    Rast_row_update_fp_range(tile, map->tileXY * depths, range, cellType);
-}
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_readRange(const char *name, const char *mapset, struct FPRange *drange)
- /* adapted from Rast_read_fp_range */
-{
-    int fd;
-    char xdr_buf[100];
-    DCELL dcell1, dcell2;
-    XDR xdr_str;
-
-    Rast_init_fp_range(drange);
-
-    fd = -1;
-
-    fd = G_open_old_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name, mapset);
-    if (fd < 0) {
-	G_warning(_("Unable to open range file for [%s in %s]"), name, mapset);
-	return -1;
-    }
-
-    if (read(fd, xdr_buf, 2 * G3D_XDR_DOUBLE_LENGTH) != 2 * G3D_XDR_DOUBLE_LENGTH) {
-	close(fd);
-	G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
-	return 2;
-    }
-
-    xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
-		  XDR_DECODE);
-
-    /* if the f_range file exists, but empty */
-    if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2)) {
-	close(fd);
-	G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
-	return -1;
-    }
-
-    Rast_update_fp_range(dcell1, drange);
-    Rast_update_fp_range(dcell2, drange);
-    close(fd);
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Loads the range into the range structure of <em>map</em>.
- *
- *  \param map
- *  \return 1 ... if successful
- *          0 ... otherwise.
- */
-
-int G3d_range_load(G3D_Map * map)
-{
-    if (map->operation == G3D_WRITE_DATA)
-	return 1;
-    if (G3d_readRange(map->fileName, map->mapset, &(map->range)) == -1) {
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Returns in <em>min</em> and <em>max</em> the minimum and maximum values of
- * the range.
- *
- *  \param map
- *  \param min
- *  \param max
- *  \return void
- */
-
-void G3d_range_min_max(G3D_Map * map, double *min, double *max)
-{
-    Rast_get_fp_range_min_max(&(map->range), min, max);
-}
-
-/*-------------------------------------------------------------------------*/
-
-static int writeRange(const char *name, struct FPRange *range)
- /* adapted from Rast_write_fp_range */
-{
-    char xdr_buf[100];
-    int fd;
-    XDR xdr_str;
-
-    fd = G_open_new_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name);
-    if (fd < 0) {
-	G_warning(_("Unable to open range file for <%s>"), name);
-	return -1;
-    }
-
-    if (range->first_time) {
-	/* if range hasn't been updated, write empty file meaning NULLs */
-	close(fd);
-	return 0;
-    }
-
-    xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
-		  XDR_ENCODE);
-
-    if (!xdr_double(&xdr_str, &(range->min)))
-	goto error;
-    if (!xdr_double(&xdr_str, &(range->max)))
-	goto error;
-
-    if (write(fd, xdr_buf, G3D_XDR_DOUBLE_LENGTH * 2) != G3D_XDR_DOUBLE_LENGTH * 2)
-	goto error;
-
-    close(fd);
-    return 0;
-
-  error:
-    close(fd);
-    G_remove_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name);	/* remove the old file with this name */
-    G_warning("can't write range file for [%s in %s]", name, G_mapset());
-    return -1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Writes the range which is stored in the range structure of <em>map</em>. 
- * (This function is invoked automatically when a new file is closed).
- *
- *  \param map
- *  \return 1 ... if successful
- *          0 ... otherwise.
- */
-
-int G3d_range_write(G3D_Map * map)
-{
-    char path[GPATH_MAX];
-
-    G3d_filename(path, G3D_RANGE_ELEMENT, map->fileName, map->mapset);
-    remove(path);
-
-    if (writeRange(map->fileName, &(map->range)) == -1) {
-	G3d_error("G3d_closeCellNew: error in writeRange");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-int G3d_range_init(G3D_Map * map)
-{
-    Rast_init_fp_range(&(map->range));
-    return 0;
-}

Deleted: grass/trunk/lib/raster3d/g3dregion.c
===================================================================
--- grass/trunk/lib/raster3d/g3dregion.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dregion.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,364 +0,0 @@
-#include <stdio.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/G3d.h>
-
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
- *
- *  \param region3d
- *  \param region2d
- *  \return void
- */
-
-void G3d_extract2dRegion(G3D_Region * region3d, struct Cell_head *region2d)
-{
-    region2d->proj = region3d->proj;
-    region2d->zone = region3d->zone;
-
-    region2d->north = region3d->north;
-    region2d->south = region3d->south;
-    region2d->east = region3d->east;
-    region2d->west = region3d->west;
-
-    region2d->rows = region3d->rows;
-    region2d->cols = region3d->cols;
-
-    region2d->ns_res = region3d->ns_res;
-    region2d->ew_res = region3d->ew_res;
-}
-
-/*!
- * \brief 
- *
- *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
- *
- *  \param region3d
- *  \param region2d
- *  \return void
- */
-
-void G3d_regionToCellHead(G3D_Region * region3d, struct Cell_head *region2d)
-{
-    region2d->proj = region3d->proj;
-    region2d->zone = region3d->zone;
-
-    region2d->north = region3d->north;
-    region2d->south = region3d->south;
-    region2d->east = region3d->east;
-    region2d->west = region3d->west;
-    region2d->top = region3d->top;
-    region2d->bottom = region3d->bottom;
-
-    region2d->rows = region3d->rows;
-    region2d->rows3 = region3d->rows;
-    region2d->cols = region3d->cols;
-    region2d->cols3 = region3d->cols;
-    region2d->depths = region3d->depths;
-
-    region2d->ns_res = region3d->ns_res;
-    region2d->ns_res3 = region3d->ns_res;
-    region2d->ew_res = region3d->ew_res;
-    region2d->ew_res3 = region3d->ew_res;
-    region2d->tb_res = region3d->tb_res;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Replaces the <em>2d</em> portion of <em>region3d</em> with the
- * values stored in <em>region2d</em>.
- *
- *  \param region2d
- *  \param region3d
- *  \return void
- */
-
-void
-G3d_incorporate2dRegion(struct Cell_head *region2d, G3D_Region * region3d)
-{
-    region3d->proj = region2d->proj;
-    region3d->zone = region2d->zone;
-
-    region3d->north = region2d->north;
-    region3d->south = region2d->south;
-    region3d->east = region2d->east;
-    region3d->west = region2d->west;
-
-    region3d->rows = region2d->rows;
-    region3d->cols = region2d->cols;
-
-    region3d->ns_res = region2d->ns_res;
-    region3d->ew_res = region2d->ew_res;
-}
-
-/*!
- * \brief 
- *
- * Replaces the <em>2d</em> portion of <em>region3d</em> with the
- * values stored in <em>region2d</em>.
- *
- *  \param region2d
- *  \param region3d
- *  \return void
- */
-
-void
-G3d_regionFromToCellHead(struct Cell_head *region2d, G3D_Region * region3d)
-{
-    region3d->proj = region2d->proj;
-    region3d->zone = region2d->zone;
-
-    region3d->north = region2d->north;
-    region3d->south = region2d->south;
-    region3d->east = region2d->east;
-    region3d->west = region2d->west;
-    region3d->top = region2d->top;
-    region3d->bottom = region2d->bottom;
-
-    region3d->rows = region2d->rows3;
-    region3d->cols = region2d->cols3;
-    region3d->depths = region2d->depths;
-
-    region3d->ns_res = region2d->ns_res3;
-    region3d->ew_res = region2d->ew_res3;
-    region3d->tb_res = region2d->tb_res;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Computes an adjusts the resolutions in the region structure from the region
- * boundaries and number of cells per dimension.
- *
- *  \param region
- *  \return void
- */
-
-void G3d_adjustRegion(G3D_Region * region)
-{
-    struct Cell_head region2d;
-
-    G3d_regionToCellHead(region, &region2d);
-    G_adjust_Cell_head3(&region2d, 1, 1, 1);
-    G3d_regionFromToCellHead(&region2d, region);
-
-    if (region->depths <= 0)
-	G3d_fatalError("G3d_adjustRegion: depths <= 0");
-    region->tb_res = (region->top - region->bottom) / region->depths;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Computes an adjusts the number of cells per dimension in the region
- * structure from the region boundaries and resolutions.
- *
- *  \param region
- *  \return void
- */
-
-void G3d_adjustRegionRes(G3D_Region * region)
-{
-    struct Cell_head region2d;
-
-    G3d_regionToCellHead(region, &region2d);
-    G_adjust_Cell_head3(&region2d, 1, 1, 1);
-    G3d_regionFromToCellHead(&region2d, region);
-
-    if (region->tb_res <= 0)
-	G3d_fatalError("G3d_adjustRegionRes: tb_res <= 0");
-
-    region->depths = (region->top - region->bottom + region->tb_res / 2.0) /
-	region->tb_res;
-    if (region->depths == 0)
-	region->depths = 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Copies the values of <em>regionSrc</em> into <em>regionDst</em>.
- *
- *  \param regionDest
- *  \param regionSrc
- *  \return void
- */
-
-void G3d_regionCopy(G3D_Region * regionDest, G3D_Region * regionSrc)
-{
-    *regionDest = *regionSrc;
-}
-
-
-/*---------------------------------------------------------------------------*/
-
-int
-G3d_readRegionMap(const char *name, const char *mapset, G3D_Region * region)
-{
-    char fullName[GPATH_MAX];
-    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
-    if (G_name_is_fully_qualified(name, xname, xmapset))
-	G3d_filename(fullName, G3D_HEADER_ELEMENT, xname, xmapset);
-    else {
-	if (!mapset || !*mapset)
-	    mapset = G_find_grid3(name, "");
-	G3d_filename(fullName, G3D_HEADER_ELEMENT, name, mapset);
-    }
-    return G3d_readWindow(region, fullName);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns 1 if region-coordinates <em>(north, west, bottom)</em> are
- * inside the region of <em>map</em>. Returns 0 otherwise.
- *
- *  \param REgion
- *  \param north
- *  \param east
- *  \param top
- *  \return int
- */
-
-int G3d_isValidLocation(G3D_Region *region, double north, double east, double top)
-{
-    return ((north >= region->south) && (north <= region->north) &&
-	    (east >= region->west) && (east <= region->east) &&
-	    (((top >= region->bottom) && (top <= region->top)) ||
-	     ((top <= region->bottom) && (top >= region->top))));
-}
-
-/*---------------------------------------------------------------------------*/
-
-/*!
- * \brief 
- *
- *  Converts region-coordinates <em>(north, east,
- *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
- *
- *  \param map
- *  \param north
- *  \param east
- *  \param top
- *  \param x
- *  \param y
- *  \param z
- *  \return void
- */
-
-void
-G3d_location2coord(G3D_Region *region, double north, double east, double top,
-		   int *x, int *y, int *z)
-{
-    double col, row, depth;
-    
-    col = (east - region->west) / (region->east -
-				      region->west) * (double)(region->cols);
-    row = (north - region->south) / (region->north -
-					region->south) * (double)(region->rows);
-    depth = (top - region->bottom) / (region->top -
-				       region->bottom) * (double)(region->depths);
-    
-    *x = (int)col;
-    /* Adjust row to start at the northern edge*/
-    *y = region->rows - (int)row - 1;
-    *z = (int)depth;
-        
-    G_debug(4, "G3d_location2coord x %i y %i z %i\n", *x, *y, *z);
-}
-
-
-/*!
- * \brief 
- *
- *  Converts region-coordinates <em>(north, east,
- *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
- *  This function calls G3d_fatalError in case location is not in window.
- *
- *  \param map
- *  \param north
- *  \param east
- *  \param top
- *  \param x
- *  \param y
- *  \param z
- *  \return void
- */
-
-void
-G3d_location2coord2(G3D_Region *region, double north, double east, double top,
-		   int *x, int *y, int *z)
-{
-    if (!G3d_isValidLocation(region, north, east, top))
-	G3d_fatalError("G3d_location2coord2: location not in region");
-
-    G3d_location2coord(region, north, east, top, x, y, z);
-}
-
-/*!
- * \brief 
- *
- *  Converts cell-coordinates <em>(x, y, z)</em> into region-coordinates 
- * <em>(north, east, top)</em>. 
- *
- *  * <b>Note:</b> x, y and z is a double:
- *  - x+0.0 will return the easting for the western edge of the column.
- *  - x+0.5 will return the easting for the center of the column.
- *  - x+1.0 will return the easting for the eastern edge of the column.
- * 
- *  - y+0.0 will return the northing for the northern edge of the row.
- *  - y+0.5 will return the northing for the center of the row.
- *  - y+1.0 will return the northing for the southern edge of the row.
- * 
- *  - z+0.0 will return the top for the lower edge of the depth.
- *  - z+0.5 will return the top for the center of the depth.
- *  - z+1.0 will return the top for the upper edge of the column.
- *
- * <b>Note:</b> The result is a <i>double</i>. Casting it to an
- * <i>int</i> will give the column, row and depth number.
- * 
- * 
- *  \param map
- *  \param x
- *  \param y
- *  \param z
- *  \param north
- *  \param east
- *  \param top
- *  \return void
- */
-
-void
-G3d_coord2location(G3D_Region * region, double x, double y, double z, double *north, double *east, double *top)
-{
-    *north = region->north - y * region->ns_res;
-    *east = region->west + x * region->ew_res;
-    *top = region->bottom + z * region->tb_res; 
-        
-    G_debug(4, "G3d_coord2location north %g east %g top %g\n", *north, *east, *top);
-}

Deleted: grass/trunk/lib/raster3d/g3dresample.c
===================================================================
--- grass/trunk/lib/raster3d/g3dresample.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dresample.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,100 +0,0 @@
-#include <stdio.h>
-#include <grass/gis.h>
-#include "G3d_intern.h"
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * The default resampling function which uses nearest
- * neighbor resampling. This method converts the window coordinates
- * x, y, and z into region coordinates and returned the nearest neighbor.
- *
- *  \param map
- *  \param col
- *  \param row
- *  \param depth
- *  \param value
- *  \param type
- *  \return void
- */
-
-void
-G3d_nearestNeighbor(G3D_Map * map, int x, int y, int z, void *value,
-		    int type)
-{
-    double north, east, top;
-    int row, col, depth;
-
-    /* convert (x, y, z) window coordinates into (north, east, top) */
-    G3d_coord2location(&(map->window), (double)x + 0.5, (double)y + 0.5, (double)z + 0.5, &north, &east, &top);
-
-    /* convert (north, east, top) into map region coordinates (row, col, depth) */
-    G3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
-
-    /* if (row, col, depth) outside map region return NULL value */
-    if ((row < 0) || (row >= map->region.rows) ||
-	(col < 0) || (col >= map->region.cols) ||
-	(depth < 0) || (depth >= map->region.depths)) {
-	G3d_setNullValue(value, 1, type);
-	return;
-    }
-    
-    /* Get the value from the map in map-region resolution */
-	G3d_getValueRegion(map, col, row, depth, value, type);
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Sets the resampling function to be used by
- * G3d_getValue () (cf.{g3d:G3d.getValue}). This function is defined
- * as follows:
- *
- *  \return void
- */
-
-void G3d_setResamplingFun(G3D_Map * map, void (*resampleFun) ())
-{
-    map->resampleFun = resampleFun;
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * 
- * Returns in <em>resampleFun</em> a pointer to the resampling function used by
- * <em>map</em>.
- *
- *  \return void
- */
-
-void G3d_getResamplingFun(G3D_Map * map, void (**resampleFun) ())
-{
-    *resampleFun = map->resampleFun;
-}
-
-/*--------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns
- * in <em>nnFunPtr</em> a pointer to G3d_nearestNeighbor () (cf.{g3d:G3d.nearestNeighbor}).
- *
- *  \return void
- */
-
-void G3d_getNearestNeighborFunPtr(void (**nnFunPtr) ())
-{
-    *nnFunPtr = G3d_nearestNeighbor;
-}

Deleted: grass/trunk/lib/raster3d/g3dvolume.c
===================================================================
--- grass/trunk/lib/raster3d/g3dvolume.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dvolume.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,267 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <grass/raster.h>
-#include <grass/G3d.h>
-
-/*---------------------------------------------------------------------------*/
-
-static int verifyVolumeVertices(map, v)
-
-     void *map;
-     double v[2][2][2][3];
-
-{
-    if (!(G3d_isValidLocation(map, v[0][0][0][0], v[0][0][0][1],
-			      v[0][0][0][2]) &&
-	  G3d_isValidLocation(map, v[0][0][1][0], v[0][0][1][1],
-			      v[0][0][1][2]) &&
-	  G3d_isValidLocation(map, v[0][1][0][0], v[0][1][0][1],
-			      v[0][1][0][2]) &&
-	  G3d_isValidLocation(map, v[0][1][1][0], v[0][1][1][1],
-			      v[0][1][1][2]) &&
-	  G3d_isValidLocation(map, v[1][0][0][0], v[1][0][0][1],
-			      v[1][0][0][2]) &&
-	  G3d_isValidLocation(map, v[1][0][1][0], v[1][0][1][1],
-			      v[1][0][1][2]) &&
-	  G3d_isValidLocation(map, v[1][1][0][0], v[1][1][0][1],
-			      v[1][1][0][2]) &&
-	  G3d_isValidLocation(map, v[1][1][1][0], v[1][1][1][1],
-			      v[1][1][1][2])))
-	G3d_fatalError("verifyCubeVertices: volume vertex out of range");
-    return 0;
-}
-
-
-/*---------------------------------------------------------------------------*/
-
-static int verifyVolumeEdges(nx, ny, nz)
-
-     int nx, ny, nz;
-
-{
-    if ((nx <= 0) || (ny <= 0) || (nz <= 0))
-	G3d_fatalError("verifyCubeEdges: Volume edge out of range");
-    return 0;
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_getVolumeA(void *map, double u[2][2][2][3], int nx, int ny, int nz,
-	       void *volumeBuf, int type)
-{
-    typedef double doubleArray[3];
-
-    doubleArray *u000, *u001, *u010, *u011;
-    doubleArray *u100, *u101, *u110, *u111;
-    double v00[3], v01[3], v10[3], v11[3];
-    double v0[3], v1[3];
-    double v[3];
-    double r, rp, s, sp, t, tp;
-    double dx, dy, dz;
-    int x, y, z, nxp, nyp, nzp;
-    double *doubleBuf;
-    float *floatBuf;
-
-    doubleBuf = (double *)volumeBuf;
-    floatBuf = (float *)volumeBuf;
-
-    verifyVolumeVertices(map, u);
-    verifyVolumeEdges(nx, ny, nz);
-
-    nxp = nx * 2 + 1;
-    nyp = ny * 2 + 1;
-    nzp = nz * 2 + 1;
-
-    u000 = (doubleArray *) u[0][0][0];
-    u001 = (doubleArray *) u[0][0][1];
-    u010 = (doubleArray *) u[0][1][0];
-    u011 = (doubleArray *) u[0][1][1];
-    u100 = (doubleArray *) u[1][0][0];
-    u101 = (doubleArray *) u[1][0][1];
-    u110 = (doubleArray *) u[1][1][0];
-    u111 = (doubleArray *) u[1][1][1];
-
-    for (dz = 1; dz < nzp; dz += 2) {
-	r = 1. - (rp = dz / nz / 2.);
-	v00[0] = r * (*u000)[0] + rp * (*u100)[0];
-	v00[1] = r * (*u000)[1] + rp * (*u100)[1];
-	v00[2] = r * (*u000)[2] + rp * (*u100)[2];
-
-	v01[0] = r * (*u001)[0] + rp * (*u101)[0];
-	v01[1] = r * (*u001)[1] + rp * (*u101)[1];
-	v01[2] = r * (*u001)[2] + rp * (*u101)[2];
-
-	v10[0] = r * (*u010)[0] + rp * (*u110)[0];
-	v10[1] = r * (*u010)[1] + rp * (*u110)[1];
-	v10[2] = r * (*u010)[2] + rp * (*u110)[2];
-
-	v11[0] = r * (*u011)[0] + rp * (*u111)[0];
-	v11[1] = r * (*u011)[1] + rp * (*u111)[1];
-	v11[2] = r * (*u011)[2] + rp * (*u111)[2];
-
-	for (dy = 1; dy < nyp; dy += 2) {
-	    s = 1. - (sp = dy / ny / 2.);
-	    v0[0] = s * v00[0] + sp * v10[0];
-	    v0[1] = s * v00[1] + sp * v10[1];
-	    v0[2] = s * v00[2] + sp * v10[2];
-
-	    v1[0] = s * v01[0] + sp * v11[0];
-	    v1[1] = s * v01[1] + sp * v11[1];
-	    v1[2] = s * v01[2] + sp * v11[2];
-
-	    for (dx = 1; dx < nxp; dx += 2) {
-		t = 1. - (tp = dx / nx / 2.);
-		v[0] = t * v0[0] + tp * v1[0];
-		v[1] = t * v0[1] + tp * v1[1];
-		v[2] = t * v0[2] + tp * v1[2];
-
-		G3d_location2coord2(map, v[0], v[1], v[2], &x, &y, &z);
-		/* DEBUG
-		   printf ("(%d %d %d) (%lf %lf %lf) (%d %d %d) %lf\n", 
-		   (int) dx / 2, (int) dy / 2, (int) dz / 2,
-		   v[0], v[1], v[2],
-		   x, y, z, 
-		   G3d_getDoubleRegion (map, x, y, z));
-		 */
-		if (type == DCELL_TYPE)
-		    *(doubleBuf + ((int)dz / 2) * nx * ny +
-		      ((int)dy / 2) * nx + (int)dx / 2) =
-G3d_getDoubleRegion(map, x, y, z);
-		else
-		    *(floatBuf + ((int)dz / 2) * nx * ny +
-		      ((int)dy / 2) * nx + (int)dx / 2) =
-G3d_getFloatRegion(map, x, y, z);
-	    }
-	}
-    }
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_getVolume(void *map,
-	      double originNorth, double originWest, double originBottom,
-	      double vxNorth, double vxWest, double vxBottom,
-	      double vyNorth, double vyWest, double vyBottom,
-	      double vzNorth, double vzWest, double vzBottom,
-	      int nx, int ny, int nz, void *volumeBuf, int type)
-{
-    double u[2][2][2][3];
-
-    u[0][0][0][0] = originNorth;
-    u[0][0][0][1] = originWest;
-    u[0][0][0][2] = originBottom;
-
-    u[0][0][1][0] = vxNorth;
-    u[0][0][1][1] = vxWest;
-    u[0][0][1][2] = vxBottom;
-
-    u[1][0][0][0] = vzNorth;
-    u[1][0][0][1] = vzWest;
-    u[1][0][0][2] = vzBottom;
-
-    u[1][0][1][0] = (u[0][0][1][0] - u[0][0][0][0]) + u[1][0][0][0];
-    u[1][0][1][1] = (u[0][0][1][1] - u[0][0][0][1]) + u[1][0][0][1];
-    u[1][0][1][2] = (u[0][0][1][2] - u[0][0][0][2]) + u[1][0][0][2];
-
-    u[0][1][0][0] = vyNorth;
-    u[0][1][0][1] = vyWest;
-    u[0][1][0][2] = vyBottom;
-
-    u[0][1][1][0] = (u[0][0][1][0] - u[0][0][0][0]) + u[0][1][0][0];
-    u[0][1][1][1] = (u[0][0][1][1] - u[0][0][0][1]) + u[0][1][0][1];
-    u[0][1][1][2] = (u[0][0][1][2] - u[0][0][0][2]) + u[0][1][0][2];
-
-    u[1][1][0][0] = (u[1][0][0][0] - u[0][0][0][0]) + u[0][1][0][0];
-    u[1][1][0][1] = (u[1][0][0][1] - u[0][0][0][1]) + u[0][1][0][1];
-    u[1][1][0][2] = (u[1][0][0][2] - u[0][0][0][2]) + u[0][1][0][2];
-
-    u[1][1][1][0] = (u[1][0][0][0] - u[0][0][0][0]) + u[0][1][1][0];
-    u[1][1][1][1] = (u[1][0][0][1] - u[0][0][0][1]) + u[0][1][1][1];
-    u[1][1][1][2] = (u[1][0][0][2] - u[0][0][0][2]) + u[0][1][1][2];
-
-    G3d_getVolumeA(map, u, nx, ny, nz, volumeBuf, type);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_getAlignedVolume(void *map,
-		     double originNorth, double originWest,
-		     double originBottom, double lengthNorth,
-		     double lengthWest, double lengthBottom, int nx, int ny,
-		     int nz, void *volumeBuf, int type)
-{
-    G3d_getVolume(map,
-		  originNorth, originWest, originBottom,
-		  originNorth + lengthNorth, originWest, originBottom,
-		  originNorth, originWest + lengthWest, originBottom,
-		  originNorth, originWest, originBottom + lengthBottom,
-		  nx, ny, nz, volumeBuf, type);
-}
-
-/*---------------------------------------------------------------------------*/
-
-void
-G3d_makeAlignedVolumeFile(void *map, const char *fileName,
-			  double originNorth, double originWest,
-			  double originBottom, double lengthNorth,
-			  double lengthWest, double lengthBottom, int nx,
-			  int ny, int nz)
-{
-    void *volumeBuf;
-    void *mapVolume;
-    int x, y, z, eltLength;
-    G3D_Region region;
-
-    volumeBuf = G3d_malloc(nx * ny * nz * sizeof(G3d_getFileType()));
-    if (volumeBuf == NULL)
-	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_malloc");
-
-    G3d_getAlignedVolume(map,
-			 originNorth, originWest, originBottom,
-			 lengthNorth, lengthWest, lengthBottom,
-			 nx, ny, nz, volumeBuf, G3d_getFileType());
-
-    region.north = originNorth;
-    region.south = originNorth + lengthNorth;
-    region.east = originWest;
-    region.west = originWest + lengthWest;
-    region.top = originBottom;
-    region.bottom = originBottom + lengthBottom;
-
-    region.rows = ny;
-    region.cols = nx;
-    region.depths = nz;
-
-    mapVolume = G3d_openCellNew(fileName, G3d_getFileType(),
-				G3D_USE_CACHE_DEFAULT, &region);
-    if (mapVolume == NULL)
-	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_openCellNew");
-
-    eltLength = G3d_length(G3d_getFileType());
-
-    for (z = 0; z < nz; z++) {
-	for (y = 0; y < ny; y++) {
-	    for (x = 0; x < nx; x++) {
-		/* G3d_putValueRegion? */
-		if (!G3d_putValue(mapVolume, x, y, z,
-				  G_incr_void_ptr(volumeBuf,
-						  (z * ny * nx + y * nx +
-						   x) * eltLength),
-				  G3d_fileTypeMap(mapVolume)))
-		    G3d_fatalError
-			("G3d_makeAlignedVolumeFile: error in G3d_putValue");
-	    }
-	}
-    }
-
-    if (!G3d_closeCell(mapVolume))
-	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_closeCell");
-
-    G3d_free(volumeBuf);
-}

Deleted: grass/trunk/lib/raster3d/g3dwindow.c
===================================================================
--- grass/trunk/lib/raster3d/g3dwindow.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dwindow.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,96 +0,0 @@
-#include <stdio.h>
-#include <grass/gis.h>
-#include <grass/G3d.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-G3D_Region g3d_window;
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Sets the window for <em>map</em> to <em>window</em>.
- * Can be used multiple times for the same map.
- *
- *  \param map
- *  \param window
- *  \return void
- */
-
-void G3d_setWindowMap(G3D_Map * map, G3D_Region * window)
-{
-    G3d_regionCopy(&(map->window), window);
-    G3d_adjustRegion(&(map->window));
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Sets the default window used for every map opened later in the program.
- * Can be used multiple times in the same program.
- *
- *  \param window
- *  \return void
- */
-
-void G3d_setWindow(G3D_Region * window)
-{
-    G3d_regionCopy(&g3d_window, window);
-    G3d_adjustRegion(&g3d_window);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Stores the current default window in <em>window</em>.
- *
- *  \param window
- *  \return void
- */
-
-void G3d_getWindow(G3D_Region * window)
-{
-    G3d_regionCopy(window, &g3d_window);
-}
-
-/*---------------------------------------------------------------------------*/
-
-G3D_Region *G3d_windowPtr()
-{
-    return &g3d_window;
-}
-
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Returns 1 if window-coordinates <em>(north, west, bottom)</em> are
- * inside the window of <em>map</em>. Returns 0 otherwise.
- *
- *  \param map
- *  \param north
- *  \param east
- *  \param top
- *  \return int
- */
-
-int G3d_isValidLocationWindow(G3D_Map * map, double north, double east, double top)
-{
-    return ((north >= map->window.south) && (north <= map->window.north) &&
-	    (east >= map->window.west) && (east <= map->window.east) &&
-	    (((top >= map->window.bottom) && (top <= map->window.top)) ||
-	     ((top <= map->window.bottom) && (top >= map->window.top))));
-}

Deleted: grass/trunk/lib/raster3d/g3dwindowio.c
===================================================================
--- grass/trunk/lib/raster3d/g3dwindowio.c	2011-08-10 16:34:05 UTC (rev 47531)
+++ grass/trunk/lib/raster3d/g3dwindowio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -1,279 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <string.h>
-#include <grass/gis.h>
-#include "G3d_intern.h"
-
-/*---------------------------------------------------------------------------*/
-
-static int
-G3d_readWriteWindow(struct Key_Value *windowKeys, int doRead, int *proj,
-		    int *zone, double *north, double *south, double *east,
-		    double *west, double *top, double *bottom, int *rows,
-		    int *cols, int *depths, double *ew_res, double *ns_res,
-		    double *tb_res)
-{
-    int returnVal;
-    int (*windowInt) (), (*windowDouble) ();
-
-    if (doRead) {
-	windowDouble = G3d_keyGetDouble;
-	windowInt = G3d_keyGetInt;
-    }
-    else {
-	windowDouble = G3d_keySetDouble;
-	windowInt = G3d_keySetInt;
-    }
-
-    returnVal = 1;
-    returnVal &= windowInt(windowKeys, G3D_REGION_PROJ, proj);
-    returnVal &= windowInt(windowKeys, G3D_REGION_ZONE, zone);
-
-    returnVal &= windowDouble(windowKeys, G3D_REGION_NORTH, north);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_SOUTH, south);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_EAST, east);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_WEST, west);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_TOP, top);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_BOTTOM, bottom);
-
-    returnVal &= windowInt(windowKeys, G3D_REGION_ROWS, rows);
-    returnVal &= windowInt(windowKeys, G3D_REGION_COLS, cols);
-    returnVal &= windowInt(windowKeys, G3D_REGION_DEPTHS, depths);
-
-    returnVal &= windowDouble(windowKeys, G3D_REGION_EWRES, ew_res);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_NSRES, ns_res);
-    returnVal &= windowDouble(windowKeys, G3D_REGION_TBRES, tb_res);
-
-    if (returnVal)
-	return 1;
-
-    G3d_error("G3d_readWriteWindow: error writing window");
-    return 0;
-}
-
-/*
- * If windowName == NULL -> G3D_WINDOW_ELEMENT ("$MAPSET/WIND3")
- * otherwise G3D_WINDOW_DATABASE ("$MAPSET/windows3d/$NAME")
- */
-static void G3d_getFullWindowPath(char *path, const char *windowName)
-{
-    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
-    if (windowName == NULL) {
-	G_file_name(path, "", G3D_WINDOW_ELEMENT, G_mapset());
-	return;
-    }
-
-    while (*windowName == ' ')
-	windowName++;
-
-    if ((*windowName == '/') || (*windowName == '.')) {
-	sprintf(path, windowName);
-	return;
-    }
-
-    if (G_name_is_fully_qualified(windowName, xname, xmapset)) {
-	G_file_name(path, G3D_WINDOW_DATABASE, xname, xmapset);
-	return;
-    }
-
-    G_file_name(path, G3D_WINDOW_DATABASE, windowName, G_mapset());
-}
-
-/*---------------------------------------------------------------------------*/
-/*
-   static void
-   G3d_getWindowLocation (path, windowName)
-
-   char path[1024];
-   char *windowName;
-
-   {
-   char xname[512], xmapset[512];
-   char *p, *slash;
-
-   if (windowName == NULL) {
-   G_file_name (path, "", "", G_mapset ());
-   return;
-   }
-
-   while (*windowName == ' ') windowName++;
-
-   if ((*windowName != '/') && (*windowName != '.')) {
-   if (G_name_is_fully_qualified (windowName, xname, xmapset)) 
-   G_file_name (path, G3D_WINDOW_DATABASE, xname, xmapset);
-   else
-   G_file_name (path, G3D_WINDOW_DATABASE, windowName, G_mapset ());
-   } else
-   sprintf (path, windowName);
-   p = path;
-   slash = NULL;
-   while (*p != 0) {
-   if (*p == '/') slash = p;
-   p++;
-   }
-   if (slash != NULL) *slash = 0;
-   }
- */
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Reads
- * <em>window</em> from the file specified by <em>windowName</em>. The name is
- * converted by the rules defined in window defaults. A NULL pointer indicates
- * the <em>WIND3</em> file in the current mapset.
- *
- *  \param window
- *  \param windowName
- *  \return 1 ... if successful
- *          0 ... otherwise.
- */
-
-int G3d_readWindow(G3D_Region * window, const char *windowName)
-{
-    struct Cell_head win;
-    struct Key_Value *windowKeys;
-    char path[GPATH_MAX];
-
-
-    if (windowName == NULL) {
-	G_get_window(&win);
-
-	window->proj = win.proj;
-	window->zone = win.zone;
-	window->north = win.north;
-	window->south = win.south;
-	window->east = win.east;
-	window->west = win.west;
-	window->top = win.top;
-	window->bottom = win.bottom;
-	window->rows = win.rows3;
-	window->cols = win.cols3;
-	window->depths = win.depths;
-	window->ns_res = win.ns_res3;
-	window->ew_res = win.ew_res3;
-	window->tb_res = win.tb_res;
-    }
-    else {
-	G3d_getFullWindowPath(path, windowName);
-
-	if (access(path, R_OK) != 0) {
-	    G_warning("G3d_readWindow: unable to find [%s].", path);
-	    return 0;
-	}
-
-	windowKeys = G_read_key_value_file(path);
-
-	if (!G3d_readWriteWindow(windowKeys, 1,
-				 &(window->proj), &(window->zone),
-				 &(window->north), &(window->south),
-				 &(window->east), &(window->west),
-				 &(window->top), &(window->bottom),
-				 &(window->rows), &(window->cols),
-				 &(window->depths), &(window->ew_res),
-				 &(window->ns_res), &(window->tb_res))) {
-	    G3d_error
-		("G3d_readWindow: error extracting window key(s) of file %s",
-		 path);
-	    return 0;
-	}
-
-	G_free_key_value(windowKeys);
-    }
-
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-/* modified version of G__make_mapset_element */
-/*
-   static int
-   G3d_createPath (thePath)
-
-   char *thePath;
-
-   {
-   char command[1024];
-   char *path, *p, *pOld;
-
-   if (*thePath == 0) return 0;
-
-   strcpy (path = command, "mkdir ");
-   while (*path) path++;
-   p = path;
- */
-  /* now append element, one directory at a time, to path */
-/*
-   while (1) {
-   if (*thePath == '/') *p++ = *thePath++;
-   pOld = p;
-   while ((*thePath) && (*thePath != '/')) *p++ = *thePath++;
-   *p = 0;
-
-   if (p == pOld) return 1;
-
-   if (access (path, 0) != 0) mkdir (path,0777);
-   if (access (path, 0) != 0) system (command);
-   if (access (path, 0) != 0) {
-   char err[1024];
-   sprintf (err, "can't make mapset element %s (%s)", thePath, path);
-   G_fatal_error (err);
-   exit(1);
-   }
-   }
-   }
- */
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * 
- * Writes <em>window</em> to the file specified by <em>windowName</em>. The name
- * is converted by the rules defined in window defaults. A NULL pointer
- * indicates the <em>WIND3</em> file in the current mapset.
- *
- *  \param window
- *  \param windowName
- *  \return 1 ... if successful
- *          0 ... otherwise.
- */
-
-/*
-   int
-   G3d_writeWindow (window, windowName)
-
-   G3D_Region *window;
-   char *windowName;
-
-   {
-   return 0;
-   }
- */
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- * Allows the window to be set at run-time via the <em>region3</em>
- * command line argument. This function has to be called before
- * <em>G_parser ()</em>. See also window defaults.
- *
- *  \return void
- */
-
-void G3d_useWindowParams(void)
-{
-    G3d_setWindowParams();
-}

Copied: grass/trunk/lib/raster3d/getvalue.c (from rev 47531, grass/trunk/lib/raster3d/g3dgetvalue.c)
===================================================================
--- grass/trunk/lib/raster3d/getvalue.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/getvalue.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,245 @@
+#include <grass/raster.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Returns in <em>*value</em> the resampled cell-value of the cell with
+ * window-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
+ * This function invokes a fatal error if an error occurs.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void G3d_getValue(G3D_Map * map, int x, int y, int z, void *value, int type)
+{
+    /* get the resampled value */
+    map->resampleFun(map, x, y, z, value, type);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Is equivalent to
+ * <tt>G3d_getValue (map, x, y, z, &value, FCELL_TYPE);</tt> return value.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return float
+ */
+
+float G3d_getFloat(G3D_Map * map, int x, int y, int z)
+{
+    float value;
+
+    G3d_getValue(map, x, y, z, &value, FCELL_TYPE);
+    return value;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Is equivalent
+ * to <tt>G3d_getValue (map, x, y, z, &value, DCELL_TYPE);</tt> return value.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return double
+ */
+
+double G3d_getDouble(G3D_Map * map, int x, int y, int z)
+{
+    double value;
+
+    G3d_getValue(map, x, y, z, &value, DCELL_TYPE);
+    return value;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
+ * window coordinates <em>(north, east, top)</em>.  The
+ * value is resampled using the resampling function specified for <em>map</em>. The
+ * <em>value</em> is of <em>type</em>.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void
+G3d_getWindowValue(G3D_Map * map, double north, double east, double top,
+		   void *value, int type)
+{
+    int col, row, depth;
+
+    G3d_location2coord(&(map->window), north, east, top, &col, &row, &depth);
+
+    /* if (row, col, depth) outside window return NULL value */
+    if ((row < 0) || (row >= map->window.rows) ||
+	(col < 0) || (col >= map->window.cols) ||
+	(depth < 0) || (depth >= map->window.depths)) {
+	G3d_setNullValue(value, 1, type);
+	return;
+    }
+
+    /* Get the value from the map in map-region resolution */
+	map->resampleFun(map, col, row, depth, value, type);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
+ * region coordinates <em>(north, east, top)</em>.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void
+G3d_getRegionValue(G3D_Map * map, double north, double east, double top,
+		   void *value, int type)
+{
+    int row, col, depth;
+
+    G3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
+
+    /* if (row, col, depth) outside region return NULL value */
+    if ((row < 0) || (row >= map->region.rows) ||
+	(col < 0) || (col >= map->region.cols) ||
+	(depth < 0) || (depth >= map->region.depths)) {
+	G3d_setNullValue(value, 1, type);
+	return;
+    }
+
+    /* Get the value from the map in map-region resolution */
+	G3d_getValueRegion(map, col, row, depth, value, type);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Is equivalent to <tt>G3d_getValueRegion (map, x, y, z, &value, FCELL_TYPE);</tt>
+ * return value.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return float
+ */
+
+float G3d_getFloatRegion(G3D_Map * map, int x, int y, int z)
+{
+    int tileIndex, offs;
+    float *tile;
+
+    if (map->typeIntern == DCELL_TYPE)
+	return (float)G3d_getDoubleRegion(map, x, y, z);
+
+    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
+    tile = (float *)G3d_getTilePtr(map, tileIndex);
+
+    if (tile == NULL)
+	G3d_fatalError("G3d_getFloatRegion: error in G3d_getTilePtr");
+
+    return tile[offs];
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Is equivalent to <tt>G3d_getValueRegion (map, x, y, z, &value,
+ * DCELL_TYPE);</tt> return value.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return double
+ */
+
+double G3d_getDoubleRegion(G3D_Map * map, int x, int y, int z)
+{
+    int tileIndex, offs;
+    double *tile;
+
+    if (map->typeIntern == FCELL_TYPE)
+	return (double)G3d_getFloatRegion(map, x, y, z);
+
+    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
+    tile = (double *)G3d_getTilePtr(map, tileIndex);
+
+    if (tile == NULL)
+	G3d_fatalError("G3d_getDoubleRegion: error in G3d_getTilePtr");
+
+    return tile[offs];
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Returns in <em>*value</em> the cell-value of the cell with
+ * region-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
+ * Here <em>region</em> means the coordinate in the cube of data in the file, i.e.
+ * ignoring geographic coordinates.
+ * This function invokes a fatal error if an error occurs.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void
+G3d_getValueRegion(G3D_Map * map, int x, int y, int z, void *value, int type)
+{
+    if (type == FCELL_TYPE) {
+	*((float *)value) = G3d_getFloatRegion(map, x, y, z);
+	return;
+    }
+
+    *((double *)value) = G3d_getDoubleRegion(map, x, y, z);
+}

Copied: grass/trunk/lib/raster3d/history.c (from rev 47531, grass/trunk/lib/raster3d/g3dhistory.c)
===================================================================
--- grass/trunk/lib/raster3d/history.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/history.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,106 @@
+
+/**********************************************************************
+ *
+ *  G3d_readHistory (name, mapset, hist)
+ *      char *name                   name of map
+ *      char *mapset                 mapset that map belongs to
+ *      struct History *hist        structure to hold history info
+ *
+ *  Reads the history information associated with map layer "map"
+ *  in mapset "mapset" into the structure "hist".
+ *
+ *   returns:    0  if successful
+ *              -1  on fail
+ *
+ *  note:   a warning message is printed if the file is incorrect
+ *
+ **********************************************************************
+ *
+ *  G3d_writeHistory (name, hist)
+ *      char *name                   name of map
+ *      struct History *hist        structure holding history info
+ *
+ *  Writes the history information associated with map layer "map"
+ *  into current from the structure "hist".
+ *
+ *   returns:    0  if successful
+ *              -1  on fail
+ **********************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <grass/glocale.h>
+#include "G3d_intern.h"
+#include <grass/raster.h>
+
+/*simple error message */
+void SimpleErrorMessage(FILE * fd, const char *name, const char *mapset)
+{
+    if (fd != NULL)
+	fclose(fd);
+
+    G_warning(_("can't get history information for [%s] in mapset [%s]"),
+	      name, mapset);
+    return;
+}
+
+/*!
+ * \brief read raster3d History file
+ *
+ * This routine reads the History file for
+ * the raster3d file <b>name</b> in <b>mapset</b> into the <b>History</b>
+ * structure.
+ * A diagnostic message is printed and -1 is returned if there is an error
+ * reading the History file. Otherwise, 0 is returned.
+ * A warning message is printed if the file is incorrect.
+ *
+ *  \param name
+ *  \param mapset
+ *  \param history
+ *  \return int
+ */
+
+int G3d_readHistory(const char *name, const char *mapset, struct History *hist)
+{
+    FILE *fp;
+
+    G_zero(hist, sizeof(struct History));
+
+    fp = G_fopen_old_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name, mapset);
+    if (!fp)
+	return -2;
+
+    if (Rast__read_history(hist, fp) == 0)
+	return 0;
+
+    SimpleErrorMessage(fp, name, mapset);
+    return -1;
+}
+
+
+/*!
+ * \brief write raster3d History file
+ *
+ * This routine writes the History file for the raster3d file
+ * <b>name</b> in the current mapset from the <b>History</b> structure.
+ * A diagnostic message is printed and -1 is returned if there is an error
+ * writing the History file. Otherwise, 0 is returned.
+ * <b>Note.</b> The <b>history</b> structure should first be initialized
+ * using <i>Rast_short_history.</i>
+ *
+ *  \param name
+ *  \param history
+ *  \return int
+ */
+
+int G3d_writeHistory(const char *name, struct History *hist)
+/* This function is adapted from Rast_write_history */
+{
+    FILE *fp = G_fopen_new_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name);
+    if (!fp)
+	return -1;
+
+    Rast__write_history(hist, fp);
+    return 0;
+}

Copied: grass/trunk/lib/raster3d/intio.c (from rev 47531, grass/trunk/lib/raster3d/g3dintio.c)
===================================================================
--- grass/trunk/lib/raster3d/intio.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/intio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,121 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_writeInts(int fd, int useXdr, const int *i, int nofNum)
+{
+    int firstTime = 1;
+    XDR xdrEncodeStream;
+    char xdrIntBuf[G3D_XDR_INT_LENGTH * 1024];
+    u_int n;
+
+    if (nofNum <= 0)
+	G3d_fatalError("G3d_writeInts: nofNum out of range");
+
+    if (useXdr == G3D_NO_XDR) {
+	if (write(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
+	    G3d_error("G3d_writeInts: writing to file failed");
+	    return 0;
+	}
+	else {
+	    return 1;
+	}
+    }
+
+    if (firstTime) {
+	xdrmem_create(&xdrEncodeStream, xdrIntBuf, G3D_XDR_INT_LENGTH * 1024,
+		      XDR_ENCODE);
+	firstTime = 1;
+    }
+
+    do {
+	n = nofNum % 1024;
+	if (n == 0)
+	    n = 1024;
+
+	if (!xdr_setpos(&xdrEncodeStream, 0)) {
+	    G3d_error("G3d_writeInts: positioning xdr failed");
+	    return 0;
+	}
+
+	if (!xdr_vector(&xdrEncodeStream, (char *)i, n, sizeof(int),
+			(xdrproc_t) xdr_int)) {
+	    G3d_error("G3d_writeInts: writing xdr failed");
+	    return 0;
+	}
+
+	if (write(fd, xdrIntBuf, G3D_XDR_INT_LENGTH * n) !=
+	    G3D_XDR_INT_LENGTH * n) {
+	    G3d_error("G3d_writeInts: writing xdr to file failed");
+	    return 0;
+	}
+
+	nofNum -= n;
+	i += n;
+    } while (nofNum);
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_readInts(int fd, int useXdr, int *i, int nofNum)
+{
+    int firstTime = 1;
+    XDR xdrDecodeStream;
+    char xdrIntBuf[G3D_XDR_INT_LENGTH * 1024];
+    u_int n;
+
+    if (nofNum <= 0)
+	G3d_fatalError("G3d_readInts: nofNum out of range");
+
+    if (useXdr == G3D_NO_XDR) {
+	if (read(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
+	    G3d_error("G3d_readInts: reading from file failed");
+	    return 0;
+	}
+	else {
+	    return 1;
+	}
+    }
+
+    if (firstTime) {
+	xdrmem_create(&xdrDecodeStream, xdrIntBuf, G3D_XDR_INT_LENGTH * 1024,
+		      XDR_DECODE);
+	firstTime = 1;
+    }
+
+    do {
+	n = nofNum % 1024;
+	if (n == 0)
+	    n = 1024;
+
+	if (read(fd, xdrIntBuf, G3D_XDR_INT_LENGTH * n) !=
+	    G3D_XDR_INT_LENGTH * n) {
+	    G3d_error("G3d_readInts: reading xdr from file failed");
+	    return 0;
+	}
+
+	if (!xdr_setpos(&xdrDecodeStream, 0)) {
+	    G3d_error("G3d_readInts: positioning xdr failed");
+	    return 0;
+	}
+
+	if (!xdr_vector(&xdrDecodeStream, (char *)i, n, sizeof(int),
+			(xdrproc_t) xdr_int)) {
+	    G3d_error("G3d_readInts: reading xdr failed");
+	    return 0;
+	}
+
+	nofNum -= n;
+	i += n;
+    } while (nofNum);
+
+    return 1;
+}

Copied: grass/trunk/lib/raster3d/keys.c (from rev 47531, grass/trunk/lib/raster3d/g3dkeys.c)
===================================================================
--- grass/trunk/lib/raster3d/keys.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/keys.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,140 @@
+#include <stdio.h>
+#include <string.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_keyGetInt(struct Key_Value *keys, const char *key, int *i)
+{
+    const char *str;
+
+    if ((str = G_find_key_value(key, keys)) == NULL) {
+	G3d_error("G3d_keyGetInt: cannot find field %s in key structure",
+		  key);
+	return 0;
+    }
+
+    if (sscanf(str, "%d", i) == 1)
+	return 1;
+
+    G3d_error("G3d_keyGetInt: invalid value: field %s in key structure", key);
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_keyGetDouble(struct Key_Value *keys, const char *key, double *d)
+{
+    const char *str;
+
+    if ((str = G_find_key_value(key, keys)) == NULL) {
+	G3d_error("G3d_keyGetDouble: cannot find field %s in key structure",
+		  key);
+	return 0;
+    }
+
+    if (sscanf(str, "%lf", d) == 1)
+	return 1;
+
+    G3d_error("G3d_keyGetDouble: invalid value: field %s in key structure",
+	      key);
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_keyGetString(struct Key_Value *keys, const char *key, char **returnStr)
+{
+    const char *str;
+
+    if ((str = G_find_key_value(key, keys)) == NULL) {
+	G3d_error("G3d_keyGetString: cannot find field %s in key structure",
+		  key);
+	return 0;
+    }
+
+    *returnStr = G_store(str);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_keyGetValue(struct Key_Value *keys, const char *key, char *val1,
+		char *val2, int result1, int result2, int *resultVar)
+{
+    const char *str;
+
+    if ((str = G_find_key_value(key, keys)) == NULL) {
+	G3d_error("G3d_keyGetValue: cannot find field %s in key structure",
+		  key);
+	return 0;
+    }
+
+    if (strcmp(str, val1) == 0) {
+	*resultVar = result1;
+	return 1;
+    }
+    if (strcmp(str, val2) == 0) {
+	*resultVar = result2;
+	return 1;
+    }
+
+    G3d_error("G3d_keyGetValue: invalid type: field %s in key structure",
+	      key);
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_keySetInt(struct Key_Value *keys, const char *key, const int *i)
+{
+    char keyValStr[200];
+
+    sprintf(keyValStr, "%d", *i);
+    G_set_key_value(key, keyValStr, keys);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_keySetDouble(struct Key_Value *keys, const char *key, const double *d)
+{
+    char keyValStr[200];
+
+    sprintf(keyValStr, "%.50f", *d);
+    G_set_key_value(key, keyValStr, keys);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_keySetString(struct Key_Value *keys, const char *key,
+		 char *const *keyValStr)
+{
+    G_set_key_value(key, *keyValStr, keys);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_keySetValue(struct Key_Value *keys, const char *key, const char *val1,
+		const char *val2, int keyval1, int keyval2,
+		const int *keyvalVar)
+{
+    if (*keyvalVar == keyval1) {
+	G_set_key_value(key, val1, keys);
+	return 1;
+    }
+
+    if (*keyvalVar == keyval2) {
+	G_set_key_value(key, val2, keys);
+	return 1;
+    }
+
+    G3d_error("G3d_keySetValue: wrong key value");
+    return 0;
+}

Copied: grass/trunk/lib/raster3d/lib.dox (from rev 47531, grass/trunk/lib/raster3d/g3dlib.dox)
===================================================================
--- grass/trunk/lib/raster3d/lib.dox	                        (rev 0)
+++ grass/trunk/lib/raster3d/lib.dox	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,1758 @@
+/*! \page g3dlib GRASS Grid3D raster volume Library
+<!-- doxygenized from "GRASS 5 Programmer's Manual" 
+     by M. Neteler 5/2004, 8/2005
+  -->
+
+\section g3dintro Grid3D raster volume Library
+
+
+<P>
+Authors: Roman Waupotitsch and Michael Shapiro, Helena Mitasova, 
+         Bill Brown, Lubos Mitas, Jaro Hofierka, 
+         Minor modification, code cleanup and test suite by Soeren Gebbert
+         
+
+
+<b>Overview</b>
+
+The Grid3D raster volume Library is used for the r3.* and vector
+volume tools. The G3D library uses a tile cache based approach to store floating point
+ values in abritrary order in a volume. The coordinate system of a volume is 
+column and row compatible to the raster library and counts from the bottom to the top
+of the cube.
+
+<center>
+<img src=g3d_volume_layout.png border=0><BR>
+<table border=0 width=700>
+<tr><td><center>
+<i>The volume coordinate system and tile layout of the G3D library</i>
+</center></td></tr>
+</table>
+</center>
+
+
+\section Directory_Structure Directory Structure
+
+<P>
+The file format consists of a mapset element <EM>grid3</EM> which contains a
+directory for every map. The elements for each map are
+
+<P>
+\verbatim 
+        3d region file
+        color file (color)
+        categories file (cats)
+        range file (range)
+        timestamp file /* not yet implemented */
+        cell file (cell)
+        header file (cellhd)
+        a directory containing display files (dsp)
+\endverbatim 
+
+<P>
+There is also a <EM>colr2</EM> mechanism provided. <EM>colr2</EM> color tables
+are stored in <EM>grid3/colr2/MAPSET/MAP</EM>.
+
+<P>
+Note: color, categories, and the range can be used in the same way as in <EM>2d</EM> 
+GRASS with the exception of reading and writng. <EM>3d</EM> read and write
+functions have to be used for this purpose.
+
+
+\section Data_File_Format Data File Format
+
+
+<UL>
+<LI>Cell-values can be either double or float.
+</LI>
+<LI>Values are written in XDR-format.
+</LI>
+<LI>NULL-values are stored in an embedded fashion.
+</LI>
+<LI>The cell-values are organized in <EM>3d</EM>-tiles.
+</LI>
+<LI>The tile dimensions can be chosen when a new map is opened.
+</LI>
+<LI>Every tile of a map has the same dimension except those which overlap the
+  region boundaries.
+</LI>
+<LI>Compression is used to store tiles.
+</LI>
+</UL>
+
+<P>
+The data file has the following format:
+
+<P>
+\verbatim 
+        xdr_int nofBytesLong;
+        xdr_int nofBytesUsed;
+        encoded_long indexOffset;
+        compressed_tile[] tiles;
+        compressed_encoded_long[] index;
+\endverbatim 
+
+<P>
+
+\section Transportability_of_data_file Transportability of data file
+
+<P>
+All numbers stored in the data file are either XDR-encoded or encoded by some
+other method (for variables of type long only).
+
+<P>
+
+\section Tile_Data_NULL_values Tile Data NULL-values
+
+<P>
+G3D uses the same functions as <EM>2d</EM> GRASS to set and test NULL-values.  The
+storage in the file is different though.  NULL-values are stored with a special
+bit-pattern if maximum precision is chosen.  They are stored by adding an
+additional bit if the precision is smaller.
+
+<P>
+
+\section Tile_Data_Compression Tile Data Compression
+
+<P>
+There are three methods of compression provided. The compression
+methods can either be those defined by default, set by environment
+variables or explicitly set at run-time.
+
+\verbatim 
+        Precision
+        RLE
+\endverbatim 
+
+<P>
+Precision indicates how many of the mantissa bits should be stored on
+file. This number can be any value between 0 and 23 for floats and
+between 0 and 52 for doubles. Choosing a small precision is the most
+effective way to achieve good compression.
+
+<P>
+RLE takes advantage of possible repetitions of the
+exponents and the NULL-bit structure. Using RLE does not significantly
+increase the running time. If for some tile the non-RLEed version is
+smaller in size, RLE is not used for this tile.
+
+<P>
+The default and suggested setting is to use precision and RLE. 
+
+<P>
+Additional compression is achieved by storing the extra NULL-bit in a
+separate bit-array. Using this scheme NULL-values need not actually be
+represented in the array of cell values. This array is stored together
+with the cell-values of the tile.
+
+
+\section Tile_Cache Tile Cache 
+
+<P>
+Tiles can either be read and written directly or use an intermediate
+cache instead.
+
+<P>
+In non-cache mode the application should only use the functions
+
+<P>
+int G3d_readTile() 
+
+<P>
+and 
+
+<P>
+int G3d_writeTile() 
+
+<P>
+to read and write tiles.  The application can use one tile provided by the map
+structure as buffer. See <TT>G3d_getTilePtr()</TT>.
+
+<P>
+In cache mode the application can access cell-values directly by their
+coordinates. The corresponding functions are
+
+<P>
+int G3d_getValue() 
+
+<P>
+and
+
+<P>
+int G3d_putValue() 
+
+<P>
+and their corresponding typed versions.
+<BR>
+<P>
+If the map is new then in addition to the memory-cache a file-cache is provided.
+This allows the application to write the cell-values in any arbitrary order.
+Tiles are written (flushed) to the data-file either at closing time or if
+explicitly requested.
+<BR>
+<P>
+If the map is new <TT>G3d_getValue()</TT> can be used even if the tile which
+contains the cell has already been flushed to the data file. In this case the
+tile is simply read back into the memory-cache from the data file.
+<BR>
+<P>
+Explicitly flushing tiles can have the advantage that less disk space is
+occupied since tiles are stored in a uncompressed fashion in the file-cache.
+Flushing tiles explicitly can cause problems with accuracy though if precision
+is less than the maximum precision and an already flushed value is used for
+computations later in the program.
+<BR>
+<P>
+The type of the cell-values of the tiles in memory can be chosen independently
+of the type of the tiles in the file. Here, once again one has to consider
+possible problems arising from mixing different precisions.
+<BR>
+<P>
+As an example consider the case where the data is stored in the file with double
+precision and the tiles are stored in memory in single precision.  Then using
+<TT>G3d_getValue()</TT> will actually return a double precision number whose precision
+is only 23 bits.  It is therefore a good idea to use the types in the memory
+consistently.
+<BR>
+<P>
+
+\section Header_File Header File
+
+<P>
+The header file has the following format:
+
+<P>
+\verbatim 
+Proj: 1
+Zone: 1
+North: 2.0000000000000
+South: 0.5000000000000
+East: 4.0000000000000
+West: 3.0000000000000
+Top: 6.0000000000000
+Bottom: 5.0000000000000
+nofRows: 30
+nofCols: 20
+nofDepths: 14
+e-w resol: 0.05
+n-s resol: 0.05
+t-b resol: 0.071428571
+TileDimensionX: 8
+TileDimensionY: 8
+TileDimensionZ: 8
+CellType: double
+useCompression: 1
+useRle: 1
+Precision: -1
+nofHeaderBytes: 12
+useXdr: 1
+hasIndex: 1
+Units: none
+\endverbatim
+
+<P>
+Except for the first 14 fields the entries of the header file should
+not be modified. The precision value -1 indicates that maximum
+precision is used.
+<BR>
+<P>
+Binary files not in G3D format can be read by the library. The
+following actions have to be taken: 
+
+<P>
+Make a new map directory in the <EM>grid3</EM> element of the mapset (say <EM>mymap</EM>).
+  Copy the file into <EM>mymap/cell</EM> and generate a header file <EM>mymap/cellhd</EM>.
+
+<P>
+In the following example the relevant values of <EM>mymap/cellhd</EM> are shown:
+
+<P>
+\verbatim 
+TileDimensionX: A
+TileDimensionY: B
+TileDimensionZ: C
+useCompression: 0
+useRle: 0
+Precision: -1
+nofHeaderBytes: X
+useXdr: 0
+hasIndex: 0
+\endverbatim
+
+<P>
+The values of <EM>A</EM>, <EM>B</EM>, and <EM>C</EM> have to be chosen
+according to one of the following patterns:
+
+<P>
+\verbatim 
+A &gt;= 1, B == 1, C == 1, or
+A &gt;= nofRows, B &gt;= 1, C == 1, or
+A &gt;= nofRows, B &gt;= nofCols, C &gt;= 1.
+\endverbatim
+
+<P>
+A larger tile size reduces the number of tile-reads. If in the third pattern
+<EM>C</EM> is chosen larger than or equal to <EM>nofDepths</EM>, the entire region is
+considered one large tile.
+
+<P>
+The value <EM>nofHeaderBytes</EM> indicates the offset in the file to the first
+data entry.
+
+<P>
+For performance reasons it is a good idea to use function
+<TT>G3d_retile()</TT> before using the file in other applications.
+
+<P>
+
+\section Region_Structure Region Structure
+
+<P>
+\verbatim 
+typedef struct{
+
+    double north, south;
+    double east, west;
+    double top, bottom;
+  
+    int rows, cols, depths;/* data dimensions in cells */
+
+    double ns_res, ew_res, tb_res;
+
+    int proj;  /* Projection (see gis.h) */
+    int zone;  /* Projection zone (see gis.h) */
+
+} G3D\_Region;
+\endverbatim
+
+<P>
+
+\section Windows Windows
+
+<P>
+Window capability similar to that of <EM>2d</EM> GRASS is provided (compare
+Region).  Additional features are the window for the third dimension
+as well as the possibility to choose a different window for every map. The
+window can be specified at the time of opening an old map. It can be modified
+at any time later in the program. The resampling method can be the default
+nearest neighbor method as well as an application provided method.
+<BR>
+<P>
+The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the mapset.
+Application programs should use <TT>G3d_useWindowParams()</TT> to allow the
+user to overwrite this default.
+
+<P>
+The window file has the following format:
+
+<P>
+\verbatim 
+Proj: 1
+Zone: 1
+North: 2.0
+South: 0.5
+East: 4.0
+West: 3.0
+Top: 5.0
+Bottom: 6.0
+nofRows: 30
+nofCols: 20
+nofDepths: 14
+e-w resol: 0.05000000000000000
+n-s resol: 0.05000000000000000
+t-b resol: 0.07142857142857142
+\endverbatim
+
+<P>
+Note: after reading the window file the fields <EM>e-w</EM>, <EM>n-s</EM>, and <EM>t-b</EM>
+ are recomputed internally.
+
+<P>
+A note about windows and caching. Caching is performed on the level of tiles
+read from the file. There is no caching performed on resampled data.  This is
+different from <EM>2d</EM> GRASS since resampling for a specific value is
+performed every time it is being accessed.
+
+<P>
+
+\section Masks Masks
+
+<P>
+G3D provides a mask for the <EM>3d</EM> region.  The mask structure is
+automatically initialized at the time the first file is opened. The same
+structure is used for all the files. The default for every file is that the
+mask is turned off. If masking should be performed, the application program has
+to turn on masking explicitly. If masking is turned on for a file, the
+cell-values of a tile are automatically checked against the mask. Values which
+are masked out, are set to NULL.
+
+<P>
+Note: changing the status of masking after one or more tiles have already
+been read does not affect the tiles which are already stored in the cache.
+
+<P>
+Any arbitrary 3d raster map can be used as mask file: NULL-values are interpreted as
+ <TT>"mask-out"</TT>, all other values are interpreted as  <TT>"don't mask
+  out"</TT>. Using <EM>r3.mask</EM> to convert a 3d raster map into a mask file instead of
+simply copying (or renaming) the directory will significantly reduce to amount
+of disk space and the access time for the mask.
+
+<P>
+
+\section Include_File Include File
+
+<P>
+Exported G3D constants and structures can be found in <EM>G3d.h</EM>.
+
+<P>
+
+\section G3D_Defaults G3D Defaults
+
+<P>
+There are three methods to set default variables. First, the default can be set
+at compile time in <EM>g3ddefault.c</EM>. This value has lowest priority.
+
+<P>
+Second, the default can be set via an environment variable.  Third, the value
+can be set explicitly set at run time. This value has highest priority.
+
+<P>
+There are also functions provided to query the value.
+
+<P>
+
+\section Cache_Mode Cache Mode
+
+<P>
+
+\subsection Limiting_the_maximum_cache_size Limiting the maximum cache size
+
+<P>
+The limit is specified in bytes. It is a limit on the size of cell-data stored
+in the cache and does not include the support structure.
+
+<P>
+Default G3D_CACHE_SIZE_MAX_DEFAULT. This is currently set to 16meg and can
+be changed at compilation time of the library.
+
+<P>
+Environment variable G3D_MAX_CACHE_SIZE.
+
+<P>
+void G3d_setCacheLimit(int nBytes)Set cache limit
+
+<P>
+int G3d_getCacheLimit(int nBytes)Get cache limit
+
+<P>
+
+\subsection Setting_the_cache_size Setting the cache size
+
+<P>
+This value specifies the number of tiles stored in the cache. It is the value
+used if at opening time of a map G3D_USE_CACHE_DEFAULT is used for the cache
+mode. Any other value used at opening time will supersede the default value. A
+default value of 0 indicates that non-cache mode should be used by default.
+
+<P>
+Default G3D_CACHE_SIZE_DEFAULT. This is currently set to 1000 and can be
+changed at compilation time of the library.
+
+<P>
+Environment variable G3D_DEFAULT_CACHE_SIZE.
+
+<P>
+void G3d_setCacheSize(int nTiles)
+
+<P>
+int G3d_getCacheSize()
+
+<P>
+
+\section Compression Compression
+
+\subsection Toggling_compression_mode Toggling compression mode
+
+<P>
+This value specifies whether compression should be used while writing a new
+map. It does not have any effect on old maps.
+
+<P>
+Default G3D_COMPRESSION_DEFAULT. This is set to G3D_COMPRESSION. This
+default should not be changed.
+
+<P>
+Environment variables G3D_USE_COMPRESSION and G3D_NO_COMPRESSION.
+
+<P>
+See functions G3d_setCompressionMode() (cf. 
+Section 22.3.2.3 ) and G3d_getCompressionMode() (cf. Section 22.3.2.3 ).
+
+<P>
+
+\subsection Toggling_RLE_compression Toggling RLE compression
+
+<P>
+This value specifies whether RLE compression should be used (in addition to
+precision).
+
+<P>
+Default G3D_USE_RLE_DEFAULT. This is currently set to G3D_USE_RLE and can
+be changed at compilation time of the library.
+
+<P>
+Environment variables G3D_USE_RLE and G3D_NO_RLE.
+
+<P>
+See functions G3d_setCompressionMode() (cf. 
+Section 22.3.2.3) and G3d_getCompressionMode() (cf. Section 22.3.2.3).
+
+\section Setting_the_precision Setting the precision
+
+<P>
+This number specifies how many mantissa bits should be used when writing a cell
+value. The minimum value is 0. The maximum value is 23 or G3D_MAX_PRECISION
+for type FCELL_TYPE, it is 52 or G3D_MAX_PRECISION for type DCELL_TYPE.
+
+<P>
+Default G3D_PRECISION_DEFAULT. This is set to G3D_MAX_PRECISION. This
+default should not be changed.
+
+<P>
+Environment variables G3D_PRECISION and G3D_MAX_PRECISION.
+
+<P>
+void G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int
+  precision) <EM>doCompress</EM> should be one of G3D_NO_COMPRESSION and
+  G3D_COMPRESSION, <EM>doRle</EM> should be either G3D_NO_RLE or
+  G3D_USE_RLE, and <EM>precision</EM> should be either G3D_MAX_PRECISION or
+  a positive integer.
+
+<P>
+void G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
+  int *precision)
+
+<P>
+
+\section Tiles Tiles
+
+\subsection Setting_the_tile_dimensions Setting the tile dimensions
+
+<P>
+The dimensions are specified in number of cell.
+
+<P>
+Defaults G3D_TILE_X_DEFAULT, G3D_TILE_Y_DEFAULT, and
+G3D_TILE_Z_DEFAULT. These are currently set to 8 and can be changed at
+compilation time of the library.
+
+<P>
+Environment variables G3D_TILE_DIMENSION_X, G3D_TILE_DIMENSION_Y, and
+G3D_TILE_DIMENSION_Z.
+
+<P>
+void G3d_setTileDimension(int tileX, int tileY, int tileZ)
+
+<P>
+void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
+
+<P>
+
+\section Setting_the_tile_cell_value_type Setting the tile cell-value type
+
+<P>
+Specifies which type is used to write cell-values on file. This type can be
+chosen independently of the type used to store cell-values in memory.
+
+<P>
+Default G3D_FILE_TYPE_DEFAULT. This is set to DCELL_TYPE. This default
+should not be changed.
+
+<P>
+Environment variables G3D_WRITE_FLOAT and G3D_WRITE_DOUBLE.
+
+<P>
+void G3d_setFileType(int type)
+
+<P>
+int G3d_getFileType(int type)
+
+<P>
+
+\section Setting_the_window Setting the window
+
+<P>
+The window is set from a <EM>3d</EM> window file.
+
+<P>
+The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the current mapset.
+
+<P>
+Possible choices for <EM>3d</EM> window files are <EM>name</EM> which refers to a
+window file in the <EM>3d</EM> window database located at <EM>windows3d</EM> of the
+current mapset; or file names which are identified by a leading <EM><TT>"/"</TT></EM> 
+or <EM><TT>"."</TT></EM>; or fully qualified
+names, i.e. <EM>file at mapset</EM> which refer to window files in the <EM>3d</EM> window 
+database of mapset.  Note, that names <EM>WIND3</EM> and <EM>WIND3 at mapset</EM> do not 
+specify the default window name in the (current)
+mapset but rather a window file in the window database of the (current) mapset.
+
+<P>
+Environment variable G3D_DEFAULT_WINDOW3D.
+
+<P>
+See functions 
+
+<P>
+<TT>G3d_useWindowParams()</TT>,
+
+<P>
+<TT>G3d_setWindow()</TT>, and
+
+<P>
+<TT>G3d_setWindowMap()</TT>.
+
+<P>
+
+\section Setting_the_Units Setting the Units
+
+<P>
+Default <TT>"none"</TT>.
+
+<P>
+No environment variable.
+
+<P>
+void G3d_setUnit (unit)
+        char *unit;
+
+<P>
+
+\section Error_Handling Error Handling: Setting the error function
+
+<P>
+This variable specifies the function which is invoked when an error
+(not a fatal error) occurs. For example setting the error function to
+<TT>G3d_fatalError</TT> simplifies debugging with dbx and also might show
+errors which are missed because the application does not check the
+return value.
+
+<P>
+Default <TT>G3d_skipError</TT>.
+
+<P>
+Environment variables G3D_USE_FATAL_ERROR and G3D_USE_PRINT_ERROR.
+
+<P>
+void G3d_setErrorFun(void (*fun)(char *))
+
+<P>
+The following 3 functions are possible choices for error functions.
+
+<P>
+void G3d_skipError(char (*msg)(char *)) This function ignores the
+  error.
+
+<P>
+void G3d_printError(char (*msg)(char *)) This function prints the
+  error message <EM>msg</EM> to <EM>stderr</EM> and returns.
+
+<P>
+void G3d_fatalError(char (*msg)(char *)) This function prints the
+  error message <EM>msg</EM> to <EM>stderr</EM>, flushes <EM>stdout</EM> 
+  and <EM>stderr</EM>, and terminates the program with a segementation fault.
+
+<P>
+
+\section G3D_Function_Index G3D Function Index
+
+\subsection Opening_and_Closing_G3D_Files Opening and Closing G3D Files
+
+<P>
+void  *G3d_openCellOld(char *name, char *mapset, G3D_Region *window,
+  int type, int cache)Opens existing g3d-file <EM>name</EM> in <EM>mapset</EM>.
+
+<P>
+Tiles are stored in memory with <EM>type</EM> which must be any of FCELL_TYPE,
+  DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
+  cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+  G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+  G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf. 
+  Section 22.4.6), or any positive integer which
+  specifies the number of tiles buffered in the cache.  <EM>window</EM> sets the
+  window-region for the map. It is either a pointer to a window structure or
+  G3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
+  set via <TT>G3d_setWindow()</TT> (cf. Section 22.4.16).
+  To modify the window for the map after it has already been opened use
+  <TT>G3d_setWindowMap()</TT> (cf. Section 22.4.16).
+
+<P>
+Returns a pointer to the cell structure ... if successful, NULL ...
+  otherwise.
+
+<P>
+void  *G3d_openCellNew(char *name, int type, int cache, G3D_Region
+  *region)Opens new g3d-file with <EM>name</EM> in the current mapset. Tiles
+  are stored in memory with <EM>type</EM> which must be one of FCELL_TYPE,
+  DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
+  cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+  G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+  G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf. 
+  Section 22.4.6), or any positive integer which
+  specifies the number of tiles buffered in the cache.  <EM>region</EM> specifies
+  the 3d region.  
+
+<P>
+Returns a pointer to the cell structure ... if successful,
+  NULL ... otherwise.
+
+<P>
+void  *G3d_openCellNewParam(char *name, int typeIntern, int cache,
+  G3D_Region *region, int type, int doLzw, int doRle, int precision, int tileX,
+  int tileY, int tileZ)Opens new g3d-file with <EM>name</EM> in the current
+  mapset. Tiles are stored in memory with <EM>typeIntern</EM> which must be one of
+  FCELL_TYPE, DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies
+  the cache-mode used and must be either G3D_NO_CACHE,
+  G3D_USE_CACHE_DEFAULT, G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
+  G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
+  G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of
+  <TT>G3d_cacheSizeEncode()</TT> (cf. 
+  Section 22.4.6), or any positive integer which
+  specifies the number of tiles buffered in the cache.  <EM>region</EM> specifies
+  the 3d region.
+
+<P>
+In addition the properties of the new file have to be specified. It is
+  assumed by default that compression is used. This function first sets the
+  global default values to the specified values, and then restores the original
+  global defaults. This function can be used in conjunction with
+  <TT>G3d_setStandard3dInputParams()</TT> (cf. 
+  Section 22.4.18) and
+  <TT>G3d_getStandard3dParams()</TT>.
+
+<P>
+Returns a pointer to the cell structure ... if successful, NULL ...
+  otherwise.
+
+<P>
+int G3d_closeCell(void *map)Closes g3d-file. If <EM>map</EM> is new
+  and cache-mode is used for <EM>map</EM> then every tile which is not flushed
+  before closing is flushed.  
+
+<P>
+Returns 1 ... if successful, 0 ...  otherwise.
+
+<P>
+
+\subsection Reading_and_Writing_Tiles Reading and Writing Tiles
+
+<P>
+These functions read or write data directly to the file (after performing the
+appropriate compression) without going through the cache. In order to avoid 
+unexpected side-effects the use of these functions in cache mode is
+discouraged.
+
+<P>
+int G3d_readTile(void *map, char *tileIndex, int tile, int type)
+  Reads tile with index <EM>tileIndex</EM> into the <EM>tile</EM> buffer. The cells
+  are stored with type <EM>type</EM> which must be one of FCELL_TYPE and
+  DCELL_TYPE. If the tile with <EM>tileIndex</EM> is not stored on the file
+  corresponding to <EM>map</EM>, and <EM>tileIndex</EM> is a valid index <EM>tile</EM>
+  is filled with NULL-values.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_readTileFloat(void *map, char *tileIndex, int tile)
+Is equivalent to G3d_readTile (map, tileIndex, tile, FCELL_TYPE).
+
+<P>
+int G3d_readTileDouble(void *map, char *tileIndex, int tile)
+Is equivalent to G3d_readTile (map, tileIndex, tile, DCELL_TYPE).
+
+<P>
+int G3d_writeTile(void *map, char *tileIndex, int tile, int type)
+  Writes tile with index <EM>tileIndex</EM> to the file corresponding to <EM>map</EM>. It is assumed that the cells in <EM>tile</EM> are of <EM>type</EM> which
+  must be one of FCELL_TYPE and DCELL_TYPE.  The actual type used to write the
+  tile depends on the type specified at the time when <EM>map</EM> is initialized.
+
+<P>
+A tile can only be written once. Subsequent attempts to write the same tile
+  are ignored.
+
+<P>
+Returns 
+        1 ... if successful,
+        2 ... if write request was ignored,
+        0 ... otherwise.
+
+<P>
+int G3d_writeTileFloat(void *map, char *tileIndex, int tile)
+Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, FCELL_TYPE).</TT>
+
+<P>
+int G3d_writeTileDouble(void *map, char *tileIndex, int tile)
+Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, DCELL_TYPE).</TT>
+
+<P>
+
+\subsection Reading_and_Writing_Cells Reading and Writing Cells
+
+<P>
+void G3d_getValue(void *map, int x, int y, int z, char *value, int
+  type) Returns in <EM>*value</EM> the cell-value of the cell with
+  window-coordinate <EM>(x, y, z)</EM>.  The value returned is of <EM>type</EM>.
+
+<P>
+This function invokes a fatal error if an error occurs.
+
+<P>
+float G3d_getFloat(void *map, int x, int y, int z)Is equivalent to
+  <TT>G3d_getValue (map, x, y, z, &amp;value, FCELL_TYPE);</TT> return value.
+
+<P>
+double G3d_getDouble(void *map, int x, int y, int z)Is equivalent
+  to <TT>G3d_getValue (map, x, y, z, &amp;value, DCELL_TYPE);</TT> return value.
+
+<P>
+void G3d_getValueRegion(void *map, int x, int y, int z, char*value,
+  int type) Returns in <EM>*value</EM> the cell-value of the cell with
+  region-coordinate <EM>(x, y, z)</EM>.  The value returned is of <EM>type</EM>.
+  Here <EM>region</EM> means the coordinate in the cube of data in the file, i.e.
+  ignoring geographic coordinates.
+
+<P>
+This function invokes a fatal error if an error occurs.
+
+<P>
+float G3d_getFloatRegion(void *map, int x, int y, int z)Is
+  equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value, FCELL_TYPE);</TT>
+  return value.
+
+<P>
+double G3d_getDoubleRegion(void *map, int x, int y, int z)Is
+  equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value,
+    DCELL_TYPE);</TT> return value.
+
+<P>
+int G3d_putValue(void *map, int x, int y, int z, char *value, int
+  type)After converting <EM>*value</EM> of <EM>type</EM> into the type specified
+  at the initialization time (i.e. <EM>typeIntern</EM>) this function writes the
+  value into the tile buffer corresponding to cell-coordinate <EM>(x, y, z)</EM>.
+
+<P>
+Returns
+
+<P>
+  1 ... if successful,  
+  0 ... otherwise.
+
+<P>
+int G3d_putFloat(void *map, int x, int y, int z, char *value)Is
+  equivalent to G3d_putValue (map, x, y, z, &amp;value, FCELL_TYPE).
+
+<P>
+int G3d_putDouble(void *map, int x, int y, int z, char *value) Is
+  equivalent to G3d_putValue (map, x, y, z, &amp;value, DCELL_TYPE).
+
+<P>
+
+\subsection Loading_and_Removing_TilesLoading and Removing Tiles
+
+<P>
+char *G3d_getTilePtr(void *map, int tileIndex) This function
+  returns a pointer to a tile which contains the data for the tile with index
+  <EM>tileIndex</EM>.  The type of the data stored in the tile depends on the type
+  specified at the initialization time of <EM>map</EM>.  The functionality is
+  different depending on whether <EM>map</EM> is old or new and depending on the
+  cache-mode of <EM>map</EM>.
+<BR>
+<P>
+If <EM>map</EM> is old and the cache is not used the tile with <EM>tileIndex</EM>
+  is read from file and stored in the buffer provided by the map structure.
+  The pointer to this buffer is returned. If the buffer already contains the
+  tile with <EM>tileIndex</EM> reading is skipped. Data which was stored in
+  earlier calls to <TT>G3d_getTilePtr</TT> is destroyed.  If the tile with 
+  <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and 
+  <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.
+<BR>
+<P>
+If <EM>map</EM> is old and the cache is used the tile with <EM>tileIndex</EM> is
+  read from file and stored in one of the cache buffers.  The pointer to buffer
+  is returned.  If no free cache buffer is available an unlocked cache-buffer
+  is freed up and the new tile is stored in its place.  If the tile with 
+  <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and 
+  <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.  If one
+  of the cache buffers already contains the tile with <EM>tileIndex</EM> reading
+  is skipped and the pointer to this buffer is returned.
+<BR>
+<P>
+If <EM>map</EM> is new and the cache is not used the functionality is the same
+  as if <EM>map</EM> is old and the cache is not used.  If the tile with 
+  <EM>tileIndex</EM> is already stored on file, it is read into the buffer, if not,
+  the cells are set to null-values.  If the buffer corresponding to the pointer
+  is used for writing, subsequent calls to <TT>G3d_getTilePtr</TT> may destroy the
+  values already stored in the buffer.  Use <TT>G3d_flushTile</TT> to write the buffer
+  to the file before reusing it for a different index.  The use of this buffer
+  as write buffer is discouraged.
+<BR>
+<P>
+If <EM>map</EM> is new and the cache is used the functionality is the same as if
+  <EM>map</EM> is old and the cache is used with the following exception.  If 
+  <EM>tileIndex</EM> is a valid index and the tile with this index is not found in
+  the cache and is not stored on the file corresponding to <EM>map</EM>, then the
+  file cache is queried next. If the file-cache contains the tile it is loaded
+  into the cache (memory-cache). Only if the file-cache does not contain the
+  tile it is filled with NULL-values.  Tile contents of buffers are never
+  destroyed. If a cache buffer needs to be freed up, and the tile stored in the
+  buffer has not been written to the file corresponding to <EM>map</EM> yet, the
+  tile is copied into the file-cache.
+<BR>
+<P>
+Care has to be taken if this function is used in non-cache mode since it is
+  implicitly invoked every time a read or write request is issued.  The only
+  I/O-functions for which it is safe to assume that they do not invoke
+  <TT>G3d_getTilePtr</TT> are <TT>G3d_readTile()</TT> and
+  <TT>G3d_writeTile()</TT> and their corresponding type-specific versions.
+
+<P>
+Returns 
+        a pointer to a buffer ... if successful,
+        NULL ... otherwise.
+
+<P>
+int G3d_tileLoad(void *map, int tileIndex)
+Same functionality as <TT>G3d_getTilePtr()</TT> but does not return the
+pointer.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_removeTile(void *map, inttileIndex) Removes a tile
+        from memory-cache if tile is in memory-cache.  For new maps the
+        application does not know whether the tile is in the memory-cache or in
+        the file-cache. Therefore, for new maps this function should be
+        preceded by <TT>G3d_tileLoad()</TT>.
+
+<P>
+<EM>(Question: Is this a useful function?)</EM>
+
+<P>
+Returns 1 ... if successful, 0 ... otherwise.
+
+<P>
+
+\subsection Write_Functions_used_in_Cache_Mode Write Functions used in Cache Mode
+
+<P>
+int G3d_flushTile(void *map, int tileIndex) Writes the tile with
+  <EM>tileIndex</EM> to the file corresponding to <EM>map</EM> and removes the tile
+  from the cache (in non-cache mode the buffer provided by the map-structure is
+  written).
+
+<P>
+If this tile has already been written before the write request is ignored.
+  If the tile was never referred to before the invokation of G3d_flushTile, a
+  tile filled with NULL-values is written.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_flushTileCube(void *map, int xMin, int yMin, int zMin, int
+  xMax, int yMax, int zMax) Writes the tiles with tile-coordinates
+  contained in the axis-parallel cube with vertices <EM>(xMin, yMin, zMin)</EM>
+  and <EM>(xMax, yMax, zMax</EM>).  Tiles which are not stored in the cache are
+  written as NULL-tiles.  Write attempts for tiles which have already been
+  written earlier are ignored.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_flushTilesInCube(void *map, int xMin, int yMin, int
+        zMin, int xMax, int yMax, int zMax) Writes those tiles for which
+        <EM>every</EM> cell has coordinate contained in the axis-parallel cube
+        defined by the vertices with cell-coordinates <EM>(xMin, yMin, zMin)</EM>
+        and <EM>(xMax, yMax, zMax)</EM>.
+
+<P>
+Tiles which are not stored in the cache are written as NULL-tiles.
+        Write attempts for tiles which have already been written earlier are
+        ignored.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+
+\subsection Locking_and_Unlocking_Tiles_and_CyclesLocking and Unlocking Tiles, and Cycles
+
+<P>
+int G3d_lockTile(void *map, int tileIndex) Locks tile with <EM>tileIndex</EM> in cache. 
+If after locking fewer than the minimum number of
+  unlocked tiles are unlocked, the lock request is ignored.
+
+<P>
+Returns 
+         1 ... if successful,
+        -1 ... if request is ignored,
+         0 ... otherwise.
+
+<P>
+int G3d_unlockTile(void *map, int tileIndex)
+Unlocks tile with <EM>tileIndex</EM>.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_unlockAll(void *map)
+Unlocks every tile in cache of <EM>map</EM>.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+void G3d_autolockOn(void *map)
+Turns autolock mode on.
+
+<P>
+void G3d_autolockOff(void *map)
+Turns autolock mode Off.
+
+<P>
+void G3d_minUnlocked(void *map, int minUnlocked) Sets the minimum
+  number of unlocked tiles to <EM>minUnlocked</EM>.  This function should be used
+  in combination with <TT>G3d_unlockAll()</TT> in order to avoid  situations where the
+  new minimum is larger than the actual number of unlocked tiles.
+
+<P>
+<EM>minUnlocked</EM> must be one of G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
+  G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
+  G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of G3d_cacheSizeEncode()
+  (cf. Section 22.4.6), or any positive integer
+  which explicitly specifies the number of tiles.
+
+<P>
+int G3d_beginCycle(void *map)
+Starts a new cycle.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_endCycle(void *map)
+Ends a cycle.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_cacheSizeEncode(int cacheCode, int n) Returns a number
+  which encodes multiplicity <EM>n</EM> of <EM>cacheCode</EM>. This value can be used
+  to specify the size of the cache.
+
+<P>
+If <EM>cacheCode</EM> is the size (in tiles) of the cache the function returns
+  <EM>cacheCode * n</EM>.
+
+<P>
+If <EM>cacheCode</EM> is G3D_USE_CACHE_DEFAULT the function returns
+  G3D_USE_CACHE_DEFAULT.
+
+<P>
+If <EM>cacheCode</EM> is G3D_USE_CACHE_??? the function returns a value
+  encoding G3D_USE_CACHE_??? and <EM>n</EM>. Here G3D_USE_CACHE_??? is one
+  of G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+  G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ, or
+  G3D_USE_CACHE_XYZ, where e.g.  G3D_USE_CACHE_X specifies that the cache
+  should store as many tiles as there exist in one row along the x-axis of the
+  tile cube, and G3D_USE_CACHE_XY specifies that the cache should store as
+  many tiles as there exist in one slice of the tile cube with constant Z
+  coordinate.
+
+<P>
+
+\subsection Reading_Volumes Reading Volumes
+
+<P>
+int G3d_getVolume(void *map, double originNorth, double originWest,
+  double originBottom, double vxNorth, double vxWest, double vxBottom, double
+  vyNorth, double vyWest, double vyBottom, double vzNorth, double vzWest,
+  double vzBottom, int nx, int ny, int nz, char *volumeBuf, int type)
+  Resamples the cube defined by <EM>origin</EM> and the 3 vertices <EM>vx</EM>, 
+  <EM>vy</EM>, and <EM>vz</EM> which are incident to the 3 edges adjacent to
+   <EM>origin</EM>.  The resampled cube is stored in <EM>volumeBuf</EM> which is a cube
+  with dimensions <EM>(nx, ny, nz)</EM>.
+
+<P>
+The method of sampling is nearest neighbor sampling.
+
+<P>
+The values stored are of <EM>type</EM>. 
+
+<P>
+Returns 1 ... if successful, 0 ... otherwise.
+
+<P>
+int G3d_getAllignedVolume(void *map, double originNorth, double
+  originWest, double originBottom, double lengthNorth, double lengthWest,
+  double lengthBottom, int nx, int ny, int nz, char *volumeBuf, int type)
+  Resamples the axis-parallel cube defined by <EM>origin</EM> and the lengths of
+  the 3 edges adjacent to <EM>origin</EM>.  The resampled cube is stored in
+   <EM>volumeBuf</EM> which is a cube with dimensions <EM>(nx, ny, nz)</EM>.  The method
+  of sampling is nearest neighbor sampling.  The values stored are of <EM>type</EM>.  
+
+<P>
+Returns 1 ... if successful, 0 ... otherwise.
+
+<P>
+
+\subsection Allocating_and_Freeing_Memory Allocating and Freeing Memory
+
+<P>
+void  *G3d_malloc(int nBytes)
+Same as <EM>malloc (nBytes)</EM>, except that in case of error
+<TT>G3d_error()</TT> is invoked.
+
+<P>
+Returns 
+        a pointer ... if successful,
+        NULL ... otherwise.
+
+<P>
+void  *G3d_realloc(void *ptr, int nBytes)
+Same as <EM>realloc (ptr, nBytes)</EM>, except that in case of error
+<TT>G3d_error()</TT> is invoked. 
+
+<P>
+Returns 
+        a pointer ... if successful,
+        NULL ... otherwise.
+
+<P>
+void G3d_free(void *ptr) Same as <EM>free (ptr)</EM>.
+
+<P>
+char *G3d_allocTilesType(void *map, int nofTiles, int type)
+Allocates a vector of <EM>nofTiles</EM> tiles with the same dimensions
+as the tiles of <EM>map</EM> and large enough to store cell-values of
+<EM>type</EM>.
+
+<P>
+Returns 
+        a pointer to the vector ... if successful,
+        NULL ... otherwise.
+
+<P>
+char *G3d_allocTiles(void *map, int nofTiles)
+Is equivalent to G3d_allocTilesType (map, nofTiles, G3d_fileTypeMap (map)).
+
+<P>
+void G3d_freeTiles(char *tiles)
+Is equivalent to <TT>G3d_free (tiles);</TT>
+
+<P>
+
+\subsection G3D_Null_Value_Support G3D Null Value Support
+
+<P>
+void G3d_isNullValueNum(void *n, int type)
+Returns 1 if the value of <EM>*n</EM> is a NULL-value. Returns 0
+otherwise.
+
+<P>
+void G3d_setNullValue(void *c, int nofElts, int type)
+Fills the vector pointed to by <EM>c</EM> with <EM>nofElts</EM> NULL-values
+of <EM>type</EM>.
+
+<P>
+void G3d_setNullTileType(void *map, int tile, int type)
+Assumes that <EM>tile</EM> is a tile with the same dimensions as the
+tiles of <EM>map</EM>. Fills <EM>tile</EM> with NULL-values of
+<EM>type</EM>.
+
+<P>
+void G3d_setNullTile(void *map, int tile)
+Is equivalent to G3d_setNullTileType (map, tile, G3d_fileTypeMap (map)).
+
+<P>
+
+\subsection G3D_Map_Header_Information G3D Map Header Information
+
+<P>
+void G3d_getCoordsMap(void *map, int *rows, int *cols, int *depths)
+Returns the size of the region of <EM>map</EM> in cells.
+
+<P>
+void G3d_getRegionMap(void *map, int *north, int *south, int *east,
+  int *west, int *top, int *bottom)Returns the size of the region.
+
+<P>
+void G3d_getRegionStructMap(void *map, G3D_Region *region)
+Returns in <EM>region</EM> the region of <EM>map</EM>.
+
+<P>
+void G3d_getTileDimensionsMap(void *map, int *x, int *y, int *z)
+Returns the tile dimensions used for <EM>map</EM>.
+
+<P>
+void G3d_getNofTilesMap(void *map, int *nx, int *ny, int *nz)
+  Returns the dimensions of the tile-cube used to tile the region of <EM>map</EM>.
+  These numbers include partial tiles.
+
+<P>
+int G3d_tileTypeMap(void *map)
+Returns the type in which tiles of <EM>map</EM> are stored in memory.
+
+<P>
+int G3d_fileTypeMap(void *map)
+Returns the type with which tiles of <EM>map</EM> are stored on file.
+
+<P>
+int G3d_tilePrecisionMap(void *map)
+Returns the precision used to store <EM>map</EM>.
+
+<P>
+int G3d_tileUseCacheMap(void *map)
+Returns 1 if <EM>map</EM> uses cache, returns 0 otherwise.
+
+<P>
+void G3d_printHeader(void *map)
+Prints the header information of <EM>map</EM>.
+
+<P>
+
+\subsection G3D_Tile_Math G3D Tile Math
+
+<P>
+void G3d_tileIndex2tile(void *map, int tileIndex, int *xTile, int
+  *yTile, int *zTile) Converts index <EM>tileIndex</EM> into tile-coordinates
+  <EM>(xTile, yTile, zTile)</EM>.
+
+<P>
+int G3d_tile2tileIndex(void *map, int xTile, int yTile, int
+  zTile) Returns tile-index corresponding to tile-coordinates <EM>(xTile,
+    yTile, zTile)</EM>.
+
+<P>
+void G3d_coord2tileCoord(void *map, int x, int y, int z, int *xTile,
+  int *yTile, int *zTile, int *xOffs, int *yOffs, int *zOffs) Converts
+  cell-coordinates <EM>(x, y, z)</EM> into tile-coordinates <EM>(xTile, yTile,
+    zTile)</EM> and the coordinate of the cell <EM>(xOffs, yOffs, zOffs)</EM> within
+  the tile.
+
+<P>
+void G3d_tileCoordOrigin(void *map, int xTile, int yTile, int zTile,
+  int *x, int *y, int *z) Computes the cell-coordinates <EM>(x, y, z)</EM>
+  which correspond to the origin of the tile with tile-coordinates <EM>(xTile,
+    yTile, zTile)</EM>.
+
+<P>
+void G3d_tileIndexOrigin(void *map, int tileIndex, int *x, int *y,
+  int *z) Computes the cell-coordinates <EM>(x, y, z)</EM> which correspond to
+  the origin of the tile with <EM>tileIndex</EM>.
+
+<P>
+void G3d_coord2tileIndex(void *map, int x, int y, int z, int
+  *tileIndex, int *offset) Converts cell-coordinates <EM>(x, y, z)</EM> into
+  <EM>tileIndex</EM> and the <EM>offset</EM> of the cell within the tile.
+
+<P>
+int G3d_coordInRange(void *map, int x, int y, int z) Returns 1 if
+  cell-coordinate <EM>(x, y, z)</EM> is a coordinate inside the region. Returns 0
+  otherwise.
+
+<P>
+int G3d_tileInRange(void *map, int x, int y, int z) Returns 1 if
+  tile-coordinate <EM>(x, y, z)</EM> is a coordinate inside tile cube. Returns 0
+  otherwise.
+
+<P>
+int G3d_tileIndexInRange(void *map, int tileIndex)
+Returns 1 if <EM>tileIndex</EM> is a valid index for <EM>map</EM>.
+Returns 0 otherwise.
+
+<P>
+int G3d_isValidLocation(void *map, double north, double west, double
+  bottom) Returns 1 if region-coordinates <EM>(north, west, bottom)</EM> are
+  inside the region of <EM>map</EM>. Returns 0 otherwise.
+
+<P>
+void G3d_location2coord(void *map, double north, double west, double
+  bottom, int *x, *y, *z) Converts region-coordinates <EM>(north, west,
+    bottom)</EM> into cell-coordinates <EM>(x, y, z)</EM>.
+
+<P>
+int G3d_computeClippedTileDimensions(void *map, int tileIndex, int
+  *rows, int *cols, int *depths, int *xRedundant, int *yRedundant, int
+  *zRedundant) Computes the dimensions of the tile when clipped to fit the
+  region of <EM>map</EM>. The clipped dimensions are returned in <EM>rows</EM>, 
+  <EM>cols</EM>, <EM>depths</EM>.  The complement is returned in <EM>xRedundant</EM>,
+   <EM>yRedundant</EM>, and <EM>zRedundant</EM>. This function returns the number of
+  cells in the clipped tile.
+
+<P>
+
+\subsection G3D_Range_Support G3D Range Support
+
+<P>
+The map structure of G3D provides storage for the range.  The range of a map is
+updated every time a cell is written to the file. When an old map is opened the
+range is not automatically loaded. The application has to invoke
+<TT>G3d_range_load()</TT> (cf. Section 22.4.12)
+ explicitly.  In
+addition to these function the application can also use the standard grass
+functions to manipulate the range.
+
+<P>
+int G3d_range_load(void *map)
+Loads the range into the range structure of <EM>map</EM>.
+
+<P>
+Returns
+        1 ... if successful
+        0 ... otherwise.
+
+<P>
+void G3d_range_min_max(void *map, double *min, double *max)
+        Returns in <EM>min</EM> and <EM>max</EM> the minimum and maximum values of
+        the range.
+
+<P>
+int G3d_range_write(void *map)
+Writes the range which is stored in the range structure of <EM>map</EM>. 
+(This function is invoked automatically when a new file is closed).
+
+<P>
+Returns
+        1 ... if successful
+        0 ... otherwise.
+
+<P>
+
+\subsection G3D_Color_Support G3D Color Support
+
+<P>
+Applications can use the standard grass functions to work with colors, except
+for the file manipulations.
+
+<P>
+int G3d_removeColor(char *name)
+Removes the primary and/or secondary color file. See <EM>G_remove_colr</EM> for
+details.
+
+<P>
+Returns always 0.
+
+<P>
+int G3d_readColors(char *name, char *mapset, struct Colors
+   *colors) Reads color file for map <EM>name</EM> in <EM>mapset</EM> into the
+   <EM>colors</EM> structure.  See <EM>G_read_colors</EM>
+   (Raster_Color_Table) for details and return values.
+
+<P>
+int G3d_writeColors(char *name, char *mapset, struct Colors
+   *colors)Writes colors stored in <EM>colors</EM> structure into the color
+   file for map <EM>name</EM> in <EM>mapset</EM>.  See <EM>G_write_colors</EM>
+   (Raster_Color_Table) for
+   details and return values.
+
+<P>
+
+\subsection G3D_Categories_Support G3D Categories Support
+
+<P>
+Applications can use the standard grass functions to work with categories, 
+except for the file manipulations.
+
+<P>
+int G3d_readCats(char *name, char *mapset, struct Categories *cats)
+Reads the categories file for map <EM>name</EM> in <EM>mapset</EM> and
+stores the categories in the <EM>cats</EM> structure.  See <EM>G_read_cats</EM>
+(Raster_Category_File) for details and return values.
+
+<P>
+int G3d_writeCats(char *name, struct Categories *cats) Writes the
+  categories stored in the <EM>cats</EM> structure into the categories file for
+  map <EM>name</EM> in the current mapset.  See <EM>G_write_cats</EM>
+  (Raster_Category_File) for details and return values.
+
+<P>
+
+
+\subsection G3D_History_Support G3D History Support
+
+<P>
+Applications can use the standard grass functions to work with histories, 
+except for the file manipulations.
+
+<P>
+int G3d_readHistory(char *name, char *mapset, struct History *hist)
+  Reads the history file for map <EM>name</EM> in <EM>mapset</EM> and
+  stores the history in the <EM>hist</EM> structure.  See <EM>G_read_history</EM>
+  (Raster_History_File) for details and return values.
+
+<P>
+int G3d_writeHistory(char *name, struct History *hist) 
+  Writes the
+  history stored in the <EM>hist</EM> structure into the categories file for
+  map <EM>name</EM> in the current mapset.  See <EM>G_write_history</EM>
+  (Raster_History_File) for details and return values.
+
+<P>
+
+\subsection G3D_Mask_Support G3D Mask Support
+
+<P>
+void G3d_maskOn(void *map) Turns on the mask for <EM>map</EM>. Do
+  not invoke this function after the first tile has been read since the result
+  might be inconsistent cell-values.
+
+<P>
+void G3d_maskOff(void *map) Turns off the mask for <EM>map</EM>.
+  This is the default.  Do not invoke this function after the first tile has
+  been read since the result might be inconsistent cell-values.
+
+<P>
+int G3d_maskIsOn(void *map) Returns 1 if the mask for <EM>map</EM>
+  is turned on. Returns 0 otherwise.
+
+<P>
+int G3d_maskIsOff(void *map)
+Returns 1 if the mask for <EM>map</EM> is turned off. Returns 0 otherwise.
+
+<P>
+The remaining functions in this section are for the explicit query of the mask
+and the masking of individual cells or tiles. These functions are used in the
+library and might have applications in situations where both the masked and
+non-masked value of a cell has to be known.  
+
+<P>
+int G3d_maskReopen(int cache)
+This function should be used to adjust the cache size used for the
+3d-mask. First the open 3d-mask is closed and then opened again with 
+a cache size as specified with <EM>cache</EM>.
+
+<P>
+Returns
+        1 ... if successful
+        0 ... otherwise.
+
+<P>
+int G3d_maskFileExists() Returns 1 if the 3d mask file
+        exists.
+
+<P>
+int G3d_maskMapExists()
+Returns 1 if the 3d mask is loaded.
+
+<P>
+char *G3d_maskFile()
+Returns the name of the 3d mask file.
+
+<P>
+int G3d_isMasked(int x, int y, int z)
+Returns 1 if the cell with cell-coordinates <EM>(x, y, z)</EM> is masked
+out. Returns 0 otherwise.
+
+<P>
+void G3d_maskNum(int x, int y, int z, void  *value, int type)
+Replaces the value stored in <EM>value</EM> with the NULL-value if 
+<EM>G3d_isMasked (x, y, z)</EM> returns 1. Does nothing otherwise.
+<EM>value</EM> is assumed to be of<EM>type</EM>.
+
+<P>
+void G3d_maskFloat(int x, int y, int z, float *value)
+Same as <EM>G3d_maskNum (x, y, z, value, FCELL_TYPE)</EM>.
+
+<P>
+void G3d_maskDouble(int x, int y, int z, double *value)
+Same as <EM>G3d_maskNum (x, y, z, value, DCELL_TYPE)</EM>.
+
+<P>
+void G3d_maskTile(void *map, int tileIndex, char *tile, int type)
+Replaces the values stored in <EM>tile</EM> (with <EM>tileIndex</EM>) for 
+which <EM>G3d_isMasked</EM> returns 1 with NULL-values. Does not change
+the remaining values. The values are assumed to be of <EM>type</EM>. 
+Whether replacement is performed or not only depends on location of the
+cells of the tile and not on the status of the mask for <EM>map</EM>
+(i.e. turned on or off).
+
+<P>
+
+\subsection G3D_Window_Support G3D Window Support
+
+<P>
+void G3d_setWindowMap(void *map, G3D_Region *window)
+Sets the window for <EM>map</EM> to <EM>window</EM>.
+Can be used multiple times for the same map.
+
+<P>
+void G3d_setWindow(G3D_Region *window)
+Sets the default window used for every map opened later in the program.
+Can be used multiple times in the same program.
+
+<P>
+void G3d_getWindow(G3D_Region *window)
+Stores the current default window in <EM>window</EM>.
+
+<P>
+void  *G3d_windowPtr()
+Returns a pointer to the current default window. This pointer should not be
+(ab)used to modify the current window structure directly. It is
+provided to pass a window pointer when opening a map.
+
+<P>
+int G3d_readWindow(G3D_Region *window, char *windowName) Reads
+  <EM>window</EM> from the file specified by <EM>windowName</EM>. The name is
+  converted by the rules defined in window defaults. A NULL pointer indicates
+  the <EM>WIND3</EM> file in the current mapset.
+
+<P>
+Returns
+        1 ... if successful
+        0 ... otherwise.
+
+<P>
+int G3d_writeWindow(G3D_Region *window, char *windowName)
+        Writes <EM>window</EM> to the file specified by <EM>windowName</EM>. The name
+        is converted by the rules defined in window defaults. A NULL pointer
+        indicates the <EM>WIND3</EM> file in the current mapset.
+
+<P>
+Returns
+        1 ... if successful
+        0 ... otherwise.
+
+<P>
+void G3d_useWindowParams()
+Allows the window to be set at run-time via the <EM>region3</EM>
+command line argument. This function has to be called before
+<EM>G_parser()</EM>. See also
+ window defaults.
+
+<P>
+void G3d_setResamplingFun(void *map, void  (*resampleFun)())
+Sets the resampling function to be used by
+G3d_getValue() (cf. Section 22.4.3). This function is defined
+as follows:
+
+<P>
+void G3d_customResampleFun(void *map, int row, int col, int depth,
+  char *value, int type) <EM>row</EM>, <EM>col</EM>, and <EM>depth</EM> are in
+  region coordinates. The result is returned in <EM>value</EM> as <EM>type</EM> which
+  is one of FCELL_TYPE or DCELL_TYPE. Possible choices include
+  G3d_nearestNeighbor() (cf. Section22.4.16) and
+  G3d_getValueRegion() (cf. Section 22.4.3).
+
+<P>
+void G3d_nearestNeighbor(void *map, int row, int col, int depth, char
+  *value, int type) The default resampling function which uses nearest
+  neighbor resampling.
+
+<P>
+void G3d_getResamplingFun(void *map, void  (**resampleFun)())
+  Returns in <EM>resampleFun</EM> a pointer to the resampling function used by
+  <EM>map</EM>.
+
+<P>
+void G3d_getNearestNeighborFunPtr(void (**nnFunPtr)()) Returns
+  in <EM>nnFunPtr</EM> a pointer to G3d_nearestNeighbor() (cf. 
+  Section&nbsp;<A HREF="#g3d:G3d.nearestNeighbor">22.4.16</A>).
+
+<P>
+
+\subsection G3D_Region G3D Region
+
+<P>
+void G3d_extract2dRegion(G3D_Region *region3d, struct Cell_head
+  *region2d) Returns in <EM>region2d</EM> the <EM>2d</EM> portion of <EM>region3d</EM>.
+
+<P>
+void G3d_incorporate2dRegion(struct Cell_head *region2d, G3D_Region
+  *region3d) Replaces the <EM>2d</EM> portion of <EM>region3d</EM> with the
+  values stored in <EM>region2d</EM>.
+
+<P>
+void G3d_adjustRegion(G3D_Region *region)
+Computes an adjusts the resolutions in the region structure from the region
+boundaries and number of cells per dimension.
+
+<P>
+void G3d_adjustRegionRes(G3D_Region *region)
+Computes an adjusts the number of cells per dimension in the region
+structure from the region boundaries and resolutions.
+
+<P>
+void G3d_regionCopy(G3D_Region *regionDest, G3D_Region *regionSrc)
+Copies the values of <EM>regionSrc</EM> into <EM>regionDst</EM>.
+(The unfortunate order of parameters was chosen in order to conform to the
+order used in <EM>G_copy()</EM>).
+
+<P>
+void G3d_getRegionValue(void *map, double north, double east, double
+  top, char *value, int type) Returns in <EM>value</EM> the value of the <EM>map</EM>
+   which corresponds to region coordinates <EM>(north, east, top)</EM>.  The
+  value is resampled using the resampling function specified for <EM>map</EM>. The
+  <EM>value</EM> is of <EM>type</EM>.
+
+<P>
+void G3d_readRegionMap(char *name, char *mapset, G3D_Region *region)
+Returns in <EM>region</EM> the region information for 3d cell <EM>name at mapset</EM>.
+
+<P>
+
+\subsection Miscellaneous_Functions Miscellaneous Functions
+
+<P>
+void G3d_g3dType2cellType(int g3dType) Returns the GRASS floating
+  point type which is equivalent to the G3D type of <EM>g3dType</EM>.
+
+<P>
+void G3d_initDefaults() Initializes the default values described
+  in G3D Defaults.  Applications have to use this function only if they need to
+  query the default values before the first file (either old or new) has been
+  opened.
+
+<P>
+void G3d_setStandard3dInputParams() 
+ Initializes a parameter
+  structure for the subset of command line arguments which lets the user
+  overwrite the default properties of the new file.  Applications are
+  encouraged to use this function in order to provide a uniform style.  The
+  command line arguments provided are the <EM>type</EM> of the cell values, the
+  <EM>precision</EM>, the properties of the <EM>compression</EM>, and the dimension
+  of the tiles (<EM>tiledimension</EM>). Every of these values defaults to the
+  value described in G3D Defaults.
+
+<P>
+This function has to be used in conjunction with
+  G3d_getStandard3dInputParams() (cf. 
+  Section 22.4.18).
+
+<P>
+int G3d_getStandard3dInputParams(int *useTypeDefault, *type, *useLzwDefault, *doLzw,
+        int *useRleDefault, *doRle, *usePrecisionDefault, *precision,
+        int *useDimensionDefault, *tileX, *tileY, *tileZ
+Returns the properties of the new file as chosen by the user via command
+line arguments. If the default is chosen the values of
+<EM>useXxxxDefault</EM> is 1, it is 0 otherwise. In addition, the
+corresponding parameters contain the default value if 
+<EM>useXxxxDefault</EM> is 1, or the value specified by the user if 
+<EM>useXxxxDefault</EM> is 0.
+
+<P>
+Function 
+G3d_setStandard3dInputParams() (cf. Section 22.4.18)
+has to be used to initialize the internal parameter structure.
+
+<P>
+Returns 
+        1 ... if successful,
+        0 ... otherwise.
+
+<P>
+int G3d_makeMapsetMapDirectory(char *mapName)
+Creates the 3d mapset element for map <EM>mapName</EM>.
+
+<P>
+int G3d_filename(char *path, *elementName, *mapName, *mapset)
+Returns in <EM>path</EM> the path for element <EM>elementName</EM> for map
+<EM>mapName</EM> in <EM>mapset</EM>. Note, an error occurs if <EM>mapName</EM>
+is fully qualified.
+
+<P>
+See TimeStamp_functions for a complete discussion of GRASS datetime
+routines (reading, writing grid3d timestamps).
+
+<P>
+
+\section Sample_G3D_Applications Sample G3D Applications
+
+<P>
+These functions were implemented to test the library. They are not very
+efficient but can be used as starting point for other
+applications. Some of them might actually be useful. They are available from
+GRASS 7 source code in lib/g3d/.
+
+<P>
+void G3d_retile(void *map, char *nameOut, int tileX, int tileY, int tileZ)
+Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which has
+tile dimensions <EM>tileX</EM>, <EM>tileY</EM>, <EM>tileZ</EM>.
+
+<P>
+The source code can be found in <EM>retile.c</EM>.
+
+<P>
+void G3d_changePrecision(void *map, int precision, char *nameOut)
+Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which is
+written with <EM>precision</EM>.
+
+<P>
+The source code can be found in <EM>changeprecision.c</EM>.
+
+<P>
+void G3d_changeType(void *map, char *nameOut)
+Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> in which the
+cells are of type FCELL_TYPE if they are DCELL_TYPE in <EM>map</EM>,
+and in DCELL_TYPE otherwise.
+
+<P>
+The source code can be found in <EM>changetype.c</EM>.
+
+<P>
+void G3d_compareFiles(char *f1, char *mapset1, char *f2, char *mapset2)
+Compares the cell-values of file <EM>f1</EM> in mapset
+<EM>mapset1</EM> and file <EM>f2</EM> in mapset <EM>mapset2</EM>.
+The values are compared up to precision.
+Terminates in error if the files don't match.
+This function uses the more advanced features of the cache.
+
+<P>
+The source code can be found in <EM>filecompare.c</EM>.
+
+<P>
+void G3d_getBlock(void *map, int x0, int y0, int z0, int nx, int ny,
+int nz, char *block,  int type)
+Copies the cells contained in the block (cube) with vertices 
+<EM>(x0, y0, z0)</EM> and <EM>(x0 + nx - 1, y0 + ny - 1, z0 + nz - 1)</EM>
+into <EM>block</EM>. The cell-values in <EM>block</EM> are of <EM>type</EM>.
+
+<P>
+The source code can be found in <EM>getblock.c</EM>.
+
+<P>
+void G3d_writeAscii(void *map, char *fname)
+Writes the cell-values of <EM>map</EM> in ascii format to file 
+<EM>fname</EM>. The values are organized by horizontal slices.
+
+
+<P>
+See \ref Compiling_and_Installing_GRASS_Modules for a complete 
+discussion of Makefiles.
+
+*/

Copied: grass/trunk/lib/raster3d/long.c (from rev 47531, grass/trunk/lib/raster3d/g3dlong.c)
===================================================================
--- grass/trunk/lib/raster3d/long.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/long.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,69 @@
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_longEncode(long *source, unsigned char *dst, int nofNums)
+{
+    long *src, d;
+    int eltLength, nBytes;
+    unsigned char *dstStop, tmp;
+
+    eltLength = G3D_LONG_LENGTH;
+    nBytes = 8;
+
+    d = 1;
+
+    while (eltLength--) {
+	dstStop = dst + nofNums;
+	src = source;
+
+	while (dst != dstStop) {
+	    tmp = ((*src++ / d) % 256);
+	    if (tmp != 0)
+		nBytes = G3D_MIN(nBytes, eltLength);
+	    *dst++ = tmp;
+	}
+
+	d *= 256;
+    }
+
+    return G3D_LONG_LENGTH - nBytes;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_longDecode(unsigned char *source, long *dst, int nofNums, int longNbytes)
+{
+    long *dest;
+    int eltLength;
+    unsigned char *srcStop;
+
+    eltLength = longNbytes;
+
+    source += nofNums * eltLength - 1;
+
+    eltLength--;
+    srcStop = source - nofNums;
+    dest = dst;
+    dest += nofNums - 1;
+    while (source != srcStop) {
+	*dest = *source--;
+	if ((eltLength >= G3D_LONG_LENGTH) && (*dest != 0))
+	    G3d_fatalError("G3d_longDecode: decoded long too long");
+	dest--;
+    }
+
+    while (eltLength--) {
+	srcStop = source - nofNums;
+	dest = dst;
+	dest += nofNums - 1;
+	while (source != srcStop) {
+	    *dest *= 256;
+	    *dest += *source--;
+	    if ((eltLength >= G3D_LONG_LENGTH) && (*dest != 0))
+		G3d_fatalError("G3d_longDecode: decoded long too long");
+	    dest--;
+	}
+    }
+}

Copied: grass/trunk/lib/raster3d/mapset.c (from rev 47531, grass/trunk/lib/raster3d/g3dmapset.c)
===================================================================
--- grass/trunk/lib/raster3d/mapset.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/mapset.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+void G3d_makeMapsetMapDirectory(const char *mapName)
+{
+    char buf[GNAME_MAX + sizeof(G3D_DIRECTORY) + 2];
+
+    sprintf(buf, "%s/%s", G3D_DIRECTORY, mapName);
+    G__make_mapset_element(buf);
+}

Copied: grass/trunk/lib/raster3d/mask.c (from rev 47531, grass/trunk/lib/raster3d/g3dmask.c)
===================================================================
--- grass/trunk/lib/raster3d/mask.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/mask.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,411 @@
+#include <stdio.h>
+#include <grass/gis.h>
+#include "G3d_intern.h"
+
+/*--------------------------------------------------------------------------*/
+
+/* the standard g3d file format is used to store the mask values. a NULL-value
+   is stored for values which are masked out and a "0." is stored for values 
+   which are not masked out. to improve compression, the precision is set to 
+   0 and RLE encoding is used.
+ */
+
+/*--------------------------------------------------------------------------*/
+
+static int G3d_maskMapExistsVar = 0;
+static G3D_Map *G3d_maskMap;
+
+/*--------------------------------------------------------------------------*/
+static void dummy(void)
+{
+    return;
+}
+
+
+static float G3D_MASKNUMmaskValue;
+
+/* Call to dummy() to match void return type of G3d_setNullValue() */
+#define G3D_MASKNUM(map,Xmask,Ymask,Zmask,VALUEmask,TYPEmask) \
+\
+   (G3D_MASKNUMmaskValue = G3d_getMaskFloat (map, Xmask, Ymask, Zmask), \
+    ((G3d_isNullValueNum (&G3D_MASKNUMmaskValue, FCELL_TYPE)) ? \
+      G3d_setNullValue (VALUEmask, 1, TYPEmask) : dummy()))
+
+/*--------------------------------------------------------------------------*/
+
+int G3d_maskClose()
+{
+    /* No Idea if this is correct return value */
+    if (!G3d_maskMapExistsVar)
+	return 1;
+
+    G3d_maskMapExistsVar = 0;
+
+    if (!G3d_closeCell(G3d_maskMap)) {
+	G3d_error("G3d_maskClose: error closing mask");
+
+	return 0;
+    }
+
+    return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns 1 if the 3d mask file exists.
+ *
+ *  \return int
+ */
+
+int G3d_maskFileExists(void)
+{
+    return G_find_file_misc(G3D_DIRECTORY, G3D_CELL_ELEMENT, G3D_MASK_MAP, G_mapset()) != NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+
+static int maskOpenOldCacheDefault = G3D_USE_CACHE_DEFAULT;
+
+int G3d_maskOpenOld(void)
+{
+    G3D_Region region;
+
+    /* No Idea if this is correct return value */
+    if (G3d_maskMapExistsVar)
+	return 1;
+
+    G3d_maskMapExistsVar = G3d_maskFileExists();
+
+    if (!G3d_maskMapExistsVar)
+	return 1;
+
+    if ((G3d_maskMap = G3d_openCellOld(G3D_MASK_MAP, G_mapset(),
+				       G3D_DEFAULT_WINDOW, FCELL_TYPE,
+				       maskOpenOldCacheDefault))
+	== NULL) {
+	G3d_error("G3d_maskOpenOld: cannot open mask");
+
+	return 0;
+    }
+
+    G3d_getRegionStructMap(G3d_maskMap, &region);
+    G3d_setWindowMap(G3d_maskMap, &region);
+
+    return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+
+static float G3d_getMaskFloat(G3D_Map * map, int x, int y, int z)
+{
+    double north, east, top;
+    float value;
+
+    north = ((double)map->window.rows - y - 0.5) / (double)map->window.rows *
+	(map->window.north - map->window.south) + map->window.south;
+    east = ((double)x + 0.5) / (double)map->window.cols *
+	(map->window.east - map->window.west) + map->window.west;
+    top = ((double)z + 0.5) / (double)map->window.depths *
+	(map->window.top - map->window.bottom) + map->window.bottom;
+
+    G3d_getRegionValue(G3d_maskMap, north, east, top, &value, FCELL_TYPE);
+    return value;
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  This function should be used to adjust the cache size used for the
+ * 3d-mask. First the open 3d-mask is closed and then opened again with 
+ * a cache size as specified with <em>cache</em>.
+ *  
+ *  \param cache
+ *  \return 1 ... if successful
+ *          0 ... otherwise.
+ */
+
+int G3d_maskReopen(int cache)
+{
+    int tmp;
+
+    if (G3d_maskMapExistsVar)
+	if (!G3d_maskClose()) {
+	    G3d_error("G3d_maskReopen: error closing mask");
+
+	    return 0;
+	}
+
+    tmp = maskOpenOldCacheDefault;
+    maskOpenOldCacheDefault = cache;
+
+    if (!G3d_maskOpenOld()) {
+	G3d_error("G3d_maskReopen: error opening mask");
+
+	return 0;
+    }
+
+    maskOpenOldCacheDefault = tmp;
+    return 1;
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns 1 if the cell with cell-coordinates <em>(x, y, z)</em> is masked
+ *  out. Returns 0 otherwise.
+ *
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return int
+ */
+
+int G3d_isMasked(G3D_Map * map, int x, int y, int z)
+{
+    if (!G3d_maskMapExistsVar)
+	return 0;
+
+    G3D_MASKNUMmaskValue = G3d_getMaskFloat(map, x, y, z);
+    return (G3d_isNullValueNum(&G3D_MASKNUMmaskValue, FCELL_TYPE));
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Replaces the value stored in <em>value</em> with the NULL-value if 
+ * <em>G3d_isMasked (x, y, z)</em> returns 1. Does nothing otherwise.
+ * <em>value</em> is assumed to be of<em>type</em>.
+ *
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void G3d_maskNum(G3D_Map * map, int x, int y, int z, void *value, int type)
+{
+    if (!G3d_maskMapExistsVar)
+	return;
+    G3D_MASKNUM(map, x, y, z, value, type);
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Same as <em>G3d_maskNum (x, y, z, value, FCELL_TYPE)</em>.
+ *
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \return void
+ */
+
+void G3d_maskFloat(G3D_Map * map, int x, int y, int z, float *value)
+{
+    if (!G3d_maskMapExistsVar)
+	return;
+    G3D_MASKNUM(map, x, y, z, value, FCELL_TYPE);
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Same as <em>G3d_maskNum (x, y, z, value, DCELL_TYPE)</em>.
+ *
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \return void
+ */
+
+void G3d_maskDouble(G3D_Map * map, int x, int y, int z, double *value)
+{
+    if (!G3d_maskMapExistsVar)
+	return;
+    G3D_MASKNUM(map, x, y, z, value, DCELL_TYPE);
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Replaces the values stored in <em>tile</em> (with <em>tileIndex</em>) for 
+ *  which <em>G3d_isMasked</em> returns 1 with NULL-values. Does not change
+ *  the remaining values. The values are assumed to be of <em>type</em>. 
+ *  Whether replacement is performed or not only depends on location of the
+ *  cells of the tile and not on the status of the mask for <em>map</em>
+ *  (i.e. turned on or off).
+ *
+ *  \param map
+ *  \param tileIndex
+ *  \param tile
+ *  \param type
+ *  \return void
+ */
+
+void G3d_maskTile(G3D_Map * map, int tileIndex, void *tile, int type)
+{
+    int nofNum, rows, cols, depths, xRedundant, yRedundant, zRedundant;
+    int x, y, z, xLength, yLength, dx, dy, dz, length;
+
+    if (!G3d_maskMapExistsVar)
+	return;
+
+    nofNum = G3d_computeClippedTileDimensions(map, tileIndex,
+					      &rows, &cols, &depths,
+					      &xRedundant, &yRedundant,
+					      &zRedundant);
+    G3d_tileIndexOrigin(map, tileIndex, &x, &y, &z);
+
+    if (nofNum == map->tileSize) {
+	 /*AV*/
+	    /* BEGIN OF ORIGINAL CODE */
+	    /*
+	     *    G3d_getTileDimensionsMap (map, &rows, &cols, &depths);
+	     */
+	     /*AV*/
+	    /* BEGIN OF MY CODE */
+	    G3d_getTileDimensionsMap(map, &cols, &rows, &depths);
+	/* END OF MY CODE */
+	xRedundant = yRedundant = 0;
+    }
+
+    rows += y;
+    cols += x;
+    depths += z;
+    length = G3d_length(type);
+    xLength = xRedundant * length;
+    yLength = map->tileX * yRedundant * length;
+
+    for (dz = z; dz < depths; dz++) {
+	for (dy = y; dy < rows; dy++) {
+	    for (dx = x; dx < cols; dx++) {
+		G3D_MASKNUM(map, dx, dy, dz, tile, type);
+		tile += length;
+	    }
+
+	    tile += xLength;
+	}
+	tile += yLength;
+    }
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Turns on the mask for <em>map</em>. Do
+ * not invoke this function after the first tile has been read since the result
+ * might be inconsistent cell-values.
+ *
+ *  \param map
+ *  \return void
+ */
+
+void G3d_maskOn(G3D_Map * map)
+{
+    map->useMask = 1;
+}
+
+
+/*!
+ * \brief 
+ *
+ *  Turns off the mask for <em>map</em>.
+ * This is the default.  Do not invoke this function after the first tile has
+ * been read since the result might be inconsistent cell-values.
+ *
+ *  \param map
+ *  \return void
+ */
+
+void G3d_maskOff(G3D_Map * map)
+{
+    map->useMask = 0;
+}
+
+
+/*!
+ * \brief 
+ *
+ *  Returns 1 if the mask for <em>map</em>
+ * is turned on. Returns 0 otherwise.
+ *
+ *  \param map
+ *  \return int
+ */
+
+int G3d_maskIsOn(G3D_Map * map)
+{
+    return map->useMask;
+}
+
+
+/*!
+ * \brief 
+ *
+ * Returns 1 if the mask for <em>map</em> is turned off. Returns 0 otherwise.
+ *
+ *  \param map
+ *  \return int
+ */
+
+int G3d_maskIsOff(G3D_Map * map)
+{
+    return !map->useMask;
+}
+
+
+/*!
+ * \brief 
+ *
+ * Returns the name of the 3d mask file.
+ *
+ *  \return char * 
+ */
+
+const char *G3d_maskFile(void)
+{
+    return G3D_MASK_MAP;
+}
+
+
+/*!
+ * \brief 
+ *
+ * Returns 1 if the 3d mask is loaded.
+ *
+ *  \return int
+ */
+
+int G3d_maskMapExists(void)
+{
+    return G3d_maskMapExistsVar;
+}

Copied: grass/trunk/lib/raster3d/misc.c (from rev 47531, grass/trunk/lib/raster3d/g3dmisc.c)
===================================================================
--- grass/trunk/lib/raster3d/misc.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/misc.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,102 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#include <grass/raster.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_g3dType2cellType(int g3dType)
+{
+    if (g3dType == FCELL_TYPE)
+	return FCELL_TYPE;
+    return DCELL_TYPE;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_copyFloat2Double(const float *src, int offsSrc, double *dst, int offsDst,
+		     int nElts)
+{
+    int i;
+
+    src += offsSrc;
+    dst += offsDst;
+
+    for (i = 0; i < nElts; i++)
+	dst[i] = (double)src[i];
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_copyDouble2Float(const double *src, int offsSrc, float *dst, int offsDst,
+		     int nElts)
+{
+    int i;
+
+    src += offsSrc;
+    dst += offsDst;
+
+    for (i = 0; i < nElts; i++)
+	dst[i] = (float)src[i];
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst,
+	       int offsDst, int typeDst, int nElts)
+{
+    int eltLength;
+
+    if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
+	G3d_copyFloat2Double(src, offsSrc, dst, offsDst, nElts);
+	return;
+    }
+
+    if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
+	G3d_copyDouble2Float(src, offsSrc, dst, offsDst, nElts);
+	return;
+    }
+
+    eltLength = G3d_length(typeSrc);
+
+    src = G_incr_void_ptr(src, eltLength * offsSrc);
+    dst = G_incr_void_ptr(dst, eltLength * offsDst);
+
+    memcpy(dst, src, nElts * eltLength);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_length(int t)
+{
+    if (!G3D_IS_CORRECT_TYPE(t))
+	G3d_fatalError("G3d_length: invalid type");
+
+    if (t == FCELL_TYPE)
+	return sizeof(FCELL);
+    if (t == DCELL_TYPE)
+	return sizeof(DCELL);
+    return 0;
+}
+
+int G3d_externLength(int t)
+{
+    if (!G3D_IS_CORRECT_TYPE(t))
+	G3d_fatalError("G3d_externLength: invalid type");
+
+    if (t == FCELL_TYPE)
+	return G3D_XDR_FLOAT_LENGTH;
+    if (t == DCELL_TYPE)
+	return G3D_XDR_DOUBLE_LENGTH;
+    return 0;
+}

Copied: grass/trunk/lib/raster3d/null.c (from rev 47531, grass/trunk/lib/raster3d/g3dnull.c)
===================================================================
--- grass/trunk/lib/raster3d/null.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/null.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <grass/raster.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_isNullValueNum(const void *n, int type)
+{
+    if (type == FCELL_TYPE)
+	return Rast_is_f_null_value(n);
+    else
+	return Rast_is_d_null_value(n);
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Fills the vector pointed to by <em>c</em> with <em>nofElts</em> NULL-values
+ * of <em>type</em>.
+ *
+ *  \param c
+ *  \param nofElts
+ *  \param type
+ *  \return void
+ */
+
+void G3d_setNullValue(void *c, int nofElts, int type)
+{
+    if (type == FCELL_TYPE) {
+	Rast_set_f_null_value((float *)c, nofElts);
+	return;
+    }
+
+    Rast_set_d_null_value((double *)c, nofElts);
+}

Copied: grass/trunk/lib/raster3d/open.c (from rev 47531, grass/trunk/lib/raster3d/g3dopen.c)
===================================================================
--- grass/trunk/lib/raster3d/open.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/open.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,324 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <grass/G3d.h>
+#include <grass/glocale.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+void *G3d_openCellOldNoHeader(const char *name, const char *mapset)
+{
+    G3D_Map *map;
+    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+
+    G3d_initDefaults();
+
+    if (!G3d_maskOpenOld()) {
+	G3d_error(_("G3d_openCellOldNoHeader: error in G3d_maskOpenOld"));
+	return (void *)NULL;
+    }
+
+    map = G3d_malloc(sizeof(G3D_Map));
+    if (map == NULL) {
+	G3d_error(_("G3d_openCellOldNoHeader: error in G3d_malloc"));
+	return (void *)NULL;
+    }
+
+    G_unqualified_name(name, mapset, xname, xmapset);
+
+    map->fileName = G_store(xname);
+    map->mapset = G_store(xmapset);
+
+    map->data_fd = G_open_old_misc(G3D_DIRECTORY, G3D_CELL_ELEMENT, xname, xmapset);
+    if (map->data_fd < 0) {
+	G3d_error(_("G3d_openCellOldNoHeader: error in G_open_old"));
+	return (void *)NULL;
+    }
+
+    G3d_range_init(map);
+    G3d_maskOff(map);
+
+    return map;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Opens existing g3d-file <em>name</em> in <em>mapset</em>.
+ * Tiles are stored in memory with <em>type</em> which must be any of FCELL_TYPE,
+ * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
+ * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+ * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+ * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+ * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt> (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
+ * specifies the number of tiles buffered in the cache.  <em>window</em> sets the
+ * window-region for the map. It is either a pointer to a window structure or
+ * G3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
+ * set via <tt>G3d_setWindow ()</tt> (cf.{g3d:G3d.setWindow}).
+ * To modify the window for the map after it has already been opened use
+ * <tt>G3d_setWindowMap ()</tt> (cf.{g3d:G3d.setWindowMap}).
+ * Returns a pointer to the cell structure ... if successful, NULL ...
+ * otherwise.
+ *
+ *  \param name
+ *  \param mapset
+ *  \param window
+ *  \param type
+ *  \param cache
+ *  \return void * 
+ */
+
+void *G3d_openCellOld(const char *name, const char *mapset,
+		      G3D_Region * window, int typeIntern, int cache)
+{
+    G3D_Map *map;
+    int proj, zone;
+    int compression, useRle, useLzw, type, tileX, tileY, tileZ;
+    int rows, cols, depths, precision;
+    double ew_res, ns_res, tb_res;
+    int nofHeaderBytes, dataOffset, useXdr, hasIndex;
+    char *ltmp, *unit;
+    double north, south, east, west, top, bottom;
+
+    map = G3d_openCellOldNoHeader(name, mapset);
+    if (map == NULL) {
+	G3d_error(_("G3d_openCellOld: error in G3d_openCellOldNoHeader"));
+	return (void *)NULL;
+    }
+
+    if (lseek(map->data_fd, (long)0, SEEK_SET) == -1) {
+	G3d_error(_("G3d_openCellOld: can't rewind file"));
+	return (void *)NULL;
+    }
+
+    if (!G3d_readHeader(map,
+			&proj, &zone,
+			&north, &south, &east, &west, &top, &bottom,
+			&rows, &cols, &depths,
+			&ew_res, &ns_res, &tb_res,
+			&tileX, &tileY, &tileZ,
+			&type, &compression, &useRle, &useLzw,
+			&precision, &dataOffset, &useXdr, &hasIndex, &unit)) {
+	G3d_error(_("G3d_openCellOld: error in G3d_readHeader"));
+	return 0;
+    }
+
+    if (window == G3D_DEFAULT_WINDOW)
+	window = G3d_windowPtr();
+
+    if (proj != window->proj) {
+	G3d_error(_("G3d_openCellOld: projection does not match window projection"));
+	return (void *)NULL;
+    }
+    if (zone != window->zone) {
+	G3d_error(_("G3d_openCellOld: zone does not match window zone"));
+	return (void *)NULL;
+    }
+
+    map->useXdr = useXdr;
+
+    if (hasIndex) {
+	/* see G3D_openCell_new () for format of header */
+	if ((!G3d_readInts(map->data_fd, map->useXdr,
+			   &(map->indexLongNbytes), 1)) ||
+	    (!G3d_readInts(map->data_fd, map->useXdr,
+			   &(map->indexNbytesUsed), 1))) {
+	    G3d_error(_("G3d_openCellOld: can't read header"));
+	    return (void *)NULL;
+	}
+
+	/* if our long is to short to store offsets we can't read the file */
+	if (map->indexNbytesUsed > sizeof(long))
+	    G3d_fatalError(_("G3d_openCellOld: index does not fit into long"));
+
+	ltmp = G3d_malloc(map->indexLongNbytes);
+	if (ltmp == NULL) {
+	    G3d_error(_("G3d_openCellOld: error in G3d_malloc"));
+	    return (void *)NULL;
+	}
+
+	/* convert file long to long */
+	if (read(map->data_fd, ltmp, map->indexLongNbytes) !=
+	    map->indexLongNbytes) {
+	    G3d_error(_("G3d_openCellOld: can't read header"));
+	    return (void *)NULL;
+	}
+	G3d_longDecode(ltmp, &(map->indexOffset), 1, map->indexLongNbytes);
+	G3d_free(ltmp);
+    }
+
+    nofHeaderBytes = dataOffset;
+
+    if (typeIntern == G3D_TILE_SAME_AS_FILE)
+	typeIntern = type;
+
+    if (!G3d_fillHeader(map, G3D_READ_DATA, compression, useRle, useLzw,
+			type, precision, cache,
+			hasIndex, map->useXdr, typeIntern,
+			nofHeaderBytes, tileX, tileY, tileZ,
+			proj, zone,
+			north, south, east, west, top, bottom,
+			rows, cols, depths, ew_res, ns_res, tb_res, unit)) {
+	G3d_error(_("G3d_openCellOld: error in G3d_fillHeader"));
+	return (void *)NULL;
+    }
+
+    G3d_regionCopy(&(map->window), window);
+    G3d_adjustRegion(&(map->window));
+    G3d_getNearestNeighborFunPtr(&(map->resampleFun));
+
+    return map;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
+ * are stored in memory with <em>type</em> which must be one of FCELL_TYPE,
+ * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
+ * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+ * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+ * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+ * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
+ * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
+ * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
+ * the 3d region.  
+ * Returns a pointer to the cell structure ... if successful,
+ * NULL ... otherwise.
+ *
+ *  \param name
+ *  \param type
+ *  \param cache
+ *  \param region
+ *  \return void * 
+ */
+
+void *G3d_openCellNew(const char *name, int typeIntern, int cache,
+		      G3D_Region * region)
+{
+    G3D_Map *map;
+    int nofHeaderBytes, dummy = 0, compression, precision;
+    long ldummy = 0;
+    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+
+    G3d_initDefaults();
+    if (!G3d_maskOpenOld()) {
+	G3d_error(_("G3d_openCellNew: error in G3d_maskOpenOld"));
+	return (void *)NULL;
+    }
+
+    compression = g3d_do_compression;
+    precision = g3d_precision;
+
+    map = G3d_malloc(sizeof(G3D_Map));
+    if (map == NULL) {
+	G3d_error(_("G3d_openCellNew: error in G3d_malloc"));
+	return (void *)NULL;
+    }
+
+    if (G_unqualified_name(name, G_mapset(), xname, xmapset) < 0) {
+	G_warning(_("map <%s> is not in the current mapset"), name);
+	return (void *)NULL;
+    }
+
+    map->fileName = G_store(xname);
+    map->mapset = G_store(xmapset);
+
+    map->tempName = G_tempfile();
+    map->data_fd = open(map->tempName, O_RDWR | O_CREAT | O_TRUNC, 0666);
+    if (map->data_fd < 0) {
+	G3d_error(_("G3d_openCellNew: could not open file"));
+	return (void *)NULL;
+    }
+
+    G3d_makeMapsetMapDirectory(map->fileName);
+
+    map->useXdr = G3D_USE_XDR;
+
+    if (g3d_file_type == FCELL_TYPE) {
+	if (precision > 23)
+	    precision = 23;	/* 32 - 8 - 1 */
+	else if (precision < -1)
+	    precision = 0;
+    }
+    else if (precision > 52)
+	precision = 52;		/* 64 - 11 - 1 */
+    else if (precision < -1)
+	precision = 0;
+
+    /* no need to write trailing zeros */
+    if ((typeIntern == FCELL_TYPE) && (g3d_file_type == DCELL_TYPE)) {
+	if (precision == -1)
+	    precision = 23;
+	else
+	    precision = G3D_MIN(precision, 23);
+    }
+
+    if (compression == G3D_NO_COMPRESSION)
+	precision = G3D_MAX_PRECISION;
+    if (compression == G3D_COMPRESSION)
+	map->useXdr = G3D_USE_XDR;
+
+    if (G3D_HAS_INDEX) {
+	map->indexLongNbytes = sizeof(long);
+
+	/* at the beginning of the file write */
+	/*      nof bytes of "long" */
+	/*      max nof bytes used for index */
+	/*      position of index in file */
+	/* the index is appended at the end of the file at closing time. since */
+	/* we do not know this position yet we write dummy values */
+
+	if ((!G3d_writeInts(map->data_fd, map->useXdr,
+			    &(map->indexLongNbytes), 1)) ||
+	    (!G3d_writeInts(map->data_fd, map->useXdr, &dummy, 1))) {
+	    G3d_error(_("G3d_openCellNew: can't write header"));
+	    return (void *)NULL;
+	}
+	if (write(map->data_fd, &ldummy, map->indexLongNbytes) !=
+	    map->indexLongNbytes) {
+	    G3d_error(_("G3d_openCellNew: can't write header"));
+	    return (void *)NULL;
+	}
+    }
+
+    /* can't use a constant since this depends on sizeof (long) */
+    nofHeaderBytes = lseek(map->data_fd, (long)0, SEEK_CUR);
+
+    G3d_range_init(map);
+    G3d_adjustRegion(region);
+
+    if (!G3d_fillHeader(map, G3D_WRITE_DATA, compression,
+			g3d_do_rle_compression, g3d_do_lzw_compression,
+			g3d_file_type, precision, cache, G3D_HAS_INDEX,
+			map->useXdr, typeIntern, nofHeaderBytes,
+			g3d_tile_dimension[0], g3d_tile_dimension[1],
+			g3d_tile_dimension[2],
+			region->proj, region->zone,
+			region->north, region->south, region->east,
+			region->west, region->top, region->bottom,
+			region->rows, region->cols, region->depths,
+			region->ew_res, region->ns_res, region->tb_res,
+			g3d_unit_default)) {
+	G3d_error(_("G3d_openCellNew: error in G3d_fillHeader"));
+	return (void *)NULL;
+    }
+
+    /*Set the map window to the map region */
+    G3d_regionCopy(&(map->window), region);
+    /*Set the resampling function to nearest neighbor for data access */
+    G3d_getNearestNeighborFunPtr(&(map->resampleFun));
+
+    G3d_maskOff(map);
+
+    return (void *)map;
+}

Copied: grass/trunk/lib/raster3d/open2.c (from rev 47531, grass/trunk/lib/raster3d/g3dopen2.c)
===================================================================
--- grass/trunk/lib/raster3d/open2.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/open2.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,122 @@
+#include <grass/gis.h>
+#include <grass/G3d.h>
+
+/*----------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
+ * are stored in memory with <em>typeIntern</em> which must be one of FCELL_TYPE,
+ * DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
+ * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+ * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+ * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+ * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
+ * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
+ * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
+ * the 3d region.  
+ * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
+ * The methods for compression can be specified LZW or RLE. The digits of the floating point mantissa
+ * can be specified. In case of FCELL_TYPE 0-23 and 0-52 in case of DCELL_TYPE. 
+ * The number cells in X, Y and Z direction defines the size of each tile.
+ * Returns a pointer to the cell structure ... if successful,
+ * NULL ... otherwise.
+ *
+ *  \param name The name of the map
+ *  \param typeIntern The internal storage type for in memory chached tiles
+ *  \param cache The type of the caching
+ *  \param region The region of the map
+ *  \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
+ *  \param doLzw Use the LZW compression algorithm  
+ *  \param doRle Use the Run-Length-Encoding algroithm for compression
+ *  \param precision The precision used for the mantissa (0 - 52) or G3D_MAX_PRECISION
+ *  \param tileX The number of cells in X direction of a tile
+ *  \param tileY The number of cells in Y direction of a tile
+ *  \param tileZ The number of cells in Z direction of a tile
+ *  \return void * 
+ */
+
+
+void *G3d_openNewParam(const char *name, int typeIntern, int cache,
+		       G3D_Region * region, int type, int doLzw, int doRle,
+		       int precision, int tileX, int tileY, int tileZ)
+{
+    void *map;
+    int oldCompress, oldLzw, oldRle, oldPrecision, oldTileX, oldTileY,
+	oldTileZ;
+    int oldType;
+
+    G3d_initDefaults();
+
+    G3d_getCompressionMode(&oldCompress, &oldLzw, &oldRle, &oldPrecision);
+    G3d_setCompressionMode(oldCompress, doLzw, doRle, precision);
+
+    G3d_getTileDimension(&oldTileX, &oldTileY, &oldTileZ);
+    G3d_setTileDimension(tileX, tileY, tileZ);
+
+    oldType = G3d_getFileType();
+    G3d_setFileType(type);
+
+    map = G3d_openCellNew(name, typeIntern, cache, region);
+
+    G3d_setCompressionMode(oldCompress, oldLzw, oldRle, oldPrecision);
+    G3d_setTileDimension(oldTileX, oldTileY, oldTileZ);
+    G3d_setFileType(oldType);
+
+    return map;
+}
+
+/*----------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Opens new g3d-file with <em>name</em> in the current mapset. This method tries to compute 
+ * optimal tile size based on the number of rows, cols and depths and the maximum allowed tile size in KB. 
+ * Tiles are stored in memory using G3D_TILE_SAME_AS_FILE method. <em>cache</em> specifies the
+ * cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
+ * G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
+ * G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
+ * G3D_USE_CACHE_XYZ, the result of <tt>G3d_cacheSizeEncode ()</tt>
+ * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
+ * specifies the number of tiles buffered in the cache.  <em>region</em> specifies
+ * the 3d region.  
+ * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
+ * Returns a pointer to the cell structure ... if successful,
+ * NULL ... otherwise.
+ *
+ *  \param name The name of the map
+ *  \param cache The type of the caching
+ *  \param region The region of the map
+ *  \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
+ *  \param maxSize The maximum size of a tile in kilo bytes
+ *  \return void * 
+ */
+
+
+void *G3d_openNewOptTileSize(const char *name, int cache, G3D_Region * region, int type, int maxSize)
+{
+    void *map;
+    int oldTileX, oldTileY, oldTileZ, oldType;
+    int tileX, tileY, tileZ;
+
+    G3d_initDefaults();
+
+
+    G3d_getTileDimension(&oldTileX, &oldTileY, &oldTileZ);
+    
+    G3d_computeOptimalTileDimension(region, type, &tileX, &tileY, &tileZ, maxSize);
+
+    G3d_setTileDimension(tileX, tileY, tileZ);
+
+    oldType = G3d_getFileType();
+    G3d_setFileType(type);
+
+    map = G3d_openCellNew(name, G3D_TILE_SAME_AS_FILE, cache, region);
+
+    G3d_setTileDimension(oldTileX, oldTileY, oldTileZ);
+    G3d_setFileType(oldType);
+
+    return map;
+}

Copied: grass/trunk/lib/raster3d/param.c (from rev 47531, grass/trunk/lib/raster3d/g3dparam.c)
===================================================================
--- grass/trunk/lib/raster3d/param.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/param.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,157 @@
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "G3d_intern.h"
+
+/*----------------------------------------------------------------------------*/
+
+typedef struct
+{
+
+    struct Option *type;
+    struct Option *precision;
+    struct Option *compression;
+    struct Option *dimension;
+    struct Option *cache;
+
+} G3d_paramType;
+
+/*----------------------------------------------------------------------------*/
+
+static G3d_paramType *param;
+
+
+/*!
+ * \brief 
+ *
+ * Initializes a parameter
+ * structure for the subset of command line arguments which lets the user
+ * overwrite the default properties of the new file.  Applications are
+ * encouraged to use this function in order to provide a uniform style.  The
+ * command line arguments provided are the <em>type</em> of the cell values, the
+ * <em>precision</em>, the properties of the <em>compression</em>, and the dimension
+ * of the tiles (<em>tiledimension</em>). Every of these values defaults to the
+ * value described in G3D Defaults.
+ * This function has to be used in conjunction with
+ * G3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
+ *
+ *  \return void
+ */
+
+void G3d_setStandard3dInputParams()
+{
+    param = G3d_malloc(sizeof(G3d_paramType));
+
+    param->type = G_define_standard_option(G_OPT_R3_TYPE);
+
+    param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
+
+    param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
+
+    param->dimension = G_define_standard_option(G_OPT_R3_TILE_DIMENSION);
+}
+
+/*----------------------------------------------------------------------------*/
+
+int G3d_getStandard3dParams(int *useTypeDefault, int *type,
+			    int *useLzwDefault, int *doLzw,
+			    int *useRleDefault, int *doRle,
+			    int *usePrecisionDefault, int *precision,
+			    int *useDimensionDefault, int *tileX, int *tileY,
+			    int *tileZ)
+{
+    int doCompress;
+
+    *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
+    *usePrecisionDefault = *useDimensionDefault = 0;
+
+    G3d_initDefaults();
+
+    if (strcmp(param->type->answer, "double") == 0)
+	*type = DCELL_TYPE;
+    else if (strcmp(param->type->answer, "float") == 0)
+	*type = FCELL_TYPE;
+    else {
+	*type = G3d_getFileType();
+	*useTypeDefault = 1;
+    }
+
+    G3d_getCompressionMode(&doCompress, doLzw, doRle, precision);
+
+    if (strcmp(param->precision->answer, "default") != 0) {
+	if (strcmp(param->precision->answer, "max") == 0)
+	    *precision = -1;
+	else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
+		 (*precision < 0)) {
+	    G3d_error(_("G3d_getStandard3dParams: precision value invalid"));
+	    return 0;
+	}
+    }
+    else
+	*usePrecisionDefault = 1;
+
+
+    if (strcmp(param->compression->answer, "default") != 0) {
+	if (strcmp(param->compression->answer, "rle") == 0) {
+	    *doRle = G3D_USE_RLE;
+	    *doLzw = G3D_NO_LZW;
+	}
+	else if (strcmp(param->compression->answer, "lzw") == 0) {
+	    *doRle = G3D_NO_RLE;
+	    *doLzw = G3D_USE_LZW;
+	}
+	else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
+	    *doRle = G3D_USE_RLE;
+	    *doLzw = G3D_USE_LZW;
+	}
+	else {
+	    *doRle = G3D_NO_RLE;
+	    *doLzw = G3D_NO_LZW;
+	}
+    }
+    else
+	*useLzwDefault = *useRleDefault = 1;
+
+    G3d_getTileDimension(tileX, tileY, tileZ);
+    if (strcmp(param->dimension->answer, "default") != 0) {
+	if (sscanf(param->dimension->answer, "%dx%dx%d",
+		   tileX, tileY, tileZ) != 3) {
+	    G3d_error(_("G3d_getStandard3dParams: tile dimension value invalid"));
+	    return 0;
+	}
+    }
+    else
+	*useDimensionDefault = 1;
+
+    G3d_free(param);
+
+    return 1;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static struct Option *windowParam = NULL;
+
+void G3d_setWindowParams(void)
+{
+    windowParam = G_define_option();
+    windowParam->key = "region3";
+    windowParam->type = TYPE_STRING;
+    windowParam->required = NO;
+    windowParam->multiple = NO;
+    windowParam->answer = NULL;
+    windowParam->description = _("Window replacing the default");
+}
+
+/*----------------------------------------------------------------------------*/
+
+char *G3d_getWindowParams(void)
+{
+    if (windowParam == NULL)
+	return NULL;
+    if (windowParam->answer == NULL)
+	return NULL;
+    if (strcmp(windowParam->answer, G3D_WINDOW_ELEMENT) == 0)
+	return G_store(G3D_WINDOW_ELEMENT);
+    return G_store(windowParam->answer);
+}

Copied: grass/trunk/lib/raster3d/putvalue.c (from rev 47531, grass/trunk/lib/raster3d/g3dputvalue.c)
===================================================================
--- grass/trunk/lib/raster3d/putvalue.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/putvalue.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,117 @@
+#include <grass/raster.h>
+#include "G3d_intern.h"
+
+
+/*!
+ * \brief 
+ *
+ * Is equivalent to G3d_putValue (map, x, y, z, &value, FCELL_TYPE).
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \return int
+ */
+
+int G3d_putFloat(G3D_Map * map, int x, int y, int z, float value)
+{
+    int tileIndex, offs;
+    float *tile;
+
+    if (map->typeIntern == DCELL_TYPE) {
+	if (!G3d_putDouble(map, x, y, z, (double)value)) {
+	    G3d_error("G3d_putFloat: error in G3d_putDouble");
+	    return 0;
+	}
+	return 1;
+    }
+
+    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
+    tile = (float *)G3d_getTilePtr(map, tileIndex);
+    if (tile == NULL) {
+	G3d_error("G3d_putFloat: error in G3d_getTilePtr");
+	return 0;
+    }
+
+    tile[offs] = value;
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Is equivalent to G3d_putValue (map, x, y, z, &value, DCELL_TYPE).
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \return int
+ */
+
+int G3d_putDouble(G3D_Map * map, int x, int y, int z, double value)
+{
+    int tileIndex, offs;
+    double *tile;
+
+    if (map->typeIntern == FCELL_TYPE) {
+	if (!G3d_putFloat(map, x, y, z, (float)value)) {
+	    G3d_error("G3d_putDouble: error in G3d_putFloat");
+	    return 0;
+	}
+	return 1;
+    }
+
+    G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
+    tile = (double *)G3d_getTilePtr(map, tileIndex);
+    if (tile == NULL) {
+	G3d_error("G3d_putDouble: error in G3d_getTilePtr");
+	return 0;
+    }
+
+    tile[offs] = value;
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * After converting <em>*value</em> of <em>type</em> into the type specified
+ * at the initialization time (i.e. <em>typeIntern</em>) this function writes the
+ * value into the tile buffer corresponding to cell-coordinate <em>(x, y, z)</em>.
+ *
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param value
+ *  \param type
+ *  \return 1 ... if successful,  
+ *          0 ... otherwise.
+ */
+
+int
+G3d_putValue(G3D_Map * map, int x, int y, int z, const void *value, int type)
+{
+    if (type == FCELL_TYPE) {
+	if (!G3d_putFloat(map, x, y, z, *((float *)value))) {
+	    G3d_error("G3d_putValue: error in G3d_putFloat");
+	    return 0;
+	}
+	return 1;
+    }
+
+    if (!G3d_putDouble(map, x, y, z, *((double *)value))) {
+	G3d_error("G3d_putValue: error in G3d_putDouble");
+	return 0;
+    }
+    return 1;
+}

Copied: grass/trunk/lib/raster3d/range.c (from rev 47531, grass/trunk/lib/raster3d/g3drange.c)
===================================================================
--- grass/trunk/lib/raster3d/range.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/range.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,222 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_range_updateFromTile(G3D_Map * map, const void *tile, int rows, int cols,
+			 int depths, int xRedundant, int yRedundant,
+			 int zRedundant, int nofNum, int type)
+{
+    int y, z, cellType;
+    struct FPRange *range;
+
+    range = &(map->range);
+    cellType = G3d_g3dType2cellType(type);
+
+    if (nofNum == map->tileSize) {
+	Rast_row_update_fp_range(tile, map->tileSize, range, cellType);
+	return;
+    }
+
+    if (xRedundant) {
+	for (z = 0; z < depths; z++) {
+	    for (y = 0; y < rows; y++) {
+		Rast_row_update_fp_range(tile, cols, range, cellType);
+		tile = G_incr_void_ptr(tile, map->tileX * G3d_length(type));
+	    }
+	    if (yRedundant)
+		tile =
+		    G_incr_void_ptr(tile,
+				    map->tileX * yRedundant *
+				    G3d_length(type));
+	}
+	return;
+    }
+
+    if (yRedundant) {
+	for (z = 0; z < depths; z++) {
+	    Rast_row_update_fp_range(tile, map->tileX * rows, range, cellType);
+	    tile = G_incr_void_ptr(tile, map->tileXY * G3d_length(type));
+	}
+	return;
+    }
+
+    Rast_row_update_fp_range(tile, map->tileXY * depths, range, cellType);
+}
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_readRange(const char *name, const char *mapset, struct FPRange *drange)
+ /* adapted from Rast_read_fp_range */
+{
+    int fd;
+    char xdr_buf[100];
+    DCELL dcell1, dcell2;
+    XDR xdr_str;
+
+    Rast_init_fp_range(drange);
+
+    fd = -1;
+
+    fd = G_open_old_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name, mapset);
+    if (fd < 0) {
+	G_warning(_("Unable to open range file for [%s in %s]"), name, mapset);
+	return -1;
+    }
+
+    if (read(fd, xdr_buf, 2 * G3D_XDR_DOUBLE_LENGTH) != 2 * G3D_XDR_DOUBLE_LENGTH) {
+	close(fd);
+	G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
+	return 2;
+    }
+
+    xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
+		  XDR_DECODE);
+
+    /* if the f_range file exists, but empty */
+    if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2)) {
+	close(fd);
+	G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
+	return -1;
+    }
+
+    Rast_update_fp_range(dcell1, drange);
+    Rast_update_fp_range(dcell2, drange);
+    close(fd);
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Loads the range into the range structure of <em>map</em>.
+ *
+ *  \param map
+ *  \return 1 ... if successful
+ *          0 ... otherwise.
+ */
+
+int G3d_range_load(G3D_Map * map)
+{
+    if (map->operation == G3D_WRITE_DATA)
+	return 1;
+    if (G3d_readRange(map->fileName, map->mapset, &(map->range)) == -1) {
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Returns in <em>min</em> and <em>max</em> the minimum and maximum values of
+ * the range.
+ *
+ *  \param map
+ *  \param min
+ *  \param max
+ *  \return void
+ */
+
+void G3d_range_min_max(G3D_Map * map, double *min, double *max)
+{
+    Rast_get_fp_range_min_max(&(map->range), min, max);
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int writeRange(const char *name, struct FPRange *range)
+ /* adapted from Rast_write_fp_range */
+{
+    char xdr_buf[100];
+    int fd;
+    XDR xdr_str;
+
+    fd = G_open_new_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name);
+    if (fd < 0) {
+	G_warning(_("Unable to open range file for <%s>"), name);
+	return -1;
+    }
+
+    if (range->first_time) {
+	/* if range hasn't been updated, write empty file meaning NULLs */
+	close(fd);
+	return 0;
+    }
+
+    xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
+		  XDR_ENCODE);
+
+    if (!xdr_double(&xdr_str, &(range->min)))
+	goto error;
+    if (!xdr_double(&xdr_str, &(range->max)))
+	goto error;
+
+    if (write(fd, xdr_buf, G3D_XDR_DOUBLE_LENGTH * 2) != G3D_XDR_DOUBLE_LENGTH * 2)
+	goto error;
+
+    close(fd);
+    return 0;
+
+  error:
+    close(fd);
+    G_remove_misc(G3D_DIRECTORY, G3D_RANGE_ELEMENT, name);	/* remove the old file with this name */
+    G_warning("can't write range file for [%s in %s]", name, G_mapset());
+    return -1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Writes the range which is stored in the range structure of <em>map</em>. 
+ * (This function is invoked automatically when a new file is closed).
+ *
+ *  \param map
+ *  \return 1 ... if successful
+ *          0 ... otherwise.
+ */
+
+int G3d_range_write(G3D_Map * map)
+{
+    char path[GPATH_MAX];
+
+    G3d_filename(path, G3D_RANGE_ELEMENT, map->fileName, map->mapset);
+    remove(path);
+
+    if (writeRange(map->fileName, &(map->range)) == -1) {
+	G3d_error("G3d_closeCellNew: error in writeRange");
+	return 0;
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+int G3d_range_init(G3D_Map * map)
+{
+    Rast_init_fp_range(&(map->range));
+    return 0;
+}

Copied: grass/trunk/lib/raster3d/region.c (from rev 47531, grass/trunk/lib/raster3d/g3dregion.c)
===================================================================
--- grass/trunk/lib/raster3d/region.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/region.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,364 @@
+#include <stdio.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/G3d.h>
+
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
+ *
+ *  \param region3d
+ *  \param region2d
+ *  \return void
+ */
+
+void G3d_extract2dRegion(G3D_Region * region3d, struct Cell_head *region2d)
+{
+    region2d->proj = region3d->proj;
+    region2d->zone = region3d->zone;
+
+    region2d->north = region3d->north;
+    region2d->south = region3d->south;
+    region2d->east = region3d->east;
+    region2d->west = region3d->west;
+
+    region2d->rows = region3d->rows;
+    region2d->cols = region3d->cols;
+
+    region2d->ns_res = region3d->ns_res;
+    region2d->ew_res = region3d->ew_res;
+}
+
+/*!
+ * \brief 
+ *
+ *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
+ *
+ *  \param region3d
+ *  \param region2d
+ *  \return void
+ */
+
+void G3d_regionToCellHead(G3D_Region * region3d, struct Cell_head *region2d)
+{
+    region2d->proj = region3d->proj;
+    region2d->zone = region3d->zone;
+
+    region2d->north = region3d->north;
+    region2d->south = region3d->south;
+    region2d->east = region3d->east;
+    region2d->west = region3d->west;
+    region2d->top = region3d->top;
+    region2d->bottom = region3d->bottom;
+
+    region2d->rows = region3d->rows;
+    region2d->rows3 = region3d->rows;
+    region2d->cols = region3d->cols;
+    region2d->cols3 = region3d->cols;
+    region2d->depths = region3d->depths;
+
+    region2d->ns_res = region3d->ns_res;
+    region2d->ns_res3 = region3d->ns_res;
+    region2d->ew_res = region3d->ew_res;
+    region2d->ew_res3 = region3d->ew_res;
+    region2d->tb_res = region3d->tb_res;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Replaces the <em>2d</em> portion of <em>region3d</em> with the
+ * values stored in <em>region2d</em>.
+ *
+ *  \param region2d
+ *  \param region3d
+ *  \return void
+ */
+
+void
+G3d_incorporate2dRegion(struct Cell_head *region2d, G3D_Region * region3d)
+{
+    region3d->proj = region2d->proj;
+    region3d->zone = region2d->zone;
+
+    region3d->north = region2d->north;
+    region3d->south = region2d->south;
+    region3d->east = region2d->east;
+    region3d->west = region2d->west;
+
+    region3d->rows = region2d->rows;
+    region3d->cols = region2d->cols;
+
+    region3d->ns_res = region2d->ns_res;
+    region3d->ew_res = region2d->ew_res;
+}
+
+/*!
+ * \brief 
+ *
+ * Replaces the <em>2d</em> portion of <em>region3d</em> with the
+ * values stored in <em>region2d</em>.
+ *
+ *  \param region2d
+ *  \param region3d
+ *  \return void
+ */
+
+void
+G3d_regionFromToCellHead(struct Cell_head *region2d, G3D_Region * region3d)
+{
+    region3d->proj = region2d->proj;
+    region3d->zone = region2d->zone;
+
+    region3d->north = region2d->north;
+    region3d->south = region2d->south;
+    region3d->east = region2d->east;
+    region3d->west = region2d->west;
+    region3d->top = region2d->top;
+    region3d->bottom = region2d->bottom;
+
+    region3d->rows = region2d->rows3;
+    region3d->cols = region2d->cols3;
+    region3d->depths = region2d->depths;
+
+    region3d->ns_res = region2d->ns_res3;
+    region3d->ew_res = region2d->ew_res3;
+    region3d->tb_res = region2d->tb_res;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Computes an adjusts the resolutions in the region structure from the region
+ * boundaries and number of cells per dimension.
+ *
+ *  \param region
+ *  \return void
+ */
+
+void G3d_adjustRegion(G3D_Region * region)
+{
+    struct Cell_head region2d;
+
+    G3d_regionToCellHead(region, &region2d);
+    G_adjust_Cell_head3(&region2d, 1, 1, 1);
+    G3d_regionFromToCellHead(&region2d, region);
+
+    if (region->depths <= 0)
+	G3d_fatalError("G3d_adjustRegion: depths <= 0");
+    region->tb_res = (region->top - region->bottom) / region->depths;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Computes an adjusts the number of cells per dimension in the region
+ * structure from the region boundaries and resolutions.
+ *
+ *  \param region
+ *  \return void
+ */
+
+void G3d_adjustRegionRes(G3D_Region * region)
+{
+    struct Cell_head region2d;
+
+    G3d_regionToCellHead(region, &region2d);
+    G_adjust_Cell_head3(&region2d, 1, 1, 1);
+    G3d_regionFromToCellHead(&region2d, region);
+
+    if (region->tb_res <= 0)
+	G3d_fatalError("G3d_adjustRegionRes: tb_res <= 0");
+
+    region->depths = (region->top - region->bottom + region->tb_res / 2.0) /
+	region->tb_res;
+    if (region->depths == 0)
+	region->depths = 1;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Copies the values of <em>regionSrc</em> into <em>regionDst</em>.
+ *
+ *  \param regionDest
+ *  \param regionSrc
+ *  \return void
+ */
+
+void G3d_regionCopy(G3D_Region * regionDest, G3D_Region * regionSrc)
+{
+    *regionDest = *regionSrc;
+}
+
+
+/*---------------------------------------------------------------------------*/
+
+int
+G3d_readRegionMap(const char *name, const char *mapset, G3D_Region * region)
+{
+    char fullName[GPATH_MAX];
+    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+
+    if (G_name_is_fully_qualified(name, xname, xmapset))
+	G3d_filename(fullName, G3D_HEADER_ELEMENT, xname, xmapset);
+    else {
+	if (!mapset || !*mapset)
+	    mapset = G_find_grid3(name, "");
+	G3d_filename(fullName, G3D_HEADER_ELEMENT, name, mapset);
+    }
+    return G3d_readWindow(region, fullName);
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns 1 if region-coordinates <em>(north, west, bottom)</em> are
+ * inside the region of <em>map</em>. Returns 0 otherwise.
+ *
+ *  \param REgion
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \return int
+ */
+
+int G3d_isValidLocation(G3D_Region *region, double north, double east, double top)
+{
+    return ((north >= region->south) && (north <= region->north) &&
+	    (east >= region->west) && (east <= region->east) &&
+	    (((top >= region->bottom) && (top <= region->top)) ||
+	     ((top <= region->bottom) && (top >= region->top))));
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ *  Converts region-coordinates <em>(north, east,
+ *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return void
+ */
+
+void
+G3d_location2coord(G3D_Region *region, double north, double east, double top,
+		   int *x, int *y, int *z)
+{
+    double col, row, depth;
+    
+    col = (east - region->west) / (region->east -
+				      region->west) * (double)(region->cols);
+    row = (north - region->south) / (region->north -
+					region->south) * (double)(region->rows);
+    depth = (top - region->bottom) / (region->top -
+				       region->bottom) * (double)(region->depths);
+    
+    *x = (int)col;
+    /* Adjust row to start at the northern edge*/
+    *y = region->rows - (int)row - 1;
+    *z = (int)depth;
+        
+    G_debug(4, "G3d_location2coord x %i y %i z %i\n", *x, *y, *z);
+}
+
+
+/*!
+ * \brief 
+ *
+ *  Converts region-coordinates <em>(north, east,
+ *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
+ *  This function calls G3d_fatalError in case location is not in window.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return void
+ */
+
+void
+G3d_location2coord2(G3D_Region *region, double north, double east, double top,
+		   int *x, int *y, int *z)
+{
+    if (!G3d_isValidLocation(region, north, east, top))
+	G3d_fatalError("G3d_location2coord2: location not in region");
+
+    G3d_location2coord(region, north, east, top, x, y, z);
+}
+
+/*!
+ * \brief 
+ *
+ *  Converts cell-coordinates <em>(x, y, z)</em> into region-coordinates 
+ * <em>(north, east, top)</em>. 
+ *
+ *  * <b>Note:</b> x, y and z is a double:
+ *  - x+0.0 will return the easting for the western edge of the column.
+ *  - x+0.5 will return the easting for the center of the column.
+ *  - x+1.0 will return the easting for the eastern edge of the column.
+ * 
+ *  - y+0.0 will return the northing for the northern edge of the row.
+ *  - y+0.5 will return the northing for the center of the row.
+ *  - y+1.0 will return the northing for the southern edge of the row.
+ * 
+ *  - z+0.0 will return the top for the lower edge of the depth.
+ *  - z+0.5 will return the top for the center of the depth.
+ *  - z+1.0 will return the top for the upper edge of the column.
+ *
+ * <b>Note:</b> The result is a <i>double</i>. Casting it to an
+ * <i>int</i> will give the column, row and depth number.
+ * 
+ * 
+ *  \param map
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \return void
+ */
+
+void
+G3d_coord2location(G3D_Region * region, double x, double y, double z, double *north, double *east, double *top)
+{
+    *north = region->north - y * region->ns_res;
+    *east = region->west + x * region->ew_res;
+    *top = region->bottom + z * region->tb_res; 
+        
+    G_debug(4, "G3d_coord2location north %g east %g top %g\n", *north, *east, *top);
+}

Copied: grass/trunk/lib/raster3d/resample.c (from rev 47531, grass/trunk/lib/raster3d/g3dresample.c)
===================================================================
--- grass/trunk/lib/raster3d/resample.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/resample.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <grass/gis.h>
+#include "G3d_intern.h"
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * The default resampling function which uses nearest
+ * neighbor resampling. This method converts the window coordinates
+ * x, y, and z into region coordinates and returned the nearest neighbor.
+ *
+ *  \param map
+ *  \param col
+ *  \param row
+ *  \param depth
+ *  \param value
+ *  \param type
+ *  \return void
+ */
+
+void
+G3d_nearestNeighbor(G3D_Map * map, int x, int y, int z, void *value,
+		    int type)
+{
+    double north, east, top;
+    int row, col, depth;
+
+    /* convert (x, y, z) window coordinates into (north, east, top) */
+    G3d_coord2location(&(map->window), (double)x + 0.5, (double)y + 0.5, (double)z + 0.5, &north, &east, &top);
+
+    /* convert (north, east, top) into map region coordinates (row, col, depth) */
+    G3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
+
+    /* if (row, col, depth) outside map region return NULL value */
+    if ((row < 0) || (row >= map->region.rows) ||
+	(col < 0) || (col >= map->region.cols) ||
+	(depth < 0) || (depth >= map->region.depths)) {
+	G3d_setNullValue(value, 1, type);
+	return;
+    }
+    
+    /* Get the value from the map in map-region resolution */
+	G3d_getValueRegion(map, col, row, depth, value, type);
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Sets the resampling function to be used by
+ * G3d_getValue () (cf.{g3d:G3d.getValue}). This function is defined
+ * as follows:
+ *
+ *  \return void
+ */
+
+void G3d_setResamplingFun(G3D_Map * map, void (*resampleFun) ())
+{
+    map->resampleFun = resampleFun;
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * 
+ * Returns in <em>resampleFun</em> a pointer to the resampling function used by
+ * <em>map</em>.
+ *
+ *  \return void
+ */
+
+void G3d_getResamplingFun(G3D_Map * map, void (**resampleFun) ())
+{
+    *resampleFun = map->resampleFun;
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns
+ * in <em>nnFunPtr</em> a pointer to G3d_nearestNeighbor () (cf.{g3d:G3d.nearestNeighbor}).
+ *
+ *  \return void
+ */
+
+void G3d_getNearestNeighborFunPtr(void (**nnFunPtr) ())
+{
+    *nnFunPtr = G3d_nearestNeighbor;
+}

Copied: grass/trunk/lib/raster3d/volume.c (from rev 47531, grass/trunk/lib/raster3d/g3dvolume.c)
===================================================================
--- grass/trunk/lib/raster3d/volume.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/volume.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,267 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <grass/raster.h>
+#include <grass/G3d.h>
+
+/*---------------------------------------------------------------------------*/
+
+static int verifyVolumeVertices(map, v)
+
+     void *map;
+     double v[2][2][2][3];
+
+{
+    if (!(G3d_isValidLocation(map, v[0][0][0][0], v[0][0][0][1],
+			      v[0][0][0][2]) &&
+	  G3d_isValidLocation(map, v[0][0][1][0], v[0][0][1][1],
+			      v[0][0][1][2]) &&
+	  G3d_isValidLocation(map, v[0][1][0][0], v[0][1][0][1],
+			      v[0][1][0][2]) &&
+	  G3d_isValidLocation(map, v[0][1][1][0], v[0][1][1][1],
+			      v[0][1][1][2]) &&
+	  G3d_isValidLocation(map, v[1][0][0][0], v[1][0][0][1],
+			      v[1][0][0][2]) &&
+	  G3d_isValidLocation(map, v[1][0][1][0], v[1][0][1][1],
+			      v[1][0][1][2]) &&
+	  G3d_isValidLocation(map, v[1][1][0][0], v[1][1][0][1],
+			      v[1][1][0][2]) &&
+	  G3d_isValidLocation(map, v[1][1][1][0], v[1][1][1][1],
+			      v[1][1][1][2])))
+	G3d_fatalError("verifyCubeVertices: volume vertex out of range");
+    return 0;
+}
+
+
+/*---------------------------------------------------------------------------*/
+
+static int verifyVolumeEdges(nx, ny, nz)
+
+     int nx, ny, nz;
+
+{
+    if ((nx <= 0) || (ny <= 0) || (nz <= 0))
+	G3d_fatalError("verifyCubeEdges: Volume edge out of range");
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_getVolumeA(void *map, double u[2][2][2][3], int nx, int ny, int nz,
+	       void *volumeBuf, int type)
+{
+    typedef double doubleArray[3];
+
+    doubleArray *u000, *u001, *u010, *u011;
+    doubleArray *u100, *u101, *u110, *u111;
+    double v00[3], v01[3], v10[3], v11[3];
+    double v0[3], v1[3];
+    double v[3];
+    double r, rp, s, sp, t, tp;
+    double dx, dy, dz;
+    int x, y, z, nxp, nyp, nzp;
+    double *doubleBuf;
+    float *floatBuf;
+
+    doubleBuf = (double *)volumeBuf;
+    floatBuf = (float *)volumeBuf;
+
+    verifyVolumeVertices(map, u);
+    verifyVolumeEdges(nx, ny, nz);
+
+    nxp = nx * 2 + 1;
+    nyp = ny * 2 + 1;
+    nzp = nz * 2 + 1;
+
+    u000 = (doubleArray *) u[0][0][0];
+    u001 = (doubleArray *) u[0][0][1];
+    u010 = (doubleArray *) u[0][1][0];
+    u011 = (doubleArray *) u[0][1][1];
+    u100 = (doubleArray *) u[1][0][0];
+    u101 = (doubleArray *) u[1][0][1];
+    u110 = (doubleArray *) u[1][1][0];
+    u111 = (doubleArray *) u[1][1][1];
+
+    for (dz = 1; dz < nzp; dz += 2) {
+	r = 1. - (rp = dz / nz / 2.);
+	v00[0] = r * (*u000)[0] + rp * (*u100)[0];
+	v00[1] = r * (*u000)[1] + rp * (*u100)[1];
+	v00[2] = r * (*u000)[2] + rp * (*u100)[2];
+
+	v01[0] = r * (*u001)[0] + rp * (*u101)[0];
+	v01[1] = r * (*u001)[1] + rp * (*u101)[1];
+	v01[2] = r * (*u001)[2] + rp * (*u101)[2];
+
+	v10[0] = r * (*u010)[0] + rp * (*u110)[0];
+	v10[1] = r * (*u010)[1] + rp * (*u110)[1];
+	v10[2] = r * (*u010)[2] + rp * (*u110)[2];
+
+	v11[0] = r * (*u011)[0] + rp * (*u111)[0];
+	v11[1] = r * (*u011)[1] + rp * (*u111)[1];
+	v11[2] = r * (*u011)[2] + rp * (*u111)[2];
+
+	for (dy = 1; dy < nyp; dy += 2) {
+	    s = 1. - (sp = dy / ny / 2.);
+	    v0[0] = s * v00[0] + sp * v10[0];
+	    v0[1] = s * v00[1] + sp * v10[1];
+	    v0[2] = s * v00[2] + sp * v10[2];
+
+	    v1[0] = s * v01[0] + sp * v11[0];
+	    v1[1] = s * v01[1] + sp * v11[1];
+	    v1[2] = s * v01[2] + sp * v11[2];
+
+	    for (dx = 1; dx < nxp; dx += 2) {
+		t = 1. - (tp = dx / nx / 2.);
+		v[0] = t * v0[0] + tp * v1[0];
+		v[1] = t * v0[1] + tp * v1[1];
+		v[2] = t * v0[2] + tp * v1[2];
+
+		G3d_location2coord2(map, v[0], v[1], v[2], &x, &y, &z);
+		/* DEBUG
+		   printf ("(%d %d %d) (%lf %lf %lf) (%d %d %d) %lf\n", 
+		   (int) dx / 2, (int) dy / 2, (int) dz / 2,
+		   v[0], v[1], v[2],
+		   x, y, z, 
+		   G3d_getDoubleRegion (map, x, y, z));
+		 */
+		if (type == DCELL_TYPE)
+		    *(doubleBuf + ((int)dz / 2) * nx * ny +
+		      ((int)dy / 2) * nx + (int)dx / 2) =
+G3d_getDoubleRegion(map, x, y, z);
+		else
+		    *(floatBuf + ((int)dz / 2) * nx * ny +
+		      ((int)dy / 2) * nx + (int)dx / 2) =
+G3d_getFloatRegion(map, x, y, z);
+	    }
+	}
+    }
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_getVolume(void *map,
+	      double originNorth, double originWest, double originBottom,
+	      double vxNorth, double vxWest, double vxBottom,
+	      double vyNorth, double vyWest, double vyBottom,
+	      double vzNorth, double vzWest, double vzBottom,
+	      int nx, int ny, int nz, void *volumeBuf, int type)
+{
+    double u[2][2][2][3];
+
+    u[0][0][0][0] = originNorth;
+    u[0][0][0][1] = originWest;
+    u[0][0][0][2] = originBottom;
+
+    u[0][0][1][0] = vxNorth;
+    u[0][0][1][1] = vxWest;
+    u[0][0][1][2] = vxBottom;
+
+    u[1][0][0][0] = vzNorth;
+    u[1][0][0][1] = vzWest;
+    u[1][0][0][2] = vzBottom;
+
+    u[1][0][1][0] = (u[0][0][1][0] - u[0][0][0][0]) + u[1][0][0][0];
+    u[1][0][1][1] = (u[0][0][1][1] - u[0][0][0][1]) + u[1][0][0][1];
+    u[1][0][1][2] = (u[0][0][1][2] - u[0][0][0][2]) + u[1][0][0][2];
+
+    u[0][1][0][0] = vyNorth;
+    u[0][1][0][1] = vyWest;
+    u[0][1][0][2] = vyBottom;
+
+    u[0][1][1][0] = (u[0][0][1][0] - u[0][0][0][0]) + u[0][1][0][0];
+    u[0][1][1][1] = (u[0][0][1][1] - u[0][0][0][1]) + u[0][1][0][1];
+    u[0][1][1][2] = (u[0][0][1][2] - u[0][0][0][2]) + u[0][1][0][2];
+
+    u[1][1][0][0] = (u[1][0][0][0] - u[0][0][0][0]) + u[0][1][0][0];
+    u[1][1][0][1] = (u[1][0][0][1] - u[0][0][0][1]) + u[0][1][0][1];
+    u[1][1][0][2] = (u[1][0][0][2] - u[0][0][0][2]) + u[0][1][0][2];
+
+    u[1][1][1][0] = (u[1][0][0][0] - u[0][0][0][0]) + u[0][1][1][0];
+    u[1][1][1][1] = (u[1][0][0][1] - u[0][0][0][1]) + u[0][1][1][1];
+    u[1][1][1][2] = (u[1][0][0][2] - u[0][0][0][2]) + u[0][1][1][2];
+
+    G3d_getVolumeA(map, u, nx, ny, nz, volumeBuf, type);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_getAlignedVolume(void *map,
+		     double originNorth, double originWest,
+		     double originBottom, double lengthNorth,
+		     double lengthWest, double lengthBottom, int nx, int ny,
+		     int nz, void *volumeBuf, int type)
+{
+    G3d_getVolume(map,
+		  originNorth, originWest, originBottom,
+		  originNorth + lengthNorth, originWest, originBottom,
+		  originNorth, originWest + lengthWest, originBottom,
+		  originNorth, originWest, originBottom + lengthBottom,
+		  nx, ny, nz, volumeBuf, type);
+}
+
+/*---------------------------------------------------------------------------*/
+
+void
+G3d_makeAlignedVolumeFile(void *map, const char *fileName,
+			  double originNorth, double originWest,
+			  double originBottom, double lengthNorth,
+			  double lengthWest, double lengthBottom, int nx,
+			  int ny, int nz)
+{
+    void *volumeBuf;
+    void *mapVolume;
+    int x, y, z, eltLength;
+    G3D_Region region;
+
+    volumeBuf = G3d_malloc(nx * ny * nz * sizeof(G3d_getFileType()));
+    if (volumeBuf == NULL)
+	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_malloc");
+
+    G3d_getAlignedVolume(map,
+			 originNorth, originWest, originBottom,
+			 lengthNorth, lengthWest, lengthBottom,
+			 nx, ny, nz, volumeBuf, G3d_getFileType());
+
+    region.north = originNorth;
+    region.south = originNorth + lengthNorth;
+    region.east = originWest;
+    region.west = originWest + lengthWest;
+    region.top = originBottom;
+    region.bottom = originBottom + lengthBottom;
+
+    region.rows = ny;
+    region.cols = nx;
+    region.depths = nz;
+
+    mapVolume = G3d_openCellNew(fileName, G3d_getFileType(),
+				G3D_USE_CACHE_DEFAULT, &region);
+    if (mapVolume == NULL)
+	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_openCellNew");
+
+    eltLength = G3d_length(G3d_getFileType());
+
+    for (z = 0; z < nz; z++) {
+	for (y = 0; y < ny; y++) {
+	    for (x = 0; x < nx; x++) {
+		/* G3d_putValueRegion? */
+		if (!G3d_putValue(mapVolume, x, y, z,
+				  G_incr_void_ptr(volumeBuf,
+						  (z * ny * nx + y * nx +
+						   x) * eltLength),
+				  G3d_fileTypeMap(mapVolume)))
+		    G3d_fatalError
+			("G3d_makeAlignedVolumeFile: error in G3d_putValue");
+	    }
+	}
+    }
+
+    if (!G3d_closeCell(mapVolume))
+	G3d_fatalError("G3d_makeAlignedVolumeFile: error in G3d_closeCell");
+
+    G3d_free(volumeBuf);
+}

Copied: grass/trunk/lib/raster3d/volume_layout.png (from rev 47531, grass/trunk/lib/raster3d/g3d_volume_layout.png)
===================================================================
(Binary files differ)

Copied: grass/trunk/lib/raster3d/volume_layout.xcf (from rev 47531, grass/trunk/lib/raster3d/g3d_volume_layout.xcf)
===================================================================
(Binary files differ)

Copied: grass/trunk/lib/raster3d/window.c (from rev 47531, grass/trunk/lib/raster3d/g3dwindow.c)
===================================================================
--- grass/trunk/lib/raster3d/window.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/window.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,96 @@
+#include <stdio.h>
+#include <grass/gis.h>
+#include <grass/G3d.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+G3D_Region g3d_window;
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Sets the window for <em>map</em> to <em>window</em>.
+ * Can be used multiple times for the same map.
+ *
+ *  \param map
+ *  \param window
+ *  \return void
+ */
+
+void G3d_setWindowMap(G3D_Map * map, G3D_Region * window)
+{
+    G3d_regionCopy(&(map->window), window);
+    G3d_adjustRegion(&(map->window));
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Sets the default window used for every map opened later in the program.
+ * Can be used multiple times in the same program.
+ *
+ *  \param window
+ *  \return void
+ */
+
+void G3d_setWindow(G3D_Region * window)
+{
+    G3d_regionCopy(&g3d_window, window);
+    G3d_adjustRegion(&g3d_window);
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Stores the current default window in <em>window</em>.
+ *
+ *  \param window
+ *  \return void
+ */
+
+void G3d_getWindow(G3D_Region * window)
+{
+    G3d_regionCopy(window, &g3d_window);
+}
+
+/*---------------------------------------------------------------------------*/
+
+G3D_Region *G3d_windowPtr()
+{
+    return &g3d_window;
+}
+
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Returns 1 if window-coordinates <em>(north, west, bottom)</em> are
+ * inside the window of <em>map</em>. Returns 0 otherwise.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \return int
+ */
+
+int G3d_isValidLocationWindow(G3D_Map * map, double north, double east, double top)
+{
+    return ((north >= map->window.south) && (north <= map->window.north) &&
+	    (east >= map->window.west) && (east <= map->window.east) &&
+	    (((top >= map->window.bottom) && (top <= map->window.top)) ||
+	     ((top <= map->window.bottom) && (top >= map->window.top))));
+}

Copied: grass/trunk/lib/raster3d/windowio.c (from rev 47531, grass/trunk/lib/raster3d/g3dwindowio.c)
===================================================================
--- grass/trunk/lib/raster3d/windowio.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/windowio.c	2011-08-10 16:45:08 UTC (rev 47532)
@@ -0,0 +1,279 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <grass/gis.h>
+#include "G3d_intern.h"
+
+/*---------------------------------------------------------------------------*/
+
+static int
+G3d_readWriteWindow(struct Key_Value *windowKeys, int doRead, int *proj,
+		    int *zone, double *north, double *south, double *east,
+		    double *west, double *top, double *bottom, int *rows,
+		    int *cols, int *depths, double *ew_res, double *ns_res,
+		    double *tb_res)
+{
+    int returnVal;
+    int (*windowInt) (), (*windowDouble) ();
+
+    if (doRead) {
+	windowDouble = G3d_keyGetDouble;
+	windowInt = G3d_keyGetInt;
+    }
+    else {
+	windowDouble = G3d_keySetDouble;
+	windowInt = G3d_keySetInt;
+    }
+
+    returnVal = 1;
+    returnVal &= windowInt(windowKeys, G3D_REGION_PROJ, proj);
+    returnVal &= windowInt(windowKeys, G3D_REGION_ZONE, zone);
+
+    returnVal &= windowDouble(windowKeys, G3D_REGION_NORTH, north);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_SOUTH, south);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_EAST, east);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_WEST, west);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_TOP, top);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_BOTTOM, bottom);
+
+    returnVal &= windowInt(windowKeys, G3D_REGION_ROWS, rows);
+    returnVal &= windowInt(windowKeys, G3D_REGION_COLS, cols);
+    returnVal &= windowInt(windowKeys, G3D_REGION_DEPTHS, depths);
+
+    returnVal &= windowDouble(windowKeys, G3D_REGION_EWRES, ew_res);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_NSRES, ns_res);
+    returnVal &= windowDouble(windowKeys, G3D_REGION_TBRES, tb_res);
+
+    if (returnVal)
+	return 1;
+
+    G3d_error("G3d_readWriteWindow: error writing window");
+    return 0;
+}
+
+/*
+ * If windowName == NULL -> G3D_WINDOW_ELEMENT ("$MAPSET/WIND3")
+ * otherwise G3D_WINDOW_DATABASE ("$MAPSET/windows3d/$NAME")
+ */
+static void G3d_getFullWindowPath(char *path, const char *windowName)
+{
+    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+
+    if (windowName == NULL) {
+	G_file_name(path, "", G3D_WINDOW_ELEMENT, G_mapset());
+	return;
+    }
+
+    while (*windowName == ' ')
+	windowName++;
+
+    if ((*windowName == '/') || (*windowName == '.')) {
+	sprintf(path, windowName);
+	return;
+    }
+
+    if (G_name_is_fully_qualified(windowName, xname, xmapset)) {
+	G_file_name(path, G3D_WINDOW_DATABASE, xname, xmapset);
+	return;
+    }
+
+    G_file_name(path, G3D_WINDOW_DATABASE, windowName, G_mapset());
+}
+
+/*---------------------------------------------------------------------------*/
+/*
+   static void
+   G3d_getWindowLocation (path, windowName)
+
+   char path[1024];
+   char *windowName;
+
+   {
+   char xname[512], xmapset[512];
+   char *p, *slash;
+
+   if (windowName == NULL) {
+   G_file_name (path, "", "", G_mapset ());
+   return;
+   }
+
+   while (*windowName == ' ') windowName++;
+
+   if ((*windowName != '/') && (*windowName != '.')) {
+   if (G_name_is_fully_qualified (windowName, xname, xmapset)) 
+   G_file_name (path, G3D_WINDOW_DATABASE, xname, xmapset);
+   else
+   G_file_name (path, G3D_WINDOW_DATABASE, windowName, G_mapset ());
+   } else
+   sprintf (path, windowName);
+   p = path;
+   slash = NULL;
+   while (*p != 0) {
+   if (*p == '/') slash = p;
+   p++;
+   }
+   if (slash != NULL) *slash = 0;
+   }
+ */
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ *  Reads
+ * <em>window</em> from the file specified by <em>windowName</em>. The name is
+ * converted by the rules defined in window defaults. A NULL pointer indicates
+ * the <em>WIND3</em> file in the current mapset.
+ *
+ *  \param window
+ *  \param windowName
+ *  \return 1 ... if successful
+ *          0 ... otherwise.
+ */
+
+int G3d_readWindow(G3D_Region * window, const char *windowName)
+{
+    struct Cell_head win;
+    struct Key_Value *windowKeys;
+    char path[GPATH_MAX];
+
+
+    if (windowName == NULL) {
+	G_get_window(&win);
+
+	window->proj = win.proj;
+	window->zone = win.zone;
+	window->north = win.north;
+	window->south = win.south;
+	window->east = win.east;
+	window->west = win.west;
+	window->top = win.top;
+	window->bottom = win.bottom;
+	window->rows = win.rows3;
+	window->cols = win.cols3;
+	window->depths = win.depths;
+	window->ns_res = win.ns_res3;
+	window->ew_res = win.ew_res3;
+	window->tb_res = win.tb_res;
+    }
+    else {
+	G3d_getFullWindowPath(path, windowName);
+
+	if (access(path, R_OK) != 0) {
+	    G_warning("G3d_readWindow: unable to find [%s].", path);
+	    return 0;
+	}
+
+	windowKeys = G_read_key_value_file(path);
+
+	if (!G3d_readWriteWindow(windowKeys, 1,
+				 &(window->proj), &(window->zone),
+				 &(window->north), &(window->south),
+				 &(window->east), &(window->west),
+				 &(window->top), &(window->bottom),
+				 &(window->rows), &(window->cols),
+				 &(window->depths), &(window->ew_res),
+				 &(window->ns_res), &(window->tb_res))) {
+	    G3d_error
+		("G3d_readWindow: error extracting window key(s) of file %s",
+		 path);
+	    return 0;
+	}
+
+	G_free_key_value(windowKeys);
+    }
+
+    return 1;
+}
+
+/*---------------------------------------------------------------------------*/
+/* modified version of G__make_mapset_element */
+/*
+   static int
+   G3d_createPath (thePath)
+
+   char *thePath;
+
+   {
+   char command[1024];
+   char *path, *p, *pOld;
+
+   if (*thePath == 0) return 0;
+
+   strcpy (path = command, "mkdir ");
+   while (*path) path++;
+   p = path;
+ */
+  /* now append element, one directory at a time, to path */
+/*
+   while (1) {
+   if (*thePath == '/') *p++ = *thePath++;
+   pOld = p;
+   while ((*thePath) && (*thePath != '/')) *p++ = *thePath++;
+   *p = 0;
+
+   if (p == pOld) return 1;
+
+   if (access (path, 0) != 0) mkdir (path,0777);
+   if (access (path, 0) != 0) system (command);
+   if (access (path, 0) != 0) {
+   char err[1024];
+   sprintf (err, "can't make mapset element %s (%s)", thePath, path);
+   G_fatal_error (err);
+   exit(1);
+   }
+   }
+   }
+ */
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * 
+ * Writes <em>window</em> to the file specified by <em>windowName</em>. The name
+ * is converted by the rules defined in window defaults. A NULL pointer
+ * indicates the <em>WIND3</em> file in the current mapset.
+ *
+ *  \param window
+ *  \param windowName
+ *  \return 1 ... if successful
+ *          0 ... otherwise.
+ */
+
+/*
+   int
+   G3d_writeWindow (window, windowName)
+
+   G3D_Region *window;
+   char *windowName;
+
+   {
+   return 0;
+   }
+ */
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief 
+ *
+ * Allows the window to be set at run-time via the <em>region3</em>
+ * command line argument. This function has to be called before
+ * <em>G_parser ()</em>. See also window defaults.
+ *
+ *  \return void
+ */
+
+void G3d_useWindowParams(void)
+{
+    G3d_setWindowParams();
+}



More information about the grass-commit mailing list