!============================================================
!  USERIO.BLK   VERSION 2 ... MAY 9 1980 ... D. MC CUNE
!
!  JAB Feb 2021 -- Convert from COMMON blocks to MODULE
!  TBT May 1995 -- Increase length of XFILE to 130 from 64.
!  DMC JAN 1985 -- MODIFIED TO SUPPORT UREAD5 FEATURES
!   SOFT CODED COMMAND CHARACTERS
!    E.G. MFILI (DFLT "@") INDIRECT INPUT FILE CHARACTER
!
!   OUTPUT LUN STACK FOR MULTIPLE SIMULTANEOUS INDIRECT FILES
!    OPEN FOR OUTPUT-- RECORDING OF PROMPTS/INSTRUCTIONS.
!
!   TYPEAHEAD BUFFER STACK TO ALLOW TYPEAHEAD PAST INDIRECT
!    INPUT FILENAMES
!
!  character buffers:  size:
!
!============
MODULE USERIO
  IMPLICIT NONE

  INTEGER, PARAMETER :: urdbufl=512

  INTEGER, DIMENSION(10) :: luntin,ncmnd,nplc
  INTEGER, DIMENSION(3)  :: nchbfp
  INTEGER ncbufp,lpunct,lprbuf,nprbuf,nvidch,ncpwd, &
       nlunin,lunido,luntrm,maxlin,nchara,ncp1a,ncp2a,ncharc,ncp1c, &
       nlunio,lbuff,lfiln,lpnam,lpval,luword,nbline,ibatch,nttyp,nclear, &
       nplotd,lready,lpmmsg,lmarkn,levcmd,lcmdin,nsaved,npgmax, &
       nplmax,npgc
