GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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  sprintf(buff, _(" The raster map %s@%s is empty"), name, mapset);
41  G_warning(buff);
42  return -1;
43  }
44 
45  /* Prompting */
46  ASK:
48  fprintf(stderr,
49  _("\n\nColor table needed for file [%s] in mapset [%s].\n"), name,
50  mapset);
51 
52  fprintf(stderr, _("\nPlease identify the type desired:\n"));
53  fprintf(stderr, _(" 1: Random colors\n"));
54  fprintf(stderr, _(" 2: Red, green, and blue color ramps\n"));
55  fprintf(stderr, _(" 3: Color wave\n"));
56  fprintf(stderr, _(" 4: Gray scale\n"));
57  fprintf(stderr, _(" 5: Aspect\n"));
58  fprintf(stderr, _(" 6: Rainbow colors\n"));
59  fprintf(stderr, _(" 7: Red through yellow to green\n"));
60  fprintf(stderr, _(" 8: Green through yellow to red\n"));
61  fprintf(stderr, _("RETURN quit\n"));
62  fprintf(stderr, "\n> ");
63 
64  for (;;) {
65  if (!G_gets(buff))
66  goto ASK;
67  G_strip(buff);
68  if (*buff == 0)
69  return -1;
70  if (sscanf(buff, "%d", &answ) != 1)
71  answ = -1;
72 
73  switch (answ) {
74  case 1:
75  return G_make_random_colors(pcolr, (CELL) min, (CELL) max);
76  case 2:
77  return G_make_ramp_fp_colors(pcolr, min, max);
78  case 3:
79  return G_make_wave_fp_colors(pcolr, min, max);
80  case 4:
81  return G_make_grey_scale_fp_colors(pcolr, min, max);
82  case 5:
83  return G_make_aspect_fp_colors(pcolr, min, max);
84  case 6:
85  return G_make_rainbow_fp_colors(pcolr, min, max);
86  case 7:
87  return G_make_ryg_fp_colors(pcolr, min, max);
88  case 8:
89  return G_make_gyr_fp_colors(pcolr, min, max);
90  default:
91  fprintf(stderr, _("\n%s invalid; Try again > "), buff);
92  break;
93  }
94  }
95 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
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:1305
#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:450
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