calcsurf.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* calcsurf.c */
  2. #include <stdlib.h>
  3. #include <grass/gis.h>
  4. #include <grass/raster.h>
  5. #include "ransurf.h"
  6. #include "local_proto.h"
  7. void CalcSurface(void)
  8. {
  9. int Count, OutRows, OutCols;
  10. int Row, Row2, Col, Col2, RanRows, RanCols;
  11. int owC, oeC, onR, osR, wC, eC, nR, sR;
  12. double **Randoms;
  13. G_debug(2, "CalcSurface()");
  14. OutRows = BigF.RowPlus;
  15. OutCols = BigF.ColPlus;
  16. RanRows = (2 * OutRows + Rs);
  17. RanCols = (2 * OutCols + Cs);
  18. owC = osR = 0;
  19. wC = OutCols;
  20. sR = OutRows;
  21. oeC = RanCols - 1;
  22. onR = RanRows - 1;
  23. if (OutCols > 0)
  24. eC = RanCols - (OutCols + 1);
  25. else
  26. eC = oeC;
  27. if (OutRows > 0)
  28. nR = RanRows - (OutRows + 1);
  29. else
  30. nR = onR;
  31. Randoms = (double **)G_malloc(sizeof(double *) * RanRows);
  32. for (Row = 0; Row < RanRows; Row++)
  33. Randoms[Row] = (double *)G_malloc(RanCols * sizeof(double));
  34. /* OLD
  35. for( Row = OutRows; Row < RanRows; Row++) {
  36. for( Col = OutCols; Col < OutCols + Cs; Col++) {
  37. Randoms[ Row][ Col] = GasDev();
  38. }
  39. }
  40. for( Row = OutRows - 1; Row >= 0; Row--) {
  41. for( Col = OutCols; Col < OutCols + Cs; Col++) {
  42. Randoms[ Row][ Col] = GasDev();
  43. }
  44. }
  45. for( Row = 0; Row < RanRows; Row++) {
  46. for( Col = 0; Col < OutCols; Col++)
  47. Randoms[ Row][ Col] = GasDev();
  48. for( Col = OutCols + Cs; Col < RanCols; Col++)
  49. Randoms[ Row][ Col] = GasDev();
  50. }
  51. end OLD */
  52. for (Row = sR; Row <= nR; Row++) {
  53. for (Col = wC; Col <= eC; Col++) {
  54. Randoms[Row][Col] = GasDev();
  55. }
  56. }
  57. Col = wC - 1;
  58. Col2 = eC + 1;
  59. while (Col >= 0) {
  60. for (Row = sR; Row <= nR; Row++) {
  61. Randoms[Row][Col] = GasDev();
  62. Randoms[Row][Col2] = GasDev();
  63. }
  64. Col--;
  65. Col2++;
  66. }
  67. Row = sR - 1;
  68. Row2 = nR + 1;
  69. while (Row >= 0) {
  70. for (Col = 0; Col < RanCols; Col++) {
  71. Randoms[Row][Col] = GasDev();
  72. Randoms[Row2][Col] = GasDev();
  73. }
  74. Row--;
  75. Row2++;
  76. }
  77. Count = 0;
  78. if (FDM == -1) {
  79. for (Row = 0; Row < Rs; Row++) {
  80. if (ODD(Row)) {
  81. for (Col = Cs - 1; Col >= 0; Col--) {
  82. G_percent(Count++, MapCount, 1);
  83. Surface[Row][Col] =
  84. MakePP(Row, Col, OutRows, OutCols, Randoms, BigF);
  85. }
  86. }
  87. else {
  88. for (Col = 0; Col < Cs; Col++) {
  89. G_percent(Count++, MapCount, 1);
  90. Surface[Row][Col] =
  91. MakePP(Row, Col, OutRows, OutCols, Randoms, BigF);
  92. }
  93. }
  94. }
  95. G_percent(1, 1, 1);
  96. }
  97. else {
  98. for (Row = 0; Row < Rs; Row++) {
  99. Rast_get_c_row_nomask(FDM, CellBuffer, Row);
  100. if (ODD(Row)) {
  101. for (Col = Cs - 1; Col >= 0; Col--) {
  102. if (CellBuffer[Col] == 0)
  103. Surface[Row][Col] = 0.0;
  104. else {
  105. G_percent(Count++, MapCount, 1);
  106. Surface[Row][Col] =
  107. MakePP(Row, Col, OutRows, OutCols, Randoms, BigF);
  108. }
  109. }
  110. }
  111. else {
  112. for (Col = 0; Col < Cs; Col++) {
  113. if (CellBuffer[Col] == 0)
  114. Surface[Row][Col] = 0.0;
  115. else {
  116. G_percent(Count++, MapCount, 1);
  117. Surface[Row][Col] =
  118. MakePP(Row, Col, OutRows, OutCols, Randoms, BigF);
  119. }
  120. }
  121. }
  122. }
  123. G_percent(1, 1, 1);
  124. }
  125. G_free(Randoms);
  126. }