Index: trunk/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 1420)
+++ trunk/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 1423)
@@ -4,9 +4,10 @@
    !! Ocean physics: solar radiation penetration in the top ocean levels
    !!======================================================================
-   !! History :  6.0  !  90-10  (B. Blanke)  Original code
-   !!            7.0  !  91-11  (G. Madec)
-   !!                 !  96-01  (G. Madec)  s-coordinates
-   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
-   !!            9.0  !  05-11  (G. Madec) zco, zps, sco coordinate
+   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11  (G. Madec)
+   !!                 !  1996-01  (G. Madec)  s-coordinates
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
+   !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
+   !!            3.2  !  2009-04  (G. Madec & NEMO team) 
    !!----------------------------------------------------------------------
 
@@ -24,20 +25,23 @@
    USE phycst          ! physical constants
    USE prtctl          ! Print control
+   USE iom             ! I/O manager
+   USE fldread         ! read input fields
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   tra_qsr      ! routine called by step.F90 (ln_traqsr=T)
-   PUBLIC   tra_qsr_init ! routine called by opa.F90
-
-   !!* Namelist namqsr: penetrative solar radiation
-   LOGICAL , PUBLIC ::   ln_traqsr = .TRUE.   !: qsr flag (Default=T)
-   REAL(wp), PUBLIC ::   rabs = 0.58_wp       ! fraction associated with xsi1
-   REAL(wp), PUBLIC ::   xsi1 = 0.35_wp       ! first depth of extinction 
-   REAL(wp), PUBLIC ::   xsi2 = 23.0_wp       ! second depth of extinction (default values: water type Ib)
-   LOGICAL , PUBLIC ::   ln_qsr_sms = .false. ! flag to use or not the biological fluxes for light 
+   PUBLIC   tra_qsr        ! routine called by step.F90 (ln_traqsr=T)
+
+   !                                           !!* Namelist namqsr: penetrative solar radiation
+   LOGICAL , PUBLIC ::   ln_traqsr  = .TRUE.    !: light absorption (qsr) flag
+   LOGICAL , PUBLIC ::   ln_qsr_rgb = .FALSE.   !: Red-Green-Blue light absorption flag  
+   LOGICAL , PUBLIC ::   ln_qsr_bio = .FALSE.   !: bio-model      light absorption flag
+   INTEGER , PUBLIC ::   nn_chldta  = 0         !: use Chlorophyll data (=1) or not (=0)
+   REAL(wp), PUBLIC ::   rn_abs     = 0.58_wp   !: fraction absorbed in the very near surface (RGB & 2 bands)
+   REAL(wp), PUBLIC ::   rn_si0     = 0.35_wp   !: very near surface depth of extinction      (RGB & 2 bands)
+   REAL(wp), PUBLIC ::   rn_si1     = 23.0_wp   !: deepest depth of extinction (water type I)       (2 bands)
+   REAL(wp), PUBLIC ::   rn_si2     = 61.8_wp   !: deepest depth of extinction (blue & 0.01 mg.m-3)     (RGB)
    
-   INTEGER ::   nksr   ! number of levels
-   REAL(wp), DIMENSION(jpk) ::   gdsr   ! profile of the solar flux penetration
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_chl   ! structure of input Chl (file informations, fields read)
 
    !! * Substitutions
@@ -45,5 +49,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
    !! $Id$
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
@@ -59,11 +63,10 @@
       !!      penetration and add it to the general temperature trend.
       !!
-      !! ** Method  : The profile of the solar radiation within the ocean is
-      !!      defined through two penetration length scale (xsr1,xsr2) and a 
-      !!      ratio (rabs) as :
-      !!         I(k) = Qsr*( rabs*EXP(z(k)/xsr1) + (1.-rabs)*EXP(z(k)/xsr2) )
-      !!         The temperature trend associated with the solar radiation
-      !!      penetration is given by :
-      !!            zta = 1/e3t dk[ I ] / (rau0*Cp)
+      !! ** Method  : The profile of the solar radiation within the ocean is defined
+      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
+      !!      Considering the 2 wavebands case:
+      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
+      !!         The temperature trend associated with the solar radiation penetration 
+      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
       !!         At the bottom, boudary condition for the radiation is no flux :
       !!      all heat which has not been absorbed in the above levels is put
@@ -76,4 +79,7 @@
       !! ** Action  : - update ta with the penetrative solar radiation trend
       !!              - save the trend in ttrd ('key_trdtra')
+      !!
+      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
       !!----------------------------------------------------------------------
       USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
@@ -82,6 +88,10 @@
       INTEGER, INTENT(in) ::   kt     ! ocean time-step
       !!
-      INTEGER  ::    ji, jj, jk       ! dummy loop indexes
-      REAL(wp) ::   zc0 , zta         ! temporary scalars
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      INTEGER  ::   irgb                 ! temporary integers
+      REAL(wp) ::   zchl, zcoef, zsi0r   ! temporary scalars
+      REAL(wp) ::   zc0, zc1, zc2, zc3   !    -         -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr            ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0, ze1 , ze2, ze3, zea    ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -91,4 +101,5 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~'
          CALL tra_qsr_init
+         IF( .NOT.ln_traqsr )   RETURN
       ENDIF
 
@@ -98,64 +109,95 @@
       ENDIF
 
