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