/
new_tephra.c
654 lines (576 loc) · 21 KB
/
new_tephra.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#if defined (UNIX)
#include <unistd.h>
#include <gc.h>
#endif
#include "prototypes.h"
/*
Code: new_tephra.c
By: C.B. & L.J. Connor, T. Hincks, and C. Bonadonna
Copyright (C) 2003 C.B. Connor, L.J. Connor, C. Bonadonna, T. Hincks
See: http://www.cas.usf.edu/~cconnor/parallel/tephra/tephra.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/* The following Global Variables are assigned some default values
double DIFFUSION_COEFFICIENT = 200.0;
double FALL_TIME_THRESHOLD = 180.0;
double EDDY_CONST = .04;
double LITHIC_DENSITY = 2350.0;
double PUMICE_DENSITY = 1000.0;
int PLUME_MODEL = 2;
double PLUME_RATIO = 0.1;
double ALPHA = 1.0;
double BETA = 1.0;
double WIND_INTERVAL;
int WIND_DAYS = 1;
int WIND_COLUMNS = 3;
double PLUME_HEIGHT = 5.0;
double ERUPTION_MASS = 1e10;
double MAX_GRAINSIZE = -7.0;
double MIN_GRAINSIZE = 7.0;
double MEDIAN_GRAINSIZE = 1.5;
double STD_GRAINSIZE = 2.0;
double VENT_EASTING = 0.0;
double VENT_NORTHING = 0.0;
double VENT_ELEVATION = 0.0;
*/
int COL_STEPS;
int PART_STEPS;
/*define the following data structures for the code
full descriptions are found in common_structures.h */
static ERUPTION e;
static WIND **W;
static POINT *pt;
/*define the following variables passed among functions in this file */
static int num_pts = 0; /*total number of points used in the analysis */
/* static int num_eruptions = 1; total number of eruptions used in the analysis */
/* static int num_wind_data = 0; number of wind data points in the analysis */
/*static int local_n; */
/* FILE *in_eruptions; */
FILE *in_points;
FILE *in_wind;
FILE *log_file;
int cmp(double *x, double *y) {
if (*x < *y) return -1;
if (*x > *y) return 1;
return 0;
}
void exit_now(int e) {
(void) fclose(in_points);
(void) fclose(in_wind);
#ifdef DEBUG
(void) fclose(log_file);
#endif
exit(e);
}
int main(int argc, char *argv[]) { /* MAIN CODE STARTS HERE */
int i, /* j, */ bin;
double val, bin_width;
STATS stats;
char log_name[25];
/* Check for correct number of comand line arguments */
if (argc != 4) {
fprintf(stderr,
"Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n");
exit(1);
}
/* Each node opens a file for logging */
sprintf(log_name, "%s", LOG_FILE);
fprintf(stderr, "%s\n", log_name);
log_file = fopen(log_name, "w+");
if (log_file == NULL) {
fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n",
log_name, strerror(errno));
exit(1);
}
/* Initialize the global variables (see top of file) with inputs from the configuration file. */
if ( init_globals(argv[1]) ) {
exit(1);
}
#ifdef _PRINT
fflush(log_file);
#endif
/*make sure the points file exists*/
in_points= fopen(argv[2], "r");
if (in_points == NULL) {
fprintf(stderr, "Cannot open points file=[%s]:[%s]. Exiting.\n",
argv[2], strerror(errno));
exit_now(1);
}
/* Input the data points from a file using the
get_points function.
*/
if (get_points(in_points) ) {
exit_now(1);
}
#ifdef _PRINT
fflush(log_file);
#endif
/*make sure the wind file exists*/
in_wind= fopen(argv[3], "r");
if (in_wind == NULL) {
fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n",
argv[3], strerror(errno));
exit_now(1);
}
if (get_wind(in_wind) ) {
exit_now(1);
}
#ifdef _PRINT
fflush(log_file);
#endif
set_global_values(log_file);
#ifdef _PRINT
fflush(log_file);
#endif
set_eruption_values(&e, W[0]);
for (i = 0; i < num_pts; i++)
{/* For each location */
tephra_calc(&e, pt+i, W[0], &stats);
}
#ifdef _PRINT
fprintf(log_file, "Calculated mass...\n");
for (i = 0; i < num_pts; i++) {
fprintf(log_file, "[%.0f][%.0f] %g ", (pt+i)->easting, (pt+i)->northing, (pt+i)->calculated_mass) ;
fprintf(log_file, "\n");
}
fprintf(log_file, "Finished.\n");
fflush(log_file);
#endif
fprintf(stderr,"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",stats.min_falltime, stats.max_falltime);
//printf("Mean_fall_time %15.6e\n",stats.
/*phi_bins = (int)((erupt+j)->max_phi - (erupt+j)->min_phi);
if (phi_bins < 1) phi_bins = 1; */
bin_width = (e.max_phi - e.min_phi)/PART_STEPS;
printf("#EAST NORTH ELEV Kg/m^2 ");
for (bin = 0; bin < PART_STEPS; bin++)
printf("[%6.5f:%6.5f) ",
e.min_phi + bin_width*bin,
e.min_phi + bin_width*(bin+1));
printf("\n");
fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", PART_STEPS, bin_width);
for (i=0; i < num_pts; i++) {
printf("%20.8e %20.8e %20.8e %20.8e ",
(pt+i)->easting,
(pt+i)->northing,
(pt+i)->elevation,
(pt+i)->calculated_mass);
///* Print out percent of total */
for (bin=0; bin < PART_STEPS; bin++) {
//val = ((pt+i)->calculated_phi[bin]/(pt+i)->calculated_mass);
val = (pt+i)->calculated_phi[bin];
//fprintf(stderr, "bin = %g mass = %g ", (pt+i)->phi[bin], (pt+i)->mass )
printf("%20.8e ", val);
}
printf("\n");
}
print_for_stats(0);
fprintf(log_file, "Finished.\n");
exit_now(0);
return 1;
}
void print_for_stats(double val) {
FILE *out;
out = fopen("plume2.dat", "w");
if (out == NULL) {
fprintf(stderr,
"Cannot output parameters to file:[%s]. Printing to STDOUT.\n",
strerror(errno));
out = stdout;
}
fprintf (out, "%.0f %.0f %d %g %g", e.max_plume_elevation, e.vent_elevation, (int) COL_STEPS, e.alpha, e.beta);
if (out != stdout) fclose(out);
}
/**************************************************************
FUNCTION: get_points
DESCRIPTION: This function reads eruption data into the
ERUPTION array. Each node stores
all of the eruption parameters which are varied and then
used in calculating the mass loading value at each point.
INPUTS: (IN) FILE *in (file handle from which to read)
OUTPUTS: int -1=error, 0=no error
***************************************************************/
int get_points(FILE *in) {
char line[MAX_LINE];
int i, j, ret, /* my_start=0,*/ pts_read=0;
#ifdef _PRINT
fprintf(log_file,"ENTER[get_points]\n");
#endif
while (fgets(line, MAX_LINE, in) != NULL) {
if (line[0] == '#' || line[0] == '\n') continue;
num_pts++;
}
rewind(in);
/* local_n = num_pts;*/
#ifdef _PRINT
fprintf(log_file, "Total locations: %d.\n", num_pts);
#endif
#if defined (UNIX)
pt = (POINT *)GC_MALLOC((size_t)num_pts * sizeof(POINT));
#else
pt = (POINT *)malloc((size_t)num_pts * sizeof(POINT));
#endif
if (pt == NULL) {
fprintf(stderr, "Cannot malloc memory for my points:[%s]\n", strerror(errno));
return -1;
}
//#ifdef _PRINT
// fprintf(log_file, "\tReading in %d locations, starting at line %d.\n",
// local_n, my_start);
//#endif
i=0;
while (i < num_pts) {
fgets(line, MAX_LINE, in);
if (line[0] == '#' || line[0] == '\n') continue;
else {
while (ret = sscanf(line,
"%lf %lf %lf",
&(pt+pts_read)->easting,
&(pt+pts_read)->northing,
&(pt+pts_read)->elevation),
ret != 3) {
if (ret == EOF && errno == EINTR) continue;
fprintf(stderr, "[line=%d,ret=%d] Did not read in 3 coordinates:[%s]\n", i+1,ret, strerror(errno));
return -1;
}
/* Initialize some values in the point structure */
/*(pt+pts_read)->cum_mass = 0.0; */
(pt+pts_read)->calculated_mass = 0.0;
/*(pt+pts_read)->calculated_phi = (double *)GC_MALLOC((size_t)PART_STEPS * sizeof(double));
if ((pt+pts_read)->calculated_phi == NULL) {
fprintf(stderr, "Cannot malloc memory for phi_bins:[%s]\n", strerror(errno));
return -1;
} */
for (j=0; j<PART_STEPS; j++)
(pt+pts_read)->calculated_phi[j] = 0.0;
pts_read++;
/* if (i >= my_start) {
pts_read++;
if (pts_read == local_n) break;
} */
}
i++;
}
fprintf(log_file,"EXIT[get_points]:Read %d points.\n",
pts_read);
#ifdef _PRINT
fprintf(log_file, "EXIT[get_points].\n");
#endif
return 0;
}
/**************************************************************
FUNCTION: get_wind
DESCRIPTION: This function reads wind data into the
WIND array. Each node stores all of the wind data.
INPUTS: (IN) FILE *in (file handle from which to read)
OUTPUTS: int -1=error, 0=no error
***************************************************************/
int get_wind(FILE *in) {
int i=0, j=0, ret, WIND_DAYS = 1;
char line[MAX_LINE];
double wind_height, wind_dir, windspeed, dir0, ht0, sp0;
double level, WIND_INTERVAL;
fprintf(log_file,"ENTER[get_wind].\n");
#ifdef _PRINT
#endif
WIND_INTERVAL = (e.max_plume_elevation - e.vent_elevation)/(double)COL_STEPS;
#if defined (UNIX)
W = (WIND**)GC_MALLOC((size_t)WIND_DAYS * sizeof(WIND *));
#else
W = (WIND**)malloc((size_t)WIND_DAYS * sizeof(WIND *));
#endif
if (W == NULL) {
fprintf(stderr, "Cannot malloc memory for wind columns:[%s]\n", strerror(errno));
return -1;
} else {
for (i=0; i < WIND_DAYS; i++) {
#if defined (UNIX)
W[i] = (WIND *)GC_MALLOC((size_t)(COL_STEPS+1) * sizeof(WIND));
#else
W[i] = (WIND *)malloc((size_t)(COL_STEPS+1) * sizeof(WIND));
#endif
if (W[i] == NULL) {
fprintf(stderr, "Cannot malloc memory for wind rows %d:[%s]\n", i, strerror(errno));
return -1;
}
}
}
/* Assume one wind day */
i=0;
/* start at the vent */
level = e.vent_elevation;
/* Do for each column step */
/* j = 0 is for the interval between the vent and the ground.
* Here we set the wind speed and direction to be at the level of the vent;
* The values used in the calculations change for each location and are
* set in the tephra_calc routine when the point elevation is known.
* The last interval ends at the top of the column.
*/
W[i][0].wind_height = e.vent_elevation;
/* fprintf(log_file, "[%d]%f %f %f\n", 0, W[i][j].wind_height, W[i][j].windspeed, W[i][j].wind_direction); */
for (j=0; j <= COL_STEPS; j++) {
ht0 = 0.0;
dir0 = 0.0;
sp0 = 0.0;
/* Find wind elevation just greater than current level
Start scanning the wind file for the best match.
Each new level starts scanning the file from the beginning.
*/
while (NULL != fgets(line, MAX_LINE, in)) {
if (line[0] == '#') continue;
else {
while (ret = sscanf(line, "%lf %lf %lf",
&wind_height,
&windspeed,
&wind_dir), ret != 3) {
if (ret == EOF && errno == EINTR) continue;
fprintf(stderr,
"[line=%d,ret=%d] Did not read in 3 parameters:[%s]\n",
i+1,ret, strerror(errno));
return -1;
}
}
/* This is the case where we find the first height that is equal to
* or greater that the level that we are assigning.
*/
if (wind_height >= level) {
if(wind_height == level) {
W[i][j].wind_direction = wind_dir;
W[i][j].windspeed = windspeed;
} else { /* interpolate */
W[i][j].wind_direction =
((wind_dir - dir0) * (level - ht0) / (wind_height - ht0)) + dir0;
W[i][j].windspeed =
((windspeed - sp0) * (level - ht0) / (wind_height - ht0)) + sp0;
}
W[i][j].wind_height = level;
break; /* ready to rescan the file for a match for the next level */
}
/* This is the case where the scanned height is less than the level
* we are assigning.
*/
else {
/* Maintain the scanned values for possible interpolation
* at the next level.
*/
ht0 = wind_height;
dir0 = wind_dir;
sp0 = windspeed;
}
}
/* If we finish scanning the file and all heights are below the level we are
* currently assigning, then just use the direction and speed
* at the upper-most height.
*/
if (!W[i][j].wind_height) {
W[i][j].wind_height = level;
W[i][j].windspeed = sp0;
W[i][j].wind_direction = dir0;
}
/* Go to the next column height */
fprintf(log_file, "[%d] %f %f %f\n",
j, W[i][j].wind_height, W[i][j].windspeed, W[i][j].wind_direction);
W[i][j].wind_direction *= DEG2RAD; /* change to radians */
rewind(in);
level += WIND_INTERVAL;
}
fprintf(log_file, "\tRead %d wind days with %d wind levels per day.\n", i+1, j);
fprintf(log_file, "EXIT[get_wind].\n");
#ifdef _PRINT
#endif
return 0;
}
/**************************************************************
FUNCTION: get_config_data
DESCRIPTION: This function reads the configuration file,
and sets some global variables.
INPUTS: (IN) FILE *in (file handle from which to read)
OUTPUTS: int -1=error, 0=no error
***************************************************************/
int init_globals(char *config_file) {
FILE *in_config;
char buf[1][30], **ptr1;
char line[MAX_LINE];
char space[4] = "\n\t ";
char *token;
int err = 0;
#ifdef _PRINT
fprintf(log_file, "ENTER[init_globals].\n");
#endif
in_config = fopen(config_file, "r");
if (in_config == NULL) {
fprintf(stderr,
"Cannot open configuration file=[%s]:[%s]. Exiting.\n", config_file, strerror(errno));
return 1;
}
ptr1 = (char **)&buf[0];
while (fgets(line, MAX_LINE, in_config) != NULL) {
fprintf(stderr, "%s\n", line);
if (line[0] == '#' || line[0] == '\n' || line[0] == ' ') continue;
#if !defined (UNIX) && !defined (OSX)
token = strtok_s(line, space, ptr1);
#else
token = strtok_r(line, space, ptr1);
#endif
if (!strncmp(token, "DIFFUSION_COEFFICIENT", strlen("DIFFUSION_COEFFICIENT"))) {
//token = strtok_s(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.diffusion_coefficient = strtod(token, NULL);
/* DIFFUSION_COEFFICIENT can never be 0 as it is used in divisions */
if (e.diffusion_coefficient < 1.0) e.diffusion_coefficient = 1.0;
fprintf(stderr, "DIFFUSION_COEFFICIENT=%.0f\n", e.diffusion_coefficient);
}
else if (!strncmp(token, "EDDY_CONST", strlen("EDDY_CONST"))) {
//token = strtok_r(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.eddy_constant = strtod(token, NULL);
fprintf(stderr, "EDDY_CONST=%.2f\n", e.eddy_constant);
}
else if (!strncmp(token, "FALL_TIME_THRESHOLD", strlen("FALL_TIME_THRESHOLD"))) {
//token = strtok_r(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.fall_time_threshold = strtod(token, NULL);
fprintf(stderr, "FALL_TIME_THRESHOLD=%.0f\n", e.fall_time_threshold);
}
else if (!strncmp(token, "LITHIC_DENSITY", strlen("LITHIC_DENSITY"))) {
//token = strtok_r(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.lithic_density = strtod(token, NULL);
fprintf(stderr, "LITHIC_DENSITY=%.0f\n", e.lithic_density);
}
else if (!strncmp(token, "PUMICE_DENSITY", strlen("PUMICE_DENSITY"))) {
//token = strtok_r(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.pumice_density = strtod(token, NULL);
fprintf(stderr, "PUMICE_DENSITY=%.0f\n", e.pumice_density);
}
else if (!strncmp(token, "PART_STEPS", strlen("PART_STEPS"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
PART_STEPS = (int)atof(token);
fprintf(stderr, "PART_STEPS = %d\n", PART_STEPS);
}
else if (!strncmp(token, "COL_STEPS", strlen("COL_STEPS"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
COL_STEPS = (int)atof(token);
fprintf(stderr, "COL_STEPS = %d\n", COL_STEPS);
}
else if (!strncmp(token, "PLUME_MODEL", strlen("PLUME_MODEL"))) {
//token = strtok_r(NULL,space,ptr1);
err = parse_tok(ptr1,&token,space);
e.plume_model = (int)atof(token);
if (e.plume_model == 0) {
pdf = plume_pdf0;
fprintf(stderr, "PLUME_MODEL=[%d]%s\n", e.plume_model, "Uniform Distribution with threshold");
}
else if (e.plume_model == 1) {
pdf = plume_pdf1;
fprintf(stderr, "PLUME_MODEL=[%d]%s\n", e.plume_model, "log-normal Distribution using beta");
}
else if (e.plume_model == 2) {
pdf = plume_pdf2;
fprintf(log_file, "PLUME_MODEL=[%d]%s\n", e.plume_model, "Beta Distribution with ALPHA and BETA parameteres");
}
}
else if (!strncmp(token, "PLUME_RATIO", strlen("PLUME_RATIO"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.plume_ratio = strtod(token, NULL);
if (!e.plume_model) fprintf(stderr, "PLUME_RATIO = %.2f\n", e.plume_ratio);
}
else if (!strncmp(token, "ALPHA", strlen("ALPHA"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.alpha = strtod(token, NULL);
if (e.plume_model==2) fprintf(stderr, "ALPHA = %g\n", e.alpha);
}
else if (!strncmp(token, "BETA", strlen("BETA"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.beta = strtod(token, NULL);
if (e.plume_model==2) fprintf(stderr, "BETA = %g\n", e.beta);
}
else if (!strncmp(token, "PLUME_HEIGHT", strlen("PLUME_HEIGHT"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.max_plume_elevation = strtod(token, NULL);
fprintf(stderr, "PLUME_HEIGHT = %.0f\n", e.max_plume_elevation);
}
else if (!strncmp(token, "ERUPTION_MASS", strlen("ERUPTION_MASS"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.total_ash_mass = strtod(token, NULL);
fprintf(stderr, "ERUPTION_MASS = %g\n", e.total_ash_mass);
}
else if (!strncmp(token, "MAX_GRAINSIZE", strlen("MAX_GRAINSIZE"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.min_phi = strtod(token, NULL);
fprintf(stderr, "MAX_GRAINSIZE = %g (phi)\n", e.min_phi);
}
else if (!strncmp(token, "MIN_GRAINSIZE", strlen("MIN_GRAINSIZE"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.max_phi = strtod(token, NULL);
fprintf(stderr, "MIN_GRAINSIZE = %g (phi)\n", e.max_phi);
}
else if (!strncmp(token, "MEDIAN_GRAINSIZE", strlen("MEDIAN_GRAINSIZE"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.mean_phi = strtod(token, NULL);
fprintf(stderr, "MEDIAN_GRAINSIZE = %g (phi)\n", e.mean_phi);
}
else if (!strncmp(token, "STD_GRAINSIZE", strlen("STD_GRAINSIZE"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.sigma_phi = strtod(token, NULL);
/* if (STD_GRAINSIZE < 1.0) STD_GRAINSIZE = 1.0; */
fprintf(stderr, "STD_GRAINSIZE = %g (phi)\n", e.sigma_phi);
}
else if (!strncmp(token, "VENT_EASTING", strlen("VENT_EASTING"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.vent_easting = strtod(token, NULL);
fprintf(stderr, "VENT_EASTING = %.0f\n", e.vent_easting);
}
else if (!strncmp(token, "VENT_NORTHING", strlen("VENT_NORTHING"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.vent_northing = strtod(token, NULL);
fprintf(stderr, "VENT_NORTHING = %.0f\n", e.vent_northing);
}
else if (!strncmp(token, "VENT_ELEVATION", strlen("VENT_ELEVATION"))) {
//token = strtok_r(NULL, space, ptr1);
err = parse_tok(ptr1,&token,space);
e.vent_elevation = strtod(token, NULL);
fprintf(stderr, "VENT_ELEVATION = %.0f\n", e.vent_elevation);
}
else continue;
}
(void) fclose(in_config);
#ifdef _PRINT
fprintf(log_file, "EXIT[init_globals].\n");
#endif
return 0;
}
int parse_tok(char** ptr1,char** token,char* space)
{
#if !defined (UNIX) && !defined (OSX)
*token = strtok_s(NULL,space,ptr1);
#else
*token = strtok_r(NULL,space,ptr1);
#endif
return 0;
}