Mapper
get_nam2.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 #line 1 "get_nam2.ec"
4 /*Translated by FOR_C, v3.4.5 (H), on 07/24/95 at 11:53:10 */
5 /*FOR_C Options SET: do=r ftn=nk op=iv s=vzn str=l */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9 #include <fcrt.h>
10 /*
11  * exec sql include sqlca;
12  */
13 #line 7 "get_nam2.ec"
14 
15 #line 7 "get_nam2.ec"
16 #line 1 "/opt/informix/incl/esql/sqlca.h"
17 /***************************************************************************
18  *
19  * INFORMIX SOFTWARE, INC.
20  *
21  * PROPRIETARY DATA
22  *
23  * THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF
24  * INFORMIX SOFTWARE, INC. THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
25  * CONFIDENCE. INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR
26  * DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT
27  * SIGNED BY AN OFFICER OF INFORMIX SOFTWARE, INC.
28  *
29  * THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
30  * SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE.
31  * UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
32  *
33  *
34  * Title: sqlca.h
35  * Sccsid: @(#)sqlca.h 9.4 1/18/93 11:09:48
36  * Description:
37  * SQL Control Area
38  *
39  ***************************************************************************
40  */
41 
42 #ifndef SQLCA_INCL
43 #define SQLCA_INCL
44 
45 #include "ifxtypes.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 typedef struct sqlca_s
52  {
53  int4 sqlcode;
54  char sqlerrm[72]; /* error message parameters */
55  char sqlerrp[8];
56  int4 sqlerrd[6];
57  /* 0 - estimated number of rows returned */
58  /* 1 - serial value after insert or ISAM error code */
59  /* 2 - number of rows processed */
60  /* 3 - estimated cost */
61  /* 4 - offset of the error into the SQL statement */
62  /* 5 - rowid after insert */
63 #ifdef _FGL_
64  char sqlawarn[8];
65 #else
66  struct sqlcaw_s
67  {
68  char sqlwarn0; /* = W if any of sqlwarn[1-7] = W */
69  char sqlwarn1; /* = W if any truncation occurred or
70  database has transactions or
71  no privileges revoked */
72  char sqlwarn2; /* = W if a null value returned or
73  ANSI database */
74  char sqlwarn3; /* = W if no. in select list != no. in into list or
75  turbo backend or no privileges granted */
76  char sqlwarn4; /* = W if no where clause on prepared update, delete or
77  incompatible float format */
78  char sqlwarn5; /* = W if non-ANSI statement */
79  char sqlwarn6; /* = W if server is in data replication secondary mode */
80  char sqlwarn7; /* = W if database locale is different from proc_locale
81  */
82  } sqlwarn;
83 #endif
85 
86 /* NOTE: 4gl assumes that the sqlwarn structure can be defined as
87  * sqlawarn -- an 8 character string, because single-char
88  * variables are not recognized in 4gl.
89  *
90  * If this structure should change, the code generated by 4gl compiler
91  * must also change
92  */
93 
94 #ifdef VMS
95 noshare
96 #endif /* VMS */
97 
98 #define SQLNOTFOUND 100
99 
100 #ifndef IFX_THREAD
101 extern struct sqlca_s sqlca;
102 
103 extern int4 SQLCODE;
104 
105 extern char SQLSTATE[];
106 #else /* IFX_THREAD */
107 extern int4 * ifx_sqlcode();
108 extern struct sqlca_s * ifx_sqlca();
109 #define SQLCODE (*(ifx_sqlcode()))
110 #define SQLSTATE ((char *)(ifx_sqlstate()))
111 #define sqlca (*(ifx_sqlca()))
112 #endif /* IFX_THREAD */
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* SQLCA_INCL */
119 
120 #line 103 "/opt/informix/incl/esql/sqlca.h"
121 #line 8 "get_nam2.ec"
122 
123 /* get_nam2.rcp
124  *
125  * this subroutine returns the watershed name, river name, and
126  * location when passed the comms5 id.
127  *
128  * sid - comms 5 id (passed)
129  * wshed - water shed name (first 4 of huc)
130  * river - river name
131  * loc - gauge location
132  * err - error return
133  * 1 - okay
134  * 2 - primekey not found
135  * 3 - climatdb error
136  *
137  * version 1.0 aug 1991 / dgs
138  *
139  *cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
140  * */
141 void /*FUNCTION*/ get_nam2(sid, sid_s, wshed, wshed_s, river, river_s,
142  loc, loc_s, err)
143 /*
144  * exec sql begin declare section;
145  */
146 #line 29 "get_nam2.ec"
147 #line 30 "get_nam2.ec"
148 #line 30 "get_nam2.ec"
149 #line 30 "get_nam2.ec"
150  char *sid;
151 int sid_s;
152 #line 31 "get_nam2.ec"
153 #line 31 "get_nam2.ec"
154  char *wshed;
155 int wshed_s;
156 #line 32 "get_nam2.ec"
157 #line 32 "get_nam2.ec"
158  char *river;
159 int river_s;
160 #line 33 "get_nam2.ec"
161 #line 33 "get_nam2.ec"
162  char *loc;
163 int loc_s;
164 #line 34 "get_nam2.ec"
165 long int *err;
166 /*
167  * exec sql end declare section;
168  */
169 #line 35 "get_nam2.ec"
170 
171 {
172 /*
173  * exec sql begin declare section;
174  */
175 #line 37 "get_nam2.ec"
176 #line 38 "get_nam2.ec"
177 #line 38 "get_nam2.ec"
178 static char dbname[200];
179 #line 39 "get_nam2.ec"
180 static char thuc1[9], twshed[31], nam[51];
181 #line 40 "get_nam2.ec"
182 static long int task, error, n, i, i_;
183 #line 41 "get_nam2.ec"
184 static float sqlcod;
185 /*
186  * exec sql end declare section;
187  */
188 #line 42 "get_nam2.ec"
189 
190 
191  f_strncpy( wshed, " ", wshed_s - 1 );
192  f_strncpy( river, " ", river_s -
193  1 );
194  f_strncpy( loc, " ", loc_s - 1 );
195 
196  /* ***** find huc *****
197  * */
198  *err = 1;
199  n = 0;
200  error = ReadConfig(dbname, "DBNAME");
201  if(error != 0) {
202  fprintf(stderr,"cannot get DBNAME var from sws.config\nassuming fastetc\n");
203  strcpy(dbname, "fastetc");
204  }
205 /*
206  * exec sql database $dbname;
207  */
208 #line 58 "get_nam2.ec"
209  {
210 #line 58 "get_nam2.ec"
211  sqli_db_open(dbname, 0);
212 #line 58 "get_nam2.ec"
213  }
214 
215  if( SQLCODE != 0 )
216  {
217  *err = 3;
218  goto L_500;
219  }
220 
221 /*
222  * exec sql select huc,des
223  * into :thuc1, :nam
224  * from stn
225  * where id= :sid;
226  */
227 #line 66 "get_nam2.ec"
228  {
229 #line 69 "get_nam2.ec"
230  static const char *sqlcmdtxt[] =
231 #line 69 "get_nam2.ec"
232  {
233 #line 69 "get_nam2.ec"
234  " select huc , des from stn where id = ?",
235  0
236  };
237 #line 69 "get_nam2.ec"
238 static ifx_cursor_t _SQ0 = {0};
239  static ifx_sqlvar_t _sqibind[] =
240  {
241  { 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
242 #line 69 "get_nam2.ec"
243  };
244  static ifx_sqlvar_t _sqobind[] =
245  {
246  { 100, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
247  { 100, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
248 #line 69 "get_nam2.ec"
249  };
250 #line 69 "get_nam2.ec"
251  _sqibind[0].sqldata = sid;
252 #line 69 "get_nam2.ec"
253  _sqobind[0].sqldata = thuc1;
254 #line 69 "get_nam2.ec"
255  _sqobind[1].sqldata = nam;
256 #line 69 "get_nam2.ec"
257  sqli_slct(ESQLINTVERSION, &_SQ0,(char **) sqlcmdtxt,1,_sqibind,2,_sqobind,0,(ifx_literal_t *) 0,(ifx_namelist_t *) 0,0);
258 #line 69 "get_nam2.ec"
259  }
260 
261  if( SQLCODE != 0 )
262  {
263 
264  *err = 2;
265  goto L_500;
266  }
267 
268  /* ***** get wshed *****
269  * */
270 /*
271  * exec sql select des4
272  * into :twshed
273  * from huc
274  * where code= :thuc1;
275  */
276 #line 80 "get_nam2.ec"
277  {
278 #line 83 "get_nam2.ec"
279  static const char *sqlcmdtxt[] =
280 #line 83 "get_nam2.ec"
281  {
282 #line 83 "get_nam2.ec"
283  " select des4 from huc where code = ?",
284  0
285  };
286 #line 83 "get_nam2.ec"
287 static ifx_cursor_t _SQ0 = {0};
288  static ifx_sqlvar_t _sqibind[] =
289  {
290  { 100, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
291 #line 83 "get_nam2.ec"
292  };
293  static ifx_sqlvar_t _sqobind[] =
294  {
295  { 100, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
296 #line 83 "get_nam2.ec"
297  };
298 #line 83 "get_nam2.ec"
299  _sqibind[0].sqldata = thuc1;
300 #line 83 "get_nam2.ec"
301  _sqobind[0].sqldata = twshed;
302 #line 83 "get_nam2.ec"
303  sqli_slct(ESQLINTVERSION, &_SQ0,(char **) sqlcmdtxt,1,_sqibind,1,_sqobind,0,(ifx_literal_t *) 0,(ifx_namelist_t *) 0,0);
304 #line 83 "get_nam2.ec"
305  }
306  if( SQLCODE != 0 )
307  {
308 
309  f_strncpy( wshed, " ", wshed_s - 1 );
310  }
311  else
312  {
313  f_strncpy( wshed, ntstr(twshed+0,20), wshed_s - 1 );
314  }
315 
316  /* ***** split name up here *****
317  *
318  * ** look for ' - ' within the station name */
319  for( i = 2; i <= 49; i++ )
320  {
321  i_ = i - 1;
322  if( f_strcmp(ntstr(nam+i - 2,min(i + 1,50) - (i - 1) + 1),
323  " - ") == 0 )
324  goto L_200;
325  }
326  /* ** not there, break on 1st 25 and 2nd 25 */
327  f_subscpy( river, 0, 24, river_s - 1, ntstr(nam+0,25) );
328  f_subscpy( loc, 0, 24, loc_s - 1, ntstr(nam+25,25) );
329  return;
330 
331 L_200:
332  f_strncpy( river, " ", river_s -
333  1 );
334  if( i <= 32 )
335  {
336  if( i > 2 )
337  f_subscpy( river, 0, i - 3, river_s - 1, ntstr(nam+0,min(i -
338  2,50)) );
339  }
340  else
341  {
342  f_subscpy( river, 0, 29, river_s - 1, ntstr(nam+0,30) );
343  }
344  f_strncpy( loc, " ", loc_s - 1 );
345  if( i >= 19 )
346  {
347  if( i <= 48 )
348  f_subscpy( loc, 0, -i + 48, loc_s - 1, ntstr(nam+i + 1,-(i +
349  2) + 51) );
350  }
351  else
352  {
353  f_subscpy( loc, 0, 29, loc_s - 1, ntstr(nam+i + 1,min(i +
354  31,50) - (i + 2) + 1) );
355  }
356 
357 
358 L_500:
359  ;
360 
361  return;
362 } /* end of function */
363 
364 
365 
366 
367 
368 
369 
370 #line 146 "get_nam2.ec"
int ReadConfig(char *answer, char *query)
Definition: ReadConfig.c:11
static int i
void get_nam2(char *sid, int sid_s, char *wshed, int wshed_s, char *river, int river_s, char *loc, int loc_s, long int *err)
Definition: get_nam2.c:141
int4 SQLCODE
struct sqlca_s ifx_sqlca_t
char SQLSTATE[]
struct sqlca_s sqlca
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
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