Mapper
snotel_rain.c
Go to the documentation of this file.
1 /* possible error returns
2 
3  stn_values - structure of inum reports
4  inum - number of reports
5  tstart - starting time
6  tstop - ending time
7  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 snotel_rain(struct stn_values *stn_values,int inum,
27  time_t tstart,time_t tstop,struct rainfall *r)
28 
29 
30 {
31 
32 int j,maxhours,eflag,sindex;
33 double fdif,mindif,pdif,svalue;
34 long tdif;
35 
36 r->rn=0.0;
37 r->rel=0;
38 r->obs=0;
39 r->tskips=0;
40 r->tdif=0L;
41 fdif=0.0;
42 mindif=.2;
43 maxhours=96;
44 eflag=-1;
45 
46 for(j=0;j<inum;j++) {
47 
48  /* observation time before start time */
49 
50  sindex=j;
51  if(j > 0 && (stn_values[j-1].value - stn_values[j].value) > 0.0) {
52  fdif=weigh(stn_values,j,inum,pdif,mindif,maxhours,&sindex,&svalue);
53 
54  }
55  if(stn_values[j].clock > tstart)
56  continue;
57 
58  if(j==0 && (tstart - stn_values[j].clock) > r->firstdif) {
59 
60  r->tdif=tstart-stn_values[j].clock;
61  return(-3);
62 
63  }
64  if(r->obs==0 && (tstart - stn_values[j].clock) > r->firstdif) {
65 
66  r->tdif=tstart-stn_values[j].clock;
67  return(-3);
68 
69  }
70 
71  if(j > 0) {
72 
73  tdif=stn_values[j-1].clock - stn_values[j].clock;
74  pdif=stn_values[j-1].value - stn_values[j].value;
75 
76 
77  if(pdif > 0.0)
78  fdif=weigh(stn_values,j,inum,pdif,mindif,maxhours,&sindex,&svalue);
79 
80  else
81  fdif=0.0;
82 
83  }
84 
85  if(stn_values[j].clock < tstop) {
86 
87  if(fdif <= 0)
88  return(1);
89 
90  if((tstop - stn_values[j].clock) > r->firstdif)
91  return(-1);
92 
93  if( fdif >= r->maxgap*2)
94  return(-5);
95 
96 
97  r->rn=r->rn+fdif/tdif*(stn_values[j-1].clock-tstop);
98 /*
99  r->rn=r->rn+fdif;
100 */
101  return(1);
102 
103  }
104 
105  r->obs++;
106  eflag=-2;
107 
108  if(r->obs <= 1)
109  continue;
110 
111  if(tdif > r->maxtdif && fdif != 0)
112  r->tskips++;
113 
114  if(fdif < 0)
115  continue;
116 
117  if( fdif >= r->maxgap*2) {
118 
119  r->rel++;
120  if(r->rel >= 2)
121  eflag=-4;
122 
123  }
124 
125  else
126  r->rn=r->rn+fdif;
127 
128 
129  }
130 return(eflag);
131 
132 }
133 
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 snotel_rain(struct stn_values *stn_values, int inum, time_t tstart, time_t tstop, struct rainfall *r)
Definition: snotel_rain.c:26
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