File: reada.c

package info (click to toggle)
ghemical 0.82-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,448 kB
  • ctags: 18,571
  • sloc: ansic: 68,828; cpp: 51,774; fortran: 35,324; sh: 2,505; makefile: 475; perl: 70
file content (253 lines) | stat: -rw-r--r-- 5,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* reada.f -- translated by f2c (version 19991025).
   You must link the resulting object file with the libraries:
	-lf2c -lm   (in that order)
*/

#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;
static doublereal c_b21 = 10.;

doublereal reada_(string, istart, string_len)
char *string;
integer *istart;
ftnlen string_len;
{
    /* System generated locals */
    integer i__1, i__2;
    doublereal ret_val, d__1;

    /* Builtin functions */
    integer i_len(), i_indx();
    double pow_dd();

    /* Local variables */
    static integer iadd, ineg, idot, ipos, i__, j, l, n, icapd, icape;
    extern doublereal digit_();
    static integer ismld, ismle, i0, i9;
    static logical expnnt;

/*     FORTRAN FUNCTION TO EXTRACT NUMBER FROM STRING */


/*     DEFINE ASCII VALUES OF NUMERIC FIELD CHARACTERS */
    i0 = '0';
    i9 = '9';
    idot = '.';
    ineg = '-';
    ipos = '+';
    icapd = 'D';
    icape = 'E';
    ismld = 'd';
    ismle = 'e';

    l = i_len(string, string_len);

/*     FIND THE START OF THE NUMERIC FIELD */
    i__1 = l;
    for (i__ = *istart; i__ <= i__1; ++i__) {
	iadd = 0;
	n = *(unsigned char *)&string[i__ - 1];

/*       SIGNAL START OF NUMERIC FIELD IF DIGIT FOUND */
	if (n >= i0 && n <= i9) {
	    goto L20;
	}

/*       ACCOUNT FOR CONSECUTIVE SIGNS [- AND(OR) +] */
	if (n == ineg || n == ipos) {
	    ++iadd;
	    if (i__ + iadd > l) {
		goto L50;
	    }
	    i__2 = i__ + iadd - 1;
	    n = *(unsigned char *)&string[i__2];
	    if (n >= i0 && n <= i9) {
		goto L20;
	    }
	}

/*       ACCOUNT FOR CONSECUTIVE DECIMAL POINTS (.) */
	if (n == idot) {
	    ++iadd;
	    if (i__ + iadd > l) {
		goto L50;
	    }
	    i__2 = i__ + iadd - 1;
	    n = *(unsigned char *)&string[i__2];
	    if (n >= i0 && n <= i9) {
		goto L20;
	    }
	}
/* L10: */
    }
    goto L50;

/*     FIND THE END OF THE NUMERIC FIELD */
L20:
    expnnt = FALSE_;
    i__1 = l;
    for (j = i__ + 1; j <= i__1; ++j) {
	iadd = 0;
	n = *(unsigned char *)&string[j - 1];

/*       CONTINUE SEARCH FOR END IF DIGIT FOUND */
	if (n >= i0 && n <= i9) {
	    goto L30;
	}

/*       CONTINUE SEARCH FOR END IF SIGN FOUND AND EXPNNT TRUE */
	if (n == ineg || n == ipos) {
	    if (! expnnt) {
		goto L40;
	    }
	    ++iadd;
	    if (j + iadd > l) {
		goto L40;
	    }
	    i__2 = j + iadd - 1;
	    n = *(unsigned char *)&string[i__2];
	    if (n >= i0 && n <= i9) {
		goto L30;
	    }
	}
	if (n == idot) {
	    ++iadd;
	    if (j + iadd > l) {
		goto L40;
	    }
	    i__2 = j + iadd - 1;
	    n = *(unsigned char *)&string[i__2];
	    if (n >= i0 && n <= i9) {
		goto L30;
	    }
	    if (n == icape || n == ismle || n == icapd || n == ismld) {
		goto L30;
	    }
	}
	if (n == icape || n == ismle || n == icapd || n == ismld) {
	    if (expnnt) {
		goto L40;
	    }
	    expnnt = TRUE_;
	    goto L30;
	}
	goto L40;
L30:
	;
    }
    j = l + 1;
L40:
    i__1 = j - 2;
    n = *(unsigned char *)&string[i__1];
    if (n == icape || n == ismle || n == icapd || n == ismld) {
	--j;
    }

/*     FOUND THE END OF THE NUMERIC FIELD (IT RUNS 'I' THRU 'J-1') */
    n = 0;
    n += i_indx(string + (i__ - 1), "e", j - 1 - (i__ - 1), (ftnlen)1);
    n += i_indx(string + (i__ - 1), "E", j - 1 - (i__ - 1), (ftnlen)1);
    n += i_indx(string + (i__ - 1), "d", j - 1 - (i__ - 1), (ftnlen)1);
    n += i_indx(string + (i__ - 1), "D", j - 1 - (i__ - 1), (ftnlen)1);
    if (n == 0) {
	ret_val = digit_(string + (i__ - 1), &c__1, j - 1 - (i__ - 1));
    } else {
	i__1 = i__ + n;
	d__1 = digit_(string, &i__1, j - 1);
	ret_val = digit_(string, &i__, i__ + n - 2) * pow_dd(&c_b21, &d__1);
    }
    return ret_val;

/*     DEFAULT VALUE RETURNED BECAUSE NO NUMERIC FIELD FOUND */
L50:
    ret_val = 0.;
    return ret_val;
} /* reada_ */

