GRASS Programmer's Manual 6.4.1(2011)
make_colr.c
Go to the documentation of this file.
00001 
00002 /**********************************************************************
00003  *
00004  *   G_make_color (name, mapset, colors)
00005  *       char *name               name of map
00006  *       char *mapset             mapset containing name
00007  *       struct Colors *colors    struct to hold colors
00008  *
00009  *   Interactively prompts user for deciding which type of color
00010  *   lookup table is desired.
00011  *       Red, green, and blue color ramps
00012  *       Gray scale
00013  *       Rainbow colors
00014  *       Random colors
00015  *       Color wave
00016  *       Aspect colors
00017  *       Red through yellow to green
00018  *
00019  *   Returns -1 user canceled the request
00020  *            1 color table is ok
00021  **********************************************************************/
00022 
00023 #include <grass/gis.h>
00024 #include <grass/glocale.h>
00025 
00026 int G_ask_colors(const char *name, const char *mapset, struct Colors *pcolr)
00027 {
00028     char buff[128];
00029     int answ;
00030     struct FPRange range;
00031     DCELL min, max;
00032 
00033     G_init_colors(pcolr);
00034 
00035     /* determine range cell values */
00036     if (G_read_fp_range(name, mapset, &range) < 0)
00037         return -1;
00038     G_get_fp_range_min_max(&range, &min, &max);
00039     if (G_is_d_null_value(&min) || G_is_d_null_value(&max)) {
00040         sprintf(buff, _(" The raster map %s@%s is empty"), name, mapset);
00041         G_warning(buff);
00042         return -1;
00043     }
00044 
00045     /* Prompting */
00046   ASK:
00047     G_clear_screen();
00048     fprintf(stderr,
00049             _("\n\nColor table needed for file [%s] in mapset [%s].\n"), name,
00050             mapset);
00051 
00052     fprintf(stderr, _("\nPlease identify the type desired:\n"));
00053     fprintf(stderr, _("    1:  Random colors\n"));
00054     fprintf(stderr, _("    2:  Red, green, and blue color ramps\n"));
00055     fprintf(stderr, _("    3:  Color wave\n"));
00056     fprintf(stderr, _("    4:  Gray scale\n"));
00057     fprintf(stderr, _("    5:  Aspect\n"));
00058     fprintf(stderr, _("    6:  Rainbow colors\n"));
00059     fprintf(stderr, _("    7:  Red through yellow to green\n"));
00060     fprintf(stderr, _("    8:  Green through yellow to red\n"));
00061     fprintf(stderr, _("RETURN  quit\n"));
00062     fprintf(stderr, "\n> ");
00063 
00064     for (;;) {
00065         if (!G_gets(buff))
00066             goto ASK;
00067         G_strip(buff);
00068         if (*buff == 0)
00069             return -1;
00070         if (sscanf(buff, "%d", &answ) != 1)
00071             answ = -1;
00072 
00073         switch (answ) {
00074         case 1:
00075             return G_make_random_colors(pcolr, (CELL) min, (CELL) max);
00076         case 2:
00077             return G_make_ramp_fp_colors(pcolr, min, max);
00078         case 3:
00079             return G_make_wave_fp_colors(pcolr, min, max);
00080         case 4:
00081             return G_make_grey_scale_fp_colors(pcolr, min, max);
00082         case 5:
00083             return G_make_aspect_fp_colors(pcolr, min, max);
00084         case 6:
00085             return G_make_rainbow_fp_colors(pcolr, min, max);
00086         case 7:
00087             return G_make_ryg_fp_colors(pcolr, min, max);
00088         case 8:
00089             return G_make_gyr_fp_colors(pcolr, min, max);
00090         default:
00091             fprintf(stderr, _("\n%s invalid; Try again > "), buff);
00092             break;
00093         }
00094     }
00095 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines