*IF DEF,SEAICE                                                             ICEBNDS.2      
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.15065  
C                                                                          GTS2F400.15066  
C Use, duplication or disclosure of this code is subject to the            GTS2F400.15067  
C restrictions as set forth in the contract.                               GTS2F400.15068  
C                                                                          GTS2F400.15069  
C                Meteorological Office                                     GTS2F400.15070  
C                London Road                                               GTS2F400.15071  
C                BRACKNELL                                                 GTS2F400.15072  
C                Berkshire UK                                              GTS2F400.15073  
C                RG12 2SZ                                                  GTS2F400.15074  
C                                                                          GTS2F400.15075  
C If no contract has been raised with this copy of the code, the use,      GTS2F400.15076  
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.15077  
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.15078  
C Modelling at the above address.                                          GTS2F400.15079  
C ******************************COPYRIGHT******************************    GTS2F400.15080  
C                                                                          GTS2F400.15081  
!+ Ensure new ice concentration will not be greater than the max           ICEBNDS.3      
!                                                                          ICEBNDS.4      
! Subroutine Interface:                                                    ICEBNDS.5      

      SUBROUTINE ice_a_gt_max(                                              1ICEBNDS.6      
*CALL ARGOINDX                                                             ORH7F402.249    
     & imt,jmt                                                             ICEBNDS.7      
     &,amx,aice                                                            ICEBNDS.8      
     &,dela                                                                ICEBNDS.9      
     & )                                                                   ICEBNDS.10     
                                                                           ICEBNDS.11     
      IMPLICIT NONE                                                        ICEBNDS.12     
!                                                                          ICEBNDS.13     
! Description:                                                             ICEBNDS.14     
!   For each grid box, if the ice conc increment would take the conc       ICEBNDS.15     
! over the max allowed, then it is reset, so that when it is applied,      ICEBNDS.16     
! the concentration will be exactly equal to the maximum.                  ICEBNDS.17     
!                                                                          ICEBNDS.18     
! Method:                                                                  ICEBNDS.19     
!   Straight forward 'if test' within nested do loops.                     ICEBNDS.20     
!                                                                          ICEBNDS.21     
! Current Code Owner: Steve Foreman                                        ICEBNDS.22     
!                                                                          ICEBNDS.23     
! History:                                                                 ICEBNDS.24     
! Version   Date     Comment                                               ICEBNDS.25     
! -------   ----     -------                                               ICEBNDS.26     
! pre 4.0            Part of subroutine ICEFLOE                            ICEBNDS.27     
! 4.0       15.6.95  Code separated by Chris Sherlock                      ICEBNDS.28     
!                                                                          ICEBNDS.29     
! Code Description:                                                        ICEBNDS.30     
!   Language: FORTRAN 77 + common extensions.                              ICEBNDS.31     
!   This code is written to UMDP3 v6 programming standards.                ICEBNDS.32     
!                                                                          ICEBNDS.33     
! System component covered:  P4                                            ICEBNDS.34     
! System Task:                                                             ICEBNDS.35     
!                                                                          ICEBNDS.36     
! Declarations:                                                            ICEBNDS.37     
!   These are of the form:-                                                ICEBNDS.38     
!     INTEGER      ExampleVariable      !Description of variable           ICEBNDS.39     
!                                                                          ICEBNDS.40     
! Global variables (*CALLed COMDECKs etc...):                              ICEBNDS.41     
!   NONE                                                                   ICEBNDS.42     
! Subroutine arguments                                                     ICEBNDS.43     
*CALL TYPOINDX                                                             ORH7F402.250    
!   Scalar arguments with intent(in):                                      ICEBNDS.44     
      INTEGER imt            ! IN row size                                 ICEBNDS.45     
      INTEGER jmt            ! IN column size                              ICEBNDS.46     
                                                                           ICEBNDS.47     
!   Array  arguments with intent(in):                                      ICEBNDS.48     
      REAL  aice(imt,jmt)  ! IN ice concentration                          ICEBNDS.49     
      REAL  amx(jmt)      ! IN maximum ice concentration                   ICEBNDS.50     
                                                                           ICEBNDS.51     
!   Scalar arguments with intent(InOut):                                   ICEBNDS.52     
                                                                           ICEBNDS.53     
