瀏覽代碼

Added vertical unit to raster3d map header structure. Temporal units are
integrated into libgis.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50691 15284696-431f-4ddb-bdfa-cd5b030d7da7

Soeren Gebbert 13 年之前
父節點
當前提交
53c09728d6

+ 9 - 7
include/datetime.h

@@ -4,13 +4,15 @@
 #define DATETIME_ABSOLUTE 1
 #define DATETIME_ABSOLUTE 1
 #define DATETIME_RELATIVE 2
 #define DATETIME_RELATIVE 2
 
 
-/* ranges - the values must start at 1 and increase */
-#define DATETIME_YEAR   1
-#define DATETIME_MONTH  2
-#define DATETIME_DAY    3
-#define DATETIME_HOUR   4
-#define DATETIME_MINUTE 5
-#define DATETIME_SECOND 6
+/* ranges - the values must start at 101 and increase 
+ * to make sure they do not interfere with the spatial
+ * units in gis.h */
+#define DATETIME_YEAR   101
+#define DATETIME_MONTH  102
+#define DATETIME_DAY    103
+#define DATETIME_HOUR   104
+#define DATETIME_MINUTE 105
+#define DATETIME_SECOND 106
 
 
 typedef struct DateTime
 typedef struct DateTime
 {
 {

+ 2 - 0
include/defs/gis.h

@@ -647,6 +647,8 @@ double G_units_to_meters_factor(int);
 double G_units_to_meters_factor_sq(int);
 double G_units_to_meters_factor_sq(int);
 const char *G_get_units_name(int, int, int);
 const char *G_get_units_name(int, int, int);
 int G_units(const char *);
 int G_units(const char *);
+int G_is_units_type_spatial(int);
+int G_is_units_type_temporal(int);
 
 
 /* user_config.c */
 /* user_config.c */
 #ifndef __MINGW32__
 #ifndef __MINGW32__

+ 36 - 30
include/defs/raster3d.h

@@ -55,29 +55,29 @@ int Rast3d_fpcompress_read_xdr_nums(int, char *, int, int, int, char *, int);
 int Rast3d_fpcompress_read_xdr_floats(int, char *, int, int, int, char *);
 int Rast3d_fpcompress_read_xdr_floats(int, char *, int, int, int, char *);
 int Rast3d_fpcompress_read_xdr_doubles(int, char *, int, int, int, char *);
 int Rast3d_fpcompress_read_xdr_doubles(int, char *, int, int, int, char *);
 
 
-/* g3dalloc.c */
+/* alloc.c */
 void *Rast3d_malloc(int);
 void *Rast3d_malloc(int);
 void *Rast3d_realloc(void *, int);
 void *Rast3d_realloc(void *, int);
 void Rast3d_free(void *);
 void Rast3d_free(void *);
 
 
-/* g3dcache.c */
+/* cache.c */
 int Rast3d_init_cache(RASTER3D_Map *, int);
 int Rast3d_init_cache(RASTER3D_Map *, int);
 int Rast3d_dispose_cache(RASTER3D_Map *);
 int Rast3d_dispose_cache(RASTER3D_Map *);
 int Rast3d_flush_all_tiles(RASTER3D_Map *);
 int Rast3d_flush_all_tiles(RASTER3D_Map *);
 
 
-/* g3dcats.c */
+/* cats.c */
 int Rast3d_write_cats(const char *, struct Categories *);
 int Rast3d_write_cats(const char *, struct Categories *);
 int Rast3d_read_cats(const char *, const char *, struct Categories *);
 int Rast3d_read_cats(const char *, const char *, struct Categories *);
 
 
-/* g3dclose.c */
+/* close.c */
 int Rast3d_close(RASTER3D_Map *);
 int Rast3d_close(RASTER3D_Map *);
 
 
-/* g3dcolor.c */
+/* color.c */
 int Rast3d_remove_color(const char *);
 int Rast3d_remove_color(const char *);
 int Rast3d_read_colors(const char *, const char *, struct Colors *);
 int Rast3d_read_colors(const char *, const char *, struct Colors *);
 int Rast3d_write_colors(const char *, const char *, struct Colors *);
 int Rast3d_write_colors(const char *, const char *, struct Colors *);
 
 
-/* g3ddefaults.c */
+/* defaults.c */
 void Rast3d_set_compression_mode(int, int, int, int);
 void Rast3d_set_compression_mode(int, int, int, int);
 void Rast3d_get_compression_mode(int *, int *, int *, int *);
 void Rast3d_get_compression_mode(int *, int *, int *, int *);
 void Rast3d_set_cache_size(int);
 void Rast3d_set_cache_size(int);
@@ -89,14 +89,13 @@ int Rast3d_get_file_type(void);
 void Rast3d_set_tile_dimension(int, int, int);
 void Rast3d_set_tile_dimension(int, int, int);
 void Rast3d_get_tile_dimension(int *, int *, int *);
 void Rast3d_get_tile_dimension(int *, int *, int *);
 void Rast3d_set_error_fun(void (*)(const char *));
 void Rast3d_set_error_fun(void (*)(const char *));
-void Rast3d_set_unit(const char *);
 void Rast3d_init_defaults(void);
 void Rast3d_init_defaults(void);
 
 
-/* g3ddoubleio.c */
+/* doubleio.c */
 int Rast3d_write_doubles(int, int, const double *, int);
 int Rast3d_write_doubles(int, int, const double *, int);
 int Rast3d_read_doubles(int, int, double *, int);
 int Rast3d_read_doubles(int, int, double *, int);
 
 
-/* g3derror.c */
+/* error.c */
 void Rast3d_skip_error(const char *);
 void Rast3d_skip_error(const char *);
 void Rast3d_print_error(const char *);
 void Rast3d_print_error(const char *);
 void Rast3d_fatal_error(const char *, ...) __attribute__ ((format(printf, 1, 2)))
 void Rast3d_fatal_error(const char *, ...) __attribute__ ((format(printf, 1, 2)))
@@ -104,7 +103,7 @@ void Rast3d_fatal_error(const char *, ...) __attribute__ ((format(printf, 1, 2))
 void Rast3d_fatal_error_noargs(const char *) __attribute__ ((noreturn));
 void Rast3d_fatal_error_noargs(const char *) __attribute__ ((noreturn));
 void Rast3d_error(const char *, ...) __attribute__ ((format(printf, 1, 2)));
 void Rast3d_error(const char *, ...) __attribute__ ((format(printf, 1, 2)));
 
 
-/* g3dfpxdr.c */
+/* fpxdr.c */
 int Rast3d_is_xdr_null_num(const void *, int);
 int Rast3d_is_xdr_null_num(const void *, int);
 int Rast3d_is_xdr_null_float(const float *);
 int Rast3d_is_xdr_null_float(const float *);
 int Rast3d_is_xdr_null_double(const double *);
 int Rast3d_is_xdr_null_double(const double *);
@@ -117,15 +116,15 @@ int Rast3d_copy_to_xdr(const void *, int);
 int Rast3d_init_copy_from_xdr(RASTER3D_Map *, int);
 int Rast3d_init_copy_from_xdr(RASTER3D_Map *, int);
 int Rast3d_copy_from_xdr(int, void *);
 int Rast3d_copy_from_xdr(int, void *);
 
 
-/* g3dhistory.c */
+/* history.c */
 int Rast3d_write_history(const char *, struct History *);
 int Rast3d_write_history(const char *, struct History *);
 int Rast3d_read_history(const char *, const char *, struct History *);
 int Rast3d_read_history(const char *, const char *, struct History *);
 
 
-/* g3dintio.c */
+/* intio.c */
 int Rast3d_write_ints(int, int, const int *, int);
 int Rast3d_write_ints(int, int, const int *, int);
 int Rast3d_read_ints(int, int, int *, int);
 int Rast3d_read_ints(int, int, int *, int);
 
 
-/* g3dkeys.c */
+/* keys.c */
 int Rast3d_key_get_int(struct Key_Value *, const char *, int *);
 int Rast3d_key_get_int(struct Key_Value *, const char *, int *);
 int Rast3d_key_get_double(struct Key_Value *, const char *, double *);
 int Rast3d_key_get_double(struct Key_Value *, const char *, double *);
 int Rast3d_key_get_string(struct Key_Value *, const char *, char **);
 int Rast3d_key_get_string(struct Key_Value *, const char *, char **);
@@ -136,14 +135,14 @@ int Rast3d_key_set_double(struct Key_Value *, const char *, const double *);
 int Rast3d_key_set_string(struct Key_Value *, const char *, char *const *);
 int Rast3d_key_set_string(struct Key_Value *, const char *, char *const *);
 int Rast3d_key_set_value(struct Key_Value *, const char *, const char *,
 int Rast3d_key_set_value(struct Key_Value *, const char *, const char *,
 		    const char *, int, int, const int *);
 		    const char *, int, int, const int *);
-/* g3dlong.c */
+/* long.c */
 int Rast3d_long_encode(long *, unsigned char *, int);
 int Rast3d_long_encode(long *, unsigned char *, int);
 void Rast3d_long_decode(unsigned char *, long *, int, int);
 void Rast3d_long_decode(unsigned char *, long *, int, int);
 
 
-/* g3dmapset.c */
+/* mapset.c */
 void Rast3d_make_mapset_map_directory(const char *);
 void Rast3d_make_mapset_map_directory(const char *);
 
 
-/* g3dmask.c */
+/* mask.c */
 int Rast3d_mask_close(void);
 int Rast3d_mask_close(void);
 int Rast3d_mask_file_exists(void);
 int Rast3d_mask_file_exists(void);
 int Rast3d_mask_open_old(void);
 int Rast3d_mask_open_old(void);
@@ -165,7 +164,7 @@ int Rast3d_mask_d_select(DCELL *, d_Mask *);
 DCELL Rast3d_mask_match_d_interval(DCELL, d_Interval *);
 DCELL Rast3d_mask_match_d_interval(DCELL, d_Interval *);
 void Rast3d_parse_vallist(char **, d_Mask **);
 void Rast3d_parse_vallist(char **, d_Mask **);
 
 
-/* g3dmisc.c */
+/* misc.c */
 int Rast3d_g3d_type2cell_type(int);
 int Rast3d_g3d_type2cell_type(int);
 void Rast3d_copy_float2Double(const float *, int, double *, int, int);
 void Rast3d_copy_float2Double(const float *, int, double *, int, int);
 void Rast3d_copy_double2Float(const double *, int, float *, int, int);
 void Rast3d_copy_double2Float(const double *, int, float *, int, int);
@@ -173,26 +172,26 @@ void Rast3d_copy_values(const void *, int, int, void *, int, int, int);
 int Rast3d_length(int);
 int Rast3d_length(int);
 int Rast3d_extern_length(int);
 int Rast3d_extern_length(int);
 
 
-/* g3dnull.c */
+/* null.c */
 int Rast3d_is_null_value_num(const void *, int);
 int Rast3d_is_null_value_num(const void *, int);
 void Rast3d_set_null_value(void *, int, int);
 void Rast3d_set_null_value(void *, int, int);
 
 
-/* g3dopen2.c */
+/* open2.c */
 void *Rast3d_open_new_param(const char *, int , int, RASTER3D_Region *, int, int, int, int, int, int, int);
 void *Rast3d_open_new_param(const char *, int , int, RASTER3D_Region *, int, int, int, int, int, int, int);
-/* g3dopen.c */
+/* open.c */
 void *Rast3d_open_cell_old_no_header(const char *, const char *);
 void *Rast3d_open_cell_old_no_header(const char *, const char *);
 void *Rast3d_open_cell_old(const char *, const char *, RASTER3D_Region *, int, int);
 void *Rast3d_open_cell_old(const char *, const char *, RASTER3D_Region *, int, int);
 void *Rast3d_open_cell_new(const char *, int, int, RASTER3D_Region *);
 void *Rast3d_open_cell_new(const char *, int, int, RASTER3D_Region *);
 void *Rast3d_open_new_opt_tile_size(const char *, int , RASTER3D_Region * , int , int );
 void *Rast3d_open_new_opt_tile_size(const char *, int , RASTER3D_Region * , int , int );
 
 
-/* g3dparam.c */
+/* param.c */
 void Rast3d_set_standard3d_input_params(void);
 void Rast3d_set_standard3d_input_params(void);
 int Rast3d_get_standard3d_params(int *, int *, int *, int *, int *, int *, int *,
 int Rast3d_get_standard3d_params(int *, int *, int *, int *, int *, int *, int *,
 			    int *, int *, int *, int *, int *);
 			    int *, int *, int *, int *, int *);
 void Rast3d_set_window_params(void);
 void Rast3d_set_window_params(void);
 char *Rast3d_get_window_params(void);
 char *Rast3d_get_window_params(void);
 
 
-/* g3drange.c */
+/* range.c */
 void Rast3d_range_update_from_tile(RASTER3D_Map *, const void *, int, int, int, int,
 void Rast3d_range_update_from_tile(RASTER3D_Map *, const void *, int, int, int, int,
 			      int, int, int, int);
 			      int, int, int, int);
 int Rast3d_read_range(const char *, const char *, struct FPRange *);
 int Rast3d_read_range(const char *, const char *, struct FPRange *);
@@ -201,7 +200,7 @@ void Rast3d_range_min_max(RASTER3D_Map *, double *, double *);
 int Rast3d_range_write(RASTER3D_Map *);
 int Rast3d_range_write(RASTER3D_Map *);
 int Rast3d_range_init(RASTER3D_Map *);
 int Rast3d_range_init(RASTER3D_Map *);
 
 
-/* g3dregion.c */
+/* region.c */
 void Rast3d_get_region_value(RASTER3D_Map *, double, double, double, void *, int);
 void Rast3d_get_region_value(RASTER3D_Map *, double, double, double, void *, int);
 void Rast3d_adjust_region(RASTER3D_Region *);
 void Rast3d_adjust_region(RASTER3D_Region *);
 void Rast3d_region_copy(RASTER3D_Region *, RASTER3D_Region *);
 void Rast3d_region_copy(RASTER3D_Region *, RASTER3D_Region *);
@@ -215,13 +214,13 @@ int Rast3d_is_valid_location(RASTER3D_Region *, double, double, double);
 void Rast3d_location2coord(RASTER3D_Region *, double, double, double, int *, int *, int *);
 void Rast3d_location2coord(RASTER3D_Region *, double, double, double, int *, int *, int *);
 void Rast3d_location2coord2(RASTER3D_Region *, double, double, double, int *, int *, int *);
 void Rast3d_location2coord2(RASTER3D_Region *, double, double, double, int *, int *, int *);
 void Rast3d_coord2location(RASTER3D_Region *, double, double, double, double *, double *, double *);
 void Rast3d_coord2location(RASTER3D_Region *, double, double, double, double *, double *, double *);
-/* g3dresample.c */
+/* resample.c */
 void Rast3d_nearest_neighbor(RASTER3D_Map *, int, int, int, void *, int);
 void Rast3d_nearest_neighbor(RASTER3D_Map *, int, int, int, void *, int);
 void Rast3d_set_resampling_fun(RASTER3D_Map *, void (*)());
 void Rast3d_set_resampling_fun(RASTER3D_Map *, void (*)());
 void Rast3d_get_resampling_fun(RASTER3D_Map *, void (**)());
 void Rast3d_get_resampling_fun(RASTER3D_Map *, void (**)());
 void Rast3d_get_nearest_neighbor_fun_ptr(void (**)());
 void Rast3d_get_nearest_neighbor_fun_ptr(void (**)());
 
 
-/* g3dvolume.c */
+/* volume.c */
 void Rast3d_get_volume_a(void *, double[2][2][2][3], int, int, int, void *, int);
 void Rast3d_get_volume_a(void *, double[2][2][2][3], int, int, int, void *, int);
 void Rast3d_get_volume(void *, double, double, double, double, double, double,
 void Rast3d_get_volume(void *, double, double, double, double, double, double,
 		   double, double, double, double, double, double, int, int,
 		   double, double, double, double, double, double, int, int,
@@ -230,7 +229,7 @@ void Rast3d_get_aligned_volume(void *, double, double, double, double, double,
 			  double, int, int, int, void *, int);
 			  double, int, int, int, void *, int);
 void Rast3d_make_aligned_volume_file(void *, const char *, double, double, double,
 void Rast3d_make_aligned_volume_file(void *, const char *, double, double, double,
 			       double, double, double, int, int, int);
 			       double, double, double, int, int, int);
-/* g3dwindow.c */
+/* window.c */
 void Rast3d_get_value(RASTER3D_Map *, int, int, int, void *, int);
 void Rast3d_get_value(RASTER3D_Map *, int, int, int, void *, int);
 float Rast3d_get_float(RASTER3D_Map *, int, int, int);
 float Rast3d_get_float(RASTER3D_Map *, int, int, int);
 double Rast3d_get_double(RASTER3D_Map *, int, int, int);
 double Rast3d_get_double(RASTER3D_Map *, int, int, int);
@@ -242,7 +241,7 @@ void Rast3d_set_window(RASTER3D_Region *);
 void Rast3d_set_window_map(RASTER3D_Map *, RASTER3D_Region *);
 void Rast3d_set_window_map(RASTER3D_Map *, RASTER3D_Region *);
 void Rast3d_get_window(RASTER3D_Region *);
 void Rast3d_get_window(RASTER3D_Region *);
 
 
-/* g3dwindowio.c */
+/* windowio.c */
 void Rast3d_use_window_params(void);
 void Rast3d_use_window_params(void);
 int Rast3d_read_window(RASTER3D_Region *, const char *);
 int Rast3d_read_window(RASTER3D_Region *, const char *);
 
 
@@ -256,17 +255,18 @@ void Rast3d_get_block(RASTER3D_Map *, int, int, int, int, int, int, void *, int)
 int Rast3d_read_header(RASTER3D_Map *, int *, int *, double *, double *, double *,
 int Rast3d_read_header(RASTER3D_Map *, int *, int *, double *, double *, double *,
 		   double *, double *, double *, int *, int *, int *,
 		   double *, double *, double *, int *, int *, int *,
 		   double *, double *, double *, int *, int *, int *, int *,
 		   double *, double *, double *, int *, int *, int *, int *,
-		   int *, int *, int *, int *, int *, int *, int *, char **);
+		   int *, int *, int *, int *, int *, int *, int *, char **, int *);
 int Rast3d_write_header(RASTER3D_Map *, int, int, double, double, double, double,
 int Rast3d_write_header(RASTER3D_Map *, int, int, double, double, double, double,
 		    double, double, int, int, int, double, double, double,
 		    double, double, int, int, int, double, double, double,
 		    int, int, int, int, int, int, int, int, int, int, int,
 		    int, int, int, int, int, int, int, int, int, int, int,
-		    char *);
+		    char *, int);
+int Rast3d_rewrite_header(RASTER3D_Map * map);
 int Rast3d_cache_size_encode(int, int);
 int Rast3d_cache_size_encode(int, int);
 int Rast3d__compute_cache_size(RASTER3D_Map *, int);
 int Rast3d__compute_cache_size(RASTER3D_Map *, int);
 int Rast3d_fill_header(RASTER3D_Map *, int, int, int, int, int, int, int, int, int,
 int Rast3d_fill_header(RASTER3D_Map *, int, int, int, int, int, int, int, int, int,
 		   int, int, int, int, int, int, int, double, double, double,
 		   int, int, int, int, int, int, int, double, double, double,
 		   double, double, double, int, int, int, double, double,
 		   double, double, double, int, int, int, double, double,
-		   double, char *);
+		   double, char *, int);
 /* headerinfo.c */
 /* headerinfo.c */
 void Rast3d_get_coords_map(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_coords_map(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_coords_map_window(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_coords_map_window(RASTER3D_Map *, int *, int *, int *);
@@ -282,6 +282,12 @@ int Rast3d_tile_precision_map(RASTER3D_Map *);
 int Rast3d_tile_use_cache_map(RASTER3D_Map *);
 int Rast3d_tile_use_cache_map(RASTER3D_Map *);
 void Rast3d_print_header(RASTER3D_Map *);
 void Rast3d_print_header(RASTER3D_Map *);
 void Rast3d_get_region_struct_map(RASTER3D_Map *, RASTER3D_Region *);
 void Rast3d_get_region_struct_map(RASTER3D_Map *, RASTER3D_Region *);
+const char* Rast3d_get_unit(RASTER3D_Map * map);
+int Rast3d_get_vertical_unit2(RASTER3D_Map * map);
+const char* Rast3d_get_vertical_unit(RASTER3D_Map * map);
+void Rast3d_set_unit(RASTER3D_Map * map, const char *);
+void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *);
+void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int);
 
 
 /* index.c */
 /* index.c */
 int Rast3d_flush_index(RASTER3D_Map *);
 int Rast3d_flush_index(RASTER3D_Map *);

+ 7 - 0
include/gis.h

@@ -74,6 +74,13 @@ static const char *GRASS_copyright __attribute__ ((unused))
 #define U_FEET		6
 #define U_FEET		6
 #define U_RADIANS	7
 #define U_RADIANS	7
 #define U_DEGREES	8
 #define U_DEGREES	8
+/* Temporal units from the datetime library */
+#define U_YEARS         DATETIME_YEAR   
+#define U_MONTHS        DATETIME_MONTH  
+#define U_DAYS          DATETIME_DAY    
+#define U_HOURS         DATETIME_HOUR   
+#define U_MINUTES       DATETIME_MINUTE 
+#define U_SECONDS       DATETIME_SECOND 
 
 
 #define PROJECTION_XY  0
 #define PROJECTION_XY  0
 #define PROJECTION_UTM 1
 #define PROJECTION_UTM 1

+ 2 - 1
include/raster3d.h

@@ -90,7 +90,8 @@ typedef struct RASTER3D_Map
     resample_fn *resampleFun;
     resample_fn *resampleFun;
 
 
     /* units */
     /* units */
-    char *unit;
+    char* unit;          /* space (U_METER, ...) */
+    int vertical_unit; /* space or time (U_METER, ..., U_YEAR, ...) */
 
 
     /* dimension of a single tile in "cells" */
     /* dimension of a single tile in "cells" */
     int tileX, tileY, tileZ;
     int tileX, tileY, tileZ;

+ 102 - 1
lib/gis/units.c

@@ -10,6 +10,7 @@
   
   
   \author Original author CERL
   \author Original author CERL
   \author Adopted for libgis by Martin Landa <landa.martin gmail.com> (2010)
   \author Adopted for libgis by Martin Landa <landa.martin gmail.com> (2010)
+  \author Temporal units and unit type check from Soeren gebbert <soerengebbert googlemail.com> (2012)
  */
  */
 
 
 #include <string.h>
 #include <string.h>
@@ -113,6 +114,62 @@ double G_units_to_meters_factor_sq(int units)
     return 1.0;
     return 1.0;
 }
 }
 
 
+/** \brief Check if the unit is of spatial type
+  
+  \param units units code from gis.h
+ 
+  \return 1 if True, 0 otherwise 
+ */
+
+int G_is_units_type_spatial(int units)
+{
+    switch (units) {
+    case U_METERS:
+        return 1;
+    case U_KILOMETERS:
+        return 1;
+    case U_HECTARES:
+        return 1;
+    case U_ACRES:
+        return 1;
+    case U_MILES:
+        return 1;
+    case U_FEET:
+        return 1;
+    case U_RADIANS:
+        return 1;
+    case U_DEGREES:
+        return 1;
+    }
+    return 0;    
+}
+
+/** \brief Check if the unit is of temporal type
+  
+  \param units units code from gis.h
+ 
+  \return 1 if True, 0 otherwise 
+ */
+
+int G_is_units_type_temporal(int units)
+{
+    switch (units) {
+    case U_YEARS:
+        return 1;
+    case U_MONTHS:
+        return 1;
+    case U_DAYS:
+        return 1;
+    case U_HOURS:
+        return 1;
+    case U_MINUTES:
+        return 1;
+    case U_SECONDS:
+        return 1;
+    }
+    return 0;    
+}
+
 /*!
 /*!
   \brief Get localized units name
   \brief Get localized units name
 
 
@@ -190,8 +247,31 @@ const char *G_get_units_name(int units, int plural, int square)
 	    return plural ? _("square degrees") : _("square degree");
 	    return plural ? _("square degrees") : _("square degree");
 	else
 	else
 	    return plural ? _("degrees") : _("degree");
 	    return plural ? _("degrees") : _("degree");
+	break;  
+        
+    case U_YEARS:
+	return plural ? _("year") : _("years");
+	break;
+	
+    case U_MONTHS:
+	return plural ? _("month") : _("months");
+	break;
+	
+    case U_DAYS:
+	return plural ? _("day") : _("days");
+	break;
+	
+    case U_HOURS:
+	return plural ? _("hour") : _("hours");
+	break;
+	
+    case U_MINUTES:
+	return plural ? _("minute") : _("minutes");
+	break;
+	
+    case U_SECONDS:
+	return plural ? _("second") : _("seconds");
 	break;
 	break;
-
     }
     }
     
     
     return NULL;
     return NULL;
@@ -207,6 +287,9 @@ const char *G_get_units_name(int units, int plural, int square)
    - U_HECTARES
    - U_HECTARES
    - U_MILES
    - U_MILES
    - U_FEET
    - U_FEET
+   - ...
+   - U_YEARS
+   - ...
 
 
   \param units_name units name (singular or plural form)
   \param units_name units name (singular or plural form)
 
 
@@ -240,6 +323,24 @@ int G_units(const char *units_name)
     else if (strcasecmp(units_name, "degree") == 0 ||
     else if (strcasecmp(units_name, "degree") == 0 ||
 	     strcasecmp(units_name, "degrees") == 0)
 	     strcasecmp(units_name, "degrees") == 0)
 	return U_DEGREES;
 	return U_DEGREES;
+    else if (strcasecmp(units_name, "year") == 0 ||
+	strcasecmp(units_name, "years") == 0)
+	return U_YEARS;
+    else if (strcasecmp(units_name, "month") == 0 ||
+	     strcasecmp(units_name, "months") == 0)
+	return U_MONTHS;
+    else if (strcasecmp(units_name, "day") == 0 ||
+	     strcasecmp(units_name, "days") == 0)
+	return U_DAYS;
+    else if (strcasecmp(units_name, "hour") == 0 ||
+	     strcasecmp(units_name, "hours") == 0)
+	return U_HOURS;
+    else if (strcasecmp(units_name, "minute") == 0 ||
+	     strcasecmp(units_name, "minutes") == 0)
+	return U_MINUTES;
+    else if (strcasecmp(units_name, "secons") == 0 ||
+	     strcasecmp(units_name, "seconds") == 0)
+	return U_SECONDS;
 
 
     return U_UNKNOWN;
     return U_UNKNOWN;
 }
 }

+ 1 - 1
lib/python/raster3d.py

@@ -54,7 +54,7 @@ def raster3d_info(map):
         else:
         else:
             return float(s)
             return float(s)
 
 
-    s = read_command('r3.info', flags = 'rstgip', map = map)
+    s = read_command('r3.info', flags='rg', map=map)
     kv = parse_key_val(s)
     kv = parse_key_val(s)
     for k in ['min', 'max']:
     for k in ['min', 'max']:
 	kv[k] = float_or_null(kv[k])
 	kv[k] = float_or_null(kv[k])

+ 1 - 2
lib/raster3d/close.c

@@ -187,12 +187,11 @@ int Rast3d_close(RASTER3D_Map * map)
 			     map->type,
 			     map->type,
 			     map->compression, map->useRle, map->useLzw,
 			     map->compression, map->useRle, map->useLzw,
 			     map->precision, map->offset, map->useXdr,
 			     map->precision, map->offset, map->useXdr,
-			     map->hasIndex, map->unit)) {
+			     map->hasIndex, map->unit, map->vertical_unit)) {
 	    G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
 	    G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
 	    return 0;
 	    return 0;
 	}
 	}
 
 
-    Rast3d_free(map->unit);
     Rast3d_free(map);
     Rast3d_free(map);
     
     
     return 1;
     return 1;

+ 7 - 21
lib/raster3d/defaults.c

@@ -19,6 +19,7 @@
 #define RASTER3D_TILE_Z_DEFAULT 8
 #define RASTER3D_TILE_Z_DEFAULT 8
 #define RASTER3D_ERROR_FUN_DEFAULT Rast3d_skip_error
 #define RASTER3D_ERROR_FUN_DEFAULT Rast3d_skip_error
 #define RASTER3D_UNIT_DEFAULT "none"
 #define RASTER3D_UNIT_DEFAULT "none"
+#define RASTER3D_VERTICAL_UNIT_DEFAULT U_UNKNOWN
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
 
@@ -62,6 +63,7 @@ int g3d_tile_dimension[3] =
     { RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT };
     { RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT };
 void (*g3d_error_fun) (const char *) = NULL;
 void (*g3d_error_fun) (const char *) = NULL;
 char *g3d_unit_default = NULL;
 char *g3d_unit_default = NULL;
+int g3d_vertical_unit_default = U_UNDEFINED;
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
 
@@ -318,25 +320,7 @@ void Rast3d_set_error_fun(void (*fun) (const char *))
 /*!
 /*!
  * \brief 
  * \brief 
  *
  *
- *  set G3d unit
- *
- *  \param unit
- *  \return void
- */
-
-void Rast3d_set_unit(const char *unit)
-{
-    Rast3d_free(g3d_unit_default);
-    g3d_unit_default = G_store(unit);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief 
- *
- *  Initializes the default values described
+ * Initializes the default values described
  * in RASTER3D Defaults.  Applications have to use this function only if they need to
  * in RASTER3D 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
  * query the default values before the first file (either old or new) has been
  * opened.
  * opened.
@@ -538,8 +522,10 @@ void Rast3d_init_defaults(void)
 	}
 	}
     }
     }
 
 
