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