!   Array  arguments with intent(InOut):                                   ICEBNDS.54     
      REAL  dela(imt,jmt)  ! INOUT ice concentration increment             ICEBNDS.55     
                                                                           ICEBNDS.56     
!   Scalar arguments with intent(out):                                     ICEBNDS.57     
                                                                           ICEBNDS.58     
!   Array  arguments with intent(out):                                     ICEBNDS.59     
                                                                           ICEBNDS.60     
! Local parameters:                                                        ICEBNDS.61     
                                                                           ICEBNDS.62     
! Local scalars:                                                           ICEBNDS.63     
      INTEGER i,j      ! loop counters                                     ICEBNDS.64     
                                                                           ICEBNDS.65     
! Local dynamic arrays:                                                    ICEBNDS.66     
                                                                           ICEBNDS.67     
! Function & Subroutine calls:                                             ICEBNDS.68     
                                                                           ICEBNDS.69     
!- End of header                                                           ICEBNDS.70     
                                                                           ICEBNDS.71     
      DO j=J_1,J_jmt                                                       ORH3F402.440    
      DO i=1,imt                                                           ICEBNDS.73     
        IF (aice(i,j)+dela(i,j).GT.amx(j))                                 ICEBNDS.74     
     &    dela(i,j) = - aice(i,j) + amx(j)                                 ICEBNDS.75     
      ENDDO                                                                ICEBNDS.76     
      ENDDO                                                                ICEBNDS.77     
                                                                           ICEBNDS.78     
      RETURN                                                               ICEBNDS.79     
      END                                                                  ICEBNDS.80     
!+ Ensure new ice concentration will not be less than the min in icy       ICEBNDS.81     
!+ grid boxes                                                              ICEBNDS.82     
!                                                                          ICEBNDS.83     
! Subroutine Interface:                                                    ICEBNDS.84     

      SUBROUTINE ice_a_lt_min(                                              1ICEBNDS.85     
*CALL ARGOINDX                                                             ORH7F402.251    
     & imt,jmt                                                             ICEBNDS.86     
     &,aicemin,aice                                                        ICEBNDS.87     
     &,icy,newice                                                          ICEBNDS.88     
     &,dela                                                                ICEBNDS.89     
     & )                                                                   ICEBNDS.90     
                                                                           ICEBNDS.91     
      IMPLICIT NONE                                                        ICEBNDS.92     
!                                                                          ICEBNDS.93     
! Description:                                                             ICEBNDS.94     
!   For each grid box, if the ice conc increment would take the conc       ICEBNDS.95     
! below the min allowed, then it is reset, so that when it is applied,     ICEBNDS.96     
! the concentration will be exactly equal to the minimum - provided        ICEBNDS.97     
! there is ice present!                                                    ICEBNDS.98     
!                                                                          ICEBNDS.99     
! Method:                                                                  ICEBNDS.100    
!   Straight forward 'if test' within nested do loops.                     ICEBNDS.101    
!                                                                          ICEBNDS.102    
! Current Code Owner: Steve Foreman                                        ICEBNDS.103    
!                                                                          ICEBNDS.104    
! History:                                                                 ICEBNDS.105    
! Version   Date     Comment                                               ICEBNDS.106    
! -------   ----     -------                                               ICEBNDS.107    
! pre 4.0            Part of subroutine ICEFLOE                            ICEBNDS.108    
! 4.0       15.6.95  Code separated by Chris Sherlock                      ICEBNDS.109    
!                                                                          ICEBNDS.110    
! Code Description:                                                        ICEBNDS.111    
!   Language: FORTRAN 77 + common extensions.                              ICEBNDS.112    
!   This code is written to UMDP3 v6 programming standards.                ICEBNDS.113    
!                                                                          ICEBNDS.114    
! System component covered:  P4                                            ICEBNDS.115    
! System Task:                                                             ICEBNDS.116    
!                                                                          ICEBNDS.117    
! Declarations:                                                            ICEBNDS.118    
!   These are of the form:-                                                ICEBNDS.119    
!     INTEGER      ExampleVariable      !Description of variable           ICEBNDS.120    
!                                                                          ICEBNDS.121    
! Global variables (*CALLed COMDECKs etc...):                              ICEBNDS.122    
!   NONE                                                                   ICEBNDS.123    
*CALL TYPOINDX                                                             ORH7F402.252    
! Subroutine arguments                                                     ICEBNDS.124    
!   Scalar arguments with intent(in):                                      ICEBNDS.125    
      INTEGER imt            ! IN row size                                 ICEBNDS.126    
      INTEGER jmt            ! IN column size                              ICEBNDS.127    
      REAL    aicemin           ! IN minimum ice concentration             ICEBNDS.128    
                                                                           ICEBNDS.129    
