GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
make_colr.c
Go to the documentation of this file.
1 
2 /**********************************************************************
3  *
4  * G_make_color (name, mapset, colors)
5  * char *name name of map
6  * char *mapset mapset containing name
7  * struct Colors *colors struct to hold colors
8  *
9  * Interactively prompts user for deciding which type of color
10  * lookup table is desired.
11  * Red, green, and blue color ramps
12  * Gray scale
13  * Rainbow colors
14  * Random colors
15  * Color wave
16  * Aspect colors
17  * Red through yellow to green
18  *
19  * Returns -1 user canceled the request
20  * 1 color table is ok
21  **********************************************************************/
22 
23 #include <grass/gis.h>
24 #include <grass/glocale.h>
25 
26 int G_ask_colors(const char *name, const char *mapset, struct Colors *pcolr)
27 {
28  char buff[128];
29  int answ;
30  struct FPRange range;
31  DCELL min, max;
32 
33  G_init_colors(pcolr);
34 
35  /* determine range cell values */
36  if (G_read_fp_range(name, mapset, &range) < 0)
37  return -1;
38  G_get_fp_range_min_max(&range, &min, &max);
39  if (G_is_d_null_value(&min) || G_is_d_null_value(&max)) {
40  G_warning(_("The raster map <%s@%s> is empty"), name, mapset);
41  return -1;
42  }
43 
44  /* Prompting */
45  ASK:
47  fprintf(stderr,
48  _("\n\nColor table needed for file [%s] in mapset [%s].\n"), name,
49  mapset);
50 
51  fprintf(stderr, _("\nPlease identify the type desired:\n"));
52  fprintf(stderr, _(" 1: Random colors\n"));
53  fprintf(stderr, _(" 2: Red, green, and blue color ramps\n"));
54  fprintf(stderr, _(" 3: Color wave\n"));
55  fprintf(stderr, _(" 4: Gray scale\n"));
56  fprintf(stderr, _(" 5: Aspect\n"));
57  fprintf(stderr, _(" 6: Rainbow colors\n"));
58  fprintf(stderr, _(" 7: Red through yellow to green\n"));
59  fprintf(stderr, _(" 8: Green through yellow to red\n"));
60  fprintf(stderr, _("RETURN quit\n"));
61  fprintf(stderr, "\n> ");
62 
63  for (;;) {
64  if (!G_gets(buff))
65  goto ASK;
66  G_strip(buff);
67  if (*buff == 0)
68  return -1;
69  if (sscanf(buff, "%d", &answ) != 1)
70  answ = -1;
71 
72  switch (answ) {
73  case 1:
74  return G_make_random_colors(pcolr, (CELL) min, (CELL) max);
75  case 2:
76  return G_make_ramp_fp_colors(pcolr, min, max);
77  case 3:
78  return G_make_wave_fp_colors(pcolr, min, max);
79  case 4:
80  return G_make_grey_scale_fp_colors(pcolr, min, max);
81  case 5:
82  return G_make_aspect_fp_colors(pcolr, min, max);
83  case 6:
84  return G_make_rainbow_fp_colors(pcolr, min, max);
85  case 7:
86  return G_make_ryg_fp_colors(pcolr, min, max);
87  case 8:
88  return G_make_gyr_fp_colors(pcolr, min, max);
89  default:
90  fprintf(stderr, _("\n%s invalid; Try again > "), buff);
91  break;
92  }
93  }
94 }
int G_ask_colors(const char *name, const char *mapset, struct Colors *pcolr)
Definition: make_colr.c:26
int G_make_ramp_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:77
int G_gets(char *buf)
Definition: gets.c:39
string name
Definition: render.py:1314
#define min(x, y)
Definition: draw2.c:68
#define max(x, y)
Definition: draw2.c:69
int G_make_wave_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:43
char buff[1024]
Definition: g3dcats.c:89
int G_make_gyr_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:113
int G_clear_screen(void)
Definition: clear_scrn.c:12
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
Definition: null_val.c:306
int G_strip(char *buf)
Removes all leading and trailing white space from string.
Definition: strings.c:389
int G_make_rainbow_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:102
int G_make_ryg_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:54
int G_make_random_colors(struct Colors *colors, CELL min, CELL max)
make random colors
Definition: color_rand.c:22
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
Definition: range.c:667
int G_make_grey_scale_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:135
int G_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
Definition: range.c:139
G_init_colors(colors)
int G_make_aspect_fp_colors(struct Colors *colors, DCELL min, DCELL max)
Definition: color_compat.c:186