Mapper
render_t.c
Go to the documentation of this file.
1 /* Converts point precipitation data in struct tdata to hrap grid. The
2  20 closest tstations are precalculated for each grid point - this
3  speeds computations for data sets with many precipitation points.
4  If there are no good precipitation points for a grid point, then
5  a recalculation is made using all precipitation points. 1/R**2
6  interpolation is used. If requested, the final interpolation
7  is scaled using seasonal isohyets. The grid is saved as a disk
8  file and used later for a raster or vector (HRAP) plot. */
9 
10 #include "prototypes_new.h"
11 
13 
14 {
15 
16 extern int isom;
17 extern Widget top_level;
18 extern int pcp_in_use[500];
19 extern Cursor watch_cursor;
20 extern int method;
21 extern struct tdata tdata[10];
22 extern struct station tstation[1000];
23 int i,j,h,hh,time_pos,htotal;
24 double distance,dist1,dist2,dist,value;
25 double temp;
26 extern struct hrap_grid *hrap_grid;
27 extern struct pcp *pcp;
28 extern Window window;
29 extern Display *display;
30 extern int max_tstations;
31 float conv=.0174;
32 float df;
33 int k;
34 int total1,total2;
35 
36 total1=0;total2=0;
37 
38 XDefineCursor(display,window,watch_cursor);
39 XmUpdateDisplay(top_level);
40 
41 if(pcpn_time_step==0)
42  time_pos=pcpn_time;
43 
44 else if(pcpn_time_step==1)
45  time_pos=4;
46 
47 else if(pcpn_time_step==2)
48  time_pos=5;
49 
50 printf("time pos %d\n",time_pos);
51 
52 for(i=0;i<hrap_grid->maxi;i++) {
53 
54 for(j=0;j<hrap_grid->maxj;j++) {
55 
56  if(hrap_grid->owner[i][j]==-1) {
57 
58  pcp->value[i][j]=-9999;
59  continue;
60 
61  }
62 
63 
64  if((pcpn_time_step==1 && hrap_grid->max[isom][i][j] <= -999) ||
65  (pcpn_time_step==2 && hrap_grid->min[isom][i][j] <= -999)) {
66 
67  pcp->value[i][j]=-9999;
68  continue;
69 
70  }
71 
72  value=0.0;
73  distance=0.0;
74  htotal=0;
75 
76  for(h=0;h<20;h++) {
77 
78  hh=hrap_grid->gage[i][j].tindex[h];
79 
80  if(tdata[pcpn_day].stn[hh].tlevel2[time_pos].data == -99 ){
81  /* printf("no data\n");*/
82  continue;
83  };
84 
85  if(tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 0 &&
86  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 8 &&
87  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 6 &&
88  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 3 &&
89  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 2)
90  continue;
91 
92  if(tstation[hh].elev <= 0)
93  continue;
94 
95 
96  if((pcpn_time_step==1 && tstation[hh].max[isom] <= -99) ||
97  (pcpn_time_step==2 && tstation[hh].min[isom] <= -99))
98  continue;
99 
100  dist1=hrap_grid->coord[i][j].lat-tstation[hh].lat;
101  dist2=(hrap_grid->coord[i][j].lon-tstation[hh].lon)*
102  cos((hrap_grid->coord[i][j].lat+tstation[hh].lat)/2*conv);
103 
104  dist=pow(dist1,2)+pow(dist2,2);
105 
106  dist=pow(dist,.5)*60;
107 
108  if(dist < .00001)
109  dist=.00001;
110 
111  df=50*abs(hrap_grid->elev[i][j]-tstation[hh].elev)/5280;
112 
113  dist=dist+df;
114 
115  dist=1/dist;
116 
117  temp=tdata[pcpn_day].stn[hh].tlevel2[time_pos].data;
118 
119  if(pcpn_time_step==1) {
120 
121  temp=(temp+((float)(hrap_grid->max[isom][i][j])/10-
122  tstation[hh].max[isom]))*dist;
123 
124  }
125 
126  if(pcpn_time_step==2) {
127 
128  temp=(temp+((float)(hrap_grid->min[isom][i][j])/10-
129  tstation[hh].min[isom]))*dist;
130 
131  }
132 
133  value=value+temp;
134 
135  distance=distance+dist;
136 
137  htotal++;
138 
139  if(htotal ==5){
140 
141  total1++;
142  break;
143 
144  }
145 
146  }
147 
148 
149  if(htotal < 5) {
150 
151  total2++;
152  value=0.0;
153  distance=0.0;
154  htotal=0;
155 
156  for(h=0;h<max_tstations;h++) {
157 
158  if(tdata[pcpn_day].stn[h].tlevel2[time_pos].data ==-99 )
159  continue;
160 
161  if(tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 0 &&
162  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 8 &&
163  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 6 &&
164  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 3 &&
165  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 2)
166  continue;
167 
168  if(tstation[h].elev <= 0)
169  continue;
170 
171  if((pcpn_time_step==1 && tstation[h].max[isom] <= -99) ||
172  (pcpn_time_step==2 && tstation[h].min[isom] <= -99))
173  continue;
174 
175  dist1=hrap_grid->coord[i][j].lat-tstation[h].lat;
176  dist2=(hrap_grid->coord[i][j].lon-tstation[h].lon)*
177  cos((hrap_grid->coord[i][j].lat+tstation[h].lat)/2*conv);
178 
179  dist=pow(dist1,2)+pow(dist2,2);
180 
181  dist=pow(dist,.5)*60;
182 
183  if(dist < .00001)
184  dist=.00001;
185 
186  df=50*abs(hrap_grid->elev[i][j]-tstation[h].elev)/5280;
187 
188  dist=dist+df;
189 
190  dist=1/dist;
191 
192  temp=tdata[pcpn_day].stn[h].tlevel2[time_pos].data;
193 
194  if(pcpn_time_step==1)
195  temp=(temp+((float)(hrap_grid->max[isom][i][j])/10-
196  tstation[h].max[isom]))*dist;
197 
198  if(pcpn_time_step==2)
199  temp=(temp+((float)(hrap_grid->min[isom][i][j])/10-
200  tstation[h].min[isom]))*dist;
201 
202  value=value+temp;
203 
204  distance=distance+dist;
205 
206  htotal++;
207 
208 
209  }
210 
211 }
212 
213  if(htotal == 0)
214  pcp->value[i][j]=-9999;
215 
216  else
217  pcp->value[i][j]=(int)(value/distance*100);
218 
219 
220  }
221 
222 }
223 
224 
225 if(pcpn_time_step==0)
226  time_pos=150+pcpn_day*4+3-pcpn_time;
227 
228 else if(pcpn_time_step==1)
229  time_pos=190+pcpn_day;
230 
231 else if(pcpn_time_step==2)
232  time_pos=200+pcpn_day;
233 
234 printf("time pos %d\n",time_pos);
235 
236 pcp_in_use[time_pos]=1;
237 
238 
239 write_file("pcp",time_pos,pcp);
240 
241 printf("totals are %d %d\n",total1,total2);
242 
243 }
244 
static int i
Display * display
Definition: mapper.c:159
char qual[10]
Definition: subdisplay.c:33
Widget top_level
Definition: display_rec.c:5
void write_file(char *, int, struct pcp *)
Definition: write_file.c:5
printf("fbuf is %s\n", fbuf)
int j
Definition: mapp2h.h:48
int elev
Definition: mapp2h.h:48
char temp[9]
Definition: mapp2h.h:66
int k
Definition: mapp2h.h:48
int pcpn_time
Definition: mapper.c:83
int pcpn_time_step
Definition: mapper.c:75
int pcpn_day
Definition: mapper.c:83
Window window
Definition: mapper.c:190
Cursor watch_cursor
Definition: mapper.c:153
float value
struct pcp * pcp
Definition: mapper.c:140
int pcp_in_use[50]
Definition: mapper.c:78
struct hrap_grid * hrap_grid
Definition: mapper.c:142
int max
Definition: rateint.c:95
void render_t(int pcpn_day, int pcpn_time, int pcpn_time_step)
Definition: render_t.c:12
float lat
Definition: misc_new.h:673
float lon
Definition: misc_new.h:674
short int tindex[30]
Definition: misc_new.h:824
short int *** min
Definition: misc_new.h:814
short int maxi
Definition: misc.h:580
short int maxj
Definition: misc.h:581
struct coord ** coord
Definition: misc.h:584
struct gage ** gage
Definition: misc.h:585
short int ** elev
Definition: misc_new.h:815
short int *** max
Definition: misc_new.h:813
short int ** owner
Definition: misc_new.h:811
Definition: misc.h:596
short int ** value
Definition: misc.h:599
Definition: misc.h:296
float lat
Definition: misc.h:303
float lon
Definition: misc.h:304
float * min
Definition: misc_new.h:466
float * max
Definition: misc_new.h:465
int elev
Definition: misc.h:305
Definition: misc.h:264
struct ttn stn[1000]
Definition: misc_new.h:452
short int data
Definition: misc_new.h:400
struct tlevel * tlevel2
Definition: misc_new.h:411