Mapper
get_station_list_new.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 void get_station_list(char *fname,int smonth,int emonth)
4 
5 {
6 
7  extern struct dval dval;
8  extern char station_list_custom_file[100];
9  extern char station_climo_file[100];
10  int i,ier,sflag,field,j,xadd,yadd;
11  extern struct station station[3000];
12  extern int max_stations;
13  FILE *fp;
14  char *p,kbuf[200],hb5[10],parm[10];
15  double dist1,dist2,dist,sorted[30];
16  int m,l,h,k;
17  int kk;
18  float lat,lon;
19  float conv=.0174;
20  long t,u;
21  float f[15];
22  int ifound;
23  int oldk;
24  float elev;
25 
26  max_stations=0;
27 
28  fp=fopen(fname,"r");
29 
30  if(fp==NULL) {
31 
32  printf("could not open %s\n",fname);
33  exit(1);
34 
35  }
36 
37  i=0;
38  for(;;) {
39 
40  p=fgets(kbuf,120,fp);
41  if(p==NULL)
42  break;
43 
44  if(i==3000)
45  break;
46 
47  p=strchr(kbuf,'\n');
48 
49  if(p!=NULL)
50  *p=0;
51 
52  j=0;
53  while(kbuf[j] != 0) {
54 
55  if(kbuf[j]=='\t')
56  kbuf[j]=' ';
57 
58  j++;
59 
60  }
61 
62  station[i].isoh=calloc(24,sizeof(float));
63  station[i].hb5=calloc(10,sizeof(char));
64  station[i].name=calloc(50,sizeof(char));
65  station[i].parm=calloc(10,sizeof(char));
66  station[i].cparm=calloc(10,sizeof(char));
67  station[i].index=calloc(30,sizeof(short int));
68  station[i].zindex=calloc(5,sizeof(short int));
69 
70  ier=sscanf(kbuf,"%s %s %f %f %f %d ",station[i].hb5,
72  &station[i].lon,&elev,&station[i].tip);
73 
74  station[i].elev=(int)elev;
75 
76  if(strncasecmp("PPD",station[i].parm,3)!=0 &&
77  strncasecmp("PPM",station[i].parm,3)!=0 )
78  continue;
79 
80  for(m=0;m<i;m++) {
81 
82  if(strcmp(station[i].hb5,station[m].hb5)==0 &&
83  station[i].parm[4]==station[m].parm[4]){
84 
85  /*printf("duplicate station %s\n",station[i].hb5);
86  */
87  break;
88 
89  }
90 
91  }
92 
93 
94 
95  if(i!=m)
96  continue;
97 
98  if(ier != 6)
99  continue;
100 
101  lat=station[i].lat;
102  lon=station[i].lon;
103 
104  t=dval.a * cos(lat*conv)/(1+sin(lat*conv))
105  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
106 
107  station[i].x=t;
108 
109  u=dval.a * cos(lat*conv)/(1+sin(lat*conv))
110  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
111 
112  station[i].y=u;
113 
114  sflag=1;
115  field=0;
116  for(j=0;j<strlen(kbuf);j++) {
117 
118  if(kbuf[j] !=' ' && sflag==1) {
119  sflag=0;
120  field++;
121 
122  }
123 
124  else if(kbuf[j]==' ')
125  sflag=1;
126 
127  if(field==7) {
128 
129  kbuf[j+49]=0;
130 
131  strcpy(station[i].name,&kbuf[j]);
132  break;
133 
134  }
135 
136  }
137 
138  i++;
139 
140  }
141 
143 
144 fclose(fp);
145 
146 for(i=0;i<max_stations;i++){
147 
148  for(m=0;m<24;m++)
149  station[i].isoh[m]=-99;
150 
151 
152 }
153 
154 fp=NULL;
155 if(station_climo_file[0]!=0)
156  fp=fopen(station_climo_file,"r");
157 
158 if(fp==NULL) {
159 
160  for(i=0;i<max_stations;i++) {
161 
162 
163  for(k=0;k<12;k++) {
164 
165  ier=is_good(k,smonth,emonth);
166 
167  if(ier == -1)
168  continue;
169 
171 
172  if(station[i].isoh[k] < 0)
173  printf("No PRISM climatology for %s\n",station[i].hb5);
174 
175  strcpy(station[i].cparm,"PPMPBZZ");
176 
177  }
178 
179  }
180 
181 }
182 
183 else {
184 
185  for(;;) {
186 
187  p=fgets(kbuf,200,fp);
188  if(p==NULL)
189  break;
190 
191  ier=sscanf(kbuf,"%s %s %f %f %f %f %f %f %f %f %f %f %f %f",
192  hb5,parm,&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],&f[8],
193  &f[9],&f[10],&f[11]);
194 
195  if(ier != 14)
196  continue;
197 
198  if(parm[0]!='P')
199  continue;
200 
201  for(i=0;i<max_stations;i++) {
202 
203  if(strcmp(station[i].hb5,hb5)==0 &&
204  station[i].parm[4]==parm[4]) {
205 
206  for(m=0;m<12;m++)
207  station[i].isoh[m]=f[m];
208 
209  strcpy(station[i].cparm,parm);
210 
211  }
212 
213  }
214 
215 
216  }
217 
218  rewind(fp);
219 
220  for(;;) {
221 
222  p=fgets(kbuf,200,fp);
223  if(p==NULL)
224  break;
225 
226  ier=sscanf(kbuf,"%s %s %f %f %f %f %f %f %f %f %f %f %f %f",
227  hb5,parm,&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],&f[8],
228  &f[9],&f[10],&f[11]);
229 
230  if(ier != 14)
231  continue;
232 
233  if(strcmp(parm,"PPMPBCM") != 0 &&
234  strcmp(parm,"PPMRZCM") != 0)
235  continue;
236 
237  for(i=0;i<max_stations;i++) {
238 
239  if(strcmp(station[i].hb5,hb5)==0 &&
240  (station[i].isoh[0] < 0 ||
241  strcmp(station[i].cparm,"PPMPBCM")==0)) {
242 
243  /* if(strcmp(station[i].cparm,"PPMPBCM")==0)
244  printf("overwrite\n"); */
245 
246  for(m=0;m<12;m++)
247  station[i].isoh[m]=f[m];
248 
249  strcpy(station[i].cparm,parm);
250 
251 
252  }
253 
254  }
255 
256 
257  }
258 
259 fclose(fp);
260 
261 
262 }
263 
264 /* finally sum up for seasonal totals */
265 
266 for(i=0;i<max_stations;i++){
267 
268 oldk=-1;
269 
270 for(kk=0;kk<12;kk++) {
271 
272  if(kk < 3)
273  k=9+kk;
274 
275  else
276  k=kk-3;
277 
278  if(oldk==-1) {
279 
280  station[i].isoh[k+12]=station[i].isoh[k];
281 
282 
283  }
284 
285  else {
286 
287  station[i].isoh[k+12]=station[i].isoh[k] + station[i].isoh[oldk];
288 
289 
290  }
291 
292  oldk=k+12;
293 
294  }
295 
296 
297 }
298 
299 strcpy(kbuf,fname);
300 strcat(kbuf,".custom");
301 strcpy(station_list_custom_file,kbuf);
302 
303 fp=fopen(kbuf,"r");
304 
305 if(fp!=NULL) {
306 
307  for(;;) {
308 
309  p=fgets(kbuf,80,fp);
310  if(p==NULL)
311  break;
312 
313  p=strchr(kbuf,'\n');
314  *p=0;
315 
316  ier=sscanf(kbuf,"%s %s %d %d",hb5,parm,&xadd,&yadd);
317 
318  for(j=0;j<max_stations;j++) {
319 
320  if(strcmp(hb5,station[j].hb5)==0) {
321 
322  if(strncmp(parm,station[j].parm,3)==0 &&
323  parm[4]==station[j].parm[4]) {
324 
325  station[j].xadd=xadd;
326  station[j].yadd=yadd;
327  break;
328 
329  }
330 
331  }
332 
333  }
334  }
335 
336 
337 fclose(fp);
338 
339  }
340 
341 for(i=0;i<max_stations;i++) {
342 
343  for(l=0;l<30;l++)
344  sorted[l]=9999999;
345 
346  for(m=0;m<max_stations;m++) {
347 
348  if(i==m)
349  continue;
350 
351  dist1=station[i].lat-station[m].lat;
352  dist2=(station[i].lon-station[m].lon)*
353  cos((station[i].lat+station[m].lat)/2*conv);
354 
355  dist=pow(dist1,2)+pow(dist2,2);
356 
357  for(l=0;l<30;l++) {
358 
359  if(dist < sorted[l]) {
360 
361  for(h=29; h > l; h--) {
362 
363  sorted[h]=sorted[h-1];
364 
365  station[i].index[h]=
366  station[i].index[h-1];
367 
368  }
369 
370  sorted[l]=dist;
371 
372  station[i].index[l]=m;
373 
374  break;
375 
376  }
377 
378 
379  }
380 
381  }
382 
383  }
384 
385 return;
386 
387 }
388 
389 
390 
391 
392 
393 
char name[35][30]
Definition: borshef.c:10
static int i
float get_lisohyet(float lat, float lon, int mon)
Definition: get_lisohyet.c:3
void get_station_list(char *fname, int smonth, int emonth)
int is_good(int k, int smonth, int emonth)
Definition: is_good.c:4
fclose(fp)
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
int j
Definition: mapp2h.h:48
int elev
Definition: mapp2h.h:48
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int k
Definition: mapp2h.h:48
int max_stations
Definition: mapper.c:64
char fname[100]
Definition: send_afos.c:6
Definition: misc.h:470
double lo
Definition: misc.h:475
double a
Definition: misc.h:472
double yo
Definition: misc.h:474
double xo
Definition: misc.h:473
Definition: misc.h:538
Definition: misc.h:296
float lat
Definition: misc.h:303
int x
Definition: misc.h:307
char hb5[10]
Definition: misc.h:299
int tip
Definition: misc.h:306
float isoh[24]
Definition: misc.h:298
float lon
Definition: misc.h:304
char name[50]
Definition: misc.h:300
int y
Definition: misc.h:308
int yadd
Definition: misc.h:310
short int index[30]
Definition: misc.h:302
short int * zindex
Definition: misc_new.h:473
int elev
Definition: misc.h:305
char parm[10]
Definition: misc.h:301
char * cparm
Definition: misc_new.h:470
int xadd
Definition: misc.h:309