      SUBROUTINE COMPIL (MAXSP,MAXEQ,MAXEL,MAXENT,NIW1,NIW2,
     @                   IW1,IW2,LR,PLS,PRS,KFLAG)
      INTEGER*2 IW1(NIW1),IW2(NIW2),LR(MAXENT),PLS(MAXEQ),PRS(MAXEQ)
      INTEGER IFIX,PLIST(10),ELEML,PP1
      INTEGER ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT,INFDAT
      REAL FLOAT
      COMMON / LUNIT / ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT
      COMMON / INFORM / IHELP,INFDAT
      DATA PLIST(1)/43/ , PLIST(2)/97/ , PLIST(3)/151/ , PLIST(4)/223/ ,
     @   PLIST(5)/307/ , PLIST(6)/419/ , PLIST(7)/541/ , PLIST(8)/691/ ,
     @   PLIST(9)/907/ , PLIST(10)/1151/
      DATA NAMEL/10/ , ELEML/5/
      IF(MAXSP.GE.1000) GOTO 10
      IF(MAXEQ.GE.1000) GOTO 11
      MH=IFIX(FLOAT(MAXSP)*1.1)
      I=1
1     IF(MH.LE.PLIST(I)) GOTO 2
      I=I+1
      IF(I.LE.10) GOTO 1
      GOTO 12
2     PP1=PLIST(I)+1
      NIW3=NAMEL*MAXSP
      NIW4=MAXSP*MAXEL
      MH=PP1+MAXSP+NIW3
      IF(MH.GT.NIW1) GOTO 13
      IF(360.GT.NIW3) GOTO 13
      IF(NIW4.GT.NIW2) GOTO 14
      REWIND SIN
      REWIND CIN
      REWIND HDS
      MH=MAXSP+PP1+1
      NIW3=NIW1-MH
      CALL CHECOM (MAXSP,MAXEQ,MAXEL,MAXENT,NAMEL,ELEML,PP1,NIW3,
     @     IW1(1),IW1(MAXSP+1),IW1(MH),IW2,LR,PLS,PRS,KFLAG)
      ENDFILE SIN
      REWIND SIN
      REWIND CIN
      REWIND HDS
      RETURN
10    WRITE(ITOUT,9000)
      GOTO 100
11    WRITE(ITOUT,9001)
      GOTO 100
12    WRITE(ITOUT,9002)
      GOTO 100
13    I=MH-NIW1
      IH=360-NIW3
      IF(IH.GT.I) I=IH
      I=I+5
      WRITE(ITOUT,9003) I
      GOTO 100
14    I=NIW4-NIW2
      WRITE(ITOUT,9004) I
100   KFLAG=-1
      RETURN
