*DECK PMAXS
      SUBROUTINE D2P(NENTRY,HENTRY,IENTRY,JENTRY,KENTRY)
*
*-----------------------------------------------------------------------
*
*Purpose:
* PMAXS interface file generation.
*
*Copyright:
* Copyright (C) 2015 IRSN
*
*Author(s): J. Taforeau
*
*parameters: input/output
* NENTRY  number of LCM objects or files used by the operator.
* HENTRY  name of each LCM object or file:
*         HENTRY(1): modification type(L_MAP);
*         HENTRY(2): read-only type(L_POWER).
* IENTRY  type of each LCM object or file:
*         =1 LCM memory object; =2 XSM file; =3 sequential binary file;
*         =4 sequential ascii file.
* JENTRY  access of each LCM object or file:
*         =0 the LCM object or file is created;
*         =1 the LCM object or file is open for modifications;
*         =2 the LCM object or file is open in read-only mode.
* KENTRY  LCM object address or file unit number.
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER      NENTRY,IENTRY(NENTRY),JENTRY(NENTRY)
      TYPE(C_PTR)  KENTRY(NENTRY)
      CHARACTER    HENTRY(NENTRY)*12
*----
*  LOCAL VARIABLES
*----
      INTEGER :: STAVEC(40) = 0
      CHARACTER TEXT*72
      INTEGER UV
      INTEGER :: NFC1 = 0
      INTEGER :: NFC2 = 0
      INTEGER :: NFC3 = 0
      INTEGER :: NFC4 = 0
      INTEGER :: NXC  = 0
      INTEGER :: JOBT  = 0
      INTEGER :: NGP = 2
      INTEGER :: NCRD = 0
      INTEGER :: MIX = -1
      INTEGER :: FA_K = 1
      INTEGER :: IUPS = 0
      INTEGER :: USRSTA = 0
      REAL :: VERS = 3.0
      REAL :: SFAC = 1.0
      REAL :: BFAC = 1.0
      REAL FLOTT
      INTEGER PHASE, ITYPLIR, NITMA
      DOUBLE PRECISION DFLOT
      INTEGER :: IPRINT = -1
      INTEGER,DIMENSION(20) :: CRDINF = -1
      INTEGER,DIMENSION(12) :: USRVAL = 0
      REAL,DIMENSION(5)::FC1=(/15.0,15.0,3.0,2.78613,0.73659 /)
      REAL,DIMENSION(8)::FC2
      DATA FC2/6.2506E-01,1E-04,6*-1.0/
      REAL,DIMENSION(7)::FC3
      DATA FC3/2.4921E+02, 2.4921E+02, 2.4921E+02, 2.3020E+01,
     1    1.4407E+02, 4.5099E+01, 4.5099E+01/
      REAL,DIMENSION(3)::FC4
      DATA FC4/1.44270E+00, 7.21350E-01, 7.21350E-01/
      REAL,DIMENSION(3)::XSC
      DATA XSC/ 4.0, 4.0, 5.32151E-01/
      CHARACTER*16 :: JOBTIT = 'D2P.PMAXS'
      CHARACTER*40 :: COM = 'PWR CASE : UOX/MOX CORE FUEL'
      CHARACTER*12 :: FILNAM = 'HELIOS.dra'
      CHARACTER*4 :: DER = 'T'
      CHARACTER*4 :: JOBOPT(14)
      CHARACTER*5 :: MESH = 'SAP'
      CHARACTER*4 :: USRPAR(12)
      REAL USRVAPK(12,10)
      CHARACTER*4 :: CRDMOD = ' '
      CHARACTER*3 :: ADF = 'DRA'
      CHARACTER*8,DIMENSION(6) :: PKEY
      DATA PKEY/ "BARR","DMOD","CBOR","TCOM","TMOD","BURN"/
      CHARACTER*12,DIMENSION(3) :: ISOT
      DATA ISOT/ "XE135PF","SM149PF","I135PF"/
      DATA JOBOPT/14*'F'/
      LOGICAL :: SAP=.FALSE.
      LOGICAL :: MIC=.TRUE.
      LOGICAL :: EXCESS=.FALSE.
      LOGICAL :: SCAT=.FALSE.
      LOGICAL :: LADD=.FALSE.
      LOGICAL :: LNEW=.FALSE.