-    if (g3d_unit_default == NULL)
-	g3d_unit_default = G_store(RASTER3D_UNIT_DEFAULT);
+    if(g3d_unit_default == NULL)
+        g3d_unit_default = G_store(RASTER3D_UNIT_DEFAULT);
+    if(g3d_vertical_unit_default == U_UNDEFINED)
+        g3d_vertical_unit_default = RASTER3D_VERTICAL_UNIT_DEFAULT;
 
 
     windowName = Rast3d_get_window_params();
     windowName = Rast3d_get_window_params();
     if (windowName == NULL) {
     if (windowName == NULL) {

+ 39 - 7
lib/raster3d/header.c

@@ -5,6 +5,7 @@
 #include <rpc/types.h>
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 #include <rpc/xdr.h>
 #include <grass/raster3d.h>
 #include <grass/raster3d.h>
+#include <grass/glocale.h>
 #include "raster3d_intern.h"
 #include "raster3d_intern.h"
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
@@ -28,6 +29,7 @@ int xdrLength;
 #define RASTER3D_HEADER_USEXDR "useXdr"
 #define RASTER3D_HEADER_USEXDR "useXdr"
 #define RASTER3D_HEADER_HASINDEX "hasIndex"
 #define RASTER3D_HEADER_HASINDEX "hasIndex"
 #define RASTER3D_HEADER_UNIT "Units"
 #define RASTER3D_HEADER_UNIT "Units"
+#define RASTER3D_HEADER_VERTICAL_UNIT "VerticalUnits"
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
 
@@ -39,7 +41,7 @@ Rast3d_readWriteHeader(struct Key_Value *headerKeys, int doRead, int *proj,
 		    double *tb_res, int *tileX, int *tileY, int *tileZ,
 		    double *tb_res, int *tileX, int *tileY, int *tileZ,
 		    int *type, int *compression, int *useRle, int *useLzw,
 		    int *type, int *compression, int *useRle, int *useLzw,
 		    int *precision, int *dataOffset, int *useXdr,
 		    int *precision, int *dataOffset, int *useXdr,
-		    int *hasIndex, char **unit)
+		    int *hasIndex, char **unit, int *vertical_unit)
 {
 {
     int returnVal;
     int returnVal;
     int (*headerInt) (), (*headerDouble) (), (*headerValue) ();
     int (*headerInt) (), (*headerDouble) (), (*headerValue) ();
@@ -98,11 +100,16 @@ Rast3d_readWriteHeader(struct Key_Value *headerKeys, int doRead, int *proj,
     returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX,
     returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX,
 			     "0", "1", 0, 1, hasIndex);
 			     "0", "1", 0, 1, hasIndex);
     returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
     returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
+    /* New format and API changes */
+    if(!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
+        G_warning("You are using an old raster3d data format, the vertical unit is undefined. "
+                  "Please use r3.support to define the vertical unit to avoid this warning.");
+
 
 
     if (returnVal)
     if (returnVal)
 	return 1;
 	return 1;
 
 
-    Rast3d_error("Rast3d_readWriteHeader: error writing header");
+    Rast3d_error("Rast3d_readWriteHeader: error reading/writing header");
     return 0;
     return 0;
 }
 }
 
 
@@ -115,7 +122,7 @@ Rast3d_read_header(RASTER3D_Map * map, int *proj, int *zone, double *north,
 	       double *ew_res, double *ns_res, double *tb_res, int *tileX,
 	       double *ew_res, double *ns_res, double *tb_res, int *tileX,
 	       int *tileY, int *tileZ, int *type, int *compression,
 	       int *tileY, int *tileZ, int *type, int *compression,
 	       int *useRle, int *useLzw, int *precision, int *dataOffset,
 	       int *useRle, int *useLzw, int *precision, int *dataOffset,
-	       int *useXdr, int *hasIndex, char **unit)
+	       int *useXdr, int *hasIndex, char **unit, int *vertical_unit)
 {
 {
     struct Key_Value *headerKeys;
     struct Key_Value *headerKeys;
     char path[GPATH_MAX];
     char path[GPATH_MAX];
@@ -135,7 +142,7 @@ Rast3d_read_header(RASTER3D_Map * map, int *proj, int *zone, double *north,
 			     ew_res, ns_res, tb_res,
 			     ew_res, ns_res, tb_res,
 			     tileX, tileY, tileZ,
 			     tileX, tileY, tileZ,
 			     type, compression, useRle, useLzw, precision,
 			     type, compression, useRle, useLzw, precision,
-			     dataOffset, useXdr, hasIndex, unit)) {
+			     dataOffset, useXdr, hasIndex, unit, vertical_unit)) {
 	Rast3d_error("Rast3d_read_header: error extracting header key(s) of file %s",
 	Rast3d_error("Rast3d_read_header: error extracting header key(s) of file %s",
 		  path);
 		  path);
 	return 0;
 	return 0;
@@ -153,7 +160,7 @@ Rast3d_write_header(RASTER3D_Map * map, int proj, int zone, double north, double
 		int cols, int depths, double ew_res, double ns_res,
 		int cols, int depths, double ew_res, double ns_res,
 		double tb_res, int tileX, int tileY, int tileZ, int type,
 		double tb_res, int tileX, int tileY, int tileZ, int type,
 		int compression, int useRle, int useLzw, int precision,
 		int compression, int useRle, int useLzw, int precision,
-		int dataOffset, int useXdr, int hasIndex, char *unit)
+		int dataOffset, int useXdr, int hasIndex, char *unit, int vertical_unit)
 {
 {
     struct Key_Value *headerKeys;
     struct Key_Value *headerKeys;
     char path[GPATH_MAX];
     char path[GPATH_MAX];
@@ -168,7 +175,7 @@ Rast3d_write_header(RASTER3D_Map * map, int proj, int zone, double north, double
 			     &tileX, &tileY, &tileZ,
 			     &tileX, &tileY, &tileZ,
 			     &type, &compression, &useRle, &useLzw,
 			     &type, &compression, &useRle, &useLzw,
 			     &precision, &dataOffset, &useXdr, &hasIndex,
 			     &precision, &dataOffset, &useXdr, &hasIndex,
-			     &unit)) {
+			     &unit, &vertical_unit)) {
 	Rast3d_error("Rast3d_write_header: error adding header key(s) for file %s",
 	Rast3d_error("Rast3d_write_header: error adding header key(s) for file %s",
 		  path);
 		  path);
 	return 0;
 	return 0;
@@ -182,6 +189,30 @@ Rast3d_write_header(RASTER3D_Map * map, int proj, int zone, double north, double
 
 
     return 1;
     return 1;
 }
 }