-      ! ---------------------------------------------- !
-      !  Biological fluxes  : all vertical coordinate  !
-      ! ---------------------------------------------- !
-      IF( lk_qsr_sms .AND. ln_qsr_sms ) THEN      
-         !                                                   ! ===============
-         DO jk = 1, jpkm1                                    ! Horizontal slab
-            !                                                ! ===============
+      
+      !                                           ! ============================================== !
+      IF( lk_qsr_bio ) THEN                       !  bio-model fluxes  : all vertical coordinates  !
+         !                                        ! ============================================== !
+         DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zc0 = ro0cpr  / fse3t(ji,jj,jk)         ! compute the qsr trend
-                  zta = zc0 * ( etot3(ji,jj,jk  ) * tmask(ji,jj,jk)     &
-                     &        - etot3(ji,jj,jk+1) * tmask(ji,jj,jk+1) )
-                  ta(ji,jj,jk) = ta(ji,jj,jk) + zta       ! add qsr trend to the temperature trend
+                  ta(ji,jj,jk) = ta(ji,jj,jk) + ro0cpr * ( etot3(ji,jj,jk) - etot3(ji,jj,jk+1) ) / fse3t(ji,jj,jk) 
                END DO
             END DO
-            !                                                ! ===============
-         END DO                                              !   End of slab
-         !                                                   ! ===============
-
-      ! ---------------------------------------------- !
-      !  Ocean alone :
-      ! ---------------------------------------------- !
-      ELSE
-         !                                                ! =================== !
-         IF( ln_sco ) THEN                                !    s-coordinate     !
-            !                                             ! =================== !
-            DO jk = 1, jpkm1
-               ta(:,:,jk) = ta(:,:,jk) + etot3(:,:,jk) * qsr(:,:)
-            END DO
-         ENDIF
-         !                                                ! =================== !
-         IF( ln_zps ) THEN                                !    partial steps    !
-            !                                             ! =================== !
+         END DO
+         !                                        ! ============================================== !
+      ELSE                                        !  Ocean alone : 
+         !                                        ! ============================================== !
+         !
+         !                                                ! ------------------------- !
+         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
+            !                                             ! ------------------------- !
+            ! Set chlorophyl concentration
+            IF( nn_chldta ==1 ) THEN                             !*  Variable Chlorophyll
+               !
+               CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
+               !         
+!CDIR COLLAPSE
+!CDIR NOVERRCHK
+               DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
+!CDIR NOVERRCHK
+                  DO ji = 1, jpi
+                     zchl = MIN( 10. , MAX( 0.03, sf_chl(1)%fnow(ji,jj) ) )
+                     achl(ji,jj) = zchl
+                     irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+                     zekb(ji,jj) = rkrgb(1,irgb)
+                     zekg(ji,jj) = rkrgb(2,irgb)
+                     zekr(ji,jj) = rkrgb(3,irgb)
+                  END DO
+               END DO
+               !
+               zsi0r = 1.e0 / rn_si0
+               zcoef  = ( 1. - rn_abs ) / 3.e0                        ! equi-partition in R-G-B
+               ze0(:,:,1) = rn_abs  * qsr(:,:)
+               ze1(:,:,1) = zcoef * qsr(:,:)
+               ze2(:,:,1) = zcoef * qsr(:,:)
+               ze3(:,:,1) = zcoef * qsr(:,:)
+               zea(:,:,1) =         qsr(:,:)
+               !
+               DO jk = 2, nksr+1
+!CDIR NOVERRCHK
+                  DO jj = 1, jpj
+!CDIR NOVERRCHK   
+                     DO ji = 1, jpi
+                        zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
+                        zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
+                        zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
+                        zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
+                        ze0(ji,jj,jk) = zc0
+                        ze1(ji,jj,jk) = zc1
+                        ze2(ji,jj,jk) = zc2
+                        ze3(ji,jj,jk) = zc3
+                        zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+               !
+               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
+                  ta(:,:,jk) = ta(:,:,jk) + ro0cpr * ( zea(:,:,jk) - zea(:,:,jk+1) ) / fse3t(:,:,jk)
+               END DO
+               !
+            ELSE                                                 !*  Constant Chlorophyll
+               DO jk = 1, nksr
+                  ta(:,:,jk) = ta(:,:,jk) + etot3(:,:,jk) * qsr(:,:)
+               END DO
+            ENDIF
+
+!!gm BUG  the case key_vvl is missing: etot3 should be recomputed at each time step !!!
+
+            !                                             ! ------------------------- !
+         ELSE                                             !  2 band light penetration !
+            !                                             ! ------------------------- !
+            !
             DO jk = 1, nksr
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ! qsr trend from gdsr
-                     zc0 = qsr(ji,jj) / fse3t(ji,jj,jk)
-                     zta = zc0 * ( gdsr(jk) * tmask(ji,jj,jk) - gdsr(jk+1) * tmask(ji,jj,jk+1) )
-                     ! add qsr trend to the temperature trend
-                     ta(ji,jj,jk) = ta(ji,jj,jk) + zta
+                     ta(ji,jj,jk) = ta(ji,jj,jk) + etot3(ji,jj,jk) * qsr(ji,jj)
                   END DO
                END DO
             END DO
+            !
          ENDIF
