main.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. ************************************************************
  3. * MODULE: r.le.patch/main.c *
  4. * Version 5.0 Nov. 1, 2001 *
  5. * *
  6. * AUTHOR: W.L. Baker, University of Wyoming *
  7. * BAKERWL@UWYO.EDU *
  8. * *
  9. * PURPOSE: To analyze attributes of patches in a landscape *
  10. * main.c calls user_input.c to read the user's *
  11. * requests from the screen, then displays those *
  12. * choices on screen and calls patch_fore *
  13. * *
  14. * COPYRIGHT: (C) 2001 by W.L. Baker *
  15. * *
  16. * This program is free software under the GNU General *
  17. * Public License(>=v2). Read the file COPYING that comes *
  18. * with GRASS for details *
  19. * *
  20. ************************************************************/
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <grass/gis.h>
  25. #include <grass/glocale.h>
  26. #include <grass/config.h>
  27. #include "patch.h"
  28. jmp_buf jmp;
  29. struct CHOICE *choice;
  30. int main(int argc, char **argv)
  31. {
  32. struct GModule *module;
  33. /* initialize the GRASS GIS system */
  34. G_gisinit(argv[0]);
  35. /* allocate space for the choice data structure */
  36. choice = (struct CHOICE *)G_calloc(1, sizeof(struct CHOICE));
  37. module = G_define_module();
  38. G_add_keyword(_("raster"));
  39. module->description =
  40. _("Calculates attribute, patch size, core (interior) size, shape, "
  41. "fractal dimension, and perimeter measures for sets of patches "
  42. "in a landscape.");
  43. /* call user_input to read in the parameters */
  44. user_input(argc, argv);
  45. /* display the parameter choices */
  46. fprintf(stderr, "\nPARAMETER CHOICES:\n");
  47. fprintf(stderr, "\tMAP:\t %s\n", choice->fn);
  48. if (choice->wrum == 'r')
  49. fprintf(stderr, "\tREGION:\t %s\n", choice->reg);
  50. fprintf(stderr, "\tSAMPLE:");
  51. if (choice->wrum == 'w')
  52. fprintf(stderr, "\t whole map ");
  53. if (choice->wrum == 'm')
  54. fprintf(stderr, "\t moving window");
  55. if (choice->wrum == 'u')
  56. fprintf(stderr, "\t units ");
  57. if (choice->wrum == 'r')
  58. fprintf(stderr, "\t regions ");
  59. fprintf(stderr, "\tTRACING:");
  60. if (choice->trace)
  61. fprintf(stderr, " 8 neighbor\n");
  62. else
  63. fprintf(stderr, " 4 neighbor\n");
  64. if (choice->coremap || choice->patchmap || choice->units)
  65. fprintf(stderr, "\tOUTPUT MAPS:\n");
  66. if (choice->coremap)
  67. fprintf(stderr, "\t\t interior\n");
  68. if (choice->patchmap)
  69. fprintf(stderr, "\t\t num\n");
  70. if (choice->units)
  71. fprintf(stderr, "\t\t units_x\n");
  72. if (choice->att[0])
  73. fprintf(stderr, "\tATTRIBUTE MEASURES:\n");
  74. if (choice->att[1])
  75. fprintf(stderr, "\t\t mean pixel attribute\n");
  76. if (choice->att[2])
  77. fprintf(stderr, "\t\t st. dev. pixel attribute\n");
  78. if (choice->att[3])
  79. fprintf(stderr, "\t\t mean patch attribute\n");
  80. if (choice->att[4])
  81. fprintf(stderr, "\t\t st. dev. patch attribute\n");
  82. if (choice->att[5])
  83. fprintf(stderr, "\t\t cover by gp\n");
  84. if (choice->att[6])
  85. fprintf(stderr, "\t\t density by gp\n");
  86. if (choice->att[7])
  87. fprintf(stderr, "\t\t total density\n");
  88. if (choice->att[8])
  89. fprintf(stderr, "\t\t eff. mesh no.\n");
  90. if (choice->size[0])
  91. fprintf(stderr, "\tSIZE MEASURES:\n");
  92. if (choice->size[1])
  93. fprintf(stderr, "\t\t mean patch size\n");
  94. if (choice->size[2])
  95. fprintf(stderr, "\t\t st. dev. patch size\n");
  96. if (choice->size[3])
  97. fprintf(stderr, "\t\t mean patch size by gp\n");
  98. if (choice->size[4])
  99. fprintf(stderr, "\t\t st. dev. patch size by gp\n");
  100. if (choice->size[5])
  101. fprintf(stderr, "\t\t no. by size class\n");
  102. if (choice->size[6])
  103. fprintf(stderr, "\t\t no. by size class by gp\n");
  104. if (choice->size[7])
  105. fprintf(stderr, "\t\t eff. mesh size\n");
  106. if (choice->size[8])
  107. fprintf(stderr, "\t\t deg. landsc. division\n");
  108. if (choice->core[0])
  109. fprintf(stderr, "\tCORE MEASURES:\n");
  110. if (choice->core[1])
  111. fprintf(stderr, "\t\t mean core size\n");
  112. if (choice->core[2])
  113. fprintf(stderr, "\t\t st. dev. core size\n");
  114. if (choice->core[3])
  115. fprintf(stderr, "\t\t mean edge size\n");
  116. if (choice->core[4])
  117. fprintf(stderr, "\t\t st. dev. edge size\n");
  118. if (choice->core[5])
  119. fprintf(stderr, "\t\t mean core size by gp\n");
  120. if (choice->core[6])
  121. fprintf(stderr, "\t\t st. dev. core size by gp\n");
  122. if (choice->core[7])
  123. fprintf(stderr, "\t\t mean edge size by gp \n");
  124. if (choice->core[8])
  125. fprintf(stderr, "\t\t st. dev. edge size by gp\n");
  126. if (choice->core[9])
  127. fprintf(stderr, "\t\t no. by size class \n");
  128. if (choice->core[10])
  129. fprintf(stderr, "\t\t no. by size class by gp\n");
  130. if (choice->shape[0])
  131. fprintf(stderr, "\tSHAPE MEASURES:\n");
  132. if (choice->shape[1])
  133. fprintf(stderr, "\t\t mean patch shape\n");
  134. if (choice->shape[2])
  135. fprintf(stderr, "\t\t st. dev. patch shape\n");
  136. if (choice->shape[3])
  137. fprintf(stderr, "\t\t mean patch shape by gp\n");
  138. if (choice->shape[4])
  139. fprintf(stderr, "\t\t st. dev. patch shape by gp\n");
  140. if (choice->shape[5])
  141. fprintf(stderr, "\t\t no. by shape class\n");
  142. if (choice->shape[6])
  143. fprintf(stderr, "\t\t no. by shape class by gp\n");
  144. if (choice->boundary[0])
  145. fprintf(stderr, "\tBOUNDARY COMPLEXITY MEASURES:\n");
  146. if (choice->boundary[1])
  147. fprintf(stderr, "\t\t mean twist number\n");
  148. if (choice->boundary[2])
  149. fprintf(stderr, "\t\t st. dev. twist number\n");
  150. if (choice->boundary[3])
  151. fprintf(stderr, "\t\t mean omega index\n");
  152. if (choice->boundary[4])
  153. fprintf(stderr, "\t\t st. dev. omega index\n");
  154. if (choice->perim[0])
  155. fprintf(stderr, "\tPERIMETER MEASURES:\n");
  156. if (choice->perim[1])
  157. fprintf(stderr, "\t\t sum of perims\n");
  158. if (choice->perim[2])
  159. fprintf(stderr, "\t\t mean perim.\n");
  160. if (choice->perim[3])
  161. fprintf(stderr, "\t\t st. dev. perim.\n");
  162. if (choice->perim[4])
  163. fprintf(stderr, "\t\t sum of perims. by gp\n");
  164. if (choice->perim[5])
  165. fprintf(stderr, "\t\t mean perim. by gp\n");
  166. if (choice->perim[6])
  167. fprintf(stderr, "\t\t st. dev. perim. by gp\n");
  168. /* if not moving window, setup the
  169. r.le.out subdirectory */
  170. if (choice->wrum != 'm')
  171. G_mkdir("r.le.out");
  172. patch_fore();
  173. G_free(choice);
  174. return (EXIT_SUCCESS);
  175. }