Mapper
get_station_list.c
Go to the documentation of this file.
1 #include "prototypes.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  int i,ier,sflag,field,j,xadd,yadd;
10  extern struct station station[1500];
11  extern int max_stations;
12  FILE *fp;
13  char *p,kbuf[150],hb5[10],parm[10];
14  double dist1,dist2,dist,sorted[30];
15  int m,l,h,k;
16  int kk;
17  float lat,lon;
18  float conv=.0174;
19  long t,u;
20 
21  max_stations=0;
22 
23  fp=fopen(fname,"r");
24 
25  if(fp==NULL) {
26 
27  printf("could not open %s\n",fname);
28  exit(1);
29 
30  }
31 
32  i=0;
33  for(;;) {
34 
35  p=fgets(kbuf,120,fp);
36  if(p==NULL)
37  break;
38 
39  if(i==1500)
40  break;
41 
42  p=strchr(kbuf,'\n');
43 
44  if(p!=NULL)
45  *p=0;
46 
47  ier=sscanf(kbuf,"%s %s %f %f %d %d ",station[i].hb5,
50 
51 
52  if(strncasecmp("PPD",station[i].parm,3)!=0 &&
53  strncasecmp("PPM",station[i].parm,3)!=0 )
54  continue;
55 
56  if(ier != 6)
57  continue;
58 
59  lat=station[i].lat;
60  lon=station[i].lon;
61 
62  t=dval.a * cos(lat*conv)/(1+sin(lat*conv))
63  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
64 
65  station[i].x=t;
66 
67  u=dval.a * cos(lat*conv)/(1+sin(lat*conv))
68  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
69 
70  station[i].y=u;
71 
72  for(k=0;k<12;k++) {
73 
74  ier=is_good(k,smonth,emonth);
75 
76  if(ier == -1)
77  continue;
78 
79 
81 
82 
83  }
84 
85  sflag=1;
86  field=0;
87  for(j=0;j<strlen(kbuf);j++) {
88 
89  if(kbuf[j] !=' ' && sflag==1) {
90  sflag=0;
91  field++;
92 
93  }
94 
95  else if(kbuf[j]==' ')
96  sflag=1;
97 
98  if(field==7) {
99 
100  kbuf[j+49]=0;
101 
102  strcpy(station[i].name,&kbuf[j]);
103  break;
104 
105  }
106 
107  }
108 
109  i++;
110 
111  }
112 
114 fclose(fp);
115 
116 strcpy(kbuf,fname);
117 strcat(kbuf,".custom");
118 strcpy(station_list_custom_file,kbuf);
119 
120 fp=fopen(kbuf,"r");
121 
122 if(fp!=NULL) {
123 printf("custom ok\n");
124  for(;;) {
125 
126  p=fgets(kbuf,80,fp);
127  if(p==NULL)
128  break;
129 
130  p=strchr(kbuf,'\n');
131  *p=0;
132 
133  ier=sscanf(kbuf,"%s %s %d %d",hb5,parm,&xadd,&yadd);
134 
135  for(j=0;j<max_stations;j++) {
136 
137  if(strcmp(hb5,station[j].hb5)==0) {
138 
139  if(strncmp(parm,station[j].parm,3)==0 &&
140  parm[4]==station[j].parm[4]) {
141 
142  station[j].xadd=xadd;
143  station[j].yadd=yadd;
144  break;
145 
146  }
147 
148  }
149 
150  }
151  }
152 
153  }
154 
155 fclose(fp);
156 
157 for(i=0;i<max_stations;i++) {
158 
159  for(l=0;l<30;l++)
160  sorted[l]=9999999;
161 
162  for(m=0;m<max_stations;m++) {
163 
164  if(i==m)
165  continue;
166 
167  dist1=station[i].lat-station[m].lat;
168  dist2=station[i].lon-station[m].lon;
169 
170  dist=pow(dist1,2)+pow(dist2,2);
171 
172  for(l=0;l<30;l++) {
173 
174  if(dist < sorted[l]) {
175 
176  for(h=29; h > l; h--) {
177 
178  sorted[h]=sorted[h-1];
179 
180  station[i].index[h]=
181  station[i].index[h-1];
182 
183  }
184 
185  sorted[l]=dist;
186 
187  station[i].index[l]=m;
188 
189  break;
190 
191  }
192 
193 
194  }
195 
196  }
197 
198  }
199 
200 return;
201 
202 }
203 
204 
205 
206 
207 
208 
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 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: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
int y
Definition: misc.h:308
int yadd
Definition: misc.h:310
short int index[30]
Definition: misc.h:302
char parm[10]
Definition: misc.h:301
int xadd
Definition: misc.h:309