Mapper
libraries
common
get_basin_data.c
Go to the documentation of this file.
1
#include "
prototypes.h
"
2
3
void
get_basin_data
(
char
*basin_file,
char
*
hrap_file
)
4
5
{
6
7
extern
struct
forecast_basins
forecast_basins
[500];
8
extern
int
forecast_basins_flag;
9
extern
struct
station
station
[1500];
10
extern
struct
map
map
[1500];
11
extern
struct
dval
dval
;
12
FILE *fr,*
fp
;
13
char
*p,ibuf[100];
14
int
ib
,ier,l,numpts,ip,x,y,ip2,ip3,ip4,zones,
i
,maxib,dum,mm;
15
double
lat
,
lon
;
16
long
r,s;
17
float
conv=.0174;
18
char
bchar[10];
19
20
if
(basin_file[0]==0 ) {
21
22
printf
(
"no basin_file specified\n"
);
23
exit(1);
24
25
}
26
27
if
(
hrap_file
[0]==0 ) {
28
29
printf
(
"no basin_file specified\n"
);
30
exit(1);
31
32
}
33
34
fr=fopen(basin_file,
"r"
);
35
36
if
(fr==NULL) {
37
38
printf
(
"could not open basin_file %s\n"
,basin_file);
39
40
exit(1);
41
42
}
43
44
fp
=fopen(
hrap_file
,
"r"
);
45
46
if
(
fp
==NULL) {
47
48
printf
(
"could not open hrap_file %s\n"
,
hrap_file
);
49
50
exit(1);
51
52
}
53
54
ib
=0;
55
56
for
(;;) {
57
58
p=fgets(ibuf,80,fr);
59
60
if
(p==NULL)
61
break
;
62
63
p=strchr(ibuf,
'\n'
);
64
if
(p!=NULL)
65
*p=0;
66
67
ier=sscanf(ibuf,
"%d %d %s"
,&numpts,&dum,
map
[
ib
].hb5);
68
69
map
[
ib
].
basin_points
=numpts;
70
71
map
[
ib
].
basin
=calloc(numpts,
sizeof
(XPoint));
72
73
for
(l=0;l<numpts;l++) {
74
75
p=fgets(ibuf,80,fr);
76
77
if
(p==NULL)
78
break
;
79
80
ier=sscanf(ibuf,
"%lf %lf"
,&
lon
,&
lat
);
81
82
lon
=-
lon
;
83
84
r=
dval
.
a
* cos(
lat
*conv)/(1+sin(
lat
*conv))
85
* cos((
lon
-
dval
.
lo
-90)*conv) +
dval
.
xo
+.5;
86
87
s=
dval
.
a
* cos(
lat
*conv)/(1+sin(
lat
*conv))
88
* sin((
lon
-
dval
.
lo
-90)*conv) +
dval
.
yo
+ .5;
89
90
map
[
ib
].
basin
[l].x=r;
91
map
[
ib
].
basin
[l].y=s;
92
93
}
94
95
p=fgets(ibuf,80,fr);
96
97
ib
++;
98
99
}
100
101
map
[
ib
].
hb5
[0]=0;
102
maxib=
ib
;
103
104
for
(
ib
=0;
ib
<maxib;
ib
++) {
105
106
p=fgets(ibuf,80,
fp
);
107
108
if
(p==NULL)
109
break
;
110
111
p=strchr(ibuf,
'\n'
);
112
if
(p!=NULL)
113
*p=0;
114
115
ier=sscanf(ibuf,
"%d %d %*s %s"
,&numpts,&zones,bchar);
116
117
strcpy(
map
[
ib
].bchar,bchar);
118
119
map
[
ib
].
hrap_points
=numpts;
120
map
[
ib
].
fmap_flag
=1;
121
122
map
[
ib
].
hrap_data
=calloc(numpts,
sizeof
(
struct
hrap_data
));
123
124
for
(mm=0;mm<4;mm++)
125
map
[
ib
].zones[mm]=-1;
126
127
for
(l=0;l<numpts;l++) {
128
129
for
(mm=0;mm<4;mm++)
130
map
[
ib
].
hrap_data
[l].zone[mm]=-1;
131
132
p=fgets(ibuf,100,
fp
);
133
134
if
(p==NULL)
135
break
;
136
137
ier=sscanf(ibuf,
"%d %d %d %d %d %d\n"
,&x,&y,&ip,&ip2,&ip3,&ip4);
138
139
if
(ip < 0 || ip > 4) {
140
141
printf
(
"hrap error\n"
);
142
exit(1);
143
144
}
145
146
map
[
ib
].
hrap_data
[l].
x
=x;
147
map
[
ib
].
hrap_data
[l].
y
=y;
148
map
[
ib
].
hrap_data
[l].
zone
[ip-1]=1;
149
map
[
ib
].
zones
[0]=1;
150
151
if
(ier>=4) {
152
153
if
(ip2 < 0 || ip2 > 4) {
154
155
printf
(
"hrap error\n"
);
156
exit(1);
157
158
}
159
160
map
[
ib
].
hrap_data
[l].
zone
[ip2-1]=1;
161
map
[
ib
].
zones
[ip2-1]=1;
162
163
}
164
165
166
if
(ier>=5) {
167
168
if
(ip3 < 0 || ip3 > 4) {
169
170
printf
(
"hrap error\n"
);
171
exit(1);
172
173
}
174
175
map
[
ib
].
hrap_data
[l].
zone
[ip3-1]=1;
176
map
[
ib
].
zones
[ip3-1]=1;
177
178
}
179
180
if
(ier>=6) {
181
182
if
(ip4 < 0 || ip4 > 4) {
183
184
printf
(
"hrap error\n"
);
185
exit(1);
186
187
}
188
189
map
[
ib
].
hrap_data
[l].
zone
[ip4-1]=1;
190
map
[
ib
].
zones
[ip4-1]=1;
191
192
}
193
194
}
195
196
197
for
(
i
=0;
i
<200;
i
++)
198
map
[
ib
].maps_done[
i
]=-1;
199
200
201
}
202
203
fclose
(fr);
204
fclose
(
fp
);
205
206
if
(forecast_basins_flag==1) {
207
208
for
(
ib
=0;
ib
<maxib;
ib
++) {
209
210
for
(
i
=0;
forecast_basins
[
i
].
hb5
[0]!=0;
i
++) {
211
212
if
(strcasecmp(
map
[
ib
].hb5,
forecast_basins
[
i
].hb5)==0)
213
break
;
214
215
}
216
217
if
(
forecast_basins
[
i
].hb5[0]==0)
218
map
[
ib
].
fmap_flag
=0;
219
220
else
221
map
[
ib
].
fmap_flag
=1;
222
223
}
224
225
}
226
227
return
;
228
229
}
230
231
i
static int i
Definition:
get_apps_defaults.c:110
get_basin_data
void get_basin_data(char *basin_file, char *hrap_file)
Definition:
get_basin_data.c:3
fclose
fclose(fp)
printf
printf("fbuf is %s\n", fbuf)
fp
fp
Definition:
make_NEXRAD.c:339
lat
double lat
Definition:
mapp2h.h:41
lon
double lon
Definition:
mapp2h.h:41
hrap_file
char hrap_file[100]
Definition:
mapper.c:19
prototypes.h
ib
ib
Definition:
shleap.cc:46
dval
Definition:
misc.h:470
dval::lo
double lo
Definition:
misc.h:475
dval::a
double a
Definition:
misc.h:472
dval::yo
double yo
Definition:
misc.h:474
dval::xo
double xo
Definition:
misc.h:473
forecast_basins
Definition:
misc.h:9
forecast_basins::hb5
char hb5[10]
Definition:
misc.h:11
hrap_data
Definition:
misc.h:228
hrap_data::zone
int zone[4]
Definition:
misc.h:232
hrap_data::x
int x
Definition:
misc.h:230
hrap_data::y
int y
Definition:
misc.h:231
map
Definition:
misc.h:236
map::hb5
char hb5[10]
Definition:
misc.h:238
map::fmap_flag
int fmap_flag
Definition:
misc.h:239
map::hrap_data
struct hrap_data * hrap_data
Definition:
misc.h:245
map::basin_points
int basin_points
Definition:
misc.h:240
map::hrap_points
int hrap_points
Definition:
misc.h:244
map::zones
int zones[4]
Definition:
misc.h:241
map::basin
XPoint * basin
Definition:
misc.h:243
station
Definition:
misc.h:296
Generated by
1.9.1