Mapper
render_t6.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 struct pcp *spf;
29 extern struct pcp *tpf;
30 extern Window window;
31 extern Display *display;
32 extern int max_tstations;
33 float conv=.0174;
34 float df;
35 int k;
36 float a,b;
37 int total1,total2;
38 
39 total1=0;total2=0;
40 
41 XDefineCursor(display,window,watch_cursor);
42 XmUpdateDisplay(top_level);
43 
44 if(pcp_in_use[190+pcpn_day]== -1 ||
45  pcp_in_use[200+pcpn_day]== -1)
46  return;
47 
48 time_pos=pcpn_time;
49 
50 read_file("pcp",190+pcpn_day,spf);
51 read_file("pcp",200+pcpn_day,tpf);
52 
53 for(i=0;i<hrap_grid->maxi;i++) {
54 
55 for(j=0;j<hrap_grid->maxj;j++) {
56 
57  if(hrap_grid->owner[i][j]==-1) {
58 
59  pcp->value[i][j]=-9999;
60  continue;
61 
62  }
63 
64 
65  value=0.0;
66  distance=0.0;
67  htotal=0;
68 
69  for(h=0;h<20;h++) {
70 
71  hh=hrap_grid->gage[i][j].tindex[h];
72 
73  if(tdata[pcpn_day].stn[hh].tlevel2[time_pos].data ==-99 ||
74  tdata[pcpn_day].stn[hh].tlevel2[time_pos].a < -98)
75  continue;
76 
77  if(tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 0 &&
78  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 8 &&
79  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 6 &&
80  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 3 &&
81  tdata[pcpn_day].stn[hh].tlevel2[time_pos].qual != 2)
82  continue;
83 
84  if(tstation[hh].elev <= 0)
85  continue;
86 
87  dist1=hrap_grid->coord[i][j].lat-tstation[hh].lat;
88  dist2=(hrap_grid->coord[i][j].lon-tstation[hh].lon)*
89  cos((hrap_grid->coord[i][j].lat+tstation[hh].lat)/2*conv);
90 
91  dist=pow(dist1,2)+pow(dist2,2);
92 
93  dist=pow(dist,.5)*60;
94 
95  if(dist < .00001)
96  dist=.00001;
97 
98  df=50*abs(hrap_grid->elev[i][j]-tstation[hh].elev)/5280;
99 
100  dist=dist+df;
101 
102  dist=1/dist;
103 
104  temp=tdata[pcpn_day].stn[hh].tlevel2[time_pos].a*dist;
105 
106  value=value+temp;
107 
108  distance=distance+dist;
109 
110  htotal++;
111 
112  if(htotal ==5) {
113 
114  total1++;
115  break;
116 
117  }
118 
119  }
120 
121 
122  if(htotal < 5) {
123 
124  total2++;
125  value=0.0;
126  distance=0.0;
127  htotal=0;
128 
129  for(h=0;h<max_tstations;h++) {
130 
131  if(tdata[pcpn_day].stn[h].tlevel2[time_pos].data ==-99 ||
132  tdata[pcpn_day].stn[h].tlevel2[time_pos].a < -98)
133  continue;
134 
135  if(tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 0 &&
136  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 8 &&
137  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 6 &&
138  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 3 &&
139  tdata[pcpn_day].stn[h].tlevel2[time_pos].qual != 2)
140  continue;
141 
142  if(tstation[h].elev <= 0)
143  continue;
144 
145  dist1=hrap_grid->coord[i][j].lat-tstation[h].lat;
146  dist2=(hrap_grid->coord[i][j].lon-tstation[h].lon)*
147  cos((hrap_grid->coord[i][j].lat+tstation[h].lat)/2*conv);
148 
149  dist=pow(dist1,2)+pow(dist2,2);
150 
151  dist=pow(dist,.5)*60;
152 
153  if(dist < .00001)
154  dist=.00001;
155 
156  df=50*abs(hrap_grid->elev[i][j]-tstation[h].elev)/5280;
157 
158  dist=dist+df;
159 
160  dist=1/dist;
161 
162  temp=tdata[pcpn_day].stn[h].tlevel2[time_pos].a*dist;
163 
164  value=value+temp;
165 
166  distance=distance+dist;
167 
168  htotal++;
169 
170 
171  }
172 
173  }
174 
175  if(htotal == 0)
176  pcp->value[i][j]=-9999;
177 
178  else {
179 
180  a=value/distance;
181 
182  b=a*(float)(spf->value[i][j] - tpf->value[i][j])+
183  (float)tpf->value[i][j];
184 
185  pcp->value[i][j]=(int)b;
186 
187  if(spf->value[i][j]==-9999 || tpf->value[i][j] == -9999)
188  pcp->value[i][j]=-9999;
189 
190  }
191 
192  }
193 
194 }
195 
196 time_pos=150+pcpn_day*4+3-pcpn_time;
197 
198 pcp_in_use[time_pos]=1;
199 
200 write_file("pcp",time_pos,pcp);
201 
202 printf("totals are %d %d\n",total1,total2);
203 
204 }
205 
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
void read_file(char *, int, struct pcp *)
Definition: read_file.c:5
static double b
Definition: rat.c:135
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
struct pcp * spf
Definition: mapper.c:141
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
void render_t6(int pcpn_day, int pcpn_time, int pcpn_time_step)
Definition: render_t6.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 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 ** 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
int elev
Definition: misc.h:305
Definition: misc.h:264
struct ttn stn[1000]
Definition: misc_new.h:452
float a
Definition: misc_new.h:404
struct tlevel * tlevel2
Definition: misc_new.h:411