@@ -32,32 +32,106 @@ int xdrLength;
32
32
33
33
/*---------------------------------------------------------------------------*/
34
34
35
- static int Rast3d_readWriteHeader (
36
- struct Key_Value * headerKeys , int doRead , int * proj , int * zone ,
37
- double * north , double * south , double * east , double * west , double * top ,
38
- double * bottom , int * rows , int * cols , int * depths , double * ew_res ,
39
- double * ns_res , double * tb_res , int * tileX , int * tileY , int * tileZ ,
40
- int * type , int * compression , int * useRle , int * useLzw , int * precision ,
41
- int * dataOffset , int * useXdr , int * hasIndex , char * * unit ,
42
- int * vertical_unit , int * version )
35
+ static int Rast3d__readHeader (
36
+ struct Key_Value * headerKeys , int * proj , int * zone , double * north ,
37
+ double * south , double * east , double * west , double * top , double * bottom ,
38
+ int * rows , int * cols , int * depths , double * ew_res , double * ns_res ,
39
+ double * tb_res , int * tileX , int * tileY , int * tileZ , int * type ,
40
+ int * compression , int * useRle , int * useLzw , int * precision , int * dataOffset ,
41
+ int * useXdr , int * hasIndex , char * * unit , int * vertical_unit , int * version )
43
42
{
44
43
int returnVal ;
45
- int (* headerInt )(), (* headerDouble )(), (* headerValue )();
46
- int (* headerString )();
47
-
48
- if (doRead ) {
49
- headerDouble = Rast3d_key_get_double ;
50
- headerInt = Rast3d_key_get_int ;
51
- headerString = Rast3d_key_get_string ;
52
- headerValue = Rast3d_key_get_value ;
53
- }
54
- else {
55
- headerDouble = Rast3d_key_set_double ;
56
- headerInt = Rast3d_key_set_int ;
57
- headerString = Rast3d_key_set_string ;
58
- headerValue = Rast3d_key_set_value ;
44
+ int (* headerInt )(struct Key_Value * , const char * , int * ),
45
+ (* headerDouble )(struct Key_Value * , const char * , double * ),
46
+ (* headerValue )(struct Key_Value * , const char * , char * , char * , int ,
47
+ int , int * );
48
+ int (* headerString )(struct Key_Value * , const char * , char * * );
49
+
50
+ headerDouble = Rast3d_key_get_double ;
51
+ headerInt = Rast3d_key_get_int ;
52
+ headerString = Rast3d_key_get_string ;
53
+ headerValue = Rast3d_key_get_value ;
54
+
55
+ returnVal = 1 ;
56
+ returnVal &= headerInt (headerKeys , RASTER3D_REGION_PROJ , proj );
57
+ returnVal &= headerInt (headerKeys , RASTER3D_REGION_ZONE , zone );
58
+
59
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_NORTH , north );
60
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_SOUTH , south );
61
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_EAST , east );
62
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_WEST , west );
63
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_TOP , top );
64
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_BOTTOM , bottom );
65
+
66
+ returnVal &= headerInt (headerKeys , RASTER3D_REGION_ROWS , rows );
67
+ returnVal &= headerInt (headerKeys , RASTER3D_REGION_COLS , cols );
68
+ returnVal &= headerInt (headerKeys , RASTER3D_REGION_DEPTHS , depths );
69
+
70
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_NSRES , ns_res );
71
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_EWRES , ew_res );
72
+ returnVal &= headerDouble (headerKeys , RASTER3D_REGION_TBRES , tb_res );
73
+
74
+ returnVal &= headerInt (headerKeys , RASTER3D_HEADER_TILEX , tileX );
75
+ returnVal &= headerInt (headerKeys , RASTER3D_HEADER_TILEY , tileY );
76
+ returnVal &= headerInt (headerKeys , RASTER3D_HEADER_TILEZ , tileZ );
77
+
78
+ returnVal &= headerValue (headerKeys , RASTER3D_HEADER_TYPE , "double" ,
79
+ "float" , DCELL_TYPE , FCELL_TYPE , type );
80
+ returnVal &= headerValue (headerKeys , RASTER3D_HEADER_COMPRESSION , "0" , "1" ,
81
+ 0 , 1 , compression );
82
+ returnVal &=
83
+ headerValue (headerKeys , RASTER3D_HEADER_USERLE , "0" , "1" , 0 , 1 , useRle );
84
+ returnVal &=
85
+ headerValue (headerKeys , RASTER3D_HEADER_USELZW , "0" , "1" , 0 , 1 , useLzw );
86
+
87
+ returnVal &= headerInt (headerKeys , RASTER3D_HEADER_PRECISION , precision );
88
+ returnVal &= headerInt (headerKeys , RASTER3D_HEADER_DATA_OFFSET , dataOffset );
89
+
90
+ returnVal &=
91
+ headerValue (headerKeys , RASTER3D_HEADER_USEXDR , "0" , "1" , 0 , 1 , useXdr );
92
+ returnVal &= headerValue (headerKeys , RASTER3D_HEADER_HASINDEX , "0" , "1" , 0 ,
93
+ 1 , hasIndex );
94
+ returnVal &= headerString (headerKeys , RASTER3D_HEADER_UNIT , unit );
95
+ /* New format and API changes */
96
+ if (!headerInt (headerKeys , RASTER3D_HEADER_VERTICAL_UNIT , vertical_unit ))
97
+ G_warning ("You are using an old raster3d data format, the vertical "
98
+ "unit is undefined. "
99
+ "Please use r3.support to define the vertical unit to avoid "
100
+ "this warning." );
101
+ /* New format and API changes */
102
+ if (!headerInt (headerKeys , RASTER3D_HEADER_VERSION , version )) {
103
+ G_warning ("You are using an old raster3d data format, the version is "
104
+ "undefined." );
105
+ * version = 1 ;
59
106
}
60
107
108
+ if (returnVal )
109
+ return 1 ;
110
+
111
+ Rast3d_error ("Rast3d_readWriteHeader: error reading/writing header" );
112
+ return 0 ;
113
+ }
114
+
115
+ static int Rast3d__writeHeader (
116
+ struct Key_Value * headerKeys , int * proj , int * zone , double * north ,
117
+ double * south , double * east , double * west , double * top , double * bottom ,
118
+ int * rows , int * cols , int * depths , double * ew_res , double * ns_res ,
119
+ double * tb_res , int * tileX , int * tileY , int * tileZ , int * type ,
120
+ int * compression , int * useRle , int * useLzw , int * precision , int * dataOffset ,
121
+ int * useXdr , int * hasIndex , char * * unit , int * vertical_unit , int * version )
122
+ {
123
+ int returnVal ;
124
+ int (* headerInt )(struct Key_Value * , const char * , const int * ),
125
+ (* headerDouble )(struct Key_Value * , const char * , const double * ),
126
+ (* headerValue )(struct Key_Value * , const char * , const char * ,
127
+ const char * , int , int , const int * );
128
+ int (* headerString )(struct Key_Value * , const char * , char * const * );
129
+
130
+ headerDouble = Rast3d_key_set_double ;
131
+ headerInt = Rast3d_key_set_int ;
132
+ headerString = Rast3d_key_set_string ;
133
+ headerValue = Rast3d_key_set_value ;
134
+
61
135
returnVal = 1 ;
62
136
returnVal &= headerInt (headerKeys , RASTER3D_REGION_PROJ , proj );
63
137
returnVal &= headerInt (headerKeys , RASTER3D_REGION_ZONE , zone );
@@ -141,11 +215,11 @@ int Rast3d_read_header(RASTER3D_Map *map, int *proj, int *zone, double *north,
141
215
142
216
headerKeys = G_read_key_value_file (path );
143
217
144
- if (!Rast3d_readWriteHeader (
145
- headerKeys , 1 , proj , zone , north , south , east , west , top , bottom ,
146
- rows , cols , depths , ew_res , ns_res , tb_res , tileX , tileY , tileZ ,
147
- type , compression , useRle , useLzw , precision , dataOffset , useXdr ,
148
- hasIndex , unit , vertical_unit , version )) {
218
+ if (!Rast3d__readHeader ( headerKeys , proj , zone , north , south , east , west ,
219
+ top , bottom , rows , cols , depths , ew_res , ns_res ,
220
+ tb_res , tileX , tileY , tileZ , type , compression ,
221
+ useRle , useLzw , precision , dataOffset , useXdr ,
222
+ hasIndex , unit , vertical_unit , version )) {
149
223
Rast3d_error (
150
224
"Rast3d_read_header: error extracting header key(s) of file %s" ,
151
225
path );
@@ -172,8 +246,8 @@ int Rast3d_write_header(RASTER3D_Map *map, int proj, int zone, double north,
172
246
173
247
headerKeys = G_create_key_value ();
174
248
175
- if (!Rast3d_readWriteHeader (
176
- headerKeys , 0 , & proj , & zone , & north , & south , & east , & west , & top ,
249
+ if (!Rast3d__writeHeader (
250
+ headerKeys , & proj , & zone , & north , & south , & east , & west , & top ,
177
251
& bottom , & rows , & cols , & depths , & ew_res , & ns_res , & tb_res , & tileX ,
178
252
& tileY , & tileZ , & type , & compression , & useRle , & useLzw , & precision ,
179
253
& dataOffset , & useXdr , & hasIndex , & unit , & vertical_unit , & version )) {
0 commit comments