25 static int get_bool(
const char *);
26 static void pr_winerr(
int,
const char *);
27 static void edge_sort(
float sides[4]);
28 static int read_old_format(
struct G_3dview *, FILE *);
30 static const int vers_major = 4;
31 static const int vers_minor = 1;
33 static int Suppress_warn = 0;
47 Suppress_warn =
b ? 0 : 1;
169 G_warning(
_(
"Unable to open %s for writing"), fname);
173 fprintf(fp,
"# %01d.%02d\n", vers_major, vers_minor);
174 fprintf(fp,
"PGM_ID: %s\n", View->
pgm_id);
177 fprintf(fp,
"north: %f\n", Win->
north);
178 fprintf(fp,
"south: %f\n", Win->
south);
179 fprintf(fp,
"east: %f\n", Win->
east);
180 fprintf(fp,
"west: %f\n", Win->
west);
181 fprintf(fp,
"rows: %d\n", Win->
rows);
182 fprintf(fp,
"cols: %d\n", Win->
cols);
185 fprintf(fp,
"north: %f\n", View->
vwin.
north);
186 fprintf(fp,
"south: %f\n", View->
vwin.
south);
187 fprintf(fp,
"east: %f\n", View->
vwin.
east);
188 fprintf(fp,
"west: %f\n", View->
vwin.
west);
189 fprintf(fp,
"rows: %d\n", View->
vwin.
rows);
190 fprintf(fp,
"cols: %d\n", View->
vwin.
cols);
193 fprintf(fp,
"TO_EASTING: %f\n", View->
from_to[1][0]);
194 fprintf(fp,
"TO_NORTHING: %f\n", View->
from_to[1][1]);
195 fprintf(fp,
"TO_HEIGHT: %f\n", View->
from_to[1][2]);
196 fprintf(fp,
"FROM_EASTING: %f\n", View->
from_to[0][0]);
197 fprintf(fp,
"FROM_NORTHING: %f\n", View->
from_to[0][1]);
198 fprintf(fp,
"FROM_HEIGHT: %f\n", View->
from_to[0][2]);
199 fprintf(fp,
"Z_EXAG: %f\n", View->
exag);
200 fprintf(fp,
"TWIST: %f\n", View->
twist);
201 fprintf(fp,
"FIELD_VIEW: %f\n", View->
fov);
202 fprintf(fp,
"MESH_FREQ: %d\n", View->
mesh_freq);
203 fprintf(fp,
"POLY_RES: %d\n", View->
poly_freq);
204 fprintf(fp,
"DOAVG: %d\n", View->
doavg);
206 fprintf(fp,
"DOZERO: %d\n", View->
dozero);
208 fprintf(fp,
"COLORGRID: %d\n", View->
colorgrid);
209 fprintf(fp,
"SHADING: %d\n", View->
shading);
210 fprintf(fp,
"FRINGE: %d\n", View->
fringe);
211 fprintf(fp,
"BG_COL: %s\n", View->
bg_col);
212 fprintf(fp,
"GRID_COL: %s\n", View->
grid_col);
213 fprintf(fp,
"OTHER_COL: %s\n", View->
other_col);
214 fprintf(fp,
"SURFACEONLY: %d\n", View->
surfonly);
215 fprintf(fp,
"LIGHTS_ON: %d\n", View->
lightson);
216 fprintf(fp,
"LIGHTPOS: %f %f %f %f\n", View->
lightpos[0], View->
lightpos[1],
220 fprintf(fp,
"LIGHTAMBIENT: %f\n", View->
ambient);
221 fprintf(fp,
"SHINE: %f\n", View->
shine);
247 char buffer[80], keystring[24], boo[8], nbuf[128], ebuf[128];
248 int lap, v_maj, v_min, wind_keys = 0, reqkeys = 0;
252 if (mapset !=
NULL) {
254 G_warning(
_(
"Unable to open %s for reading"), fname);
261 if (
NULL != fgets(buffer, 80, fp)) {
262 if (buffer[0] !=
'#') {
264 if (0 <= read_old_format(View, fp))
270 sscanf(buffer,
"#%d.%d\n", &v_maj, &v_min);
271 if (v_maj == vers_major && v_min == vers_minor)
276 while (
NULL != fgets(buffer, 75, fp)) {
277 if (buffer[0] !=
'#') {
279 sscanf(buffer,
"%[^:]:", keystring);
281 if (!strcmp(keystring,
"PGM_ID")) {
282 sscanf(buffer,
"%*s%s", (View->
pgm_id));
285 if (!strcmp(keystring,
"north")) {
286 sscanf(buffer,
"%*s%lf", &(View->
vwin.
north));
290 if (!strcmp(keystring,
"south")) {
291 sscanf(buffer,
"%*s%lf", &(View->
vwin.
south));
295 if (!strcmp(keystring,
"east")) {
296 sscanf(buffer,
"%*s%lf", &(View->
vwin.
east));
300 if (!strcmp(keystring,
"west")) {
301 sscanf(buffer,
"%*s%lf", &(View->
vwin.
west));
305 if (!strcmp(keystring,
"rows")) {
306 sscanf(buffer,
"%*s%d", &(View->
vwin.
rows));
310 if (!strcmp(keystring,
"cols")) {
311 sscanf(buffer,
"%*s%d", &(View->
vwin.
cols));
315 if (!strcmp(keystring,
"TO_EASTING")) {
316 sscanf(buffer,
"%*s%f", &(View->
from_to[1][0]));
320 if (!strcmp(keystring,
"TO_NORTHING")) {
321 sscanf(buffer,
"%*s%f", &(View->
from_to[1][1]));
325 if (!strcmp(keystring,
"TO_HEIGHT")) {
326 sscanf(buffer,
"%*s%f", &(View->
from_to[1][2]));
330 if (!strcmp(keystring,
"FROM_EASTING")) {
331 sscanf(buffer,
"%*s%f", &(View->
from_to[0][0]));
335 if (!strcmp(keystring,
"FROM_NORTHING")) {
336 sscanf(buffer,
"%*s%f", &(View->
from_to[0][1]));
340 if (!strcmp(keystring,
"FROM_HEIGHT")) {
341 sscanf(buffer,
"%*s%f", &(View->
from_to[0][2]));
345 if (!strcmp(keystring,
"Z_EXAG")) {
346 sscanf(buffer,
"%*s%f", &(View->
exag));
350 if (!strcmp(keystring,
"MESH_FREQ")) {
351 sscanf(buffer,
"%*s%d", &(View->
mesh_freq));
354 if (!strcmp(keystring,
"POLY_RES")) {
355 sscanf(buffer,
"%*s%d", &(View->
poly_freq));
358 if (!strcmp(keystring,
"DOAVG")) {
359 sscanf(buffer,
"%*s%d", &(View->
doavg));
362 if (!strcmp(keystring,
"FIELD_VIEW")) {
363 sscanf(buffer,
"%*s%f", &(View->
fov));
367 if (!strcmp(keystring,
"TWIST")) {
368 sscanf(buffer,
"%*s%f", &(View->
twist));
371 if (!strcmp(keystring,
"DISPLAY_TYPE")) {
375 if (!strcmp(keystring,
"DOZERO")) {
376 sscanf(buffer,
"%*s%s", boo);
377 View->
dozero = get_bool(boo);
380 if (!strcmp(keystring,
"COLORGRID")) {
381 sscanf(buffer,
"%*s%s", boo);
385 if (!strcmp(keystring,
"FRINGE")) {
386 sscanf(buffer,
"%*s%s", boo);
387 View->
fringe = get_bool(boo);
390 if (!strcmp(keystring,
"SHADING")) {
391 sscanf(buffer,
"%*s%s", boo);
395 if (!strcmp(keystring,
"BG_COL")) {
396 sscanf(buffer,
"%*s%s", View->
bg_col);
399 if (!strcmp(keystring,
"GRID_COL")) {
400 sscanf(buffer,
"%*s%s", View->
grid_col);
403 if (!strcmp(keystring,
"OTHER_COL")) {
404 sscanf(buffer,
"%*s%s", View->
other_col);
407 if (!strcmp(keystring,
"SURFACEONLY")) {
408 sscanf(buffer,
"%*s%s", boo);
412 if (!strcmp(keystring,
"LIGHTS_ON")) {
413 sscanf(buffer,
"%*s%s", boo);
417 if (!strcmp(keystring,
"LIGHTPOS")) {
418 sscanf(buffer,
"%*s%f%f%f%f", &(View->
lightpos[0]),
423 if (!strcmp(keystring,
"LIGHTCOL")) {
424 sscanf(buffer,
"%*s%f%f%f", &(View->
lightcol[0]),
428 if (!strcmp(keystring,
"LIGHTAMBIENT")) {
429 sscanf(buffer,
"%*s%f", &(View->
ambient));
432 if (!strcmp(keystring,
"SHINE")) {
433 sscanf(buffer,
"%*s%f", &(View->
shine));
445 if (wind_keys == 6) {
454 if (!Suppress_warn) {
455 if (95 > (lap = compare_wind(&(View->
vwin), &curwin))) {
457 fprintf(stderr,
_(
"GRASS window when view was saved:\n"));
459 fprintf(stderr,
"north: %s\n", nbuf);
461 fprintf(stderr,
"south: %s\n", nbuf);
463 fprintf(stderr,
"east: %s\n", ebuf);
465 fprintf(stderr,
"west: %s\n", ebuf);
466 pr_winerr(lap, fname);
471 G_warning(
_(
"Unable to open %s for reading"), fname);
483 static int compare_wind(
const struct Cell_head *savedwin,
486 float e_ings[4], n_ings[4], area_lap, area_saved;
500 e_ings[0] = savedwin->
west;
501 e_ings[1] = savedwin->
east;
502 e_ings[2] = curwin->
west;
503 e_ings[3] = curwin->
east;
506 n_ings[0] = savedwin->
south;
507 n_ings[1] = savedwin->
north;
508 n_ings[2] = curwin->
south;
509 n_ings[3] = curwin->
north;
512 area_lap = (e_ings[2] - e_ings[1]) * (n_ings[2] - n_ings[1]);
516 return ((
int)(area_lap * 100.0 / area_saved));
519 static int get_bool(
const char *str)
521 if (str[0] ==
'y' || str[0] ==
'Y')
523 if (str[0] ==
'n' || str[0] ==
'N')
526 return (atoi(str) ? 1 : 0);
531 const char *viewname)
535 G_warning(
_(
" Window saved in \"%s\" is completely outside of current "
540 G_warning(
_(
" Only %d%% of window saved in \"%s\" overlaps with "
541 "current GRASS window."),
550 static void edge_sort(
float sides[4])
555 for (i = 0; i < 4; ++i) {
556 for (j = i + 1; j < 4; ++j) {
557 if (sides[j] < sides[i]) {
566 static int read_old_format(
struct G_3dview *v, FILE *fp)
574 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][0])))
576 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][1])))
578 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][2])))
580 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][0])))
582 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][1])))
584 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][2])))
586 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
exag)))
588 sscanf(fgets(buffer, 80, fp),
"%d", &(v->
mesh_freq));
589 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
fov)))
591 if (1 == sscanf(fgets(buffer, 80, fp),
"%lf", &td)) {
597 sscanf(fgets(buffer, 80, fp),
"%s", boo);
599 sscanf(fgets(buffer, 80, fp),
"%s", boo);
600 v->
dozero = get_bool(boo);
601 sscanf(fgets(buffer, 80, fp),
"%s", v->
grid_col);
605 sscanf(fgets(buffer, 80, fp),
"%s", v->
other_col);
606 sscanf(fgets(buffer, 80, fp),
"%s", v->
bg_col);
607 sscanf(fgets(buffer, 80, fp),
"%s", boo);
608 v->
doavg = get_bool(boo);
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch)
void G_warning(const char *,...) __attribute__((format(printf
void G_get_set_window(struct Cell_head *)
Get the current working window (region)
void G_format_easting(double, char *, int)
Easting to ASCII.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
int G_projection(void)
Query cartographic projection.
void G_format_northing(double, char *, int)
Northing to ASCII.
2D/3D raster map header (used also for region)
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
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)
double east
Extent coordinates (east)
double ns_res
Resolution - north to south cell size for 2D data.
int rows
Number of rows for 2D data.
int cols
Number of columns for 2D data.
double south
Extent coordinates (south)
double west
Extent coordinates (west)
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View)
Gets a 3D View.
void G_3dview_warning(int b)
Turns 3D View warnings on and off.
int G_get_3dview_defaults(struct G_3dview *v, struct Cell_head *w)
Sets default for v based on w.
int G_put_3dview(const char *fname, const struct G_3dview *View, const struct Cell_head *Win)
Saves info to a 3d.view file in the current mapset.