	SUBROUTINE USRINP(A,N,TYPE,LENGTH,IDEF,KEYWORD,MESS)
C
C  Note:  This is the UNIX version.  This must be linked with the UNIX 
C         version of NELD.FOR
C	A		(C)	The variable being input
C	N		(C)	The dimension of A
C	TYPE		(C)	The data type of A:  'F','A','I','L'
C	LENGTH		(C)	The number of bytes of A
C	IDEF		(C)	The key for how to accept the input:
C				0 = no default, 1 = default, 3 = default
C				with no verification
C	KEYWORD		(C)	The keyword
C	MESS		(C)	The message
C
C		Version 1, R. D. Ekers
C		Version 2, W. Zwitser, Jan. 2, 1979
C		Version 3, R. D. Ekers, Jan. 5, 1979
C		Modified for use on the Mt. Stromlo VAX
C		Version 4, Donald H. Gudehus, June, 1993
C		Added the COMMON BLOCK /WRITE_FILES/ which contains the
C		logical DONT_WRITE_FILES.  In MIIPS usage, this logical is
C		by default set to .FALSE., and the LOG and SVE files are
C		written to disk.  For some user applications, the accumulation
C		of FOR007.DAT and FOR049.DAT files can be avoided by setting
C		the logical to .TRUE. 
C		Version 4U, Donald H. Gudehus, August, 1994
C		Made it work under UNIX
C		Version 5, Donald H. Gudehus, March 27, 1998
C		Changed FORMAT statement 1001 slightly.
C		Version 6, Donald H. Gudehus, March 22, 1999
C		Changed TYPE and ATYPE from BYTE to CHARACTER.
C		Version 7, Donald H. Gudehus, April 7, 1999
C		Changed "0 to '0'O and removed 8 GO TOs.
C		Version 8U, Donald H. Gudehus, September 28, 1999
C		Changed SETEND to ISETEND for integer case
C		Version 8, Donald H. Gudehus, October 30, 2001
C		Changed formatting of output to log file, and screen
C		so that small numbers of parameters are arranged
C		horizontally on one line as before, but large numbers of
C		parameters are output on successive lines.  This allows
C		for arbitrarily large numbers of parameters for one
C		keyword.  Also, allowed MESS to be written to the screen
C		and to the log file when input is from a save file.
C		Version 9, Donald H. Gudehus, September 21, 2002
C		Increased B1 to 2048 to allow for larger number of dimensions
C		in an array (consistent with changes in SAVE.FOR and
C		STRKEY.FOR;  replaced ASSIGN statement for IAFILL with
C		a simple GO TO.
C		Version 10, Donald H. Gudehus, February 24, 2004
C		In writing out default values to the terminal and save
C		files, logicals would sometimes not be written if they
C		were declared as LOGICAL rather than LOGICAL*1 in the 
C		calling program.  This was because the ENDLIN function
C		was being used.  Now this is only used for integer
C		and real variables.
C		Version 10UM, Donald H. Gudehus, February 2, 2005
C		Introduced ENTRY USRINP_CHAR for Absoft compiler on Mac OS
C		Version 11, D. Gudehus, March 30, 2005
C		Changed LB to LOGICAL*4 and ALB to ALB(4) so that variable can
C		be declared as either LOGICAL*1, LOGICAL*2, or LOGICAL in
C		calling program and function on either little endian or big
C		endian machines.
C
	COMMON /BKEY/ B1
	PARAMETER MAXLP=10,NR8=2048
	CHARACTER*(*) KEYWORD,MESS
	LOGICAL LB,LOOP,SEP,DEFAULT,ENTERED,KEYWORD_FOUND
	BYTE DOLOOP(2,MAXLP),TYPEL(2,3),TYPEL6(6),LTYPEL(3)
	BYTE ALB(4),LPSYM,INSERT
	BYTE A1(132),A(1),B1(2048)
	CHARACTER*1 TYPE,ATYPE(4)
	CHARACTER*40 VFORMAT
	REAL*4 A4
	REAL*8 B8(NR8),INCR,LOW,UPP,A8
	INTEGER*2 I2
	INTEGER*4 I4,ENDLIN
	EQUIVALENCE(A8,A4,I4,I2,A1,LB),(TYPEL,TYPEL6),(ALB,LB)
C
	LOGICAL DONT_WRITE_FILES
	COMMON /WRITE_FILES/ DONT_WRITE_FILES
C
	DATA ATYPE/'F','A','I','L'/
	DATA TYPEL/4,8,0,0,2,4/ !  Floating, Character, Integer
	DATA LTYPEL/1,2,4/ !  Logical, DHG
C
	GO TO 1
	ENTRY USRINP_CHAR(N,TYPE,LENGTH,IDEF,KEYWORD,MESS,A)
   1	LPSYM=':'
	DEFAULT=.FALSE.
	ENTERED=.FALSE.
	NX=N*LENGTH
C  # of double-length words in input array B8
	NI=0
C  Default type is 1
	ITYPE=1
C  What type?
	DO I=1,4
	  IF (TYPE.EQ.ATYPE(I)) THEN
	    ITYPE=I
	  END IF
	END DO
	IF ((ITYPE.NE.2.AND.ITYPE.NE.4).AND.(LENGTH.NE.TYPEL(1,ITYPE).AND.
	1LENGTH.NE.TYPEL(2,ITYPE))) THEN
	  CALL ERROR(-4,'ILLEGAL LENGTH OF PARAMETER FOR THIS DATA TYPE')
	ELSE IF (ITYPE.EQ.4.AND.LENGTH.NE.LTYPEL(1).AND.LENGTH.NE.LTYPEL(2)
	1.AND.LENGTH.NE.LTYPEL(3)) THEN
	  CALL ERROR(-4,'ILLEGAL LENGTH OF PARAMETER FOR LOGICAL DATA TYPE')
	END IF
C  Get input parameters if present in .SVE file.
	NCH=0
	CALL GETKEY(KEYWORD,NCH)  ! In file STRKEY.FOR
	IF ((IDEF.EQ.0.OR.IDEF.EQ.1.OR.IDEF.EQ.3).AND.NCH.EQ.-1) NCH=0
	IF (NCH.NE.0) THEN
	  KEYWORD_FOUND=.TRUE.
	ELSE
	  KEYWORD_FOUND=.FALSE.
	END IF
  20	WRITE(6,1000) MESS
1000	FORMAT(1X,A)
	IF (.NOT.DONT_WRITE_FILES) WRITE(7,1000) MESS
	IF (KEYWORD_FOUND) GO TO 100
C
	WRITE(6,1001) KEYWORD
1001	FORMAT(1X,A,$)  ! D. H. G.
C  Perform input
	GO TO 100
 101	CONTINUE  ! Return point for DO looping
C  Was a default possible?
	IF ((IDEF.NE.0).OR.(.NOT.DEFAULT)) GO TO 30
	CALL ERROR(-1,'NO DEFAULT IS POSSIBLE')
C  Insist on reply if IDEF=0
	GO TO 20
  30	IF (DEFAULT) THEN
	  GO TO 140  ! Performs DEFAULTOUT
	END IF
C
	IF (.TRUE.) GO TO 110
 
C  Read input
C**************************************** PROC INPT
 100	CONTINUE
  	IF (NCH.EQ.0) THEN !  KEYWORD not in .SVE file
	  READ(5,2000) NCH,(B1(I),I=1,NCH)
2000	  FORMAT(Q,80A1)
	  ENTERED=.TRUE.
	END IF
C
2001	FORMAT('('' '',A,'I,'A1)') !  For Absoft compiler
	IF (NCH.LT.0) THEN
	  WRITE (6,2002) KEYWORD
2002	  FORMAT(1X,A)
	  IF (.NOT.DONT_WRITE_FILES) WRITE(7,2002) KEYWORD
	ELSE IF (NCH.EQ.0) THEN !  Default
	  IF (.NOT.DONT_WRITE_FILES) WRITE(7,2002) KEYWORD
	ELSE !  KEYWORD was in .SVE file, or parameters
	     !  entered above
	  IF (NCH.LT.50) THEN !  Horizontally spaced
	    NCHAR=NCH
	    WRITE(VFORMAT,2001) NCH
	    IF (.NOT.ENTERED) THEN
	      WRITE(6,VFORMAT) KEYWORD,(B1(I),I=1,NCH)
C	      WRITE(6,2001) KEYWORD,(B1(I),I=1,NCH)
C2001	      FORMAT(1X,A,<NCHAR>A1)
	    END IF
	    IF (.NOT.DONT_WRITE_FILES) THEN
	      WRITE(7,VFORMAT) KEYWORD,(B1(I),I=1,NCH)
C	      WRITE(7,2001) KEYWORD,(B1(I),I=1,NCH)
	    END IF
	  ELSE !  Vertically spaced (to avoid too long a line) D. H. G.
	    IF (.NOT.ENTERED) THEN
	      WRITE (6,2002) KEYWORD
	    END IF
	    IF (.NOT.DONT_WRITE_FILES) THEN
	      WRITE (7,2002) KEYWORD
	    END IF
	    I=1
C  Find the beginning (the first non-blank character)
	    DO WHILE (I.LE.NCH)
	      IF (B1(I).EQ.32) THEN
	        I=I+1
	      ELSE
C  Find the next blank
	        N1=I
	        J=N1+1
	        DO WHILE (B1(J).NE.32.AND.J.LE.NCH)
	          J=J+1
	        END DO
	        IF (J.GT.NCH) THEN
	          N2=0
	        ELSE
	          N2=J
	        END IF
	        IF (N2.GE.N1.AND.N2.LE.NCH) THEN
	          NCHAR=N2-N1
	          WRITE(VFORMAT,2001) NCHAR
	          IF (.NOT.ENTERED) THEN
	            WRITE (6,VFORMAT) (B1(I),I=N1,N2-1)
C	            WRITE (6,2001) (B1(I),I=N1,N2-1)
	          END IF
	          IF (.NOT.DONT_WRITE_FILES) THEN
	            WRITE (7,VFORMAT) (B1(I),I=N1,N2-1)
C	            WRITE (7,2001) (B1(I),I=N1,N2-1)
	          END IF
	          I=N2+1
	        ELSE
	          NCHAR=NCH-N1+1
	          WRITE(VFORMAT,2001) NCHAR
	          IF (.NOT.ENTERED) THEN
	            WRITE (6,VFORMAT) (B1(J),J=N1,NCH)
C	            WRITE (6,2001) (B1(J),J=N1,NCH)
	          END IF
	          IF (.NOT.DONT_WRITE_FILES) THEN
	            WRITE (7,VFORMAT) (B1(J),J=N1,NCH)
C	            WRITE (7,2001) (B1(J),J=N1,NCH)
	          END IF
	          I=NCH+1 !  Ends the loop
	        END IF
	      END IF
	    END DO
	  END IF
	END IF
C
	IF (NCH.NE.-1.AND..NOT.DONT_WRITE_FILES) CALL SAVEP(KEYWORD,NCH)
	! Saves the keyword, and parameters (contained in COMMON block BKEY)
	IF (NCH.LE.0) THEN
	  DEFAULT=.TRUE.
	ELSE  ! Decodes loop structures
	  DEFAULT=.FALSE.
	  NLOOP=0
C  Real plus integer only
	  IF (ITYPE.EQ.1.OR.ITYPE.EQ.3) THEN
	    DO I=1,MAXLP
	      DOLOOP(1,I)=0
	      DOLOOP(2,I)=0
	    END DO
	    NLOOP=1
C  Startword of do-loop in B1
	    NWORD=1
	    INSERT=0
	    LOOP=.FALSE.
	    SEP=.TRUE.
	    DO 103 I=1,NCH
	      IF (B1(I).EQ.LPSYM) THEN
	        IF (DOLOOP(2,NLOOP).EQ.1) THEN
C  Increment value present
	          DOLOOP(2,NLOOP)=2
	          INSERT=INSERT+1
	        ELSE IF (DOLOOP(2,NLOOP).EQ.2) THEN
	          CALL ERROR(-1,'ERROR IN DO-LOOP')
	          GO TO 20
	        ELSE
C  Uppervalue present
	          DOLOOP(1,NLOOP)=NWORD+INSERT
	          DOLOOP(2,NLOOP)=1
	          INSERT=INSERT+1
	        END IF
	        LOOP=.TRUE.
	        B1(I)=','
	      ELSE
C  Separation symbols
	        IF (B1(I).EQ.' '.OR.B1(I).EQ.',') THEN
	          IF (.NOT.SEP) THEN
	            NWORD=NWORD+1
	            SEP=.TRUE.
	          END IF
	          IF (LOOP) THEN
	            NLOOP=NLOOP+1
	            LOOP=.FALSE.
	          END IF
	        ELSE
	          SEP=.FALSE.
	        END IF
	      END IF
  103 	    CONTINUE
	    IF (.NOT.LOOP) THEN
	      NLOOP=NLOOP-1
	    END IF
	  END IF
	END IF
C  Decode input string into REAL*8 or Characters
	IF (NCH.GT.0) THEN
	  IF (TYPE.NE.'A'.AND.TYPE.NE.'L') CALL DCD(B1,NCH,B8,NR8)
C  # of double-length words
	  NI=NELD(B8,NR8)
	END IF
	GO TO 101
C
C  Fill output array
C*************************************** PROC OUT
 110	IF (ITYPE.EQ.2) THEN
C  Alphanumeric mode
	  DO I=1,NCH
	    A(I)=B1(I)
	  END DO
C  Remaining characters binary zero
	  DO I=NCH+1,NX
	    A(I)='0'O
	  END DO
	  RETURN
	ELSE IF (ITYPE.EQ.4) THEN
C  Logical
	  IF (B1(1).EQ.'Y'.OR.B1(1).EQ.'J'.OR.B1(1).EQ.'T'.OR.B1(1)
	1 .EQ.'y'.OR.B1(1).EQ.'j'.OR.B1(1).EQ.'t') THEN
	    LB=.TRUE.
	  ELSE
	    LB=.FALSE.
	  END IF
	  A(1)=ALB(1) !  DHG
	  IF (LENGTH.EQ.2) A(2)=ALB(2) !  DHG
	  IF (LENGTH.EQ.4) THEN !  DHG
	    A(3)=ALB(3)
	    A(4)=ALB(4)
	  END IF
	  RETURN
	END IF
C  Reals plus integers

C  ************* Perform DOVAL*********************
C  Substitute current value for DO loop variable ($).
C  $ is ASCII 36;  & is ASCII 38.  Necessary for Absoft compiler
	DO I=1,NI
	  IF (B8(I).EQ.36) B8(I)=DOVAL(IDUM)
	  IF (B8(I).EQ.38) B8(I)=DOVAL2(IDUM)
	END DO
C  ************************************************
C  Position in A
	IPOS=0
C  Next loop (if present)
	ILOOP=1
C  Position in B8
	IIN=0
	IF (NI.GT.0) THEN
  119	CONTINUE
	IIN=IIN+1
	A8=B8(IIN)
C  Perform CONVRT
	ASSIGN 121 TO ICNVRT
	GO TO 120
  121	CONTINUE
	IF (IIN.EQ.DOLOOP(1,ILOOP)) THEN
	  LOW=B8(IIN)
	  IIN=IIN+1
	  UPP=B8(IIN)
	  IF (DOLOOP(2,ILOOP).EQ.1) THEN
C  No iNCrementvalue was given
	    INCR=1.
	  ELSE
	    IIN=IIN+1
	    INCR=B8(IIN)
	  END IF
C  # of reals to be added in A
	  A4=((UPP-LOW)/INCR)
	  NREAL=IFIX(A4)
	  IF (NREAL.GT.0) THEN
	    DO IREAL=1,NREAL
	      LOW=LOW+INCR
	      A8=LOW
C  Perform CONVRT
	      ASSIGN 122 TO ICNVRT
	      GO TO 120
  122	      CONTINUE
	    END DO
	  END IF
	  ILOOP=ILOOP+1
	END IF
	IF (IIN.LT.NI) GO TO 119
	END IF
C  Close outputarray with "ENDLIN"-value
	IF (NX-IPOS.GE.LENGTH) THEN
	  IF (ITYPE.EQ.3) THEN
	    J=ISETEND(A8) !  For Unix
	  ELSE
	    J=SETEND(A8)
	  END IF
C  PERFORM AFILL
	  GO TO 130
C 131	  CONTINUE
	END IF
	RETURN
C
C  Real - Integer Conversion
C**************************************** PROC CONVRT
  120	IF (ITYPE.EQ.3) THEN
	  IF (LENGTH.EQ.2) THEN
C  integer*2
	    I2=NINT(A8)
	  ELSE
C  integer*4
	    I4=NINT(A8)
	  END IF
	END IF
C  Perform AFILL
C	ASSIGN 132 TO IAFILL
	IF (LENGTH.EQ.4.AND.ITYPE.EQ.1) A4=A8  ! For UNIX
	GO TO 130
  132	CONTINUE
	GO TO ICNVRT,(121,122)
C  Fill input/output array A
C**************************************** PROC AFILL
  130	DO I=1,LENGTH
	  A(IPOS+I)=A1(I)
	END DO
	IPOS=IPOS+LENGTH
	IF (IPOS.GT.NX) THEN
	  CALL ERROR(-3,'NUMBER OF ARRAYELEMENTS EXCEEDED')
	  NCH=0
	  GO TO 20
	END IF
	GO TO 132
C	GO TO IAFILL,(131,132)
C*********************************************** PROC DEFAULTOUT
C  Write out default values
 140	CONTINUE

C	IF (IDEF.GT.2) RETURN
	IF (TYPE.EQ.'A') THEN
1002	  FORMAT('(1X',I,'(A1))') !  For Absoft compiler
	  WRITE(VFORMAT,1002) NX
	  IF (IDEF.LE.2) WRITE(6,VFORMAT) (A(I),I=1,NX)
C	  IF (IDEF.LE.2) WRITE(6,1002) (A(I),I=1,NX)
C  NX is the total number of bytes of the variable in the call
	  IF (.NOT.DONT_WRITE_FILES) WRITE(7,VFORMAT) (A(I),I=1,NX)
	  IF (.NOT.DONT_WRITE_FILES) WRITE(49,VFORMAT) (A(I),I=1,NX)
C	  IF (.NOT.DONT_WRITE_FILES) WRITE(7,1002) (A(I),I=1,NX)
C	  IF (.NOT.DONT_WRITE_FILES) WRITE(49,1002) (A(I),I=1,NX)  
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
C1002	  FORMAT(1X,<NX>A1)
	END IF
	DO 143 J=1,N  ! Repeat for the N words of the variable
	  DO I=1,LENGTH
	    A1(I)=A(LENGTH*(J-1)+I) !  Copies input into A1
	  END DO
	  IF (TYPE.EQ.'I') THEN
	    IF (IENDLIN(I4).EQ.1) RETURN !  For Unix
	  ELSE
	    IF (TYPE.NE.'L') THEN !  D. H. G.
	      IF (ENDLIN(I4).EQ.1) RETURN
	    END IF
	  END IF
C
	  IF (TYPE.EQ.'F') THEN
	    IF (LENGTH.EQ.4) THEN
	      IF (IDEF.LE.2) WRITE(6,1003) A4
	      IF (.NOT.DONT_WRITE_FILES) WRITE(7,1003) A4
	      IF (.NOT.DONT_WRITE_FILES) WRITE(49,1003) A4
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
1003	      FORMAT(1X,G13.6,2X)
	    ELSE
	      IF (IDEF.LE.2) WRITE(6,1004) A8
	      IF (.NOT.DONT_WRITE_FILES) WRITE(7,1004) A8
	      IF (.NOT.DONT_WRITE_FILES) WRITE(49,1004) A8
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
1004	      FORMAT(1X,G16.9)
	    END IF
	  END IF
	  IF (TYPE.EQ.'I') THEN
	    IF (LENGTH.EQ.4) THEN
	      IF (IDEF.LE.2) WRITE(6,1005) I4
	      IF (.NOT.DONT_WRITE_FILES) WRITE(7,1005) I4
	      IF (.NOT.DONT_WRITE_FILES) WRITE(49,1005) I4
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
1005	      FORMAT(1X,I10)
	    ELSE
	      IF (IDEF.LE.2) WRITE(6,1006) I2
	      IF (.NOT.DONT_WRITE_FILES) WRITE(7,1006) I2
	      IF (.NOT.DONT_WRITE_FILES) WRITE(49,1006) I2
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
1006	      FORMAT(1X,I10)
	    END IF
	  END IF
	  IF (TYPE.EQ.'L') THEN
	    IF (IDEF.LE.2) WRITE(6,1007) LB
	    IF (.NOT.DONT_WRITE_FILES) WRITE(7,1007) LB
	    IF (.NOT.DONT_WRITE_FILES) WRITE(49,1007) LB
	!  Writes default parameter values to save file.  Keyword was
	!  already written with call to SAVEP
1007	    FORMAT(1X,L1) !  Must be L1 so that answer is correctly written
			  !  to the "save" file
	  END IF
 143	CONTINUE
 144	RETURN
C
	END