*----
*  parameters VALIDATION
*----
*----
*  RECOVER iPHASE AND iPRINT INDICES
*----
      WRITE(6,*) "****************************************************"
      WRITE(6,*) "*          RECOVERING DRAG2PARCS DATA INPUT        *"
      WRITE(6,*) "****************************************************"

 100  CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
      IF (ITYPLIR.NE.3) THEN
       CALL XABORT ('@D2P: KEYWORD EXPECTED AS INPUT OF D2P: MODULE')
      ELSE IF (ITYPLIR.EQ.3) THEN
       IF (TEXT.EQ.'PHASE' ) THEN
        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
        IF (ITYPLIR.EQ.1) THEN
         PHASE=NITMA
         GO TO 100
        ELSE
         CALL XABORT('@D2P: INTEGER EXPECTED AFTER KEYWORD PHASE')
        ENDIF
       ELSE IF (TEXT.EQ.'EDIT' ) THEN
        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
        IF (ITYPLIR.EQ.1) THEN
         IPRINT=NITMA
         GO TO 100
        ELSE
         CALL XABORT('@D2P: INTEGER EXPECTED AFTER KEYWORD EDIT')
        ENDIF
       ELSE IF (TEXT.EQ.'FUEL' ) THEN
        FA_K=1
        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
        IF (ITYPLIR.NE.3) THEN
         CALL XABORT ('@D2P: KEYWORD BARR EXPECTED AFTER FUEL CARD')
        ELSE IF (TEXT.EQ.'BARR') THEN
  10     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF (ITYPLIR.EQ.1 .AND. TEXT .NE.'ENDBARR') THEN
          IF (TEXT .EQ. 'DEF' .OR. TEXT .EQ. 'USER') THEN
           NCRD = NCRD + 1
           IF (NCRD <= 20) THEN
            CRDINF(NCRD)=NITMA
            GO TO 10
           ELSE
            CALL XABORT('@D2P: NUMBER OF BARR COMPOSITIONS EXCEED 20')
           ENDIF
          ELSE
            CALL XABORT('@D2P: DEF OR USER KEYWORD EXPECTED AFTER BARR'
     1      //' KEYWORD')
          ENDIF
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
  11       IF (TEXT .EQ. 'GRID') THEN
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.NE.3) THEN
             CALL XABORT('@D2P: CHARACTER EXPECTED AFTER GRID KEYWORD')
            ELSE
             IF((TEXT.EQ.'SAP').OR.(TEXT.EQ.'DEF').OR.
     1         (TEXT.EQ.'USER')) THEN
              IF (TEXT.EQ.'SAP') THEN
              MESH=TEXT(:5)
               GO TO 10
              ELSE IF (TEXT.EQ.'DEF') THEN
              MESH=TEXT(:5)
               GO TO 10
              ELSE IF (TEXT.EQ.'USER') THEN
  12           CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
               IF (ITYPLIR.NE.3) THEN
                CALL XABORT('@D2P: KEYWORD EXPECTED AFTER USER KEYWORD')
               ELSE IF (TEXT.EQ.'NEW') THEN
                LNEW=.TRUE.
                GO TO 12
               ELSE IF (TEXT.EQ.'GLOBAL') THEN
                IF (LNEW) THEN
                 CALL XABORT('@D2P: INCOMPATIBLE OPT GLOBAL WITH NEW')
                ENDIF
                MESH='GLOB'
  90            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
                IF  (ITYPLIR.NE.3) THEN
                 CALL XABORT('@D2P: PKEY NAME EXPECTED IN GLOBAL OPT')
                ELSE
                 IF (TEXT.EQ.'ENDGLOBAL') GO TO 10
                 IF(NITMA > 4) THEN
                  CALL XABORT('@D2P: PKEY NAME IN GLOBAL MUST BE C*4')
                 ELSE
                  CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
                  USRSTA = USRSTA+1
                  USRPAR(USRSTA)=TEXT(:4)
                  IF  (ITYPLIR.NE.1) THEN
                   CALL XABORT ('@D2P: VALUES FOR STATE '//TEXT//
     1              'EXPECTED')
                  ELSE
                   USRVAL(USRSTA)=NITMA
                   GO TO 90
                  ENDIF
                 ENDIF
                ENDIF
               ELSE IF (TEXT.EQ.'ADD') THEN
                MESH='ADD'
                LADD=.TRUE.
  95            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
                IF  (ITYPLIR.NE.3) THEN
                 CALL XABORT('@D2P: PKEY NAME EXPECTED IN USER ADD OPT')
                ELSE
                 IF (TEXT.EQ.'ENDADD') GO TO 10
                 IF(NITMA.NE.4) THEN
                  CALL XABORT('@D2P: STATE NAME IN ADD MUST BE C*4')
                 ELSE
                  USRSTA = USRSTA+1
                  USRPAR(USRSTA)=TEXT(:4)
                  CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
                  IF  (ITYPLIR.NE.1) THEN
                   CALL XABORT('@D2P: VALUES FOR STATE'//TEXT//
     1              'EXPECTED')
                  ELSE
                   USRVAL(USRSTA)=NITMA
                   DO UV=1,USRVAL(USRSTA)
                   CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
                    IF (ITYPLIR .NE. 2) THEN
                     CALL XABORT ('@D2P: REAL EXPECTED IN USER ADD OPT')
                    ELSE
                     USRVAPK(USRSTA,UV)=FLOTT
                    ENDIF
                   ENDDO
                   UV=1
                   GO TO 95
                  ENDIF
                 ENDIF
                ENDIF
               ELSE
                CALL XABORT('@D2P: UNKNOWN OPTION '//TEXT//
     1                'FOR USER OPT')
               ENDIF
              ENDIF
             ELSE
              CALL XABORT('@D2P: UNKNOWN OPTION FOR GRID KEYWORD')
             ENDIF
            ENDIF
           ELSE IF (TEXT.EQ.'DEF' .OR. TEXT.EQ.'USER') THEN
            CRDMOD=TEXT(:4)
            GO TO 10
           ELSE IF (TEXT.EQ.'ENDBARR') THEN
            IF (CRDMOD=='DEF') THEN
              CALL XABORT('@D2P: ENDBARR KEYWORD IS EXPECTED ONLY FOR'
     1        //' USER BARR COMPOSITION')
            ELSE
              GO TO 10
            ENDIF
           ELSE IF (TEXT .EQ. 'SCATTERING') THEN
             SCAT=.TRUE.
             GO TO 10
           ELSE IF (TEXT .EQ. 'ADF') THEN
             CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
             IF(ITYPLIR.NE.3)THEN
              CALL XABORT('@D2P: C*3 EXPECTED AFTER ADF CARD')
             ENDIF
             IF(NITMA.NE.3) THEN
              CALL XABORT('@D2P: C*3 EXPECTED AFTER ADF CARD')
             ENDIF
             ADF=TEXT(:3)
             IF ((ADF.NE.'SEL') .AND. (ADF .NE.'GET')
     >            .AND. (ADF .NE.'DRA')) THEN
              WRITE(6,*) "@D2P: UNKNOWN KEYWORD :", ADF
              CALL XABORT('@D2P: SEL OR GET EXPECTED AFTER ADF CARD')
             ENDIF
             GO TO 10
           ELSE IF (TEXT .EQ. 'ABSORPTION') THEN
   5        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.NE.3) THEN        
             CALL XABORT('@D2P: C*6 EXPECTED AFTER ABSORPTION KEYWORD')
            ELSE IF (TEXT .EQ. 'MIC') THEN
             MIC =.TRUE.
             GO TO 10
            ELSE IF (TEXT .EQ. 'SAP') THEN
             SAP =.TRUE.
             MIC =.FALSE.
             GO TO 5
            ELSE IF (TEXT .EQ. 'EXCESS') THEN
             IF (SAP .EQV. .FALSE.) THEN
              CALL XABORT('@D2P: SAP KEYWORD EXPECTED BEFORE EXCESS')
             ELSE
              EXCESS = .TRUE.
              GO TO 10
             ENDIF
            ELSE
             GO TO 11                
            ENDIF
           ELSE IF (TEXT .EQ. 'PKEY') THEN
  15        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.NE.3) THEN
             CALL XABORT('@D2P: CHARACTER EXPECTED AFTER PKEY KEYWORD')
            ELSE
             IF (TEXT.EQ.'BARR') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(1)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'DMOD') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(2)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'CBOR') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(3)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'TCOM') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(4)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'TMOD') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(5)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'BURN') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              PKEY(6)=TEXT(:8)
              GO TO 15
             ELSE IF (TEXT.EQ.'ENDPKEY') THEN
             GO TO 10
             ELSE
              CALL XABORT('@D2P: UNKNOWN NAME OF PKEY TYPE '//TEXT//'.')
             ENDIF
            ENDIF
           ELSE IF (TEXT .EQ. 'ISOTOPES') THEN
  25        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.NE.3) THEN
             CALL XABORT('@D2P: CHARACTER EXPECTED AFTER PKEY KEYWORD')
            ELSE
             IF (TEXT.EQ.'XE135') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              ISOT(1)=TEXT(:12)
              GO TO 25
             ELSE IF (TEXT.EQ.'SM149') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              ISOT(2)=TEXT(:12)
              GO TO 25
             ELSE IF (TEXT.EQ.'I135') THEN
              CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
              ISOT(3)=TEXT(:12)
              GO TO 25
             ELSE IF (TEXT.EQ.'ENDISOTOPES') THEN
             GO TO 10
             ELSE
              CALL XABORT('@D2P: UNKNOWN NAME OF ISOTOPE: '//TEXT//'.')
             ENDIF
            ENDIF
           ELSE IF (TEXT.EQ.'GENPMAXS') THEN
            GO TO 120
           ELSE IF (TEXT.EQ.'HELIOS') THEN
            GO TO 21
           ELSE
            CALL XABORT('@D2P: SOMETHING WRONG OCCURS IN INPUT DATA')
           ENDIF
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE
          CALL XABORT('@D2P: UNKNOWN KEYWORD '//TEXT//', BARR EXPECTED')
        ENDIF
       ELSE IF (TEXT .EQ. 'REFLECTOR') THEN
        FA_K=0
        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
        IF (ITYPLIR.NE.3) THEN
         CALL XABORT('@D2P: KEYWORD MIX EXPECTED AFTER REFLECTOR CARD')
        ELSE IF (TEXT.EQ.'MIX') THEN
  20     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF (ITYPLIR.EQ.1) THEN
          IF (MIX .EQ. -1) THEN
          MIX = NITMA
          GO TO 20
          ELSE
           CALL XABORT('@D2P: ONLY ONE VALUE FOR MIX IS EXPECTED')
          ENDIF
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF ((TEXT.NE.';'))THEN
           IF (TEXT.EQ.'GENPMAXS') THEN
            GO TO 120
           ELSE IF (TEXT.EQ.'HELIOS') THEN
            GO TO 21
           ELSE
            CALL XABORT('@D2P: SOMETHING WRONG OCCURS IN INPUT DATA')
           ENDIF
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE
          CALL XABORT('@D2P: UNKNOWN KEYWORD '//TEXT//', MIX EXPECTED')
        ENDIF
       ENDIF

  21   IF (TEXT .EQ. 'HELIOS') THEN
        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
  30    IF (ITYPLIR.NE.3) THEN
         CALL XABORT ('@D2P: KEYWORD EXPECTED AFTER HELIOS CARD')
        ELSE IF (TEXT.EQ.'FILE_CONT_1') THEN
  40     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.EQ.1).OR.(ITYPLIR.EQ.2)) THEN
          NFC1 = NFC1 +1
          IF (NFC1 <= 5) THEN
           IF (ITYPLIR.EQ.1) FC1(NFC1) = NITMA
           IF (ITYPLIR.EQ.2) FC1(NFC1) = FLOTT
           GO TO 40
          ELSE
           CALL XABORT('@D2P: FIVE VALUES FOR FILE_CONT_1 ARE EXPECTED')
          ENDIF
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (NFC1.NE.5) THEN
           CALL XABORT('@D2P: FIVE VALUES FOR FILE_CONT_1 ARE EXPECTED')
          ENDIF
          IF (TEXT .NE. ';' ) THEN
           GO TO 30
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'FILE_CONT_2') THEN

  50     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)

         IF (ITYPLIR.EQ.2) THEN
          NFC2 = NFC2 +1
          IF (NFC2 <= 8) THEN
           FC2(NFC2) = FLOTT
           GO TO 50
          ELSE
           CALL XABORT('@D2P: 8 VALUES AT MOST IN FILE_CONT_2')
          ENDIF
         ELSE IF (ITYPLIR.EQ.1) THEN
           CALL XABORT('@D2P: REAL VALUES EXPECTED IN FILE_CONT_2')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (NFC2<2) THEN
           CALL XABORT('@D2P: 2 VALUES AT LEAST IN FILE_CONT_2')
          ENDIF
          IF (TEXT .NE. ';' ) THEN
           GO TO 30
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'FILE_CONT_3') THEN

  60     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)

         IF (ITYPLIR.EQ.2) THEN
          NFC3 = NFC3 +1
          IF (NFC3 <= 7) THEN
           FC3(NFC3) = FLOTT
           GO TO 60
          ELSE
           CALL XABORT('@D2P: 7 VALUES IN FILE_CONT_3 EXPECTED')
          ENDIF
         ELSE IF (ITYPLIR.EQ.1) THEN
           CALL XABORT('@D2P: REAL VALUES EXPECTED IN FILE_CONT_3  ')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (NFC3<7) THEN
           CALL XABORT('@D2P: 7 VALUES FOR FILE_CONT_3 EXPECTED')
          ENDIF
          IF (TEXT .NE. ';' ) THEN
           GO TO 30
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'FILE_CONT_4') THEN

  70     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)

         IF (ITYPLIR.EQ.2) THEN
          NFC4 = NFC4 +1
          IF (NFC4 <= 3) THEN
           FC4(NFC4) = FLOTT
           GO TO 70
          ELSE
           CALL XABORT('@D2P: 3 VALUES IN FILE_CONT_4 EXPECTED')
          ENDIF
         ELSE IF (ITYPLIR.EQ.1) THEN
           CALL XABORT('@D2P: REAL VALUES EXPECTED IN FILE_CONT_4')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (NFC4<3) THEN
           CALL XABORT('@D2P: 3 VALUES IN FILE_CONT_4 EXPECTED')
          ENDIF
          IF (TEXT .NE. ';' ) THEN
           GO TO 30
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'XS_CONT') THEN

  80     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)

         IF ((ITYPLIR.EQ.1).OR.(ITYPLIR.EQ.2)) THEN
          NXC = NXC +1
          IF (NXC <= 3) THEN
           IF (ITYPLIR.EQ.1) XSC(NXC) = NITMA
           IF (ITYPLIR.EQ.2) XSC(NXC) = FLOTT
           GO TO 80
          ELSE
           CALL XABORT('@D2P: 3 VALUES IN XS_CONT ARE EXPECTED')
          ENDIF
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (NXC<3) THEN
           CALL XABORT('@D2P: 3 VALUES FOR XS_CONT ARE EXPECTED')
          ENDIF
          IF (TEXT .NE. ';' ) THEN
           GO TO 30
          ELSE
           GOTO 200
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'GENPMAXS')THEN
         GO TO 120
        ELSE
         CALL XABORT ('@D2P: UNKNOWN KEYWORD: '//TEXT//'.')
        ENDIF
       ENDIF

  120  IF (TEXT .EQ. 'GENPMAXS') THEN

        CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
  130   IF (ITYPLIR.NE.3) THEN
         CALL XABORT ('@D2P: KEYWORD EXPECTED AFTER GENPMAXS CARD')
        ELSE IF (TEXT.EQ.'JOB_TIT') THEN

         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)

         IF ((ITYPLIR.NE.3)) THEN
          CALL XABORT('@D2P: CHARACTER EXPECTED AFTER JOB_TIT CARD')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
           JOBTIT=TEXT(:16)
           IF (NITMA>16) THEN
            CALL XABORT('@D2P: JOB_TIT NAME TOO LONG (>C*16)')
           ENDIF
           CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
           GO TO 130
          ELSE
           CALL XABORT('@D2P: CHARACTER EXPECTED AFTER JOB_TIT CARD')
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'FILE_NAME') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.3)) THEN
          CALL XABORT('CHARACTER EXPECTED AFTER JOB_TIT CARD')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
           FILNAM=TEXT(:12)
           IF (NITMA>12) THEN
            CALL XABORT('FILE_NAME NAME TOO LONG (>C*12)')
           ENDIF
           CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
           GO TO 130
          ELSE
           CALL XABORT('@D2P: CHARACTER EXPECTED AFTER FILE_NAME CARD')
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'DERIVATIVE') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.3)) THEN
          CALL XABORT('@D2P: CHARACTER EXPECTED AFTER DERIVATIVE CARD')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
           IF ((TEXT.EQ.'T').OR.(TEXT.EQ.'F')) THEN
            DER=TEXT(:4)
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            GO TO 130
           ELSE
            CALL XABORT('@D2P: (T/F) EXECTED AFTER DERIVATIVE CARD')
           ENDIF
          ELSE
           CALL XABORT('@D2P: (T/F) EXPECTED AFTER DERIVATIVE CARD')
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'COMMENT') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.3)) THEN
          CALL XABORT('@D2P: CHARACTER EXPECTED AFTER COMMENT CARD')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
           COM=TEXT(:40)
           IF (NITMA>40)THEN
            CALL XABORT('@D2P: COMMENT NAME TOO LONG (>C*40)')
           ENDIF
           CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
           GO TO 130
          ELSE
           CALL XABORT('@D2P: CHARACTER EXPECTED AFTER COMMENT CARD')
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'JOB_OPT') THEN
 140     CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.3)) THEN
          CALL XABORT('@D2P: CHARACTER EXPECTED AFTER JOB_OPT CARD')
         ELSE IF (ITYPLIR.EQ.3) THEN
          IF (TEXT .NE. ';' ) THEN
           JOBT=JOBT+1
           IF ((TEXT.EQ.'T').OR.(TEXT.EQ.'F')) THEN
            IF (JOBT<=14) THEN
             JOBOPT(JOBT)=TEXT(:4)
             GO TO 140
            ELSE
             WRITE (6,*) '@D2P: LAST JOB_OPT VALUE :', TEXT
             CALL XABORT('@D2P: 14 VALUES EXPECTED FOR JOB_OPT CARD')
            ENDIF
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            GO TO 130
           ELSE
             IF (JOBT<=14) THEN
             WRITE (6,*)'@D2P: ',JOBT,'th JOB_OPT VALUE :', TEXT
             CALL XABORT('@D2P: (T/F) VALUES EXPECTED FOR JOB_OPT CARD')
             ELSE
             GO TO 130
             ENDIF
           ENDIF
          ELSE IF (JOBT==14 .and. TEXT==';') THEN
           GO TO 190
          ELSE IF (JOBT==15) THEN
           GO TO 130
          ELSE
           CALL XABORT('@D2P: CHARACTER EXPECTED AFTER JOB_OPT CARD')
          ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'IUPS') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.1)) THEN
          CALL XABORT('@D2P: INTEGER EXPECTED AFTER IUPS CARD')
         ELSE IF (ITYPLIR.EQ.1) THEN
           IF ((NITMA>2).OR.(NITMA<0)) THEN
            CALL XABORT ('@D2P: INTEGER MUST BE 0,1 or 2')
           ELSE
            IUPS=NITMA
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.EQ.3) THEN
             GO TO 130
            ELSE
             CALL XABORT('@D2P: ONLY 1 VALUE IS EXPECTED FOR IUPS')
            ENDIF
           ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'VERSION') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.2)) THEN
          CALL XABORT('@D2P: REAL EXPECTED AFTER VERSION CARD')
         ELSE IF (ITYPLIR.EQ.2) THEN
           IF ((FLOTT<0)) THEN
            CALL XABORT ('@D2P: VERSION NUMBER MUST BE POSITIVE')
           ELSE
            VERS=FLOTT
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.EQ.3) THEN
             GO TO 130
            ELSE
             CALL XABORT('@D2P: ONLY ONE VALUE IS EXPECTED FOR VERSION')
            ENDIF
           ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'SFAC') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.2)) THEN
          CALL XABORT('@D2P: REAL EXPECTED AFTER SFAC CARD')
         ELSE IF (ITYPLIR.EQ.2) THEN
           IF ((FLOTT<0)) THEN
            CALL XABORT ('@D2P: SFAC FACTOR MUST BE POSITIVE')
           ELSE
            SFAC=FLOTT
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.EQ.3) THEN
             GO TO 130
            ELSE
             CALL XABORT('@D2P: ONLY ONE VALUE IS EXPECTED FOR SFAC ')
            ENDIF
           ENDIF
         ENDIF
        ELSE IF (TEXT.EQ.'BFAC') THEN
         CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
         IF ((ITYPLIR.NE.2)) THEN
          CALL XABORT('@D2P: REAL EXPECTED AFTER BFAC CARD')
         ELSE IF (ITYPLIR.EQ.2) THEN
           IF ((FLOTT<0)) THEN
            CALL XABORT ('@D2P: BFAC FACTOR MUST BE POSITIVE')
           ELSE
            BFAC=FLOTT
            CALL REDGET(ITYPLIR,NITMA,FLOTT,TEXT,DFLOT)
            IF (ITYPLIR.EQ.3) THEN
             GO TO 130
            ELSE
             CALL XABORT('@D2P: ONLY 1 VALUE IS EXPETCTED FOR BFAC')
            ENDIF
           ENDIF
         ENDIF
        ELSE IF (TEXT .EQ. ';' ) THEN
         GO TO 190
        ELSE
         CALL XABORT ('@D2P: UNKNOWN KEYWORD: '//TEXT//'.')
        ENDIF
       ENDIF
 190   IF (TEXT .EQ. ';' ) THEN
        IF (NFC2.NE.0) NGP = NFC2
        IF (JOBT.NE.14) THEN
         IF (JOBT.NE.15) THEN
          IF (JOBT.NE.0)THEN
           CALL XABORT('@D2P: 14 VALUES EXPECTED FOR JOB_OPT')
          ENDIF
         ENDIF
        ENDIF
        GO TO 200
       ELSE
        CALL XABORT('@D2P: UNKNOWN KEYWORD:'//TEXT//'.')
       ENDIF
      ENDIF

 200  CALL  D2PDRV( NENTRY, HENTRY, IENTRY, JENTRY, KENTRY,    NGP,
     >                     NCRD,    MIX,   FA_K,   IUPS, USRSTA,  PHASE,
     >                   IPRINT, STAVEC, CRDINF, USRVAL,   VERS,   SFAC,
     >                     BFAC,   FC1,    FC2,    FC3,     FC4,    XSC,
     >                  USRVAPK,   ADF,    DER, CRDMOD,  JOBOPT, USRPAR,
     >                     MESH,  PKEY, FILNAM,   ISOT,  JOBTIT,    COM,
     >                      SAP,    MIC,    EXC,   SCAT,   LADD,   LNEW)

      END
