Index: /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4708)
+++ /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4709)
@@ -982,4 +982,5 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+   nn_diacfl   =    0      !  Write out cfl diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 4708)
+++ /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 4709)
@@ -5,7 +5,6 @@
    !!==============================================================================
    !! History :  1.0  !  2010-03  (E. Blockley)  Original code
+   !!                 !  2014-06  (T Graham) Removed CPP key & Updated to vn3.6
    !! 
-   !!----------------------------------------------------------------------
-#if defined key_diacfl
    !!----------------------------------------------------------------------
    !!   dia_cfl        : Compute and output Courant numbers at each timestep
@@ -16,12 +15,15 @@
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
    USE in_out_manager  ! I/O manager
-   USE domvvl
+   USE domvvl     
+   USE timing          ! Performance output
 
    IMPLICIT NONE
    PRIVATE
 
-   LOGICAL, PUBLIC, PARAMETER   ::   lk_diacfl = .TRUE.    ! CFL diag flag
-   REAL(wp) :: cu_max, cv_max, cw_max                      ! daily max U Courant number 
-   INTEGER, DIMENSION(3) :: cu_loc, cv_loc, cw_loc         ! daily max locations
+   REAL(wp) :: cu_max, cv_max, cw_max                      ! Run max U Courant number 
+   INTEGER, DIMENSION(3) :: cu_loc, cv_loc, cw_loc         ! Run max locations
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcu_cfl           ! Courant number arrays
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcv_cfl           ! Courant number arrays
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcw_cfl           ! Courant number arrays
 
    INTEGER  :: numcfl                                       ! outfile unit
@@ -29,4 +31,5 @@
 
    PUBLIC   dia_cfl       ! routine called by step.F90
+   PUBLIC   dia_cfl_init  ! routine called by nemogcm
 
    !! * Substitutions
@@ -53,7 +56,4 @@
       INTEGER, INTENT(in) ::  kt                            ! ocean time-step index
 
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zcu_cfl           ! Courant number arrays
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zcv_cfl           !     "     "     "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zcw_cfl           !     "     "     "
       REAL(wp) :: zcu_max, zcv_max, zcw_max                 ! max Courant numbers per timestep
       INTEGER, DIMENSION(3) :: zcu_loc, zcv_loc, zcw_loc    ! max Courant number locations
@@ -63,9 +63,127 @@
       INTEGER  :: ji, jj, jk                                ! dummy loop indices
 
