C******************** START FILE USPLNM.FOR ; GROUP USPARM ******************
C---------------------------------------------------------------
C&  USPLNM  CHECK LEGALITY AND PACK UREAD PARAMETER NAME
C   INPUT-- ZLINE:  UNPACKED DATA LINE (1 CHAR PER WORD)
C           LLINE:  LENGTH THEREOF
C           IND1:  1ST INDEX OF NAME FIELD
C           IND2:  LAST INDEX OF NAME FIELD
C      (IND1,IND2 MODIFIED ON OUTPUT)
C   OUTPUT- ZNAME:  16 CHAR RIGHT-JUSTIFIED PACKED ALPHANUMERIC NAME
C           IER     =0: NORMAL SUCCESSFUL COMPLETION
C                   =1: ILLEGAL SYNTAX IN NAME FIELD (E.G IMBEDDED
C                       BLANKS)
C                   =2: ILLEGAL CHARACTER IN NAME FIELD
C
C
      SUBROUTINE USPLNM(ZLINE,LLINE,IND1,IND2,ZNAME,IER)
      PARAMETER (NLEGLC=38)
      INCLUDE 'USERIO'
      CHARACTER*1 ZLINE(LLINE)
      CHARACTER*16 ZNAME
      CHARACTER*1 ZBLANK,ZLEGAL(NLEGLC),ZUT(16)
      DATA ZBLANK/' '/
      DATA ZLEGAL/'A','B','C','D','E','F','G','H','I','J'
     >             ,'K','L','M','N','O','P','Q','R','S','T'
     >             ,'U','V','W','X','Y','Z','1','2','3','4'
     >             ,'5','6','7','8','9','0','_','$'/
C
C  START OF EXECUTABLE CODE.  IGNORE LEADING AND TRAILING BLANKS
C
      IER=0
C
      ILENMX=LEN(ZNAME)
C
 10   CONTINUE
        IF(IND1.GT.IND2) GO TO 500
        CALL UDELIM(ZLINE(IND1),JCODE)
        IF((JCODE.LT.1).OR.(JCODE.GT.2)) GO TO 20
        IND1=IND1+1
      GO TO 10
C
 20   CONTINUE
        IF(IND2.LT.IND1) GO TO 500
        CALL UDELIM(ZLINE(IND2),JCODE)
        IF((JCODE.LT.1).OR.(JCODE.GT.2)) GO TO 40
        IND2=IND2-1
      GO TO 20
C
 40   CONTINUE
      INDIB=IND1
C  CHECK FOR IMBEDDED BLANKS
      CALL UFCHAR(ZLINE,ZBLANK,INDIB,LLINE)
      IF((IND1.LT.INDIB).AND.(IND2.GT.INDIB)) GO TO 500
C  CHECK LENGTH
      ILEN=IND2-IND1+1
      IF(ILEN.GT.ILENMX) GO TO 500
C  CHECK LEGALITY OF EACH CHARACTER
      DO 50 I=IND1,IND2
        CALL USPCAP(ZLINE(I))
        DO 45 J=1,NLEGLC
          IF(ZLINE(I).EQ.ZLEGAL(J)) GO TO 50
 45     CONTINUE
        GO TO 1000
 50   CONTINUE
C  PACK NAME
      DO 60 I=1,ILENMX
        ZUT(I)=ZBLANK
        IF(I.GT.ILEN) GO TO 60
        IND=IND1+I-1
        ZUT(I)=ZLINE(IND)
 60   CONTINUE
      WRITE(ZNAME,1001) (ZUT(I),I=1,ILENMX)
 1001 FORMAT(80A1)
      RETURN
C
C  ERRORS *********
C
 500  CONTINUE
      WRITE(LUNTRM,9001) ILENMX
 9001 FORMAT(' % ILLEGAL SYNTAX IN PARAMETER NAME FIELD:'/
     >  '   NULL NAME, NAME TOO LONG (MAX ',I2,' CHARS), OR'/
     >  '   NAME CONTAINS IMBEDDED BLANKS'/)
      CALL UCLEAR
      CALL UPAUST(1)
      IER=1
      RETURN
C
 1000 CONTINUE
      WRITE(LUNTRM,9002) ZLINE(I)
 9002 FORMAT(' % ILLEGAL CHARACTER "',A1,'" IN PARAMETER'/
     >  '   NAME FIELD; ONLY LETTERS, DIGITS, OR "_" ARE LEGAL'/)
      CALL UCLEAR
      CALL UPAUST(1)
      IER=2
      RETURN
C
      	END
C******************** END FILE USPLNM.FOR ; GROUP USPARM ******************
