GRASS Programmer's Manual  6.4.2(2012)
 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  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 }