Mapper
next_report.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 #line 1 "next_report.ec"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <ctype.h>
9 #include <sys/time.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 
13 void next_report(char *stn_id, char *shef, char *next, int debug)
14 {
15 /* general defintions */
16 FILE *pf,*popen();
17 char random[2];
18 char line[256];
19 int freq,nr,i;
20 int nhr,nmin;
21 int yy,mm,dd,hh;
22 int year,month,day,hour,minute,second;
23 int time_cur;
24 
25 /* declare informix host variables */
26 /*
27  * exec sql begin declare section;
28  */
29 #line 23 "next_report.ec"
30 #line 24 "next_report.ec"
31  char id[6];
32  char pe1[2];
33  char pe2[2];
34  char dur[2];
35  char t[2];
36  char s[2];
37  char e[2];
38  char p[2];
39 int obstime;
40 /*
41  * exec sql end declare section;
42  */
43 #line 33 "next_report.ec"
44 
45 
46  /* take care of time control zone = Z */
47  pf=popen("date -u '+%Y %m %d %H %M %S'","r");
48  fgets(line,sizeof(line),pf);
49  pclose(pf);
50  sscanf(line,"%d %d %d %d %d %d",
51  &year,&month,&day,&hour,&minute,&second);
52  time_cur=100*hour+minute;
53 
54  strcpy(id,stn_id);
55 
56  strncpy(pe1,shef,1);
57  *(pe1+1)='\0';
58  strncpy(pe2,shef+1,1);
59  *(pe2+1)='\0';
60  strncpy(dur,shef+2,1);
61  *(dur+1)='\0';
62  strncpy(t,shef+3,1);
63  *(t+1)='\0';
64  strncpy(s,shef+4,1);
65  *(s+1)='\0';
66  strncpy(e,shef+5,1);
67  *(e+1)='\0';
68  strncpy(p,shef+6,1);
69  *(p+1)='\0';
70 
71  strcpy(next,"UNKNOWN");
72 
73  if(!strcmp(s,"R"))
74  strcpy(next,"EVENT");
75 
76  if(!strcmp(s,"P"))
77  strcpy(next,"DIAL UP");
78 
79 /*
80  * $select obstime into $obstime from sens where id=$id and
81  * pe1=$pe1 and pe2=$pe2 and dur=$dur and t=$t and s=$s and
82  * e=$e and p=$p;
83  */
84 #line 68 "next_report.ec"
85  {
86 #line 70 "next_report.ec"
87  static const char *sqlcmdtxt[] =
88 #line 70 "next_report.ec"
89  {
90 #line 70 "next_report.ec"
91  "select obstime from sens where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ?",
92  0
93  };
94 #line 70 "next_report.ec"
95 static ifx_cursor_t _SQ0 = {0};
96  static ifx_sqlvar_t _sqibind[] =
97  {
98  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
99  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
100  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
101  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
102  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
103  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
104  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
105  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
106 #line 70 "next_report.ec"
107  };
108  static ifx_sqlvar_t _sqobind[] =
109  {
110  { 102, sizeof(obstime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
111 #line 70 "next_report.ec"
112  };
113 #line 70 "next_report.ec"
114  _sqibind[0].sqldata = id;
115 #line 70 "next_report.ec"
116  _sqibind[1].sqldata = pe1;
117 #line 70 "next_report.ec"
118  _sqibind[2].sqldata = pe2;
119 #line 70 "next_report.ec"
120  _sqibind[3].sqldata = dur;
121 #line 70 "next_report.ec"
122  _sqibind[4].sqldata = t;
123 #line 70 "next_report.ec"
124  _sqibind[5].sqldata = s;
125 #line 70 "next_report.ec"
126  _sqibind[6].sqldata = e;
127 #line 70 "next_report.ec"
128  _sqibind[7].sqldata = p;
129 #line 70 "next_report.ec"
130  _sqobind[0].sqldata = (char *) &obstime;
131 #line 70 "next_report.ec"
132  sqli_slct(ESQLINTVERSION, &_SQ0,sqlcmdtxt,8,_sqibind,1,_sqobind,0,(ifx_literal_t *)0,(ifx_namelist_t *)0,0);
133 #line 70 "next_report.ec"
134  }
135  if(!sqlca.sqlcode)
136  {
137 
138  if(obstime <= -99999)
139  obstime=0;
140 
141  if(!strcmp(s,"M"))
142  obstime=10030;
143 
144  strcpy(random," ");
145 
146  if(debug)
147  printf("%s %s%s%s%s%s%s%s %d\n",id,pe1,pe2,dur,t,s,e,p,obstime);
148 
149  if(obstime < 0)
150  {
151  strcpy(random,"R");
152  obstime=obstime*-1;
153  }
154 
155  if(obstime)
156  {
157  freq=obstime/10000;
158  nr=obstime%1000;
159 
160  nhr=nr/100;
161  nmin=nr%100;
162 
163  if(freq)
164  {
165  sprintf(next,"%02d%02dZ %s",nhr,nmin,random);
166  for(i=1;i<=23;i++)
167  {
168  if(!(i%freq))
169  {
170  if(time_cur < 100*(i+nhr)+nmin)
171  {
172  sprintf(next,"%02d%02dZ %s",i+nhr,nmin,random);
173  break;
174  }
175  }
176  }
177  }
178 
179  if(debug)
180  printf("time is %d. code is %d. next report is at %s\n",
181  time_cur,obstime,next);
182  }
183  }
184  else
185  if(debug)
186  printf("could not read sens table for %s %s%s%s%s%s%s%s\n",
187  id,pe1,pe2,dur,t,s,e,p);
188 
189  return;
190 }
191 
192 
193 #line 127 "next_report.ec"
static int i
struct sqlca_s sqlca
int hour
Definition: display_data.c:26
int day
Definition: display_data.c:26
int year
Definition: display_data.c:26
int month
Definition: display_data.c:26
int debug
Definition: hydro_data.h:53
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
printf("fbuf is %s\n", fbuf)
double yy
Definition: mapp2h.h:41
void next_report(char *stn_id, char *shef, char *next, int debug)
Definition: next_report.c:13
long sqlcode
Definition: db.c:44