GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
write2d.c
Go to the documentation of this file.
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 
20 
21 #include <grass/config.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <unistd.h>
25 
26 #include <grass/gis.h>
27 #include <grass/glocale.h>
28 #include <grass/interpf.h>
29 
30 
31 /* parameter descriptions takes from a strange comment */
32 /*!
33  * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
34  * and offset) in corresponding temp file
35  */
36 int IL_write_temp_2d(struct interp_params *params,
37  int ngstc, /*!< begin. column */
38  int nszc, /*!< end. column */
39  off_t offset2 /*!< offset */
40  )
41 {
42  int j;
43  static FCELL *array_cell = NULL;
44 
45  if (!array_cell)
46  array_cell = G_malloc(sizeof(FCELL) * params->nsizc + 1);
47  if (params->Tmp_fd_z != NULL) {
48  for (j = ngstc; j <= nszc; j++)
49  array_cell[j - 1] = (FCELL) params->az[j];
50  G_fseek(params->Tmp_fd_z, offset2, SEEK_SET);
51  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
52  params->Tmp_fd_z))
53  G_fatal_error(_("Cannot write files"));
54  }
55  if (params->Tmp_fd_dx != NULL) {
56  for (j = ngstc; j <= nszc; j++)
57  if (!params->deriv)
58  array_cell[j - 1] = (FCELL) params->adx[j];
59  else
60  array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1);
61  G_fseek(params->Tmp_fd_dx, offset2, SEEK_SET);
62  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
63  params->Tmp_fd_dx))
64  G_fatal_error(_("Cannot write files"));
65  }
66  if (params->Tmp_fd_dy != NULL) {
67  for (j = ngstc; j <= nszc; j++) {
68  if (!params->deriv) {
69  if (params->ady[j] > 0. && params->ady[j] < 0.5)
70  params->ady[j] = 360.;
71  array_cell[j - 1] = (FCELL) params->ady[j];
72  }
73  else
74  array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1);
75  }
76  G_fseek(params->Tmp_fd_dy, offset2, SEEK_SET);
77  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
78  params->Tmp_fd_dy))
79  G_fatal_error(_("Cannot write files"));
80  }
81  if (params->Tmp_fd_xx != NULL) {
82  for (j = ngstc; j <= nszc; j++) {
83  array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1);
84  }
85  G_fseek(params->Tmp_fd_xx, offset2, SEEK_SET);
86  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
87  params->Tmp_fd_xx))
88  G_fatal_error(_("Cannot write files"));
89  }
90  if (params->Tmp_fd_yy != NULL) {
91  for (j = ngstc; j <= nszc; j++)
92  array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2);
93  G_fseek(params->Tmp_fd_yy, offset2, SEEK_SET);
94  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
95  params->Tmp_fd_yy))
96  G_fatal_error(_("Cannot write files"));
97  }
98  if (params->Tmp_fd_xy != NULL) {
99  for (j = ngstc; j <= nszc; j++)
100  array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3);
101  G_fseek(params->Tmp_fd_xy, offset2, SEEK_SET);
102  if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
103  params->Tmp_fd_xy))
104  G_fatal_error(_("Cannot write files"));
105  }
106  return 1;
107 }
#define G_malloc(n)
Definition: defs/gis.h:112
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
FILE * Tmp_fd_xy
Definition: interpf.h:92
FILE * Tmp_fd_yy
Definition: interpf.h:92
DCELL * adxx
Definition: interpf.h:78
#define NULL
Definition: ccmath.h:32
FILE * Tmp_fd_xx
Definition: interpf.h:92
DCELL * adx
Definition: interpf.h:78
FILE * Tmp_fd_dx
Definition: interpf.h:92
DCELL * az
Definition: interpf.h:78
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
Definition: gis/seek.c:50
float FCELL
Definition: gis.h:604
DCELL * ady
Definition: interpf.h:78
FILE * Tmp_fd_dy
Definition: interpf.h:92
FILE * Tmp_fd_z
Definition: interpf.h:92
#define _(str)
Definition: glocale.h:10
DCELL * adxy
Definition: interpf.h:78
int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, off_t offset2)
Definition: write2d.c:36
DCELL * adyy
Definition: interpf.h:78