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)) {
147 if (strncmp(label,
"proj", 4) == 0) {
151 if (!scan_int(value, &cellhd->proj))
157 if (strncmp(label,
"zone", 4) == 0) {
161 if (!scan_int(value, &cellhd->zone))
175 for (line = 1; (buf = array[i++]); line++) {
176 G_debug(3,
"region item: %s", buf);
177 switch (scan_item(buf, label, value)) {
186 if (strncmp(label,
"proj", 4) == 0)
188 if (strncmp(label,
"zone", 4) == 0)
191 if (strncmp(label,
"nort", 4) == 0) {
199 if (strncmp(label,
"sout", 4) == 0) {
207 if (strncmp(label,
"east", 4) == 0) {
215 if (strncmp(label,
"west", 4) == 0) {
223 if (strncmp(label,
"top", 3) == 0) {
226 if (!scan_double(value, &cellhd->top))
231 if (strncmp(label,
"bottom", 6) == 0) {
234 if (!scan_double(value, &cellhd->bottom))
239 if (strncmp(label,
"e-w ", 4) == 0 && strlen(label) == 9) {
244 if (cellhd->ew_res <= 0.0)
249 if (strncmp(label,
"e-w resol3", 10) == 0) {
254 if (cellhd->ew_res3 <= 0.0)
259 if (strncmp(label,
"n-s ", 4) == 0 && strlen(label) == 9) {
264 if (cellhd->ns_res <= 0.0)
269 if (strncmp(label,
"n-s resol3", 10) == 0) {
274 if (cellhd->ns_res3 <= 0.0)
279 if (strncmp(label,
"t-b ", 4) == 0) {
282 if (!scan_double(value, &cellhd->tb_res))
284 if (cellhd->tb_res <= 0.0)
289 if (strncmp(label,
"rows", 4) == 0 && strlen(label) == 4) {
292 if (!scan_int(value, &cellhd->rows))
294 if (cellhd->rows <= 0)
299 if (strncmp(label,
"rows3", 5) == 0) {
302 if (!scan_int(value, &cellhd->rows3))
304 if (cellhd->rows3 <= 0)
309 if (strncmp(label,
"cols", 4) == 0 && strlen(label) == 4) {
312 if (!scan_int(value, &cellhd->cols))
314 if (cellhd->cols <= 0)
319 if (strncmp(label,
"cols3", 5) == 0) {
322 if (!scan_int(value, &cellhd->cols3))
324 if (cellhd->cols3 <= 0)
329 if (strncmp(label,
"depths", 6) == 0) {
332 if (!scan_int(value, &cellhd->depths))
334 if (cellhd->depths <= 0)
339 if (strncmp(label,
"form", 4) == 0) {
342 if (!scan_int(value, &cellhd->format))
347 if (strncmp(label,
"comp", 4) == 0) {
350 if (!scan_int(value, &cellhd->compressed))
390 cellhd->ew_res3 = cellhd->ew_res;
391 cellhd->ns_res3 = cellhd->ns_res;
392 cellhd->cols3 = cellhd->cols;
393 cellhd->rows3 = cellhd->rows;
400 static int scan_item(
const char *buf,
char *label,
char *value)
403 if (sscanf(buf,
"%1s", label) != 1)
411 if (sscanf(buf,
"%[^:]:%[^\n]", label, value) != 2)
419 static int scan_int(
const char *buf,
int *n)
424 return (sscanf(buf,
"%d%1s", n, dummy) == 1 && *dummy == 0);
427 static double scan_double(
const char *buf,
double *n)
432 return (sscanf(buf,
"%lf%1s", n, dummy) == 1 && *dummy == 0);
void G_strip(char *buf)
Removes all leading and trailing white space from string.
void G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
char * G_store(const char *s)
Copy string to allocated memory.
void G__read_Cell_head(FILE *fd, struct Cell_head *cellhd, int is_cellhd)
Read cell header (for internal use only)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
void G__read_Cell_head_array(char **array, struct Cell_head *cellhd, int is_cellhd)
Read window from NULL terminated array of strings (for internal use only)
int G_debug(int level, const char *msg,...)
Print debugging message.
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.
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
void G_free(void *buf)
Free allocated memory.
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.