1
C @(#)usrinp.for 13.1.1.1 (ES0-DMD) 06/02/98 18:30:08
2
C===========================================================================
3
C Copyright (C) 1995 European Southern Observatory (ESO)
5
C This program is free software; you can redistribute it and/or
6
C modify it under the terms of the GNU General Public License as
7
C published by the Free Software Foundation; either version 2 of
8
C the License, or (at your option) any later version.
10
C This program is distributed in the hope that it will be useful,
11
C but WITHOUT ANY WARRANTY; without even the implied warranty of
12
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
C GNU General Public License for more details.
15
C You should have received a copy of the GNU General Public
16
C License along with this program; if not, write to the Free
17
C Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
C Corresponding concerning ESO-MIDAS should be addressed as follows:
21
C Internet e-mail: midas@eso.org
22
C Postal address: European Southern Observatory
23
C Data Management Division
24
C Karl-Schwarzschild-Strasse 2
25
C D 85748 Garching bei Muenchen
27
C===========================================================================
29
SUBROUTINE USRINP(A,N,TYPE,CHARST)
31
C.PURPOSE: Decode a character string into integer or real array
32
C.AUTHOR: J.P. Terlouw, Kapteynlab, Groningen
34
C.VERSION: ?????? RHW implementation
35
C.VERSION: 910115 RHW IMPLICIT NONE added
52
INTEGER DOLOOP(2,MAXLP)
68
CHARACTER ATYPE(2),LPSYM
72
EQUIVALENCE (RA,IA,AA)
77
ERR = .FALSE. ! error in do-loop
78
LPSYM = ':' ! loop symbol
79
NI = 0 ! initial number of used words for array
80
IPOS = 0 ! starting for array pointer
81
ITYPE = 1 ! default type is real
86
CALL ALPHA(CHARST,72,NCH,NREST)
93
IF (TYPE.EQ.ATYPE(I)) THEN ! what type?
98
C *** GET INPUT PARAMETERS IF PRESENT
101
ERR = .FALSE. ! reset error flag
103
IF ((ITYPE.EQ.1) .OR. (ITYPE.EQ.3)) THEN ! decode loop
109
NWORD = 1 ! startword of do-loop in b1
114
IF (B1(I).EQ.LPSYM) THEN
115
IF (B1(I-1).EQ.' ' .OR. B1(I+1).EQ.' ') THEN ! bad syntax
119
IF (DOLOOP(2,NLOOP).EQ.1) THEN
120
DOLOOP(2,NLOOP) = 2 ! increment value present
123
ELSE IF (DOLOOP(2,NLOOP).EQ.2) THEN
124
ERR = .TRUE. ! error in do-loop input string
126
GO TO 60 ! back to inpu
127
ELSE ! upper value present
128
DOLOOP(1,NLOOP) = NWORD + INSERT
135
IF (B1(I).EQ.' ' .OR. B1(I).EQ.',') THEN ! sep. symbols
152
IF ((.NOT.LOOP) .AND. (.NOT.ERR)) THEN
158
IF ((NCH.GT.0) .AND. (.NOT.ERR)) THEN ! decode input into real or char.
159
CALL DECUSR(B1,NCH,B8,NR8) ! decodes input array into b8(nr8)
160
NI = NEL(B8,NR8) ! actual number of words (=array elements)
163
C *** CONSTRUCT THE OUTPUT ARRAY ************************************
165
IPOS = 0 ! position in a
166
ILOOP = 1 ! next loop (if present)
167
IIN = 0 ! position in b8
172
IF (ITYPE.EQ.3) THEN ! real+integer conversion
175
IF (IPOS+1.LE.N) THEN ! conversion if ipos+1<# array el.
178
IPOS = IPOS + 1 ! increase position by one
179
IF (IIN.EQ.DOLOOP(1,ILOOP)) THEN
183
IF (DOLOOP(2,ILOOP).EQ.1) THEN ! no increment was given
189
AA = ((UPP-LOW)/INCR) ! # of reals to be added in A
192
DO 80 IREAL = 1,NREAL
195
IF (ITYPE.EQ.3) THEN ! real+integer conversion
198
IF (IPOS+1.LE.N) THEN ! conversion if ipos+1<# array el.
201
IPOS = IPOS + 1 ! increase position by one
206
IF (IIN.LT.NI) GO TO 70
210
CALL SETEND(A(IPOS+1))
216
SUBROUTINE DECUSR(SS,L,ARRAY,NIN)
218
C.PURPOSE: Subroutine to decode input string into a real array
219
C.AUTHOR: J.P. Terlouw, Kapteynlab Groningen
221
C.VERSION: 87???? RHW adjustments for and implementation in MIDAS
222
C.VERSION: 910115 RHW IMPLICIT NONE added
225
INTEGER L ! IN: length of character string
226
CHARACTER SS(L) ! IN: character string
227
REAL ARRAY(*) ! OUT: real array
228
INTEGER NIN ! OUT: length of the array
230
INTEGER IPOINT, IEPOW, ISIGN
231
INTEGER I, II, IARR, IFMT
237
CHARACTER FMT*150,SSS*150
238
LOGICAL RREAL,EPOW,XSIGN,XCHAR,SEP
241
9010 FORMAT (I2.2,'X')
242
9020 FORMAT ('F',I2.2,'.',I2.2)
254
DO 10 II = 1,L ! put ss(1 --> l) into sss(1:l)
261
I = 1 ! index used for ss(1 ---> l)
262
NOUT = 0 ! # of elements filled in array
265
N1 = 1 ! first position of next field
272
IF (I.LE.L .AND. NOUT.LT.NIN) THEN
273
IF ((SS(I).EQ.' ') .OR. (SS(I).EQ.',')
274
+ .OR. (SS(I).EQ.':')) THEN
276
LF = I - N1 ! character string
278
LF = MIN(((NIN-NOUT)*1),LF) ! max space in array
281
WRITE (FMT(IFMT:),9000) MIN(1,LF)
293
IF (IPOINT.EQ.0) THEN
296
LD = MAX((IEPOW-IPOINT-1),0)
297
WRITE (FMT(IFMT:IFMT+5),9020) LF,LD
318
WRITE (FMT(IFMT:IFMT+2),9010) LF
325
C *** input element is real
326
IF (SS(I).GE.'0' .AND. SS(I).LE.'9' .OR. SS(I).EQ.
327
+ '+' .OR. SS(I).EQ.'-') THEN
330
IF (SS(I).EQ.'.') THEN ! decimal point
334
XCHAR = .TRUE. ! input element is character
339
IF ( .NOT. XCHAR) THEN
341
IF ( .NOT. XSIGN) THEN
342
IF (SS(I).EQ.'+' .OR. SS(I).EQ.'-') THEN
346
IF (SS(I).GE.'0' .AND. SS(I).LE.'9') THEN
353
IF (SS(I).LT.'0' .OR. SS(I).GT.'9' .OR.
354
+ ((IEPOW+ISIGN+2).LT.I)) THEN
359
IF (SS(I).EQ.'E') THEN
363
IF (SS(I).EQ.'.') THEN
364
IF (IPOINT.GT.0) THEN
370
IF (SS(I).LT.'0' .OR. SS(I).GT.'9') THEN
386
IF (XCHAR) THEN ! character string
387
LF = MIN((NIN-NOUT),LF) ! max space in array
390
WRITE (FMT(IFMT:),9000) MIN(1,LF)
402
IF (IPOINT.EQ.0) THEN
405
LD = MAX((IEPOW-IPOINT-1),0)
406
WRITE (FMT(IFMT:),9020) LF,LD
416
FMT(IFMT-1:IFMT-1) = ')'
418
READ (SSS(1:L),FMT=FMT(1:IFMT-1)) (ARRAY(J),J=1,NOUT)
424
INTEGER FUNCTION NEL(A,N)
426
C.PURPOSE: Count the number of words in the input array of dimension
427
C N by testing the array on -0 value
428
C.AUTHOR: Rein H. Warmels
430
C.VERSION: 890117 RHW Documented
431
C.VERSION: 910115 RHW IMPLICIT NONE added
444
IF (A(I).EQ.END) THEN
457
C.PURPOSE: put an end of array word in X