-         !                                                ! =================== !
-         IF( ln_zco ) THEN                                !     z-coordinate    !
-            !                                             ! =================== !
-            DO jk = 1, nksr
-               zc0 = 1. / e3t_0(jk)
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ! qsr trend
-                     zta = qsr(ji,jj) * zc0 * ( gdsr(jk)*tmask(ji,jj,jk) - gdsr(jk+1)*tmask(ji,jj,jk+1) )
-                     ! add qsr trend to the temperature trend
-                     ta(ji,jj,jk) = ta(ji,jj,jk) + zta      
-                  END DO
-               END DO
-            END DO
-         ENDIF
+
+!!gm BUG  the case key_vvl is missing: etot3 should be recomputed at each time step !!!
+
          !
       ENDIF
@@ -178,39 +220,158 @@
       !!
       !! ** Method  :   The profile of solar radiation within the ocean is set
-      !!      from two length scale of penetration (xsr1,xsr2) and a ratio
-      !!      (rabs). These parameters are read in the namqsr namelist. The
+      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
+      !!      (rn_abs). These parameters are read in the namqsr namelist. The
       !!      default values correspond to clear water (type I in Jerlov' 
       !!      (1968) classification.
       !!         called by tra_qsr at the first timestep (nit000)
       !!
-      !! ** Action  : - initialize xsr1, xsr2 and rabs
+      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
       !!
       !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
       !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk   ! dummy loop index
-      INTEGER  ::   indic        ! temporary integer
-      REAL(wp) ::   zc0 , zc1 , zc2    ! temporary scalars
-      REAL(wp) ::   zcst, zdp1, zdp2   !    "         "
-
-      NAMELIST/namqsr/ ln_traqsr, rabs, xsi1, xsi2, ln_qsr_sms
-      !!----------------------------------------------------------------------
-
-      REWIND ( numnam )           ! Read Namelist namqsr : ratio and length of penetration
-      READ   ( numnam, namqsr )
-
-      IF( ln_traqsr  ) THEN       ! Parameter control and print
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'tra_qsr_init : penetration of the surface solar radiation'
-            WRITE(numout,*) '~~~~~~~~~~~~'
-            WRITE(numout,*) '    Namelist namqsr : set the parameter of penetration'
-            WRITE(numout,*) '        fraction associated with xsi     rabs        = ',rabs
-            WRITE(numout,*) '        first depth of extinction        xsi1        = ',xsi1
-            WRITE(numout,*) '        second depth of extinction       xsi2        = ',xsi2
-            IF( lk_qsr_sms ) THEN
-               WRITE(numout,*) '     Biological fluxes for light(Y/N) ln_qsr_sms  = ',ln_qsr_sms
+      INTEGER  ::   ji, jj, jk     ! dummy loop indices
+      INTEGER  ::   irgb, ierror   ! temporary integer
+      REAL(wp) ::   zc0  , zc1  , zem     ! temporary scalars
+      REAL(wp) ::   zc2  , zc3  , zchl    !    -         -
+      REAL(wp) ::   zsi0r, zsi1r, zcoef   !    -         -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr              ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0 , ze1 , ze2 , ze3 , zea   ! 3D workspace
+      !!
+      CHARACTER(len=100) ::   cn_dir   ! Root directory for location of ssr files
+      TYPE(FLD_N)        ::   sn_chl   ! informations about the chlorofyl field to be read
+      NAMELIST/namqsr/  sn_chl, cn_dir, ln_traqsr, ln_qsr_rgb, ln_qsr_bio,   &
+         &              nn_chldta, rn_abs, rn_si0, rn_si1, rn_si2
+      !!----------------------------------------------------------------------
+
+      cn_dir = './'       ! directory in which the model is executed
+      ! ... default values (NB: frequency positive => hours, negative => months)
+      !            !     file       ! frequency !  variable  ! time interp !  clim   ! 'yearly' or ! weights  ! rotation   !
+      !            !     name       !  (hours)  !    name    !    (T/F)    !  (T/F)  ! 'monthly'   ! filename ! pairs      !
+      sn_chl = FLD_N( 'chlorophyll' ,    -1     ,  'CHLA'    ,  .true.     , .true.  ,   'yearly'  , ''       , ''         )
+      !
+      REWIND( numnam )            ! Read Namelist namqsr : ratio and length of penetration
+      READ  ( numnam, namqsr )
+      !
+      IF(lwp) THEN                ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_qsr_init : penetration of the surface solar radiation'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '    Namelist namqsr : set the parameter of penetration'
+         WRITE(numout,*) '        Light penetration (T) or not (F)         ln_traqsr  = ', ln_traqsr
+         WRITE(numout,*) '        RGB (Red-Green-Blue) light penetration   ln_qsr_rgb = ', ln_qsr_rgb
+         WRITE(numout,*) '        bio-model            light penetration   ln_qsr_bio = ', ln_qsr_bio
+         WRITE(numout,*) '        RGB : Chl data (=1) or cst value (=0)    nn_chldta  = ', nn_chldta
+         WRITE(numout,*) '        RGB & 2 bands: fraction of light (rn_si1)    rn_abs = ', rn_abs
+         WRITE(numout,*) '        RGB & 2 bands: shortess depth of extinction  rn_si0 = ', rn_si0
+         WRITE(numout,*) '        2 bands: longest depth of extinction         rn_si1 = ', rn_si1
+         WRITE(numout,*) '        3 bands: longest depth of extinction         rn_si2 = ', rn_si2
+      ENDIF
+      !                         ! control consistency
+      IF( lk_qsr_bio .AND. .NOT.ln_qsr_bio ) THEN
+         ln_qsr_bio = .true.
+         CALL ctl_warn( 'Force bio-model light penetraton ln_qsr_bio  = TRUE ' )
+      ENDIF
+      
+      !                          ! ===================================== !
+      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  !  
+         !                       ! ===================================== !
+         !
+         zsi0r = 1.e0 / rn_si0
+         zsi1r = 1.e0 / rn_si1
+         !                                ! ---------------------------------- !
+         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
+            !                             ! ---------------------------------- !
+            !
+            !                                ! level of light extinction
+            nksr = trc_oce_ext_lev( rn_si2, 0.33e2 )
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) '        level max of computation of qsr = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
             ENDIF
