17#include "gis_local_proto.h"
19static int scan_item(
const char *,
char *,
char *);
20static int scan_int(
const char *,
int *);
21static double scan_double(
const char *,
double *);
45#define SET(x) flags |= (1 << x)
46#define TEST(x) (flags & (1 << x))
60 G_debug(2,
"G__read_Cell_head");
65 while (
G_getl(buf,
sizeof(buf), fd))
72 while (
G_getl(buf,
sizeof(buf), fd)) {
80 while (array[
count]) {
102 G_debug(2,
"G__read_Cell_head_array");
131 for (line = 1; (buf = array[i++]); line++) {
135 switch (scan_item(buf, label, value)) {
137 G_fatal_error(
_(
"Syntax error in cell header, line %d: %s"), line,
144 if (
strncmp(label,
"proj", 4) == 0) {
148 if (!scan_int(value, &cellhd->
proj))
154 if (
strncmp(label,
"zone", 4) == 0) {
158 if (!scan_int(value, &cellhd->
zone))
172 for (line = 1; (buf = array[i++]); line++) {
173 G_debug(3,
"region item: %s", buf);
174 switch (scan_item(buf, label, value)) {
176 G_fatal_error(
_(
"Syntax error in cell header, line %d: %s"), line,
184 if (
strncmp(label,
"proj", 4) == 0)
186 if (
strncmp(label,
"zone", 4) == 0)
189 if (
strncmp(label,
"nort", 4) == 0) {
197 if (
strncmp(label,
"sout", 4) == 0) {
205 if (
strncmp(label,
"east", 4) == 0) {
213 if (
strncmp(label,
"west", 4) == 0) {
221 if (
strncmp(label,
"top", 3) == 0) {
224 if (!scan_double(value, &cellhd->
top))
229 if (
strncmp(label,
"bottom", 6) == 0) {
232 if (!scan_double(value, &cellhd->
bottom))
242 if (cellhd->
ew_res <= 0.0)
247 if (
strncmp(label,
"e-w resol3", 10) == 0) {
262 if (cellhd->
ns_res <= 0.0)
267 if (
strncmp(label,
"n-s resol3", 10) == 0) {
277 if (
strncmp(label,
"t-b ", 4) == 0) {
280 if (!scan_double(value, &cellhd->
tb_res))
282 if (cellhd->
tb_res <= 0.0)
290 if (!scan_int(value, &cellhd->
rows))
292 if (cellhd->
rows <= 0)
297 if (
strncmp(label,
"rows3", 5) == 0) {
300 if (!scan_int(value, &cellhd->
rows3))
302 if (cellhd->
rows3 <= 0)
310 if (!scan_int(value, &cellhd->
cols))
312 if (cellhd->
cols <= 0)
317 if (
strncmp(label,
"cols3", 5) == 0) {
320 if (!scan_int(value, &cellhd->
cols3))
322 if (cellhd->
cols3 <= 0)
327 if (
strncmp(label,
"depths", 6) == 0) {
330 if (!scan_int(value, &cellhd->
depths))
337 if (
strncmp(label,
"form", 4) == 0) {
340 if (!scan_int(value, &cellhd->
format))
345 if (
strncmp(label,
"comp", 4) == 0) {
353 G_fatal_error(
_(
"Syntax error in cell header, line %d: %s"), line, buf);
398static 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)
417static int scan_int(
const char *buf,
int *n)
422 return (
sscanf(buf,
"%d%1s", n, dummy) == 1 && *dummy == 0);
425static double scan_double(
const char *buf,
double *n)
430 return (
sscanf(buf,
"%lf%1s", n, dummy) == 1 && *dummy == 0);
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_scan_easting(const char *, double *, int)
ASCII easting to double.
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
void G_strip(char *)
Removes all leading and trailing white space from string.
int G_scan_resolution(const char *, double *, int)
ASCII resolution to double.
char * G_store(const char *)
Copy string to allocated memory.
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
void G_adjust_Cell_head(struct Cell_head *, int, int)
Adjust cell header.
int G_debug(int, const char *,...) __attribute__((format(printf
int G_scan_northing(const char *, double *, int)
ASCII northing to double.
void G__read_Cell_head_array(char **array, struct Cell_head *cellhd)
Read window from NULL terminated array of strings (for internal use only)
void G__read_Cell_head(FILE *fd, struct Cell_head *cellhd)
Read cell header (for internal use only)
2D/3D raster map header (used also for region)
int cols3
Number of columns for 3D data.
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
double bottom
Extent coordinates (bottom) - 3D data.
int compressed
Compression mode (raster header only)
int format
Max number of bytes per raster data value minus 1 (raster header only)
int zone
Projection zone (UTM)
int depths
number of depths for 3D data
double east
Extent coordinates (east)
double ew_res3
Resolution - east to west cell size for 3D data.
double ns_res
Resolution - north to south cell size for 2D data.
double ns_res3
Resolution - north to south cell size for 3D data.
double top
Extent coordinates (top) - 3D data.
int rows3
Number of rows for 3D data.
int rows
Number of rows for 2D data.
int cols
Number of columns for 2D data.
double south
Extent coordinates (south)
double tb_res
Resolution - top to bottom cell size for 3D data.
double west
Extent coordinates (west)