9000  FORMAT(//,14H *** ERROR ***,/,24H MAXSP GREATER THAN 1000)
9001  FORMAT(//,14H *** ERROR ***,/,24H MAXEQ GREATER THAN 1000)
9002  FORMAT(//,14H *** ERROR ***,/,24H LARGEST AVAILABLE PRIME,
     @       22H NUMBER .LT. MAXSP*1.1)
9003  FORMAT(//,14H *** ERROR ***,/,30H INTEGER WORK SPACE EXHAUSTED;
     @       ,I4,/,26H STORAGE LOCATIONS MISSING,/)
9004  FORMAT(//,14H *** ERROR ***,/,27H REAL WORK SPACE EXHAUSTED;
     @       ,I4,/,26H STORAGE LOCATIONS MISSING,/)
      END
      SUBROUTINE CHECOM (MAXSP,MAXEQ,MAXEL,MAXENT,NAMEL,ELEML,PP1,NIW3,
     @                   IW1,IW2,IW3,SPEL,LR,PLS,PRS,KFLAG)
      DOUBLE PRECISION ERR1,ERR2
      DOUBLE PRECISION ATWS(10),KINPAR(3),ATW,ZERO,RKTEST
      DOUBLE PRECISION TEMP,EPS,T,X,GAS
      INTEGER MOUT
      INTEGER ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT,INFDAT
      INTEGER PP1,ELEML
      INTEGER*2 IW1(MAXSP),IW2(PP1),IW3(NIW3),SPEL(MAXSP,MAXEL)
      INTEGER*2 LR(MAXENT),PRS(MAXEQ),PLS(MAXEQ)
      INTEGER*2 ELEM(10,5),IBAL(10),IN(10)
      INTEGER*2 LQ(80) , KEY(80) , SIG(80)
         INTEGER*2 CHAR,CHAR1,CHAR2,BLANK,PLUS,GREAT,LESS,EQUAL,ERR
      INTEGER*2 PARL,PARR,COMMA,STAR,AA,CC,EE,GG,II,NN,OO,PP,RR,SS
      INTEGER*2 TT,PL,PR
      LOGICAL PRM1,PRM2,OVERFL,SPLIST,REV,BN
      COMMON / LUNIT / ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT
      COMMON / INFORM / IHELP,INFDAT
      COMMON / CCC / ICOUNT
      DATA BLANK/1H / , PLUS/1H+/ , GREAT/1H>/ , LESS/1H</ ,
     @     EQUAL/1H=/ , PARL/1H(/ , PARR/1H)/ , COMMA/1H,/ , STAR/1H*/ ,
     @     ERR/1H$/ , AA/1HA/ , CC/1HC/ , EE/1HE/ , GG/1HG/ , II/1HI/,
     @     NN/1HN/ , OO/1HO/ , PP/1HP/ , RR/1HR/ , SS/1HS/ , TT/1HT/ ,
     @     ERR1/8H *** ERR/ , ERR2/8HOR ***  /
      DATA ZERO/0.D0/ , RKTEST/-1.D+31/
      KPRINT=KFLAG
      KFLAG=0
      PRM1=.FALSE.
      PRM2=.FALSE.
      IF(KPRINT.GE.1) PRM1=.TRUE.
      IF(KPRINT.GE.2) PRM2=.TRUE.
      MOUT=ITOUT
      IF(PRM1) WRITE(ITOUT,9998)
      NA=NAMEL*MAXSP
      ICOUNT=0
      READ(CIN,9000)
      ICOUNT=ICOUNT+1
      L1=1
10    L2=L1+71
11    READ(CIN,9000,END=11017) (IW3(L),L=L1,L2)
      ICOUNT=ICOUNT+1
      IF(IW3(L1).EQ.STAR) GOTO 12
      L1=L2+1
      IF(L1.LE.361) GOTO 10
      GOTO 10031
12    IF(IW3(L1+1).EQ.CC) GOTO 11
      IF(IW3(L1+1).NE.EE) GOTO 11025
      L2=L2-72
      L1=L2/72
      WRITE(SIN,9300) L1
      IF(PRM2) WRITE(MOUT,8000)
      IF(L2.EQ.0) GOTO 14
      WRITE(SIN,9000) (IW3(L),L=1,L2)
      IF(PRM2) WRITE(MOUT,8002) (IW3(L),L=1,L2)
14    DO 22 L=1,PP1
22    IW2(L)=0
      DO 24 L=1,NA
24    IW3(L)=BLANK
      DO 26 L=1,MAXEL
      ATWS(L)=0.
      DO 26 I=1,ELEML
26    ELEM(L,I)=BLANK
      IEL=0
      IF(PRM2) WRITE(MOUT,8004)
30    READ(CIN,9000,END=11023) (LQ(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(LQ(1).NE.STAR) GOTO 32
      IF(LQ(2).EQ.SS) GOTO 40
      IF(LQ(2).EQ.CC) GOTO 30
32    J=0
      IF(PRM2) WRITE(MOUT,8002) (LQ(L),L=1,72)
33    J=J+1
      IF(J.GT.72) GOTO 30
      IF(LQ(J).EQ.BLANK) GOTO 33
      L=0
34    L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(LQ(J).NE.BLANK) GOTO 34
      IF(L.LE.ELEML) GOTO 35
      IF(PRM1) WRITE(ITOUT,10027) ELEML,(KEY(I),I=1,ELEML)
      L=ELEML
35    IEL=IEL+1
      IF(IEL.GT.MAXEL) GOTO 10013
      DO 36 I=1,L
36    ELEM(IEL,I)=KEY(I)
      CALL RNUM (LQ,J,72,X,KFLAG)
      IF(KFLAG.LT.0) GOTO 10033
      ATWS(IEL)=X
      GOTO 30
40    IF(IEL.GT.0) GOTO 41
      IF(PRM1) WRITE(ITOUT,10025)
      GOTO 50
41    DO 42 L=1,MAXEL
      DO 42 I=1,MAXSP
42    SPEL(I,L)=0
50    ISP=0
      OVERFL=.FALSE.
      SPLIST=.TRUE.
      IF(PRM2) WRITE(MOUT,8006)
51    READ(CIN,9000,END=11023) (LQ(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(LQ(1).NE.STAR) GOTO 52
      IF(LQ(2).EQ.RR) GOTO 100
      IF(LQ(2).EQ.CC) GOTO 51
52    J=0
      IF(PRM2) WRITE(MOUT,8002) (LQ(L),L=1,72)
      ISPOLD=ISP
53    J=J+1
      IF(J.GT.72) GOTO 51
      IF(LQ(J).EQ.BLANK) GOTO 53
      L=0
54    L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(LQ(J).NE.BLANK) GOTO 54
      CALL HASH (OVERFL,SPLIST,KEY,L,ISP,INDEX,PP1,MAXSP,NAMEL,NA,
     @           IW1,IW2,IW3,PRM1)
      IF(ISPOLD.EQ.ISP.AND.PRM1) WRITE(ITOUT,10037) (KEY(I),I=1,L)
      IF(OVERFL) GOTO 999
      IF(IEL.EQ.0) GOTO 51
60    J=J+1
      IF(J.GE.72) GOTO 51
      IF(LQ(J).EQ.BLANK) GOTO 60
      L=0
62    L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(J.GE.72.AND.PRM1) WRITE(ITOUT,10028) (LQ(I),I=1,72)
      IF(LQ(J).NE.BLANK) GOTO 62
      KEY(L+1)=BLANK
      IF(L.LT.ELEML) L=L+1
      IF(L.GT.ELEML) L=ELEML
      DO 64 I=1,IEL
      IH=I
      DO 63 K=1,L
      IF(KEY(K).NE.ELEM(I,K)) GOTO 64
63    CONTINUE
      GOTO 66
64    CONTINUE
      GOTO 10035
66    J=J+1
      IF(J.GE.72.AND.PRM1) WRITE(ITOUT,10028) (LQ(I),I=1,72)
      IF(LQ(J).EQ.BLANK) GOTO 66
      J1=J
68    J=J+1
      IF(J.GE.72.AND.PRM1) WRITE(ITOUT,10028) (LQ(I),I=1,72)
      IF(LQ(J).NE.BLANK) GOTO 68
      CALL INUM (LQ,J1,J,IVAL,KFLAG)
      IF(KFLAG.NE.0.AND.PRM1) WRITE(ITOUT,10028) (LQ(I),I=1,72)
      SPEL(ISP,IH)=IVAL
      GOTO 60
100   ICEQ=0
      NSP=ISP
      LENGTH=72
      LRI=1
      IR2=0
      SPLIST=.FALSE.
      REV=.FALSE.
      IF(PRM2) WRITE(MOUT,8008)
101   READ(CIN,9000,END=11015) (LQ(L),L=1,72)
      ICOUNT=ICOUNT+1
      PL=LRI
      LENGTH=72
      IF(LQ(1).NE.STAR) GOTO 102
      IF(LQ(2).EQ.II) GOTO 200
      IF(LQ(2).NE.CC.AND.PRM1) WRITE(ITOUT,10026)
      GOTO 101
102   ICEQ=ICEQ+1
      IF(PRM2) WRITE(MOUT,8003) ICEQ,(LQ(L),L=1,72)
8003  FORMAT(I5,3X,72A1)
      IF(ICEQ.GT.MAXEQ) GOTO 10082
      J=0
103   J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).EQ.BLANK) GOTO 103
      IF(LQ(J).EQ.EQUAL) GOTO 106
      L=0
104   L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.BLANK) GOTO 104
      CALL HASH (OVERFL,SPLIST,KEY,L,ISP,INDEX,PP1,MAXSP,NAMEL,NA,
     @           IW1,IW2,IW3,PRM1)
      IF(OVERFL) GOTO 999
      LR(LRI)=INDEX
      LRI=LRI+1
      IF(LRI.GT.MAXENT) GOTO 10080
105   J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).EQ.BLANK) GOTO 105
      IF(LQ(J).NE.PLUS) GOTO 106
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.BLANK) GOTO 10050
      GOTO 103
