Index: branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 8053)
+++ branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 8105)
@@ -16,4 +16,5 @@
    !!----------------------------------------------------------------------
    !! * Modules used   
+   USE trc,         ONLY: trn            ! ERSEM state variables
    USE wrk_nemo                 ! Memory Allocation
    USE par_kind                 ! Precision variables
@@ -92,4 +93,40 @@
    LOGICAL, PUBLIC :: ln_logchl      !: Logical switch for log10(chlorophyll)
    LOGICAL, PUBLIC :: ln_logchlfb    !: Logical switch for logchl from feedback files
+
+
+
+
+
+
+
+
+
+
+
+! JOZEF ADDITION
+
+
+   LOGICAL, PUBLIC :: ln_logchlpft      !: Logical switch for log10(chlorophyll) PFTs
+   LOGICAL, PUBLIC :: ln_logchlpftfb    !: Logical switch for logchl PFTs from feedback files
+
+   INTEGER, PUBLIC :: nn_logchlpftscc = 4 ! Number of logchl PFTs
+
+
+
+! END
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    LOGICAL, PUBLIC :: ln_spm         !: Logical switch for spm
    LOGICAL, PUBLIC :: ln_spmfb       !: Logical switch for spm from feedback files
@@ -117,4 +154,8 @@
 
    INTEGER, PARAMETER :: MaxNumFiles = 1000
+   
+
+   
+  
    LOGICAL, DIMENSION(MaxNumFiles) :: &
       & ln_profb_ena, & !: Is the feedback files from ENACT data ?
@@ -163,4 +204,5 @@
       IMPLICIT NONE
 
+     
       !! * Local declarations
       CHARACTER(len=128) :: enactfiles(MaxNumFiles)
@@ -183,4 +225,27 @@
       CHARACTER(len=128) :: logchlfiles(MaxNumFiles)
       CHARACTER(len=128) :: logchlfbfiles(MaxNumFiles)
+
+
+
+
+
+! JOZEF ADDITION
+
+
+
+      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: logchlpftfiles
+      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: logchlpftfbfiles
+
+ !      CHARACTER(len=128) :: logchlpftfiles(MaxNumFiles, nn_logchlpftscc)
+ !      CHARACTER(len=128) :: logchlpftfbfiles(MaxNumFiles, nn_logchlpftscc)
+
+! END
+
+
+
+
+
+
+
       CHARACTER(len=128) :: spmfiles(MaxNumFiles)
       CHARACTER(len=128) :: spmfbfiles(MaxNumFiles)
@@ -216,4 +281,17 @@
          &            ln_logchl, ln_logchlfb,                         &
          &            logchlfiles, logchlfbfiles,                     &
+
+
+
+! JOZEF ADDITION
+
+         &            ln_logchlpft, ln_logchlpftfb,                     &
+         &          logchlpftfiles, logchlpftfbfiles,                   &
+
+! END
+
+
+
+
          &            ln_spm, ln_spmfb,                               &
          &            spmfiles, spmfbfiles,                           &
@@ -245,4 +323,24 @@
       INTEGER :: jnumlogchl
       INTEGER :: jnumlogchlfb
+      
+
+      
+
+! JOZEF ADDITION
+ !     INTEGER :: nn_logchlpftscc
+
+  !    INTEGER, DIMENSION(:), ALLOCATABLE :: jnumlogchlpft
+  !    INTEGER, DIMENSION(:), ALLOCATABLE :: jnumlogchlpftfb
+
+     INTEGER :: jnumlogchlpft(nn_logchlpftscc)
+     INTEGER :: jnumlogchlpftfb(nn_logchlpftscc)
+
+
+! END
+
+
+
+
+
       INTEGER :: jnumspm
       INTEGER :: jnumspmfb
@@ -256,4 +354,13 @@
       LOGICAL :: lmask(MaxNumFiles), ll_u3d, ll_v3d
 
