16 #include <grass/gis.h>
17 #include <grass/glocale.h>
19 #define ERROR(x,line) return error(x,line)
20 static int scan_item(
const char *,
char *,
char *);
21 static int scan_int(
const char *,
int *);
22 static double scan_double(
const char *,
double *);
23 static char *error(
const char *,
int);
47 #define SET(x) flags|=(1<<x)
48 #define TEST(x) (flags&(1<<x))
51 struct Cell_head *cellhd,
int is_cellhd);
56 char *result, **array;
59 G_debug(2,
"G__read_Cell_head");
64 while (
G_getl(buf,
sizeof(buf), fd))
67 array = (
char **)G_calloc(count + 1,
sizeof(
char *));
71 while (
G_getl(buf,
sizeof(buf), fd)) {
79 while (array[count]) {
90 struct Cell_head *cellhd,
int is_cellhd)
100 G_debug(2,
"G__read_Cell_head_array");
113 cellhd->compressed = -1;
114 cellhd->ew_res = 0.0;
115 cellhd->ew_res3 = 1.0;
116 cellhd->ns_res = 0.0;
117 cellhd->ns_res3 = 1.0;
118 cellhd->tb_res = 1.0;
124 cellhd->bottom = 0.0;
129 for (line = 1; (buf = array[i++]); line++) {
133 switch (scan_item(buf, label, value)) {
141 if (strncmp(label,
"proj", 4) == 0) {
143 ERROR(_(
"duplicate projection field"), line);
145 if (!scan_int(value, &cellhd->proj))
151 if (strncmp(label,
"zone", 4) == 0) {
153 ERROR(_(
"duplicate zone field"), line);
155 if (!scan_int(value, &cellhd->zone))
163 ERROR(_(
"projection field missing"), 0);
165 ERROR(_(
"zone field missing"), 0);
169 for (line = 1; (buf = array[i++]); line++) {
170 G_debug(3,
"region item: %s", buf);
171 switch (scan_item(buf, label, value)) {
180 if (strncmp(label,
"proj", 4) == 0)
182 if (strncmp(label,
"zone", 4) == 0)
185 if (strncmp(label,
"nort", 4) == 0) {
187 ERROR(_(
"duplicate north field"), line);
193 if (strncmp(label,
"sout", 4) == 0) {
195 ERROR(_(
"duplicate south field"), line);
201 if (strncmp(label,
"east", 4) == 0) {
203 ERROR(_(
"duplicate east field"), line);
209 if (strncmp(label,
"west", 4) == 0) {
211 ERROR(_(
"duplicate west field"), line);
217 if (strncmp(label,
"top", 3) == 0) {
219 ERROR(_(
"duplicate top field"), line);
220 if (!scan_double(value, &cellhd->top))
225 if (strncmp(label,
"bottom", 6) == 0) {
227 ERROR(_(
"duplicate bottom field"), line);
228 if (!scan_double(value, &cellhd->bottom))
233 if (strncmp(label,
"e-w ", 4) == 0 && strlen(label) == 9) {
235 ERROR(_(
"duplicate e-w resolution field"), line);
238 if (cellhd->ew_res <= 0.0)
243 if (strncmp(label,
"e-w resol3", 10) == 0) {
245 ERROR(_(
"duplicate 3D e-w resolution field"), line);
248 if (cellhd->ew_res3 <= 0.0)
253 if (strncmp(label,
"n-s ", 4) == 0 && strlen(label) == 9) {
255 ERROR(_(
"duplicate n-s resolution field"), line);
258 if (cellhd->ns_res <= 0.0)
263 if (strncmp(label,
"n-s resol3", 10) == 0) {
265 ERROR(_(
"duplicate 3D n-s resolution field"), line);
268 if (cellhd->ns_res3 <= 0.0)
273 if (strncmp(label,
"t-b ", 4) == 0) {
275 ERROR(_(
"duplicate t-b resolution field"), line);
276 if (!scan_double(value, &cellhd->tb_res))
278 if (cellhd->tb_res <= 0.0)
283 if (strncmp(label,
"rows", 4) == 0 && strlen(label) == 4) {
285 ERROR(_(
"duplicate rows field"), line);
286 if (!scan_int(value, &cellhd->rows))
288 if (cellhd->rows <= 0)
293 if (strncmp(label,
"rows3", 5) == 0) {
295 ERROR(_(
"duplicate 3D rows field"), line);
296 if (!scan_int(value, &cellhd->rows3))
298 if (cellhd->rows3 <= 0)
303 if (strncmp(label,
"cols", 4) == 0 && strlen(label) == 4) {
305 ERROR(_(
"duplicate cols field"), line);
306 if (!scan_int(value, &cellhd->cols))
308 if (cellhd->cols <= 0)
313 if (strncmp(label,
"cols3", 5) == 0) {
315 ERROR(_(
"duplicate 3D cols field"), line);
316 if (!scan_int(value, &cellhd->cols3))
318 if (cellhd->cols3 <= 0)
323 if (strncmp(label,
"depths", 6) == 0) {
325 ERROR(_(
"duplicate depths field"), line);
326 if (!scan_int(value, &cellhd->depths))
328 if (cellhd->depths <= 0)
333 if (strncmp(label,
"form", 4) == 0) {
335 ERROR(_(
"duplicate format field"), line);
336 if (!scan_int(value, &cellhd->format))
341 if (strncmp(label,
"comp", 4) == 0) {
343 ERROR(_(
"duplicate compressed field"), line);
344 if (!scan_int(value, &cellhd->compressed))
354 ERROR(_(
"north field missing"), 0);
356 ERROR(_(
"south field missing"), 0);
358 ERROR(_(
"west field missing"), 0);
360 ERROR(_(
"east field missing"), 0);
362 ERROR(_(
"cols field missing"), 0);
364 ERROR(_(
"rows field missing"), 0);
375 ERROR(_(
"ewres3 field missing"), 0);
377 ERROR(_(
"nsres3 field missing"), 0);
379 ERROR(_(
"cols3 field missing"), 0);
381 ERROR(_(
"rows3 field missing"), 0);
384 cellhd->ew_res3 = cellhd->ew_res;
385 cellhd->ns_res3 = cellhd->ns_res;
386 cellhd->cols3 = cellhd->cols;
387 cellhd->rows3 = cellhd->rows;
398 static int scan_item(
const char *
buf,
char *
label,
char *
value)
401 if (sscanf(buf,
"%1s", label) != 1)
409 if (sscanf(buf,
"%[^:]:%[^\n]", label, value) != 2)
417 static int scan_int(
const char *buf,
int *
n)
422 return (sscanf(buf,
"%d%1s", n, dummy) == 1 && *dummy == 0);
425 static double scan_double(
const char *buf,
double *n)
430 return (sscanf(buf,
"%lf%1s", n, dummy) == 1 && *dummy == 0);
433 static char *error(
const char *
msg,
int line)
438 sprintf(buf, _(
"line %d: <%s>"), line, msg);
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
char * G_store(const char *s)
Copy string to allocated memory.
char * G__read_Cell_head_array(char **array, struct Cell_head *cellhd, int is_cellhd)
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
int G_strip(char *buf)
Removes all leading and trailing white space from string.
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
int G_getl(char *buf, int n, FILE *fd)
gets a line of text from a file
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G__read_Cell_head(FILE *fd, struct Cell_head *cellhd, int is_cellhd)
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.