-
-      IF( kt == nit000  ) THEN
+      
+      IF( nn_diacfl == 1) THEN
+         IF( nn_timing == 1 )   CALL timing_start('dia_cfl')
+         ! setup timestep multiplier to account for initial Eulerian timestep
+         IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    dt = rdt
+         ELSE                                        ;    dt = rdt * 2.0
+         ENDIF
+
+             ! calculate Courant numbers
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, fs_jpim1   ! vector opt.
+
+                  ! Courant number for x-direction (zonal current)
+                  zcu_cfl(ji,jj,jk) = ABS(un(ji,jj,jk))*dt/e1u(ji,jj)
+
+                  ! Courant number for y-direction (meridional current)
+                  zcv_cfl(ji,jj,jk) = ABS(vn(ji,jj,jk))*dt/e2v(ji,jj)
+
+                  ! Courant number for z-direction (vertical current)
+                  zcw_cfl(ji,jj,jk) = ABS(wn(ji,jj,jk))*dt/fse3w_n(ji,jj,jk)
+               END DO
+            END DO         
+         END DO
+         CALL lbc_lnk( zcu_cfl(:,:,:), 'U', 1. )
+         CALL lbc_lnk( zcv_cfl(:,:,:), 'V', 1. )
+         CALL lbc_lnk( zcw_cfl(:,:,:), 'W', 1. )
+
+         ! calculate maximum values and locations
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(zcu_cfl,umask,zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3))
+            CALL mpp_maxloc(zcv_cfl,vmask,zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3))
+            CALL mpp_maxloc(zcw_cfl,tmask,zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3))
+         ELSE
+            zlocu = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
+            zcu_loc(1) = zlocu(1) + nimpp - 1
+            zcu_loc(2) = zlocu(2) + njmpp - 1
+            zcu_loc(3) = zlocu(3)
+            zcu_max = zcu_cfl(zcu_loc(1),zcu_loc(2),zcu_loc(3))
+
+            zlocv = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
+            zcv_loc(1) = zlocv(1) + nimpp - 1
+            zcv_loc(2) = zlocv(2) + njmpp - 1
+            zcv_loc(3) = zlocv(3)
+            zcv_max = zcv_cfl(zcv_loc(1),zcv_loc(2),zcv_loc(3))
+
+            zlocw = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
+            zcw_loc(1) = zlocw(1) + nimpp - 1
+            zcw_loc(2) = zlocw(2) + njmpp - 1
+            zcw_loc(3) = zlocw(3)
+            zcw_max = zcw_cfl(zcw_loc(1),zcw_loc(2),zcw_loc(3))
+         ENDIF
+      
+         ! write out to file
+         IF( lwp ) THEN
+            WRITE(numcfl,FMT='(2x,i4,5x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3)
+            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cv', zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3)
+            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cw', zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3)
+         ENDIF
+
+         ! update maximum Courant numbers from whole run if applicable
+         IF( zcu_max > cu_max ) THEN
+            cu_max = zcu_max
+            cu_loc = zcu_loc
+         ENDIF
+         IF( zcv_max > cv_max ) THEN
+            cv_max = zcv_max
+            cv_loc = zcv_loc
+         ENDIF
+         IF( zcw_max > cw_max ) THEN
+            cw_max = zcw_max
+            cw_loc = zcw_loc
+         ENDIF
+
+         ! at end of run output max Cu and Cv and close ascii file
+         IF( kt == nitend .AND. lwp ) THEN
+            ! to ascii file
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', cu_max, cu_loc(1), cu_loc(2), cu_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', cv_max, cv_loc(1), cv_loc(2), cv_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
+            WRITE(numcfl,*) '******************************************'
+            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', cw_max, cw_loc(1), cw_loc(2), cw_loc(3)
+            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
+            CLOSE( numcfl ) 
+
+            ! to ocean output
+            WRITE(numout,*)
+            WRITE(numout,*) 'dia_cfl     : Maximum Courant number information for the run:'
+            WRITE(numout,*) '~~~~~~~~~~~~'
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) = (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) = (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) = (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
+            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
+
+         ENDIF
+
+         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl')
+      ENDIF
+
+   END SUBROUTINE dia_cfl
+
+   SUBROUTINE dia_cfl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_cfl_init  ***
+      !!                   
+      !! ** Purpose :   create output file, initialise arrays
+      !!----------------------------------------------------------------------
+
+
+      IF( nn_diacfl == 1 ) THEN
+         IF( nn_timing == 1 )   CALL timing_start('dia_cfl_init')
+
          cu_max=0.0
          cv_max=0.0
          cw_max=0.0
+
+         ALLOCATE( zcu_cfl(jpi, jpj, jpk), zcv_cfl(jpi, jpj, jpk), zcw_cfl(jpi, jpj, jpk) )
+
          zcu_cfl(:,:,:)=0.0
          zcv_cfl(:,:,:)=0.0
@@ -83,117 +201,10 @@
             WRITE(numcfl,*) '******************************************'
          ENDIF
+
+         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl_init')
+
       ENDIF
 
-      ! setup timestep multiplier to account for initial Eulerian timestep
-      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    dt = rdt
-      ELSE                                        ;    dt = rdt * 2.0
-      ENDIF
-
-      ! calculate Courant numbers
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-
-               ! Courant number for x-direction (zonal current)
-               zcu_cfl(ji,jj,jk) = ABS(un(ji,jj,jk))*dt/e1u(ji,jj)
-
-               ! Courant number for y-direction (meridional current)
-               zcv_cfl(ji,jj,jk) = ABS(vn(ji,jj,jk))*dt/e2v(ji,jj)
-
-               ! Courant number for z-direction (vertical current)
-               zcw_cfl(ji,jj,jk) = ABS(wn(ji,jj,jk))*dt/fse3w_n(ji,jj,jk)
-            END DO
-         END DO         
-      END DO
-      CALL lbc_lnk( zcu_cfl(:,:,:), 'U', 1. )
-      CALL lbc_lnk( zcv_cfl(:,:,:), 'V', 1. )
-      CALL lbc_lnk( zcw_cfl(:,:,:), 'W', 1. )
-
-      ! calculate maximum values and locations
-      IF( lk_mpp ) THEN
-         CALL mpp_maxloc(zcu_cfl,umask,zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3))
-         CALL mpp_maxloc(zcv_cfl,vmask,zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3))
-         CALL mpp_maxloc(zcw_cfl,tmask,zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3))
-      ELSE
-         zlocu = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
-         zcu_loc(1) = zlocu(1) + nimpp - 1
-         zcu_loc(2) = zlocu(2) + njmpp - 1
-         zcu_loc(3) = zlocu(3)
-         zcu_max = zcu_cfl(zcu_loc(1),zcu_loc(2),zcu_loc(3))
-
-         zlocv = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
-         zcv_loc(1) = zlocv(1) + nimpp - 1
-         zcv_loc(2) = zlocv(2) + njmpp - 1
-         zcv_loc(3) = zlocv(3)
-         zcv_max = zcv_cfl(zcv_loc(1),zcv_loc(2),zcv_loc(3))
-
-         zlocw = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
-         zcw_loc(1) = zlocw(1) + nimpp - 1
-         zcw_loc(2) = zlocw(2) + njmpp - 1
-         zcw_loc(3) = zlocw(3)
-         zcw_max = zcw_cfl(zcw_loc(1),zcw_loc(2),zcw_loc(3))
-      ENDIF
-   
-      ! write out to file
-      IF( lwp ) THEN
-         WRITE(numcfl,FMT='(2x,i4,5x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3)
-         WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cv', zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3)
-         WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cw', zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3)
-      ENDIF
-
-      ! update maximum daily Courant numbers if applicable
-      IF( zcu_max > cu_max ) THEN
-         cu_max = zcu_max
-         cu_loc = zcu_loc
-      ENDIF
-      IF( zcv_max > cv_max ) THEN
-         cv_max = zcv_max
-         cv_loc = zcv_loc
-      ENDIF
-      IF( zcw_max > cw_max ) THEN
-         cw_max = zcw_max
-         cw_loc = zcw_loc
-      ENDIF
-
-      ! at end of run output max Cu and Cv and close ascii file
-      IF( kt == nitend .AND. lwp ) THEN
-         ! to ascii file
-         WRITE(numcfl,*) '******************************************'
-         WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', cu_max, cu_loc(1), cu_loc(2), cu_loc(3)
-         WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
-         WRITE(numcfl,*) '******************************************'
-         WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', cv_max, cv_loc(1), cv_loc(2), cv_loc(3)
-         WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
-         WRITE(numcfl,*) '******************************************'
-         WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', cw_max, cw_loc(1), cw_loc(2), cw_loc(3)
-         WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
-         CLOSE( numcfl ) 
-
-         ! to ocean output
-         WRITE(numout,*)
-         WRITE(numout,*) 'dia_cfl     : Maximum Courant number information for the run:'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) = (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
-         WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
-         WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) = (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
-         WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
-         WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) = (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
-         WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
-
-      ENDIF
-
-   END SUBROUTINE dia_cfl
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Dummy Module
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER   ::   lk_diacfl = .FALSE.   ! CFL diag flag
-CONTAINS
-   SUBROUTINE dia_cfl( kt )        ! Empty routine
-      WRITE(*,*) 'dia_cfl: : You should not have seen this print! error?', kt
-   END SUBROUTINE dia_cfl
-#endif
-
-   !!======================================================================
+   END SUBROUTINE dia_cfl_init
+
 END MODULE diacfl
Index: /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4708)
+++ /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4709)
@@ -91,4 +91,5 @@
    LOGICAL ::   ln_ctl       !: run control for debugging
    INTEGER ::   nn_timing    !: run control for timing
