File: write2d.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (143 lines) | stat: -rw-r--r-- 4,044 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

/*-
 * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
 * University of Illinois
 * US Army Construction Engineering Research Lab  
 * Copyright 1993, H. Mitasova (University of Illinois),
 * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)   
 *
 * modified by McCauley in August 1995
 * modified by Mitasova in August 1995  
 *
 */

#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <grass/gis.h>

#include <grass/interpf.h>

int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, int offset2	/* begin. and end. column, offset */
    )

/*
 * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
 * and offset) in corresponding temp file
 */
{
    int j;
    static FCELL *array_cell = NULL;

    if (!array_cell) {

	if (!
	    (array_cell =
	     (FCELL *) G_malloc(sizeof(FCELL) * params->nsizc + 1))) {
	    fprintf(stderr, "Cannot allocate memory for array_cell\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_z != NULL) {
	for (j = ngstc; j <= nszc; j++)
	    array_cell[j - 1] = (FCELL) params->az[j];
	if (fseek(params->Tmp_fd_z, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek elev offset2=%d\n", (int)offset2);
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_z))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_dx != NULL) {
	for (j = ngstc; j <= nszc; j++)
	    if (!params->deriv)
		array_cell[j - 1] = (FCELL) params->adx[j];
	    else
		array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1);
	if (fseek(params->Tmp_fd_dx, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek slope\n");
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_dx))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_dy != NULL) {
	for (j = ngstc; j <= nszc; j++) {
	    if (!params->deriv) {
		if (params->ady[j] > 0. && params->ady[j] < 0.5)
		    params->ady[j] = 360.;
		array_cell[j - 1] = (FCELL) params->ady[j];
	    }
	    else
		array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1);
	}
	if (fseek(params->Tmp_fd_dy, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek aspect\n");
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_dy))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_xx != NULL) {
	for (j = ngstc; j <= nszc; j++) {
	    array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1);
	}
	if (fseek(params->Tmp_fd_xx, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek pcurv\n");
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_xx))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_yy != NULL) {
	for (j = ngstc; j <= nszc; j++)
	    array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2);
	if (fseek(params->Tmp_fd_yy, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek tcurv\n");
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_yy))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    if (params->Tmp_fd_xy != NULL) {
	for (j = ngstc; j <= nszc; j++)
	    array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3);
	if (fseek(params->Tmp_fd_xy, (long)offset2, 0) == -1) {
	    fprintf(stderr, "Cannot fseek mcurv\n");
	    return -1;
	}
	if (!
	    (fwrite
	     (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
	      params->Tmp_fd_xy))) {
	    fprintf(stderr, "Not enough disk space--cannot write files\n");
	    return -1;
	}
    }
    return 1;
}