-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
153 lines (139 loc) · 4.63 KB
/
input.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
#define INPUT_MODULE
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include "coeff_obj.h"
#include "igrid_obj.h"
#include "landclass_obj.h"
#include "globals.h"
#include "ugm_typedefs.h"
#include "output.h"
#include "input.h"
#include "utilities.h"
#include "ugm_macros.h"
#include "scenario_obj.h"
/*****************************************************************************\
*******************************************************************************
** **
** MACROS **
** **
*******************************************************************************
\*****************************************************************************/
#define GIF_ID "GIF87a"
#define GIF_ROW_OFFSET 8
#define GIF_COL_OFFSET 6
#define GIF_RES_OFFSET 10
#define MAX_ANSWER_STR_LEN 20
#define MAX_DUMMY_STR_LEN 80
#define MAX_CMD_STR_LEN 120
#ifdef DEBUG
#define CHECK_EOF(arg0,arg1,arg2,arg3) \
if((arg0) != 2) \
{ \
printf("%s Line %d EOF occurred while reading file: %s\n", \
(arg1),(arg2),(arg3)); \
EXIT(1); \
}
#else
#define CHECK_EOF(arg0,arg1,arg2,arg3)
#endif
/*****************************************************************************\
*******************************************************************************
** **
** SCCS ID **
** **
*******************************************************************************
\*****************************************************************************/
char input_c_sccs_id[] = "@(#)input.c 1.629 12/4/00";
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: inp_slurp
** PURPOSE: read count chars from filename into ptr
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
inp_slurp (char *filename,
void *ptr,
int count)
{
char func[] = "inp_slurp";
FILE *fp;
int actual;
FUNC_INIT;
assert (filename != NULL);
assert (ptr != NULL);
assert (count > 0);
FILE_OPEN (fp, (filename), "r");
actual = fread (ptr, sizeof (char), count, fp);
if (actual != count)
{
sprintf (msg_buf, "Read failed. %u bytes of %u read from file %s",
actual, count, filename);
LOG_ERROR (msg_buf);
}
fclose (fp);
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: inp_read_restart_file
** PURPOSE: read the restart file
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
inp_read_restart_file (int *diffusion,
int *breed,
int *spread,
int *slope_resistance,
int *road_gravity,
long *random_seed,
int *counter)
{
char func[] = "inp_read_restart_file";
char filename[MAX_FILENAME_LEN];
FILE *FileToRead;
int rc;
assert (diffusion != NULL);
assert (breed != NULL);
assert (spread != NULL);
assert (slope_resistance != NULL);
assert (road_gravity != NULL);
assert (random_seed != NULL);
assert (counter != NULL);
FUNC_INIT;
sprintf (filename, "%s%s%u", scen_GetOutputDir (), RESTART_FILE, glb_mype);
FILE_OPEN (FileToRead, filename, "r");
/*
* Read the restart file
*/
printf ("Reading restart file: %s\n", filename);
rc = fscanf (FileToRead, "%d %d %d %d %d %ld %d",
diffusion,
breed,
spread,
slope_resistance,
road_gravity,
random_seed,
counter);
if (rc != 7)
{
sprintf (msg_buf, "EOF occurred when reading file %s", filename);
LOG_ERROR (msg_buf);
EXIT (1);
}
fclose (FileToRead);
FUNC_END;
}