write2d.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*-
  2. * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
  3. * University of Illinois
  4. * US Army Construction Engineering Research Lab
  5. * Copyright 1993, H. Mitasova (University of Illinois),
  6. * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)
  7. *
  8. * modified by McCauley in August 1995
  9. * modified by Mitasova in August 1995
  10. *
  11. */
  12. #include <grass/config.h>
  13. #include <stdio.h>
  14. #include <math.h>
  15. #include <unistd.h>
  16. #include <grass/gis.h>
  17. #include <grass/glocale.h>
  18. #include <grass/interpf.h>
  19. /*
  20. * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
  21. * and offset) in corresponding temp file
  22. */
  23. int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, off_t offset2) /* begin. and end. column, offset */
  24. {
  25. int j;
  26. static FCELL *array_cell = NULL;
  27. if (!array_cell)
  28. array_cell = G_malloc(sizeof(FCELL) * params->nsizc + 1);
  29. if (params->Tmp_fd_z != NULL) {
  30. for (j = ngstc; j <= nszc; j++)
  31. array_cell[j - 1] = (FCELL) params->az[j];
  32. G_fseek(params->Tmp_fd_z, offset2, SEEK_SET);
  33. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  34. params->Tmp_fd_z))
  35. G_fatal_error(_("Cannot write files"));
  36. }
  37. if (params->Tmp_fd_dx != NULL) {
  38. for (j = ngstc; j <= nszc; j++)
  39. if (!params->deriv)
  40. array_cell[j - 1] = (FCELL) params->adx[j];
  41. else
  42. array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1);
  43. G_fseek(params->Tmp_fd_dx, offset2, SEEK_SET);
  44. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  45. params->Tmp_fd_dx))
  46. G_fatal_error(_("Cannot write files"));
  47. }
  48. if (params->Tmp_fd_dy != NULL) {
  49. for (j = ngstc; j <= nszc; j++) {
  50. if (!params->deriv) {
  51. if (params->ady[j] > 0. && params->ady[j] < 0.5)
  52. params->ady[j] = 360.;
  53. array_cell[j - 1] = (FCELL) params->ady[j];
  54. }
  55. else
  56. array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1);
  57. }
  58. G_fseek(params->Tmp_fd_dy, offset2, SEEK_SET);
  59. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  60. params->Tmp_fd_dy))
  61. G_fatal_error(_("Cannot write files"));
  62. }
  63. if (params->Tmp_fd_xx != NULL) {
  64. for (j = ngstc; j <= nszc; j++) {
  65. array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1);
  66. }
  67. G_fseek(params->Tmp_fd_xx, offset2, SEEK_SET);
  68. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  69. params->Tmp_fd_xx))
  70. G_fatal_error(_("Cannot write files"));
  71. }
  72. if (params->Tmp_fd_yy != NULL) {
  73. for (j = ngstc; j <= nszc; j++)
  74. array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2);
  75. G_fseek(params->Tmp_fd_yy, offset2, SEEK_SET);
  76. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  77. params->Tmp_fd_yy))
  78. G_fatal_error(_("Cannot write files"));
  79. }
  80. if (params->Tmp_fd_xy != NULL) {
  81. for (j = ngstc; j <= nszc; j++)
  82. array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3);
  83. G_fseek(params->Tmp_fd_xy, offset2, SEEK_SET);
  84. if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
  85. params->Tmp_fd_xy))
  86. G_fatal_error(_("Cannot write files"));
  87. }
  88. return 1;
  89. }