+
+      ! JOZEF ADDITION
+
+      INTEGER :: pft
+
+      !END
+
+
+
       !-----------------------------------------------------------------------
       ! Read namelist parameters
@@ -262,4 +369,30 @@
       ln_logchl   = .FALSE.
       ln_logchlfb = .FALSE.
+
+
+
+
+
+
+   ! JOZEF ADDITION
+      ln_logchlpft   = .FALSE.
+      ln_logchlpftfb = .FALSE.
+
+  !    #if defined key_fabm
+  !     nn_logchlpftscc = 4
+  !    #elif defined key_medusa
+  !     nn_logchlpftscc = 2
+  !    #elif defined key_hadocc
+  !     nn_logchlpftscc = 1
+  !    #else
+  !     nn_logchlpftscc = 0
+  !    #fi
+   
+   ! END
+
+
+
+
+
       ln_spm      = .FALSE.
       ln_spmfb    = .FALSE.
@@ -290,4 +423,25 @@
       logchlfiles(:) = ''
       logchlfbfiles(:) = ''
+
+
+
+
+! JOZEF ADDITION
+
+      ALLOCATE(logchlpftfiles(MaxNumFiles, nn_logchlpftscc))
+      ALLOCATE(logchlpftfbfiles(MaxNumFiles, nn_logchlpftscc))
+
+      DO pft = 1,nn_logchlpftscc
+      logchlpftfiles(:,pft) = ''
+      logchlpftfbfiles(:,pft) = ''
+      END DO
+! END
+
+
+
+
+
+
+
       spmfiles(:) = ''
       spmfbfiles(:) = ''
@@ -406,4 +560,46 @@
          jnumlogchlfb = COUNT(lmask)
       ENDIF
+
+
+
+
+
+
+
+
+
+
+! JOZEF ADDITION
+
+     DO pft=1,nn_logchlpftscc
+
+     IF (ln_logchlpft) THEN
+
+         lmask(:) = .FALSE.
+         WHERE (logchlpftfiles(:,pft) /= '') lmask(:) = .TRUE.
+         jnumlogchlpft(pft) = COUNT(lmask)
+
+      ENDIF
+      IF (ln_logchlpftfb) THEN
+         lmask(:) = .FALSE.
+         WHERE (logchlpftfbfiles(:,pft) /= '') lmask(:) = .TRUE.
+         jnumlogchlpftfb(pft) = COUNT(lmask)
+       
+
+      ENDIF
+
+      !WRITE(numout,*)'jnumlogchlpftfb is', jnumlogchlpftfbfiles(:,pft)
+
+    END DO
+! END
+
+
+
+WRITE(numout,*)'jnumlogchlpftfb is', logchlpftfbfiles
+
+
+
+
+
       IF (ln_spm) THEN
          lmask(:) = .FALSE.
@@ -468,4 +664,20 @@
          WRITE(numout,*) '             Logical switch for logchl observations          ln_logchl = ', ln_logchl
          WRITE(numout,*) '             Logical switch for feedback logchl data       ln_logchlfb = ', ln_logchlfb
+
+
+
+
+
+! JOZEF ADDITION
+
+         WRITE(numout,*) '             Logical switch for logchlpft observations          ln_logchlpft = ', ln_logchlpft
+         WRITE(numout,*) '             Logical switch for feedback logchlpft data       ln_logchlpftfb = ', ln_logchlpftfb
+
+! END
+
+
+
+
+
          WRITE(numout,*) '             Logical switch for spm observations                ln_spm = ', ln_spm
          WRITE(numout,*) '             Logical switch for feedback spm data             ln_spmfb = ', ln_spmfb
@@ -572,4 +784,6 @@
             END DO
          ENDIF
+
+
          IF (ln_logchl) THEN
             DO ji = 1, jnumlogchl
@@ -584,4 +798,44 @@
             END DO
          ENDIF