/*     ****************************************************************** */
doublereal digit_(string, istart, string_len)
char *string;
integer *istart;
ftnlen string_len;
{
    /* System generated locals */
    integer i__1;
    doublereal ret_val;

    /* Builtin functions */
    integer i_len();

    /* Local variables */
    static integer idig, ineg, ispc, idot;
    static logical sign;
    static integer ipos, i__, j, l, n;
    static doublereal c1, c2;
    static integer i0, i9;
    static doublereal deciml;

/*     FORTRAN FUNCTION TO CONVERT NUMERIC FIELD TO DOUBLE PRECISION */
/*     NUMBER.  THE STRING IS ASSUMED TO BE CLEAN (NO INVALID DIGIT */
/*     OR CHARACTER COMBINATIONS FROM ISTART TO THE FIRST NONSPACE, */
/*     NONDIGIT, NONSIGN, AND NONDECIMAL POINT CHARACTER). */


/*     DEFINE ASCII VALUES OF NUMERIC FIELD CHARACTERS */
    i0 = '0';
    i9 = '9';
    ineg = '-';
    ipos = '+';
    idot = '.';
    ispc = ' ';

    c1 = 0.;
    c2 = 0.;
    sign = TRUE_;
    l = i_len(string, string_len);

/*     DETERMINE THE CONTRIBUTION TO THE NUMBER GREATER THAN ONE */
    idig = 0;
    i__1 = l;
    for (i__ = *istart; i__ <= i__1; ++i__) {
	n = *(unsigned char *)&string[i__ - 1];
	if (n >= i0 && n <= i9) {
	    ++idig;
	    c1 = c1 * 10. + n - i0;
	} else if (n == ineg || n == ipos || n == ispc) {
	    if (n == ineg) {
		sign = FALSE_;
	    }
	} else if (n == idot) {
	    goto L20;
	} else {
	    goto L40;
	}
/* L10: */
    }

/*     DETERMINE THE CONTRIBUTION TO THE NUMBER LESS THAN THAN ONE */
L20:
    deciml = 1.;
    i__1 = l;
    for (j = i__ + 1; j <= i__1; ++j) {
	n = *(unsigned char *)&string[j - 1];
	if (n >= i0 && n <= i9) {
	    deciml /= 10.;
	    c2 += (n - i0) * deciml;
	} else if (n != ispc) {
	    goto L40;
	}
/* L30: */
    }

/*     PUT THE PIECES TOGETHER */
L40:
    ret_val = c1 + c2;
    if (! sign) {
	ret_val = -ret_val;
    }
    return ret_val;
} /* digit_ */