106   PLS(ICEQ)=LRI-1
      IF(LQ(J).NE.LESS) GOTO 107
      REV=.TRUE.
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
107   IF(LQ(J).NE.EQUAL) GOTO 10050
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.GREAT) GOTO 10050
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.BLANK) GOTO 10050
      PR=LRI
108   J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).EQ.BLANK) GOTO 108
      IF(LQ(J).EQ.PARL) GOTO 114
      L=0
109   L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.BLANK) GOTO 109
      CALL HASH (OVERFL,SPLIST,KEY,L,ISP,INDEX,PP1,MAXSP,NAMEL,NA,
     @           IW1,IW2,IW3,PRM1)
      IF(OVERFL) GOTO 999
      LR(LRI)=INDEX
      LRI=LRI+1
      IF(LRI.GT.MAXENT) GOTO 10080
110   J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).EQ.BLANK) GOTO 110
      IF(LQ(J).NE.PLUS) GOTO 112
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      IF(LQ(J).NE.BLANK) GOTO 10050
      GOTO 108
112   IF(LQ(J).NE.PARL) GOTO 10050
114   PRS(ICEQ)=LRI-1
      IF(IEL.EQ.0) GOTO 130
      IL1=IR2+1
      IL2=PLS(ICEQ)
      IR2=LRI-1
      DO 120 I=1,IEL
      IBAL(I)=0
      DO 120 L=IL1,IR2
      IH=LR(L)
      IF(L.GT.IL2) GOTO 118
      IBAL(I)= IBAL(I) + SPEL(IH,I)
      GOTO 120
118   IBAL(I)= IBAL(I) - SPEL(IH,I)
120   CONTINUE
      DO 123 I=1,IEL
      IF(IBAL(I).NE.0) GOTO 124
123   CONTINUE
      GOTO 125
124   IF(PRM1) WRITE(ITOUT,10030) ICEQ,(LQ(L),L=1,72),(IBAL(I),
     @                            (ELEM(I,L),L=1,5),I=1,IEL)
      IF(PRM1) WRITE(ITOUT,9010)
125   CONTINUE
130   L1=0
      KINPAR(1)=RKTEST
      KINPAR(2)=RKTEST
      KINPAR(3)=RKTEST
131   L=0
132   J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      L=L+1
      CHAR=LQ(J)
      KEY(L)=CHAR
      IF(CHAR.NE.PARR.AND.CHAR.NE.COMMA) GOTO 132
      L1=L1+1
      L=L-1
      IF(L.LE.0) GOTO 133
      CALL RNUM (KEY,1,L,KINPAR(L1),KFLAG)
      IF(KFLAG.EQ.1) GOTO 134
      IF(KFLAG.NE.0) GOTO 10015
133   IF(CHAR.NE.PARR) GOTO 131
134   WRITE(HDS,9060) (KINPAR(L),L=1,3)
      DO 135 I=1,3
      IH=4-I
      IF(KINPAR(IH).NE.RKTEST) GOTO 136
135   CONTINUE
      IF(PRM1) WRITE(ITOUT,10038) ICEQ
      GOTO 139
136   IH=IH-1
      IF(IH.EQ.0) GOTO 139
      IF(KINPAR(IH).EQ.RKTEST) GOTO 10088
      GOTO 136
139   IF(.NOT.REV) GOTO 101
      REV=.FALSE.
      L=LRI-1
      J1=MAXENT-LRI
      J2=LRI-PL
      IF(J1.LT.J2) GOTO 10080
      ICEQ=ICEQ+1
      IF(ICEQ.GT.MAXEQ) GOTO 10082
      IF(L.LT.PR) GOTO 141
140   LR(LRI)=LR(L)
      LRI=LRI+1
      L=L-1
      IF(L.GE.PR) GOTO 140
141   PLS(ICEQ)=LRI-1
      IF(L.LT.PL) GOTO 143
142   LR(LRI)=LR(L)
      LRI=LRI+1
      L=L-1
      IF(L.GE.PL) GOTO 142
