Mapper
read_and_sum_nexrad.c
Go to the documentation of this file.
1 
2 #include "prototypes.h"
3 
4 void read_and_sum_nexrad(int type,int index)
5 
6 {
7 
8 extern char nexrad_file[100];
9 extern int nexrad_flag;
10 extern Display *display;
11 extern Window window;
12 extern Cursor watch_cursor;
13 extern Widget drawing_area;
14 extern struct hrap_grid *hrap_grid;
15 extern int ditime[];
16 extern time_t itime[500],dtime[500],xtime[500],htime[500];
17 extern struct pcp *pcp;
18 extern struct pcp *spf;
19 int gmini,gminj,gmaxi,gmaxj,ghrapi,ghrapj;
20 int minhrapi,minhrapj,maxhrapi,maxhrapj;
21 int hours;
22 time_t btim,tim;
23 int i,j,k;
24 struct tm *gm;
25 FILE *fq;
26 char fbuf[100];
27 char nbuf[100];
28 int ii,jj;
29 int ier;
30 char ibuf[100];
31 Cardinal argcount;
32 Arg args[10];
33 XmString msg;
34 Widget cerr;
35 char kbuf[10000];
36 int iflag;
37 int h;
38 char *p;
39 
40 if(nexrad_flag==1)
41  return;
42 
43 XDefineCursor(display,window,watch_cursor);
44 
45 msg=XmStringCreateLocalized("Reading and summing NEXRAD precipitation");
46 
47 argcount=0;
48 XtSetArg(args[argcount],XmNmessageString,msg);argcount++;
49 XtSetArg(args[argcount],XmNdialogStyle,
50  XmDIALOG_FULL_APPLICATION_MODAL);argcount++;
51 cerr=XmCreateErrorDialog(drawing_area,"info",args,argcount);
52 
53 XtUnmanageChild(XmMessageBoxGetChild(cerr,XmDIALOG_CANCEL_BUTTON));
54 XtUnmanageChild(XmMessageBoxGetChild(cerr,XmDIALOG_OK_BUTTON));
55 XtUnmanageChild(XmMessageBoxGetChild(cerr,XmDIALOG_HELP_BUTTON));
56 XtUnmanageChild(XmMessageBoxGetChild(cerr,XmDIALOG_DEFAULT_BUTTON));
57 XtUnmanageChild(XmMessageBoxGetChild(cerr,XmDIALOG_SEPARATOR));
58 
59 XtManageChild(cerr);
60 XmStringFree(msg);
61 
63 
64 for(i=0;i<hrap_grid->maxi;i++) {
65 
66 for(j=0;j<hrap_grid->maxj;j++) {
67 
68  spf->value[i][j]=-9999;
69 
70  }
71 
72  }
73 
74 if(type==13) {
75 
76 /* instantaneous */
77 
78  hours=ditime[index]/60;
79  btim=htime[0];
80 
81  }
82 
83 else if(type==14) {
84 
85 /* hourly */
86 
87  hours=1;
88  btim=htime[index];
89 
90  }
91 
92 else if(type==15) {
93 
94 /* six hourly */
95 
96  if(index==0) {
97 
98  hours=6;
99  btim=xtime[0];
100  hours=(xtime[0]-xtime[1])/3600;
101 
102  }
103 
104  else {
105 
106  hours=6;
107  btim=xtime[index];
108 
109 
110 
111  }
112 
113 
114  }
115 
116 else if(type==16) {
117 
118 /* daily */
119 printf("daly\n");
120  if(index==0) {
121 
122  btim=dtime[0];
123  hours=(dtime[0] - dtime[1])/3600;
124 
125  }
126 
127  else {
128 
129  hours=24;
130  btim=dtime[index];
131 
132  }
133 
134  printf("%d %d %d %d\n",dtime[1],dtime[0],hours,index);
135 
136  }
137 
138 for(k=0;k<hours;k++) {
139 
140  for(i=0;i<hrap_grid->maxi;i++) {
141 
142  for(j=0;j<hrap_grid->maxj;j++) {
143 
144  pcp->value[i][j]=-9999;
145 
146  }
147 
148  }
149 
150 
151  tim=btim - 3600*k;
152  gm=gmtime(&tim);
153 
154  sprintf(fbuf,"/awips/hydroapps/rfc/local/apps/mapper/nexrad/%02d/%02d/ngrid.%02d-%02d-%02d-%02d",
155  gm->tm_year,gm->tm_mon+1,gm->tm_year,
156  gm->tm_mon+1,gm->tm_mday,gm->tm_hour);
157 
158  sprintf(nbuf,"%s/ngrid.%02d-%02d-%02d-%02d.%d",
159  nexrad_file,
160  gm->tm_year,gm->tm_mon+1,gm->tm_mday,gm->tm_hour,
161  getpid());
162 
163  sprintf(ibuf,"cp %s.gz %s.gz",fbuf,nbuf);
164 
165  ier=system(ibuf);
166 
167  if(ier!=0)
168  continue;
169 
170  sprintf(ibuf,"gzip -t %s.gz",nbuf);
171 
172  ier=system(ibuf);
173 
174  if(ier != 0)
175  continue;
176 
177  sprintf(ibuf,"gzip -d -f %s.gz",nbuf);
178 
179  ier=system(ibuf);
180 
181  if(ier != 0)
182  continue;
183 
184  fq=fopen(nbuf,"r");
185 
186  /* what if missing ?? */
187 
188  if(fq==NULL) {
189 
190  printf("could not find %s\n",nbuf);
191  continue;
192 
193  }
194 
195  minhrapi=hrap_grid->hrap_minx;
196  minhrapj=hrap_grid->hrap_miny;
197  maxhrapi=hrap_grid->hrap_minx + hrap_grid->maxi;
198  maxhrapj=hrap_grid->hrap_miny + hrap_grid->maxj;
199 
200  p=fgets(kbuf,100,fq);
201 
202  ier=sscanf(kbuf,"%d %d %d %d %d\n",&gmini,&gminj,&gmaxi,&gmaxj,&iflag);
203 
204  if(ier==4)
205  iflag=0;
206 
207  for(i=0;i<gmaxi;i++) {
208 
209  if(iflag==0)
210  fread(kbuf,sizeof(char),gmaxj*4,fq);
211 
212  else
213  fread(kbuf,sizeof(char),gmaxj*6,fq);
214 
215  /* get hrap coord of gridded data */
216 
217  ghrapi=gmini+i;
218 
219  ii=ghrapi-minhrapi;
220 
221  if(ghrapi >= minhrapi && ghrapi < maxhrapi) {
222 
223  h=0;
224 
225  for(j=0;j<gmaxj;j++) {
226 
227  ghrapj=gminj+j;
228 
229  jj=ghrapj-minhrapj;
230 
231  if(ghrapj >= minhrapj && ghrapj < maxhrapj) {
232 
233  pcp->value[ii][jj]=atoi(&kbuf[h]);
234 
235 
236  }
237 
238  if(iflag==0)
239  h=h+4;
240 
241  else
242  h=h+6;
243 
244  }
245 
246  }
247 
248  }
249 
250  fclose(fq);
251 
252  for(i=0;i<hrap_grid->maxi;i++) {
253 
254  for(j=0;j<hrap_grid->maxj;j++) {
255 
256  if(spf->value[i][j] < 0 && pcp->value[i][j] >=0)
257  spf->value[i][j]=pcp->value[i][j];
258 
259  else if(pcp->value[i][j] >=0)
260  spf->value[i][j]=spf->value[i][j]+pcp->value[i][j];
261 
262  }
263 
264  }
265 
266 }
267 
268 sprintf(ibuf,"rm %s/*%d*",nexrad_file,getpid());
269 
270 system(ibuf);
271 
272 XtDestroyWidget(cerr);
273 
274 nexrad_flag=1;
275 
276 }
static int i
char fbuf[100]
Definition: decode_HDP.c:2
Display * display
Definition: mapper.c:159
void XmtWaitUntilMapped(Widget)
Definition: Wait.c:39
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
printf("fbuf is %s\n", fbuf)
system(tarbuf)
int j
Definition: mapp2h.h:48
int k
Definition: mapp2h.h:48
int ditime[]
Definition: mapper.c:51
time_t dtime[500]
Definition: mapper.c:150
int nexrad_flag
Definition: mapper.c:46
time_t itime[500]
Definition: mapper.c:150
struct pcp * spf
Definition: mapper.c:141
char nexrad_file[100]
Definition: mapper.c:7
Window window
Definition: mapper.c:190
time_t htime[500]
Definition: mapper.c:150
Widget cerr
Definition: mapper.c:183
Cursor watch_cursor
Definition: mapper.c:153
time_t xtime[500]
Definition: mapper.c:150
struct pcp * pcp
Definition: mapper.c:140
struct hrap_grid * hrap_grid
Definition: mapper.c:142
Arg args[10]
Widget drawing_area
Definition: mapper.c:185
void read_and_sum_nexrad(int type, int index)
short int hrap_miny
Definition: misc.h:583
short int hrap_minx
Definition: misc.h:582
short int maxi
Definition: misc.h:580
short int maxj
Definition: misc.h:581
Definition: misc.h:596
short int ** value
Definition: misc.h:599
struct stim btim
Definition: subdisplay.c:30
tim()
Definition: tim.c:4