      SUBROUTINE IONCOMP(H,TE,AM,AN2,CO2,H2O,O2,O3,O1,                  
     1ANO1,ANO2,O2S,HNO3,QIO2P,QINOP,O2COL,ALPH1,ALPH3)                 
      SAVE
      COMMON/QIONDC/AR(54),ISWTC,ELEC                                   
      COMMON/PIONTR/PHOXO2,PHOXNO,PHOXI,PHOXT                           
      ALPH4 = 8.5E-8                                                    
      QO2X=QIO2P                                                        
      R6 = 1.E-9                                                        
      R7 = 1.E-9                                                        
      R8 = 1.E-9                                                        
      R14 = 1.E-9                                                       
      R15 = 1.E-9                                                       
      R16 = 1.E-9                                                       
      R22 = 1.E-9                                                       
      R23 = 1.E-9                                                       
      R24 = 1.E-9                                                       
      R25 = 7.E-11                                                      
      R41 = 1.5E-9                                                      
      R42 = 1.E-9                                                       
      R43 = 1.E-9                                                       
      R47 = 2.8E-28                                                     
      R44 = 1.E-9                                                       
      R45 = 2.E-10                                                      
      R46 = 1.4E-9                                                      
      R48 = 3.E-10                                                      
      RN2 = 1.E-31                                                      
      RN3 = 1.5E-10                                                     
      RN4 = 1.5E-10                                                     
      RN5 = 2.5E-10                                                     
      RN6 = 1.1E-10                                                     
      RN7 = 6.E-10                                                      
      RN8 = 5.5E-10                                                     
      RN9 = 1.1E-11                                                     
      RN10 = 2.5E-12                                                    
      RN11 = 1.2E-10                                                    
      RN12 = 4.3E-10                                                    
      RN13 = 2.5E-10                                                    
      RN14 = 4.8E-11                                                    
      RN15 = 4.E-10                                                     
      RN16 = 1.4E-10                                                    
      RN17 = 1.9E-10                                                    
      RN18 = 8.E-10                                                     
      RN19 = 4.E-10                                                     
      RN20 = 2.E-10                                                     
      RN21 = 1.5E-11                                                    
      RN22 = 1.3E-10                                                    
      RN23 = 8.E-10                                                     
      RN26 = 1.E-9                                                      
      RN29 = 1.2E-9                                                     
      RN30 = 1.4E-9                                                     
      RN31 = 3.E-10                                                     
      RN32 = 2.E-10                                                     
      RN33 = 5.8E-10                                                    
      RN34 = 3.E-28                                                     
      RN35 = 4.7E-29                                                    
      RN37 = 1.E-9                                                      
      RN38 = 1.6E-9                                                     
      RN39 = 8.E-10                                                     
      RN40 = 3.E-9                                                      
      RN41 = 2.8E-9                                                     
      R49 = 4.4E-10                                                     
      S1 = 0.                                                           
      S2 = 0.                                                           
      S3 = 0.                                                           
      S4 = 0.                                                           
      S5 = 0.                                                           
      S6 = 0.                                                           
      S7 = 0.                                                           
      S8 = 0.                                                           
      S9 = 0.                                                           
      S10 = 0.                                                          
      S11 = 0.                                                          
      S12 = 0.                                                          
      I=1                                                               
      ELEC=100.                                                         