143   IR2=LRI-1
      PRS(ICEQ)=IR2
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
145   IF(LQ(J).EQ.PARL) GOTO 130
      J=J+1
      IF(J.GT.LENGTH) GOTO 10003
      GOTO 145
200   NCEQ=ICEQ
      NSP=ISP
      IZ=0
      DO 210 J=1,NSP
      IF(IW1(J)) 10055,210,204
204   IZ=IZ+1
210   CONTINUE
      IF(IZ.LE.0) GOTO 222
      IF(PRM1) WRITE (ITOUT,10039) IZ
      IF(.NOT.PRM2) GOTO 222
      DO 400 J=1,NSP
      IF(IW1(J).LT.1) GOTO 400
      JJ=(J-1)*NAMEL
      L1=JJ+1
      L2=JJ+NAMEL
      WRITE(MOUT,8012) (IW3(L),L=L1,L2)
8012  FORMAT(T5,6(2X,10A1))
400   CONTINUE
222   WRITE(SIN,9350) IEL
      IF(IEL.GT.0) WRITE(SIN,9355) ((ELEM(L,I),I=1,5),ATWS(L),L=1,IEL)
      WRITE(SIN,9400) NSP
      ATW=ZERO
      IF(PRM2) WRITE(MOUT,8010)
      BN=.TRUE.
