Mapper
render_pcp.c
Go to the documentation of this file.
1 /* Converts point precipitation data in struct pdata to hrap grid. The
2  20 closest stations 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 pdata pdata[10];
22 extern struct station station[3000];
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_stations;
31 int totals[5];
32 
33 
34 printf("in render_pcp\n");
35 
36 for(i=0;i<5;i++)
37  totals[i]=0;
38 
39 XDefineCursor(display,window,watch_cursor);
40 XmUpdateDisplay(top_level);
41 
42 if(pcpn_time_step==0)
43  time_pos=pcpn_time;
44 
45 else
46  time_pos=4;
47 
48 for(i=0;i<hrap_grid->maxi;i++) {
49 
50 for(j=0;j<hrap_grid->maxj;j++) {
51 
52  if(hrap_grid->owner[i][j]==-1) {
53 
54  pcp->value[i][j]=0;
55  continue;
56 
57  }
58 
59  value=0.0;
60  distance=0.0;
61  htotal=0;
62 
63  for(h=0;h<30;h++) {
64 
65  hh=hrap_grid->gage[i][j].index[h];
66 
67  if(pdata[pcpn_day].stn[hh].frain[time_pos].data < 0 ){
68  /* printf("no data\n");*/
69  continue;
70 };
71 
72  if(pdata[pcpn_day].stn[hh].frain[time_pos].qual != 0 &&
73  pdata[pcpn_day].stn[hh].frain[time_pos].qual != 8 &&
74  pdata[pcpn_day].stn[hh].frain[time_pos].qual != 6 &&
75  pdata[pcpn_day].stn[hh].frain[time_pos].qual != 3 &&
76  pdata[pcpn_day].stn[hh].frain[time_pos].qual != 4 &&
77  pdata[pcpn_day].stn[hh].frain[time_pos].qual != 2)
78  continue;
79 
80  dist1=(double)(hrap_grid->coord[i][j].x-
81  station[hh].x);
82  dist2=(double)(hrap_grid->coord[i][j].y-
83  station[hh].y);
84 
85  dist=pow(dist1,2)+pow(dist2,2);
86 
87  if(dist < .00001)
88  dist=.00001;
89 
90  dist=1/dist;
91 
92  temp=pdata[pcpn_day].stn[hh].frain[time_pos].data*dist;
93 
94  if(method==2 && station[hh].isoh[isom] > 0)
95  temp=temp*(float)hrap_grid->isoh[isom][i][j]/
96  (station[hh].isoh[isom] * 25.4);
97 
98  if(method==2 && station[hh].isoh[isom] <= 0)
99 
100  continue;
101 
102  value=value+temp;
103 
104  distance=distance+dist;
105 
106  htotal++;
107 
108  if(htotal ==10)
109  break;
110 
111  }
112 
113 
114  if(htotal < 4) {
115 
116  value=0.0;
117  distance=0.0;
118  htotal=0;
119 
120  for(h=0;h<max_stations;h++) {
121 
122  if(pdata[pcpn_day].stn[h].frain[time_pos].data < 0 )
123  continue;
124 
125  if(pdata[pcpn_day].stn[h].frain[time_pos].qual != 0 &&
126  pdata[pcpn_day].stn[h].frain[time_pos].qual != 8 &&
127  pdata[pcpn_day].stn[h].frain[time_pos].qual != 6 &&
128  pdata[pcpn_day].stn[h].frain[time_pos].qual != 3 &&
129  pdata[pcpn_day].stn[h].frain[time_pos].qual != 4 &&
130  pdata[pcpn_day].stn[h].frain[time_pos].qual != 2)
131  continue;
132 
133  dist1=(double)(hrap_grid->coord[i][j].x-
134  station[h].x);
135  dist2=(double)(hrap_grid->coord[i][j].y-
136  station[h].y);
137 
138  dist=pow(dist1,2)+pow(dist2,2);
139 
140  if(dist < .00001)
141  dist=.00001;
142 
143  dist=1/dist;
144 
145  temp=pdata[pcpn_day].stn[h].frain[time_pos].data*dist;
146 
147  if(method==2 && station[h].isoh[isom] <= 0)
148  continue;
149 
150  if(method==2 && station[h].isoh[isom] > 0)
151  temp=temp*(float)hrap_grid->isoh[isom][i][j]/
152  (station[h].isoh[isom]*25.4);
153 
154  value=value+temp;
155 
156  distance=distance+dist;
157 
158  htotal++;
159 
160  }
161 
162 }
163 
164  if(htotal == 0)
165  pcp->value[i][j]=0;
166 
167  else
168  pcp->value[i][j]=(int)(value/distance*100);
169 
170  if(pcp->value[i][j] < .01)
171  pcp->value[i][j]=0;
172 
173  }
174 
175 }
176 
177 if(pcpn_time_step==0)
178  time_pos=pcpn_day*4+3-pcpn_time;
179 
180 else
181  time_pos=40+pcpn_day;
182 
183 pcp_in_use[time_pos]=1;
184 
185 write_file("pcp",time_pos,pcp);
186 
187 }
188 
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 render_pcp(int pcpn_day, int pcpn_time, int pcpn_time_step)
Definition: render_pcp.c:12
printf("fbuf is %s\n", fbuf)
int j
Definition: mapp2h.h:48
char temp[9]
Definition: mapp2h.h:66
int pcpn_time
Definition: mapper.c:83
int pcpn_time_step
Definition: mapper.c:75
int max_stations
Definition: mapper.c:64
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
short int y
Definition: misc.h:498
short int x
Definition: misc.h:497
short int index[20]
Definition: misc.h:592
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 *** isoh
Definition: misc.h:586
short int ** owner
Definition: misc_new.h:811
Definition: misc.h:538
Definition: misc.h:596
short int ** value
Definition: misc.h:599
Definition: misc.h:280
struct stn stn[1500]
Definition: misc.h:286
float data
Definition: misc.h:257
Definition: misc.h:296
int x
Definition: misc.h:307
float isoh[24]
Definition: misc.h:298
int y
Definition: misc.h:308
Definition: misc.h:264
struct rain frain[5]
Definition: misc.h:267