16 #include <grass/gis.h>
17 #include <grass/glocale.h>
19 #include "gis_local_proto.h"
21 static int scan_item(
const char *,
char *,
char *);
22 static int scan_int(
const char *,
int *);
23 static double scan_double(
const char *,
double *);
47 #define SET(x) flags|=(1<<x)
48 #define TEST(x) (flags&(1<<x))
63 G_debug(2,
"G__read_Cell_head");
68 while (
G_getl(buf,
sizeof(buf), fd))
71 array = (
char **)G_calloc(
count + 1,
sizeof(
char *));
75 while (
G_getl(buf,
sizeof(buf), fd)) {
83 while (array[
count]) {
98 struct Cell_head *cellhd,
int is_cellhd)
106 G_debug(2,
"G__read_Cell_head_array");
119 cellhd->compressed = -1;
120 cellhd->ew_res = 0.0;
121 cellhd->ew_res3 = 1.0;
122 cellhd->ns_res = 0.0;
123 cellhd->ns_res3 = 1.0;
124 cellhd->tb_res = 1.0;
130 cellhd->bottom = 0.0;
135 for (line = 1; (buf = array[i++]); line++) {
139 switch (scan_item(buf, label, value)) {
148 if (strncmp(label,
"proj", 4) == 0) {
152 if (!scan_int(value, &cellhd->proj))
158 if (strncmp(label,
"zone", 4) == 0) {
162 if (!scan_int(value, &cellhd->zone))
176 for (line = 1; (buf = array[i++]); line++) {
177 G_debug(3,
"region item: %s", buf);
178 switch (scan_item(buf, label, value)) {
188 if (strncmp(label,
"proj", 4) == 0)
190 if (strncmp(label,
"zone", 4) == 0)
193 if (strncmp(label,
"nort", 4) == 0) {
201 if (strncmp(label,
"sout", 4) == 0) {
209 if (strncmp(label,
"east", 4) == 0) {
217 if (strncmp(label,
"west", 4) == 0) {
225 if (strncmp(label,
"top", 3) == 0) {
228 if (!scan_double(value, &cellhd->top))
233 if (strncmp(label,
"bottom", 6) == 0) {
236 if (!scan_double(value, &cellhd->bottom))
241 if (strncmp(label,
"e-w ", 4) == 0 && strlen(label) == 9) {
246 if (cellhd->ew_res <= 0.0)
251 if (strncmp(label,
"e-w resol3", 10) == 0) {
255 G_fatal_error(_(
"Invalid 3D e-w resolution field: %s"), value);
256 if (cellhd->ew_res3 <= 0.0)
257 G_fatal_error(_(
"Invalid 3D e-w resolution field: %s"), value);
261 if (strncmp(label,
"n-s ", 4) == 0 && strlen(label) == 9) {
266 if (cellhd->ns_res <= 0.0)
271 if (strncmp(label,
"n-s resol3", 10) == 0) {
275 G_fatal_error(_(
"Invalid 3D n-s resolution field: %s"), value);
276 if (cellhd->ns_res3 <= 0.0)
277 G_fatal_error(_(
"Invalid 3D n-s resolution field: %s"), value);
281 if (strncmp(label,
"t-b ", 4) == 0) {
284 if (!scan_double(value, &cellhd->tb_res))
286 if (cellhd->tb_res <= 0.0)
291 if (strncmp(label,
"rows", 4) == 0 && strlen(label) == 4) {
294 if (!scan_int(value, &cellhd->rows))
296 if (cellhd->rows <= 0)
301 if (strncmp(label,
"rows3", 5) == 0) {
304 if (!scan_int(value, &cellhd->rows3))
306 if (cellhd->rows3 <= 0)
311 if (strncmp(label,
"cols", 4) == 0 && strlen(label) == 4) {
314 if (!scan_int(value, &cellhd->cols))
316 if (cellhd->cols <= 0)
321 if (strncmp(label,
"cols3", 5) == 0) {
324 if (!scan_int(value, &cellhd->cols3))
326 if (cellhd->cols3 <= 0)
331 if (strncmp(label,
"depths", 6) == 0) {
334 if (!scan_int(value, &cellhd->depths))
336 if (cellhd->depths <= 0)
341 if (strncmp(label,
"form", 4) == 0) {
344 if (!scan_int(value, &cellhd->format))
349 if (strncmp(label,
"comp", 4) == 0) {
352 if (!scan_int(value, &cellhd->compressed))
393 cellhd->ew_res3 = cellhd->ew_res;
394 cellhd->ns_res3 = cellhd->ns_res;
395 cellhd->cols3 = cellhd->cols;
396 cellhd->rows3 = cellhd->rows;
403 static int scan_item(
const char *buf,
char *label,
char *value)
406 if (sscanf(buf,
"%1s", label) != 1)
414 if (sscanf(buf,
"%[^:]:%[^\n]", label, value) != 2)
422 static int scan_int(
const char *buf,
int *n)
427 return (sscanf(buf,
"%d%1s", n, dummy) == 1 && *dummy == 0);
430 static double scan_double(
const char *buf,
double *n)
435 return (sscanf(buf,
"%lf%1s", n, dummy) == 1 && *dummy == 0);