+
+
+
+    
+
+! JOZEF ADDITION
+
+          IF (ln_logchlpft) THEN
+         
+            DO pft=1,nn_logchlpftscc
+
+            DO ji = 1, jnumlogchlpft(pft)
+               WRITE(numout,'(1X,2A)') '             logchlpft input observation file name        logchlfiles = ', &
+                  TRIM(logchlpftfiles(ji,pft))
+            END DO
+            END DO
+         ENDIF
+         IF (ln_logchlpftfb) THEN
+
+            DO pft=1,nn_logchlpftscc
+
+            DO ji = 1, jnumlogchlpftfb(pft)
+               WRITE(numout,'(1X,2A)') '        Feedback logchlpft input observation file name  logchlfbfiles = ', &
+                  TRIM(logchlpftfbfiles(ji,pft))
+            END DO
+            END DO
+
+           
+         ENDIF
+
+
+!END
+
+
+
+
+
+
+
+
          IF (ln_spm) THEN
             DO ji = 1, jnumspm
@@ -1182,4 +1436,9 @@
          nlogchlsets = 0
 
+
+
+
+
+
          IF ( ln_logchlfb ) THEN             ! Feedback file format
 
@@ -1212,5 +1471,116 @@
          ENDIF
  
-      ENDIF
+         ENDIF
+     
+
+
+
+
+
+
+
+
+
+! JOZEF ADDITION
+
+
+ IF ( ln_logchlpft ) THEN
+
+         ! Set the number of variables for logchl to 1
+         nlogchlpftvars = 1   ! ??????? ASK DAVID
+
+         ! Set the number of extra variables for logchl to 0
+         nlogchlpftextr = 0
+         
+         DO pft = 1, nn_logchlpftscc 
+
+
+
+         IF ( ln_logchlpftfb ) THEN
+            nlogchlpftsets = jnumlogchlpftfb(pft)
+         ELSE
+            nlogchlpftsets = 1
+         ENDIF
+
+
+
+         END DO
+
+         ALLOCATE(logchlpftdata(nn_logchlpftscc)) 
+         ALLOCATE(logchlpftdatqc(nn_logchlpftscc))
+         
+
+
+         DO pft = 1, nn_logchlpftscc
+
+         logchlpftdata(pft)%nsurf=0
+         logchlpftdatqc(pft)%nsurf=0
+
+         nlogchlpftsets = 0
+
+         WRITE(numout,*)'jnumlogchlpftfb is', jnumlogchlpftfb, ln_logchlpftfb
+
+         IF ( ln_logchlpftfb ) THEN             ! Feedback file format
+
+            DO jset = 1, jnumlogchlpftfb(pft)
+            
+               nlogchlpftsets = nlogchlpftsets + 1
+
+               CALL obs_rea_logchl( 0, logchlpftdata(pft), 1, &
+                  &                 logchlpftfbfiles(jset:jset,pft), &
+                  &                 nlogchlpftvars, nlogchlpftextr, nitend-nit000+2, &
+                  &                 dobsini, dobsend, ln_ignmis, .FALSE. )
+
+               CALL obs_pre_logchl( logchlpftdata(pft), logchlpftdatqc(pft), &
+                  &                 ln_logchlpft, ln_nea )
+            
+            ENDDO
+
+         ELSE                              ! Original file format
+
+            nlogchlpftsets = 1
+
+            CALL obs_rea_logchl( 1, logchlpftdata(pft), jnumlogchlpft(pft), &
+               &                 logchlpftfiles(1:jnumlogchlpft(pft),pft), &
+               &                 nlogchlpftvars, nlogchlpftextr, nitend-nit000+2, &
+               &                 dobsini, dobsend, ln_ignmis, .FALSE. )
+
+            CALL obs_pre_logchl( logchlpftdata(pft), logchlpftdatqc(pft), &
+               &                 ln_logchlpft, ln_nea )
+
+         ENDIF
+ 
+       ENDDO
+
+
+
+
+
+      ENDIF
+
+
+nlogchlpftsets = 1   ! THIS SPECIAL CASE NEEDS TO BE GENERALIZED LATER
+
+WRITE(numout,*)'Producing nlogchlpftsets', nlogchlpftsets
+
+! END
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
       !  - spm
