write2d.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*!
  2. * \file secpar2d.c
  3. *
  4. * \author H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 (original authors)
  5. * \author modified by McCauley in August 1995
  6. * \author modified by Mitasova in August 1995
  7. * \author H. Mitasova (University of Illinois)
  8. * \author I. Kosinovsky, (USA-CERL)
  9. * \author D.Gerdes (USA-CERL)
  10. *
  11. * \copyright
  12. * (C) 1993-1995 by Helena Mitasova and the GRASS Development Team
  13. *
  14. * \copyright
  15. * This program is free software under the
  16. * GNU General Public License (>=v2).
  17. * Read the file COPYING that comes with GRASS for details.
  18. */
  19. #include <grass/config.h>
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include <unistd.h>
  23. #include <grass/gis.h>
  24. #include <grass/glocale.h>
  25. #include <grass/interpf.h>
  26. /* parameter descriptions takes from a strange comment */
  27. /*!
  28. * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
  29. * and offset) in corresponding temp file
  30. */
  31. int IL_write_temp_2d(struct interp_params *params,
  32. int ngstc, /*!< begin. column */
  33. int nszc, /*!< end. column */
  34. off_t offset2 /*!< offset */
  35. )
  36. {
  37. int j;
  38. static FCELL *array_cell = NULL;
  39. if (!array_cell)
  40. array_cell = G_malloc(sizeof(FCELL) * params->nsizc + 1);
  41. if (params->Tmp_fd_z != NULL) {
  42. for (j = ngstc; j <= nszc; j++)
  43. array_cell[j - 1] = (FCELL) params->az[j];
  44. G_fseek(params->Tmp_fd_z, offset2, SEEK_SET);
  45. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  46. params->Tmp_fd_z))
  47. G_fatal_error(_("Cannot write files"));
  48. }
  49. if (params->Tmp_fd_dx != NULL) {
  50. for (j = ngstc; j <= nszc; j++)
  51. if (!params->deriv)
  52. array_cell[j - 1] = (FCELL) params->adx[j];
  53. else
  54. array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1);
  55. G_fseek(params->Tmp_fd_dx, offset2, SEEK_SET);
  56. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  57. params->Tmp_fd_dx))
  58. G_fatal_error(_("Cannot write files"));
  59. }
  60. if (params->Tmp_fd_dy != NULL) {
  61. for (j = ngstc; j <= nszc; j++) {
  62. if (!params->deriv) {
  63. if (params->ady[j] > 0. && params->ady[j] < 0.5)
  64. params->ady[j] = 360.;
  65. array_cell[j - 1] = (FCELL) params->ady[j];
  66. }
  67. else
  68. array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1);
  69. }
  70. G_fseek(params->Tmp_fd_dy, offset2, SEEK_SET);
  71. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  72. params->Tmp_fd_dy))
  73. G_fatal_error(_("Cannot write files"));
  74. }
  75. if (params->Tmp_fd_xx != NULL) {
  76. for (j = ngstc; j <= nszc; j++) {
  77. array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1);
  78. }
  79. G_fseek(params->Tmp_fd_xx, offset2, SEEK_SET);
  80. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  81. params->Tmp_fd_xx))
  82. G_fatal_error(_("Cannot write files"));
  83. }
  84. if (params->Tmp_fd_yy != NULL) {
  85. for (j = ngstc; j <= nszc; j++)
  86. array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2);
  87. G_fseek(params->Tmp_fd_yy, offset2, SEEK_SET);
  88. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  89. params->Tmp_fd_yy))
  90. G_fatal_error(_("Cannot write files"));
  91. }
  92. if (params->Tmp_fd_xy != NULL) {
  93. for (j = ngstc; j <= nszc; j++)
  94. array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3);
  95. G_fseek(params->Tmp_fd_xy, offset2, SEEK_SET);
  96. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  97. params->Tmp_fd_xy))
  98. G_fatal_error(_("Cannot write files"));
  99. }
  100. return 1;
  101. }