1 
2 /**********************************************************
3 * I_get_group_elev (group, elev_layer, mapset_elev, tl, math_exp, units, nd);
4 * I_put_group_elev (group, elev_layer, mapset_elev, tl, math_exp, units, nd);
5 **********************************************************/
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <grass/gis.h>
9 #include <grass/ortholib.h>
10 #include <grass/glocale.h>
11 #include "orthophoto.h"
12 
13 
14 #define IN_BUF 200
15 
16 
17 /* Put the "elev" name into the block file "ELEV" */
I_put_group_elev(char * group,char * elev,char * mapset_elev,char * tl,char * math_exp,char * units,char * nd)18 int I_put_group_elev(char *group, char *elev, char *mapset_elev, char *tl,
19 		     char *math_exp, char *units, char *nd)
20 {
21     FILE *fd;
22 
23     /*    G_suppress_warnings(1); */
24     fd = (FILE *) I_fopen_group_elev_new(group);
25     /*    G_suppress_warnings(0); */
26     if (fd == NULL)
27 	return 0;
28 
29     fprintf(fd, "elevation layer :%s\n", elev);
30     fprintf(fd, "mapset elevation:%s\n", mapset_elev);
31     fprintf(fd, "location        :%s\n", tl);
32     fprintf(fd, "math expression :%s\n", math_exp);
33     fprintf(fd, "units           :%s\n", units);
34     fprintf(fd, "no data values  :%s\n", nd);
35 
36     return 0;
37 }
38 
39 
40 /* Return the elev name from the block file ELEV
41     returns 0 on fail,  1 on success */
I_get_group_elev(char * group,char * elev,char * mapset_elev,char * tl,char * math_exp,char * units,char * nd)42 int I_get_group_elev(char *group, char *elev, char *mapset_elev, char *tl,
43 		     char *math_exp, char *units, char *nd)
44 {
45     char *err;
46     char buf[IN_BUF];
47     FILE *fd;
48 
49     if (!I_find_group_elev_file(group)) {
50 	G_warning(
51 	    _("Unable to find elevation file for group <%s> in mapset <%s>"),
52 	      group, G_mapset());
53 	return 0;
54     }
55 
56     G_suppress_warnings(1);
57     fd = I_fopen_group_elev_old(group);
58     G_suppress_warnings(0);
59 
60     if (!fd) {
61 	G_warning(
62 	    _("Unable to open elevation file for group <%s> in mapset <%s>"),
63 	      group, G_mapset());
64 	G_sleep(3);
65 
66 	return 0;
67     }
68 
69     err=fgets(buf, IN_BUF, fd);
70     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
71     sscanf(buf, "elevation layer :%s\n", elev);
72     err=fgets(buf, IN_BUF, fd);
73     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
74     sscanf(buf, "mapset elevation:%s\n", mapset_elev);
75     err=fgets(buf, IN_BUF, fd);
76     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
77     sscanf(buf, "location        :%s\n", tl);
78     err=fgets(buf, IN_BUF, fd);
79     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
80     sscanf(buf, "math expression :%s\n", math_exp);
81     err=fgets(buf, IN_BUF, fd);
82     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
83     sscanf(buf, "units           :%s\n", units);
84     err=fgets(buf, IN_BUF, fd);
85     if(err==NULL) G_fatal_error(_("Unable to read elevation parameter file"));
86     sscanf(buf, "no data values  :%s\n", nd);
87     fclose(fd);
88 
89     return 1;
90 }
91