!   Array  arguments with intent(in):                                      ICEBNDS.130    
      REAL  aice(imt,jmt)  ! IN ice concentration                          ICEBNDS.131    
      LOGICAL icy(imt,jmt) ! IN does grid box already contain ice?         ICEBNDS.132    
      LOGICAL newice(imt,jmt) ! IN is ice forming in icefree grid box?     ICEBNDS.133    
                                                                           ICEBNDS.134    
!   Scalar arguments with intent(InOut):                                   ICEBNDS.135    
                                                                           ICEBNDS.136    
!   Array  arguments with intent(InOut):                                   ICEBNDS.137    
      REAL  dela(imt,jmt)  ! INOUT ice concentration increment             ICEBNDS.138    
                                                                           ICEBNDS.139    
!   Scalar arguments with intent(out):                                     ICEBNDS.140    
                                                                           ICEBNDS.141    
!   Array  arguments with intent(out):                                     ICEBNDS.142    
                                                                           ICEBNDS.143    
! Local parameters:                                                        ICEBNDS.144    
                                                                           ICEBNDS.145    
! Local scalars:                                                           ICEBNDS.146    
      INTEGER i,j      ! loop counters                                     ICEBNDS.147    
                                                                           ICEBNDS.148    
! Local dynamic arrays:                                                    ICEBNDS.149    
                                                                           ICEBNDS.150    
! Function & Subroutine calls:                                             ICEBNDS.151    
                                                                           ICEBNDS.152    
!- End of header                                                           ICEBNDS.153    
                                                                           ICEBNDS.154    
      DO j=J_1,J_jmt                                                       ORH3F402.441    
      DO i=1,imt                                                           ICEBNDS.156    
        IF ((icy(i,j).or.newice(i,j)).and.                                 ICEBNDS.157    
     &      (aice(i,j)+dela(i,j).lt.aicemin))                              ICEBNDS.158    
     &    dela(i,j)= - aice(i,j) + aicemin                                 ICEBNDS.159    
      ENDDO                                                                ICEBNDS.160    
      ENDDO                                                                ICEBNDS.161    
                                                                           ICEBNDS.162    
      RETURN                                                               ICEBNDS.163    
      END                                                                  ICEBNDS.164    
!+ Deal with gridboxes with ice depth below the minimum                    ICEBNDS.165    
!                                                                          ICEBNDS.166    
! Subroutine Interface:                                                    ICEBNDS.167    

      SUBROUTINE ice_h_lt_hicemin(                                          1ICEBNDS.168    
*CALL ARGOINDX                                                             ORH7F402.253    
     & imt,jmt                                                             ICEBNDS.169    
     &,qibydt,qsbydt,salice                                                ICEBNDS.170    
     &,const1,const2,const4                                                ICEBNDS.171    
     &,surfsal,sublim                                                      ICEBNDS.172    
     &,hice,aice,hsnow                                                     ICEBNDS.173    
     &,delh,dela,hicemin                                                   ICEBNDS.174    
     &,caryheat,carysalt,snowmelt                                          ICEBNDS.175    
     &,icy                                                                 ICEBNDS.176    
     &  ,salref)                                                           OJL1F405.44     
                                                                           ICEBNDS.178    
      IMPLICIT NONE                                                        ICEBNDS.179    
