Mapper
shreal.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 04/06/95 at 13:56:27 */
2 /*FOR_C Options SET: c=2 com=u do=r44 ftn=ln6kk op=iv s=dvnk str=l sq=i */
3 
4 #define _POSIX_SOURCE
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <dirent.h>
9 #include <unistd.h>
10 #include <math.h>
11 #include <string.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include "shef_structs_external.h"
15 
16 /*---------------------------------------------------------------------
17 
18  NAME
19  SUBROUTINE SHREAL(VALUE,IFLAG,NDIG,STATUS)
20 
21  PURPOSE
22 
23  THIS ROUTINE READS REAL NUMBERS WITH A IF IFLAG IS SET TO
24  ZERO
25  CHARACTER READ.
26 
27  VERSION and UPDATES
28  1.0 JUL 82 Geoffrey M. Bonnin
29  Original Version
30  1.1 AUG 84
31  Improve screening of signs
32  1.2 AUG 92 David G. Brandon
33  Allow blanks between the minus or plus sign and the
34  numerical digits in the value. For example the value
35  - 34 was not valid before, but now is.
36  2.0 MAY 94 David G. Brandon
37  Also Translated to 'C' using FOR_C
38  2.1 Add iscore to t_codes array.
39  2.2 NOV 95 DGB
40  If the charater O is placed as a data value,
41  cast it to a 0. NOTE: data qualifier of O should
42  not be used.
43  2.3 JAN 27 98 DGB
44  Add check for a NULL field, in .E messages. If a NULL
45  field was determined, i.e. sucessive slashes without a
46  value between, an 'N' is internally written and flagged.
47  *--------------------------------------------------------------------- */
48 
49 
50 void shreal(value, iflag, ndig, status)
51 double *value;
52 short int *iflag, *ndig, *status;
53 {
54  short int num();
55  static short int _fst, i, i_, idec, iend_, isign;
56  static double sign, x;
57 
58  int DEBUG1,DEBUG2;
59  DEBUG1 = 0;
60  DEBUG2 = 0;
61 
62  /* Initialise */
63  *status = 0;
64  *value = 0e0;
65  isign = 0;
66  sign = 1e0;
67  idec = 0;
68  *ndig = 0;
69  iend_ = 0;
70 
71  /* Clear past blanks */
72 
73  if( *iflag == 0 )
74  goto L_7;
75 L_5:
76  if ( DEBUG1 ) printf("\nshreal: at L_5 CLEAR xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
77  nextch( &xchar_.ichar, status );
78  if( *status == 1 )
79  {
80  *status = 0;
81  goto L_9010;
82  }
83  else if( *status == 2 )
84  {
85  *status = 0;
86  goto L_9020;
87  }
88 
89 L_7:
90  if ( DEBUG1 ) printf("\nshreal: at L_7 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
91  if( xchar_.ichar == codes_.iblnk )
92  goto L_5;
93  goto L_20;
94 
95  /* Get the next character */
96 
97 L_10:
98  if ( DEBUG1 ) printf("\nshreal: at L_10 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
99  nextch( &xchar_.ichar, status );
100  if( *status == 1 )
101  {
102  *status = 0;
103  goto L_9010;
104  }
105  else if( *status == 2 )
106  {
107  *status = 0;
108  goto L_9020;
109  }
110 
111  /* Check for sign */
112 
113 L_20:
114  if ( DEBUG1 ) printf("\nshreal: at L_20 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
115  if( (xchar_.ichar != codes_.iplus) && (xchar_.ichar != codes_.iminus) )
116  goto L_30;
117  if ( DEBUG1 ) printf("\nshreal: isign = %d",isign);
118  if( isign != 0 )
119  goto L_100;
120  isign = 1;
121  if( xchar_.ichar == codes_.iminus )
122  sign = -1e0;
123 
124 L_21:
125  if ( DEBUG1 ) printf("\nshreal: at L_21 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
126  nextch( &xchar_.ichar, status );
127  if ( DEBUG2 ) printf("\nshreal: status from nextch = %d",*status);
128 
129  if( *status == 1 )
130  {
131  *status = 0;
132  goto L_9010;
133  }
134  else if( *status == 2 )
135  {
136  *status = 0;
137  goto L_9020;
138  }
139  if ( DEBUG2 ) printf("\nshreal: xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
140 /* if( xchar_.ichar == codes_.iblnk )
141  goto L_21;
142 */
143  goto L_20;
144 
145  /* Check for decimal */
146 
147 
148 L_30:
149  if ( DEBUG1 ) printf("\nshreal: at L_30 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
150  if( xchar_.ichar != codes_.idot )
151  goto L_40;
152  if ( DEBUG1 ) printf("\nshreal: idec = %d",idec);
153  if( idec > 0 )
154  goto L_100;
155  idec = 1;
156  isign = 1;
157  goto L_10;
158 
159  /* Check for 'M' - missing */
160 
161 L_40:
162  if ( DEBUG1 ) printf("\nshreal: at L_40 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
163  if( xchar_.ichar != codes_.ichm )
164  goto L_45;
165  if ( DEBUG1 ) printf("\nshreal: ndig = %d isign = %d",*ndig,isign);
166  if( (*ndig > 0) || (isign != 0) )
167  goto L_100;
168  *value = -9999e0;
169  *ndig = 1;
170  nextch( &xchar_.ichar, status );
171  if( *status == 1 )
172  {
173  *status = 0;
174  goto L_9010;
175  }
176  else if( *status == 2 )
177  {
178  *status = 0;
179  goto L_9020;
180  }
181 
182  goto L_9000;
183 
184  /* check for 'N' which represents a NULL */ /* dgb:01/27/98 */
185 
186 L_45: /* dgb:01/27/98 */
187  if( xchar_.ichar != codes_.ichn ) /* dgb:01/27/98 */
188  goto L_50; /* dgb:01/27/98 */
189  if( (*ndig > 0) || (isign != 0) ) /* dgb:01/27/98 */
190  goto L_100; /* dgb:01/27/98 */
191  *value = -10000e0; /* dgb:01/27/98 */
192  *ndig = 1; /* dgb:01/27/98 */
193  nextch( &xchar_.ichar, status ); /* dgb:01/27/98 */
194  if( *status == 1 ) /* dgb:01/27/98 */
195  { /* dgb:01/27/98 */
196  *status = 0; /* dgb:01/27/98 */
197  goto L_9010; /* dgb:01/27/98 */
198  } /* dgb:01/27/98 */
199  else if( *status == 2 ) /* dgb:01/27/98 */
200  { /* dgb:01/27/98 */
201  *status = 0; /* dgb:01/27/98 */
202  goto L_9020; /* dgb:01/27/98 */
203  } /* dgb:01/27/98 */
204 
205  goto L_9000; /* dgb:01/27/98 */
206 
207  /* Check for 'T' = TRACE = 0.001 */
208 
209 L_50:
210  if ( DEBUG1 ) printf("\nshreal: at L_50 trace xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
211  if( xchar_.ichar != codes_.icht )
212  goto L_60;
213  if ( DEBUG1 ) printf("\nshreal: ndig = %d isign = %d",ndig,isign);
214  if( (*ndig > 0) || (isign != 0) )
215  goto L_100;
216  *value = -9e10;
217  *ndig = 1;
218  nextch( &xchar_.ichar, status );
219  if( *status == 1 )
220  {
221  *status = 0;
222  goto L_9010;
223  }
224  else if( *status == 2 )
225  {
226  *status = 0;
227  goto L_9020;
228  }
229 
230 
231  goto L_9000;
232 
233  /* Check for a digit and adjust the value */
234 
235 L_60:
236  if ( DEBUG1 ) printf("\nshreal: at L_60 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
237  if ( xchar_.ichar == codes_.icho ) /* dgb:11/05/95 */
239 
240  irang( &xchar_.ichar, &codes_.ich0, &codes_.ich9, status );
241  if( *status == 1 )
242  {
243  *status = 0;
244  goto L_90;
245  }
246  *ndig = *ndig + 1;
247  isign = 1;
248  if( idec > 0 )
249  goto L_70;
250 /* *value = 10e0**value + (num( &xchar_.ichar ) - num( &codes_.ich0 )); */
251  *value = 10e0**value + ( xchar_.ichar - codes_.ich0 );
252  goto L_10;
253 
254 L_70:
255  if ( DEBUG1 ) printf("\nshreal: at L_70 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
256 /* x = num( &xchar_.ichar ) - num( &codes_.ich0 ); */
257  x = xchar_.ichar - codes_.ich0 ;
258  for( i = 1, _fst=1; (i <= idec) || _fst; i++, _fst=0 )
259  {
260  i_ = i - 1;
261  x = x/10e0;
262  }
263 
264  *value = *value + x;
265  idec = idec + 1;
266  goto L_10;
267 
268  /* Check for / + = MISSING */
269 
270 L_90:
271  if ( DEBUG1 ) printf("\nshreal: at L_90 + xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
272  if( *ndig > 0 )
273  goto L_100;
274  if( (xchar_.ichar == codes_.islash) && (isign == 0) )
275  goto L_110;
276  if ( DEBUG1 ) printf("\nshreal: isign = %d",isign);
277  if( isign == 0 )
278  goto L_100;
279  if( sign < 0e0 )
280  goto L_100;
281  *value = -9999e0;
282  *ndig = 1;
283  goto L_9000;
284 
285  /* This is a NULL ? */
286 
287 L_110:
288  if ( DEBUG1 ) printf("\nshreal: at L_110 NULL xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
289  *ndig = -1;
290  goto L_9000;
291 
292  /* Multiply by the sign */
293 
294 L_100:
295  if ( DEBUG1 ) printf("\nshreal: at L_100 MULTIPLY BY SIGN xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
296  *value = sign**value;
297  if( iend_ == 1 )
298  goto L_9011;
299 
300 
301 L_9000:
302  if ( DEBUG1 ) printf("\nshreal: at L_9000 xchar_.ichar = %d %c",xchar_.ichar,xchar_.ichar);
303  return;
304 
305  /* Stop reading the line */
306 
307 L_9010:
308  iend_ = 1;
309  goto L_100;
310 
311 L_9011:
312  *status = 1;
313  return;
314 
315  /* Error in reading file */
316 
317 L_9020:
318  *status = 2;
319  return;
320 
321 }
322 
static int i
void irang(short int *i, short int *min_, short int *max_, short int *status)
Definition: irang.c:33
printf("fbuf is %s\n", fbuf)
void nextch(short int *ichar, short int *status)
Definition: nextch.c:76
float value
struct t_codes_ codes_
struct t_xchar_ xchar_
void shreal(double *value, short int *iflag, short int *ndig, short int *status)
Definition: shreal.c:50
short int iblnk
Definition: shef_structs.h:81
short int ich0
Definition: shef_structs.h:80
short int icho
Definition: shef_structs.h:79
short int iplus
Definition: shef_structs.h:81
short int ichm
Definition: shef_structs.h:79
short int islash
Definition: shef_structs.h:81
short int iminus
Definition: shef_structs.h:81
short int ich9
Definition: shef_structs.h:81
short int ichn
Definition: shef_structs.h:79
short int icht
Definition: shef_structs.h:79
short int idot
Definition: shef_structs.h:82
short int ichar
Definition: shef_structs.h:112