+            !
+            CALL trc_oce_rgb( rkrgb )           !* tabulated attenuation coef.
+!!gm            CALL trc_oce_rgb_read( rkrgb )           !* tabulated attenuation coef.
+            !
+            IF( nn_chldta == 1 ) THEN           !* Chl data : set sf_chl structure
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '        Chlorophyll read in a file'
+               ALLOCATE( sf_chl(1), STAT=ierror )
+               IF( ierror > 0 ) THEN
+                  CALL ctl_stop( 'tra_qsr_init: unable to allocate sf_chl structure' )   ;   RETURN
+               ENDIF
+               ALLOCATE( sf_chl(1)%fnow(jpi,jpj)   )
+               ALLOCATE( sf_chl(1)%fdta(jpi,jpj,2) )
+               !                                        ! fill sf_chl with sn_chl and control print
+               CALL fld_fill( sf_chl, (/ sn_chl /), cn_dir, 'tra_qsr_init',   &
+                  &                                         'Solar penetration function of read chlorophyll', 'namqsr' )
+               !
+            ELSE                                !* constant Chl : compute once for all the distribution of light (etot3)
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '        Constant Chlorophyll concentration = 0.05'
+               IF(lwp) WRITE(numout,*) '        light distribution computed once for all'
+               !
+               zchl = 0.05                                 ! constant chlorophyll
+               irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+               zekb(:,:) = rkrgb(1,irgb)                   ! Separation in R-G-B depending of the chlorophyl concentration
+               zekg(:,:) = rkrgb(2,irgb)
+               zekr(:,:) = rkrgb(3,irgb)
+               !
+               zcoef = ( 1. - rn_abs ) / 3.e0              ! equi-partition in R-G-B
+               ze0(:,:,1) = rn_abs
+               ze1(:,:,1) = zcoef
+               ze2(:,:,1) = zcoef 
+               ze3(:,:,1) = zcoef
+               zea(:,:,1) = tmask(:,:,1)                   ! = ( ze0+ze1+z2+ze3 ) * tmask
+               
+               DO jk = 2, nksr+1
+!CDIR NOVERRCHK
+                  DO jj = 1, jpj
+!CDIR NOVERRCHK   
+                     DO ji = 1, jpi
+                        zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
+                        zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
+                        zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
+                        zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
+                        ze0(ji,jj,jk) = zc0                 
+                        ze1(ji,jj,jk) = zc1
+                        ze2(ji,jj,jk) = zc2     
+                        ze3(ji,jj,jk) = zc3
+                        zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO 
+               !
+               DO jk = 1, nksr
+                  etot3(:,:,jk) = ro0cpr * ( zea(:,:,jk) - zea(:,:,jk+1) ) / fse3t(:,:,jk)
+               END DO
+               etot3(:,:,nksr+1:jpk) = 0.e0                ! below 400m set to zero
+            ENDIF
+            !
+            !                             ! ---------------------------------- !
+         ELSE                             !    2 bands    light penetration    !
+            !                             ! ---------------------------------- !
+            !
+            !                                ! level of light extinction
+            nksr = trc_oce_ext_lev( rn_si1, 1.e2 )
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) '        level max of computation of qsr = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
+            ENDIF
+            !
+            DO jk = 1, nksr                    !*  solar heat absorbed at T-point computed once for all
+               DO jj = 1, jpj                              ! top 400 meters
+                  DO ji = 1, jpi
+                     zc0 = rn_abs * EXP( -fsdepw(ji,jj,jk  )*zsi0r ) + (1.-rn_abs) * EXP( -fsdepw(ji,jj,jk  )*zsi1r )
+                     zc1 = rn_abs * EXP( -fsdepw(ji,jj,jk+1)*zsi0r ) + (1.-rn_abs) * EXP( -fsdepw(ji,jj,jk+1)*zsi1r )
+                     etot3(ji,jj,jk) = ro0cpr * (  zc0 * tmask(ji,jj,jk) - zc1 * tmask(ji,jj,jk+1)  ) / fse3t(ji,jj,jk)
+                  END DO
+               END DO
+            END DO 
+            etot3(:,:,nksr+1:jpk) = 0.e0                   ! below 400m set to zero
+            !
          ENDIF
-      ELSE
+         !                       ! ===================================== !
+      ELSE                       !        No light penetration           !                   
+         !                       ! ===================================== !
          IF(lwp) THEN
             WRITE(numout,*)
@@ -219,62 +380,4 @@
          ENDIF
       ENDIF
