~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.histogram/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <stdlib.h>
35
35
#include <string.h>
36
36
#include <grass/gis.h>
 
37
#include <grass/raster.h>
37
38
#include <grass/display.h>
38
 
#include <grass/raster.h>
39
39
#include <grass/glocale.h>
40
 
#define MAIN
 
40
 
41
41
#include "options.h"
42
42
#include "dhist.h"
43
43
 
 
44
struct stat_list dist_stats;
 
45
struct Categories cats;
 
46
struct FPRange fp_range;
 
47
int is_fp;
 
48
 
 
49
char *map_name;
 
50
int color;
 
51
float size;
 
52
int style;
 
53
int type;
 
54
int is_fp;
 
55
int nodata;
 
56
int nsteps;
 
57
int cat_ranges;
 
58
 
44
59
int main(int argc, char **argv)
45
60
{
46
61
    int text_height;
47
62
    int text_width;
48
 
    char *mapset;
49
63
    struct Categories cats;
50
64
    struct Range range;
51
65
    struct Colors pcolors;
52
 
    int bgcolor;
53
 
    char title[512];
54
 
    int tt, tb, tl, tr;
55
 
    int t, b, l, r;
56
 
    int quiet;
 
66
    char title[GNAME_MAX];
 
67
    double tt, tb, tl, tr;
 
68
    double t, b, l, r;
57
69
    struct GModule *module;
58
70
    struct Option *opt1;
59
71
    struct Option *opt2, *bg_opt;
68
80
    G_gisinit(argv[0]);
69
81
 
70
82
    module = G_define_module();
71
 
    module->keywords = _("display, histogram, statistics");
 
83
    G_add_keyword(_("display"));
 
84
    G_add_keyword(_("histogram"));
 
85
    G_add_keyword(_("statistics"));
72
86
    module->description =
73
87
        _("Displays a histogram in the form of a pie or bar chart "
74
88
          "for a user-specified raster map.");
86
100
 
87
101
    /* The color option specifies the color for the labels, tic-marks,
88
102
     * and borders of the chart. */
89
 
    opt2 = G_define_standard_option(G_OPT_C_FG);
 
103
    opt2 = G_define_standard_option(G_OPT_C);
90
104
    opt2->label = _("Color for text and axes");
91
105
 
92
 
    bg_opt = G_define_standard_option(G_OPT_C_BG);
 
106
    bg_opt = G_define_standard_option(G_OPT_CN);
 
107
    bg_opt->key = "bgcolor";
 
108
    bg_opt->label = _("Background color");
 
109
    bg_opt->answer = DEFAULT_BG_COLOR;
93
110
 
94
111
#ifdef CAN_DO_AREAS
95
112
    opt3 = G_define_option();
114
131
    flag1->key = 'n';
115
132
    flag1->description = _("Display information for null cells");
116
133
 
117
 
    flag2 = G_define_flag();
118
 
    flag2->key = 'q';
119
 
    flag2->description = _("Gather the histogram quietly");
120
 
 
121
134
    flag3 = G_define_flag();
122
 
    flag3->key = 'C';
 
135
    flag3->key = 'c';
123
136
    flag3->description =
124
137
        _("Report for ranges defined in cats file (fp maps only)");
125
138
 
130
143
    map_name = opt1->answer;
131
144
 
132
145
    color = D_parse_color(opt2->answer, FALSE);
133
 
    bgcolor = D_parse_color(bg_opt->answer, TRUE);
134
146
 
135
147
    type = COUNT;
136
148
#ifdef CAN_DO_AREAS
154
166
        G_warning(_("When -C flag is set, the nsteps argument is ignored"));
155
167
 
156
168
    nodata = flag1->answer;
157
 
    quiet = flag2->answer ? YES : NO;
158
 
 
159
 
    /* Make sure map is available */
160
 
    mapset = G_find_cell2(map_name, "");
161
 
    if (mapset == NULL)
162
 
        G_fatal_error(_("Raster map <%s> not found"), map_name);
163
 
 
164
 
    if (G_read_colors(map_name, mapset, &pcolors) == -1)
 
169
 
 
170
    if (Rast_read_colors(map_name, "", &pcolors) == -1)
165
171
        G_fatal_error(_("Color file for <%s> not available"), map_name);
166
172
 
167
 
    if (G_read_cats(map_name, mapset, &cats) == -1)
 
173
    if (Rast_read_cats(map_name, "", &cats) == -1)
168
174
        G_fatal_error(_("Category file for <%s> not available"), map_name);
169
175
 
170
 
    if (G_read_range(map_name, mapset, &range) == -1)
 
176
    if (Rast_read_range(map_name, "", &range) == -1)
171
177
        G_fatal_error(_("Range information for <%s> not available"),
172
178
                      map_name);
173
179
 
174
180
    /* get the distribution statistics */
175
181
 
176
 
    get_stats(map_name, mapset, &dist_stats, quiet);
 
182
    get_stats(map_name, &dist_stats);
177
183
 
178
184
    /* set up the graphics driver and initialize its color-table */
179
185
 
180
 
    if (R_open_driver() != 0)
181
 
        G_fatal_error(_("No graphics device selected"));
182
 
 
183
 
    D_setup(0);                 /* 0 = don't clear frame */
184
 
    D_get_screen_window(&t, &b, &l, &r);
 
186
    D_open_driver();
 
187
    
 
188
    D_setup_unity(0);                   /* 0 = don't clear frame */
 
189
    D_get_src(&t, &b, &l, &r);
185
190
 
186
191
    /* clear the frame, if requested to do so */
187
 
    if (strcmp(bg_opt->answer, "none")) {
188
 
        /*          D_clear_window(); *//* clears d.save history: but also any font setting! */
189
 
        D_raster_use_color(bgcolor);
190
 
        R_box_abs(l, t, r, b);
191
 
    }
 
192
    if (strcmp(bg_opt->answer, "none") != 0)
 
193
        D_erase(bg_opt->answer);
192
194
 
193
195
    /* draw a title for */
194
 
    sprintf(title, "%s in mapset %s", map_name, mapset);
 
196
    sprintf(title, "%s", map_name);
195
197
    text_height = (b - t) * 0.05;
196
198
    text_width = (r - l) * 0.05 * 0.50;
197
 
    R_text_size(text_width, text_height);
198
 
    R_get_text_box(title, &tt, &tb, &tl, &tr);
199
 
    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
200
 
               (int)(t + (b - t) * 0.07));
201
 
    D_raster_use_color(color);
202
 
    R_text(title);
 
199
    D_text_size(text_width, text_height);
 
200
    D_get_text_box(title, &tt, &tb, &tl, &tr);
 
201
    D_pos_abs(l + (r - l) / 2 - (tr - tl) / 2,
 
202
              t + (b - t) * 0.07);
 
203
    D_use_color(color);
 
204
    D_text(title);
203
205
 
204
206
    /* plot the distributrion statistics */
205
207
    if (style == PIE)
207
209
    else
208
210
        bar(&dist_stats, &pcolors);
209
211
 
210
 
    R_flush();
211
 
    D_add_to_list(G_recreate_command());
212
 
    R_close_driver();
 
212
    D_save_command(G_recreate_command());
 
213
    D_close_driver();
213
214
 
214
215
    exit(EXIT_SUCCESS);
215
216
}