*/ ! *****************************COPYRIGHT*******************************
*/ ! (C) Crown copyright Met Office. All rights reserved.
*/ ! For further details please refer to the file COPYRIGHT.txt
*/ ! which you should have received as part of this distribution.
*/ ! *****************************COPYRIGHT*******************************

*IDENT oxygen.mod 
*/
*/ FAMOUS mod to include oxygen as a prognostic tracer
*/----------------------------------------------------------------------
*/
*DECLARE BIOLOGY
*/
*B BIOLOGY.114
C
C  New declarations for oxygen calculations
C
      REAL
     &   del_o2(IMT,KM)   ! amount of o2 to bring negative conc to zero
     &  ,reset_o2(IMT)    ! vertical sum of del_o2
     &  ,RO2CO2           ! O2 to CO2 molar ratio
*/
*I BIOLOGY.207
C
C  Set the O2:CO2 ratio
      RO2CO2 = 138.0 / 106.0
C
*/
*/ Add in block changing oxygen tracer proportionally to (organic)
*/ flows of DIC
*/ 
*I OJP0F404.198
C
          TA(I,K,O2_TRACER) = TA(I,K,O2_TRACER) -
     &        TIMESTEP_DAYS(K) * RO2CO2 *
     &       ( - growth_c(I,K) + d_remin_c(I,K) + excrete_c(I,K)
     &         + z_mort_c(I,K) + p_mort_c(I,K)
     &         + p_resp_c(I,K) ) 
C
*/
*B BIOLOGY.637
C
      DO I=ISSW,IESW
        reset_o2(I) = 0.0
      ENDDO
      DO K=1,KM
        DO I=ISSW,IESW
          del_o2(I,K) = FM(I,K) * MIN( 0.0, TA(I,K,O2_TRACER) )
          TA(I,K,O2_TRACER) = TA(I,K,O2_TRACER) - del_o2(I,K)
	  reset_o2(I) = reset_o2(I) + del_o2(I,K)*DZ(K)*0.01
C	
        ENDDO
      ENDDO
C      
      DO I=ISSW,IESW
        TA(I,1,O2_TRACER) = TA(I,1,O2_TRACER)
     &    + reset_o2(I) * 100.0 / DZ(1)
C	  
        IF ( TA(I,1,O2_TRACER) .LT. 0.0 ) TA(I,1,O2_TRACER) = 0.0
C	
      ENDDO
C      
*/
*DECLARE OTRACPNT
*/ Passing O2_TRACER pointer from STOCNPT to BIOLOGY
*I OTRACPNT.38
     &        O2_TRACER,
*I OTRACPNT.54
     &        O2_TRACER,
*/   
*/ Initialising the value of O2_TRACER in STOCNPT
*DECLARE STOCNPT1
*I OJP0F404.721
          IF (IFLD.EQ.15) THEN   
            O2_TRACER = cox_tracer    
          ENDIF
C 
*/
*I STOCNPT1.151
*/
*/ Now calculate the air-sea flux of oxygen.
*/
*DECLARE FLUX_CO2
*/
*I FLUX_CO2.100
C     DEFINE VARIABLES FOR O2 FLUX CALCULATION
      REAL
     &   ASF_O2(IMT)      ! air-sea flux of O2
     &  ,csat_o2(IMT)     ! saturation conc of O2
     &  ,pv(IMT)          ! piston velocity
     &  ,schmdt(IMT)      ! schmidt number for oxygen
     &  ,sal              ! salinity intermediate
     &  ,ttc              ! temperature intermediate for schmidt
     &  ,tts              ! temperature intermediate for saturation
*/   
*I FLUX_CO2.197
C
      DO I=IFROM_CYC,ITO_CYC
        sal = MAX( 0.0, 35.0 + 1000.0 * TA(I,1,2) )
C	
        ttc = MAX( -2.0, MIN( 40.0, TA(I,1,1) ) )
C	
        tts = LOG( ( 5.713/MAX(2.71,0.01*(273.15+TA(I,1,1))) ) - 1.0 )
C
*/
*/ Note added in proof: In the denominator on the next line,
*/ a value of 22.9316 was used in the simulation presented.
*/ The correct value is 22.3916. This is a difference of 
*/ approximately 2%, thus making a negligible difference to  
*/ the conclusions reached in this paper.
*/	
        csat_o2(I) = 1.0 * ( 1000.0 / 22.3916) * EXP (
     &   ( 2.00907 + tts * ( 3.22014 + tts * ( 4.05010 + tts *
     &   ( 4.94457 + tts * ( -2.56847E-1 + tts * 3.88767 ) ) ) ) )
     &   - sal * ( 6.24523E-3 + tts * ( 7.37614E-3 + tts * ( 1.03410E-2
     &   + tts * 8.17083E-3 ) ) ) - 4.88682E-7 * sal * sal )
C 
        schmdt(I) = ( 1.0 - FM(I,1) ) + FM(I,1) * (
     &   1638.0 + ttc * ( -81.83 + ttc * ( 1.483 - ttc * 0.008004 ) ) )
C
       PISTON_VEL(I) = 0.31 * wind_speed * wind_speed  
C
       pv(I) = PISTON_VEL(I) * (0.01/3600.0) / SQRT( schmdt(I)/660.0 )
        ASF_O2(I) = RHO_WATER_SI * 1.0e-3 * (1.0 - AICE(I))
     &   * PV(I) * ( csat_o2(I) - TA(I,1,O2_TRACER) )
C
        if (ASF_O2(i).ne.ASF_O2(i)) then
          ASF_O2(i)=0.0
        endif
C
*/ The flux calcuation itself
C
        TA(I,1,O2_TRACER) = TA(I,1,O2_TRACER)
     &   + ASF_O2(I) * 43200.0 * 100.0 / DZ(1)
C
      ENDDO    
C

