setup.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /*
  2. ************************************************************
  3. * MODULE: r.le.setup/setup.c *
  4. * Version 5.0beta Oct. 1, 2001 *
  5. * *
  6. * AUTHOR: W.L. Baker, University of Wyoming *
  7. * BAKERWL@UWYO.EDU *
  8. * *
  9. * PURPOSE: To set up sampling areas, which can can then *
  10. * be used to obtain data using the r.le.dist, *
  11. * r.le.patch, and r.le.pixel programs. The *
  12. * setup.c code displays menus on the screen and *
  13. * asks for user input *
  14. * *
  15. * COPYRIGHT: (C) 2001 by W.L. Baker *
  16. * *
  17. * This program is free software under the GNU General *
  18. * Public License(>=v2). Read the file COPYING that comes *
  19. * with GRASS for details *
  20. * *
  21. ************************************************************/
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <unistd.h>
  25. #include <grass/gis.h>
  26. #include <grass/display.h>
  27. #include "setup.h"
  28. #include <grass/config.h>
  29. struct Colors *colors_old;
  30. static void change_draw(void);
  31. static void set_rgn(double *msc, char *name, char *name1, char *name2);
  32. static void set_frame(double *msc, int *t, int *b, int *l, int *r);
  33. static void ppoint(double *m, int x, int y, int num);
  34. static void pbutton(int opt);
  35. static void save_rgn(char *name, char *tempfile, FILE * tmp, int *x, int *y,
  36. int pts, int class, int opt);
  37. static void print_hd(FILE * mapfile, struct Cell_head *universe);
  38. static void scr_cell(struct Cell_head *wind, int top, int bot, int left,
  39. int right, double *m);
  40. static void change_color(char *name, char *name1, char *name2);
  41. static void change_draw(void)
  42. {
  43. int method;
  44. double dtmp;
  45. G_system("clear");
  46. fprintf(stderr, "\n\n CHOOSE THE COLOR FOR DRAWING:\n\n");
  47. fprintf(stderr, " Red 1\n");
  48. fprintf(stderr, " Orange 2\n");
  49. fprintf(stderr, " Yellow 3\n");
  50. fprintf(stderr, " Green 4\n");
  51. fprintf(stderr, " Blue 5\n");
  52. fprintf(stderr, " Indigo 6\n");
  53. fprintf(stderr, " White 7\n");
  54. fprintf(stderr, " Black 8\n");
  55. fprintf(stderr, " Brown 9\n");
  56. fprintf(stderr, " Magenta 10\n");
  57. fprintf(stderr, " Aqua 11\n");
  58. fprintf(stderr, " Gray 12\n\n");
  59. do {
  60. fprintf(stderr, "\n Which Number? ");
  61. numtrap(1, &dtmp);
  62. if ((method = fabs(dtmp)) > 12 || method < 1) {
  63. fprintf(stderr, "\n Choice must between 1-12; try again");
  64. }
  65. }
  66. while (method > 12 || method < 1);
  67. if (method == 1)
  68. R_standard_color(D_translate_color("red"));
  69. else if (method == 2)
  70. R_standard_color(D_translate_color("orange"));
  71. else if (method == 3)
  72. R_standard_color(D_translate_color("yellow"));
  73. else if (method == 4)
  74. R_standard_color(D_translate_color("green"));
  75. else if (method == 5)
  76. R_standard_color(D_translate_color("blue"));
  77. else if (method == 6)
  78. R_standard_color(D_translate_color("indigo"));
  79. else if (method == 7)
  80. R_standard_color(D_translate_color("white"));
  81. else if (method == 8)
  82. R_standard_color(D_translate_color("black"));
  83. else if (method == 9)
  84. R_standard_color(D_translate_color("brown"));
  85. else if (method == 10)
  86. R_standard_color(D_translate_color("magenta"));
  87. else if (method == 11)
  88. R_standard_color(D_translate_color("aqua"));
  89. else if (method == 12)
  90. R_standard_color(D_translate_color("gray"));
  91. return;
  92. }
  93. /* SHOW MAIN MENU AND INVOKE THE SETUP
  94. ROUTINES */
  95. void set_map(char *name, char *name1, char *name2, struct Cell_head window,
  96. int top, int bot, int left, int right)
  97. {
  98. char cmd[30], cmd1[30], cmd2[30], **sel;
  99. int i, j, btn, d, class, top0, bot0, right0, left0, paint = 0, method;
  100. double msc[2], dtmp;
  101. /* VARIABLES
  102. IN:
  103. name = raster map name to be set up
  104. name1 = overlay vector map name
  105. name2 = overlay site map name
  106. */
  107. colors_old = (struct Colors *)G_malloc(1 * sizeof(struct Colors));
  108. Rast_init_colors(colors_old);
  109. Rast_read_colors(name, G_mapset(), colors_old);
  110. G_system("clear");
  111. paint_map(name, name1, name2);
  112. paint = 1;
  113. /* setup the screen to raster map
  114. coordinate conversion system */
  115. scr_cell(&window, top, bot, left, right, msc);
  116. top0 = top;
  117. bot0 = bot;
  118. left0 = left;
  119. right0 = right;
  120. /* display the menu and instructions */
  121. again:
  122. if (!paint) {
  123. if (G_yes
  124. ("\n Refresh the screen before choosing more setup? ", 1))
  125. paint_map(name, name1, name2);
  126. }
  127. else
  128. G_system("clear");
  129. fprintf(stderr, "\n\n CHOOSE THE SETUP OPTION:\n\n");
  130. fprintf(stderr, " Draw sampling regions 1\n");
  131. fprintf(stderr, " Setup a sampling frame 2\n");
  132. fprintf(stderr, " Setup sampling units 3\n");
  133. fprintf(stderr, " Setup a moving window 4\n");
  134. fprintf(stderr, " Setup group or class limits 5\n");
  135. fprintf(stderr, " Change the raster map color table 6\n");
  136. fprintf(stderr, " Exit and save setup 7\n");
  137. do {
  138. fprintf(stderr, "\n Which Number? ");
  139. dtmp = 5.0;
  140. numtrap(1, &dtmp);
  141. if ((method = fabs(dtmp)) > 7 || method < 1) {
  142. fprintf(stderr, "\n Choice must between 1-7; try again");
  143. }
  144. }
  145. while (method > 7 || method < 1);
  146. /* setup regions */
  147. if (method == 1)
  148. set_rgn(msc, name, name1, name2);
  149. /* setup the sampling frame */
  150. else if (method == 2) {
  151. top = top0;
  152. bot = bot0;
  153. right = right0;
  154. left = left0;
  155. set_frame(msc, &top, &bot, &left, &right);
  156. }
  157. /* setup sampling units */
  158. else if (method == 3) {
  159. sample(top, bot, left, right, name, name1, name2, msc);
  160. }
  161. /* setup the moving window */
  162. else if (method == 4) {
  163. mov_wind(top, bot, left, right, name, name1, name2, msc);
  164. }
  165. /* setup group/class limits */
  166. else if (method == 5) {
  167. /* setup the buffer to store the user's input */
  168. sel = (char **)G_malloc(10 * sizeof(char *));
  169. for (i = 0; i < 9; i++)
  170. sel[i] = (char *)G_calloc(2, sizeof(char));
  171. back:
  172. ask_group(sel);
  173. /* check for no input */
  174. if (sel[0][0] != 'x' && sel[1][0] != 'x' && sel[2][0] != 'x' &&
  175. sel[3][0] != 'x' && sel[4][0] != 'x' && sel[5][0] != 'x' &&
  176. sel[6][0] != 'x' && sel[7][0] != 'x' && sel[8][0] != 'x') {
  177. G_system("clear");
  178. fprintf(stderr,
  179. " Did you mean to not make any attribute group");
  180. if (!G_yes("\n or index class setup choices? ", 1))
  181. goto back;
  182. }
  183. /* if there is input, then invoke the
  184. group/class setup module and then free
  185. the memory allocated for selections */
  186. else {
  187. get_group_drv(sel);
  188. for (i = 0; i < 9; i++)
  189. G_free(sel[i]);
  190. G_free(sel);
  191. }
  192. }
  193. /* change color tables */
  194. else if (method == 6)
  195. change_color(name, name1, name2);
  196. /* reset the colortable and exit */
  197. else if (method == 7) {
  198. Rast_write_colors(name, G_mapset(), colors_old);
  199. Rast_free_colors(colors_old);
  200. /* R_close_driver(); */
  201. G_system("d.frame -e");
  202. exit(0);
  203. }
  204. paint = 0;
  205. goto again;
  206. return;
  207. }
  208. /* REDISPLAY THE RASTER MAP AND THE
  209. OVERLAYS */
  210. void paint_map(char *n1, char *n2, char *n3)
  211. {
  212. char *cmd;
  213. cmd = G_malloc(120);
  214. G_system("clear");
  215. sprintf(cmd, "d.rast %s", n1);
  216. G_system("d.erase");
  217. G_system(cmd);
  218. if (n2) {
  219. sprintf(cmd, "d.vect %s color=black", n2);
  220. G_system(cmd);
  221. }
  222. if (n3) {
  223. sprintf(cmd, "d.vect %s color=black", n3);
  224. G_system(cmd);
  225. }
  226. G_free(cmd);
  227. return;
  228. }
  229. /* SETUP REGIONS */
  230. static void set_rgn(double *msc, char *name, char *name1, char *name2)
  231. {
  232. char reg_name[20];
  233. int x0, y0, xp, yp, *x, *y, xstart, ystart, btn, d, method, meth;
  234. static int pts, rgn_cnt = 0;
  235. double dtmp, etmp;
  236. FILE *tmp;
  237. char *tempfile;
  238. /* get the name of the regions map */
  239. if (!G_ask_cell_new(" ENTER THE NEW REGION MAP NAME:", reg_name))
  240. return;
  241. /* allocate memory for storing the
  242. points along the boundary of each
  243. region */
  244. x = (int *)G_malloc(100 * sizeof(int));
  245. y = (int *)G_malloc(100 * sizeof(int));
  246. tempfile = G_tempfile();
  247. tmp = fopen(tempfile, "w");
  248. back2:
  249. G_system("clear");
  250. fprintf(stderr, "\n\n CHOOSE AN OPTION:\n\n");
  251. fprintf(stderr, " Draw a region 1\n");
  252. fprintf(stderr, " Quit drawing regions and return");
  253. fprintf(stderr, "\n to setup options menu 2\n");
  254. fprintf(stderr, " Change the color for drawing 3\n\n");
  255. do {
  256. fprintf(stderr, " Which Number? ");
  257. numtrap(1, &etmp);
  258. if ((meth = fabs(etmp)) > 3 || meth < 1) {
  259. fprintf(stderr, "\n Choice must between 1-3; try again");
  260. }
  261. }
  262. while (meth > 3 || meth < 1);
  263. if (meth == 2)
  264. return;
  265. if (meth == 3) {
  266. R_open_driver();
  267. change_draw();
  268. }
  269. if (meth == 1) {
  270. R_open_driver();
  271. rgn_cnt = 0;
  272. }
  273. /* ask the user to outline a region */
  274. back:
  275. G_system("clear");
  276. ppoint(NULL, 0, 0, -1);
  277. fprintf(stderr, "\n PLEASE OUTLINE REGION # %d\n", (++rgn_cnt));
  278. pbutton(0);
  279. pts = 0;
  280. x0 = 0;
  281. y0 = 0;
  282. /* get the points along the boundary
  283. of the region as they are drawn */
  284. do {
  285. btn = 0;
  286. R_get_location_with_line(x0, y0, &xp, &yp, &btn);
  287. if (btn == 1)
  288. ppoint(msc, xp, yp, 0);
  289. else if (btn == 2) {
  290. if (!pts) {
  291. pbutton(1);
  292. R_move_abs(xp, yp);
  293. xstart = xp;
  294. ystart = yp;
  295. }
  296. x[pts] = xp * msc[0];
  297. y[pts] = yp * msc[1];
  298. ppoint(msc, xp, yp, (++pts));
  299. x0 = xp;
  300. y0 = yp;
  301. R_cont_abs(x0, y0);
  302. }
  303. else if (btn == 3 && pts < 3) {
  304. fprintf(stderr,
  305. "\n\n Please digitize more than 2 boundary points\n\n");
  306. }
  307. }
  308. while (btn != 3 || pts < 3);
  309. R_cont_abs(xstart, ystart);
  310. R_close_driver();
  311. R_open_driver();
  312. x[pts] = x[0];
  313. y[pts] = y[0];
  314. pts++;
  315. /* redisplay the menu and find out what
  316. to do next */
  317. back1:
  318. G_system("clear");
  319. fprintf(stderr, "\n\n CHOOSE AN OPTION:\n\n");
  320. fprintf(stderr,
  321. " Draw another region 1\n");
  322. fprintf(stderr,
  323. " Start over drawing regions 2\n");
  324. fprintf(stderr,
  325. " Quit drawing and save the region map 3\n");
  326. fprintf(stderr,
  327. " Quit drawing and don't save the region map 4\n");
  328. fprintf(stderr,
  329. " Change the color for drawing 5\n\n");
  330. do {
  331. fprintf(stderr,
  332. " Which Number? ");
  333. numtrap(1, &dtmp);
  334. if ((method = fabs(dtmp)) > 5 || method < 1) {
  335. fprintf(stderr, "\n Choice must between 1-5; try again");
  336. }
  337. }
  338. while (method > 5 || method < 1);
  339. /* save the region and draw another */
  340. if (method == 1) {
  341. save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 1);
  342. goto back;
  343. }
  344. /* start over */
  345. else if (method == 2) {
  346. fclose(tmp);
  347. if (!(tmp = fopen(tempfile, "w")))
  348. G_fatal_error
  349. ("Can't open temporary file for storing region info\n");
  350. rgn_cnt = 0;
  351. R_close_driver();
  352. paint_map(name, name1, name2);
  353. goto back2;
  354. }
  355. /* save the region and exit */
  356. else if (method == 3)
  357. save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 2);
  358. /* change the color for drawing */
  359. else if (method == 5) {
  360. change_draw();
  361. goto back1;
  362. }
  363. R_close_driver();
  364. G_free(x);
  365. G_free(y);
  366. unlink(tempfile);
  367. return;
  368. }
  369. /* SETUP THE SAMPLING FRAME */
  370. static void set_frame(double *msc, int *t, int *b, int *l, int *r)
  371. {
  372. int t0, b0, l0, r0, btn;
  373. /* record the initial boundaries of the map */
  374. t0 = *t;
  375. b0 = *b;
  376. l0 = *l;
  377. r0 = *r;
  378. /* if the total area to be sampled will be the
  379. whole map */
  380. G_system("clear");
  381. if (G_yes
  382. ("\n Will the sampling frame (total area within which sampling\n units are distributed) be the whole map? ",
  383. 1)) {
  384. R_open_driver();
  385. R_standard_color(D_translate_color("grey"));
  386. draw_box(*l, *t, *r, *b, 1);
  387. R_close_driver();
  388. fprintf(stderr, "\n Sampling frame set to whole map");
  389. }
  390. /* if the total area to be sampled is not the
  391. whole map, then have the user draw the
  392. area */
  393. else {
  394. back:
  395. G_system("clear");
  396. fprintf(stderr, " \n OUTLINE SAMPLING FRAME:\n");
  397. R_open_driver();
  398. fprintf(stderr,
  399. "\n Please move cursor to the UPPER-LEFT corner of\n");
  400. fprintf(stderr,
  401. " the sampling frame and click any mouse button\n");
  402. R_get_location_with_line(0, 0, l, t, &btn);
  403. fprintf(stderr,
  404. "\n Please move cursor to the LOWER-RIGHT corner of\n");
  405. fprintf(stderr,
  406. " the sampling frame and click any mouse button again\n");
  407. back2:
  408. R_get_location_with_box(*l, *t, r, b, &btn);
  409. /* check that sampling frame is in map */
  410. if (*l < l0 || *r > r0 || *t < t0 || *b > b0) {
  411. fprintf(stderr,
  412. "\n The cursor is outside of the map, try again\n");
  413. goto back;
  414. }
  415. /* check that cursor is below & to right */
  416. if (*r <= *l || *b <= *t) {
  417. fprintf(stderr,
  418. "\n Please put the lower right corner below and to the");
  419. fprintf(stderr, "\n right of the upper left corner\n");
  420. goto back2;
  421. }
  422. R_standard_color(D_translate_color("grey"));
  423. *l = (int)((double)((int)(*l * msc[0] + 0.5)) / msc[0]);
  424. *r = (int)((double)((int)(*r * msc[0] + 0.5)) / msc[0]);
  425. *t = (int)((double)((int)(*t * msc[1] + 0.5)) / msc[1]);
  426. *b = (int)((double)((int)(*b * msc[1] + 0.5)) / msc[1]);
  427. draw_box(*l, *t, *r, *b, 1);
  428. R_close_driver();
  429. fprintf(stderr,
  430. "\n Sampling frame is set to the area you just drew");
  431. }
  432. return;
  433. }
  434. /* SHOW THE CURSOR COORDINATES TO
  435. THE USER */
  436. static void ppoint(double *m, int x, int y, int num)
  437. {
  438. register int i;
  439. if (num < 0) {
  440. for (i = 0; i < 80; i++)
  441. fprintf(stderr, " ");
  442. }
  443. else {
  444. if (num > 0) {
  445. fprintf(stderr, " Point %d is at Row %5d and Col %5d",
  446. num, (int)(y * m[1]), (int)(x * m[0]));
  447. }
  448. else if (num == 0) {
  449. fprintf(stderr, " Point is at Row %5d and Col %5d",
  450. (int)(y * m[1]), (int)(x * m[0]));
  451. }
  452. for (i = 0; i < 80; i++) {
  453. fprintf(stderr, "\b");
  454. }
  455. }
  456. return;
  457. }
  458. /* PRINT THE INSTRUCTIONS FOR USING THE
  459. MOUSE BUTTONS */
  460. static void pbutton(int opt)
  461. {
  462. static char *str[2] = { "start", "next" };
  463. fprintf(stderr, "\n Use the mouse to outline the region\n");
  464. fprintf(stderr,
  465. " Left button: What are row & column coordinates at this point?\n");
  466. fprintf(stderr, " Middle button: Mark %s point\n", str[opt]);
  467. fprintf(stderr,
  468. " Right button: Finish region-connect to first point\n\n");
  469. return;
  470. }
  471. /* SAVE THE REGION */
  472. static void save_rgn(char *name, char *tempfile, FILE * tmp, int *x, int *y,
  473. int pts, int class, int opt)
  474. {
  475. char *cmd;
  476. struct Cell_head wind;
  477. struct Colors colors;
  478. static double rx, ry, ofy, ofx;
  479. register int i;
  480. /* setup the temporary file to save
  481. the region boundary pts */
  482. if (class == 1) {
  483. G_get_set_window(&wind);
  484. print_hd(tmp, &wind);
  485. ofy = wind.north;
  486. ofx = wind.west;
  487. ry = (wind.north - wind.south) / wind.rows;
  488. rx = (wind.east - wind.west) / wind.cols;
  489. }
  490. fprintf(tmp, "A %10.2f %10.2f %10d\n", (ofy - *y * ry), (*x * rx + ofx),
  491. class);
  492. for (i = 0; i < pts; i++)
  493. fprintf(tmp, " %10.2f %10.2f\n", (ofy - *(y + i) * ry),
  494. (*(x + i) * rx + ofx));
  495. /* if the choice was made to draw more
  496. regions, then return */
  497. if (opt != 2)
  498. return;
  499. fprintf(tmp, "E\n");
  500. fclose(tmp);
  501. G_get_set_window(&wind);
  502. Rast_put_cellhd(name, &wind);
  503. /* make a GRASS raster map from the
  504. region boundary pts, using the
  505. poly_to_bmif and bmif_to_cell
  506. programs */
  507. cmd = G_malloc(200);
  508. sprintf(cmd,
  509. "%s/etc/poly_to_bmif < %s | sort -t: +0n -1 | %s/etc/bmif_to_cell %s",
  510. G_gisbase(), tempfile, G_gisbase(), name);
  511. fprintf(stderr, " Generating '%s' file... %20c\n\n", name, ' ');
  512. G_system(cmd);
  513. G_free(cmd);
  514. /* set the color table for the regions
  515. file to color wave */
  516. Rast_init_colors(&colors);
  517. Rast_make_wave_colors(&colors, 1, class);
  518. Rast_write_colors(name, G_mapset(), &colors);
  519. /* overlay the region file on the
  520. screen */
  521. if (!(cmd = G_malloc(20)))
  522. G_fatal_error("Can't allocate enough memory\n");
  523. R_close_driver();
  524. sprintf(cmd, "d.rast -o %s", name);
  525. G_system(cmd);
  526. G_free(cmd);
  527. G_sleep(4); /* hold the screen for 4 seconds */
  528. R_open_driver();
  529. return;
  530. }
  531. /* SETUP THE HEADER FOR THE REGION
  532. FILE */
  533. static void print_hd(FILE * mapfile, struct Cell_head *universe)
  534. {
  535. fprintf(mapfile, "TITLE:\n");
  536. fprintf(mapfile, " User created region.\n");
  537. fprintf(mapfile, "ENDT\n");
  538. fprintf(mapfile, "SIZE %10d %10d\n", universe->rows, universe->cols);
  539. fprintf(mapfile, "BOUND %10.2f %10.2f %10.2f %10.2f\n",
  540. universe->ns_res, universe->ew_res,
  541. universe->south, universe->west);
  542. fprintf(mapfile, "VERTI\n");
  543. return;
  544. }
  545. /* SETUP THE CONVERSION BETWEEN SCREEN
  546. AND RASTER COORDINATES */
  547. static void scr_cell(struct Cell_head *wind, int top, int bot, int left,
  548. int right, double *m)
  549. {
  550. m[0] = (double)wind->cols / (right - left);
  551. m[1] = (double)wind->rows / (bot - top);
  552. return;
  553. }
  554. /* CHANGE THE COLORTABLE OF THE RASTER
  555. MAP */
  556. static void change_color(char *name, char *name1, char *name2)
  557. {
  558. struct Colors colors;
  559. struct Range range;
  560. int d, min, max;
  561. double etmp;
  562. Rast_read_range(name, G_mapset(), &range);
  563. Rast_get_range_min_max(&range, &min, &max);
  564. G_system("clear");
  565. again:
  566. fprintf(stderr, "\n\n SELECT NEW COLOR TABLE FOR RASTER MAP:\n\n");
  567. fprintf(stderr, " Aspect 1\n");
  568. fprintf(stderr, " Color ramp 2\n");
  569. fprintf(stderr, " Color wave 3\n");
  570. fprintf(stderr, " Linear grey scale 4\n");
  571. fprintf(stderr, " Rainbow colors 5\n");
  572. fprintf(stderr, " Random colors 6\n");
  573. fprintf(stderr, " Red-Yellow-Green Sequence 7\n");
  574. fprintf(stderr, " Green-Yellow-Red Sequence 8\n");
  575. fprintf(stderr, " Set original color table 9\n");
  576. fprintf(stderr, " Return to setup options menu 10\n");
  577. do {
  578. fprintf(stderr, "\n Which Number? ");
  579. numtrap(1, &etmp);
  580. if ((d = fabs(etmp)) > 10 || d < 1) {
  581. fprintf(stderr, "\n Choice must between 1-10; try again");
  582. }
  583. }
  584. while (d > 10 || d < 1);
  585. if (d == 1) {
  586. Rast_make_aspect_colors(&colors, min, max);
  587. Rast_write_colors(name, G_mapset(), &colors);
  588. }
  589. else if (d == 2) {
  590. Rast_make_ramp_colors(&colors, min, max);
  591. Rast_write_colors(name, G_mapset(), &colors);
  592. }
  593. else if (d == 3) {
  594. Rast_make_wave_colors(&colors, min, max);
  595. Rast_write_colors(name, G_mapset(), &colors);
  596. }
  597. else if (d == 4) {
  598. Rast_make_grey_scale_colors(&colors, min, max);
  599. Rast_write_colors(name, G_mapset(), &colors);
  600. }
  601. else if (d == 5) {
  602. Rast_make_rainbow_colors(&colors, min, max);
  603. Rast_write_colors(name, G_mapset(), &colors);
  604. }
  605. else if (d == 6) {
  606. Rast_make_random_colors(&colors, min, max);
  607. Rast_write_colors(name, G_mapset(), &colors);
  608. }
  609. else if (d == 7) {
  610. Rast_make_ryg_colors(&colors, min, max);
  611. Rast_write_colors(name, G_mapset(), &colors);
  612. }
  613. else if (d == 8) {
  614. Rast_make_gyr_colors(&colors, min, max);
  615. Rast_write_colors(name, G_mapset(), &colors);
  616. }
  617. else if (d == 9) {
  618. Rast_write_colors(name, G_mapset(), colors_old);
  619. }
  620. else if (d == 10) {
  621. return;
  622. }
  623. paint_map(name, name1, name2);
  624. fprintf(stderr, "\n CHOOSE NEXT OPTION:\n\n");
  625. fprintf(stderr, " Don't save color table just chosen:");
  626. fprintf(stderr, "\n Return to color table menu 1\n");
  627. fprintf(stderr, " Return to setup option menu 2\n");
  628. fprintf(stderr, " Exit r.le.setup 3\n\n");
  629. fprintf(stderr, " Do save color table just chosen:");
  630. fprintf(stderr, "\n Return to setup options menu 4\n");
  631. fprintf(stderr, " Exit r.le.setup 5\n");
  632. do {
  633. fprintf(stderr,
  634. "\n Which Number? ");
  635. numtrap(1, &etmp);
  636. if ((d = fabs(etmp)) > 5 || d < 1) {
  637. fprintf(stderr, "\n Choice must between 1-5; try again");
  638. }
  639. }
  640. while (d > 5 || d < 1);
  641. if (d == 1)
  642. goto again;
  643. else if (d == 2)
  644. return;
  645. else if (d == 3) {
  646. Rast_write_colors(name, G_mapset(), colors_old);
  647. Rast_free_colors(colors_old);
  648. }
  649. else if (d == 4)
  650. *colors_old = colors;
  651. if (d == 3 || d == 5) {
  652. G_system("d.frame -e");
  653. exit(0);
  654. }
  655. return;
  656. }