300   READ(CIN,9000,END=11001) (LQ(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(LQ(1).NE.STAR) GOTO 302
      IF(LQ(2).EQ.TT) GOTO 390
      IF(LQ(2).NE.CC.AND.PRM1) WRITE(ITOUT,10026)
      GOTO 300
302   J=0
      IF(PRM2) WRITE(MOUT,8002) (LQ(L),L=1,72)
306   J=J+1
      IF(J.GT.72) GOTO 10084
      IF(LQ(J).EQ.BLANK) GOTO 306
      L=0
308   L=L+1
      KEY(L)=LQ(J)
      J=J+1
      IF(J.GT.72) GOTO 10005
      IF(LQ(J).NE.BLANK) GOTO 308
      CALL HASH (OVERFL,SPLIST,KEY,L,ISP,INDEX,PP1,MAXSP,NAMEL,NA,
     @           IW1,IW2,IW3,PRM1)
      IF(ISP.GT.NSP) GOTO 10086
      CALL RNUM (LQ,J,72,X,KFLAG)
      IF(KFLAG.LT.0) GOTO 10005
      IF(X.NE.ZERO) BN=.FALSE.
      IW1(INDEX)=2
      JJ=(INDEX-1)*NAMEL
      L1=JJ+1
      L2=JJ+NAMEL
      IF(IEL.EQ.0) GOTO 380
      ATW=ZERO
      DO 370 I=1,IEL
370   ATW=ATW+ATWS(I)*SPEL(INDEX,I)
      WRITE(SIN,9101) INDEX,(IW3(L),L=L1,L2),X,ATW,
     @                (SPEL(INDEX,I),I=1,IEL)
      GOTO 300
380   WRITE(SIN,9102) INDEX,(IW3(L),L=L1,L2),X
      GOTO 300
390   X=ZERO
      IF(BN.AND.PRM1) WRITE(ITOUT,10040)
      DO 395 J=1,NSP
      IF(IW1(J).EQ.2) GOTO 395
      JJ=(J-1)*NAMEL
      L1=JJ+1
      L2=JJ+NAMEL
      IF(IEL.EQ.0) GOTO 394
      ATW=ZERO
      DO 392 I=1,IEL
392   ATW=ATW+ATWS(I)*SPEL(J,I)
      WRITE(SIN,9101) J,(IW3(L),L=L1,L2),X,ATW,(SPEL(J,I),I=1,IEL)
      GOTO 395
394   WRITE(SIN,9102) J,(IW3(L),L=L1,L2),X
395   CONTINUE
      IF(.NOT.PRM2) GOTO 396
      WRITE(MOUT,8100)
      IF(IEL.EQ.0) WRITE(MOUT,8110)
      IF(IEL.GT.0) WRITE(MOUT,8120) ((ELEM(I,L),L=1,5),I=1,IEL)
      DO 450 J=1,NSP
      JJ=(J-1)*NAMEL
      L1=JJ+1
      L2=JJ+NAMEL
      IF(IEL.EQ.0) GOTO 420
      ATW=ZERO
      DO 410 I=1,IEL
410   ATW=ATW+ATWS(I)*SPEL(J,I)
      WRITE(MOUT,8130) J,(IW3(L),L=L1,L2),ATW,(SPEL(J,I),I=1,IEL)
      GOTO 450
420   WRITE(MOUT,8140) J,(IW3(L),L=L1,L2)
450   CONTINUE
396   TEMP=ZERO
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(KEY(1).EQ.STAR) GOTO 398
      IF(PRM2) WRITE(MOUT,8016) (KEY(L),L=1,72)
      CALL RNUM (KEY,1,72,TEMP,KFLAG)
      IF(KFLAG.NE.0) GOTO 10007
      READ(CIN,9000,END=11019) CHAR1,CHAR2
      ICOUNT=ICOUNT+1
      IF(CHAR1.NE.STAR .OR. CHAR2.NE.GG) GOTO 11027
398   WRITE(SIN,9945) TEMP
      GAS=ZERO
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(KEY(1).EQ.STAR) GOTO 399
      IF(PRM2) WRITE(MOUT,8017) (KEY(L),L=1,72)
      CALL RNUM (KEY,1,72,GAS,KFLAG)
      IF(KFLAG.NE.0) GOTO 10009
      READ(CIN,9000,END=11019) CHAR1,CHAR2
      ICOUNT=ICOUNT+1
      IF(CHAR1.NE.STAR .OR. CHAR2.NE.NN) GOTO 11003
399   WRITE(SIN,9947) GAS
      IF(TEMP.NE.ZERO.AND.GAS.EQ.ZERO.AND.PRM1) WRITE(ITOUT,10041)
      WRITE(SIN,9500) NCEQ
      ENDFILE HDS
      REWIND HDS
      DO 1000 I=1,NCEQ
      READ(HDS,9060,END=1100) (KINPAR(L),L=1,3)
1000  WRITE(SIN,9060) (KINPAR(L),L=1,3)
      REWIND HDS
1100  NLR=LRI-1
      WRITE(SIN,9600) NLR
      WRITE(SIN,9200) (PLS(L),L=1,NCEQ)
      WRITE(SIN,9200) (PRS(L),L=1,NCEQ)
      WRITE(SIN,9200) (LR(L),L=1,NLR)
      DO 1190 I=1,NSP
1190  IW1(I)=1
      NSP1=NSP+1
      ISUM=NSP
      IR2=0
      DO 1200 K=1,NCEQ
      IL1=IR2+1
      IL2=PLS(K)
      IK=IL2-IR2
      IR2=PRS(K)
      IF(IK.LE.0) GOTO 1200
      IM=0
      DO 1210 I=IL1,IR2
      IH=LR(I)
      IF(I.GT.IL2) GOTO 1205
      IW1(IH)=IW1(IH)+IK-1
      GOTO 1210
1205  IW1(IH)=IW1(IH)+IK
1210  CONTINUE
      ISUM=ISUM + IK*(IR2-IL1)
1200  CONTINUE
      IF(ISUM.GT.NIW3) GOTO 10092
      IW2(1)=1
      IW3(1)=1
      IH=1
      DO 1220 I=2,NSP
      IH=IH + IW1(I-1)
      IW2(I)=IH
1220  IW3(IH)=I
      IR2=0
      DO 1230 K=1,NCEQ
      IL1=IR2+1
      IL2=PLS(K)
      IK=IL2-IR2
      IR2=PRS(K)
      IF(IK.LE.0) GOTO 1230
      IM=0
      DO 1240 M=IL1,IR2
      IM=IM+1
1240  IN(IM)=LR(M)
      DO 1243 I=1,IM
      IH=IN(I)
      JJ=IW2(IH)
      DO 1242 J=1,IK
      IF(I.EQ.J) GOTO 1242
      JJ=JJ+1
      IW3(JJ)=IN(J)
1242  CONTINUE
      IW2(IH)=JJ
1243  CONTINUE
1230  CONTINUE
      CALL SORT(NSP,NNZ,IW1,IW2,IW3,MAXSP,PP1,NIW3)
      WRITE(HDS,9200) (IW3(L),L=1,NNZ)
      WRITE(HDS,9200) (IW2(L),L=1,NSP1)
      WRITE(HDS,9200) (IW1(L),L=1,NSP)
      ENDFILE HDS
      REWIND HDS
      WRITE(SIN,9650) NNZ
      READ(HDS,9200) (IW3(L),L=1,NNZ)
      WRITE(SIN,9200) (IW3(L),L=1,NNZ)
      READ(HDS,9200) (IW2(L),L=1,NSP1)
      WRITE(SIN,9200) (IW2(L),L=1,NSP1)
      READ(HDS,9200) (IW1(L),L=1,NSP)
      WRITE(SIN,9200) (IW1(L),L=1,NSP)
      T=ZERO
      IF(PRM2) WRITE(MOUT,8018)
      READ(CIN,9000,END=11019) CHAR1,CHAR2
      ICOUNT=ICOUNT+1
      IF(CHAR1.NE.STAR .OR. CHAR2.NE.AA) GOTO 11005
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(PRM2) WRITE(MOUT,8020) (KEY(L),L=1,72)
      CALL RNUM (KEY,1,72,EPS,KFLAG)
      IF(KFLAG.NE.0) GOTO 10017
      WRITE(SIN,9800) EPS
      READ(CIN,9000,END=11019) CHAR1,CHAR2
      ICOUNT=ICOUNT+1
      IF(CHAR1.NE.STAR .OR. CHAR2.NE.OO) GOTO 11007
      IF(PRM2) WRITE(MOUT,8022)
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(PRM2) WRITE(MOUT,8002) (KEY(L),L=1,72)
      CALL INUM (KEY,1,72,ITP,KFLAG)
      IF(KFLAG.NE.0) GOTO 10019
      WRITE(SIN,9850) ITP
      IF(PRM2) WRITE(MOUT,8024)
      DO 2100 I=1,ITP
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(PRM2) WRITE(MOUT,8002) (KEY(L),L=1,72)
      IF(KEY(1).EQ.STAR) GOTO 11021
      CALL RNUM (KEY,1,72,T,KFLAG)
      IF(KFLAG.NE.0) GOTO 10021
2100  WRITE(SIN,9900) T
      READ(CIN,9000,END=11019) CHAR1,CHAR2
      ICOUNT=ICOUNT+1
      IF(CHAR1.NE.STAR .OR. CHAR2.NE.PP) GOTO 11009
      IF(PRM2) WRITE(MOUT,8028)
      READ(CIN,9000,END=11019) (KEY(L),L=1,72)
      ICOUNT=ICOUNT+1
      IF(PRM2) WRITE(MOUT,8002) (KEY(L),L=1,72)
      CALL INUM (KEY,1,72,IPRINT,KFLAG)
      IF(KFLAG.NE.0) GOTO 10023
      WRITE(SIN,9950) IPRINT
2210  CONTINUE
      IF(PRM1) WRITE(ITOUT,9999)
      KFLAG=0
      RETURN
10003 WRITE(ITOUT,10004) ERR1,ERR2,ICEQ,(LQ(L),L=1,72)
10004 FORMAT(//,2A8,/,10H EQUATION ,I3,17H NOT COMPLETE    ,
     @  /,1X,72A1,/)
      GOTO 999
10005 WRITE(ITOUT,10006) ERR1,ERR2
10006 FORMAT(//,2A8,/,30H INITIAL CONCENTRATION INVALID,/)
      GOTO 999
10007 WRITE(ITOUT,10008) ERR1,ERR2
10008 FORMAT(//,2A8,/,30H VALUE FOR TEMPERATURE INVALID,/)
      GOTO 999
10009 WRITE(ITOUT,10010) ERR1,ERR2
10010 FORMAT(//,2A8,/,41H VALUE FOR UNIVERSAL GAS CONSTANT INVALID,/)
      GOTO 999
10017 WRITE(ITOUT,10018) ERR1,ERR2
10018 FORMAT(//2A8,/,22H VALUE FOR EPS INVALID,/)
      GOTO 999
10019 WRITE(ITOUT,10020) ERR1,ERR2
10020 FORMAT(//2A8,/,43H VALUE FOR NUMBER OF OUTPUT POINTS INVALID,/)
      GOTO 999
10021 WRITE(ITOUT,10022) ERR1,ERR2
10022 FORMAT(//,2A8,/,34H VALUE FOR AN OUTPUT POINT INVALID,/)
      GOTO 999
10023 WRITE(ITOUT,10024) ERR1,ERR2
10024 FORMAT(//,2A8,/,34H VALUE FOR PRINT PARAMETER INVALID,/)
      GOTO 999
10031 WRITE(ITOUT,10032) ERR1,ERR2
10032 FORMAT(//,2A8,/,24H TOO MANY LINES FOR HEAD,/)
      GOTO 999
10033 WRITE(ITOUT,10034) ERR1,ERR2
10034 FORMAT(//,2A8,/,22H INVALID ATOMIC WEIGHT,/)
      GOTO 999
10035 WRITE(ITOUT,10036) ERR1,ERR2,(LQ(I),I=1,72),(KEY(I),I=1,L)
10036 FORMAT(//,2A8,/,22H INVALID SPECIES CARD:,/,1X,72A1,/,
     @       29H UNKNOWN ELEMENT NAME FOUND: ,15A1)
      GOTO 999
10050 DO 10051 L=1,72
10051 SIG(L)=BLANK
      SIG(J)=ERR
      WRITE(ITOUT,10053) ICEQ,(LQ(L),L=1,72),(SIG(L),L=1,72)
10053 FORMAT(10H EQUATION ,I3,9H INVALID ,/,2(1H ,72A1,/))
      GOTO 999
10055 L1=(J-1)*NAMEL+1
      L2=J*NAMEL
      WRITE(ITOUT,10056) ERR1,ERR2,(IW3(L),L=L1,L2)
10056 FORMAT(//,2A8,/,10H SPECIES: ,10A1,25 H ,DEFINED IN SPECIES LIST,
     @       /,36H HAS NOT APPEARED IN REACTION SYSTEM,/)
      GOTO 999
10013 WRITE(ITOUT,10014) ERR1,ERR2,MAXEL
10014 FORMAT(//,2A8,/,11H MORE THAN ,I4,9H ELEMENTS,/)
      GOTO 999
10015 WRITE(ITOUT,10016) ERR1,ERR2,ICEQ
10016 FORMAT(//,2A8,/,33H KINETIC PARAMETER(S) IN EQUATION,I4,
     @       10H INCORRECT,/)
      GOTO 999
10082 WRITE(ITOUT,10083) ERR1,ERR2,MAXEQ
10083 FORMAT(//,2A8,/,11H MORE THAN ,I4,10H EQUATIONS,/)
      GOTO 999
10080 WRITE(ITOUT,10081) ERR1,ERR2
10081 FORMAT(//,2A8,/,31H TABLE OVERFLOW ,ENLARGE MAXENT,/)
      GOTO 999
10084 WRITE(ITOUT,10085) ERR1,ERR2
10085 FORMAT(//,2A8,/,20H BLANK LINE IN INPUT,/)
      GOTO 999
10086 WRITE(ITOUT,10087) ERR1,ERR2
10087 FORMAT(//,2A8,/,46H WRONG NAME IN INPUT OF INITIAL CONCENTRATIONS)
      GOTO 999
10088 WRITE(ITOUT,10089) ERR1,ERR2,ICEQ
10089 FORMAT(//,2A8,/,43H (MODIFIED) ARRHENIUS TYP FOR RATE CONSTANT,
     @       10H DECLARED,,/,35H BUT A KINETIC PARAMETER IS MISSING,/)
      GOTO 999
10092 WRITE(ITOUT,10093) ERR1,ERR2
10093 FORMAT(//,2A8,/,41H INTEGER WORK SPACE EXHAUSTED; ENLARGE IW,/)
      GOTO 999
11001 WRITE(ITOUT,11002) ERR1,ERR2
11002 FORMAT(//,2A8,/,33H LINE '*TEMP...' IN INPUT MISSING,/)
      GOTO 11019
11003 WRITE(ITOUT,11004) ERR1,ERR2
11004 FORMAT(//,2A8,/,33H LINE '*NUME...' IN INPUT MISSING,/)
      GOTO 11019
11005 WRITE(ITOUT,11006) ERR1,ERR2
11006 FORMAT(//,2A8,/,33H LINE '*ACCU...' IN INPUT MISSING,/)
      GOTO 11019
11007 WRITE(ITOUT,11008) ERR1,ERR2
11008 FORMAT(//,2A8,/,33H LINE '*OUTP...' IN INPUT MISSING,/)
      GOTO 11019
11009 WRITE(ITOUT,11010) ERR1,ERR2
11010 FORMAT(//,2A8,/,33H LINE '*PRIN...' IN INPUT MISSING,/)
      GOTO 11019
11015 WRITE(ITOUT,11016) ERR1,ERR2
11016 FORMAT(//,2A8,/,33H LINE '*INIT...' IN INPUT MISSING,/)
      GOTO 11019
11017 WRITE(ITOUT,11018) ERR1,ERR2
11018 FORMAT(//,2A8,/,33H LINE '*SPECIES' IN INPUT MISSING,/)
      GOTO 11019
11023 WRITE(ITOUT,11024) ERR1,ERR2
11024 FORMAT(//,2A8,/,33H LINE '*REACT..' IN INPUT MISSING,/)
      GOTO 11019
11025 WRITE(ITOUT,11026) ERR1,ERR2
11026 FORMAT(//,2A8,/,33H LINE '*ELEM...' IN INPUT MISSING,/)
      GOTO 11019
11027 WRITE(ITOUT,11028) ERR1,ERR2
11028 FORMAT(//,2A8,/,33H LINE '*GAS ...' IN INPUT MISSING,/)
11019 WRITE(ITOUT,11020)
11020 FORMAT(/,25H INPUT DATASET INCOMPLETE,/)
      GOTO 999
11021 WRITE(ITOUT,11022) ERR1,ERR2
11022 FORMAT(//,2A8,/,30H INVALID LINE IN OUTPUT POINTS,/)
      GOTO 999
999   KFLAG=-1
      WRITE(ITOUT,9996) ICOUNT
      WRITE(ITOUT,9997)
      RETURN
8000  FORMAT(//,19X,14H ACTUAL MODEL:,/,20X,13(1H-),/)
8002  FORMAT(1X,72A1)
8004  FORMAT(//,19X,15H ELEMENT CARDS:,/,20X,14(1H-),/)
8006  FORMAT(//,19X,15H SPECIES CARDS:,/,20X,14(1H-),/)
8008  FORMAT(//,19X,17H REACTION SYSTEM:,/,20X,16(1H-),/)
8010  FORMAT(//,19X,24H INITIAL CONCENTRATIONS:,/,20X,23(1H-),/)
8100  FORMAT(//,19X,21H *** SPECIES INFO ***,/)
8110  FORMAT(/,4X,16H NO ^   NAME   ^)
8120  FORMAT(/,4X,45H NO ^   NAME   ^ MOLECULAR WEIGHT ^  ELEMENT ,
     @       11HCOMPOSITION,/,40X,5(1X,5A1),/,40X,5(1X,5A1))
8130  FORMAT(4X,I4,2X,10A1,2X,D13.6,4X,5(I6),/,39X,5(I6))
8140  FORMAT(4X,I4,2X,10A1,2X,D13.6)
8016  FORMAT(//,19X,13H TEMPERATURE:,/,20X,12(1H-),/,1X,72A1)
8017  FORMAT(//,19X,24H UNIVERSAL GAS CONSTANT:,/,20X,23(1H-),/,1X,72A1)
8018  FORMAT(//,19X,23H NUMERICAL INPUT CARDS:,/,20X,22(1H-),/)
8020  FORMAT(/,32H FOR REQUIRED RELATIVE ACCURACY:,/,1X,72A1)
8022  FORMAT(/,29H FOR NUMBER OF OUTPUT POINTS:)
8024  FORMAT(/,29H FOR VALUES OF OUTPUT POINTS:)
8028  FORMAT(/,21H FOR PRINT PARAMETER:)
9000  FORMAT(72A1)
9010  FORMAT(/)
9060  FORMAT(3D24.14)
9101  FORMAT(I4,1X,10A1,1X,D21.12,1X,D21.12,1X,2(I8),/,8(I8))
9102  FORMAT(I5,1X,10A1,2X,D21.12)
9200  FORMAT(9I8)
9300  FORMAT(5H*HEAD,14X,I5)
9350  FORMAT(9H*ELEMENTS,10X,I5)
9355  FORMAT(5A1,3X,D21.12)
9400  FORMAT(8H*SPECIES,11X,I5)
9500  FORMAT(19H*KINETIC PARAMETERS,I5)
9600  FORMAT(4H*FCN,15X,I5)
9650  FORMAT(7H*JACOBI,12X,I5)
9945  FORMAT(12H*TEMPERATURE,7X,D21.12)
9947  FORMAT(13H*GAS CONSTANT,7X,D21.12)
9800  FORMAT(5H*EPS:,14X,D21.12)
9850  FORMAT(15H*OUTPUT POINTS:,4X,I5)
9900  FORMAT(D21.12)
9950  FORMAT(13H*PRINTPARAM.:,6X,I5)
9996  FORMAT(/,28H COMPILATION STOPPED AT CARD,I6)
9997  FORMAT(//,9X,40H ***** COMPILER ENDED DUE TO ERROR *****,/)
9998  FORMAT(/,9X,33H ***** COMPILER DIAGNOSTICS *****)
9999  FORMAT(//,9X,43H ***** CHEMICAL INPUT SUCCESSFULLY COMPILED,
     @       6H *****,/)
10025 FORMAT(/16H *** WARNING ***,/,26H NO STOICHIOMETRIC BALANCE,
     @        15H CHECK POSSIBLE,/)
10026 FORMAT(/16H *** WARNING ***,/,27H INPUT LINE STARTS WITH '*',
     @        13H LINE IGNORED,/,1H ,72A1,/)
10027 FORMAT(/16H *** WARNING ***,/,26H ELEMENT NAME TRUNCATED TO,
     @        I3,9H DIGITS: ,5A1,/)
10028 FORMAT(/16H *** WARNING ***,/,23H SPECIES CARD INCORRECT,/,
     @        1X,72A1,/)
10030 FORMAT(/,16H *** WARNING ***,/,28H INCORRECT STOICHIOMETRIC IN,
     @     10H EQUATION ,I4,/,1X,72A1,/,10H  MISSING:,5(I5,1X,5A1),/,
     @     10X,5(I5,1X,5A1),/)
10037 FORMAT(/,16H *** WARNING ***,/,24H DOUBLY DEFINED SPECIES:,/,
     @         2X,10A1,/)
10038 FORMAT(/,16H *** WARNING ***,/,28H NO KINETIC PARAMETER(S) FOR,
     @     9H EQUATION,I4,/,37H RATE CONSTANT SET TO ZERO INTERNALLY,/)
10039 FORMAT(/,16H *** WARNING ***,/,I4,
     @         49H SPECIES DETECTED IN REACTION MECHANISM WHICH ARE,/,
     @         32H   NOT IDENTIFIED IN SPECIESLIST,/)
10040 FORMAT(/,16H *** WARNING ***,/,
     @         40H NO NON-ZERO INITIAL CONCENTRATION FOUND,/)
10041 FORMAT(/,16H *** WARNING ***,/,
     @         48H NON-ZERO VALUE FOR TEMPERATURE BUT NO VALUE FOR,/,
     @         29H UNIVERSAL GAS CONSTANT FOUND,/)
      END
      SUBROUTINE HASH (OVERFL,SPLIST,IN,L,ISP,IND,PP1,MAXSP,NAMEL,NN,
     @                 FLAG,P,NAME,PRM1)
      INTEGER*2 BLANK
      INTEGER ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT,INFDAT
      INTEGER IABS,MOD,H,PH,PP1,PRIM
      LOGICAL OVERFL,SPLIST,PRM1
      INTEGER*2 IN(80) , FLAG(MAXSP) , P(PP1) , NAME(NN)
      COMMON / LUNIT / ITIN,ITOUT,CIN,HDS,POUT,SIN,DOUT
      COMMON / INFORM / IHELP,INFDAT
      DATA BLANK/1H /
      PRIM=PP1-1
10    H=0
      DO 20 I=1,L
20    H=H+I*IN(I)
      H=MOD(IABS(H),PRIM)+1
      IF(L-NAMEL) 22,30,100
22    L=L+1
      IN(L)=BLANK
30    PH=P(H)
      IF(PH.EQ.0) GOTO 50
      II=(PH-1)*NAMEL
      DO 32 I=1,L
      IH=II+I
      IF(IN(I).NE.NAME(IH)) GOTO 40
32    CONTINUE
      IF(SPLIST) RETURN
      IND=PH
      IF(FLAG(IND).LT.0) FLAG(IND)=0
      RETURN
40    H=H-1
      IF(H.EQ.0) H=PP1
      GOTO 30
50    II=ISP*NAMEL
      ISP=ISP+1
      IF(ISP.GT.MAXSP) GOTO 200
      P(H)=ISP
      IND=ISP
      FLAG(ISP)=1
      IF(SPLIST) FLAG(ISP)=-1
      DO 62 I=1,L
      IH=II+I
62    NAME(IH)=IN(I)
      RETURN
100   IF(PRM1) WRITE(ITOUT,101) (IN(K),K=1,L)
      L=NAMEL
      GOTO 10
200   WRITE(ITOUT,201) MAXSP
      OVERFL=.TRUE.
      RETURN
101   FORMAT(/,16H *** WARNING ***,/,
     @       30H NAME TRUNCATED TO 10 DIGITS: ,69A1,/)
201   FORMAT(/,14H *** ERROR ***,/,
     @       27H TABLE OVERFLOW: MORE THAN ,I3,8H SPECIES,/)
      END
      SUBROUTINE SORT (NSP,NNZ,IW1,IW2,IW3,NIW1,NIW2,NIW3)
CI4       INTEGER IW1(NIW1),IW2(NIW2),IW3(NIW3)
      INTEGER*2 IW1(NIW1),IW2(NIW2),IW3(NIW3)
      NSP1=NSP+1
C
C  SORTING/CONDENSING
C
      IAI=1
      J2=0
      DO 1300 I=1,NSP
      J1=J2+1
      J2=IW2(I)
      IF(J1.EQ.J2) GOTO 1266
      ITEST=J2
1261  JM=ITEST-1
      ITEST=0
      DO 1265 J=J1,JM
      IF(IW3(J).LE.IW3(J+1)) GOTO 1265
      IH=IW3(J)
      IW3(J)=IW3(J+1)
      IW3(J+1)=IH
      ITEST=J
1265  CONTINUE
      IF(ITEST.NE.0) GOTO 1261
1266  IW2(I)=IAI
      JJ=IW3(J1)
      IW3(IAI)=JJ
      IF(JJ.EQ.I) IW1(I)=IAI
      IAI=IAI+1
1280  J1=J1+1
      IF(J1.GT.J2) GOTO 1300
      IF(IW3(J1).EQ.JJ) GOTO 1280
      JJ=IW3(J1)
      IW3(IAI)=JJ
      IF(JJ.EQ.I) IW1(I)=IAI
      IAI=IAI+1
      GOTO 1280
1300  CONTINUE
      IW2(NSP1)=IAI
      NNZ=IAI-1
      RETURN
      END
 
