Mapper
get_fcst_values.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 static const char _Cn2[] = "loop2";
4 static const char _Cn1[] = "loop1";
5 #line 1 "get_fcst_values.ec"
6 #include "prototypes.h"
7 
8 int get_fcst_values(char *stn_id,char *shef,time_t abeg,time_t aend,
9  struct stn_values *stn_values)
10 {
11 
12 /* general variable definitions */
13 int i,k;
14 int nval=0;
15 int debug=1;
16 int loop1_err;
17 int loop2_err;
18 char *caller="get_fcst_values: ";
19 
20 struct tm *gm;
21 time_t acur,acur00;
22 
23 /* declare informix host variables */
24 /*
25  * exec sql begin declare section;
26  */
27 #line 19 "get_fcst_values.ec"
28 #line 20 "get_fcst_values.ec"
29  char id[6];
30  char pe1[2];
31  char pe2[2];
32  char dur[2];
33  char t[2];
34  char s[2];
35  char e[2];
36  char p[2];
37 int vcal_yr, ccal_yr;
38 int vmon, cmon;
39 int vzday, czday;
40 int ctime, vtime;
41 float value;
42 int b_year, b_month, b_day, b_hour, b_min, b_sec;
43 int e_year, e_month, e_day, e_hour, e_min, e_sec;
44 int b_time;
45 int e_time;
46 /*
47  * exec sql end declare section;
48  */
49 #line 37 "get_fcst_values.ec"
50 
51 
52  strcpy(id,stn_id);
53  strncpy(pe1,shef+0,1);
54  *(pe1+1)='\0';
55  strncpy(pe2,shef+1,1);
56  *(pe2+1)='\0';
57  strncpy(dur,shef+2,1);
58  *(dur+1)='\0';
59  strncpy(t,"F",1);
60  *(t+1)='\0';
61  strncpy(s,"Z",1);
62  *(s+1)='\0';
63  strncpy(e,shef+5,1);
64  *(e+1)='\0';
65  strncpy(p,shef+6,1);
66  *(p+1)='\0';
67 
68  if(debug)
69  {
70  gm=gmtime(&abeg);
71  b_year=gm->tm_year+1900;
72  b_month=gm->tm_mon+1;
73  b_day=gm->tm_mday;
74  b_hour=gm->tm_hour;
75  b_min=gm->tm_min;
76  b_sec=gm->tm_sec;
77  b_time=b_hour*10000+b_min*100+b_sec;
78 
79  gm=gmtime(&aend);
80  e_year=gm->tm_year+1900;
81  e_month=gm->tm_mon+1;
82  e_day=gm->tm_mday;
83  e_hour=gm->tm_hour;
84  e_min=gm->tm_min;
85  e_sec=gm->tm_sec;
86  e_time=e_hour*10000+e_min*100+e_sec;
87 
88  printf("%s %s%s%s%s%s\n"
89  "%d = %02d/%02d/%04d %02d:%02d\n"
90  "%d = %02d/%02d/%04d %02d:%02d\n",
91  id,pe1,pe2,dur,t,s,
92  abeg,b_month,b_day,b_year,b_hour,b_min,
93  aend,e_month,e_day,e_year,e_hour,e_min);
94  }
95 
96  /* find the latest creation date/time */
97 /*
98  * $declare loop1 cursor for select ccal_yr, cmon, czday, ctime
99  * from fval where id=$id and pe1=$pe1 and pe2=$pe2 and dur=$dur and
100  * t=$t and s=$s and e=$e and p=$p
101  * order by ccal_yr desc,
102  * cmon desc,
103  * czday desc,
104  * ctime desc;
105  */
106 #line 84 "get_fcst_values.ec"
107  {
108 #line 90 "get_fcst_values.ec"
109  static const char *sqlcmdtxt[] =
110 #line 90 "get_fcst_values.ec"
111  {
112 #line 90 "get_fcst_values.ec"
113  "select ccal_yr , cmon , czday , ctime from fval where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ? order by ccal_yr desc , cmon desc , czday desc , ctime desc",
114  0
115  };
116 #line 90 "get_fcst_values.ec"
117  static ifx_sqlvar_t _sqibind[] =
118  {
119  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
120  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
121  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
122  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
123  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
124  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
125  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
126  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
127 #line 90 "get_fcst_values.ec"
128  };
129  static ifx_sqlda_t _SD0 = { 8, _sqibind, {0}, 8, 0 };
130 #line 90 "get_fcst_values.ec"
131  _sqibind[0].sqldata = id;
132 #line 90 "get_fcst_values.ec"
133  _sqibind[1].sqldata = pe1;
134 #line 90 "get_fcst_values.ec"
135  _sqibind[2].sqldata = pe2;
136 #line 90 "get_fcst_values.ec"
137  _sqibind[3].sqldata = dur;
138 #line 90 "get_fcst_values.ec"
139  _sqibind[4].sqldata = t;
140 #line 90 "get_fcst_values.ec"
141  _sqibind[5].sqldata = s;
142 #line 90 "get_fcst_values.ec"
143  _sqibind[6].sqldata = e;
144 #line 90 "get_fcst_values.ec"
145  _sqibind[7].sqldata = p;
146 #line 90 "get_fcst_values.ec"
147 sqli_curs_decl_stat(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 512), _Cn1, sqlcmdtxt, &_SD0, (ifx_sqlda_t *)0, 0, (ifx_literal_t *)0, (ifx_namelist_t *)0, 2, 0, 0);
148 #line 90 "get_fcst_values.ec"
149  }
150  if(!sqlca.sqlcode)
151  {
152 /*
153  * $open loop1;
154  */
155 #line 93 "get_fcst_values.ec"
156  {
157 #line 93 "get_fcst_values.ec"
158  sqli_curs_open(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, (char *)0, (struct value *)0, 0, 0);
159 #line 93 "get_fcst_values.ec"
160  }
161  if(!sqlca.sqlcode)
162  {
163 /*
164  * $fetch next loop1 into $ccal_yr,$cmon,$czday,$ctime;
165  */
166 #line 96 "get_fcst_values.ec"
167  {
168 #line 96 "get_fcst_values.ec"
169  static ifx_sqlvar_t _sqobind[] =
170  {
171  { 102, sizeof(ccal_yr), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
172  { 102, sizeof(cmon), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
173  { 102, sizeof(czday), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
174  { 102, sizeof(ctime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
175 #line 96 "get_fcst_values.ec"
176  };
177  static ifx_sqlda_t _SD0 = { 4, _sqobind, {0}, 4, 0 };
178  static _FetchSpec _FS1 = { 0, 1, 0 };
179 #line 96 "get_fcst_values.ec"
180  _sqobind[0].sqldata = (char *) &ccal_yr;
181 #line 96 "get_fcst_values.ec"
182  _sqobind[1].sqldata = (char *) &cmon;
183 #line 96 "get_fcst_values.ec"
184  _sqobind[2].sqldata = (char *) &czday;
185 #line 96 "get_fcst_values.ec"
186  _sqobind[3].sqldata = (char *) &ctime;
187  sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, &_SD0, (char *)0, &_FS1);
188 #line 96 "get_fcst_values.ec"
189  }
190  if(!sqlca.sqlcode)
191  {
192 /*
193  * $declare loop2 cursor for
194  * select vcal_yr,vmon,vzday,vtime,value
195  * from fval
196  * where id=$id and
197  * pe1=$pe1 and pe2=$pe2 and dur=$dur and
198  * t=$t and s=$s and e=$e and p=$p and
199  * ccal_yr=$ccal_yr and cmon=$cmon and
200  * czday=$czday and ctime=$ctime
201  * order by vcal_yr, vmon, vzday, vtime;
202  */
203 #line 99 "get_fcst_values.ec"
204  {
205 #line 107 "get_fcst_values.ec"
206  static const char *sqlcmdtxt[] =
207 #line 107 "get_fcst_values.ec"
208  {
209 #line 107 "get_fcst_values.ec"
210  "select vcal_yr , vmon , vzday , vtime , value from fval where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ? and ccal_yr = ? and cmon = ? and czday = ? and ctime = ? order by vcal_yr , vmon , vzday , vtime",
211  0
212  };
213 #line 107 "get_fcst_values.ec"
214  static ifx_sqlvar_t _sqibind[] =
215  {
216  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
217  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
218  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
219  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
220  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
221  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
222  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
223  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
224  { 102, sizeof(ccal_yr), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
225  { 102, sizeof(cmon), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
226  { 102, sizeof(czday), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
227  { 102, sizeof(ctime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
228 #line 107 "get_fcst_values.ec"
229  };
230  static ifx_sqlda_t _SD0 = { 12, _sqibind, {0}, 12, 0 };
231 #line 107 "get_fcst_values.ec"
232  _sqibind[0].sqldata = id;
233 #line 107 "get_fcst_values.ec"
234  _sqibind[1].sqldata = pe1;
235 #line 107 "get_fcst_values.ec"
236  _sqibind[2].sqldata = pe2;
237 #line 107 "get_fcst_values.ec"
238  _sqibind[3].sqldata = dur;
239 #line 107 "get_fcst_values.ec"
240  _sqibind[4].sqldata = t;
241 #line 107 "get_fcst_values.ec"
242  _sqibind[5].sqldata = s;
243 #line 107 "get_fcst_values.ec"
244  _sqibind[6].sqldata = e;
245 #line 107 "get_fcst_values.ec"
246  _sqibind[7].sqldata = p;
247 #line 107 "get_fcst_values.ec"
248  _sqibind[8].sqldata = (char *) &ccal_yr;
249 #line 107 "get_fcst_values.ec"
250  _sqibind[9].sqldata = (char *) &cmon;
251 #line 107 "get_fcst_values.ec"
252  _sqibind[10].sqldata = (char *) &czday;
253 #line 107 "get_fcst_values.ec"
254  _sqibind[11].sqldata = (char *) &ctime;
255 #line 107 "get_fcst_values.ec"
256 sqli_curs_decl_stat(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn2, 512), _Cn2, sqlcmdtxt, &_SD0, (ifx_sqlda_t *)0, 0, (ifx_literal_t *)0, (ifx_namelist_t *)0, 2, 0, 0);
257 #line 107 "get_fcst_values.ec"
258  }
259 /*
260  * $open loop2;
261  */
262 #line 108 "get_fcst_values.ec"
263  {
264 #line 108 "get_fcst_values.ec"
265  sqli_curs_open(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn2, 768), (ifx_sqlda_t *)0, (char *)0, (struct value *)0, 0, 0);
266 #line 108 "get_fcst_values.ec"
267  }
268  if(!sqlca.sqlcode)
269  {
270  loop2_err=sqlca.sqlcode;
271  while(!loop2_err)
272  {
273 /*
274  * $fetch next loop2 into $vcal_yr,$vmon,$vzday,$vtime,$value;
275  */
276 #line 114 "get_fcst_values.ec"
277  {
278 #line 114 "get_fcst_values.ec"
279  static ifx_sqlvar_t _sqobind[] =
280  {
281  { 102, sizeof(vcal_yr), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
282  { 102, sizeof(vmon), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
283  { 102, sizeof(vzday), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
284  { 102, sizeof(vtime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
285  { 104, sizeof(value), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
286 #line 114 "get_fcst_values.ec"
287  };
288  static ifx_sqlda_t _SD0 = { 5, _sqobind, {0}, 5, 0 };
289  static _FetchSpec _FS1 = { 0, 1, 0 };
290 #line 114 "get_fcst_values.ec"
291  _sqobind[0].sqldata = (char *) &vcal_yr;
292 #line 114 "get_fcst_values.ec"
293  _sqobind[1].sqldata = (char *) &vmon;
294 #line 114 "get_fcst_values.ec"
295  _sqobind[2].sqldata = (char *) &vzday;
296 #line 114 "get_fcst_values.ec"
297  _sqobind[3].sqldata = (char *) &vtime;
298 #line 114 "get_fcst_values.ec"
299  _sqobind[4].sqldata = (char *) &value;
300  sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn2, 768), (ifx_sqlda_t *)0, &_SD0, (char *)0, &_FS1);
301 #line 114 "get_fcst_values.ec"
302  }
303  loop2_err=sqlca.sqlcode;
304  if(!loop2_err)
305  {
306  gm->tm_year=vcal_yr-1900;
307  gm->tm_mon=vmon-1;
308  gm->tm_mday=vzday;
309  gm->tm_hour=vtime/10000;
310  gm->tm_min=(vtime%1000)/100;
311  gm->tm_sec=0;
312  acur=mktime(gm)-28800L;
313  if(acur <= abeg && acur >= aend)
314  {
315  stn_values[nval].value = value;
316  stn_values[nval].qual = 'Z';
317  stn_values[nval].clock=acur;
318  stn_values[nval].zdate=10000*vcal_yr+100*vmon+vzday;
319  stn_values[nval].ztime=vtime;
320  nval++;
321  }
322  }
323  }
324  }
325  }
326  }
327  }
328 
329 if(debug)
330  printf("%s %s%s%s%s%s: %4d fcsts.\n",id,pe1,pe2,dur,t,s,nval);
331 return (nval);
332 }
333 
334 
335 #line 145 "get_fcst_values.ec"
static int i
struct sqlca_s sqlca
int get_fcst_values(char *stn_id, char *shef, time_t abeg, time_t aend, struct stn_values *stn_values)
static const char _Cn1[]
static const char _Cn2[]
int debug
Definition: hydro_data.h:53
printf("fbuf is %s\n", fbuf)
int k
Definition: mapp2h.h:48
float value
long sqlcode
Definition: db.c:44
char qual
Definition: hydro_data.h:36
time_t clock
Definition: hydro_data.h:32
float value
Definition: hydro_data.h:35