Mapper
domsat_rain.c
Go to the documentation of this file.
1 /* possible error returns
2 
3  rpt - structure of inum reports
4  inum - number of reports
5  tstart - starting time
6  tstop - ending time
7  r->maxgap - maximum data gap
8  r->maxtdif- maximum time gap
9  r - rain structure
10  r->rn - amount of rain
11  r->tdif- time gap of end time and last report
12 
13  error returns
14  1 good data
15  -1 no report after begin time
16  -2 no report after end time
17  -3 time gap between begin time and first report after begin time too large
18  -4 data not reliable
19  -5 large gaps in data
20 
21 
22  */
23 
24 #include "prototypes.h"
25 
26 int domsat_rain(struct stn_values *stn_values,int inum,
27  time_t tstart,time_t tstop,struct rainfall *r)
28 
29 {
30 
31 int j,eflag,mer,maxhours,sindex;
32 double fdif,mindif,pdif,svalue;
33 long tdif;
34 struct tm *tm;
35 
36 
37 mindif=.1;
38 r->rn=0.0;
39 r->rel=0;
40 r->obs=0;
41 r->tskips=0;
42 r->tdif=0L;
43 fdif=0.0;
44 maxhours=48;
45 sindex=0;
46 svalue=0.0;
47 
48 eflag=-1;
49 
50 for(j=0;j<inum;j++) {
51 
52  /* observation time before start time */
53  sindex=j;
54 
55  if(j > 0 && (stn_values[j-1].value - stn_values[j].value) > 0.0)
56  fdif=weigh(stn_values,j,inum,pdif,mindif,maxhours,&sindex,&svalue);
57 
58  if(stn_values[j].clock > tstart)
59  continue;
60 
61  if(j > 0) {
62 
63  tdif=stn_values[j-1].clock - stn_values[j].clock;
64  pdif=stn_values[j-1].value - stn_values[j].value;
65 
66  if(pdif > 0.0)
67  fdif=weigh(stn_values,j,inum,pdif,mindif,maxhours,&sindex,&svalue);
68 
69  else
70  fdif=0.0;
71 
72  if(pdif > 0)
73  tm=localtime(&stn_values[j].clock);
74 
75  }
76 
77  if(r->obs==0 || j==0)
78  r->tdif=tstart-stn_values[j].clock;
79 
80  if(r->obs==0 && (tstart - stn_values[j].clock) > r->firstdif && fdif >r->maxgap){
81 
82  r->tdif=tstart-stn_values[j].clock;
83  return(-3);
84 
85  }
86 
87  if(j==0 && (tstart - stn_values[j].clock) > r->firstdif) {
88 
89  r->tdif=tstart-stn_values[j].clock;
90  return(-3);
91 
92  }
93 
94 /* if(j==0 && tflag==1)
95  tstop=tstop-(tstart-stn_values[j].clock);
96 */
97 /* needed data is between two reports */
98 
99  if(j > 0 && r->obs==0 && stn_values[j].clock <= tstop) {
100 
101  if(fdif > r->maxgap)
102  return(-5);
103 
104  if(tdif <= r->maxtdif && fdif > 0.0)
105  r->rn=fdif/tdif*(tstart - tstop);
106 
107  return(1);
108 
109  }
110 
111 /* first piece of data is between two reports */
112 
113  if(j > 0 && r->obs==0) {
114 
115  if(fdif > r->maxgap)
116  return(-5);
117 
118  r->rn=fdif/tdif*(tstart - stn_values[j].clock);
119 
120  }
121 
122  /* observation after end time */
123 
124  if(stn_values[j].clock <= tstop) {
125 
126  if( fdif <= 0)
127  return(1);
128 
129  /*gross error check*/
130 
131  if(fdif > r->maxgap)
132  return(-5);
133 
134  /* more than 10 days gap */
135 
136  if((tstop-stn_values[j].clock) > r->maxtdif && fdif > r->maxgap)
137  return(-5);
138 
139  r->rn=r->rn+fdif/tdif*(stn_values[j-1].clock-tstop);
140 
141  return(1);
142  }
143 
144  /* split rain from previous observation into current */
145 
146  r->obs++;
147  eflag=-2;
148 
149  if(r->obs <= 1)
150  continue;
151 
152  if(tdif > r->maxtdif && fdif != 0)
153  r->tskips++;
154 
155  if(fdif < 0)
156  continue;
157 
158  if( fdif >= r->maxgap*2) {
159 
160  r->rel++;
161  if(r->rel >= 2)
162  eflag=-4;
163 
164  }
165 
166  else
167  r->rn=r->rn+fdif;
168 
169  }
170 
171 return(eflag);
172 
173 }
174 
int domsat_rain(struct stn_values *stn_values, int inum, time_t tstart, time_t tstop, struct rainfall *r)
Definition: domsat_rain.c:26
float weigh(struct stn_values *, int, int, double, double, int, int *, double *)
Definition: weigh.c:5
int j
Definition: mapp2h.h:48
int maxhours
Definition: mapper.c:57
float value
int maxtdif
Definition: hydro_data.h:24
float rn
Definition: hydro_data.h:18
float maxgap
Definition: hydro_data.h:26
int firstdif
Definition: hydro_data.h:25
int obs
Definition: hydro_data.h:20
int tskips
Definition: hydro_data.h:21
int tdif
Definition: hydro_data.h:22
int rel
Definition: hydro_data.h:19
time_t clock
Definition: hydro_data.h:32
float value
Definition: hydro_data.h:35