      SUBROUTINE PARINS(OUTCR,IMAGE,NIM,NAME,VALUE,NUS,NPARM,NPS,ALLOK) 
C
C     * DEC 20/91 - M.LAZARE (MODIFIED TO HANDLE 132 CHAR/LINE).  
C     * FEB 19/91 - F.MAJAESS (MODIFIED TO HANDLE 82 CHAR/LINE). 
C     * JAN 20/83 - R.LAPRISE,B.DUGAS,J.D.HENDERSON.
C
C     * PARAMETER INSERTION SUBROUTINE FOR PROGRAM PARMSUB. 
C 
C     * OUTCR = OUTPUT CARD IMAGE COPIED FROM IMAGE WITH
C     *         SUBSTITUTION VALUES INSERTED. 
C     * IMAGE = INPUT 132 CHARACTER CARD IMAGE WITH
C     *         PARAMETER NAMES BETWEEN DOLLAR SIGNS. 
C     * NIM   = CARD IMAGE NUMBER.
C     * NAME  = INPUT LIST OF PARAMETER NAMES.
C     * VALUE = INPUT LIST OF SUBSTITUTION VALUES FOR THE 
C     *         PARAMETERS IN ARRAY NAME. 
C     * NUS   = NAME USE ARRAY (INCREMENTED EACH TIME USED).
C     * NPARM = NUMBER OF PARAMETERS IN THIS SET. 
C     * NPS   = PARAMETER SET NUMBER. 
C     * ALLOK IS SET TO .FALSE. IF ANY ERROR OCCURS.
C 
      IMPLICIT INTEGER (A-Z)
C     * LEVEL 2,NAME,VALUE,NUS

      CHARACTER*1 IMAGE,OUTCR,NAME,VALUE,DDOL,PN
      DIMENSION IMAGE(132),OUTCR(132) 
      DIMENSION NAME(80,NPARM),VALUE(80,NPARM),NUS(NPARM) 
      DIMENSION PN(80),DDOL(36)
C 
      LOGICAL ALLOK,INSIDE
      DATA DDOL/'A','B','C','D','E','F','G','H','I','J','K','L','M',
     1  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1',
     2  '2','3','4','5','6','7','8','9'/
C-------------------------------------------------------------------- 
C     * PN HOLDS THE PARAMETER NAME READ FROM THE CARD. 
C     * CLEAR THE PREVIOUS CHARACTERS BEFORE INPUTTING NEW DATA.
C
      DO 100 I=1,80
  100 PN(I)='<'
C   
      DO 110 I=1,132
  110 OUTCR(I)=' '
C 
C     * SET COUNTERS AND START SCAN OF CARD IMAGE.
C 
      INSIDE=.FALSE.
      NXTPNC=1
      OUTPTR=1
      IMPTR=0 
C 
C     * INCREMENT IMAGE POINTER. RETURN AT END OF CARD. 
C     * STOP IF CARD ENDS INSIDE A NAME.
C 
  300 IMPTR=IMPTR+1 
      IF(IMPTR.LE.132) GO TO 305 
      IF(.NOT.INSIDE) RETURN
      WRITE(6,6005) 
      WRITE(6,6030) NIM,IMAGE 
      CALL XIT('PARINS',-1) 
C 
C     * IF WE ARE NOT INSIDE A PARAMETER NAME THEN WE 
C     * JUST COPY THE CURRENT CHARACTER TO THE OUTPUT CARD IMAGE. 
C     * IF WE ARE COPYING A BLANK AND THE OUTPUT CARD IMAGE IS FULL 
C     * WE ASSUME THAT INFO ON THE INPUT CARD HAS TERMINATED. 
C 
  305 IF(INSIDE) GO TO 410
      IF(IMAGE(IMPTR).EQ.'$') GO TO 320 
      IF(IMAGE(IMPTR).EQ.' '.AND.OUTPTR.GT.82) GO TO 300
      IF(OUTPTR.GT.132) GO TO 510
      OUTCR(OUTPTR)=IMAGE(IMPTR)
      OUTPTR=OUTPTR+1 
      GO TO 300 
C 
C     * IF WE HAVE JUST ENCOUNTERED A DOLLAR SIGN 
C     * A NEW PARAMETER NAME IS JUST STARTING.
C 
  320 INSIDE=.TRUE. 
      IF(IMAGE(IMPTR+1).NE.'$') GO TO 300 
C 
C     * IF THERE ARE TWO DOLLAR SIGNS IN A ROW
C     * A SPECIAL CHARACTER IS INSERTED THAT IS GENERATED 
C     * FROM THE PARAMETER SET NUMBER (NPS) 
C 
      IF(OUTPTR.GT.132) GO TO 510
      OUTCR(OUTPTR)=DDOL(NPS) 
      OUTPTR=OUTPTR+1 
      INSIDE=.FALSE.
      IMPTR=IMPTR+1 
      GO TO 300 
C 
C     * IF WE ARE INSIDE A PARAMETER NAME THEN WE 
C     * COPY THIS CHARACTER OF THE NAME TO ARRAY PN.
C 
  410 IF(IMAGE(IMPTR).EQ.'$') GO TO 420 
      PN(NXTPNC)=IMAGE(IMPTR) 
      NXTPNC=NXTPNC+1 
      GO TO 300 
C 
C     * IF WE ENCOUNTER THE SECOND DOLLAR SIGN
C     * FIND WHERE THAT NAME IS LOCATED IN THE NAME ARRAY.
C 
  420 IC=1
      DO 440 L=1,NPARM
      DO 430 I=1,80
      IF (NAME(I,L).NE.PN(I)) GO TO 440 
  430 CONTINUE
      N=L 
      GO TO 450 
  440 CONTINUE
C 
C     * IF IT IS MISSING WRITE A MESSAGE AND CONTINUE.
C 
      LPN=NXTPNC-1
      WRITE(6,6010) (PN(I),I=1,LPN) 
      WRITE(6,6030) NIM,IMAGE 
      DO 445 I=1,LPN
  445 PN(I)='<' 
      NXTPNC=1
      INSIDE=.FALSE.
      ALLOK=.FALSE. 
      GO TO 300 
C 
C     * OTHERWISE, COPY THE VALUE TO THE OUTPUT CARD IMAGE. 
C 
  450 IF(VALUE(IC,N).EQ.'<') GO TO 460
      IF(OUTPTR.GT.132) GO TO 510
      OUTCR(OUTPTR)=VALUE(IC,N) 
      OUTPTR=OUTPTR+1 
      IC=IC+1 
      GO TO 450 
C 
  460 INSIDE=.FALSE.
      NUS(N)=NUS(N)+1 
      DO 470 I=1,NXTPNC 
  470 PN(I)='<' 
      NXTPNC=1
      GO TO 300 
C 
C     * RETURN IF THE OUTPUT CARD IMAGE IS TOO LARGE. 
C 
  510 WRITE(6,6020) 
      WRITE(6,6030) NIM,IMAGE 
      ALLOK=.FALSE. 
      RETURN
C-------------------------------------------------------------------- 
 6005 FORMAT('0...INPUT CARD ENDS INSIDE A NAME')
 6010 FORMAT('0...MISSING VALUE FOR PARAMETER -',80A1) 
 6020 FORMAT('0...OUTPUT CARD IMAGE EXCEEDS 132 CHARACTERS')
 6030 FORMAT('0',17X,'ON CARD ',I5,' -',132A1) 
      END 