C  14 FORMAT(F15.2)                                                     
      NH=1                                                              
      QNO=QINOP                                                         
      QO2=QIO2P                                                         
      ALPH2=3.E-6                                                       
      R1 = 2.E-31*(300./TE)**4.4                                        
      R2 = 1.5E6/(TE**5.4*EXP(2450./TE))                                
      R3 = 7.E-30*(300./TE)**3.                                         
      R5 = 1.8E-28*(308./TE)**4.7                                       
      R9 = 2.E-31*(300./TE)**4.4                                        
      R10 = 1.5E6/(TE**5.4*EXP(2150./TE))                               
      R11 = 7.E-30*(300./TE)**3.                                        
      R13 = 1.E-27*(308./TE)**4.7                                       
      R17 = 2.E-31*(300./TE)**4.4                                       
      R18 = 1.5E6/(TE**5.4*EXP(1800./TE))                               
      R19 = 7.E-30*(300./TE)**3.                                        
      R21 = 1.E-27*(308./TE)**4.7                                       
      R26 = 2.4E-27*(300./TE)**4.                                       
      R27 = 1.36E11/(TE**5.*EXP(8360./TE))                              
      R28 = 9.E-28*(300./TE)**4.                                        
      R29 = 6.9E11/(TE**5.*EXP(7670./TE))                               
      R30 = 9.E-28*(300./TE)**4.                                        
      R31 = 2.1E11/(TE**5.*EXP(6540./TE))                               
      R36 = 2.3E-27*(300./TE)**4.                                       
      R37 = 1.95E11/(TE**5.*EXP(11000./TE))                             
      R38 = 3.4E-27*(300./TE)**4.                                       
      R39 = 9.6E11/(TE**5.*EXP(17100./TE))                              
      R32 = 9.E-28*(300./TE)**4.                                        
      R33 = 1.26E11/(TE**5.*EXP(5830/TE))                               
      R34 = 9.E-28*(300./TE)**4.                                        
      R35 = 2.3E10/(TE**5.*EXP(5000./TE))                               
      R4 = 3.11E4/(TE**4.*EXP(4590./TE))                                
      R12 = 3.11E4/(TE**4.*EXP(4025./TE))                               
      R20 = 3.11E4/(TE**4.*EXP(3335./TE))                               
      R40 = 2.6E-30*(300./TE)**3.2                                      
      RN1 = 1.4E-29*(300./TE)*EXP(-600./TE)                             
      RN24 = 3.1E-31*(300./TE)**2.5                                     
      RN25 = 6.3E-32*(300./TE)**4.2                                     
      RN27 = 4.7E-31*(300./TE)**1.9                                     
      RN28 = 1.8E-31*(300./TE)**2.5                                     
      RN36 = 9.E-12*(TE/300.)**1.5                                      
      ALAM = 0.                                                         
      SUMT = 0.                                                         
      TNWEW=TE                                                          
      IABC=0                                                            
   30 ALAM1 = ALAM*ALPH4                                                
      REC1 = (ALPH1+ALAM1)*ELEC                                         
      REC2 = (ALPH2+ALAM1)*ELEC                                         
      REC3 = (ALPH3+ALAM1)*ELEC                                         
      C19 = R49*ANO1+(R40*O2+R47*H2O)*AM+REC3                           
      C20 = C19/(R48*O1)                                                
      C21 = R41*H2O+R42*O3+R48*O1+REC2                                  
      C22 = R40*O2*AM/C21                                               
      AO2 = QO2/(R48*O1*(C20-C22))                                      
      IF(AO2 .GT. 1.E7) AO2=1.E7                                        
      AO4 = C22*AO2                                                     
      AO5 = R42*O3*AO4/(R43*H2O+REC2)                                   
      C23 = H2O*(R41*AO4+R43*AO5+R47*AM*AO2)                            
      AO2H = C23/((R44+R45)*H2O+REC2)                                   
      AHHOH = R44*H2O*AO2H/(R46*H2O+REC2)                               
      C1 = (R1*AN2+R3*CO2+R5*H2O)*AM                                    
      C2 = R2*AM+R6*CO2+R8*H2O                                          
      C3 = R4*AM+R7*H2O                                                 
      C4 = R1*AN2*AM/(C2+REC2)                                          
      IABC=IABC+1                                                       
      C5 = (R3*CO2*AM+R6*CO2*C4)/(C3+REC2)                              
      ANO = (QNO+R49*ANO1*AO2)/(C1+REC1-R2*AM*C4-R4*AM*C5)              
      ANON1 = C4*ANO                                                    
      ANOC1 = C5*ANO                                                    
      C6 = (R9*AN2+R11*CO2+R13*H2O)*AM                                  
      C7 = R10*AM+R14*CO2+R16*H2O                                       
      C8 = R12*AM+R15*H2O                                               
      C9 = R9*AN2*AM/(C7+REC2)                                          
      C10 = (R11*CO2*AM+R14*CO2*C9)/(C8+REC2)                           
      C11 = (R5*AM*ANO+R7*ANOC1+R8*ANON1)*H2O                           
      ANOH1 = C11/(C6+REC2-(R10*C9+R12*C10)*AM)                         
      ANOHN = C9*ANOH1                                                  
      ANOHC = C10*ANOH1                                                 
      C12 = (R17*AN2+R19*CO2+R21*H2O)*AM                                
      C13 = R18*AM+R22*CO2+R24*H2O                                      
      C14 = R20*AM+R23*H2O                                              
      C15 = R17*AN2*AM/(C13+REC2)                                       
      C16 = (R19*AM+R22*C15)*CO2/(C14+REC2)                             
      C17 = (R13*AM*ANOH1+R15*ANOHC+R16*ANOHN)*H2O                      
      ANOH2 = C17/(C12+REC2-AM*(R18*C15+R20*C16))                       
      ANOH2N = C15*ANOH2                                                
      ANOH2C = C16*ANOH2                                                
      C18 = (R21*AM*ANOH2+R23*ANOH2C+R24*ANOH2N)*H2O                    
      ANOH3 = C18/(R25*H2O+REC2)                                        
      C24 = R34*AM*H2O/(R35*AM+REC2)                                    
      C25 = (R34*H2O+R33-R35*C24)*AM+REC2                               
      C26 = R32*AM*H2O/C25                                              
      C27 = (R32*H2O+R31-R33*C26)*AM+REC2                               
      C28 = R30*AM*H2O/C27                                              
      C29 = (R30*H2O+R29-R31*C28)*AM+REC2                               
      C30 = R28*AM*H2O/C29                                              
      C31 = (R28*H2O+R27-R29*C30)*AM+REC2                               
      C32 = R26*AM*H2O/C31                                              
      C33 = R25*H2O*ANOH3                                               
      C34 = R36*AM*H2O                                                  
      C35 = (R26*H2O+R37-R27*C32)*AM+REC2                               
      C36 = R46*H2O*AHHOH                                               
      C37 = R38*AM*H2O                                                  
      C38 = R37*AM                                                      
      C39 = (R36*H2O+R39)*AM+REC2                                       
      C40 = R45*H2O*AO2H                                                
      C41 = R39*AM                                                      
      C42 = R38*AM*H2O+REC2                                             
      C43 = C42*(C35*C36+C33*C38)+C35*C37*C40                           
      C44 = C42*(C34*C38-C35*C39)+C35*C37*C41                           
      W2 = -C43/C44                                                     
      W1 = (C40+C41*W2)/C42                                             
      W3 = (C33+C34*W2)/C35                                             
      W4 = C32*W3                                                       
      W5 = C30*W4                                                       
      W6 = C28*W5                                                       
      W7 = C26*W6                                                       
      W8 = C24*W7                                                       
      SUM1 = ANON1+ANOC1+ANOH1+ANOHN                                    
      SUM2 = ANOHC+ANOH2+ANOH2N+ANOH2C+ANOH3                            
      SUM3 = AO4+AO5+AO2H+AHHOH                                         
      SUM4 = SUM1+SUM2+SUM3                                             
      SUM5 = W1+W2+W3+W4+W5+W6+W7+W8                                    
      SUMT = ANO+AO2+SUM4+SUM5                                          
      ALPH5 = ALPH4*SUMT                                                
      GA1 = (RN3+RN4)*O1+RN7*O3+RN20*O2S+RN23*ANO2+RN41*HNO3            
      GA2 = (RN24*O2+RN25*AN2+RN34*H2O+RN35*CO2)*AM                     
      G1 = GA1+GA2+S1+ALPH5                                             
      GA3 = RN17*O1+(RN18+RN19)*O3+RN29*ANO2+RN40*HNO3                  
      G2 = GA3+(RN27*O2+RN28*AN2)*AM+S2+ALPH5                           
      G3 = RN5*O1+RN8*CO2+RN10*ANO1+S3+ALPH5                            
      G4 = RN6*O1+RN9*ANO1+RN32*ANO2+RN39*HNO3+S4+ALPH5                 
      G5 = RN11*O3+RN38*HNO3+S5+ALPH5                                   
      G6 = S6+ALPH5                                                     
      G7 = RN12*CO2+RN13*ANO1+RN15*O1+RN30*H2O+S7+ALPH5                 
      G8 = RN14*ANO1+RN16*O1+RN22*O3+S8+ALPH5                           
      G9 = RN21*ANO1+S9+ALPH5                                           
      G10 = RN26*O2+S10+ALPH5                                           
      G11 = RN37*O2+S11+ALPH5                                           
      G12 = RN31*O3+RN33*CO2+S12+ALPH5                                  
      BL10 = RN25*AN2*AM/G10                                            
      BL7 = (RN24*O2*AM+RN26*O2*BL10)/G7                                
      BL12 = (RN34*H2O*AM+RN30*H2O*BL7)/G12                             
      BL8 = (RN35*AM+RN12*BL7+RN33*BL12)*CO2/G8                         
      BL2 = RN4*O1/G2                                                   
      BLA2 = RN36*O3/G2                                                 
      BLB11 = RN28*AN2*AM                                               
      BL11 = BLB11*BL2/G11                                              
      BLA11 = BLB11*BLA2/G11                                            
      BL9 = (RN13*BL7+RN14*BL8)*ANO1/G9                                 
      BLB3 = RN18*O3+RN27*O2*AM                                         
      BLC3 = RN7*O3+RN15*O1*BL7+RN22*O3*BL8                             
      BLD3 = BLB3*BL2+RN31*O3*BL12+RN37*O2*BL11                         
      BL3 = (BLC3+BLD3)/G3                                              
      BLA3 = (BLB3*BLA2+RN37*O2*BLA11)/G3                               
      BL4 = (RN8*CO2*BL3+RN16*O1*BL8)/G4                                
      BLA4 = RN8*CO2*BLA3/G4                                            
      BLB5 = RN23*ANO2+RN9*ANO1*BL4+RN10*ANO1*BL3                       
      BLC5 = RN21*ANO1*BL9+RN29*ANO2*BL2                                
      BL5 = (BLB5+BLC5)/G5                                              
      BLA5 = (RN9*ANO1*BLA4+RN10*ANO1*BLA3+RN29*ANO2*BLA2)/G5           
      BLB6 = HNO3*(RN41+RN40*BL2+RN39*BL4+RN38*BL5)                     
      BL6 = (BLB6+RN32*ANO2*BL4+RN11*O3*BL5)/G6                         
      BLC6 = HNO3*(RN40*BLA2+RN39*BLA4+RN38*BLA5)                       
      BLA6 = (BLC6+RN32*ANO2*BLA4+RN11*O3*BLA5)/G6                      
      COE1 = (RN1*O2+RN2*AN2)*O2+RN5*O1*BLA3                            
      COE2 = RN6*O1*BLA4+RN19*O3*BLA2                                   
      COE3 = RN5*O1*BL3+RN6*O1*BL4+RN19*O3*BL2                          
      AL1 = (COE1+COE2)/(G1-COE3)                                       
      AL2 = BL2*AL1+BLA2                                                
      AL3 = BL3*AL1+BLA3                                                
      AL4 = BL4*AL1+BLA4                                                
      AL5 = BL5*AL1+BLA5                                                
      AL6 = BL6*AL1+BLA6                                                
      AL7 = BL7*AL1                                                     
      AL8 = BL8*AL1                                                     
      AL9 = BL9*AL1                                                     
      AL10 = BL10*AL1                                                   
      AL11 = BL11*AL1+BLA11                                             
      AL12 = BL12*AL1                                                   
      SUMN1 = AL1+AL2+AL3+AL4+AL5+AL6                                   
      SUMN2 = AL7+AL8+AL9+AL10+AL11+AL12                                
      ALAM = SUMN1+SUMN2                                                
      ANEG = ELEC*(1.+ALAM)                                             
      TEST = SUMT-ANEG                                                  
      TEST1 = ABS(TEST)                                                 
      AQDFY=0.01                                                        
      IF(H.LT.10.) AQDFY=0.05                                           
      TEST2=TEST1-AQDFY*ANEG                                            
      IF(TEST2) 40,40,41                                                
   41 AB1=ELEC*SUMT/(1.+ALAM)                                           
      AB1=ABS(AB1)                                                      
      ELEC=SQRT(AB1)                                                    
      IF(IABC.LT.100) GO TO 30                                          
      WRITE(6,792) IABC,ELEC,ALAM,SUMT,ANEG,TEST1,TEST2,AB1             
  792 FORMAT(2X,I4,2X,7E12.4)                                           