!                                                                          ICEBNDS.180    
! Description:                                                             ICEBNDS.181    
!     TEST WHETHER ALL ICE IS GOING TO MELT : IF SO,STORE ANY SURPLUS      ICEBNDS.182    
!     HEAT IN CARYHEAT FOR RELEASE INTO THE OCEAN NEXT STEP,AND WORK       ICEBNDS.183    
!     OUT BOTH CONTRIBUTIONS TO CARYSALT AS WELL. (IF A VERY SMALL         ICEBNDS.184    
!     AMOUNT OF ICE REMAINS,IT IS REMOVED BY TEMPORARILY BORROWING A       ICEBNDS.185    
!     LITTLE HEAT FROM THE OCEAN,AS A SAFETY MEASURE.)                     ICEBNDS.186    
!     N.B. THERE IS AT PRESENT A SMALL ERROR HERE,BECAUSE SUBLIMATION      ICEBNDS.187    
!     IS ALLOWED TO INCREASE CARYHEAT,WHICH IS INCORRECT.                  ICEBNDS.188    
!                                                                          ICEBNDS.189    
! Method:                                                                  ICEBNDS.190    
!   Straight forward 'if test' within nested do loops.                     ICEBNDS.191    
!                                                                          ICEBNDS.192    
! Current Code Owner: Steve Foreman                                        ICEBNDS.193    
!                                                                          ICEBNDS.194    
! History:                                                                 ICEBNDS.195    
! Version   Date     Comment                                               ICEBNDS.196    
! -------   ----     -------                                               ICEBNDS.197    
! pre 4.0            Part of subroutine ICEFLOE                            ICEBNDS.198    
! 4.0       15.6.95  Code separated by Chris Sherlock                      ICEBNDS.199    
!                                                                          ICEBNDS.200    
! Code Description:                                                        ICEBNDS.201    
!   Language: FORTRAN 77 + common extensions.                              ICEBNDS.202    
!   This code is written to UMDP3 v6 programming standards.                ICEBNDS.203    
!                                                                          ICEBNDS.204    
! System component covered:  P4                                            ICEBNDS.205    
! System Task:                                                             ICEBNDS.206    
!                                                                          ICEBNDS.207    
! Declarations:                                                            ICEBNDS.208    
!   These are of the form:-                                                ICEBNDS.209    
!     INTEGER      ExampleVariable      !Description of variable           ICEBNDS.210    
!                                                                          ICEBNDS.211    
! Global variables (*CALLed COMDECKs etc...):                              ICEBNDS.212    
!   NONE                                                                   ICEBNDS.213    
! Subroutine arguments                                                     ICEBNDS.214    
*CALL CNTLOCN                                                              OJL1F405.46     
*CALL TYPOINDX                                                             ORH7F402.254    
!   Scalar arguments with intent(in):                                      ICEBNDS.215    
      INTEGER imt      ! IN row size                                       ICEBNDS.216    
      INTEGER jmt      ! IN column size                                    ICEBNDS.217    
      REAL    hicemin  ! IN minimum ice depth                              ICEBNDS.218    
      REAL    qibydt   ! IN volumetric heat of fusion (ice) / time step    ICEBNDS.219    
      REAL    qsbydt   ! IN volumetric heat of fusion (ocn) / time step    ICEBNDS.220    
      REAL    salice   ! IN reference salinity for ice                     ICEBNDS.221    
      REAL    const1   ! IN rhoice/rhowater / depth of ocean level         ICEBNDS.222    
      REAL    const2   ! IN rhosno/rhowater / depth of ocean level 1       ICEBNDS.223    
      REAL    const4   ! IN timestep / (rhowater * " " " " " " " " ")      ICEBNDS.224    
        real salref                                                        OJL1F405.45     
                                                                           ICEBNDS.225    
!   Array  arguments with intent(in):                                      ICEBNDS.226    
      REAL surfsal(imt,jmt)  ! IN salinity of top ocean level              ICEBNDS.227    
      REAL sublim(imt,jmt)   ! IN rate of sublimation kg m-2 s-1           ICEBNDS.228    
                                                                           ICEBNDS.229    
!   Scalar arguments with intent(InOut):                                   ICEBNDS.230    
                                                                           ICEBNDS.231    
!   Array  arguments with intent(InOut):                                   ICEBNDS.232    
      REAL hice(imt,jmt)     ! INOUT effective ice depth                   ICEBNDS.233    
      REAL aice(imt,jmt)     ! INOUT ice concentration                     ICEBNDS.234    
      REAL hsnow(imt,jmt)    ! INOUT snow depth over ice                   ICEBNDS.235    
      REAL delh(imt,jmt)     ! INOUT ice depth increment                   ICEBNDS.236    
      REAL dela(imt,jmt)     ! INOUT ice conc. increment                   ICEBNDS.237    
      REAL caryheat(imt,jmt) ! INOUT misc. heat ice <==> ocean             ICEBNDS.238    
      REAL carysalt(imt,jmt) ! INOUT salinity flux ice => ocean            ICEBNDS.239    
      REAL snowmelt(imt,jmt) ! INOUT keeps track of snow that melts        ICEBNDS.240    
                             !   during a time step for contrib. to        ICEBNDS.241    
                             !   carysalt.                                 ICEBNDS.242    
      LOGICAL icy(imt,jmt)   ! INOUT true if ice in grid box               ICEBNDS.243    
                                                                           ICEBNDS.244    
!   Scalar arguments with intent(out):                                     ICEBNDS.245    
                                                                           ICEBNDS.246    
!   Array  arguments with intent(out):                                     ICEBNDS.247    
                                                                           ICEBNDS.248    
! Local parameters:                                                        ICEBNDS.249    
                                                                           ICEBNDS.250    
! Local scalars:                                                           ICEBNDS.251    
      INTEGER i,j      ! loop counters                                     ICEBNDS.252    
                                                                           ICEBNDS.253    
! Local dynamic arrays:                                                    ICEBNDS.254    
                                                                           ICEBNDS.255    
! Function & Subroutine calls:                                             ICEBNDS.256    
                                                                           ICEBNDS.257    
!- End of header                                                           ICEBNDS.258    
                                                                           ICEBNDS.259    
!-------------------------------------------                               ICEBNDS.260    
                                                                           ICEBNDS.261    
      DO j=J_1,J_jmt                                                       ORH3F402.442    
        DO i=1,imt                                                         ICEBNDS.263    
          IF (icy(i,j).and.((hice(i,j)+delh(i,j)).lt.hicemin))             ICEBNDS.264    
     &    THEN                                                             ICEBNDS.265    
            ICY(I,J) = .FALSE.                                             ICEBNDS.266    
            CARYHEAT(I,J) = caryheat(i,j)                                  ICEBNDS.267    
     &                    - QIBYDT*( HICE(I,J) + DELH(I,J) )               ICEBNDS.268    
     &                    - QSBYDT*HSNOW(I,J)*AICE(I,J)                    ICEBNDS.269    
            SNOWMELT(I,J) = SNOWMELT(I,J) + HSNOW(I,J)*AICE(I,J)           ICEBNDS.270    
            DELH(I,J) = - HICE(I,J)                                        ICEBNDS.271    
            DELA(I,J) = - AICE(I,J)                                        ICEBNDS.272    
            HICE(I,J) = 0.0                                                ICEBNDS.273    
            AICE(I,J) = 0.0                                                ICEBNDS.274    
            HSNOW(I,J) = 0.0                                               ICEBNDS.275    
       if (L_REFSAL) then                                                  OJL1F405.47     
           CARYSALT(I,J) = carysalt(i,j)                                   OJL1F405.48     
     &     +CONST1*(salref-SALICE )*DELH(I,J)                              OJL1F405.49     
     &     +salref*(CONST4*SUBLIM(I,J)-CONST2*SNOWMELT(I,J))               OJL1F405.50     
       else                                                                OJL1F405.51     
           CARYSALT(I,J) = carysalt(i,j)                                   OJL1F405.52     
     &   + CONST1*( SURFSAL(I,J) - SALICE )*DELH(I,J)                      OJL1F405.53     
     &   + SURFSAL(I,J)*( CONST4*SUBLIM(I,J)-CONST2*SNOWMELT(I,J))         OJL1F405.54     
       endif                                                               OJL1F405.55     
          ENDIF                                                            ICEBNDS.279    
        ENDDO                                                              ICEBNDS.280    
      ENDDO                                                                ICEBNDS.281    
      RETURN                                                               ICEBNDS.282    
      END                                                                  ICEBNDS.283    
*ENDIF                                                                     ICEBNDS.284