Mapper
alert_rain.c
Go to the documentation of this file.
1 /* possible error returns
2 
3  -1 no report after begin time
4  -2 no report after end time
5  -3 time gap between begin time and first report after begin time too large
6  -4 data not reliable
7  -5 large gaps in data
8 
9  r->rn amount of rain
10  r->tdif time gap of end time and last report
11 
12  */
13 
14 #include "prototypes.h"
15 
16 alert_rain(struct stn_values *stn_values,int inum,
17  time_t tstart,time_t tstop,struct rainfall *r)
18 
19 {
20 
21 int j,eflag;
22 float fdif;
23 long tdif;
24 
25 r->rn=0.0;
26 r->rel=0;
27 r->obs=0;
28 r->tskips=0;
29 r->tdif=0L;
30 fdif=0.0;
31 
32 eflag=-1;
33 
34 for(j=0;j<inum;j++) {
35 
36  /* observation time before start time */
37 
38  if(stn_values[j].clock > tstart)
39  continue;
40 
41  if(r->obs==0 && (tstart - stn_values[j].clock) > r->maxtdif && fdif >r->maxgap) {
42 
43  r->tdif=tstart-stn_values[j].clock;
44  return(-3);
45 
46  }
47 
48  if(j==0 && (tstart - stn_values[j].clock) > r->maxtdif) {
49 
50  r->tdif=tstart-stn_values[j].clock;
51  return(-3);
52 
53  }
54 
55  if(j > 0) {
56 
57  tdif=stn_values[j-1].clock - stn_values[j].clock;
58  fdif=stn_values[j-1].value - stn_values[j].value;
59 
60  /* correction for cycles of 100 */
61 
62  if ( r->cycle==100 && fdif >= -4.00 && fdif < -2.00)
63  fdif=fdif+ 4.00;
64 
65  }
66 
67  if(stn_values[j].clock < tstop) {
68 
69  if(r->obs < 1 || fdif <= 0)
70  return(1);
71 
72  /*gross error check*/
73 
74  if(fdif > r->maxgap*2)
75  return(-5);
76 
77  /* more than 10 days gap */
78 
79  if((tstop-stn_values[j].clock) > r->maxtdif)
80  return(-5);
81 
82  r->rn=r->rn + fdif;
83 
84  if(fdif<=r->maxgap/5)
85  return(1);
86 
87  else
88  return(-5);
89 
90  }
91 
92  r->obs++;
93  eflag=-2;
94 
95  if(r->obs <= 1)
96  continue;
97 
98  if(tdif > r->maxtdif && fdif != 0)
99  r->tskips++;
100 
101 
102 
103  if(fdif < 0 || fdif >= r->maxgap) {
104 
105  r->rel++;
106  if(r->rel >= 2)
107  eflag=-4;
108 
109  }
110 
111  else
112  r->rn=r->rn+fdif;
113 
114  /* observation time after end time */
115 
116  }
117 
118 return(eflag);
119 
120 }
121 
alert_rain(struct stn_values *stn_values, int inum, time_t tstart, time_t tstop, struct rainfall *r)
Definition: alert_rain.c:16
int j
Definition: mapp2h.h:48
int maxtdif
Definition: hydro_data.h:24
float rn
Definition: hydro_data.h:18
float maxgap
Definition: hydro_data.h:26
int obs
Definition: hydro_data.h:20
int tskips
Definition: hydro_data.h:21
int tdif
Definition: hydro_data.h:22
int cycle
Definition: hydro_data.h:23
int rel
Definition: hydro_data.h:19
time_t clock
Definition: hydro_data.h:32
float value
Definition: hydro_data.h:35