Daily_QC
read_snow.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 int read_snow(char *fname,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 
25  for(k=0;k<max_stations;k++) {
26 
27  for(m=0;m<5;m++) {
28 
29  pdata[i].stn[k].srain[m].data=-99;
30  pdata[i].stn[k].srain[m].qual=-99;
31  pdata[i].stn[k].sflag[m]=-1;
32 
33  }
34 
35  }
36 
37  if(fr==NULL) {
38 
39  return(-1);
40 
41  }
42 
43  for(;;) {
44 
45  bad:
46  p=fgets(kbuf,100,fr);
47 
48 
49 
50  if(p==NULL)
51  break;
52 
53  if(kbuf[0]==':')
54  continue;
55 
56  ier=sscanf(&kbuf[2],"%s %s %s",hb5,datbuf,parmbuf);
57  if(ier==0)
58  continue;
59 
60  p=strchr(parmbuf,'/');
61  if(p==NULL)
62  continue;
63 
64  pc=*(p+5);
65 
66  for(j=0;j<max_stations;j++) {
67 
68  if(strcmp(hb5,station[j].hb5)==0 &&
69  pc==station[j].parm[4]) {
70 
71  break;
72 
73  }
74 
75  }
76 
77  if(j==max_stations) {
78 
79  continue;
80 
81  }
82 
83  p=strchr(kbuf,'/');
84  if(p==NULL)
85  continue;
86 
87  q=strchr(p,' ');
88  if(p==NULL)
89  continue;
90 
91  maxk=5;
92  startk=4;
93 
94  for(k=startk;k<maxk;k++) {
95 
96  pdata[i].stn[j].srain[k].qual=0;
97 
98  if((p=strchr(q,'/'))==NULL &&
99  (p=strchr(q,'\n'))==NULL)
100  goto bad;
101 
102  *p=0;
103 
104  strcpy(buf,q);
105 
106  if((p=strchr(buf,'.'))==NULL) {
107 
108  if((p=strchr(buf,'m'))==NULL &&
109  (p=strchr(buf,'M'))==NULL) {
110 
111  pdata[i].stn[j].srain[k].data=-1;
112  pdata[i].stn[j].srain[k].qual=-1;
113 
114  }
115 
116  }
117 
118  else {
119 
120  pdata[i].stn[j].srain[k].data=atof(buf);
121 
122  qual=8;
123 
124  break;
125 
126  }
127 
128  }
129 
130 
131  }
132 
133 
134 
135 fclose(fr);
136 
137 return(1);
138 
139 }
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
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
int read_snow(char *fname, int i)
Definition: read_snow.c:3
Definition: misc.h:397
Definition: misc.h:216
struct stn stn[1500]
Definition: misc.h:222
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
short int * sflag
Definition: misc_new.h:385
struct rain * srain
Definition: misc_new.h:386