-
-      IF( rabs > 1.e0 .OR. rabs < 0.e0 .OR. xsi1 < 0.e0 .OR. xsi2 < 0.e0 ) &
-         CALL ctl_stop( '             0<rabs<1, 0<xsi1, or 0<xsi2 not satisfied' )
-
-      !                           ! Initialization of gdsr
-      IF( ln_zco .OR. ln_zps ) THEN
-         !
-         ! z-coordinate with or without partial step : same w-level everywhere inside the ocean
-         gdsr(:) = 0.e0
-         DO jk = 1, jpk
-            zdp1 = -gdepw_0(jk)
-            gdsr(jk) = ro0cpr * (  rabs  * EXP( zdp1/xsi1 ) + (1.-rabs) * EXP( zdp1/xsi2 )  )
-            IF ( gdsr(jk) <= 1.e-10 ) EXIT
-         END DO
-         indic = 0
-         DO jk = 1, jpk
-            IF( gdsr(jk) <= 1.e-15 .AND. indic == 0 ) THEN
-               gdsr(jk) = 0.e0
-               nksr = jk
-               indic = 1
-            ENDIF
-         END DO
-         nksr = MIN( nksr, jpkm1 )
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) '        - z-coordinate, level max of computation =', nksr
-            WRITE(numout,*) '             profile of coef. of penetration:'
-            WRITE(numout,"('              ',7e11.2)") ( gdsr(jk), jk = 1, nksr )
-            WRITE(numout,*)
-         ENDIF
-         ! Initialisation of Biological fluxes for light here because
-         ! the optical biological model is call after the dynamical one
-         IF( lk_qsr_sms .AND. ln_qsr_sms ) THEN
-            DO jk = 1, jpkm1
-               zcst = gdsr(jk) / ro0cpr
-               etot3(:,:,jk) = qsr(:,:) * zcst * tmask(:,:,jk) 
-            END DO
-         ENDIF
-         !
-      ENDIF
-
-      ! Initialisation of etot3 (s-coordinate)
-      ! -----------------------
-      IF( ln_sco ) THEN
-         etot3(:,:,jpk) = 0.e0
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zdp1 = -fsdepw(ji,jj,jk  )
-                  zdp2 = -fsdepw(ji,jj,jk+1)
-                  zc0  = ro0cpr / fse3t(ji,jj,jk)
-                  zc1  =   (  rabs * EXP(zdp1/xsi1) + (1.-rabs) * EXP(zdp1/xsi2)  )
-                  zc2  = - (  rabs * EXP(zdp2/xsi1) + (1.-rabs) * EXP(zdp2/xsi2)  )
-                  etot3(ji,jj,jk)  = zc0 * (  zc1 * tmask(ji,jj,jk) + zc2 * tmask(ji,jj,jk+1)  )
-               END DO
-            END DO
-         END DO 
-      ENDIF
       !
    END SUBROUTINE tra_qsr_init
Index: trunk/NEMO/OPA_SRC/trc_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/trc_oce.F90	(revision 1420)
+++ trunk/NEMO/OPA_SRC/trc_oce.F90	(revision 1423)
@@ -4,26 +4,239 @@
    !! Ocean passive tracer  :  share SMS/Ocean variables
    !!======================================================================
-   !! History :
-   !!   9.0  !  04-03  (C. Ethe)  F90: Free form and module
-   !!----------------------------------------------------------------------
+   !! History :  1.0  !  2004-03  (C. Ethe)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trc_oce_rgb : tabulated attenuation coefficients for RGB light penetration         
+   !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+
 #if defined key_top && defined key_pisces
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Id$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   USE sms_pisces , ONLY :  &
-      etot3    =>   etot3   !!:  Biological fluxes for light
-   !! Shared module variables
-   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_sms = .TRUE. 
+   !!   'key_top'   &   'key_pisces'                       PISCES bio-model          
+   !!----------------------------------------------------------------------
+   USE sms_pisces , ONLY :   etot3    =>   etot3   !:  bio-model light absorption
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_oce_rgb   ! routine called by p4zopt.F90
+   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_bio = .TRUE.   !: bio-model light absorption flag
+   
 #else
    !!----------------------------------------------------------------------
-   !! Default option                         No Biological fluxes for light          
+   !! Default option                          No bio-model light absorption      
    !!----------------------------------------------------------------------
    USE par_oce
-   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_sms = .FALSE. 
-   REAL(wp), PUBLIC , DIMENSION (jpi,jpj,jpk) :: &
-      etot3
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_oce_rgb   ! routine called by traqsr.F90
+   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_bio = .FALSE.   !: bio-model light absorption flag
+   
+   REAL(wp), PUBLIC , DIMENSION(jpi,jpj,jpk) ::   etot3   !: light absortion coefficient
 #endif
 