@@ -1423,6 +1793,5 @@
          & tmask, umask, vmask                            
       USE phycst, ONLY : &              ! Physical constants
-         & rday, &
-         & rt0
+         & rday                         
       USE oce, ONLY : &                 ! Ocean dynamics and tracers variables
          & tsn,  &             
@@ -1456,6 +1825,4 @@
       USE par_spm, ONLY: &              ! ERSEM/SPM sediments
          & jp_spm
-      USE trc, ONLY :  &
-         & trn
 #endif
       IMPLICIT NONE
@@ -1481,4 +1848,27 @@
       REAL(wp), DIMENSION(jpi,jpj) :: &
          logchl                         ! array for log chlorophyll
+
+
+
+
+
+
+
+! JOZEF ADDITION
+
+
+      REAL(wp), DIMENSION(jpi,jpj,nn_logchlpftscc) :: &
+         logchlpfts
+
+
+! END
+
+
+
+
+
+
+
+                         ! array for log chlorophyll pfts
       REAL(wp), DIMENSION(jpi,jpj) :: &
          maskchl                        ! array for special chlorophyll mask
@@ -1496,6 +1886,27 @@
 #if defined key_fabm
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: logchl_3d
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: pco2_3d
+
+
+
+
+
+
+     
+      ! JOZEF ADDITION
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk,nn_logchlpftscc) :: logchlpfts_3d
 #endif
+
+      INTEGER :: pft
+      ! END
+
+
+
+
+
+
+
+
+
       CHARACTER(LEN=20) :: datestr=" ",timestr=" "
  
@@ -1639,4 +2050,99 @@
       ENDIF 
 