+/*---------------------------------------------------------------------------*/
+
+int
+Rast3d_rewrite_header(RASTER3D_Map * map)
+{
+    if (!Rast3d_write_header(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, map->vertical_unit)) {
+        G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
+        return 0;
+    }
+    return 1;
+}
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
 
@@ -272,7 +303,7 @@ Rast3d_fill_header(RASTER3D_Map * map, int operation, int compression, int useRl
 	       int tileY, int tileZ, int proj, int zone, double north,
 	       int tileY, int tileZ, int proj, int zone, double north,
 	       double south, double east, double west, double top,
 	       double south, double east, double west, double top,
 	       double bottom, int rows, int cols, int depths, double ew_res,
 	       double bottom, int rows, int cols, int depths, double ew_res,
-	       double ns_res, double tb_res, char *unit)
+	       double ns_res, double tb_res, char *unit, int vertical_unit)
 {
 {
     if (!RASTER3D_VALID_OPERATION(operation))
     if (!RASTER3D_VALID_OPERATION(operation))
 	Rast3d_fatal_error("Rast3d_fill_header: operation not valid\n");
 	Rast3d_fatal_error("Rast3d_fill_header: operation not valid\n");
@@ -280,6 +311,7 @@ Rast3d_fill_header(RASTER3D_Map * map, int operation, int compression, int useRl
     map->operation = operation;
     map->operation = operation;
 
 
     map->unit = G_store(unit);
     map->unit = G_store(unit);
+    map->vertical_unit = vertical_unit;
 
 
     map->region.proj = proj;
     map->region.proj = proj;
     map->region.zone = zone;
     map->region.zone = zone;

+ 105 - 2
lib/raster3d/headerinfo.c

@@ -165,6 +165,109 @@ int Rast3d_tile_type_map(RASTER3D_Map * map)
 
 
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
 
+/*!
+ * \brief 
+ *
+ *  Set the data unit defintiong
+ *
+ *  \param map
+ *  \param unit
+ *  \return void
+ */
+
+void Rast3d_set_unit(RASTER3D_Map * map, const char *unit)
+{
+    map->unit = G_store(unit);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ *  set Vertical unit from integer value defined in gis.h (U_METERS, ...)
+ *
+ *  \param map
+ *  \param unit
+ *  \return void
+ */
+
+void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int vertical_unit)
+{
+    map->vertical_unit = vertical_unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ *  set Vertical unit from string
+ *
+ *  \param map
+ *  \param unit
+ *  \return void
+ */
+
+void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *vertical_unit)
+{
+    map->vertical_unit = G_units(vertical_unit);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Return the data unit definition of <em>map</em>.
+ *
+ *  \param map
+ *  \return int
+ */
+
+const char* Rast3d_get_unit(RASTER3D_Map * map)
+{
+    return map->unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Returns the vertical unit of <em>map</em> as integer. Units are defined in gis.h.
+ * 
+ * Vertical units may have temporal type
+ *
+ *  \param map
+ *  \return int
+ */
+
+int Rast3d_get_vertical_unit2(RASTER3D_Map * map)
+{
+    return map->vertical_unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief 
+ *
+ * Return the name of the unit of <em>map</em>. Units are defined in gis.h.
+ *
+ * Vertical units may have temporal type
+ * 
+ *  \param map
+ *  \return int
+ */
+
+const char* Rast3d_get_vertical_unit(RASTER3D_Map * map)
+{
+    return G_get_units_name(map->vertical_unit, 1, 0);
+}
+
+/*---------------------------------------------------------------------------*/
+
 
 
 /*!
 /*!
  * \brief 
  * \brief 
@@ -232,8 +335,8 @@ void Rast3d_print_header(RASTER3D_Map * map)
     printf("File %s open for %sing:\n", map->fileName,
     printf("File %s open for %sing:\n", map->fileName,
 	   (map->operation == RASTER3D_WRITE_DATA ? "writ" :
 	   (map->operation == RASTER3D_WRITE_DATA ? "writ" :
 	    (map->operation == RASTER3D_READ_DATA ? "read" : "unknown")));
 	    (map->operation == RASTER3D_READ_DATA ? "read" : "unknown")));
-    printf("  Fd = %d, Unit %s, Type: %s, ", map->data_fd,
-	   map->unit,
+    printf("  Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
+	   map->unit, G_get_units_name(map->vertical_unit, 1, 0),
 	   (map->type == FCELL_TYPE ? "float" :
 	   (map->type == FCELL_TYPE ? "float" :
 	    (map->type == DCELL_TYPE ? "double" : "unknown")));
 	    (map->type == DCELL_TYPE ? "double" : "unknown")));
     printf("Type intern: %s\n",
     printf("Type intern: %s\n",

+ 4 - 3
lib/raster3d/open.c

@@ -84,6 +84,7 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
     double ew_res, ns_res, tb_res;
     double ew_res, ns_res, tb_res;
     int nofHeaderBytes, dataOffset, useXdr, hasIndex;
     int nofHeaderBytes, dataOffset, useXdr, hasIndex;
     char *ltmp, *unit;
     char *ltmp, *unit;
+    int vertical_unit;
     double north, south, east, west, top, bottom;
     double north, south, east, west, top, bottom;
 
 
     map = Rast3d_open_cell_old_no_header(name, mapset);
     map = Rast3d_open_cell_old_no_header(name, mapset);
@@ -104,7 +105,7 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
 			&ew_res, &ns_res, &tb_res,
 			&ew_res, &ns_res, &tb_res,
 			&tileX, &tileY, &tileZ,
 			&tileX, &tileY, &tileZ,
 			&type, &compression, &useRle, &useLzw,
 			&type, &compression, &useRle, &useLzw,
-			&precision, &dataOffset, &useXdr, &hasIndex, &unit)) {
+			&precision, &dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit)) {
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_read_header"));
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_read_header"));
 	return 0;
 	return 0;
     }
     }
@@ -164,7 +165,7 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
 			nofHeaderBytes, tileX, tileY, tileZ,
 			nofHeaderBytes, tileX, tileY, tileZ,
 			proj, zone,
 			proj, zone,
 			north, south, east, west, top, bottom,
 			north, south, east, west, top, bottom,
-			rows, cols, depths, ew_res, ns_res, tb_res, unit)) {
+			rows, cols, depths, ew_res, ns_res, tb_res, unit, vertical_unit)) {
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_fill_header"));
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_fill_header"));
 	return (void *)NULL;
 	return (void *)NULL;
     }
     }
@@ -308,7 +309,7 @@ void *Rast3d_open_cell_new(const char *name, int typeIntern, int cache,
 			region->west, region->top, region->bottom,
 			region->west, region->top, region->bottom,
 			region->rows, region->cols, region->depths,
 			region->rows, region->cols, region->depths,
 			region->ew_res, region->ns_res, region->tb_res,
 			region->ew_res, region->ns_res, region->tb_res,
-			g3d_unit_default)) {
+			g3d_unit_default, g3d_vertical_unit_default)) {
 	Rast3d_error(_("Rast3d_open_cell_new: error in Rast3d_fill_header"));
 	Rast3d_error(_("Rast3d_open_cell_new: error in Rast3d_fill_header"));
 	return (void *)NULL;
 	return (void *)NULL;
     }
     }

+ 2 - 1
lib/raster3d/raster3d_intern.h

@@ -55,7 +55,8 @@ extern int g3d_cache_max;	/* in bytes */
 extern int g3d_file_type;	/* FCELL_TYPE or DCELL_TYPE */
 extern int g3d_file_type;	/* FCELL_TYPE or DCELL_TYPE */
 extern int g3d_tile_dimension[3];
 extern int g3d_tile_dimension[3];
 extern void (*g3d_error_fun) (const char *);
 extern void (*g3d_error_fun) (const char *);
-extern char *g3d_unit_default;
+extern char *g3d_unit_default;   /* The unit description of the map data */
+extern int g3d_vertical_unit_default; /* spatial or temporal units from gis.h, U_METERS; ..., U_YEARS, ... */
 
 
 extern RASTER3D_Region g3d_window;
 extern RASTER3D_Region g3d_window;
 
 

+ 14 - 5
lib/raster3d/raster3dlib.dox

@@ -232,6 +232,7 @@ nofHeaderBytes: 12
 useXdr: 1
 useXdr: 1
 hasIndex: 1
 hasIndex: 1
 Units: none
 Units: none
+VerticalUnits: 1
 \endverbatim
 \endverbatim
 
 
 <P>
 <P>
@@ -600,16 +601,24 @@ See functions
 
 
 \section Setting_the_Units Setting the Units
 \section Setting_the_Units Setting the Units
 
 
-<P>
-Default <TT>"none"</TT>.
+The data untis of a map can be described using a string.
+The vertical units are defined in gis.h and can be spatial or temporal.
 
 
 <P>
 <P>
 No environment variable.
 No environment variable.
 
 
 <P>
 <P>
-void Rast3d_setUnit (unit)
-        char *unit;
-
+void Rast3d_set_unit (map, unit)
+        RASTER3d_Map; /* the map */
+        char *unit; /* The data unit description */ 
+<P>
+void Rast3d_set_vertical_unit (map, unit)
+        RASTER3d_Map; /* the map */
+        char *unit;  /* Use the standard from units.c in lib/gis */
+<P>
+void Rast3d_set_vertical_unit2 (map, unit)
+        RASTER3d_Map; /* the map */
+        int unit; /* defined in gis.h */
 <P>
 <P>
 
 
 \section Error_Handling Error Handling: Setting the error function
 \section Error_Handling Error Handling: Setting the error function