int GRASS_LIB_EXPORT G_read_raster_cats( const char *name, const char *mapset, struct Categories *pcats ) { Q_UNUSED( name ); Q_UNUSED( mapset ); G_init_raster_cats( "Cats", pcats ); return 0; }
int E_edit_fp_cats(const char *name, struct Categories *cats) { long incr; long atnum; long startcat; long endcat; char buff[NLINES][60]; char next[20]; char next_line[80]; char title[80]; char msg1[80]; char msg2[80]; int line, ncats; size_t lab_len; DCELL max_val[NLINES], min_val[NLINES]; DCELL dmin, dmax; CELL tmp_cell; struct Categories old_cats; struct FPRange fp_range; if (G_read_fp_range(name, G_mapset(), &fp_range) < 0) G_fatal_error("can't read the floating point range for %s", name); G_get_fp_range_min_max(&fp_range, &dmin, &dmax); /* first save old cats */ G_copy_raster_cats(&old_cats, cats); G_init_raster_cats(old_cats.title, cats); G_free_raster_cats(cats); ncats = old_cats.ncats; V_clear(); if (!ncats) sprintf(msg1, "There are no predefined fp ranges to label"); else sprintf(msg1, "There are %d predefined fp ranges to label", ncats); sprintf(msg2, "Enter the number of fp ranges you want to label"); V_line(1, msg1); V_line(2, msg2); V_ques(&ncats, 'l', 2, 48, 5); V_line(16, next_line); *next_line = 0; V_intrpt_ok(); if (!V_call()) return -1; *title = 0; if (old_cats.title != NULL) strcpy(title, old_cats.title); startcat = 0; sprintf(msg1, "The fp data in map %s ranges from %f to %f", name, dmin, dmax); sprintf(msg2, "[%s] ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES", name); while (1) { V_clear(); V_line(0, msg1); V_line(1, msg2); V_line(3, "TITLE: "); V_line(4, "FP RANGE NEW CATEGORY NAME"); V_ques(title, 's', 2, 8, 60); endcat = startcat + NLINES <= ncats ? startcat + NLINES : ncats; line = 6; for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; if (incr < old_cats.ncats) { /* if editing existing range label */ lab_len = strlen(old_cats.labels[incr]); if (lab_len > 58) lab_len = 58; strncpy(buff[atnum], old_cats.labels[incr], lab_len); buff[atnum][lab_len] = 0; G_quant_get_ith_rule(&old_cats.q, incr, &min_val[atnum], &max_val[atnum], &tmp_cell, &tmp_cell); } else { /* adding new range label */ strcpy(buff[atnum], ""); max_val[atnum] = min_val[atnum] = 0; } V_ques(&min_val[atnum], 'd', line, 1, 8); V_const("-", 's', line, 9, 1); V_ques(&max_val[atnum], 'd', line, 10, 8); V_ques(buff[atnum], 's', line, 19, 58); line++; } line += 2; *next = 0; if (endcat >= ncats) strcpy(next, "end"); else sprintf(next, "%ld", endcat); sprintf(next_line, "%*s%*s (of %d)", 41, "Next range number ('end' to end): ", 5, "", ncats); V_line(line, next_line); V_ques(next, 's', line, 41, 5); V_intrpt_ok(); if (!V_call()) return -1; /* store new category name in structure */ for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; G_strip(buff[atnum]); /* adding new range label */ if (!(strcmp(buff[atnum], "") == 0 && min_val[atnum] == 0. && max_val[atnum] == 0.)) G_set_d_raster_cat(&min_val[atnum], &max_val[atnum], buff[atnum], cats); } if (*next == 0) break; if (strcmp(next, "end") == 0) break; if (sscanf(next, "%ld", &endcat) != 1) continue; if (endcat < 0) endcat = 0; if (endcat > ncats) { endcat = ncats - NLINES + 1; if (endcat < 0) endcat = 0; } startcat = endcat; } G_strip(title); cats->title = G_store(title); /* since label pointers in old_cats point to the old allocated strings, and cats now has all the newly allocated strings, it never reuses old ones, we need to free them */ return (1); }