Index: branches/UKMO/AMM15_v3_6_STABLE_package_collate_utils366_fabmv1_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- branches/UKMO/AMM15_v3_6_STABLE_package_collate_utils366_fabmv1_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 13489)
+++ branches/UKMO/AMM15_v3_6_STABLE_package_collate_utils366_fabmv1_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 13496)
@@ -32,4 +32,8 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
+#if defined key_fabm
+   USE trc, ONLY: trn  ! FABM variables
+   USE par_fabm        ! FABM parameters
+#endif
 
    IMPLICIT NONE
@@ -107,4 +111,5 @@
       REAL(wp) ::   zz0, zz1, z1_e3t     !    -         -
       REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zekb_3d, zekg_3d, zekr_3d
       REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea, ztrdt
       !!----------------------------------------------------------------------
@@ -114,4 +119,5 @@
       CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
       CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
+      CALL wrk_alloc( jpi, jpj, jpk, zekb_3d, zekg_3d, zekr_3d )  
       !
       IF( kt == nit000 ) THEN
@@ -215,7 +221,25 @@
             !                                             ! ------------------------- !
             ! Set chlorophyl concentration
-            IF( nn_chldta == 1 .OR. lk_vvl ) THEN            !*  Variable Chlorophyll or ocean volume
-               !
-               IF( nn_chldta == 1 ) THEN                             !*  Variable Chlorophyll
+            IF( nn_chldta == 2 .OR. nn_chldta == 1 .OR. lk_vvl ) THEN   !*  Variable Chlorophyll or ocean volume
+               !
+               IF( nn_chldta == 2 ) THEN
+                  DO jk = 1, nksr+1
+                     DO jj = 1, jpj
+                        DO ji = 1, jpi
+#if defined key_fabm
+                           zchl = trn(ji,jj,jk,jp_fabm_m1+jp_fabm_chl1) + trn(ji,jj,jk,jp_fabm_m1+jp_fabm_chl2) + &
+                              &   trn(ji,jj,jk,jp_fabm_m1+jp_fabm_chl3) + trn(ji,jj,jk,jp_fabm_m1+jp_fabm_chl4)
+#endif
+                           zchl = MIN(  10. , MAX( 0.03, zchl )  )
+                           irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+                           !                                                         
+                           zekb_3d(ji,jj,jk) = rkrgb(1,irgb)
+                           zekg_3d(ji,jj,jk) = rkrgb(2,irgb)
+                           zekr_3d(ji,jj,jk) = rkrgb(3,irgb)
+                        END DO
+                     END DO
+                  END DO
+                  !
+               ELSEIF( nn_chldta == 1 ) THEN                             !*  Variable Chlorophyll
                   !
                   CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
@@ -249,4 +273,9 @@
                !
                DO jk = 2, nksr+1
+                  IF( nn_chldta == 2 ) THEN
+                     zekb(:,:) = zekb_3d(:,:,jk)
+                     zekg(:,:) = zekg_3d(:,:,jk)
+                     zekr(:,:) = zekr_3d(:,:,jk)
+                  ENDIF
 !CDIR NOVERRCHK
                   DO jj = 1, jpj
@@ -267,4 +296,9 @@
                ! clem: store attenuation coefficient of the first ocean level
                IF ( ln_qsr_ice ) THEN
+                  IF( nn_chldta == 2 ) THEN
+                     zekb(:,:) = zekb_3d(:,:,1)
+                     zekg(:,:) = zekg_3d(:,:,1)
+                     zekr(:,:) = zekr_3d(:,:,1)
+                  ENDIF
                   DO jj = 1, jpj
                      DO ji = 1, jpi
@@ -416,4 +450,5 @@
       CALL wrk_dealloc( jpi, jpj,      zekb, zekg, zekr        ) 
       CALL wrk_dealloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
+      CALL wrk_dealloc( jpi, jpj, jpk, zekb_3d, zekg_3d, zekr_3d ) 
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_qsr')
@@ -483,5 +518,5 @@
          WRITE(numout,*) '      ERSEM spectral heating model             ln_qsr_spec= ', ln_qsr_spec
          WRITE(numout,*) '      light penetration for ice-model LIM3     ln_qsr_ice = ', ln_qsr_ice
-         WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)    nn_chldta  = ', nn_chldta
+         WRITE(numout,*) '      RGB: model (2), file (1) or cst (0) chl   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
@@ -510,21 +545,26 @@
          IF( ln_qsr_rgb .AND. nn_chldta == 0 )   nqsr =  1 
          IF( ln_qsr_rgb .AND. nn_chldta == 1 )   nqsr =  2
-         IF( ln_qsr_2bd                      )   nqsr =  3
-         IF( ln_qsr_bio                      )   nqsr =  4
-         IF( nn_kd490dta == 1                )   nqsr =  5
-         IF( ln_qsr_spec                     )   nqsr =  6
+         IF( ln_qsr_rgb .AND. nn_chldta == 2 )   nqsr =  3
+         IF( ln_qsr_2bd                      )   nqsr =  4
+         IF( ln_qsr_bio                      )   nqsr =  5
+         IF( nn_kd490dta == 1                )   nqsr =  6
+         IF( ln_qsr_spec                     )   nqsr =  7
          !
          IF(lwp) THEN                   ! Print the choice
             WRITE(numout,*)
             IF( nqsr ==  1 )   WRITE(numout,*) '         R-G-B   light penetration - Constant Chlorophyll'
-            IF( nqsr ==  2 )   WRITE(numout,*) '         R-G-B   light penetration - Chl data '
-            IF( nqsr ==  3 )   WRITE(numout,*) '         2 bands light penetration'
-            IF( nqsr ==  4 )   WRITE(numout,*) '         bio-model light penetration'
-            IF( nqsr ==  5 )   WRITE(numout,*) '         KD490 light penetration'
-            IF( nqsr ==  6 )   WRITE(numout,*) '         ERSEM spectral light penetration'
+            IF( nqsr ==  2 )   WRITE(numout,*) '         R-G-B   light penetration - Chl data from file'
+            IF( nqsr ==  3 )   WRITE(numout,*) '         R-G-B   light penetration - Chl data from model'
+            IF( nqsr ==  4 )   WRITE(numout,*) '         2 bands light penetration'
+            IF( nqsr ==  5 )   WRITE(numout,*) '         bio-model light penetration'
+            IF( nqsr ==  6 )   WRITE(numout,*) '         KD490 light penetration'
+            IF( nqsr ==  7 )   WRITE(numout,*) '         ERSEM spectral light penetration'
          ENDIF
 #if ! defined key_fabm
          !
-         IF( nqsr ==  6 ) THEN
+         IF( nqsr ==  2 ) THEN
+            CALL ctl_stop( 'nn_chldta=2 so trying to use ERSEM chlorophyll for light penetration', &
+               &           'but not running with ERSEM' )
+         ELSEIF( nqsr ==  7 ) THEN
             CALL ctl_stop( 'ln_qsr_spec=.true. so trying to use ERSEM spectral light penetration', &
                &           'but not running with ERSEM' )
@@ -577,4 +617,7 @@
                   &                                         'Solar penetration function of read chlorophyll', 'namtra_qsr' )
                !
+            ELSEIF( nn_chldta == 2 ) THEN       !* Chl data will be got from model at each time step
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '        Chlorophyll will be taken from model at each time step'
             ELSE                                !* constant Chl : compute once for all the distribution of light (etot3)
                IF(lwp) WRITE(numout,*)