+   PUBLIC   trc_oce_ext_lev    ! function called by traqsr.F90 at least
+
+   INTEGER, PUBLIC ::   nksr   ! levels below which the light cannot penetrate ( depth larger than 391 m)
+
+   REAL(wp), DIMENSION(3,61), PUBLIC ::   rkrgb   !: tabulated attenuation coefficients for RGB absorption
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_oce_rgb( prgb )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE p4z_opt_init  ***
+      !!
+      !! ** Purpose :   Initialization of of the optical scheme
+      !!
+      !! ** Method  :   Set a look up table for the optical coefficients
+      !!                i.e. the attenuation coefficient for R-G-B light 
+      !!                tabulated in Chlorophyll class (from JM Andre)
+      !!
+      !! ** Action  :   prgb(3,61) tabulated R-G-B attenuation coef. 
+      !!
+      !! Reference  : Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(3,61), INTENT(inout) ::   prgb   ! tabulated attenuation coefficient
+      !!
+      INTEGER  ::   jc     ! dummy loop indice
+      INTEGER  ::   irgb   ! temporary integer
+      REAL(wp) ::   zchl   ! temporary scalar
+      REAL(wp), DIMENSION(4,61) ::   zrgb   ! tabulated attenuation coefficient (formerly read in 'kRGB61.txt')
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_oce_rgb : Initialisation of the optical look-up table'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+      !
+      !  Chlorophyll        !     Blue attenuation     !     Green attenuation    !     Red attenuation      !
+      zrgb(1, 1) =  0.010   ;   zrgb(2, 1) = 0.01618   ;   zrgb(3, 1) = 0.07464   ;   zrgb(4, 1) = 0.37807
+      zrgb(1, 2) =  0.011   ;   zrgb(2, 2) = 0.01654   ;   zrgb(3, 2) = 0.07480   ;   zrgb(4, 2) = 0.37823
+      zrgb(1, 3) =  0.013   ;   zrgb(2, 3) = 0.01693   ;   zrgb(3, 3) = 0.07499   ;   zrgb(4, 3) = 0.37840
+      zrgb(1, 4) =  0.014   ;   zrgb(2, 4) = 0.01736   ;   zrgb(3, 4) = 0.07518   ;   zrgb(4, 4) = 0.37859
+      zrgb(1, 5) =  0.016   ;   zrgb(2, 5) = 0.01782   ;   zrgb(3, 5) = 0.07539   ;   zrgb(4, 5) = 0.37879
+      zrgb(1, 6) =  0.018   ;   zrgb(2, 6) = 0.01831   ;   zrgb(3, 6) = 0.07562   ;   zrgb(4, 6) = 0.37900
+      zrgb(1, 7) =  0.020   ;   zrgb(2, 7) = 0.01885   ;   zrgb(3, 7) = 0.07586   ;   zrgb(4, 7) = 0.37923
+      zrgb(1, 8) =  0.022   ;   zrgb(2, 8) = 0.01943   ;   zrgb(3, 8) = 0.07613   ;   zrgb(4, 8) = 0.37948
+      zrgb(1, 9) =  0.025   ;   zrgb(2, 9) = 0.02005   ;   zrgb(3, 9) = 0.07641   ;   zrgb(4, 9) = 0.37976
+      zrgb(1,10) =  0.028   ;   zrgb(2,10) = 0.02073   ;   zrgb(3,10) = 0.07672   ;   zrgb(4,10) = 0.38005
+      zrgb(1,11) =  0.032   ;   zrgb(2,11) = 0.02146   ;   zrgb(3,11) = 0.07705   ;   zrgb(4,11) = 0.38036
+      zrgb(1,12) =  0.035   ;   zrgb(2,12) = 0.02224   ;   zrgb(3,12) = 0.07741   ;   zrgb(4,12) = 0.38070
+      zrgb(1,13) =  0.040   ;   zrgb(2,13) = 0.02310   ;   zrgb(3,13) = 0.07780   ;   zrgb(4,13) = 0.38107
+      zrgb(1,14) =  0.045   ;   zrgb(2,14) = 0.02402   ;   zrgb(3,14) = 0.07821   ;   zrgb(4,14) = 0.38146
+      zrgb(1,15) =  0.050   ;   zrgb(2,15) = 0.02501   ;   zrgb(3,15) = 0.07866   ;   zrgb(4,15) = 0.38189
+      zrgb(1,16) =  0.056   ;   zrgb(2,16) = 0.02608   ;   zrgb(3,16) = 0.07914   ;   zrgb(4,16) = 0.38235
+      zrgb(1,17) =  0.063   ;   zrgb(2,17) = 0.02724   ;   zrgb(3,17) = 0.07967   ;   zrgb(4,17) = 0.38285
+      zrgb(1,18) =  0.071   ;   zrgb(2,18) = 0.02849   ;   zrgb(3,18) = 0.08023   ;   zrgb(4,18) = 0.38338
+      zrgb(1,19) =  0.079   ;   zrgb(2,19) = 0.02984   ;   zrgb(3,19) = 0.08083   ;   zrgb(4,19) = 0.38396
+      zrgb(1,20) =  0.089   ;   zrgb(2,20) = 0.03131   ;   zrgb(3,20) = 0.08149   ;   zrgb(4,20) = 0.38458
+      zrgb(1,21) =  0.100   ;   zrgb(2,21) = 0.03288   ;   zrgb(3,21) = 0.08219   ;   zrgb(4,21) = 0.38526
+      zrgb(1,22) =  0.112   ;   zrgb(2,22) = 0.03459   ;   zrgb(3,22) = 0.08295   ;   zrgb(4,22) = 0.38598
+      zrgb(1,23) =  0.126   ;   zrgb(2,23) = 0.03643   ;   zrgb(3,23) = 0.08377   ;   zrgb(4,23) = 0.38676
+      zrgb(1,24) =  0.141   ;   zrgb(2,24) = 0.03842   ;   zrgb(3,24) = 0.08466   ;   zrgb(4,24) = 0.38761
+      zrgb(1,25) =  0.158   ;   zrgb(2,25) = 0.04057   ;   zrgb(3,25) = 0.08561   ;   zrgb(4,25) = 0.38852
+      zrgb(1,26) =  0.178   ;   zrgb(2,26) = 0.04289   ;   zrgb(3,26) = 0.08664   ;   zrgb(4,26) = 0.38950
+      zrgb(1,27) =  0.200   ;   zrgb(2,27) = 0.04540   ;   zrgb(3,27) = 0.08775   ;   zrgb(4,27) = 0.39056
+      zrgb(1,28) =  0.224   ;   zrgb(2,28) = 0.04811   ;   zrgb(3,28) = 0.08894   ;   zrgb(4,28) = 0.39171
+      zrgb(1,29) =  0.251   ;   zrgb(2,29) = 0.05103   ;   zrgb(3,29) = 0.09023   ;   zrgb(4,29) = 0.39294
+      zrgb(1,30) =  0.282   ;   zrgb(2,30) = 0.05420   ;   zrgb(3,30) = 0.09162   ;   zrgb(4,30) = 0.39428
+      zrgb(1,31) =  0.316   ;   zrgb(2,31) = 0.05761   ;   zrgb(3,31) = 0.09312   ;   zrgb(4,31) = 0.39572
+      zrgb(1,32) =  0.355   ;   zrgb(2,32) = 0.06130   ;   zrgb(3,32) = 0.09474   ;   zrgb(4,32) = 0.39727
+      zrgb(1,33) =  0.398   ;   zrgb(2,33) = 0.06529   ;   zrgb(3,33) = 0.09649   ;   zrgb(4,33) = 0.39894
+      zrgb(1,34) =  0.447   ;   zrgb(2,34) = 0.06959   ;   zrgb(3,34) = 0.09837   ;   zrgb(4,34) = 0.40075
+      zrgb(1,35) =  0.501   ;   zrgb(2,35) = 0.07424   ;   zrgb(3,35) = 0.10040   ;   zrgb(4,35) = 0.40270
+      zrgb(1,36) =  0.562   ;   zrgb(2,36) = 0.07927   ;   zrgb(3,36) = 0.10259   ;   zrgb(4,36) = 0.40480
+      zrgb(1,37) =  0.631   ;   zrgb(2,37) = 0.08470   ;   zrgb(3,37) = 0.10495   ;   zrgb(4,37) = 0.40707
+      zrgb(1,38) =  0.708   ;   zrgb(2,38) = 0.09056   ;   zrgb(3,38) = 0.10749   ;   zrgb(4,38) = 0.40952
+      zrgb(1,39) =  0.794   ;   zrgb(2,39) = 0.09690   ;   zrgb(3,39) = 0.11024   ;   zrgb(4,39) = 0.41216
+      zrgb(1,40) =  0.891   ;   zrgb(2,40) = 0.10374   ;   zrgb(3,40) = 0.11320   ;   zrgb(4,40) = 0.41502
+      zrgb(1,41) =  1.000   ;   zrgb(2,41) = 0.11114   ;   zrgb(3,41) = 0.11639   ;   zrgb(4,41) = 0.41809
+      zrgb(1,42) =  1.122   ;   zrgb(2,42) = 0.11912   ;   zrgb(3,42) = 0.11984   ;   zrgb(4,42) = 0.42142
+      zrgb(1,43) =  1.259   ;   zrgb(2,43) = 0.12775   ;   zrgb(3,43) = 0.12356   ;   zrgb(4,43) = 0.42500
+      zrgb(1,44) =  1.413   ;   zrgb(2,44) = 0.13707   ;   zrgb(3,44) = 0.12757   ;   zrgb(4,44) = 0.42887
+      zrgb(1,45) =  1.585   ;   zrgb(2,45) = 0.14715   ;   zrgb(3,45) = 0.13189   ;   zrgb(4,45) = 0.43304
+      zrgb(1,46) =  1.778   ;   zrgb(2,46) = 0.15803   ;   zrgb(3,46) = 0.13655   ;   zrgb(4,46) = 0.43754
+      zrgb(1,47) =  1.995   ;   zrgb(2,47) = 0.16978   ;   zrgb(3,47) = 0.14158   ;   zrgb(4,47) = 0.44240
+      zrgb(1,48) =  2.239   ;   zrgb(2,48) = 0.18248   ;   zrgb(3,48) = 0.14701   ;   zrgb(4,48) = 0.44765
+      zrgb(1,49) =  2.512   ;   zrgb(2,49) = 0.19620   ;   zrgb(3,49) = 0.15286   ;   zrgb(4,49) = 0.45331
+      zrgb(1,50) =  2.818   ;   zrgb(2,50) = 0.21102   ;   zrgb(3,50) = 0.15918   ;   zrgb(4,50) = 0.45942
+      zrgb(1,51) =  3.162   ;   zrgb(2,51) = 0.22703   ;   zrgb(3,51) = 0.16599   ;   zrgb(4,51) = 0.46601
+      zrgb(1,52) =  3.548   ;   zrgb(2,52) = 0.24433   ;   zrgb(3,52) = 0.17334   ;   zrgb(4,52) = 0.47313
+      zrgb(1,53) =  3.981   ;   zrgb(2,53) = 0.26301   ;   zrgb(3,53) = 0.18126   ;   zrgb(4,54) = 0.48080
+      zrgb(1,54) =  4.467   ;   zrgb(2,54) = 0.28320   ;   zrgb(3,54) = 0.18981   ;   zrgb(4,55) = 0.48909
+      zrgb(1,55) =  5.012   ;   zrgb(2,55) = 0.30502   ;   zrgb(3,55) = 0.19903   ;   zrgb(4,56) = 0.49803
+      zrgb(1,56) =  5.623   ;   zrgb(2,56) = 0.32858   ;   zrgb(3,56) = 0.20898   ;   zrgb(4,57) = 0.50768
+      zrgb(1,57) =  6.310   ;   zrgb(2,57) = 0.35404   ;   zrgb(3,57) = 0.21971   ;   zrgb(4,58) = 0.51810
+      zrgb(1,58) =  7.079   ;   zrgb(2,58) = 0.38154   ;   zrgb(3,58) = 0.23129   ;   zrgb(4,59) = 0.52934
+      zrgb(1,59) =  7.943   ;   zrgb(2,59) = 0.41125   ;   zrgb(3,59) = 0.24378   ;   zrgb(4,50) = 0.54147
+      zrgb(1,60) =  8.912   ;   zrgb(2,60) = 0.44336   ;   zrgb(3,60) = 0.25725   ;   zrgb(4,60) = 0.55457
+      zrgb(1,61) = 10.000   ;   zrgb(2,61) = 0.47804   ;   zrgb(3,61) = 0.27178   ;   zrgb(4,61) = 0.56870
+      !
+      prgb(:,:) = zrgb(2:4,:)
+      !
+      DO jc = 1, 61                         ! check
+         zchl = zrgb(1,jc)
+         irgb = NINT( 41 + 20.* LOG10( zchl ) + 1.e-15 )
+         IF(lwp) WRITE(numout,*) '    jc =', jc, '  Chl = ', zchl, '  irgb = ', irgb
+         IF( irgb /= jc ) THEN
+            IF(lwp) WRITE(numout,*) '    jc =', jc, '  Chl = ', zchl, '  Chl class = ', irgb
+            CALL ctl_stop( 'trc_oce_rgb : inconsistency in Chl tabulated attenuation coeff.' )
+         ENDIF
+      END DO
+      !
+   END SUBROUTINE trc_oce_rgb
+
+
+   SUBROUTINE trc_oce_rgb_read( prgb )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE p4z_opt_init  ***
+      !!
+      !! ** Purpose :   Initialization of of the optical scheme
+      !!
+      !! ** Method  :   read the look up table for the optical coefficients
+      !!
+      !! ** input   :   xkrgb(61) precomputed array corresponding to the  
+      !!                          attenuation coefficient (from JM Andre)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(3,61), INTENT(inout) ::   prgb   ! tabulated attenuation coefficient
+      !!
+      INTEGER  ::   jchl, jband   ! dummy loop indices
+      INTEGER  ::   numlight
+      REAL(wp) ::   ztoto
+      CHARACTER(LEN=20) :: clname
+      !!----------------------------------------------------------------------
+      !
+      clname = 'kRGB61.txt' 
+      CALL ctlopn( numlight, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL', 1, numout, .TRUE., 1 )
+      DO jchl = 1, 61
+         READ(numlight,*) ztoto, ( prgb(jband,jchl), jband=1,3 )
+      END DO
+      CLOSE( numlight )
+      !
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trc_oce_rgb_read : optical look-up table read in kRGB61.txt file'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+      ENDIF
+      !
+   END SUBROUTINE trc_oce_rgb_read
+
+
+   FUNCTION trc_oce_ext_lev( prldex, pqsr_frc ) RESULT( pjl )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE trc_oce_ext_lev  ***
+      !!       
+      !! ** Purpose :   compute max. level for light penetration
+      !!          
+      !! ** Method  :   the function provides the level at which irradiance 
+      !!                becomes negligible (i.e. = 1.e-15 W/m2) for 3 or 2 bands light
+      !!                penetration: I(z) = pqsr_frc * EXP(hext/prldex) = 1.e-15 W/m2
+      !!                # prldex is the longest depth of extinction:
+      !!                   - prldex = 23 m (2 bands case)
+      !!                   - prldex = 62 m (3 bands case: blue waveband & 0.01 mg/m2 for the chlorophyll)
+      !!                # pqsr_frc is the fraction of solar radiation which penetrates,
+      !!                considering Qsr=240 W/m2 and rn_abs = 0.58:
+      !!                   - pqsr_frc = Qsr * (1-rn_abs)   = 1.00e2 W/m2 (2 bands case)
+      !!                   - pqsr_frc = Qsr * (1-rn_abs)/3 = 0.33e2 W/m2 (3 bands case & equi-partition)
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in) ::   prldex    ! longest depth of extinction
+      REAL(wp), INTENT(in) ::   pqsr_frc  ! frac. solar radiation which penetrates 
+      !!
+      INTEGER  ::   jk, pjl            ! levels
+      REAL(wp) ::   zhext              ! deepest level till which light penetrates
+      REAL(wp) ::   zprec = 15._wp     ! precision to reach -LOG10(1.e-15)
+      REAL(wp) ::   zem                ! temporary scalar 
+      !!----------------------------------------------------------------------
+      !
+      ! It is not necessary to compute anything bellow the following depth
+      zhext = prldex * ( LOG(10.e0) * zprec + LOG(pqsr_frc) )
+     
+      ! Level of light extinction
+      pjl = jpkm1
+      DO jk = jpkm1, 1, -1
+         zem = MAXVAL( fsdepw(:,:,jk+1) * tmask(:,:,jk) )
+         IF( zem >= zhext )   pjl = jk                       ! last T-level reached by Qsr
+      END DO
+      !
+   END FUNCTION trc_oce_ext_lev
+
+
+   !!======================================================================
 END MODULE trc_oce
