~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/photo.rectify/ask_elev.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* #include "gis.h" */
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include <grass/vask.h>
5
 
#include "global.h"
6
 
 
7
 
#define ZERO_DATA  0
8
 
 
9
 
int ask_elev_data(void)
10
 
{
11
 
    char buf1[60];
12
 
    char buf2[60];
13
 
    char units[10];
14
 
    char *tl;                   /* Target Location */
15
 
    char *elev_data;            /* Tempoary elevation data layer */
16
 
    short ok;
17
 
    int no_data_value = ZERO_DATA;
18
 
 
19
 
    tl = (char *)G_calloc(40, sizeof(char));
20
 
    elev_data = (char *)G_calloc(40, sizeof(char));
21
 
    tl = G_location();
22
 
 
23
 
    sprintf(elev_data, "ELEV_DATA");
24
 
    sprintf(units, "METERS");
25
 
    *buf1 = '\0';
26
 
 
27
 
    ok = 0;
28
 
 
29
 
  /** Ask user if modification of elevation data is needed **/
30
 
    ok = G_yes("\nModify the data used for elevation ? ", ok);
31
 
    if (!ok) {
32
 
        select_target_env();
33
 
        if ((mapset_elev = G_find_cell(elev_layer, "")) == NULL)
34
 
            exit(0);
35
 
        select_current_env();
36
 
        return (0);
37
 
    }
38
 
 
39
 
    ok = 0;
40
 
    while (!ok) {
41
 
        /* List options on the screen for the user to answer */
42
 
        ok = 1;
43
 
        V_clear();
44
 
        V_line(1, "Please check the G_mapcalc convention:");
45
 
        V_line(3,
46
 
               "ELEV_DATA  =  CELL FILE  [MAPSET  in  LOCATION] [MATH EXPERSION][UNITS]");
47
 
 
48
 
        V_line(5, "ELEV_DATA :       ");
49
 
        V_line(6, "CELL FILE :       ");
50
 
        V_line(7, "MAPSET :          ");
51
 
        V_line(8, "LOCATION :        ");
52
 
        V_line(9, "MATH EXPRESSION : ");
53
 
        V_line(10, "UNITS :           ");
54
 
        V_line(12, "NO DATA VALUES = :");
55
 
 
56
 
 
57
 
        /* V_ques ( variable, type, row, col, length) ; */
58
 
        V_ques(elev_data, 's', 5, 20, 40);
59
 
        V_const(elev_layer, 's', 6, 20, 40);
60
 
        V_const(mapset_elev, 's', 7, 20, 40);
61
 
        V_const(tl, 's', 8, 20, 40);
62
 
        V_ques(buf1, 's', 9, 20, 40);
63
 
        V_const(units, 's', 10, 20, 10);
64
 
        V_ques(&no_data_value, 'i', 12, 20, 10);
65
 
 
66
 
        V_intrpt_ok();
67
 
        if (!V_call())
68
 
            exit(1);
69
 
 
70
 
        ok = 1;
71
 
        sprintf(buf2, "Gmapcalc %s = 'if(%s, %s %s , %d)'", elev_data,
72
 
                elev_layer, elev_layer, buf1, no_data_value);
73
 
 
74
 
        fprintf(stderr,
75
 
                "\n\n The following G_mapcalc syntax will be used \n for the modified elevation data\n\n");
76
 
        fprintf(stderr, "%s = 'if(%s, %s %s , %d)'", elev_data, elev_layer,
77
 
                elev_layer, buf1, no_data_value);
78
 
        ok = G_yes("\nDo you accept this G_mapcalc convention \n", ok);
79
 
        if (ok) {
80
 
 
81
 
                 /** Set LOCATION to target location **/
82
 
            G_setenv("LOCATION_NAME", tl);
83
 
 
84
 
                 /** system GMAPCALC **/
85
 
            G_system(buf2);
86
 
            /* elev_data becomes the new elevation layer */
87
 
            strcpy(elev_layer, elev_data);
88
 
            /* need mapset if changed */
89
 
            if ((mapset_elev = G_find_cell(elev_layer, "")) == NULL)
90
 
                exit(0);
91
 
            select_current_env();
92
 
 
93
 
                 /** reset LOCATION to current location **/
94
 
            G_setenv("LOCATION_NAME", G_location());
95
 
 
96
 
        }
97
 
    }
98
 
    return (0);
99
 
}