Mapper
make_NEXRAD.c
Go to the documentation of this file.
1 
2 #include "prototypes.h"
3 char fbuf[100];
4 
5 void main(int argc, char **argv)
6 {
7 
8  struct nexrad nexrad;
9  int i,j,k,ii,jj,kk,l,mm;
10  struct HRAP hrap;
11  struct HRAP irap;
12  float cx,cy,lat,lon;
13  FILE *fp,*fq,*fw;
14  char *p,kbuf[120],dbuf[200],mbuf[200];
15  float xlat,nlat,nlon,xlon;
16  int nrapx[131][131],nrapy[131][131];
17  char name[100];
18  time_t ltim;
19  float hmaxx,hmaxy,hminx,hminy;
20  struct nexstruct nexstruct[25];
21  float pw,pnexrad[255];
22  int imaxx,iminx,imaxy,iminy;
23  char fbuf[100];
24  int maxi,maxj;
25  time_t tim,stim;
26  struct tm *gm;
27  int irain;
28  char tarbuf[1000];
29  int nexarray[20][24];
30  char *nexname[20];
31  int ier;
32  int m, maxdays=1;
33  float frain;
34  int iflag;
35  int h;
36  int ilen,slen;
37  char ibuf[100];
38  float val[500][500];
39  int month,day,year,hour;
40 
41  month=atoi(argv[1]);
42  day=atoi(argv[2]);
43  year=atoi(argv[3]);
44  hour=atoi(argv[4]);
45 
46 
47  /* initialize val */
48 
49  for(i=0;i<500;i++) {
50  for(j=0;j<500;j++) {
51 
52  val[i][j]=-9999;
53 
54  }
55 
56  }
57 
58  /* initialize name */
59 
60  for(i=0;i<20;i++)
61  nexname[i]=calloc(20,1);
62 
63 /* initialize pnexrad */
64 
65  for(i=0;i<255;i++) {
66 
67  pw=(-6) +( (float)(i-1))*.125;
68  pw=pw/10;
69  pw=.0397 * pow(10,pw);
70 
71  if(i==0)
72  pnexrad[i]=0;
73 
74  else
75  pnexrad[i]=pw;
76 
77  }
78 
79  /* pars argv for lat,lon,date and hour */
80 
81  sprintf(dbuf,"/usr/mapper/NEXRAD_radars");
82 
83  fp=fopen(dbuf,"r");
84 
85  if(fp==NULL) {
86 
87  printf("could not open /usr/mapper/NEXRAD_radars\n");
88  exit(1);
89 
90  }
91 
92  p=fgets(kbuf,80,fp);
93  if(p==NULL) {
94 
95  printf("error in format /usr/mapper/NEXRAD_radars\n");
96  exit(1);
97 
98  }
99 
100  p=pars_line(kbuf,"x_lat=",dbuf);
101 
102  if(p==NULL) {
103 
104  printf("no x_lat\n");
105  exit(1);
106 
107  }
108 
109  xlat=atof(dbuf);
110 
111  p=pars_line(kbuf,"n_lat=",dbuf);
112 
113  if(p==NULL) {
114 
115  printf("no n_lat\n");
116  exit(1);
117 
118  }
119 
120  nlat=atof(dbuf);
121 
122  p=pars_line(kbuf,"x_lon=",dbuf);
123 
124  if(p==NULL) {
125 
126  printf("no x_lon\n");
127  exit(1);
128 
129  }
130 
131  xlon=atof(dbuf);
132 
133  p=pars_line(kbuf,"n_lon=",dbuf);
134 
135  if(p==NULL) {
136 
137  printf("no n_lon\n");
138  exit(1);
139 
140  }
141 
142  nlon=atof(dbuf);
143 
144  hmaxx=-1;hmaxy=-1;
145  hminx=9999;hminy=9999;
146 
148 
149  if(hrap.x > hmaxx)
150  hmaxx=hrap.x;
151 
152 
153  if(hrap.x < hminx)
154  hminx=hrap.x;
155 
156 
157  if(hrap.y > hmaxy)
158  hmaxy=hrap.y;
159 
160 
161  if(hrap.y < hminy)
162  hminy=hrap.y;
163 
164  hrap=LatLongToHrap(xlat,nlon);
165 
166  if(hrap.x > hmaxx)
167  hmaxx=hrap.x;
168 
169 
170  if(hrap.x < hminx)
171  hminx=hrap.x;
172 
173 
174  if(hrap.y > hmaxy)
175  hmaxy=hrap.y;
176 
177 
178  if(hrap.y < hminy)
179  hminy=hrap.y;
180 
181  hrap=LatLongToHrap(nlat,xlon);
182 
183  if(hrap.x > hmaxx)
184  hmaxx=hrap.x;
185 
186 
187  if(hrap.x < hminx)
188  hminx=hrap.x;
189 
190 
191  if(hrap.y > hmaxy)
192  hmaxy=hrap.y;
193 
194 
195  if(hrap.y < hminy)
196  hminy=hrap.y;
197 
198  hrap=LatLongToHrap(nlat,nlon);
199 
200  if(hrap.x > hmaxx)
201  hmaxx=hrap.x;
202 
203 
204  if(hrap.x < hminx)
205  hminx=hrap.x;
206 
207 
208  if(hrap.y > hmaxy)
209  hmaxy=hrap.y;
210 
211 
212  if(hrap.y < hminy)
213  hminy=hrap.y;
214 
215  imaxx=hmaxx+.5;
216  iminx=hminx+.5;
217 
218  imaxy=hmaxy+.5;
219  iminy=hminy+.5;
220 
221  maxi=imaxx-iminx;
222  maxj=imaxy-iminy;
223 
224  /* need times to get for each file */
225 
226  for(l=0;l<20;l++) {
227 
228  p=fgets(kbuf,80,fp);
229  if(p==NULL) {
230 
231  fclose(fp);
232  break;
233 
234  }
235 
236  p=pars_line(kbuf,"radar=",dbuf);
237 
238  if(p==NULL)
239  continue;
240 
241  strcpy(name,dbuf);
242 
243  for(i=0;i<3;i++)
244  name[i]=tolower(name[i]);
245 
246  name[3]=0;
247 
248  strcpy(nexname[l],name);
249 
250  p=pars_line(kbuf,"latitude=",dbuf);
251 
252  if(p==NULL)
253  continue;
254 
255  lat=atof(p);
256 
257  p=pars_line(kbuf,"longitude=",dbuf);
258 
259  if(p==NULL)
260  continue;
261 
262  lon=atof(p);
263 
264  if(lon > 0)
265  lon=-lon;
266 
267  /* get hrap coordinates of radar */
268 
270 
271  cx=(int)hrap.x+1;
272  cy=(int)hrap.y;
273 
274  for (i=0; i < 131; i++){
275  for (k=0; k < 131 ;k++){
276 
277 
278  irap.x=cx + (float)(k - 65);
279  irap.y=cy + (float)(i-65);
280 
281  nrapx[i][k]=irap.x;
282  nrapy[i][k]=irap.y;
283 
284  }
285 
286  }
287 
288  sprintf(fbuf,"/usr/mapper/nexrad/scratch/%s.%02d-%02d-%02d-%02d",
290 
291  fq=fopen(fbuf,"rb");
292 
293  /* what if missing ?? */
294 
295  if(fq==NULL) {
296 
297  printf("could not find %s\n",fbuf);
298  continue;
299 
300  }
301 
302  fread(&nexrad,sizeof(char),131*131,fq);
303 
304  fclose(fq);
305 
306  for (i=0; i < 131; i++) {
307  for (j=0; j < 131 ;j++) {
308 
309  ii=nrapx[i][j]-iminx;
310  jj=nrapy[i][j]-iminy;
311 
312  if(ii < 0 || ii > maxi ||
313  jj < 0 || jj > maxj)
314  continue;
315 
316  if(nexrad.value[i][j] == 255)
317  continue;
318 
319  if(pnexrad[nexrad.value[i][j]] >
320  val[ii][jj])
321  val[ii][jj]=pnexrad[nexrad.value[i][j]];
322 
323  }
324 
325  }
326 
327  }
328 
329  }
330 
331 /* now add up all numbers and divide by total contributions */
332 
334 
335 sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d",year,month,day,hour);
336 
337 printf("fbuf is %s\n",fbuf);
338 
339 fp=fopen(fbuf,"w");
340 
341 fprintf(fp,"%d %d %d %d 1\n",iminx,iminy,maxi,maxj);
342 
343 for(i=0;i<maxi;i++) {
344 
345 for(j=0;j<maxj;j++) {
346 
347 
348  if(val[i][j] >=0)
349  irain=val[i][j]* 100;
350 
351  else
352  irain=-9999;
353 
354  fprintf(fp," %5d",irain);
355 
356  }
357 
358  }
359 
360 fclose(fp);
361 
362 sprintf(tarbuf,"gzip -f %s",fbuf);
363 
364 system(tarbuf);
365 
366 }
367 
368 }
369 
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
char name[35][30]
Definition: borshef.c:10
static int i
int hour
Definition: display_data.c:26
int day
Definition: display_data.c:26
int year
Definition: display_data.c:26
int month
Definition: display_data.c:26
struct HRAP LatLongToHrap(float lat, float lon)
Definition: hrap.c:105
char * pars_line(char *buf, char *s, char *sbuf)
Definition: pars_line.c:3
fclose(fp)
char fbuf[100]
Definition: make_NEXRAD.c:3
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
void main(int argc, char **argv)
Definition: make_NEXRAD.c:5
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
system(tarbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
double xlat
Definition: mapp2h.h:41
double lat
Definition: mapp2h.h:41
double xlon
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int k
Definition: mapp2h.h:48
HRAP hrap
Definition: mapp2h.h:53
int maxdays
Definition: mapper.c:56
Definition: mapp2h.h:25
float y
Definition: mapp2h.h:26
float x
Definition: mapp2h.h:26
Definition: misc.h:487
unsigned char value[131][131]
Definition: misc.h:489
Definition: misc.h:93
tim()
Definition: tim.c:4