+
+
+
+
+
+
+
+
+! JOZEF ADDITION
+
+
+
+IF ( ln_logchlpft ) THEN
+
+#if defined key_hadocc
+         logchl(:,:) = HADOCC_CHL(:,:,1)    ! (not log) chlorophyll from HadOCC
+#elif defined key_medusa && defined key_foam_medusa
+         logchl(:,:) = MEDUSA_CHL(:,:,1)    ! (not log) chlorophyll from HadOCC
+#elif defined key_fabm
+         logchlpfts_3d(:,:,:,1) = trn(:,:,:,jp_fabm_m1+jp_fabm_chl1)
+         logchlpfts(:,:,1) = logchlpfts_3d(:,:,1,1)
+         logchlpfts_3d(:,:,:,2) = trn(:,:,:,jp_fabm_m1+jp_fabm_chl2)
+         logchlpfts(:,:,2) = logchlpfts_3d(:,:,1,2)
+         logchlpfts_3d(:,:,:,3) = trn(:,:,:,jp_fabm_m1+jp_fabm_chl3)
+         logchlpfts(:,:,3) = logchlpfts_3d(:,:,1,3)
+         logchlpfts_3d(:,:,:,4) = trn(:,:,:,jp_fabm_m1+jp_fabm_chl4)
+         logchlpfts(:,:,4) = logchlpfts_3d(:,:,1,4)
+#else
+         CALL ctl_stop( ' Trying to run logchl observation operator', &
+            &           ' but no biogeochemical model appears to have been defined' )
+#endif
+
+                  ! create a special mask to exclude certain things
+
+         ! Take the log10 where we can, otherwise exclude
+         tiny = 1.0e-20
+
+         DO pft=1,nn_logchlpftscc
+
+         maskchl(:,:) = tmask(:,:,1)
+
+         WRITE(numout,*) 'Running pft: ',pft
+
+         WHERE(logchlpfts(:,:,pft) > tiny .AND. logchlpfts(:,:,pft) /= obfillflt )
+            logchlpfts(:,:,pft)  = LOG10(logchlpfts(:,:,pft))
+         ELSEWHERE
+            logchlpfts(:,:,pft)  = obfillflt
+            maskchl(:,:) = 0
+         END WHERE
+
+         WRITE(numout,*) 'Max value of Pft: ', MINVAL(logchlpfts(:,:,pft))
+
+         DO jlogchlset = 1, nlogchlpftsets
+             WRITE(numout,*) 'nlogchlpftsets, nn_logchlpftscc, obfillflt = ', nlogchlpftsets, nn_logchlpftscc, obfillflt
+             WRITE(numout,*) 'kstp, jpi, jpj, nit000, n2dint = ', kstp, jpi, jpj, nit000, n2dint
+             !WRITE(numout,*) 'ALLOCATED(logchlpftdatqc) = ', ALLOCATED(logchlpftdatqc)
+             WRITE(numout,*) 'SHAPE(logchlpftdatqc) = ', SHAPE(logchlpftdatqc)
+             WRITE(numout,*) 'SIZE(logchlpftdatqc) = ', SIZE(logchlpftdatqc)
+             !WRITE(numout,*) 'ALLOCATED(logchlpfts) = ', ALLOCATED(logchlpfts) 
+             WRITE(numout,*) 'SHAPE(logchlpfts) = ', SHAPE(logchlpfts)
+             WRITE(numout,*) 'SIZE(logchlpfts) = ', SIZE(logchlpfts)
+             !WRITE(numout,*) 'ALLOCATED(maskchl) = ', ALLOCATED(maskchl)
+             WRITE(numout,*) 'SHAPE(maskchl) = ', SHAPE(maskchl)
+             WRITE(numout,*) 'SIZE(maskchl) = ', SIZE(maskchl)
+             CALL flush(numout)
+             
+             CALL obs_logchl_opt( logchlpftdatqc(pft),             &
+               &                  kstp, jpi, jpj, nit000, logchlpfts(:,:,pft), &
+               &                  maskchl(:,:), n2dint )
+
+             WRITE(numout,*) 'Max value of Pft: ', MINVAL(logchlpfts(:,:,pft))
+         END DO         
+     
+         
+         END DO
+
+        ENDIF
+
+! END
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
       IF ( ln_spm ) THEN
 #if defined key_spm
@@ -1787,4 +2293,5 @@
       CHARACTER(LEN=20) :: datestr=" ",timestr=" "
       CHARACTER(LEN=20) :: cdtmp
+      INTEGER :: pft
       !-----------------------------------------------------------------------
       ! Depending on switches call various observation output routines
@@ -2058,4 +2565,81 @@
 
       ENDIF
+
+
+
+
+
+
+
+     
+
+
+
+
+
+
+
+
+! JOZEF ADDITION 
+
+ IF ( ln_logchlpft ) THEN
+
+         WRITE(numout,*)'Pfts loop started'
+         WRITE(numout,*)'nlogchlpftsets', nlogchlpftsets
+
+         DO pft = 1, nn_logchlpftscc         
+
+         ! Copy data from logchldatqc to logchldata structures
+         DO jlogchlset = 1, nlogchlpftsets
+
+            CALL obs_surf_decompress( logchlpftdatqc(pft), &
+                 &                    logchlpftdata(pft), .TRUE., numout )
+
+         END DO
+         
+         ! Mark as bad observations with no valid model counterpart due to activities in dia_obs
+         ! Seem to need to set to fill value rather than marking as bad to be effective, so do both
+         DO jlogchlset = 1, nlogchlpftsets
+            WHERE ( logchlpftdata(pft)%rmod(:,1) == obfillflt )
+               logchlpftdata(pft)%nqc(:)    = 1
+               logchlpftdata(pft)%robs(:,1) = obfillflt
+            END WHERE
+         END DO
+
+         ! Write the logchl data
+         DO jlogchlset = 1, nlogchlpftsets
+
+            WRITE(numout,*)'Code Pfts here!'
+      
+           ! WRITE(cdtmp,'(A,I2.2)')'logchlpftfb_',jlogchlset
+            WRITE(cdtmp,'(A,I2.2,A,I2.2)')'logchlpft',pft,'fb_',jlogchlset
+            !CALL obs_wri_logchl( cdtmp, logchlpftdata(jlogchlset,pft) )
+            CALL obs_wri_logchl( cdtmp, logchlpftdata(pft), pft_num=jlogchlset )
+
+         END DO
+
+         END DO
+
+      ENDIF
+
+! END
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
       !  - spm
