Mapper
build_hrap.c
Go to the documentation of this file.
1 #include "prototypes.h"
2 
3 struct top *topo;
4 struct h_grid *h_grid;
5 double pgon[5000][2];
6 
7 
8 void main(int argc, char **argv)
9 
10 {
11 
12 FILE *fp,*fr,*fh,*fb,*fn;
13 double max_lat,min_lat,cen_lon,lat,lon,point[2],area2,area3,felev,area4;
14 double totlat,totlon;
15 int i,numverts,j,ier,ii,jj,lower,mid,upper,numpoints,lpoints,mpoints,upoints,good,zones,glacial,gpoints,icount;
16 char *p,kbuf[100],ibuf[100],dbuf[100],hb5[100];
17 long fpos,fpos1;
18 
19 topo=NULL;
20 h_grid=NULL;
21 
22 p=pars_argv(argv,"max_lat=");
23 
24 if(p==NULL) {
25 
26  printf("no max_lat specified\n");
27  exit(1);
28 
29  }
30 
31 max_lat=atof(p);
32 
33 p=pars_argv(argv,"min_lat=");
34 
35 if(p==NULL) {
36 
37  printf("no min_lat specified\n");
38  exit(1);
39 
40  }
41 
42 
43 min_lat=atof(p);
44 
45 p=pars_argv(argv,"cen_lon=");
46 
47 if(p==NULL) {
48 
49  printf("no cen_lon specified\n");
50  exit(1);
51 
52  }
53 
54 
55 cen_lon=atof(p);
56 
57 p=pars_argv(argv,"index_file=");
58 
59 if(p==NULL) {
60 
61  printf("no index file specified\n");
62  exit(1);
63 
64  }
65 
66 
67 fr=fopen(p,"r");
68 
69 if(fr==NULL) {
70 
71  printf("could not open index file %s\n",p);
72 
73  exit(1);
74 
75  }
76 
77 
78 p=pars_argv(argv,"topo=");
79 
80 if(p==NULL){
81 
82  printf("no topo file specified\n");
83 
84  exit(1);
85 
86  }
87 
88 get_topo(p);
89 
90 p=pars_argv(argv,"hrap=");
91 
92 if(p==NULL){
93 
94  printf("no hrap file specified\n");
95 
96  exit(1);
97 
98  }
99 
100 fh=fopen(p,"w");
101 
102 p=pars_argv(argv,"basin=");
103 
104 if(p==NULL){
105 
106  printf("no basin file specified\n");
107 
108  exit(1);
109 
110  }
111 
112 fb=fopen(p,"w");
113 
114 p=pars_argv(argv,"basin_name=");
115 
116 if(p==NULL){
117 
118  printf("no basin_name file specified\n");
119 
120  exit(1);
121 
122  }
123 
124 fn=fopen(p,"w");
125 
127 
128 for(;;) {
129 
130  icount=0;
131  p=fgets(ibuf,100,fr);
132 
133  if(p==NULL)
134  exit(1);
135 
136  p=pars_line(ibuf,"i=",hb5);
137 
138 
139 
140  if(p==NULL){
141 
142  printf("no input file specified\n");
143 
144  continue;
145 
146  }
147 
148  p=strchr(hb5,'\n');
149  if(p!=NULL)
150  *p=0;
151 
152  fp=fopen(hb5,"r");
153 
154  if(fp==NULL) {
155 
156  printf("could not open input file %s\n",p);
157 
158  continue;
159 
160  }
161 
162  p=pars_line(ibuf,"upper=",dbuf);
163 
164  if(p==NULL){
165 
166  printf("no upper area specified - assume none exists\n");
167  area3=2000000;
168 
169  }
170 
171  else
172  area3=atof(p);
173 
174  p=pars_line(ibuf,"middle=",dbuf);
175 
176  if(p==NULL){
177 
178  printf("no middle area specified - assume none exists\n");
179  area2=2000000;
180 
181  }
182 
183  else
184  area2=atof(p);
185 
186  if(area2 < 30000 && area3 > 30000) {
187 
188  printf("middle area with no upper area\n");
189 
190  exit(1);
191 
192  }
193 
194  p=pars_line(ibuf,"glacial=",dbuf);
195 
196  if(p==NULL){
197 
198  printf("no glacial specified - assume none exists\n");
199  area4=2000000;
200 
201  }
202 
203  else
204  area2=atof(p);
205 
206  fpos=ftell(fh);
207 
208  fprintf(fh," \n");
209 
210  zones=1;
211 
212  if(area2 < 30000)
213  zones++;
214 
215  if(area3 < 30000)
216  zones++;
217 
218  if(area4 < 30000)
219  zones++;
220 
221  p=fgets(kbuf,100,fp);
222  p=strchr(kbuf,'\n');
223  *p=0;
224 
225  strcat(kbuf," ");
226  strcat(kbuf,hb5);
227  strcat(kbuf,"\n");
228 
229  sscanf(kbuf,"%d",&numverts);
230  fputs(kbuf,fb);
231 
232  sprintf(kbuf,"%d %s 0 0 1 -center\n",icount,hb5);
233  icount++;
234  fputs(kbuf,fn);
235 
236  i=0;
237  for(i=0;i<numverts;i++) {
238 
239  p=fgets(kbuf,100,fp);
240 
241  if(p==NULL)
242  break;
243 
244  fputs(kbuf,fb);
245  ier=sscanf(kbuf,"%lf %lf",&lon,&lat);
246 
247  if(ier != 2)
248  continue;
249 
250  pgon[i][0]=-lon;
251  pgon[i][1]=lat;
252 
253  }
254 
255  fclose(fp);
256 
257  printf("number of points in region %d\n",numverts);
258  printf("area2=%f area3=%f\n",area2,area3);
259 
260  numpoints=0;lpoints=0;mpoints=0;upoints=0;gpoints=0;
261  totlat=0;totlon=0;
262 
263  for(i=0;i<h_grid->maxi-1;i++)
264  {
265  for(j=0;j<h_grid->maxj-1;j++)
266  {
267 
268  good=0;
269  for(ii=i;ii<=i+1;ii++){
270  for(jj=j;jj<=j+1;jj++){
271 
272  point[0]=h_grid->latlon[ii][jj].x;
273  point[1]=h_grid->latlon[ii][jj].y;
274 
276  good++;
277 
278 
279  }
280  }
281 
282  if(good==0)
283  continue;
284 
285  numpoints++;
286 
287  printf("point %f %f\n",point[0],point[1]);
288  totlon=totlon+point[0];
289  totlat=totlat+point[1];
290 
291  lower=0;
292  mid=0;
293  upper=0;
294  glacial=0;
295 
296  for(ii=i;ii<=i+1;ii++){
297  for(jj=j;jj<=j+1;jj++){
298 
299  felev=(float)h_grid->elev[ii][jj] * 32.1;
300 
301  if(zones==1)
302  lower++;
303 
304  else if(zones==2) {
305 
306  if(felev < area3)
307  lower++;
308 
309  else
310  upper++;
311 
312  }
313 
314  else if(zones==3) {
315 
316  if(felev < area2)
317  lower++;
318 
319  else if(felev < area3)
320  mid++;
321 
322  else
323  upper++;
324 
325  }
326 
327 
328 
329  else if(zones==4) {
330 
331  if(felev < area2)
332  lower++;
333 
334  else if(felev < area3)
335  mid++;
336 
337  else if(felev < area4)
338  upper++;
339 
340  else
341  glacial++;
342 
343  }
344 
345 
346  }
347  }
348 
349  fprintf(fh,"%d %d ",h_grid->box[i][j].x,h_grid->box[i][j].y);
350 
351  if(lower > 0) {
352 
353  fprintf(fh,"1 ");
354  lpoints++;
355 
356  }
357 
358  if(mid > 0) {
359 
360  fprintf(fh,"2 ");
361  mpoints++;
362 
363  }
364 
365  if(upper > 0) {
366 
367  fprintf(fh,"3 ");
368 
369  upoints++;
370 
371  }
372 
373  if(glacial > 0) {
374 
375  fprintf(fh,"4 ");
376 
377  upoints++;
378 
379  }
380 
381  fprintf(fh,"\n");
382 
383 
384  }
385 
386  }
387 
388  if(numpoints > 0) {
389 
390  totlat=totlat/(float)numpoints;
391  totlon=totlon/(float)numpoints;
392 
393  }
394 
395  fprintf(fn,"%f %f\n",-totlon,totlat);
396 
397  printf("%f %f\n",totlat,totlon);
398 
399  fpos1=ftell(fh);
400  fseek(fh,fpos,SEEK_SET);
401 
402  fprintf(fh,"%d %d %s",numpoints,zones,hb5);
403 
404  printf("number of hrap boxes inside region %d\n",numpoints);
405  printf("lower %d middle %d upper %d\n",lpoints,mpoints,upoints);
406 
407  fseek(fh,fpos1,SEEK_SET);
408  icount=0;
409 
410 
411  }
412 
413 fclose(fh);
414 fclose(fb);
415 
416 }
417 
418 
419 
void main(int argc, char **argv)
Definition: build_hrap.c:8
struct top * topo
Definition: build_hrap.c:3
struct h_grid * h_grid
Definition: build_hrap.c:4
double pgon[5000][2]
Definition: build_hrap.c:5
static int i
void get_coord(double maximum_latitude, double minimum_latitude, double center_longitude)
Definition: get_coord.c:3
void get_topo(char *fname)
Definition: get_topo.c:3
char * pars_line(char *buf, char *s, char *sbuf)
Definition: pars_line.c:3
char * pars_argv(char **, char *)
int macmartintest(pgon, numverts, point)
Definition: mac.c:6
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
double cen_lon
Definition: mapper.c:22
int numverts
Definition: mapper.c:91
double min_lat
Definition: mapper.c:22
double max_lat
Definition: mapper.c:22
float y
Definition: mapp2h.h:26
float x
Definition: mapp2h.h:26
short int y
Definition: misc.h:498
short int x
Definition: misc.h:497
Definition: misc.h:554
short int maxj
Definition: misc.h:557
struct HRAP ** latlon
Definition: misc.h:559
struct coord ** box
Definition: misc.h:558
short int ** elev
Definition: misc.h:560
short int maxi
Definition: misc.h:556
Definition: mapp2h.h:29
Definition: misc.h:509
Definition: misc.h:523