GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
write2d.c
Go to the documentation of this file.
1 
2 /*-
3  * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
4  * University of Illinois
5  * US Army Construction Engineering Research Lab
6  * Copyright 1993, H. Mitasova (University of Illinois),
7  * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)
8  *
9  * modified by McCauley in August 1995
10  * modified by Mitasova in August 1995
11  *
12  */
13 
14 #include <stdio.h>
15 #include <math.h>
16 #include <unistd.h>
17 #include <grass/gis.h>
18 
19 #include <grass/interpf.h>
20 
21 int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, int offset2 /* begin. and end. column, offset */
22  )
23 
24 /*
25  * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
26  * and offset) in corresponding temp file
27  */
28 {
29  int j;
30  static FCELL *array_cell = NULL;
31 
32  if (!array_cell) {
33 
34  if (!
35  (array_cell =
36  (FCELL *) G_malloc(sizeof(FCELL) * params->nsizc + 1))) {
37  fprintf(stderr, "Cannot allocate memory for array_cell\n");
38  return -1;
39  }
40  }
41  if (params->Tmp_fd_z != NULL) {
42  for (j = ngstc; j <= nszc; j++)
43  array_cell[j - 1] = (FCELL) params->az[j];
44  if (fseek(params->Tmp_fd_z, (long)offset2, 0) == -1) {
45  fprintf(stderr, "Cannot fseek elev offset2=%d\n", (int)offset2);
46  return -1;
47  }
48  if (!
49  (fwrite
50  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
51  params->Tmp_fd_z))) {
52  fprintf(stderr, "Not enough disk space--cannot write files\n");
53  return -1;
54  }
55  }
56  if (params->Tmp_fd_dx != NULL) {
57  for (j = ngstc; j <= nszc; j++)
58  if (!params->deriv)
59  array_cell[j - 1] = (FCELL) params->adx[j];
60  else
61  array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1);
62  if (fseek(params->Tmp_fd_dx, (long)offset2, 0) == -1) {
63  fprintf(stderr, "Cannot fseek slope\n");
64  return -1;
65  }
66  if (!
67  (fwrite
68  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
69  params->Tmp_fd_dx))) {
70  fprintf(stderr, "Not enough disk space--cannot write files\n");
71  return -1;
72  }
73  }
74  if (params->Tmp_fd_dy != NULL) {
75  for (j = ngstc; j <= nszc; j++) {
76  if (!params->deriv) {
77  if (params->ady[j] > 0. && params->ady[j] < 0.5)
78  params->ady[j] = 360.;
79  array_cell[j - 1] = (FCELL) params->ady[j];
80  }
81  else
82  array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1);
83  }
84  if (fseek(params->Tmp_fd_dy, (long)offset2, 0) == -1) {
85  fprintf(stderr, "Cannot fseek aspect\n");
86  return -1;
87  }
88  if (!
89  (fwrite
90  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
91  params->Tmp_fd_dy))) {
92  fprintf(stderr, "Not enough disk space--cannot write files\n");
93  return -1;
94  }
95  }
96  if (params->Tmp_fd_xx != NULL) {
97  for (j = ngstc; j <= nszc; j++) {
98  array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1);
99  }
100  if (fseek(params->Tmp_fd_xx, (long)offset2, 0) == -1) {
101  fprintf(stderr, "Cannot fseek pcurv\n");
102  return -1;
103  }
104  if (!
105  (fwrite
106  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
107  params->Tmp_fd_xx))) {
108  fprintf(stderr, "Not enough disk space--cannot write files\n");
109  return -1;
110  }
111  }
112  if (params->Tmp_fd_yy != NULL) {
113  for (j = ngstc; j <= nszc; j++)
114  array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2);
115  if (fseek(params->Tmp_fd_yy, (long)offset2, 0) == -1) {
116  fprintf(stderr, "Cannot fseek tcurv\n");
117  return -1;
118  }
119  if (!
120  (fwrite
121  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
122  params->Tmp_fd_yy))) {
123  fprintf(stderr, "Not enough disk space--cannot write files\n");
124  return -1;
125  }
126  }
127  if (params->Tmp_fd_xy != NULL) {
128  for (j = ngstc; j <= nszc; j++)
129  array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3);
130  if (fseek(params->Tmp_fd_xy, (long)offset2, 0) == -1) {
131  fprintf(stderr, "Cannot fseek mcurv\n");
132  return -1;
133  }
134  if (!
135  (fwrite
136  (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
137  params->Tmp_fd_xy))) {
138  fprintf(stderr, "Not enough disk space--cannot write files\n");
139  return -1;
140  }
141  }
142  return 1;
143 }
FILE * Tmp_fd_xy
Definition: interpf.h:60
FILE * Tmp_fd_yy
Definition: interpf.h:60
DCELL * adxx
Definition: interpf.h:48
FILE * Tmp_fd_xx
Definition: interpf.h:60
DCELL * adx
Definition: interpf.h:48
FILE * Tmp_fd_dx
Definition: interpf.h:60
DCELL * az
Definition: interpf.h:48
DCELL * ady
Definition: interpf.h:48
return NULL
Definition: dbfopen.c:1394
FILE * Tmp_fd_dy
Definition: interpf.h:60
FILE * Tmp_fd_z
Definition: interpf.h:60
int IL_write_temp_2d(struct interp_params *, int, int, int)
Definition: write2d.c:21
DCELL * adxy
Definition: interpf.h:48
DCELL * adyy
Definition: interpf.h:48