C     STOP
   40 BO2 = AL1*ELEC                                                    
      BO1 = AL2*ELEC                                                    
      BO3 = AL3*ELEC                                                    
      BCO3 = AL4*ELEC                                                   
      BNO2 = AL5*ELEC                                                   
      BNO3 = AL6*ELEC                                                   
      BO4 = AL7*ELEC                                                    
      BCO4 = AL8*ELEC                                                   
      BO2NO = AL9*ELEC                                                  
      BO2N2 = AL10*ELEC                                                 
      BO1N2 = AL11*ELEC                                                 
      BO2H2O = AL12*ELEC                                                
      ANEG1 = ELEC*ALAM                                                 
      AR(1)=H                                                           
      AR(2)=ELEC                                                        
      AR(3)=ALAM                                                        
      AR(4)=SUMT                                                        
      AR(5)=ANEG1                                                       
      AR(6)=ANO                                                         
      AR(7)=ANOH1                                                       
      AR(8)=ANOH2                                                       
      AR(9)=ANOH3                                                       
      AR(10)=ANON1                                                      
      AR(11)=ANOHN                                                      
      AR(12)=ANOH2N                                                     
      AR(13)=ANOC1                                                      
      AR(14)=ANOHC                                                      
      AR(15)=ANOH2C                                                     
      AR(16)=AO2                                                        
      AR(17)=AO4                                                        
      AR(18)=AO5                                                        
      AR(19)=AO2H                                                       
      AR(20)=AHHOH                                                      
      AR(21)=W1                                                         
      AR(22)=W2                                                         
      AR(23)=W3                                                         
      AR(24)=W4                                                         
      AR(25)=W5                                                         
      AR(26)=W6                                                         
      AR(27)=W7                                                         
      AR(28)=W8                                                         
      AR(29)=BO1                                                        
      AR(30)=BO2                                                        
      AR(31)=BO3                                                        
      AR(32)=BO4                                                        
      AR(33)=BNO2                                                       
      AR(34)=BNO3                                                       
      AR(35)=BCO3                                                       
      AR(36)=BCO4                                                       
      AR(37)=BO2NO                                                      
      AR(38)=BO2N2                                                      
      AR(39)=BO1N2                                                      
      AR(40)=BO2H2O                                                     
      AR(41)=TE                                                         
      AR(42)=AM                                                         
      AR(43)=CO2                                                        
      AR(44)=H2O                                                        
      AR(45)=O3                                                         
      AR(46)=O1                                                         
      AR(47)=O2S                                                        
      AR(48)=ANO1                                                       
      AR(49)=ANO2                                                       
      AR(50)=QNO                                                        
      AR(51)=QO2                                                        
      AR(52)=O2                                                         
      AR(53)=HNO3                                                       
      AR(54)=O2COL                                                      
      QIT=QIO2P+QINOP                                                   
      RK5=4.4E-10                                                       
      ALF1=R40*O2*AM/(ALPH3*ELEC+R40*O2*AM+RK5*ANO1)                    
      ALF2=R41*H2O/(R48*O1+ALPH2*ELEC+R41*H2O)                          
      ALF3=(R44+R45)*H2O/((R44+R45)*H2O+ALPH2*ELEC)                     
      PHOXO2=2.*(0.904*QIT+R48*O1*(0.904*QIT*ALF1/(ALPH2*ELEC+R41*H2O   
     1+(1.-ALF1)*R48*O1)))*ALF1*ALF2*ALF3/QIT                           
      XL1=(R9*AN2+R11*CO2+R13*H2O)*AM+ALPH2*ELEC                        
      XL2=R12*AM+R15*H2O+ALPH2*ELEC                                     
      XL3=R10*AM+R14*CO2+R16*H2O+ALPH2*ELEC                             
      GAM1=R9*AN2*AM                                                    
      P1=GAM1*AR(7)                                                     
      P2=R11*AR(7)*CO2*AM+R14*AR(11)*CO2                                
      BET1=1.-(ALPH2*ELEC/(XL1-AM*(R10*GAM1/XL3+R12*(R11*CO2*AM+GAM1*   
     1R14*CO2)/XL3/XL2)))                                               
      XL4=(R17*AN2+R19*CO2+R21*H2O)*AM+ALPH2*ELEC                       
      XL5=R23*H2O+R20*AM+ALPH2*ELEC                                     
      XL6=R22*CO2+R24*H2O+R18*AM+ALPH2*ELEC                             
      GAM2=R17*AN2*AM                                                   
      P3=GAM2*AR(8)                                                     
      P4=R22*AR(12)*CO2+R19*AR(8)*CO2*AM                                
      BET2=1.-(ALPH2*ELEC/(XL4-AM*(R18*GAM2/XL6+R20*(R19*CO2*AM+GAM2*   
     1R22*CO2)/XL6/XL5)))                                               
      BET3=R25*H2O/(R25*H2O+ALPH2*ELEC)                                 
      PHOXNO=2.*BET1*BET2*BET3*(.096+.904*R49*ANO1*(1.+ALPH1*R48*O1/    
     1(ALPH2*ELEC+R41*H2O+(1.-ALPH1)*R48*O1))/(ALPH2*                   
     2ELEC+R40*O2*AM+R49*ANO1))                                         
      PHOXT=PHOXO2+PHOXNO                                               
      IF (ISWTC.EQ.0) GO TO 4444                                        
      WRITE(6,125) (AR(J),J=1,12)                                       
      WRITE(6,130) AR(1),(AR(J),J=13,24)                                
      WRITE(6,135) AR(1),(AR(J),J=25,36)                                
      WRITE(6,140) AR(1),(AR(J),J=37,48)                                
      WRITE(6,145) AR(1),AR(52),AR(54),AR(49),AR(53),AR(50),AR(51)      
  125 FORMAT (7H1HEIGHT,2X,9HELECTRONS,4X,6HLAMBDA,5X,5HTOTAL,5X,       
     *        5HTOTAL,7X,3HNO+,2X,8HNO+(H2O),1X,9HNO+(H2O)2,1X,         
     *        9HNO+(H2O)3,3X,7HNO+(N2),2X,8HNO+(H2O),2X,8HNO+(H2O)/     
     *        33X,5H+IONS,5X,5H-IONS,56X,4H(N2),5X,5H2(N2)/             
     *        (1X,0PF5.1,2X,1PE10.3,10E10.3))                           
  130 FORMAT (//7H0HEIGHT,3X,8HNO+(CO2),2X,8HNO+(H2O),2X,8HNO+(H2O),7X, 
     *        3HO2+,7X,3HO4+,7X,3HO5+,2X,8HO2+(H2O),3X,7HH+(H2O),3X,    
     *        7HH+(H2O),2X,8HH+(H2O)2,2X,8HH+(H2O)3,2X,8HH+(H2O)4/      
     *        23X,5H(CO2),4X,6H2(CO2),46X,4H(OH)/                       
     *        (1X,0PF5.1,2X,1PE10.3,11E10.3))                           
  135 FORMAT (//7H0HEIGHT,3X,8HH+(H2O)5,2X,8HH+(H2O)6,2X,8HH+(H2O)7,2X, 
     *        8HH+(H2O)8,8X,2HO-,7X,3HO2-,7X,3HO3-,7X,3HO4-,6X,4HNO2-,  
     *        6X,4HNO3-,6X,4HCO3-,6X,4HCO4-//                           
     *        (1X,0PF5.1,2X,1PE10.3,11E10.3))                           
  140 FORMAT (//7H0HEIGHT,4X,7HO2-(NO),3X,7HO2-(N2),4X,6HO-(N2),2X,     
     *        8HO2-(H2O),6X,4HTEMP,7X,3H(M),5X,5H(CO2),5X,5H(H2O),6X,   
     *        4H(O3),7X,3H(O),6X,4H(O2 ,6X,4H(NO)/110X,8HSINGLET)/      
     *        (1X,0PF5.1,2X,1PE10.3,11E10.3))                           
  145 FORMAT (//7H0HEIGHT,7X,4H(O2),1X,9HO2 COLUMN,5X,5H(NO2),4X,       
     *        6H(HNO3),4X,6HQ(NO+),4X,6HQ(O2+)//                        
     *        (1X,0PF5.1,2X,1PE10.3,5E10.3))                            
 4444 CONTINUE                                                          
      RETURN                                                            
      END                                                               
