Daily_QC
render_z.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 zdata zdata[10];
22 extern struct station zstation[500];
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_zstations;
31 int totals[5];
32 
33 for(i=0;i<5;i++)
34  totals[i]=0;
35 
36 XDefineCursor(display,window,watch_cursor);
37 XmUpdateDisplay(top_level);
38 
39 time_pos=pcpn_time;
40 
41 for(i=0;i<hrap_grid->maxi;i++) {
42 
43 for(j=0;j<hrap_grid->maxj;j++) {
44 
45  if(hrap_grid->owner[i][j]==-1) {
46 
47  pcp->value[i][j]=-9999;
48  continue;
49 
50  }
51 
52  value=0.0;
53  distance=0.0;
54  htotal=0;
55 
56  for(h=0;h<5;h++) {
57 
58  hh=hrap_grid->gage[i][j].zindex[h];
59 
60  if(zdata[pcpn_day].stn[hh].zlevel2[time_pos].data < 0 )
61  continue;
62 
63  if(zdata[pcpn_day].stn[hh].zlevel2[time_pos].qual != 5 &&
64  zdata[pcpn_day].stn[hh].zlevel2[time_pos].qual != 8 &&
65  zdata[pcpn_day].stn[hh].zlevel2[time_pos].qual != 2 )
66  continue;
67 
68  dist1=(double)(hrap_grid->coord[i][j].x-
69  zstation[hh].x);
70  dist2=(double)(hrap_grid->coord[i][j].y-
71  zstation[hh].y);
72 
73  dist=pow(dist1,2)+pow(dist2,2);
74 
75  if(dist < .00001)
76  dist=.00001;
77 
78  dist=1/dist;
79 
80  temp=zdata[pcpn_day].stn[hh].zlevel2[time_pos].data*dist;
81 
82  value=value+temp;
83 
84  distance=distance+dist;
85 
86  htotal++;
87 
88  }
89 
90 
91  if(htotal < 4) {
92 
93  value=0.0;
94  distance=0.0;
95  htotal=0;
96 
97  for(h=0;h<max_zstations;h++) {
98 
99  if(zdata[pcpn_day].stn[h].zlevel2[time_pos].data < 0 )
100  continue;
101 
102  if(zdata[pcpn_day].stn[h].zlevel2[time_pos].qual != 5 &&
103  zdata[pcpn_day].stn[h].zlevel2[time_pos].qual != 8 &&
104  zdata[pcpn_day].stn[h].zlevel2[time_pos].qual != 2)
105  continue;
106 
107  dist1=(double)(hrap_grid->coord[i][j].x-
108  zstation[h].x);
109  dist2=(double)(hrap_grid->coord[i][j].y-
110  zstation[h].y);
111 
112  dist=pow(dist1,2)+pow(dist2,2);
113 
114  if(dist < .00001)
115  dist=.00001;
116 
117  dist=1/dist;
118 
119  temp=zdata[pcpn_day].stn[h].zlevel2[time_pos].data*dist;
120 
121  value=value+temp;
122 
123  distance=distance+dist;
124 
125  htotal++;
126 
127  }
128 
129  }
130 
131  if(htotal == 0)
132  pcp->value[i][j]=-9999;
133 
134  else
135  pcp->value[i][j]=(int)(value/distance*100);
136 
137 
138  }
139 
140 }
141 
142 time_pos=100+pcpn_day*4+3-pcpn_time;
143 
144 pcp_in_use[time_pos]=1;
145 
146 write_file("pcp",time_pos,pcp);
147 
148 }
149 
int pcpn_time
Definition: daily_qc.c:248
struct station zstation[500]
Definition: daily_qc.c:196
int pcpn_time_step
Definition: daily_qc.c:238
int pcp_in_use[500]
Definition: daily_qc.c:243
Widget top_level
Definition: daily_qc.c:214
struct pcp * pcp
Definition: daily_qc.c:277
int pcpn_day
Definition: daily_qc.c:248
struct hrap_grid * hrap_grid
Definition: daily_qc.c:285
Display * display
Definition: daily_qc.c:228
int max_zstations
Definition: daily_qc.c:45
Window window
Definition: daily_qc.c:229
int isom
Definition: daily_qc.c:141
int method
Definition: daily_qc.c:254
Cursor watch_cursor
Definition: daily_qc.c:220
char qual[10]
Definition: display_data.c:29
void write_file(char *, int, struct pcp *)
void render_z(int pcpn_day, int pcpn_time, int pcpn_time_step)
Definition: render_z.c:12
short int y
Definition: misc.h:425
short int x
Definition: misc.h:424
short int zindex[30]
Definition: misc_new.h:823
short int maxi
Definition: misc.h:507
short int maxj
Definition: misc.h:508
struct coord ** coord
Definition: misc.h:511
struct gage ** gage
Definition: misc.h:512
short int ** owner
Definition: misc_new.h:811
Definition: misc.h:523
short int ** value
Definition: misc.h:526
Definition: misc.h:232
int x
Definition: misc.h:243
int y
Definition: misc.h:244
Definition: misc.h:200
struct ztn stn[500]
Definition: misc_new.h:442
float data
Definition: misc_new.h:357
struct zlevel * zlevel2
Definition: misc_new.h:394