exec.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* CMD mode from Bob Covill 2001
  2. *
  3. * small fixes: MN
  4. *
  5. * Bug left: extension overwrites input name 1/2002
  6. */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <fcntl.h>
  13. #include <time.h>
  14. #include <unistd.h>
  15. #include <math.h>
  16. #include <grass/raster.h>
  17. #include <grass/glocale.h>
  18. #include "global.h"
  19. int exec_rectify(int order, char *extension, char *interp_method)
  20. /* ADDED WITH CRS MODIFICATIONS */
  21. {
  22. char *name;
  23. char *mapset;
  24. char *result;
  25. char *type = "raster";
  26. int n;
  27. struct Colors colr;
  28. struct Categories cats;
  29. struct History hist;
  30. int colr_ok, cats_ok;
  31. long start_time, rectify_time;
  32. Rast_set_output_window(&target_window);
  33. G_message("-----------------------------------------------");
  34. /* rectify each file */
  35. for (n = 0; n < ref.nfiles; n++) {
  36. if (ref_list[n]) {
  37. name = ref.file[n].name;
  38. mapset = ref.file[n].mapset;
  39. /* generate out name, add extension to output */
  40. result =
  41. G_malloc(strlen(ref.file[n].name) + strlen(extension) + 1);
  42. strcpy(result, ref.file[n].name);
  43. strcat(result, extension);
  44. select_current_env();
  45. cats_ok = Rast_read_cats(name, mapset, &cats) >= 0;
  46. colr_ok = Rast_read_colors(name, mapset, &colr) > 0;
  47. /* Initialze History */
  48. if (Rast_read_history(name, mapset, &hist) < 0)
  49. Rast_short_history(result, type, &hist);
  50. time(&start_time);
  51. if (rectify(name, mapset, result, order, interp_method)) {
  52. select_target_env();
  53. if (cats_ok) {
  54. Rast_write_cats(result, &cats);
  55. Rast_free_cats(&cats);
  56. }
  57. if (colr_ok) {
  58. Rast_write_colors(result, G_mapset(), &colr);
  59. Rast_free_colors(&colr);
  60. }
  61. /* Write out History */
  62. Rast_command_history(&hist);
  63. Rast_write_history(result, &hist);
  64. select_current_env();
  65. time(&rectify_time);
  66. report(rectify_time - start_time, 1);
  67. }
  68. else
  69. report((long)0, 0);
  70. G_free(result);
  71. }
  72. }
  73. return 0;
  74. }