Mapper
ma_qtrly.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 #line 1 "ma_qtrly.ec"
4 #include "prototypes_new.h"
5 /*
6  * EXEC SQL include sqlca.h;
7  */
8 #line 2 "ma_qtrly.ec"
9 
10 #line 2 "ma_qtrly.ec"
11 #line 1 "/opt/informix/incl/esql/sqlca.h"
12 /****************************************************************************
13  *
14  * Licensed Material - Property Of IBM
15  *
16  * "Restricted Materials of IBM"
17  *
18  * IBM Informix Client SDK
19  * Copyright IBM Corporation 1997, 2008. All rights reserved.
20  *
21  * Title: sqlca.h
22  * Description: SQL Control Area
23  *
24  ***************************************************************************
25  */
26 
27 #ifndef SQLCA_INCL
28 #define SQLCA_INCL
29 
30 #include "ifxtypes.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct sqlca_s
37  {
38  int4 sqlcode;
39 #ifdef DB2CLI
40  char sqlerrm[600]; /* error message parameters */
41 #else /* DB2CLI */
42  char sqlerrm[72]; /* error message parameters */
43 #endif /* DB2CLI */
44  char sqlerrp[8];
45  int4 sqlerrd[6];
46  /* 0 - estimated number of rows returned */
47  /* 1 - serial value after insert or ISAM error code */
48  /* 2 - number of rows processed */
49  /* 3 - estimated cost */
50  /* 4 - offset of the error into the SQL statement */
51  /* 5 - rowid after insert */
52 #ifdef _FGL_
53  char sqlawarn[8];
54 #else
55  struct sqlcaw_s
56  {
57  char sqlwarn0; /* = W if any of sqlwarn[1-7] = W */
58  char sqlwarn1; /* = W if any truncation occurred or
59  database has transactions or
60  no privileges revoked */
61  char sqlwarn2; /* = W if a null value returned or
62  ANSI database */
63  char sqlwarn3; /* = W if no. in select list != no. in into list or
64  turbo backend or no privileges granted */
65  char sqlwarn4; /* = W if no where clause on prepared update, delete or
66  incompatible float format */
67  char sqlwarn5; /* = W if non-ANSI statement */
68  char sqlwarn6; /* = W if server is in data replication secondary mode */
69  char sqlwarn7; /* = W if database locale is different from proc_locale
70  = W if backend XPS and if explain avoid_execute is set
71  (for select, insert, delete and update only)
72  */
73  } sqlwarn;
74 #endif
76 
77 /* NOTE: 4gl assumes that the sqlwarn structure can be defined as
78  * sqlawarn -- an 8 character string, because single-char
79  * variables are not recognized in 4gl.
80  *
81  * If this structure should change, the code generated by 4gl compiler
82  * must also change
83  */
84 
85 #define SQLNOTFOUND 100
86 
87 #ifndef IFX_THREAD
88 #ifdef DB2CLI
89 #define sqlca ifmxsqlca
90 extern struct sqlca_s sqlca;
91 #else /* DB2CLI */
92 extern struct sqlca_s sqlca;
93 #endif /* DB2CLI */
94 
95 #ifndef DRDAHELP
96 extern int4 SQLCODE;
97 #endif
98 
99 extern char SQLSTATE[];
100 #else /* IFX_THREAD */
101 extern int4 * ifx_sqlcode(void);
102 extern struct sqlca_s * ifx_sqlca(void);
103 /* ifx_sqlstate() declared in sqlhdr.h */
104 #define SQLCODE (*(ifx_sqlcode()))
105 #define SQLSTATE ((char *)(ifx_sqlstate()))
106 #define sqlca (*(ifx_sqlca()))
107 #endif /* IFX_THREAD */
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* SQLCA_INCL */
114 
115 #line 103 "/opt/informix/incl/esql/sqlca.h"
116 #line 3 "ma_qtrly.ec"
117 
118 /*
119  * EXEC SQL BEGIN DECLARE SECTION;
120  */
121 #line 4 "ma_qtrly.ec"
122 #line 5 "ma_qtrly.ec"
123 int eyr, emo, edy;
124 int byr, bmo, bdy;
125 extern struct ma_qrtly_rec
126  {
127  char id[6];
128  char drain[2];
129  char pos[2];
130  char cgroup[2];
131  char pe1[2];
132  char pe2[2];
133  char dur[2];
134  char t[2];
135  char s[2];
136  char e[2];
137  char p[2];
138  int cal_yr;
139  int mon;
140  int zday;
141  double z00;
142  double z06;
143  double z12;
144  double z18;
145  char qz00[2];
146  char qz06[2];
147  char qz12[2];
148  char qz18[2];
150 /*
151  * EXEC SQL END DECLARE SECTION;
152  */
153 #line 36 "ma_qtrly.ec"
154 
155 
156 extern struct data_rec {
157  char id[9];
158  char source[9];
159  char pe1;
160  char pe2;
161  char dur;
162  char t;
163  char s;
164  char e;
165  char p;
166  int zdate;
167  int ztime;
168  int czdate;
169  int cztime;
170  int idur;
171  double codp;
172  char lwal;
173  int idote;
174  int irev;
175  double value;
176  double values[96];
177  char lwals[96];
178  char pedtsep[8];
180 
182 
183 int ma_qtrly(char *hb5,char *dparm,char *parm,struct stim begin_date,
184  struct stim end_date, char *qual, struct stn_values *stn_values)
185 
186 {
187 
188 int i,jtotal,k,atime;
189 int etime,btime;
190 int hour,min;
191 int zdate,hh,qlen;
192 
193 /*
194  * EXEC SQL BEGIN DECLARE SECTION;
195  */
196 #line 75 "ma_qtrly.ec"
197 #line 76 "ma_qtrly.ec"
198 int edate, bdate;
199 int year, month, day;
200  char sparm[10];
201  char pe1[2], pe2[2], dur[2], t[2], s[2], e[2], p[2], shb5[10];
202  char drain[2], pos[2], cgroup[2];
203 /*
204  * EXEC SQL END DECLARE SECTION;
205  */
206 #line 82 "ma_qtrly.ec"
207 
208 
209 qlen=strlen(qual);
210 
211 drain[1]=0;
212 pos[1]=0;
213 cgroup[1]=0;
214 
215 drain[0]=dparm[0];
216 pos[0]=dparm[1];
217 cgroup[0]=dparm[2];
218 
219 pe1[1]=0;
220 pe2[1]=0;
221 dur[1]=0;
222 t[1]=0;
223 s[1]=0;
224 e[1]=0;
225 p[1]=0;
226 
227 strcpy(shb5,hb5);
228 pe1[0]=parm[0];
229 pe2[0]=parm[1];
230 dur[0]=parm[2];
231 t[0]=parm[3];
232 s[0]=parm[4];
233 e[0]=parm[5];
234 p[0]=parm[6];
235 
236 eyr=end_date.year;
237 emo=end_date.month;
238 edy=end_date.day;
239 etime=end_date.hour*10000+
240  end_date.minute*100;
241 
242 byr=begin_date.year;
243 bmo=begin_date.month;
244 bdy=begin_date.day;
245 btime=begin_date.hour*10000+
246  begin_date.minute*100;
247 
248 year=byr;
249 month=bmo;
250 day=bdy;
251 
252 jtotal=0;
253 
254 for(;;) {
255 
256 /*
257  * EXEC SQL select *
258  * into :ma_qtrly_rec
259  * from maqtrly
260  * where id=:shb5 and
261  * pe1=:pe1 and
262  * pe2=:pe2 and
263  * dur=:dur and
264  * t=:t and
265  * s=:s and
266  * e=:e and
267  * p=:p and
268  * drain=:drain and
269  * pos=:pos and
270  * cgroup=:cgroup and
271  * cal_yr=:year and
272  * mon=:month and
273  * zday=:day;
274  */
275 #line 131 "ma_qtrly.ec"
276  {
277 #line 147 "ma_qtrly.ec"
278  static const char *sqlcmdtxt[] =
279 #line 147 "ma_qtrly.ec"
280  {
281 #line 147 "ma_qtrly.ec"
282  "select * from maqtrly where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ? and drain = ? and pos = ? and cgroup = ? and cal_yr = ? and mon = ? and zday = ?",
283  0
284  };
285 #line 147 "ma_qtrly.ec"
286 static ifx_cursor_t _SQ0 = {0};
287  static ifx_sqlvar_t _sqibind[] =
288  {
289  { 100, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
290  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
291  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
292  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
293  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
294  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
295  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
296  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
297  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
298  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
299  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
300  { 102, sizeof(year), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
301  { 102, sizeof(month), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
302  { 102, sizeof(day), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
303 #line 147 "ma_qtrly.ec"
304  };
305  static ifx_sqlvar_t _sqobind[] =
306  {
307  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
308  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
309  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
310  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
311  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
312  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
313  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
314  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
315  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
316  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
317  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
318  { 102, sizeof((ma_qtrly_rec).cal_yr), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
319  { 102, sizeof((ma_qtrly_rec).mon), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
320  { 102, sizeof((ma_qtrly_rec).zday), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
321  { 105, sizeof((ma_qtrly_rec).z00), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
322  { 105, sizeof((ma_qtrly_rec).z06), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
323  { 105, sizeof((ma_qtrly_rec).z12), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
324  { 105, sizeof((ma_qtrly_rec).z18), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
325  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
326  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
327  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
328  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
329 #line 147 "ma_qtrly.ec"
330  };
331 #line 147 "ma_qtrly.ec"
332  _sqibind[0].sqldata = shb5;
333 #line 147 "ma_qtrly.ec"
334  _sqibind[1].sqldata = pe1;
335 #line 147 "ma_qtrly.ec"
336  _sqibind[2].sqldata = pe2;
337 #line 147 "ma_qtrly.ec"
338  _sqibind[3].sqldata = dur;
339 #line 147 "ma_qtrly.ec"
340  _sqibind[4].sqldata = t;
341 #line 147 "ma_qtrly.ec"
342  _sqibind[5].sqldata = s;
343 #line 147 "ma_qtrly.ec"
344  _sqibind[6].sqldata = e;
345 #line 147 "ma_qtrly.ec"
346  _sqibind[7].sqldata = p;
347 #line 147 "ma_qtrly.ec"
348  _sqibind[8].sqldata = drain;
349 #line 147 "ma_qtrly.ec"
350  _sqibind[9].sqldata = pos;
351 #line 147 "ma_qtrly.ec"
352  _sqibind[10].sqldata = cgroup;
353 #line 147 "ma_qtrly.ec"
354  _sqibind[11].sqldata = (char *) &year;
355 #line 147 "ma_qtrly.ec"
356  _sqibind[12].sqldata = (char *) &month;
357 #line 147 "ma_qtrly.ec"
358  _sqibind[13].sqldata = (char *) &day;
359 #line 147 "ma_qtrly.ec"
360  _sqobind[0].sqldata = (ma_qtrly_rec).id;
361 #line 147 "ma_qtrly.ec"
362  _sqobind[1].sqldata = (ma_qtrly_rec).drain;
363 #line 147 "ma_qtrly.ec"
364  _sqobind[2].sqldata = (ma_qtrly_rec).pos;
365 #line 147 "ma_qtrly.ec"
366  _sqobind[3].sqldata = (ma_qtrly_rec).cgroup;
367 #line 147 "ma_qtrly.ec"
368  _sqobind[4].sqldata = (ma_qtrly_rec).pe1;
369 #line 147 "ma_qtrly.ec"
370  _sqobind[5].sqldata = (ma_qtrly_rec).pe2;
371 #line 147 "ma_qtrly.ec"
372  _sqobind[6].sqldata = (ma_qtrly_rec).dur;
373 #line 147 "ma_qtrly.ec"
374  _sqobind[7].sqldata = (ma_qtrly_rec).t;
375 #line 147 "ma_qtrly.ec"
376  _sqobind[8].sqldata = (ma_qtrly_rec).s;
377 #line 147 "ma_qtrly.ec"
378  _sqobind[9].sqldata = (ma_qtrly_rec).e;
379 #line 147 "ma_qtrly.ec"
380  _sqobind[10].sqldata = (ma_qtrly_rec).p;
381 #line 147 "ma_qtrly.ec"
382  _sqobind[11].sqldata = (char *) &(ma_qtrly_rec).cal_yr;
383 #line 147 "ma_qtrly.ec"
384  _sqobind[12].sqldata = (char *) &(ma_qtrly_rec).mon;
385 #line 147 "ma_qtrly.ec"
386  _sqobind[13].sqldata = (char *) &(ma_qtrly_rec).zday;
387 #line 147 "ma_qtrly.ec"
388  _sqobind[14].sqldata = (char *) &(ma_qtrly_rec).z00;
389 #line 147 "ma_qtrly.ec"
390  _sqobind[15].sqldata = (char *) &(ma_qtrly_rec).z06;
391 #line 147 "ma_qtrly.ec"
392  _sqobind[16].sqldata = (char *) &(ma_qtrly_rec).z12;
393 #line 147 "ma_qtrly.ec"
394  _sqobind[17].sqldata = (char *) &(ma_qtrly_rec).z18;
395 #line 147 "ma_qtrly.ec"
396  _sqobind[18].sqldata = (ma_qtrly_rec).qz00;
397 #line 147 "ma_qtrly.ec"
398  _sqobind[19].sqldata = (ma_qtrly_rec).qz06;
399 #line 147 "ma_qtrly.ec"
400  _sqobind[20].sqldata = (ma_qtrly_rec).qz12;
401 #line 147 "ma_qtrly.ec"
402  _sqobind[21].sqldata = (ma_qtrly_rec).qz18;
403 #line 147 "ma_qtrly.ec"
404  sqli_slct(ESQLINTVERSION, &_SQ0,sqlcmdtxt,14,_sqibind,22,_sqobind,0,(ifx_literal_t *)0,(ifx_namelist_t *)0,0);
405 #line 147 "ma_qtrly.ec"
406  }
407 
408 /* union
409 
410  select *
411  into :ma_qtrly_rec
412  from calmaqtrly
413  where id=:shb5 and
414  pe1=:pe1 and
415  pe2=:pe2 and
416  dur=:dur and
417  t=:t and
418  s=:s and
419  e=:e and
420  p=:p and
421  drain=:drain and
422  pos=:pos and
423  cgroup=:cgroup and
424  cal_yr=:year and
425  mon=:month and
426  zday=:day;*/
427 
428 
429 
430  if(sqlca.sqlcode < 0)
431  return(sqlca.sqlcode);
432 
433  if(sqlca.sqlcode == 0) {
434 
435  get_ma06_array();
436 
437  for(k=3;k>=0;k--) {
438 
439  hour=k;
440  atime=hour*60000;
442 
443  if(year==eyr && month==emo && day==edy &&
444  atime < etime)
445  break;
446 
447  if(year==byr && month==bmo && day==bdy &&
448  atime > btime)
449  continue;
450 
451  if(data_record.values[k] < -98)
452  continue;
453 
455  stn_values[jtotal].zdate=zdate;
456  stn_values[jtotal].qual= data_record.lwals[k];
457  stn_values[jtotal].ztime=atime;
458 
459  jtotal++;
460 
461  }
462 
463  }
464 
465 
466  if(jtotal > 9600)
467  break;
468 
469  if(year==eyr && month==emo && day==edy)
470  break;
471 
473 
474  }
475 
476 
477 return(jtotal);
478 
479 }
480 
482 {
483 
492 
493  return(0);
494 }
495 
496 void change_datemaq(int *year,int *month, int*day)
497 
498 {
499 
500 extern int mday[];
501 
502 char buf[10];
503 XmString btn_text;
504 Arg args[10];
505 
506 if (!((*year)%4))
507  mday[1]=29;
508 else
509  mday[1]=28;
510 
511 /*
512 if ((*year)==1972 || (*year)==1976 || (*year)==1980 ||
513  (*year)==1984 || (*year)==1988 || (*year)==1992 ||
514  (*year)==1996 || (*year)==2000 || (*year)==2004 ||
515  (*year)==2008 || (*year)==2012 || (*year)==2016)
516  mday[1]=29;
517 else
518  mday[1]=28;
519 */
520 
521 (*day)--;
522 
523 if(*day <= 0) {
524 
525  (*month)--;
526  if(*month==0) {
527 
528  (*year)--;
529  *month=12;
530 
531  }
532 
533  *day=mday[*month-1];
534 
535  }
536 
537 else if(*day > mday[*month-1]) {
538 
539  *(month)++;
540 
541  if(*month > 12) {
542 
543  (*year)++;
544  *month=1;
545 
546  }
547 
548  *day=1;
549 
550  }
551 
552 
553 }
554 
555 
556 
557 
558 #line 297 "ma_qtrly.ec"
static int i
int hour
Definition: display_data.c:26
int day
Definition: display_data.c:26
int year
Definition: display_data.c:26
char qual[10]
Definition: subdisplay.c:33
int month
Definition: display_data.c:26
int mday[]
Definition: fmap_qtrly.c:519
char * mon[]
struct stat buf
Definition: is_file_closed.c:8
int emo
Definition: ma_qtrly.c:123
struct data_rec data_record
int bdy
Definition: ma_qtrly.c:124
int ma_qtrly(char *hb5, char *dparm, char *parm, struct stim begin_date, struct stim end_date, char *qual, struct stn_values *stn_values)
Definition: ma_qtrly.c:183
int eyr
Definition: ma_qtrly.c:123
int edy
Definition: ma_qtrly.c:123
int get_ma06_array()
Definition: ma_qtrly.c:481
int bmo
Definition: ma_qtrly.c:124
struct ma_qrtly_rec ma_qtrly_rec
int4 SQLCODE
struct sqlca_s ifx_sqlca_t
char SQLSTATE[]
struct sqlca_s sqlca
int byr
Definition: ma_qtrly.c:124
void change_datemaq()
int k
Definition: mapp2h.h:48
Arg args[10]
char source[9]
Definition: calfma_qtrly.c:162
double values[96]
Definition: calfma_qtrly.c:180
char lwals[96]
Definition: calfma_qtrly.c:181
char pedtsep[8]
Definition: calfma_qtrly.c:182
double codp
Definition: calfma_qtrly.c:175
double value
Definition: calfma_qtrly.c:179
char p[2]
Definition: ma_qtrly.c:137
char pe1[2]
Definition: ma_qtrly.c:131
double z12
Definition: ma_qtrly.c:143
char qz18[2]
Definition: ma_qtrly.c:148
char dur[2]
Definition: ma_qtrly.c:133
char s[2]
Definition: ma_qtrly.c:135
char pos[2]
Definition: ma_qtrly.c:129
double z00
Definition: ma_qtrly.c:141
char cgroup[2]
Definition: ma_qtrly.c:130
char qz00[2]
Definition: ma_qtrly.c:145
double z06
Definition: ma_qtrly.c:142
char e[2]
Definition: ma_qtrly.c:136
char drain[2]
Definition: ma_qtrly.c:128
char qz12[2]
Definition: ma_qtrly.c:147
char t[2]
Definition: ma_qtrly.c:134
char pe2[2]
Definition: ma_qtrly.c:132
double z18
Definition: ma_qtrly.c:144
char qz06[2]
Definition: ma_qtrly.c:146
char sqlwarn5
Definition: db.c:65
char sqlwarn3
Definition: db.c:61
char sqlwarn4
Definition: db.c:63
char sqlwarn7
Definition: db.c:67
char sqlwarn1
Definition: db.c:57
char sqlwarn6
Definition: db.c:66
char sqlwarn2
Definition: db.c:59
char sqlwarn0
Definition: db.c:56
Definition: db.c:43
long sqlerrd[6]
Definition: db.c:47
struct sqlca_s::sqlcaw_s sqlwarn
long sqlcode
Definition: db.c:44
char sqlerrm[72]
Definition: db.c:45
char sqlerrp[8]
Definition: db.c:46
Definition: misc.h:93
int minute
Definition: misc.h:99
int day
Definition: misc.h:97
int year
Definition: misc.h:95
int hour
Definition: misc.h:98
int month
Definition: misc.h:96
char qual
Definition: hydro_data.h:36
float value
Definition: hydro_data.h:35