/* return NULL on error: otherwise returns dspout */ char *check_get_any_dspname(char *dspf, char *g3f, char *mset) { char element[200], question[200]; static char dspout[200]; if (!G_legal_filename(dspf)) return (NULL); if (!G_find_grid3(g3f, "")) G_fatal_error("[%s] 3D raster map not found", g3f); if (mset) { /* otherwise must be reading only */ if (g3_find_dsp_file(g3f, dspf, mset)) { /* already exists */ sprintf(question, "\n** %s exists. ok to overwrite? ", dspf); if (!G_yes(question, 0)) { if (NULL == G_ask_any("", dspout, element, "display", 1)) return (NULL); return (dspout); } /* or else just print a warning & use it as is */ } } strcpy(dspout, dspf); return (dspout); }
int digitize(FILE * fd) { int any; struct Categories labels; G_init_cats((CELL) 0, "", &labels); any = 0; for (;;) { switch (get_type()) { case 'A': /* area */ if (get_area(fd, &labels)) any = 1; break; case 'C': /* circle */ if (get_circle(fd, &labels)) any = 1; break; case 'L': /* line */ if (get_line(fd, &labels)) any = 1; break; case 'X': /* done */ return any; case 'Q': /* exit without saving */ if (G_yes(_("Quit without creating a map?? "), 0)) return 0; } } }
int get_category(FILE * fd, char *type, struct Categories *labels) { long cat; char *lbl; R_stabilize(); /* force out all graphics */ do { fprintf(stdout, "\n"); cat = get_cat(type); lbl = get_label(cat, labels); fprintf(stdout, "%ld [%s]\n", cat, *lbl ? lbl : G_get_cat((CELL) cat, labels)); } while (!G_yes(_("Look ok? "), 1)); if (*lbl) G_set_cat((CELL) cat, lbl, labels); fprintf(fd, "= %ld %s\n", cat, lbl); return (0); }
/* DEFINE SAMPLING UNITS MANUALLY */ static void man_unit(int t, int b, int l, int r, char *n1, char *n2, char *n3, double *mx, int fmask) { int i, j, dx, dy, w_w, w_l, u_w, u_l, method, l0, t0, randflag = 0, unit_num, num = 0, scales, h_d = 1, v_d = 1, itmp, thick, sites, *row_buf, fr, k, count = 0, maxsize = 0, nx = 0, ny = 0, numx = 0, numy = 0, al = 0, ar = 0, at = 0, ab = 0, au_w = 0, au_l = 0; double *ux, *uy; FILE *fp; double dtmp, ratio, size, intv = 0.0, start[2], cnt = 0, radius = 0.0; char *sites_mapset; struct Cell_head wind; /* VARIABLES: COORDINATES IN THIS ROUTINE ARE IN CELLS t = top row of sampling frame b = bottom row of sampling frame l = left col of sampling frame r = right col of sampling frame n1 = n2 = n3 = start[0]= row of UL corner of starting pt for strata start[1]= col of UL corner of starting pt for strata mx[0] = cols of region/width of screen mx[1] = rows of region/height of screen */ start[0] = 0.0; start[1] = 0.0; l = (int)((double)(l * mx[0]) + 0.5); r = (int)((double)(r * mx[0]) + 0.5); t = (int)((double)(t * mx[1]) + 0.5); b = (int)((double)(b * mx[1]) + 0.5); w_w = r - l; w_l = b - t; /* draw the sampling frame */ R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box((int)(l / mx[0] + 0.5), (int)(t / mx[1] + 0.5), (int)(r / mx[0] + 0.5), (int)(b / mx[1] + 0.5), 1); R_close_driver(); /* open the units file for output */ fp = fopen0("r.le.para/units", "w"); G_sleep_on_error(0); /* get the number of scales */ do { fprintf(stderr, "\n How many different SCALES do you want (1-15)? "); numtrap(1, &dtmp); if (dtmp > 15 || dtmp < 1) { fprintf(stderr, "\n Too many (>15) or too few scales; try again"); } } while (dtmp < 1 || dtmp > 15); fprintf(fp, "%10d # of scales\n", (scales = (int)dtmp)); /* for each scale */ for (i = 0; i < scales; i++) { for (;;) { G_system("clear"); radius = 0.0; fprintf(stderr, "\n\n TYPE IN PARAMETERS FOR SCALE %d:\n", i + 1); /* get the distribution method */ fprintf(stderr, "\n Choose method of sampling unit DISTRIBUTION \n"); fprintf(stderr, " Random nonoverlapping 1\n"); fprintf(stderr, " Systematic contiguous 2\n"); fprintf(stderr, " Systematic noncontiguous 3\n"); fprintf(stderr, " Stratified random 4\n"); fprintf(stderr, " Centered over sites 5\n"); fprintf(stderr, " Exit to setup option menu 6\n\n"); do { fprintf(stderr, " Which Number? "); numtrap(1, &dtmp); if ((method = fabs(dtmp)) > 6 || method < 1) { fprintf(stderr, "\n Choice must between 1-5; try again"); } } while (method > 6 || method < 1); if (method == 6) return; /* for stratified random distribution, determine the number of strata */ if (method == 4) { getstrata: fprintf(stderr, "\n Number of strata along the x-axis? (1-60) "); numtrap(1, &dtmp); h_d = fabs(dtmp); fprintf(stderr, "\n Number of strata along the y-axis? (1-60) "); numtrap(1, &dtmp); v_d = fabs(dtmp); if (h_d < 1 || v_d < 1 || h_d > 60 || v_d > 60) { fprintf(stderr, "\n Number must be between 1-60; try again."); goto getstrata; } } /* for methods with strata */ if (method == 2 || method == 3 || method == 4) { strata: fprintf(stderr, "\n Sampling frame row & col for upper left corner of"); fprintf(stderr, " the strata?\n Rows are numbered down and columns"); fprintf(stderr, " are numbered to the right\n Enter 1 1 to start in"); fprintf(stderr, " upper left corner of sampling frame: "); numtrap(2, start); start[0] = start[0] - 1.0; start[1] = start[1] - 1.0; if (start[0] > w_l || start[0] < 0 || start[1] > w_w || start[1] < 0) { fprintf(stderr, "\n The starting row and col you entered are outside"); fprintf(stderr, " the sampling frame\n Try again\n"); goto strata; } } if (method == 4) { /* call draw_grid with the left, top, width, length, the number of horizontal and vertical strata, and the starting row and col for the strata */ draw_grid((int)(l / mx[0] + 0.5), (int)(t / mx[1] + 0.5), (int)(w_w / mx[0] + 0.5), (int)(w_l / mx[1] + 0.5), h_d, v_d, (int)(start[0] / mx[1] + 0.5), (int)(start[1] / mx[0] + 0.5), mx[0], mx[1]); if (!G_yes(" Are these strata OK? ", 1)) { if (G_yes("\n\n Refresh the screen? ", 1)) { paint_map(n1, n2, n3); R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box((int)(l / mx[0] + 0.5), (int)(t / mx[1] + 0.5), (int)(r / mx[0] + 0.5), (int)(b / mx[1] + 0.5), 1); R_close_driver(); } goto getstrata; } } /* if sampling using circles */ fprintf(stderr, "\n Do you want to sample using rectangles"); if (!G_yes ("\n (including squares) (y) or circles (n)? ", 1)) { getradius: fprintf(stderr, "\n What radius do you want for the circles? Radius"); fprintf(stderr, "\n is in pixels; add 0.5 pixels, for the center"); fprintf(stderr, "\n pixel, to the number of pixels outside the"); fprintf(stderr, "\n center pixel. Type a real number with one"); fprintf(stderr, "\n decimal place ending in .5 (e.g., 4.5): "); numtrap(1, &radius); if (radius > 100.0) { fprintf(stderr, "\n Are you sure that you want such a large"); if (!G_yes("\n radius (> 100 pixels)? ", 1)) goto getradius; } ratio = 1.0; u_w = (int)(2 * radius); u_l = (int)(2 * radius); if (fmask > 0) { count = 0; row_buf = Rast_allocate_buf(CELL_TYPE); fr = Rast_open_old(n1, G_mapset()); for (j = t; j < b; j++) { Rast_zero_buf(row_buf, CELL_TYPE); Rast_get_row(fr, row_buf, j, CELL_TYPE); for (k = l; k < r; k++) { if (*(row_buf + k)) count++; } } G_free(row_buf); Rast_close(fr); cnt = (double)(count); if (cnt) cnt = sqrt(cnt); else cnt = 0; } else { count = (w_l - (int)(start[0])) * (w_w - (int)(start[1])); } } /* if sampling using rectangles/squares */ else { /* get the width/length ratio */ getratio: fprintf(stderr, "\n Sampling unit SHAPE (aspect ratio, #cols/#rows) " "expressed as real number" "\n (e.g., 10 cols/5 rows = 2.0) for sampling units " "of scale %d? ", i + 1); numtrap(1, &ratio); if (ratio < 0) ratio = -ratio; else if (ratio > 25.0) if (!G_yes ("\n Are you sure you want such a large ratio? ", 1)) goto getratio; /* determine the recommended maximum size for sampling units */ getsize: dtmp = (ratio > 1) ? 1 / ratio : ratio; dtmp /= (h_d > v_d) ? h_d * h_d : v_d * v_d; tryagain: if (method == 1) { if (fmask > 0) { count = 0; row_buf = Rast_allocate_buf(CELL_TYPE); fr = Rast_open_old(n1, G_mapset()); for (j = t; j < b; j++) { Rast_zero_buf(row_buf, CELL_TYPE); Rast_get_row(fr, row_buf, j, CELL_TYPE); for (k = l; k < r; k++) { if (*(row_buf + k)) count++; } } G_free(row_buf); Rast_close(fr); cnt = (double)(count); if (cnt) cnt = sqrt(cnt); else cnt = 0; maxsize = ((cnt * dtmp / 2) * (cnt * dtmp / 2) > 1.0 / dtmp) ? (cnt * dtmp / 2) * (cnt * dtmp / 2) : 1.0 / dtmp; fprintf(stderr, "\n Recommended maximum SIZE is %d in %d cell total", maxsize, count); fprintf(stderr, " area\n"); } else { fprintf(stderr, "\n Recommended maximum SIZE is"); fprintf(stderr, " %d in %d pixel total area\n", (int)((w_l - (int)(start[0])) * (w_w - (int)(start [1])) * dtmp / 2), (w_l - (int)(start[0])) * (w_w - (int)(start[1]))); count = (w_l - (int)(start[0])) * (w_w - (int)(start[1])); maxsize = (int)((w_l - (int)(start[0])) * (w_w - (int)(start[1])) * dtmp / 2); } } else if (method == 2 || method == 3 || method == 5) { fprintf(stderr, "\n Recommended maximum SIZE is %d in %d pixel total", (int)((w_l - (int)(start[0])) * (w_w - (int)(start[1])) * dtmp / 2), (w_l - (int)(start[0])) * (w_w - (int)(start[1]))); fprintf(stderr, " area\n"); } else if (method == 4) { fprintf(stderr, "\n Recommended maximum SIZE is"); fprintf(stderr, " %d in %d pixel individual", (int)(w_w * w_l * dtmp / 2), ((w_w - (int)(start[1])) / h_d) * ((w_l - (int)(start [0])) / v_d)); fprintf(stderr, " stratum area\n"); } /* get the unit size, display the calculated size, and ask if it is OK */ fprintf(stderr, " What size (in pixels) for each sampling unit of scale %d? ", i + 1); numtrap(1, &size); thick = 1; if (size < 15 || ratio < 0.2 || ratio > 5) thick = 0; u_w = sqrt(size * ratio); u_l = sqrt(size / ratio); fprintf(stderr, "\n The nearest size is %d cells wide X %d cells high = %d", u_w, u_l, u_w * u_l); fprintf(stderr, " cells\n"); if (!u_w || !u_l) { fprintf(stderr, "\n 0 cells wide or high is not acceptable; try again"); goto tryagain; } if (!G_yes(" Is this SIZE OK? ", 1)) goto getsize; } /* for syst. noncontig. distribution, get the interval between units */ if (method == 3) { fprintf(stderr, "\n The interval, in pixels, between the units of scale"); fprintf(stderr, " %d? ", i + 1); numtrap(1, &intv); } /* if the unit dimension + the interval is too large, print a warning and try getting another size */ if (u_w + intv > w_w / h_d || u_l + intv > w_l / v_d) { fprintf(stderr, "\n Unit size too large for sampling frame; try again\n"); if (radius) goto getradius; else goto getsize; } /* for stratified random distribution, the number of units is the same as the number of strata */ if (method == 4) num = h_d * v_d; /* for the other distributions, calculate the maximum number of units, then get the number of units */ else if (method == 1 || method == 2 || method == 3) { if (method == 1) { if (! (unit_num = calc_num(w_w, w_l, ratio, u_w, u_l, method, intv, (int)(start[1]), (int)(start[0]), u_w * u_l, count))) { fprintf(stderr, "\n Something wrong with sampling unit size, try again\n"); if (radius) goto getradius; else goto getsize; } fprintf(stderr, "\n Maximum NUMBER of units in scale %d is %d\n", i + 1, unit_num); fprintf(stderr, " Usually 1/2 of this number can be successfully"); fprintf(stderr, " distributed\n More than 1/2 can sometimes be"); fprintf(stderr, " distributed\n"); } else if (method == 2 || method == 3) { numx = floor((double)(w_w - start[1]) / (u_w + intv)); numy = floor((double)(w_l - start[0]) / (u_l + intv)); if (((w_w - (int)(start[1])) % (numx * (u_w + (int)(intv)))) >= u_w) numx++; if (((w_l - (int)(start[0])) % (numy * (u_l + (int)(intv)))) >= u_l) numy++; unit_num = numx * numy; fprintf(stderr, "\n Maximum NUMBER of units in scale %d is %d as %d", i + 1, unit_num, numy); fprintf(stderr, " rows with %d units per row", numx); } do { fprintf(stderr, "\n What NUMBER of sampling units do you want to try"); fprintf(stderr, " to use? "); numtrap(1, &dtmp); if ((num = dtmp) > unit_num || num < 1) { fprintf(stderr, "\n %d is greater than the maximum number of", num); fprintf(stderr, " sampling units; try again\n"); } else if (method == 2 || method == 3) { fprintf(stderr, "\n How many sampling units do you want per row? "); numtrap(1, &dtmp); if ((nx = dtmp) > num) { fprintf(stderr, "\n Number in each row > number requested; try"); fprintf(stderr, " again\n"); } else { if (nx > numx) { fprintf(stderr, "\n Can't fit %d units in each row, try", nx); fprintf(stderr, " again\n"); } else { if (num % nx) ny = num / nx + 1; else ny = num / nx; if (ny > numy) { fprintf(stderr, "\n Can't fit the needed %d rows, try", ny); fprintf(stderr, " again\n"); } } } } } while (num > unit_num || num < 1 || nx > num || nx > numx || ny > numy); } /* dynamically allocate storage for arrays to store the upper left corner of sampling units */ if (method != 5) { ux = G_calloc(num + 1, sizeof(double)); uy = G_calloc(num + 1, sizeof(double)); } else { ux = G_calloc(250, sizeof(double)); uy = G_calloc(250, sizeof(double)); } /* calculate the upper left corner of sampling units and store them in arrays ux and uy */ if (!calc_unit_loc (radius, t, b, l, r, ratio, u_w, u_l, method, intv, num, h_d, v_d, ux, uy, &sites, (int)(start[1]), (int)(start[0]), fmask, nx, mx[0], mx[1])) goto last; signal(SIGINT, SIG_DFL); if (method == 5) num = sites; /* draw the sampling units on the screen */ if (method == 2 || method == 3 || method == 5) { R_open_driver(); R_standard_color(D_translate_color("red")); for (j = 0; j < num; j++) { if (radius) { draw_circle((int)((double)(ux[j]) / mx[0]), (int)((double)(uy[j]) / mx[1]), (int)((double)(ux[j] + u_w) / mx[0]), (int)((double)(uy[j] + u_l) / mx[1]), 3); } else { draw_box((int)((double)(ux[j]) / mx[0]), (int)((double)(uy[j]) / mx[1]), (int)((double)(ux[j] + u_w) / mx[0]), (int)((double)(uy[j] + u_l) / mx[1]), 1); } } R_close_driver(); } if (G_yes("\n Is this set of sampling units OK? ", 1)) break; last: signal(SIGINT, SIG_DFL); if (G_yes("\n Refresh the screen? ", 1)) { paint_map(n1, n2, n3); R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]), (int)(b / mx[1]), 1); R_close_driver(); } } /* save the sampling unit parameters in r.le.para/units file */ fprintf(fp, "%10d # of units of scale %d.\n", num, (i + 1)); fprintf(fp, "%10d%10d u_w, u_l of units in scale %d\n", u_w, u_l, (i + 1)); fprintf(fp, "%10.1f radius of circles in scale %d\n", radius, (i + 1)); for (j = 0; j < num; j++) fprintf(fp, "%10d%10d left, top of unit[%d]\n", (int)ux[j], (int)uy[j], j + 1); if (i < scales - 1 && G_yes("\n\n Refresh the screen? ", 1)) { paint_map(n1, n2, n3); R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]), (int)(b / mx[1]), 1); R_close_driver(); } } /* free dynamically allocated memory */ G_free(ux); G_free(uy); fclose(fp); return; }
static void graph_unit(int t, int b, int l, int r, char *n1, char *n2, char *n3, double *mx, int fmask) { int x0 = 0, y0 = 0, xp, yp, ux[250], uy[250], u_w, u_l, btn = 0, k = 0, w_w = 0, w_l = 0, *row_buf, at, ab, al, ar, circle = 0, tmpw, tmpl, au_w, au_l, lap = 0, l0 = 0, r0 = 0, t0 = 0, b0 = 0; FILE *fp; double tmp, radius = 0.0; register int i, j; /* VARIABLES: COORDINATES IN THIS ROUTINE ARE IN CELLS t = top row of sampling frame b = bottom row of sampling frame l = left col of sampling frame r = right col of sampling frame n1 = n2 = n3 = mx[0] = cols of region/width of screen mx[1] = rows of region/height of screen xp = mouse x location in screen coordinates (col) yp = mouse y location in screen coordinates (row) ar = mouse x location in map coordinates (col) al = mouse y location in map coordinates (row) */ l0 = l; r0 = r; t0 = t; b0 = b; l = (int)((double)(l * mx[0]) + 0.5); r = (int)((double)(r * mx[0]) + 0.5); t = (int)((double)(t * mx[1]) + 0.5); b = (int)((double)(b * mx[1]) + 0.5); w_w = r - l; w_l = b - t; /* draw the sampling frame */ R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]), (int)(b / mx[1]), 1); R_close_driver(); fp = fopen0("r.le.para/units", "w"); G_sleep_on_error(0); /* get the number of scales */ do { fprintf(stderr, "\n How many different SCALES do you want? (1-15) "); numtrap(1, &tmp); if (tmp < 1 || tmp > 15) fprintf(stderr, " Too many (>15) or too few scales, try again.\n"); } while (tmp < 1 || tmp > 15); fprintf(fp, "%10d # of scales\n", (int)(tmp)); /* for each scale */ for (i = 0; i < tmp; i++) { G_system("clear"); radius = 0.0; circle = 0; /* if sampling using circles */ fprintf(stderr, "\n SCALE %d\n", i + 1); fprintf(stderr, "\n Do you want to sample using rectangles"); if (!G_yes("\n (including squares) (y) or circles (n)? ", 1)) { circle = 1; fprintf(stderr, "\n Draw a rectangular area to contain a standard circular"); fprintf(stderr, "\n sampling unit of scale %d. First select upper left", i + 1); fprintf(stderr, "\n corner, then lower right:\n"); fprintf(stderr, " Left button: Check unit size\n"); fprintf(stderr, " Middle button: Upper left corner of area here\n"); fprintf(stderr, " Right button: Lower right corner of area here\n"); } else { fprintf(stderr, "\n Draw a standard rectangular unit of scale %d.", i + 1); fprintf(stderr, "\n First select upper left corner, then lower right:\n"); fprintf(stderr, " Left button: Check unit size\n"); fprintf(stderr, " Middle button: Upper left corner of unit here\n"); fprintf(stderr, " Right button: Lower right corner of unit here\n"); } R_open_driver(); do { back1: R_get_location_with_box(x0, y0, &xp, &yp, &btn); /* convert the upper left screen coordinate (x0, y0) and the mouse position (xp, yp) on the screen to the nearest row and column; do the same for the sampling unit width (u_w) and height (u_l); then convert back */ ar = (int)((double)(xp) * mx[0] + 0.5); xp = (int)((double)(ar) / mx[0] + 0.5); al = (int)((double)(x0) * mx[0] + 0.5); x0 = (int)((double)(al) / mx[0] + 0.5); au_w = ar - al; u_w = (int)((double)(au_w) / mx[0] + 0.5); ab = (int)((double)(yp) * mx[1] + 0.5); yp = (int)((double)(ab) / mx[1] + 0.5); at = (int)((double)(y0) * mx[1] + 0.5); y0 = (int)((double)(at) / mx[1] + 0.5); au_l = ab - at; u_l = (int)((double)(au_l) / mx[1] + 0.5); /* left button, check the size of the rubber box in array system */ if (btn == 1) { if (ar > r || ab > b || ar < l || ab < t) { fprintf(stderr, "\n This point is not in the sampling frame; try again\n"); goto back1; } if (x0 < l || y0 < t) { fprintf(stderr, "\n Use the middle button to first put the upper left"); fprintf(stderr, "\n corner inside the sampling frame\n"); goto back1; } if (ar <= al || ab <= at) { fprintf(stderr, "\n Please put the lower right corner down and to"); fprintf(stderr, "\n the right of the upper left corner\n"); goto back1; } else { fprintf(stderr, "\n Unit would be %d columns wide by %d rows long\n", abs(au_w), abs(au_l)); fprintf(stderr, " Width/length would be %5.2f and size %d pixels\n", (double)abs((au_w)) / (double)abs((au_l)), abs(au_w) * abs(au_l)); } } /* mid button, move the start point of the rubber box */ else if (btn == 2) { if (ar > r || ab > b || ar < l || ab < t) { fprintf(stderr, "\n Point is not in the sampling frame; try again\n"); goto back1; } else { R_move_abs(xp, yp); x0 = xp; y0 = yp; } } /* right button, outline the unit */ else if (btn == 3) { if (circle) { if (u_w > u_l) { al = al + ((ar - al) - (ab - at)) / 2; ar = al + (ab - at); x0 = (int)((double)(al) / mx[0] + 0.5); xp = (int)((double)(ar) / mx[0] + 0.5); au_w = ar - al; u_w = u_l = (int)((double)(au_w) / mx[0] + 0.5); } if (u_l > u_w) { at = at + ((ab - at) - (ar - al)) / 2; ab = at + (ar - al); y0 = (int)((double)(at) / mx[1] + 0.5); yp = (int)((double)(ab) / mx[1] + 0.5); au_l = ab - at; u_w = u_l = (int)((double)(au_l) / mx[1] + 0.5); } } if (ar > r || ab > b || al < l || at < t) { fprintf(stderr, "\n The unit extends outside the sampling frame or map;"); fprintf(stderr, "\n try again\n"); goto back1; } if (au_w > w_w || au_l > w_l) { fprintf(stderr, "\n The unit is too big for the sampling frame; "); fprintf(stderr, "try again\n"); goto back1; } /* if there is a mask, check to see that the unit will be within the mask area, by checking to see whether the four corners of the unit are in the mask */ if (fmask > 0) { row_buf = Rast_allocate_c_buf(); Rast_get_c_row_nomask(fmask, row_buf, at); if (!(*(row_buf + al) && *(row_buf + ar - 1))) { fprintf(stderr, "\n The unit would be outside the mask; "); fprintf(stderr, "try again\n"); G_free(row_buf); goto back1; } Rast_zero_c_buf(row_buf); Rast_get_c_row_nomask(fmask, row_buf, ab - 1); if (!(*(row_buf + al) && *(row_buf + ar - 1))) { fprintf(stderr, "\n The unit would be outside the mask; "); fprintf(stderr, "try again\n"); G_free(row_buf); goto back1; } G_free(row_buf); } if (xp - x0 > 0 && yp - y0 > 0) { R_standard_color(D_translate_color("red")); if (circle) draw_circle(x0, y0, xp, yp, 3); else draw_box(x0, y0, xp, yp, 1); G_system("clear"); if (circle) { fprintf(stderr, "\n\n The standard circular sampling unit has:\n"); fprintf(stderr, " radius = %f pixels\n", (double)(ar - al) / 2.0); } else { fprintf(stderr, "\n\n The standard sampling unit has:\n"); fprintf(stderr, " columns=%d rows=%d\n", abs(ar - al), abs(ab - at)); fprintf(stderr, " width/length ratio=%5.2f\n", (double)abs(ar - al) / (double)abs(ab - at)); fprintf(stderr, " size=%d pixels\n", abs(ar - al) * abs(ab - at)); } k = 0; ux[0] = al; uy[0] = at; } else if (xp - x0 == 0 || yp - y0 == 0) { fprintf(stderr, "\n Unit has 0 rows and/or 0 columns; try again\n"); goto back1; } else { fprintf(stderr, "\n You did not put the lower right corner below"); fprintf(stderr, "\n and to the right of the upper left corner. Please try again"); goto back1; } } } while (btn != 3); R_close_driver(); /* use the size and shape of the standard unit to outline more units in that scale */ fprintf(stderr, "\n Outline more sampling units of scale %d?\n", i + 1); fprintf(stderr, " Left button: Exit\n"); fprintf(stderr, " Middle button: Check unit position\n"); fprintf(stderr, " Right button: Lower right corner of next unit here\n"); R_open_driver(); /* if not the left button (to exit) */ back2: while (btn != 1) { R_get_location_with_box(xp - u_w, yp - u_l, &xp, &yp, &btn); /* convert the left (x0), right (y0), top (y0), bottom (yp) coordinates in screen pixels to the nearest row and column; do the same for the sampling unit width (u_w) and height (u_l); then convert back */ ar = (int)((double)(xp) * mx[0] + 0.5); ab = (int)((double)(yp) * mx[1] + 0.5); xp = (int)((double)(ar) / mx[0] + 0.5); yp = (int)((double)(ab) / mx[1] + 0.5); al = (int)((double)(xp - u_w) * mx[0] + 0.5); at = (int)((double)(yp - u_l) * mx[0] + 0.5); x0 = (int)((double)(al) / mx[0] + 0.5); y0 = (int)((double)(at) / mx[1] + 0.5); /* if right button, outline the unit */ if (btn == 3) { if (ar > r || ab > b || al < l || at < t) { fprintf(stderr, "\n The unit would be outside the map; try again"); goto back2; } /* if there is a mask, check to see that the unit will be within the mask area */ if (fmask > 0) { row_buf = Rast_allocate_c_buf(); Rast_get_c_row_nomask(fmask, row_buf, at); if (!(*(row_buf + al) && *(row_buf + ar - 1))) { fprintf(stderr, "\n The unit would be outside the mask; "); fprintf(stderr, "try again"); G_free(row_buf); goto back2; } Rast_zero_c_buf(row_buf); Rast_get_c_row_nomask(fmask, row_buf, ab - 1); if (!(*(row_buf + al) && *(row_buf + ar - 1))) { fprintf(stderr, "\n The unit would be outside the mask; "); fprintf(stderr, "try again"); G_free(row_buf); goto back2; } G_free(row_buf); } /* check for sampling unit overlap */ lap = 0; for (j = 0; j < k + 1; j++) { if (overlap(al, at, ux[j], uy[j], au_w, au_l)) { fprintf(stderr, "\n The unit would overlap a previously drawn "); fprintf(stderr, "unit; try again"); lap = 1; } } if (lap) goto back2; k++; fprintf(stderr, "\n %d sampling units have been placed", (k + 1)); ux[k] = al; uy[k] = at; R_standard_color(D_translate_color("red")); if (circle) draw_circle(x0, y0, xp, yp, 3); else draw_box(x0, y0, xp, yp, 1); } } R_close_driver(); /* save the sampling units in the r.le.para/units file */ if (circle) radius = (double)(ar - al) / 2.0; else radius = 0.0; fprintf(fp, "%10d # of units of scale %d\n", k + 1, i + 1); fprintf(fp, "%10d%10d u_w, u_l of units in scale %d\n", (int)(u_w * mx[0]), (int)(u_l * mx[1]), i + 1); fprintf(fp, "%10.1f radius of circles in scale %d\n", radius, (i + 1)); for (j = 0; j < k + 1; j++) fprintf(fp, "%10d%10d left, top of unit[%d]\n", ux[j], uy[j], j + 1); if (i < tmp - 1 && G_yes("\n Refresh the screen? ", 1)) { paint_map(n1, n2, n3); R_open_driver(); R_standard_color(D_translate_color("red")); R_close_driver(); } } fclose(fp); return; }
int main(int argc, char *argv[]) { struct GModule *module; int Out_proj; int out_stat; int old_zone, old_proj; int i; int stat; char cmnd2[500]; char proj_out[20], proj_name[50], set_name[20]; char path[1024], buffa[1024], buffb[1024], answer[200], answer1[200]; char answer2[200], buff[1024]; char tmp_buff[20], *buf; struct Key_Value *old_proj_keys, *out_proj_keys, *in_unit_keys; double aa, e2; double f; FILE *FPROJ; int exist = 0; char spheroid[100]; int j, k, sph_check; struct Cell_head cellhd; char datum[100], dat_ellps[100], dat_params[100]; struct proj_parm *proj_parms; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("general")); G_add_keyword(_("projection")); module->description = _("Interactively reset the location's projection settings."); if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (strcmp(G_mapset(), "PERMANENT") != 0) G_fatal_error(_("You must be in the PERMANENT mapset to run g.setproj")); /*** * no longer necessary, table is a static struct * init_unit_table(); ***/ sprintf(set_name, "PERMANENT"); G_file_name(path, "", PROJECTION_FILE, set_name); /* get the output projection parameters, if existing */ /* Check for ownership here */ stat = G__mapset_permissions(set_name); if (stat == 0) { G_fatal_error(_("PERMANENT: permission denied")); } G_get_default_window(&cellhd); if (-1 == G_set_window(&cellhd)) G_fatal_error(_("Current region cannot be set")); if (G_get_set_window(&cellhd) == -1) G_fatal_error(_("Retrieving and setting region failed")); Out_proj = cellhd.proj; old_zone = cellhd.zone; old_proj = cellhd.proj; if (access(path, 0) == 0) { exist = 1; FPROJ = fopen(path, "r"); old_proj_keys = G_fread_key_value(FPROJ); fclose(FPROJ); buf = G_find_key_value("name", old_proj_keys); fprintf(stderr, "\nWARNING: A projection file already exists for this location\n(Filename '%s')\n", path); fprintf(stderr, "\nThis file contains all the parameters for the location's projection:\n %s\n", buf); fprintf(stderr, "\n Overriding this information implies that the old projection parameters\n" " were incorrect. If you change the parameters, all existing data will\n" " be interpreted differently by the projection software.\n%c%c%c", 7, 7, 7); fprintf(stderr, " GRASS will not re-project your data automatically.\n\n"); if (!G_yes (_("Would you still like to change some of the parameters?"), 0)) { G_message(_("The projection information will not be updated")); leave(SP_NOCHANGE); } } out_proj_keys = G_create_key_value(); if (exist) { buf = G_find_key_value("zone", old_proj_keys); if (buf != NULL) sscanf(buf, "%d", &zone); if (zone != old_zone) { G_warning(_("Zone in default geographic region definition: %d\n" " is different from zone in PROJ_INFO file: %d"), old_zone, zone); old_zone = zone; } } switch (Out_proj) { case 0: /* No projection/units */ if (!exist) { /* leap frog over code, and just make sure we remove the file */ G_warning(_("XY-location cannot be projected")); goto write_file; break; } case PROJECTION_UTM: if (!exist) { sprintf(proj_name, "%s", G__projection_name(PROJECTION_UTM)); sprintf(proj_out, "utm"); break; } case PROJECTION_SP: if (!exist) { sprintf(proj_name, "%s", G__projection_name(PROJECTION_SP)); sprintf(proj_out, "stp"); break; } case PROJECTION_LL: if (!exist) { sprintf(proj_name, "%s", G__projection_name(PROJECTION_LL)); sprintf(proj_out, "ll"); break; } case PROJECTION_OTHER: if (G_ask_proj_name(proj_out, proj_name) < 0) leave(SP_NOCHANGE); if (G_strcasecmp(proj_out, "LL") == 0) Out_proj = PROJECTION_LL; else if (G_strcasecmp(proj_out, "UTM") == 0) Out_proj = PROJECTION_UTM; else if (G_strcasecmp(proj_out, "STP") == 0) Out_proj = PROJECTION_SP; break; default: G_fatal_error(_("Unknown projection")); } cellhd.proj = Out_proj; proj_parms = get_proj_parms(proj_out); if (!proj_parms) G_fatal_error(_("Projection %s is not specified in the file 'proj-parms.table'"), proj_out); G_set_key_value("name", proj_name, out_proj_keys); sph_check = 0; if (G_yes (_("Do you wish to specify a geodetic datum for this location?"), 1)) { char lbuf[100], lbufa[100]; if (exist && (G_get_datumparams_from_projinfo(old_proj_keys, lbuf, lbufa) == 2)) { G_strip(lbuf); if ((i = G_get_datum_by_name(lbuf)) > 0) { G_message(_("The current datum is %s (%s)"), G_datum_name(i), G_datum_description(i)); if (G_yes (_("Do you wish to change the datum (or datum transformation parameters)?"), 0)) sph_check = ask_datum(datum, dat_ellps, dat_params); else { sprintf(datum, lbuf); sprintf(dat_params, lbufa); sprintf(dat_ellps, G_datum_ellipsoid(i)); sph_check = 1; G_message(_("The datum information has not been changed")); } } else sph_check = ask_datum(datum, dat_ellps, dat_params); } else sph_check = ask_datum(datum, dat_ellps, dat_params); } if (sph_check > 0) { char *paramkey, *paramvalue; /* write out key/value pairs to out_proj_keys */ if (G_strcasecmp(datum, "custom") != 0) G_set_key_value("datum", datum, out_proj_keys); /* G_set_key_value("datumparams", dat_params, out_proj_keys); */ paramkey = strtok(dat_params, "="); paramvalue = dat_params + strlen(paramkey) + 1; G_set_key_value(paramkey, paramvalue, out_proj_keys); sprintf(spheroid, "%s", dat_ellps); } else { /***************** GET spheroid **************************/ if (Out_proj != PROJECTION_SP) { /* some projections have * fixed spheroids */ if (G_strcasecmp(proj_out, "ALSK") == 0 || G_strcasecmp(proj_out, "GS48") == 0 || G_strcasecmp(proj_out, "GS50") == 0) { sprintf(spheroid, "%s", "clark66"); G_set_key_value("ellps", spheroid, out_proj_keys); sph_check = 1; } else if (G_strcasecmp(proj_out, "LABRD") == 0 || G_strcasecmp(proj_out, "NZMG") == 0) { sprintf(spheroid, "%s", "international"); G_set_key_value("ellps", spheroid, out_proj_keys); sph_check = 1; } else if (G_strcasecmp(proj_out, "SOMERC") == 0) { sprintf(spheroid, "%s", "bessel"); G_set_key_value("ellps", spheroid, out_proj_keys); sph_check = 1; } else if (G_strcasecmp(proj_out, "OB_TRAN") == 0) { /* Hard coded to use "Equidistant Cylincrical" * until g.setproj has been changed to run * recurively, to allow input of options for * a second projection, MHu991010 */ G_set_key_value("o_proj", "eqc", out_proj_keys); sph_check = 2; } else { if (exist && (buf = G_find_key_value("ellps", old_proj_keys)) != NULL) { strcpy(spheroid, buf); G_strip(spheroid); if (G_get_spheroid_by_name(spheroid, &aa, &e2, &f)) { /* if legal ellips. exist, ask wether or not to change it */ G_message(_("The current ellipsoid is %s"), spheroid); if (G_yes (_("Do you want to change ellipsoid parameter?"), 0)) sph_check = G_ask_ellipse_name(spheroid); else { G_message(_("The ellipse information has not been changed")); sph_check = 1; } } /* the val is legal */ else sph_check = G_ask_ellipse_name(spheroid); } else sph_check = G_ask_ellipse_name(spheroid); } } if (sph_check > 0) { if (sph_check == 2) { /* ask radius */ if (exist) { buf = G_find_key_value("a", old_proj_keys); if ((buf != NULL) && (sscanf(buf, "%lf", &radius) == 1)) { G_message(_("The radius is currently %f"), radius); if (G_yes(_("Do you want to change the radius?"), 0)) radius = prompt_num_double(_("Enter radius for the sphere in meters"), RADIUS_DEF, 1); } } else radius = prompt_num_double(_("Enter radius for the sphere in meters"), RADIUS_DEF, 1); } /* end ask radius */ } } /*** END get spheroid ***/ /* create the PROJ_INFO & PROJ_UNITS files, if required */ if (G_strcasecmp(proj_out, "LL") == 0) ; else if (G_strcasecmp(proj_out, "STP") == 0) get_stp_proj(buffb); else if (sph_check != 2) { G_strip(spheroid); if (G_get_spheroid_by_name(spheroid, &aa, &e2, &f) == 0) G_fatal_error(_("Invalid input ellipsoid")); } write_file: /* ** NOTE the program will (hopefully) never exit abnormally ** after this point. Thus we know the file will be completely ** written out once it is opened for write */ if (exist) { sprintf(buff, "%s~", path); G_rename_file(path, buff); } if (Out_proj == 0) goto write_units; /* ** Include MISC parameters for PROJ_INFO */ if (G_strcasecmp(proj_out, "STP") == 0) { for (i = 0; i < strlen(buffb); i++) if (buffb[i] == ' ') buffb[i] = '\t'; sprintf(cmnd2, "%s\t\n", buffb); for (i = 0; i < strlen(cmnd2); i++) { j = k = 0; if (cmnd2[i] == '+') { while (cmnd2[++i] != '=') buffa[j++] = cmnd2[i]; buffa[j] = 0; while (cmnd2[++i] != '\t' && cmnd2[i] != '\n' && cmnd2[i] != 0) buffb[k++] = cmnd2[i]; buffb[k] = 0; G_set_key_value(buffa, buffb, out_proj_keys); } } } else if (G_strcasecmp(proj_out, "LL") == 0) { G_set_key_value("proj", "ll", out_proj_keys); G_set_key_value("ellps", spheroid, out_proj_keys); } else { if (sph_check != 2) { G_set_key_value("proj", proj_out, out_proj_keys); G_set_key_value("ellps", spheroid, out_proj_keys); sprintf(tmp_buff, "%.10f", aa); G_set_key_value("a", tmp_buff, out_proj_keys); sprintf(tmp_buff, "%.10f", e2); G_set_key_value("es", tmp_buff, out_proj_keys); sprintf(tmp_buff, "%.10f", f); G_set_key_value("f", tmp_buff, out_proj_keys); } else { G_set_key_value("proj", proj_out, out_proj_keys); /* G_set_key_value ("ellps", "sphere", out_proj_keys); */ sprintf(tmp_buff, "%.10f", radius); G_set_key_value("a", tmp_buff, out_proj_keys); G_set_key_value("es", "0.0", out_proj_keys); G_set_key_value("f", "0.0", out_proj_keys); } for (i = 0;; i++) { struct proj_parm *parm = &proj_parms[i]; struct proj_desc *desc; if (!parm->name) break; desc = get_proj_desc(parm->name); if (!desc) break; if (parm->ask) { if (G_strcasecmp(desc->type, "bool") == 0) { if (G_yes((char *)desc->desc, 0)) { G_set_key_value(desc->key, "defined", out_proj_keys); if (G_strcasecmp(parm->name, "SOUTH") == 0) cellhd.zone = -abs(cellhd.zone); } } else if (G_strcasecmp(desc->type, "lat") == 0) { double val; while (!get_LL_stuff(parm, desc, 1, &val)) ; sprintf(tmp_buff, "%.10f", val); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } else if (G_strcasecmp(desc->type, "lon") == 0) { double val; while (!get_LL_stuff(parm, desc, 0, &val)) ; sprintf(tmp_buff, "%.10f", val); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } else if (G_strcasecmp(desc->type, "float") == 0) { double val; while (!get_double(parm, desc, &val)) ; sprintf(tmp_buff, "%.10f", val); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } else if (G_strcasecmp(desc->type, "int") == 0) { int val; while (!get_int(parm, desc, &val)) ; sprintf(tmp_buff, "%d", val); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } else if (G_strcasecmp(desc->type, "zone") == 0) { if ((Out_proj == PROJECTION_UTM) && (old_zone != 0)) { G_message(_("The UTM zone is now set to %d"), old_zone); if (!G_yes (_("Do you want to change the UTM zone?"), 0)) { G_message(_("UTM zone information has not been updated")); zone = old_zone; break; } else { G_message(_("But if you change zone, all the existing " "data will be interpreted by projection software. " "GRASS will not automatically re-project or even " "change the headers for existing maps.")); if (!G_yes (_("Would you still like to change the UTM zone?"), 0)) { zone = old_zone; break; } } } /* UTM */ while (!get_zone()) ; sprintf(tmp_buff, "%d", zone); G_set_key_value("zone", tmp_buff, out_proj_keys); cellhd.zone = zone; } } else if (parm->def_exists) { /* don't ask, use the default */ if (G_strcasecmp(desc->type, "float") == 0 || G_strcasecmp(desc->type, "lat") == 0 || G_strcasecmp(desc->type, "lon") == 0) { sprintf(tmp_buff, "%.10f", parm->deflt); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } else if (G_strcasecmp(desc->type, "int") == 0) { sprintf(tmp_buff, "%d", (int)parm->deflt); G_set_key_value(desc->key, tmp_buff, out_proj_keys); } } } /* for OPTIONS */ } /* create the PROJ_INFO & PROJ_UNITS files, if required */ G_write_key_value_file(path, out_proj_keys, &out_stat); if (out_stat != 0) { G_fatal_error(_("Error writing PROJ_INFO file <%s>"), path); } G_free_key_value(out_proj_keys); if (exist) G_free_key_value(old_proj_keys); write_units: G_file_name(path, "", UNIT_FILE, set_name); /* if we got this far, the user ** already affirmed to write over old info ** so if units file is here, remove it. */ if (access(path, 0) == 0) { sprintf(buff, "%s~", path); G_rename_file(path, buff); } if (Out_proj == 0) leave(0); { in_unit_keys = G_create_key_value(); switch (Out_proj) { case PROJECTION_UTM: G_set_key_value("unit", "meter", in_unit_keys); G_set_key_value("units", "meters", in_unit_keys); G_set_key_value("meters", "1.0", in_unit_keys); break; case PROJECTION_SP: for (;;) { do { fprintf(stderr, "\nSpecify the correct units to use:\n"); fprintf(stderr, "Enter the corresponding number\n"); fprintf(stderr, "1.\tUS Survey Foot (Default for State Plane 1927)\n"); fprintf(stderr, "2.\tInternational Foot\n"); fprintf(stderr, "3.\tMeter\n"); fprintf(stderr, ">"); } while (!G_gets(answer)); G_strip(answer); if (strcmp(answer, "1") == 0) { G_set_key_value("unit", "USfoot", in_unit_keys); G_set_key_value("units", "USfeet", in_unit_keys); G_set_key_value("meters", "0.30480060960121920243", in_unit_keys); break; } else if (strcmp(answer, "2") == 0) { G_set_key_value("unit", "foot", in_unit_keys); G_set_key_value("units", "feet", in_unit_keys); G_set_key_value("meters", "0.3048", in_unit_keys); break; } else if (strcmp(answer, "3") == 0) { G_set_key_value("unit", "meter", in_unit_keys); G_set_key_value("units", "meters", in_unit_keys); G_set_key_value("meters", "1.0", in_unit_keys); break; } else fprintf(stderr, "\nInvalid Entry (number 1 - 3)\n"); } break; case PROJECTION_LL: G_set_key_value("unit", "degree", in_unit_keys); G_set_key_value("units", "degrees", in_unit_keys); G_set_key_value("meters", "1.0", in_unit_keys); break; default: if (G_strcasecmp(proj_out, "LL") != 0) { fprintf(stderr, _("Enter plural form of units [meters]: ")); G_gets(answer); if (strlen(answer) == 0) { G_set_key_value("unit", "meter", in_unit_keys); G_set_key_value("units", "meters", in_unit_keys); G_set_key_value("meters", "1.0", in_unit_keys); } else { const struct proj_unit *unit; G_strip(answer); unit = get_proj_unit(answer); if (unit) { #ifdef FOO if (G_strcasecmp(proj_out, "STP") == 0 && !strcmp(answer, "feet")) { fprintf(stderr, "%cPROJECTION 99 State Plane cannot be in FEET.\n", 7); remove(path); /* remove file */ leave(SP_FATAL); } #endif G_set_key_value("unit", unit->unit, in_unit_keys); G_set_key_value("units", unit->units, in_unit_keys); sprintf(buffb, "%.10f", unit->fact); G_set_key_value("meters", buffb, in_unit_keys); } else { double unit_fact; while (1) { fprintf(stderr, _("Enter singular for unit: ")); G_gets(answer1); G_strip(answer1); if (strlen(answer1) > 0) break; } while (1) { fprintf(stderr, _("Enter conversion factor from %s to meters: "), answer); G_gets(answer2); G_strip(answer2); if (! (strlen(answer2) == 0 || (1 != sscanf(answer2, "%lf", &unit_fact)))) break; } G_set_key_value("unit", answer1, in_unit_keys); G_set_key_value("units", answer, in_unit_keys); sprintf(buffb, "%.10f", unit_fact); G_set_key_value("meters", buffb, in_unit_keys); } } } else { G_set_key_value("unit", "degree", in_unit_keys); G_set_key_value("units", "degrees", in_unit_keys); G_set_key_value("meters", "1.0", in_unit_keys); } } /* switch */ G_write_key_value_file(path, in_unit_keys, &out_stat); if (out_stat != 0) G_fatal_error(_("Error writing into UNITS output file <%s>"), path); G_free_key_value(in_unit_keys); } /* if */ if (G__put_window(&cellhd, "", "DEFAULT_WIND") < 0) G_fatal_error(_("Unable to write to DEFAULT_WIND region file")); fprintf(stderr, _("\nProjection information has been recorded for this location\n\n")); if ((old_zone != zone) | (old_proj != cellhd.proj)) { G_message(_("The geographic region information in WIND is now obsolete")); G_message(_("Run g.region -d to update it")); } leave(0); }
/* in addition there seem to be some useful user options here which are not currently available from the main parser */ int com_line_Gwater(INPUT * input, OUTPUT * output) { struct Cell_head *window; char map_layer[48], buf[100], *prog_name, *mapset; double d; int i; window = &(output->window); if (0 == G_yes("Continue?", 1)) exit(EXIT_SUCCESS); input->haf_name = (char *)G_calloc(40, sizeof(char)); input->accum_name = (char *)G_calloc(40, sizeof(char)); G_message(_("\nThis set of questions will organize the command line for the")); G_message(_("%s program to run properly for your application."), NON_NAME); G_message(_("The first question is whether you want %s to run"), NON_NAME); G_message(_("in its fast mode or its slow mode. If you run %s"), NON_NAME); G_message(_("in the fast mode, the computer will finish about 10 times faster")); G_message(_("than in the slow mode, but will not allow other programs to run")); G_message(_("at the same time. The fast mode also places all of the data into")); G_message(_("RAM, which limits the size of window that can be run. The slow")); G_message(_("mode uses disk space in the same hard disk partition as where GRASS is")); G_message(_("stored. Thus, if the program does not work in the slow mode, you will")); G_message(_("need to remove unnecessary files from that partition. The slow mode")); G_message(_("will allow other processes to run concurrently with %s.\n"), NON_NAME); sprintf(buf, "Do you want to use the fast mode of %s?", NON_NAME); input->com_line_ram = input->com_line_seg = NULL; input->fast = 0; input->slow = 0; if (G_yes(buf, 1)) { input->fast = 1; input->com_line_ram = (char *)G_calloc(400, sizeof(char)); prog_name = G_store(RAM_NAME); sprintf(input->com_line_ram, "\"%s/etc/water/%s\"", G_gisbase(), RAM_NAME); fprintf(stderr, "\nIf there is not enough ram for the fast mode (%s) to run,\n", RAM_NAME); sprintf(buf, "should the slow mode (%s) be run instead?", SEG_NAME); if (G_yes(buf, 1)) { input->slow = 1; input->com_line_seg = (char *)G_calloc(400, sizeof(char)); sprintf(input->com_line_seg, "\"%s/etc/water/%s\"", G_gisbase(), SEG_NAME); } } else { input->slow = 1; prog_name = G_store(SEG_NAME); input->com_line_seg = (char *)G_calloc(400, sizeof(char)); sprintf(input->com_line_seg, "\"%s/etc/water/%s\"", G_gisbase(), SEG_NAME); } G_message(_("\nIf you hit <return> by itself for the next question, this")); G_message(_("program will terminate.")); mapset = G_ask_old("What is the name of the elevation map layer?", map_layer, "cell", "cell"); if (!mapset) exit(EXIT_FAILURE); if (input->fast) com_line_add(&(input->com_line_ram), " el=", map_layer, mapset); if (input->slow) com_line_add(&(input->com_line_seg), " el=", map_layer, mapset); G_message(_("\nOne of the options for %s is a `depression map'. A"), prog_name); G_message(_("depression map indicates all the locations in the current map window where")); G_message(_("water accumulates and does not leave by the edge of the map. Lakes without")); G_message(_("outlet streams and sinkholes are examples of `depressions'. If you wish to")); G_message(_("have a depression map, prepare a map where non-zero values indicate the")); G_message(_("locations where depressions occur.\n")); G_message(_("Hit <return> by itself for the next question if there is no depression map.")); mapset = G_ask_old("What is the name of the depression map layer?", map_layer, "cell", "cell"); if (mapset) { if (input->fast) com_line_add(&(input->com_line_ram), " de=", map_layer, mapset); if (input->slow) com_line_add(&(input->com_line_seg), " de=", map_layer, mapset); } G_message(_("\nThe %s program will divide the elevation map into a number of"), prog_name); G_message(_("watershed basins. The number of watershed basins is indirectly determined")); G_message(_("by the `basin threshold' value. The basin threshold is the area necessary for")); G_message(_("%s to define a unique watershed basin. This area only applies to"), prog_name); G_message(_("`exterior drainage basins'. An exterior drainage basin does not have any")); G_message(_("drainage basins flowing into it. Interior drainage basin size is determined")); G_message(_("by the surface flow going into stream segments between stream interceptions.")); G_message(_("Thus interior drainage basins can be of any size. The %s program"), prog_name); G_message(_("also allows the user to relate basin size to potential overland flow")); G_message(_("(i.e., areas with low infiltration capacities will need smaller areas to")); G_message(_("develop stream channels than neighboring areas with high infiltration rates).")); G_message(_("The user can create a map layer with potential overland flow values, and")); G_message(_("%s will accumulate those values instead of area.\n"), prog_name); G_message(_("What unit of measure will you use for the basin threshold:")); do { G_message(_(" 1) acres, 2) meters sq., 3) miles sq., 4) hectares,")); G_message(_(" 5) kilometers sq., 6) map cells, 7) overland flow units")); fprintf(stderr, _("Choose 1-7 or 0 to exit this program: ")); G_gets(map_layer); sscanf(map_layer, "%d", &i); } while (i > 7 || i < 0); if (!i) exit(EXIT_SUCCESS); output->type_area = (char)i; G_message(_("\nHow large an area (or how many overland flow units) must a drainage basin")); fprintf(stderr, _("be for it to be an exterior drainage basin: ")); G_gets(map_layer); sscanf(map_layer, "%lf", &d); switch (i) { case 1: if (input->fast) basin_com_add(&(input->com_line_ram), d, ACRE_TO_METERSQ, window); if (input->slow) basin_com_add(&(input->com_line_seg), d, ACRE_TO_METERSQ, window); break; case 2: if (input->fast) basin_com_add(&(input->com_line_ram), d, 1.0, window); if (input->slow) basin_com_add(&(input->com_line_seg), d, 1.0, window); break; case 3: if (input->fast) basin_com_add(&(input->com_line_ram), d, MILESQ_TO_METERSQ, window); if (input->slow) basin_com_add(&(input->com_line_seg), d, MILESQ_TO_METERSQ, window); break; case 4: if (input->fast) basin_com_add(&(input->com_line_ram), d, HECTACRE_TO_METERSQ, window); if (input->slow) basin_com_add(&(input->com_line_seg), d, HECTACRE_TO_METERSQ, window); break; case 5: if (input->fast) basin_com_add(&(input->com_line_ram), d, KILOSQ_TO_METERSQ, window); if (input->slow) basin_com_add(&(input->com_line_seg), d, KILOSQ_TO_METERSQ, window); break; case 6: if (input->fast) basin_com_add(&(input->com_line_ram), d, (window->ns_res * window->ew_res), window); if (input->slow) basin_com_add(&(input->com_line_seg), d, (window->ns_res * window->ew_res), window); break; case 7: /* needs an overland flow map */ G_message(_("\nIf you hit <return> by itself for the next question, this")); G_message(_("program will terminate.")); mapset = G_ask_old("What is the name of the overland flow map layer?", map_layer, "cell", "cell"); if (!mapset) exit(EXIT_FAILURE); if (input->fast) { com_line_add(&(input->com_line_ram), " ov=", map_layer, mapset); basin_com_add(&(input->com_line_ram), d, (window->ns_res * window->ew_res), window); } if (input->slow) { com_line_add(&(input->com_line_seg), " ov=", map_layer, mapset); basin_com_add(&(input->com_line_seg), d, (window->ns_res * window->ew_res), window); } break; } G_message(_("\n%s must create a map layer of watershed basins"), prog_name); G_message(_("before %s can run properly."), G_program_name()); strcpy(buf, "Please name the output watershed basin map:"); do { mapset = G_ask_new(buf, input->haf_name, "cell", ""); } while (NULL == mapset); if (input->fast) com_line_add(&(input->com_line_ram), " ba=", input->haf_name, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " ba=", input->haf_name, NULL); /* This section queries the user about the armsed file input. If you want to make this an option, the code below "COMMENT2" needs to be modified. */ #ifdef ARMSED G_message(_("\n%s must create a file of watershed basin relationships"), prog_name); G_message(_("before %s can run properly."), G_program_name()); input->ar_file_name = NULL; while (input->ar_file_name == NULL) { fprintf(stderr, _("\nPlease name this file:")); G_gets(char_input); if (1 != G_legal_filename(char_input)) { G_message(_("<%s> is an illegal file name"), char_input); } else input->ar_file_name = G_store(char_input); } if (input->fast) com_line_add(&(input->com_line_ram), " ar=", input->ar_file_name, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " ar=", input->ar_file_name, NULL); /* end of ARMSED comment code */ /* COMMENT2 This section of code tells the program where to place the statistics about the watershed basin. GRASS users don't need this (w/ r.stats), but the format is suppossed to be "user-friendly" to hydrologists. For the stats to be created, the armsed file output needs to exist. For the stats to be an option in this program: 1) it should be querried before the armsed file query, and 2) make the armsed file query manditory if this option is invoked. */ G_message(_("\n%s will generate a lot of output. Indicate a file"), G_program_name()); G_message(_("name for %s to send the output to."), G_program_name()); output->file_name = NULL; while (output->file_name == NULL) { fprintf(stderr, _("\nPlease name this file:")); G_gets(char_input); if (1 != G_legal_filename(char_input)) { G_message(_("<%s> is an illegal file name"), char_input); } else output->file_name = G_store(char_input); } /* end of COMMENT2 */ #endif G_message(_("\nThe accumulation map from %s must be present for"), prog_name); G_message(_("%s to work properly."), G_program_name()); strcpy(buf, "Please name the accumulation map:"); do { mapset = G_ask_new(buf, input->accum_name, "cell", ""); } while (NULL == mapset); if (input->fast) com_line_add(&(input->com_line_ram), " ac=", input->accum_name, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " ac=", input->accum_name, NULL); G_message(_("\n%s can produce several maps not necessary for"), prog_name); G_message(_("%s to function (stream channels, overland flow aspect, and"), G_program_name()); G_message(_("a display version of the accumulation map). %s also has the"), prog_name); G_message(_("ability to generate several variables in the Revised Universal Soil Loss")); G_message(_("Equation (Rusle): Slope Length (LS), and Slope Steepness (S).\n")); sprintf(buf, "Would you like any of these maps to be created?"); if (G_yes(buf, 1)) { mapset = G_ask_new("", map_layer, "cell", "stream channel"); if (mapset != NULL) { if (input->fast) com_line_add(&(input->com_line_ram), " se=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " se=", map_layer, NULL); } mapset = G_ask_new("", map_layer, "cell", "half basin"); if (mapset != NULL) { if (input->fast) com_line_add(&(input->com_line_ram), " ha=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " ha=", map_layer, NULL); } mapset = G_ask_new("", map_layer, "cell", "overland aspect"); if (mapset != NULL) { if (input->fast) com_line_add(&(input->com_line_ram), " dr=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " dr=", map_layer, NULL); } mapset = G_ask_new("", map_layer, "cell", "display"); if (mapset != NULL) { if (input->fast) com_line_add(&(input->com_line_ram), " di=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " di=", map_layer, NULL); } i = 0; mapset = G_ask_new("", map_layer, "cell", "Slope Length"); if (mapset != NULL) { i = 1; if (input->fast) com_line_add(&(input->com_line_ram), " LS=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " LS=", map_layer, NULL); } mapset = G_ask_new("", map_layer, "cell", "Slope Steepness"); if (mapset != NULL) { i = 1; if (input->fast) com_line_add(&(input->com_line_ram), " S=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " S=", map_layer, NULL); } if (i) { G_message(_("\nThe Slope Length factor (LS) and Slope Steepness (S) are influenced by")); G_message(_("disturbed land. %s reflects this with an optional map layer or value"), prog_name); G_message(_("where the value indicates the percent of disturbed (barren) land in that cell.")); G_message(_("Type <return> if you do not have a disturbed land map layer.")); mapset = G_ask_old("", map_layer, "cell", "disturbed land"); if (mapset != NULL) { if (input->fast) com_line_add(&(input->com_line_ram), " r=", map_layer, NULL); if (input->slow) com_line_add(&(input->com_line_seg), " r=", map_layer, NULL); } else { G_message(_("\nType the value indicating the percent of disturbed land. This value will")); G_message(_("be used for every cell in the current region.")); i = -6; while (i < 0 || i > 100) { fprintf(stderr, _("\nInput value here [0-100]: ")); fgets(buf, 80, stdin); sscanf(buf, "%d", &i); } if (input->fast) com_add(&(input->com_line_ram), " r=", i); if (input->slow) com_add(&(input->com_line_seg), " r=", i); } /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ G_message(_("\nOverland surface flow only occurs for a set distance before swales form.")); G_message(_("Because of digital terrain model limitations, %s cannot pick up"), prog_name); G_message(_("these swales. %s allows for an input (warning: kludge factor)"), prog_name); G_message(_("that prevents the surface flow distance from getting too long. Normally,")); G_message(_("maximum slope length is around 600 feet (about 183 meters).")); i = -1; while (i < 0) { fprintf(stdout, "\nInput maximum slope length here (in meters): "); fgets(buf, 80, stdin); sscanf(buf, "%d", &i); } if (input->fast) com_add(&(input->com_line_ram), " ms=", i); if (input->slow) com_add(&(input->com_line_seg), " ms=", i); /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ G_message(_("\nRoads, ditches, changes in ground cover, and other factors will stop")); G_message(_("slope length. You may input a raster map indicating the locations of these")); G_message(_("blocking factors.\n")); G_message(_("Hit <return> by itself for the next question if there is no blocking map.")); mapset = G_ask_old("What is the name of the blocking map layer?", map_layer, "cell", "cell"); if (mapset) { if (input->fast) com_line_add(&(input->com_line_ram), " ob=", map_layer, mapset); if (input->slow) com_line_add(&(input->com_line_seg), " ob=", map_layer, mapset); } } } return 0; }
static void set_frame(double *msc, int *t, int *b, int *l, int *r) { int t0, b0, l0, r0, btn; /* record the initial boundaries of the map */ t0 = *t; b0 = *b; l0 = *l; r0 = *r; /* if the total area to be sampled will be the whole map */ G_system("clear"); if (G_yes ("\n Will the sampling frame (total area within which sampling\n units are distributed) be the whole map? ", 1)) { R_open_driver(); R_standard_color(D_translate_color("grey")); draw_box(*l, *t, *r, *b, 1); R_close_driver(); fprintf(stderr, "\n Sampling frame set to whole map"); } /* if the total area to be sampled is not the whole map, then have the user draw the area */ else { back: G_system("clear"); fprintf(stderr, " \n OUTLINE SAMPLING FRAME:\n"); R_open_driver(); fprintf(stderr, "\n Please move cursor to the UPPER-LEFT corner of\n"); fprintf(stderr, " the sampling frame and click any mouse button\n"); R_get_location_with_line(0, 0, l, t, &btn); fprintf(stderr, "\n Please move cursor to the LOWER-RIGHT corner of\n"); fprintf(stderr, " the sampling frame and click any mouse button again\n"); back2: R_get_location_with_box(*l, *t, r, b, &btn); /* check that sampling frame is in map */ if (*l < l0 || *r > r0 || *t < t0 || *b > b0) { fprintf(stderr, "\n The cursor is outside of the map, try again\n"); goto back; } /* check that cursor is below & to right */ if (*r <= *l || *b <= *t) { fprintf(stderr, "\n Please put the lower right corner below and to the"); fprintf(stderr, "\n right of the upper left corner\n"); goto back2; } R_standard_color(D_translate_color("grey")); *l = (int)((double)((int)(*l * msc[0] + 0.5)) / msc[0]); *r = (int)((double)((int)(*r * msc[0] + 0.5)) / msc[0]); *t = (int)((double)((int)(*t * msc[1] + 0.5)) / msc[1]); *b = (int)((double)((int)(*b * msc[1] + 0.5)) / msc[1]); draw_box(*l, *t, *r, *b, 1); R_close_driver(); fprintf(stderr, "\n Sampling frame is set to the area you just drew"); } return; }
void set_map(char *name, char *name1, char *name2, struct Cell_head window, int top, int bot, int left, int right) { char cmd[30], cmd1[30], cmd2[30], **sel; int i, j, btn, d, class, top0, bot0, right0, left0, paint = 0, method; double msc[2], dtmp; /* VARIABLES IN: name = raster map name to be set up name1 = overlay vector map name name2 = overlay site map name */ colors_old = (struct Colors *)G_malloc(1 * sizeof(struct Colors)); Rast_init_colors(colors_old); Rast_read_colors(name, G_mapset(), colors_old); G_system("clear"); paint_map(name, name1, name2); paint = 1; /* setup the screen to raster map coordinate conversion system */ scr_cell(&window, top, bot, left, right, msc); top0 = top; bot0 = bot; left0 = left; right0 = right; /* display the menu and instructions */ again: if (!paint) { if (G_yes ("\n Refresh the screen before choosing more setup? ", 1)) paint_map(name, name1, name2); } else G_system("clear"); fprintf(stderr, "\n\n CHOOSE THE SETUP OPTION:\n\n"); fprintf(stderr, " Draw sampling regions 1\n"); fprintf(stderr, " Setup a sampling frame 2\n"); fprintf(stderr, " Setup sampling units 3\n"); fprintf(stderr, " Setup a moving window 4\n"); fprintf(stderr, " Setup group or class limits 5\n"); fprintf(stderr, " Change the raster map color table 6\n"); fprintf(stderr, " Exit and save setup 7\n"); do { fprintf(stderr, "\n Which Number? "); dtmp = 5.0; numtrap(1, &dtmp); if ((method = fabs(dtmp)) > 7 || method < 1) { fprintf(stderr, "\n Choice must between 1-7; try again"); } } while (method > 7 || method < 1); /* setup regions */ if (method == 1) set_rgn(msc, name, name1, name2); /* setup the sampling frame */ else if (method == 2) { top = top0; bot = bot0; right = right0; left = left0; set_frame(msc, &top, &bot, &left, &right); } /* setup sampling units */ else if (method == 3) { sample(top, bot, left, right, name, name1, name2, msc); } /* setup the moving window */ else if (method == 4) { mov_wind(top, bot, left, right, name, name1, name2, msc); } /* setup group/class limits */ else if (method == 5) { /* setup the buffer to store the user's input */ sel = (char **)G_malloc(10 * sizeof(char *)); for (i = 0; i < 9; i++) sel[i] = (char *)G_calloc(2, sizeof(char)); back: ask_group(sel); /* check for no input */ if (sel[0][0] != 'x' && sel[1][0] != 'x' && sel[2][0] != 'x' && sel[3][0] != 'x' && sel[4][0] != 'x' && sel[5][0] != 'x' && sel[6][0] != 'x' && sel[7][0] != 'x' && sel[8][0] != 'x') { G_system("clear"); fprintf(stderr, " Did you mean to not make any attribute group"); if (!G_yes("\n or index class setup choices? ", 1)) goto back; } /* if there is input, then invoke the group/class setup module and then free the memory allocated for selections */ else { get_group_drv(sel); for (i = 0; i < 9; i++) G_free(sel[i]); G_free(sel); } } /* change color tables */ else if (method == 6) change_color(name, name1, name2); /* reset the colortable and exit */ else if (method == 7) { Rast_write_colors(name, G_mapset(), colors_old); Rast_free_colors(colors_old); /* R_close_driver(); */ G_system("d.frame -e"); exit(0); } paint = 0; goto again; return; }
int E_edit_cellhd(struct Cell_head *cellhd, int type) { char ll_north[20]; char ll_south[20]; char ll_east[20]; char ll_west[20]; char ll_nsres[20]; char ll_ewres[20]; char ll_def_north[20]; char ll_def_south[20]; char ll_def_east[20]; char ll_def_west[20]; char ll_def_ewres[20]; char ll_def_nsres[20]; char projection[80]; char **screen; struct Cell_head def_wind; double north, south, east, west; double nsres, ewres; char buf[64], buf2[30], *p; short ok; int line; char *prj; char *err; if (type == AS_CELLHD && (cellhd->rows <= 0 || cellhd->cols <= 0)) { G_message("E_edit_cellhd() - programmer error"); G_message(" ** rows and cols must be positive **"); return -1; } if (type != AS_DEF_WINDOW) { if (G_get_default_window(&def_wind) != 1) return -1; if (cellhd->proj < 0) { cellhd->proj = def_wind.proj; cellhd->zone = def_wind.zone; } else if (cellhd->zone < 0) cellhd->zone = def_wind.zone; } prj = G__projection_name(cellhd->proj); if (!prj) prj = "** unknown **"; sprintf(projection, "%d (%s)", cellhd->proj, prj); if (type != AS_DEF_WINDOW) { if (cellhd->west >= cellhd->east || cellhd->south >= cellhd->north) { cellhd->north = def_wind.north; cellhd->south = def_wind.south; cellhd->west = def_wind.west; cellhd->east = def_wind.east; if (type != AS_CELLHD) { cellhd->ew_res = def_wind.ew_res; cellhd->ns_res = def_wind.ns_res; cellhd->rows = def_wind.rows; cellhd->cols = def_wind.cols; } } if (cellhd->proj != def_wind.proj) { if (type == AS_CELLHD) G_message ("header projection %d differs from default projection %d", cellhd->proj, def_wind.proj); else G_message ("region projection %d differs from default projection %d", cellhd->proj, def_wind.proj); if (!G_yes("do you want to make them match? ", 1)) return -1; cellhd->proj = def_wind.proj; cellhd->zone = def_wind.zone; } if (cellhd->zone != def_wind.zone) { if (type == AS_CELLHD) G_message("header zone %d differs from default zone %d", cellhd->zone, def_wind.zone); else G_message("region zone %d differs from default zone %d", cellhd->zone, def_wind.zone); if (!G_yes("do you want to make them match? ", 1)) return -1; cellhd->zone = def_wind.zone; } *ll_def_north = 0; *ll_def_south = 0; *ll_def_east = 0; *ll_def_west = 0; *ll_def_ewres = 0; *ll_def_nsres = 0; format_northing(def_wind.north, ll_def_north, def_wind.proj); format_northing(def_wind.south, ll_def_south, def_wind.proj); format_easting(def_wind.east, ll_def_east, def_wind.proj); format_easting(def_wind.west, ll_def_west, def_wind.proj); format_resolution(def_wind.ew_res, ll_def_ewres, def_wind.proj); format_resolution(def_wind.ns_res, ll_def_nsres, def_wind.proj); } *ll_north = 0; *ll_south = 0; *ll_east = 0; *ll_west = 0; *ll_ewres = 0; *ll_nsres = 0; format_northing(cellhd->north, ll_north, cellhd->proj); format_northing(cellhd->south, ll_south, cellhd->proj); format_easting(cellhd->east, ll_east, cellhd->proj); format_easting(cellhd->west, ll_west, cellhd->proj); format_resolution(cellhd->ew_res, ll_ewres, cellhd->proj); format_resolution(cellhd->ns_res, ll_nsres, cellhd->proj); while (1) { ok = 1; /* List window options on the screen for the user to answer */ switch (type) { case AS_CELLHD: screen = cellhd_screen; break; case AS_DEF_WINDOW: screen = def_window_screen; break; default: screen = window_screen; break; } V_clear(); line = 0; while (*screen) V_line(line++, *screen++); /* V_ques ( variable, type, row, col, length) ; */ V_ques(ll_north, 's', 6, 36, 10); V_ques(ll_south, 's', 10, 36, 10); V_ques(ll_west, 's', 9, 12, 10); V_ques(ll_east, 's', 9, 52, 10); if (type != AS_CELLHD) { V_ques(ll_ewres, 's', 18, 48, 10); V_ques(ll_nsres, 's', 19, 48, 10); } if (type != AS_DEF_WINDOW) { V_const(ll_def_north, 's', 3, 36, 10); V_const(ll_def_south, 's', 13, 36, 10); V_const(ll_def_west, 's', 9, 1, 10); V_const(ll_def_east, 's', 9, 65, 10); if (type != AS_CELLHD) { V_const(ll_def_ewres, 's', 18, 21, 10); V_const(ll_def_nsres, 's', 19, 21, 10); } } V_const(projection, 's', 15, 23, (int)strlen(projection)); V_const(&cellhd->zone, 'i', 15, 60, 3); V_intrpt_ok(); if (!V_call()) return -1; G_squeeze(ll_north); G_squeeze(ll_south); G_squeeze(ll_east); G_squeeze(ll_west); if (type != AS_CELLHD) { G_squeeze(ll_ewres); G_squeeze(ll_nsres); } if (!G_scan_northing(ll_north, &cellhd->north, cellhd->proj)) { G_warning("Illegal value for north: %s", ll_north); ok = 0; } if (!G_scan_northing(ll_south, &cellhd->south, cellhd->proj)) { G_warning("Illegal value for south: %s", ll_south); ok = 0; } if (!G_scan_easting(ll_east, &cellhd->east, cellhd->proj)) { G_warning("Illegal value for east: %s", ll_east); ok = 0; } if (!G_scan_easting(ll_west, &cellhd->west, cellhd->proj)) { G_warning("Illegal value for west: %s", ll_west); ok = 0; } if (type != AS_CELLHD) { if (!G_scan_resolution(ll_ewres, &cellhd->ew_res, cellhd->proj)) { G_warning("Illegal east-west resolution: %s", ll_ewres); ok = 0; } if (!G_scan_resolution(ll_nsres, &cellhd->ns_res, cellhd->proj)) { G_warning("Illegal north-south resolution: %s", ll_nsres); ok = 0; } } if (!ok) { hitreturn(); continue; } /* Adjust and complete the cell header */ north = cellhd->north; south = cellhd->south; east = cellhd->east; west = cellhd->west; nsres = cellhd->ns_res; ewres = cellhd->ew_res; if ((err = G_adjust_Cell_head(cellhd, type == AS_CELLHD, type == AS_CELLHD))) { G_message("%s", err); hitreturn(); continue; } if (type == AS_CELLHD) { nsres = cellhd->ns_res; ewres = cellhd->ew_res; } SHOW: fprintf(stderr, "\n\n"); G_message(" projection: %s", projection); G_message(" zone: %d", cellhd->zone); G_format_northing(cellhd->north, buf, cellhd->proj); G_format_northing(north, buf2, cellhd->proj); fprintf(stderr, " north: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_northing(cellhd->south, buf, cellhd->proj); G_format_northing(south, buf2, cellhd->proj); fprintf(stderr, " south: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_easting(cellhd->east, buf, cellhd->proj); G_format_easting(east, buf2, cellhd->proj); fprintf(stderr, " east: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_easting(cellhd->west, buf, cellhd->proj); G_format_easting(west, buf2, cellhd->proj); fprintf(stderr, " west: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n\n"); G_format_resolution(cellhd->ew_res, buf, cellhd->proj); G_format_resolution(ewres, buf2, cellhd->proj); fprintf(stderr, " e-w res: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to conform to grid)"); } fprintf(stderr, "\n"); G_format_resolution(cellhd->ns_res, buf, cellhd->proj); G_format_resolution(nsres, buf2, cellhd->proj); fprintf(stderr, " n-s res: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to conform to grid)"); } fprintf(stderr, "\n\n"); G_message(" total rows: %15d", cellhd->rows); G_message(" total cols: %15d", cellhd->cols); sprintf(buf, "%lf", (double)cellhd->rows * cellhd->cols); *(p = strchr(buf, '.')) = 0; G_insert_commas(buf); G_message(" total cells: %15s", buf); fprintf(stderr, "\n"); if (type != AS_DEF_WINDOW) { if (cellhd->north > def_wind.north) { G_warning("north falls outside the default region"); ok = 0; } if (cellhd->south < def_wind.south) { G_warning("south falls outside the default region"); ok = 0; } if (cellhd->proj != PROJECTION_LL) { if (cellhd->east > def_wind.east) { G_warning("east falls outside the default region"); ok = 0; } if (cellhd->west < def_wind.west) { G_warning("west falls outside the default region"); ok = 0; } } } ASK: fflush(stdin); if (type == AS_CELLHD) fprintf(stderr, "\nDo you accept this header? (y/n) [%s] > ", ok ? "y" : "n"); else fprintf(stderr, "\nDo you accept this region? (y/n) [%s] > ", ok ? "y" : "n"); if (!G_gets(buf)) goto SHOW; G_strip(buf); switch (*buf) { case 0: break; case 'y': case 'Y': ok = 1; break; case 'n': case 'N': ok = 0; break; default: goto ASK; } if (ok) return 0; } }