!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
*** S/P LACS
#include "phy_macros_f.h"

      SUBROUTINE LACS (F, FSIZ, NI)
#include "impnone.cdk"
*
      integer fsiz, ni
      real f(fsiz)
*
*Author
*          Bernard Bilodeau (June 2001) - From lacs.cdk
*
*Revisions
* 001     B. Dugas (Jul 03)   - Introduce CRITLAC
*
*Object
*          define sea ice fraction and thickness over lakes
*
*Arguments
*          - Input/Output -
* F        permanent bus of the physics variables
*
*          - Input -
* FSIZ     dimension of F
* NI       horizontal length
*
*Implicites
*
#include "surfacepar.cdk"
#include "phybus.cdk"
#include "consphy.cdk"
#include "leads.cdk"
*
***
*
       integer i
*         
*VDIR NODEP
      DO i=0,ni-1
*
*        Array ML is the fraction of lakes.
*
         IF (f(ml+i).lt.critlac) then         ! Not over lakes
*
*           Leadfrac is the climatological value of % of leads in
*           MARINE ice. The ice-covered lakes remain untouched.
*           GLSEA0 contains the original value of the sea-ice
*           analysis (updated if needed with daily increments
*           if switch "CLIMAT" is true in subroutine CLIMPHS).
*
            f(glsea   +i                 ) = f(glsea +i) *
     +                                        (1. - leadfrac)
*
*           Set minimal ice depth if zero ice thickness in 
*           analysis (or climatology) while ice fraction is non zero
            if (f(glsea+i).ge.0..and.f(icedp+i).le.0.) then
               f(icedp+i) = max(minicedp, 0.25 * f(glsea+i))
            endif
*
         ELSE                                       ! Over lakes
*
*           Water temperature of ice-covered lakes is 0 C.
            if (f(glsea+i) .gt. 10.*critmask) f(twater+i) = TRPL 
*
*           Over lakes, ice thickness is set to a minimum of 30 cm
*           if GL > 50%. GL is then changed to 100% since the lakes
*           are usually fully frozen. Otherwise, linear interpolation
*           of ice thickness (varying between 0 and 30 cm) is performed
*           when GL ranges from 0 to 50%.
*
            IF (f(glsea+i).gt.0.50) then
               f(icedp   +i              ) = 0.30
               f(glsea   +i              ) = 1.00
            ELSE
               f(icedp   +i              ) = 0.60 * f(glsea+i)
            END IF 
*
         END IF
*
      END DO
*
      RETURN
      END