Index: branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_logchl.F90
===================================================================
--- branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_logchl.F90	(revision 8053)
+++ branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_logchl.F90	(revision 8105)
@@ -22,14 +22,24 @@
    PRIVATE
 
-   PUBLIC nlogchlvars, nlogchlextr, nlogchlsets, logchldata, logchldatqc
+   PUBLIC nlogchlvars, nlogchlpftvars, nlogchlextr, nlogchlpftextr, nlogchlsets, nlogchlpftsets, logchldata, logchldatqc, logchlpftdata, logchlpftdatqc, nn_logchlpfts
 
    !! * Shared Module variables
+   INTEGER :: nn_logchlpfts
+
    INTEGER :: nlogchlvars                               ! Number of logchldata variables
    INTEGER :: nlogchlextr                               ! Number of logchldata extra 
-                                                        ! variables
-   INTEGER :: nlogchlsets                               ! Number of logchldata sets
+                   
+   INTEGER :: nlogchlpftvars                               ! Number of logchldata variables
+   INTEGER :: nlogchlpftextr                               ! Number of logchldata extra
+                                     ! variables
+   INTEGER :: nlogchlsets    
+   INTEGER :: nlogchlpftsets   
+                           ! Number of logchldata sets
    TYPE(obs_surf), POINTER, DIMENSION(:) :: logchldata  ! Initial logchl data
    TYPE(obs_surf), POINTER, DIMENSION(:) :: logchldatqc ! Sea ice data after quality control
 
+   TYPE(obs_surf), POINTER, DIMENSION(:) :: logchlpftdata  ! Initial logchl data
+   TYPE(obs_surf), POINTER, DIMENSION(:) :: logchlpftdatqc 
+
 END MODULE obs_logchl
 
Index: branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 8053)
+++ branches/UKMO/dev_r4650_general_vert_coord_obsoper_pfts/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 8105)
@@ -938,5 +938,6 @@
    END SUBROUTINE obs_wri_vel
 
-   SUBROUTINE obs_wri_logchl( cprefix, logchldata, padd, pext )
+  ! SUBROUTINE obs_wri_logchl( cprefix, logchldata, padd, pext )
+   SUBROUTINE obs_wri_logchl( cprefix, logchldata, padd, pext, pft_num )
       !!-----------------------------------------------------------------------
       !!
@@ -970,4 +971,5 @@
       INTEGER :: nadd
       INTEGER :: next
+      INTEGER, OPTIONAL :: pft_num
 
       IF ( PRESENT( padd ) ) THEN
@@ -988,5 +990,11 @@
          &                 1 + nadd, next, .TRUE. )
 
-      fbdata%cname(1)      = 'LOGCHL'
+      !fbdata%cname(1)      = 'LOGCHL'
+      IF ( PRESENT( pft_num ) ) THEN
+      WRITE(fbdata%cname(1),'(A,I2.2)')'LOGCHL',pft_num
+      ELSE
+          fbdata%cname(1)      = 'LOGCHL'
+      ENDIF
+
       fbdata%coblong(1)    = 'logchl concentration'
       fbdata%cobunit(1)    = 'mg/m3'