+   INTEGER ::   nn_diacfl    !: flag whether to create CFL diagnostics
    INTEGER ::   nn_print     !: level of print (0 no print)
    INTEGER ::   nn_ictls     !: Start i indice for the SUM control
Index: /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4708)
+++ /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4709)
@@ -65,4 +65,5 @@
    USE diadct          ! sections transports           (dia_dct_init routine)
    USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
+   USE diacfl          ! CFL diagnostics               (dia_cfl_init routine)
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
    USE step            ! NEMO time-stepping                 (stp     routine)
@@ -230,5 +231,5 @@
       NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_bench, nn_timing
+         &             nn_bench, nn_timing, nn_diacfl
       NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
          &             jpizoom, jpjzoom, jperio
@@ -453,4 +454,5 @@
                                             ! Diagnostics
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
+                            CALL dia_cfl_init   ! Initialise CFL diagnostics
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
                             CALL dia_ptr_init   ! Poleward TRansports initialization
Index: /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4708)
+++ /branches/2014/dev_r4650_UKMO12_CFL_diagnostic/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4709)
@@ -202,5 +202,5 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
-      IF( lk_diacfl  )   CALL dia_cfl( kstp )         ! Courant number diagnostics
+      IF( nn_diacfl == 1 )   CALL dia_cfl( kstp )         ! Courant number diagnostics
       IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
       IF( lk_diafwb  )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
