-
Notifications
You must be signed in to change notification settings - Fork 23
/
InitSedTables.c
executable file
·328 lines (255 loc) · 9.85 KB
/
InitSedTables.c
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* SUMMARY: InitSedTables.c - Initialize lookup tables
* USAGE: Part of DHSVM
*
* AUTHOR: Bart Nijssen
* ORG: University of Washington, Department of Civil Engineering
* E-MAIL: [email protected]
* ORIG-DATE: Apr-96
* LAST-MOD: Sat Feb 7 17:23:51 1998 by Bart Nijssen <[email protected]>
* DESCRIPTION: Initialize lookup tables
* DESCRIP-END.
* FUNCTIONS: InitSedimentTables()
* InitSedTable()
* InitVegStats()
* COMMENTS:
*/
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "settings.h"
#include "DHSVMerror.h"
#include "Calendar.h"
#include "data.h"
#include "constants.h"
#include "fileio.h"
#include "getinit.h"
int InitSedTable(SEDTABLE **SedType, LISTPTR Input, SOILTABLE **SType);
int InitVegStats(VEGTABLE **VType, LISTPTR Input);
float CalcSatDensity(float AveDensity);
/*******************************************************************************/
/* InitSedimentTables() */
/*******************************************************************************/
void InitSedimentTables(int StepsPerDay, LISTPTR Input, SEDTABLE **SedType, SOILTABLE **SType,
VEGTABLE **VType, LAYER *Soil, LAYER *Veg)
{
int NSedimentTypes, NVegTypes;
printf("Initializing sediment tables\n");
if((NSedimentTypes = InitSedTable(SedType, Input, SType)) == 0)
ReportError("Input Sediment File", 8);
if(Soil->NTypes != NSedimentTypes)
ReportError("Input Sediment File", 2);
if((NVegTypes = InitVegStats(VType, Input)) == 0)
ReportError("Input Vegetation File", 8);
if(Veg->NTypes != NVegTypes)
ReportError("Input Vegetation File", 2);
}
/********************************************************************************
Function Name: InitSedTable()
Purpose : Initialize the sediment lookup table
Processes most of the following section in InFileName:
[SEDIMENT]
Required :
SEDTABLE **SedType - Pointer to lookup table
LISTPTR Input - Pointer to linked list with input info
LAYER *Soil - Pointer to structure with soil layer information
Returns : Number of soil layers
Modifies : SedTable
Comments :
********************************************************************************/
int InitSedTable(SEDTABLE **SedType, LISTPTR Input, SOILTABLE **SType)
{
const char *Routine = "InitSedTable";
int i; /* counter */
int j; /* counter */
int NSoils; /* Number of soil types */
char KeyName[fa_mode+1][BUFSIZE+1];
char *KeyStr[] = {
"SOIL DESCRIPTION",
"KINDEX",
"D50",
"SOIL COHESION DISTRIBUTION",
"SC MIN",
"SC MAX",
"SC MEAN",
"SC DEV",
"SC MODE",
"ANGLE OF INTERNAL FRICTION DISTRIBUTION",
"AIF MIN",
"AIF MAX",
"AIF MEAN",
"AIF DEV",
"AIF MODE"
};
char SectionName[] = "SEDIMENT";
char VarStr[fa_mode+1][BUFSIZE+1];
float AveDensity; /* Average soil density (km/m^3) */
/* Get the number of different soil types */
GetInitString(SectionName, "NUMBER OF SOIL TYPES", "", VarStr[0],
(unsigned long) BUFSIZE, Input);
if (!CopyInt(&NSoils, VarStr[0], 1))
ReportError("NUMBER OF SOIL TYPES", 51);
if (NSoils == 0)
return NSoils;
if (!(*SedType = (SEDTABLE *) calloc(NSoils, sizeof(SEDTABLE))))
ReportError((char *) Routine, 1);
/********** Read information and allocate memory for each soil type *********/
for (i = 0; i < NSoils; i++) {
/* Read the key-entry pairs from the input file */
for (j = 0; j <= fa_mode; j++) {
sprintf(KeyName[j], "%s %d", KeyStr[j], i+1);
GetInitString(SectionName, KeyName[j], "", VarStr[j],
(unsigned long) BUFSIZE, Input);
}
/* Assign the entries to the appropriate variables */
if (IsEmptyStr(VarStr[sed_description]))
ReportError(KeyName[sed_description], 51);
strcpy((*SedType)[i].Desc, VarStr[sed_description]);
if (!CopyFloat(&((*SedType)[i].KIndex), VarStr[kindex], 1))
ReportError(KeyName[kindex], 51);
if (!CopyFloat(&((*SedType)[i].d50), VarStr[dfifty], 1))
ReportError(KeyName[dfifty], 51);
if (IsEmptyStr(VarStr[cohesion]))
ReportError(KeyName[cohesion], 51);
strcpy((*SedType)[i].Cohesion.Distribution, VarStr[cohesion]);
if(strcmp((*SedType)[i].Cohesion.Distribution, "NORMAL")==0) {
if (!CopyFloat(&((*SedType)[i].Cohesion.mean), VarStr[coh_mean], 1))
ReportError(KeyName[coh_mean], 51);
if (!CopyFloat(&((*SedType)[i].Cohesion.stdev), VarStr[coh_dev], 1))
ReportError(KeyName[coh_dev], 51);
}
else {
if (!CopyFloat(&((*SedType)[i].Cohesion.min), VarStr[coh_min], 1))
ReportError(KeyName[coh_min], 51);
if (!CopyFloat(&((*SedType)[i].Cohesion.max), VarStr[coh_max], 1))
ReportError(KeyName[coh_max], 51);
}
if(strcmp((*SedType)[i].Cohesion.Distribution, "TRIANGULAR")==0) {
if (!CopyFloat(&((*SedType)[i].Cohesion.mode), VarStr[coh_mode], 1))
ReportError(KeyName[coh_mode], 51);
}
if (IsEmptyStr(VarStr[friction_angle]))
ReportError(KeyName[friction_angle], 51);
strcpy((*SedType)[i].Friction.Distribution, VarStr[friction_angle]);
if(strcmp((*SedType)[i].Friction.Distribution, "NORMAL")==0) {
if (!CopyFloat(&((*SedType)[i].Friction.mean), VarStr[fa_mean], 1))
ReportError(KeyName[fa_mean], 51);
if (!CopyFloat(&((*SedType)[i].Friction.stdev), VarStr[fa_dev], 1))
ReportError(KeyName[fa_dev], 51);
}
else {
if (!CopyFloat(&((*SedType)[i].Friction.min), VarStr[fa_min], 1))
ReportError(KeyName[fa_min], 51);
if (!CopyFloat(&((*SedType)[i].Friction.max), VarStr[fa_max], 1))
ReportError(KeyName[fa_max], 51);
}
if(strcmp((*SedType)[i].Friction.Distribution, "TRIANGULAR")==0) {
if (!CopyFloat(&((*SedType)[i].Friction.mode), VarStr[fa_mode], 1))
ReportError(KeyName[fa_mode], 51);
}
/* Calculating the saturated soil density based on average density -
this is not a weighted average */
AveDensity = 0.0;
for (j = 0; j < (*SType)[i].NLayers; j++){
AveDensity += (*SType)[i].Dens[j];
}
AveDensity /= j;
(*SedType)[i].SatDensity = CalcSatDensity(AveDensity);
}
return NSoils;
}
/********************************************************************************
Function Name: InitVegTable()
Purpose : Initialize the vegetation lookup table
Processes most of the following section in the input file:
[VEGETATION]
Required :
VEGTABLE **VType - Pointer to lookup table
LISTPTR Input - Pointer to linked list with input info
LAYER *Veg - Pointer to structure with veg layer information
Returns : Number of vegetation types
Modifies : VegTable and Veg
Comments :
********************************************************************************/
int InitVegStats(VEGTABLE **VType, LISTPTR Input)
{
const char *Routine = "InitVegStats";
int i; /* Counter */
int j; /* Counter */
int NVegs; /* Number of vegetation types */
char KeyName[vs_mode+1][BUFSIZE+1];
char *KeyStr[] = {
"ROOT COHESION DISTRIBUTION",
"RC MIN",
"RC MAX",
"RC MEAN",
"RC DEV",
"RC MODE",
"VEGETATION SURCHARGE DISTRIBUTION",
"VS MIN",
"VS MAX",
"VS MEAN",
"VS DEV",
"VS MODE",
};
char SectionName[] = "VEGETATION";
char VarStr[vs_mode+1][BUFSIZE+1];
/* Get the number of different vegetation types */
GetInitString(SectionName, "NUMBER OF VEGETATION TYPES", "", VarStr[0],
(unsigned long) BUFSIZE, Input);
if (!CopyInt(&NVegs, VarStr[0], 1))
ReportError("NUMBER OF VEGETATION TYPES", 51);
if (NVegs == 0)
return NVegs;
/******* Read information for each vegetation type ******/
for (i = 0; i < NVegs; i++) {
/* Read the key-entry pairs from the input file */
for (j = 0; j <= vs_mode; j++) {
sprintf(KeyName[j], "%s %d", KeyStr[j], i+1);
GetInitString(SectionName, KeyName[j], "", VarStr[j],
(unsigned long) BUFSIZE, Input);
}
/* Assign the entries to the appropriate variables */
if (IsEmptyStr(VarStr[root_cohesion]))
ReportError(KeyName[root_cohesion], 51);
strcpy((*VType)[i].RootCoh.Distribution, VarStr[root_cohesion]);
if(strcmp((*VType)[i].RootCoh.Distribution, "NORMAL")==0) {
if (!CopyFloat(&((*VType)[i].RootCoh.mean), VarStr[rc_mean], 1))
ReportError(KeyName[rc_mean], 51);
if (!CopyFloat(&((*VType)[i].RootCoh.stdev), VarStr[rc_dev], 1))
ReportError(KeyName[rc_dev], 51);
}
else {
if (!CopyFloat(&((*VType)[i].RootCoh.min), VarStr[rc_min], 1))
ReportError(KeyName[rc_min], 51);
if (!CopyFloat(&((*VType)[i].RootCoh.max), VarStr[rc_max], 1))
ReportError(KeyName[rc_max], 51);
}
if(strcmp((*VType)[i].RootCoh.Distribution, "TRIANGULAR")==0) {
if (!CopyFloat(&((*VType)[i].RootCoh.mode), VarStr[rc_mode], 1))
ReportError(KeyName[rc_mode], 51);
}
if (IsEmptyStr(VarStr[veg_surcharge]))
ReportError(KeyName[veg_surcharge], 51);
strcpy((*VType)[i].VegSurcharge.Distribution, VarStr[veg_surcharge]);
if(strcmp((*VType)[i].VegSurcharge.Distribution, "NORMAL")==0) {
if (!CopyFloat(&((*VType)[i].VegSurcharge.mean), VarStr[vs_mean], 1))
ReportError(KeyName[vs_mean], 51);
if (!CopyFloat(&((*VType)[i].VegSurcharge.stdev), VarStr[vs_dev], 1))
ReportError(KeyName[vs_dev], 51);
}
else {
if (!CopyFloat(&((*VType)[i].VegSurcharge.min), VarStr[vs_min], 1))
ReportError(KeyName[vs_min], 51);
if (!CopyFloat(&((*VType)[i].VegSurcharge.max), VarStr[vs_max], 1))
ReportError(KeyName[vs_max], 51);
}
if(strcmp((*VType)[i].VegSurcharge.Distribution, "TRIANGULAR")==0) {
if (!CopyFloat(&((*VType)[i].VegSurcharge.mode), VarStr[vs_mode], 1))
ReportError(KeyName[vs_mode], 51);
}
}
return NVegs;
}