!
!  ** note ** if urdbufl changes then see also fldlim.for, iscmp0.for,
!     and numfld.for in the ureadsub library...
!
!    NLUINI=.TRUE. IF BLOCK HAS BEEN INITIALIZED VIA CALL USINIT
!  COMMON BLOCK CONTAINING BUFFERS AND INFORMATION USEFUL
!   FOR CARRYING OUT USER-COMPUTER INTERACTION
!
!  CBUFF  -- (urdbufl) CHARACTER BUFFER  PACKED   - COMMAND INPUT
!  CBUFFP -- RECORD OF RECENT INPUT LINES - CAPACITY NCBUFP
!   NCHBFP CHARACTERS IN EACH ENTRY OF CBUFFP
!  DBUFF  -- (urdbufl) CHARACTER BUFFER UNPACKED  - COMMAND INPUT
!  BBUFF  -- (urdbufl) CHARACTER BUFFER UNPACKED  - PROGRAM PROMPT
!   NCHAR-- # OF CHARACTERS BEFORE "$" IN BBUFF
!  NCPWD  -- # OF CHARACTERS PER WORD
!
!  MSEMI  -- ASCII SEMICOLON
!  MDOLLR -- ASCII DOLLAR SIGN "$"
!  MCAROT -- ASCII ">"
!  MIDAT  -- ASCII "@"
!
!  NLINDI -- LOGICAL FLAG  .TRUE.==> USING INDIRECT FILE AS INPUT
!   NEW AUG 1981
!    NLXPER  -- LOGICAL FLAG  .TRUE. ==> PROGRAM USER IS EXPERT
!      SUPPRESS EXTRA PROMPTS
!    NLXOUT  -- LOGICAL FLAG  .TRUE. ==> PRINT EXTRA PROMPTS
!      NLXOUT = (.NOT.NLXPER).AND.(.NOT.NLINDI)
!  NLINDO -- LOGICAL FLAG  .TRUE.==> CREATING INDIRECT FILE AS OUTPUT
!
!  LUNTIN -- STACK OF INPUT L.U.N. S
!  MAXLIN -- MAX # OF INPUT UNITS (EQUALS MAX LEVEL OF
!             INDIRECT FILES)
!  NLUNIN -- POINTS TO CURRENT INPUT LINE
!
!  LUNIDO -- POINTS TO OUTPUT DEVICE LUN FOR CREATING INDIRECT FILE
!  LUNTRM --- LUN OF TERMINAL FOR OUTPUT
!  IBATCH --- =1 IF IN BATCH, 0 OTHERWISE.
!    IBATCH SET BY: CALL ISBATCH(IBATCH);  [JOD]ISBATCH.OBJ
!
!  XFILE-- LIST OF INDIRECT FILE NAMES FOR TRACE-BACK
!  NCMND-- LIST OF COMMAND COUNTS FOR TRACEBACK
!
!  " EDITOR " COMMON:
!    NLEDIT = .TRUE. IF EDITOR IN EFFECT
!    NLCOPI = .TRUE. TO COPY TERMINAL INPUT TO OUTPUT FILE
!    NLSWIN = .TRUE. IF CHANGING INPUT CHANNEL DUE TO EDIT COMMAND
!    NSAVED = # OF FILE INPUT LINES SAVED PRIOR TO PROCESSING
!    MSTAR = '*' SPECIAL CHARACTER USED TO INVOKE SPECIAL FUNCTIONS
!
!    LURCAP = .TRUE. for uppercase script filenames
!             .FALSE. for lowercase filenames -- unix option
!
!-----
!  23 JAN 1982
!   NLNULL - FLAG TO UREAD - PERMIT NULL LINE ANSWER TO PROMPT
!     NLCRI -- VALUE OF NLNULL TO USE FOR COMMAND INPUT MODE
!     (SET VIA ROUTINE URDCRI)
!   nlcmd -- .TRUE. to enable * commands 
!   NL1LIN - FLAG TO UPROMT - PROMPT AND ANSWER ON ONE LINE
!   NLHOLD - FLAG TO UREAD UTILITIES
!     IF NLHOLD=.TRUE. (INITIAL DEFAULT) DO NOT DELETE STRING FROM
!   INPUT BUFFER AFTER DECODING (IDCODE,FDCODE,IXUOPC, ETC.)
!     IF NLHOLD .FALSE. DO DELETE STRING AND RE-JUSTIFY INPUT BUFFER
!   ALLOWS STACKING OF MULTIPLE COMMANDS ON LINE
!     TO SET NLHOLD CALL UHOLD; TO CLEAR CALL UFREE
!
!     NCLEAR - PAGE CLEARING COUNT
!     NPLOTD - SGLIB PLOT DISPLAY COUNT
!-----
!-----
!  STRING PARAMETER BLOCKS--
!   (DEC. 1980  D. MC CUNE)  ALLOWS "LOCAL" AND "GLOBAL" STRING
!   PARAMETER DEFINITION; THESE MAY IN EFFECT BE INPUT ARGUMENTS
!   FROM HIGHER-LEVEL TO LOWER LEVEL INDIRECT INPUT FILES.
!    E.G. LINE "@FILE.TMI/NSHOT=12345" WILL EXECUTE INDIRECT
!   FILE "FILE.TMI"; ANY OCCURENCE OF THE STRING "=NSHOT" IN
!   "FILE.TMI" WILL BE REPLACED BY THE SPECIFIED STRING "12345"
!     LOCAL-- PARMS DEFINED IN @FILE LINE
!     GLOBAL-- PARMS DEFINED IN LINE OF FORM /NAME=VALUE
!       / IN *FIRST* CHARACTER POSITION.
!   WHEREVER STRING =(PARM. NAME) OCCURS IN INPUT STREAM, BOTH
!   LOCAL AND GLOBAL VALUE TABLES ARE SEARCHED; IF SEARCH FAILS,
!   USER IS PROMPTED TO SUPPLY VALUE; IF IN BATCH AND VALUE
!   IS NOT FOUND, CODE HALTS.
!     GLOBAL ARRAYS-- PGLNAM(1500),PGLVAL(1500),NPGMAX(=1500),NPGC
!     LOCAL ARRAYS-- PLCNAM(300,10),PLCVAL(300,10),NPLC(10)
!       NPLMAX(=300)  (ALSO MAX # OF LEVS = MAXLIN = 10)
!     INCL. PARAMETER NAMES,VALUES, AND COUNTERS
!
!
!  REV. DEC. 1980-- ADD 3 CHARACTER VARIABLE "FILEXT"
!     DEFAULT FILENAME EXTENSION FOR CONSTRUCTING NAMES OF INDIRECT
!     INPUT FILES, 3 CHARACTERS
!
!----
!  CHARACTER*8 UTTYP - USER TTY TYPE (HHT SYSTEM - VAX)
!  INTEGER     NTTYP - DITTO INTEGER CODE (HHT SYSTEM - VAX)
!    CF [NBEAM.TERMCTL]TERMCTL SUBROUTINE LIBRARY -
!      READS LOGICAL SYMBOL "TERMINAL_TYPE" FROM JOB LOGIN.COM
!  (DMC - NOV 1984)
!
!----
!  DMC FEB 1989
!  UPUNCT(1:LPUNCT) CONTAINS LIST OF USER DEFINED "PUNCTUATION
!  CHARACTERS" WHICH DELIMIT UREAD INPUT WORDS AND ARE VISIBLE AS
!  WORDS TO THE APPLICATION.  INITIAL DEFAULT WILL BE LPUNCT=0,
!  NO PUNCTUATION DEFINED.
!
!  DMC FEB 1989
!  UPCHAR -- CHARACTER ENTERED BY USER TO ACKNOWLEDGE "UPAUSE" CALL
!  *INTERACTIVE JOBS ONLY*
!
!
!  ADDED MAXIMUM LENGTHS OF ELEMENTS DMC MAY 86
!   LBUFF - LENGTH (CHARACTERS) OF INPUT LINE BUFFER
!   LFILN - LENGTH (CHARACTERS) OF UREAD FILENAME
!   LPNAM - LENGTH (CHARACTERS) OF UREAD STRING PARAMETER NAME
!   LPVAL - LENGTH (CHARACTERS) OF UREAD STRING PARAMETER VALUE
!      ... SEE USINIT.FOR
!
!
!   NBLINE-- NO. OF BLANK LINES TO TYPE BEFORE EACH PROMPT
!
!
!  DMC JAN 1985
!    LEVCMD=1 CMD INPUT  =2 TEXT INPUT (NO UPPERCASE CONVERSION...)
!    LCMDIN=1 TTY/FILE INPUT  =2 USER PROGRAM CALL
!
  INTEGER NCPRM(2)
  LOGICAL LURCAP,NLEDIT,NLSKIP,NLCOPI,NLECHO,NLUINI,NLJAVA
  CHARACTER*1 MSTAR,MFILI,MFILO,MBRNCH,MTARGT,MCOMMT, &
       MPARAM,MSUB1,MSUB2(2),MCMD,MQMARK,MCOLON,M1QUOT,M2QUOT,MLBRAK,MRBRAK
  CHARACTER*128 ABUFF,USRCMD
  CHARACTER*(urdbufl) CBUFF,CBUFFP(3),AHDBUF(10),UWORD,PREBUF(8)
  LOGICAL NLUSRC,NLSSUB
  CHARACTER*130 URFILE
  CHARACTER*64 URMARK
  Character*1   T1buff(urdbufl)
  Character*(urdbufl) T2buff
  Character*64  T1File, T2File
  CHARACTER*1 BBUFF(urdbufl),DBUFF(urdbufl),MSEMI,MCAROT,MIDAT,MDOLLR
  CHARACTER*1 MSLASH,MEQS,MDOT
  CHARACTER*8 UTTYP,VIDCHS
  CHARACTER*16 UPUNCT
  CHARACTER*1 UPCHAR
  LOGICAL NLINDI,NLINDO,NLXPER,NLXOUT,NLRVID
  LOGICAL NLNULL,NL1LIN,NLHOLD,NLCRI,nlcmd
  CHARACTER*130 XFILE(10)
  CHARACTER*3 FILEXT
!
!  if the sizes of these arrays change, update definitions of
!  NPGMAX and NPLMAX in ureadsub/usinit.for
!
  CHARACTER*16 PGLNAM(1500),PLCNAM(300,10)
  CHARACTER*96 PGLVAL(1500),PLCVAL(300,10),PRMSUB
!
  integer levdflt

  data NLUINI/.FALSE./
  data levdflt/1/
!
END MODULE USERIO
