Daily_QC
read_precip_a.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 int read_precip_a(char *fname,time_t tget,int i)
4 
5 {
6  extern struct dval dval;
7  extern struct pdata pdata[10];
8  extern struct station station[3000];
9  extern int max_stations;
10  FILE *fr;
11  int j,k,ier,m,qual,len,len2;
12  char kbuf[100],*p,*q,*r,buf[100],hb5[10];
13  long t,u;
14  float conv=.0174;
15  double lat,lon;
16  int number_found[5];
17  char parm[10];
18  int type;
19  char pc,datbuf[50],parmbuf[50];
20  int maxk,startk;
21  struct tm *gm;
22 
23  fr=fopen(fname,"r");
24  pdata[i].data_time=tget;
25 
26  gm=gmtime(&tget);
27 
28  pdata[i].ztime=(gm->tm_year+1900)*10000+(gm->tm_mon+1)*100+gm->tm_mday;
29 
30  printf("ztime %d\n", pdata[i].ztime);
31 
32  for(j=0;j<5;j++)
33  number_found[j]=0;
34 
35  for(k=0;k<max_stations;k++) {
36 
37  for(m=0;m<5;m++) {
38 
39  pdata[i].stn[k].rain[m].data=-1;
40  pdata[i].stn[k].rain[m].qual=-1;
41 
42  }
43 
44  }
45 
46 if(fr==NULL) {
47 
48  for(k=0;k<5;k++)
49  pdata[i].used[k]=0;
50 
51  pdata[i].level=0;
52 
53  return(-1);
54 
55  }
56 
57  for(k=0;k<5;k++)
58  pdata[i].used[k]=1;
59 
60  pdata[i].level=1;
61 
62 /* initialize structure */
63 
64  for(;;) {
65 
66  bad:
67  p=fgets(kbuf,100,fr);
68  if(p==NULL)
69  break;
70 
71  if(kbuf[0]==':')
72  continue;
73 
74  if(kbuf[0]=='.' && kbuf[1]=='E')
75  type=1;
76 
77  if(kbuf[0]=='.' && kbuf[1]=='A')
78  type=0;
79 
80  ier=sscanf(&kbuf[2],"%s %s %s",hb5,datbuf,parmbuf);
81  if(ier==0)
82  continue;
83 
84  p=strchr(parmbuf,'/');
85  if(p==NULL)
86  continue;
87 
88  pc=*(p+5);
89 
90  for(j=0;j<max_stations;j++) {
91 
92  if(strcmp(hb5,station[j].hb5)==0 &&
93  pc==station[j].parm[4]) {
94 
95  break;
96 
97  }
98 
99  }
100 
101  if(j==max_stations) {
102 
103  continue;
104 
105  }
106 
107  if(type==0) {
108 
109  p=strchr(kbuf,'/');
110  if(p==NULL)
111  continue;
112 
113  q=strchr(p,' ');
114  if(p==NULL)
115  continue;
116 
117  maxk=5;
118  startk=4;
119 
120  }
121 
122  else if(type==1) {
123 
124  q=kbuf;
125  for(k=0;k<3;k++) {
126 
127  p=strchr(q,'/');
128  if(p==NULL)
129  break;
130 
131  q=p+1;
132 
133  }
134 
135  if(k!=3)
136  continue; /* missing */
137 
138  maxk=4;
139  startk=0;
140 
141  }
142 
143  for(k=startk;k<maxk;k++) {
144 
145  pdata[i].stn[j].rain[k].qual=0;
146 
147  if((p=strchr(q,'/'))==NULL &&
148  (p=strchr(q,'\n'))==NULL)
149  goto bad;
150 
151  *p=0;
152 
153  strcpy(buf,q);
154 
155  if((p=strchr(buf,'.'))==NULL) {
156 
157  if((p=strchr(buf,'m'))!=NULL ||
158  (p=strchr(buf,'M'))!=NULL) {
159 
160  pdata[i].stn[j].rain[k].data=-1;
161  pdata[i].stn[j].rain[k].qual=-1;
162 
163  }
164 
165  else {
166 
167 
168  pdata[i].stn[j].rain[k].data=-2;
169 
170  }
171 
172  }
173 
174  else {
175 
176  number_found[k]++;
177 
178  pdata[i].stn[j].rain[k].data=atof(buf);
179 
180  r=p+3;
181  qual=8;
182  while(*r != 0) {
183 
184  if(*r != ' '){
185 
186  if(*r=='S')
187  qual=8;
188 
189  else if(*r=='F')
190  qual=1;
191 
192  else if(*r=='L')
193  qual=2;
194 
195  else if(*r=='Q')
196  qual=3;
197 
198  else if(*r=='F')
199  qual=4;
200 
201  else if(*r=='V')
202  qual=8;
203 
204  else if(*r=='E')
205  qual=5;
206 
207  else if(*r=='T')
208  qual=6;
209 
210  pdata[i].stn[j].rain[k].qual=qual;
211 
212  break;
213 
214  }
215 
216  else
217  r++;
218 
219  }
220 
221 
222  }
223 
224  p=strchr(q,0);
225  q=p+1;
226 
227  }
228 
229  }
230 
231 
232 fclose(fr);
233 
234 for(j=0;j<5;j++) {
235 
236  if(number_found[j] == 0)
237  pdata[i].used[j]=0;
238 
239  }
240 
241 
242 return(1);
243 
244 }
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
int max_stations
Definition: daily_qc.c:199
char t
Definition: build_list.c:122
char type[5]
Definition: daily_qc.c:98
char qual[10]
Definition: display_data.c:29
fr
Definition: jnk.c:17
printf("pcp %d\n", pcp_in_use[103])
int read_precip_a(char *fname, time_t tget, int i)
Definition: read_precip_a.c:3
Definition: misc.h:397
Definition: misc.h:216
time_t data_time
Definition: misc.h:218
int ztime
Definition: misc_new.h:427
int used[5]
Definition: misc.h:219
struct stn stn[1500]
Definition: misc.h:222
int level
Definition: misc.h:221
float data
Definition: misc.h:193
short int qual
Definition: misc.h:194
Definition: misc.h:232
float lat
Definition: misc.h:239
float lon
Definition: misc.h:240
char parm[10]
Definition: misc.h:237
char hb5[10]
Definition: misc.h:235
struct rain rain[5]
Definition: misc.h:202