Index: NEMO/branches/2020/dev_r12472_ASINTER-05_Masson_CurrentFeedback/src/OCE/ZDF/zdfiwm.F90
===================================================================
--- NEMO/branches/2020/dev_r12472_ASINTER-05_Masson_CurrentFeedback/src/OCE/ZDF/zdfiwm.F90	(revision 12495)
+++ NEMO/branches/2020/dev_r12472_ASINTER-05_Masson_CurrentFeedback/src/OCE/ZDF/zdfiwm.F90	(revision 12551)
@@ -23,4 +23,5 @@
    USE phycst         ! physical constants
    !
+   USE fldread        ! field read
    USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
@@ -383,9 +384,24 @@
       !!              de Lavergne et al. in prep., 2017
       !!----------------------------------------------------------------------
-      INTEGER  ::   inum         ! local integer
+      INTEGER  ::   ifpr               ! dummy loop indices
+      INTEGER  ::   inum               ! local integer
       INTEGER  ::   ios
       REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
-      !!
-      NAMELIST/namzdf_iwm/ nn_zpyc, ln_mevar, ln_tsdiff
+      !
+      CHARACTER(len=256)            ::   cn_dir                 ! Root directory for location of ssr files
+      INTEGER, PARAMETER            ::   jpiwm  = 5             ! maximum number of files to read
+      INTEGER, PARAMETER            ::   jp_mpb = 1
+      INTEGER, PARAMETER            ::   jp_mpp = 2
+      INTEGER, PARAMETER            ::   jp_mpc = 3
+      INTEGER, PARAMETER            ::   jp_dsb = 4
+      INTEGER, PARAMETER            ::   jp_dsc = 5
+      !
+      TYPE(FLD_N), DIMENSION(jpiwm) ::   slf_iwm                ! array of namelist informations
+      TYPE(FLD_N)                   ::   sn_mpb, sn_mpp, sn_mpc ! informations about Mixing Power field to be read
+      TYPE(FLD_N)                   ::   sn_dsb, sn_dsc         ! informations about Decay Scale field to be read
+      TYPE(FLD  ), DIMENSION(jpiwm) ::   sf_iwm                 ! structure of input fields (file informations, fields read)
+      !
+      NAMELIST/namzdf_iwm/ nn_zpyc, ln_mevar, ln_tsdiff, &
+         &                 cn_dir, sn_mpb, sn_mpp, sn_mpc, sn_dsb, sn_dsc
       !!----------------------------------------------------------------------
       !
@@ -422,32 +438,36 @@
       IF( zdf_iwm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_iwm_init : unable to allocate iwm arrays' )
       !
+      ! store namelist information in an array
+      slf_iwm(jp_mpb) = sn_mpb ; slf_iwm(jp_mpp) = sn_mpp ; slf_iwm(jp_mpc) = sn_mpc
+      slf_iwm(jp_dsb) = sn_dsb ; slf_iwm(jp_dsc) = sn_dsc
+      !
+      DO ifpr= 1, jpiwm
+         ALLOCATE( sf_iwm(ifpr)%fnow(jpi,jpj,1)   )
+         IF( slf_iwm(ifpr)%ln_tint )ALLOCATE( sf_iwm(ifpr)%fdta(jpi,jpj,1,2) )
+      END DO
+
+      ! fill sf_iwm with sf_iwm and control print
+      CALL fld_fill( sf_iwm, slf_iwm , cn_dir, 'zdfiwm_init', 'iwm input file', 'namiwm' )
+
+      !                             ! hard-coded default definition (to be defined in namelist ?)
+      sf_iwm(jp_mpb)%fnow(:,:,1) = 1.e-6
+      sf_iwm(jp_mpp)%fnow(:,:,1) = 1.e-6
+      sf_iwm(jp_mpc)%fnow(:,:,1) = 1.e-10
+      sf_iwm(jp_dsb)%fnow(:,:,1) = 100.
+      sf_iwm(jp_dsc)%fnow(:,:,1) = 100.
+
       !                             ! read necessary fields
-      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ebot_iwm, 1 ) 
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', epyc_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ecri_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hbot_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hcri_iwm, 1 )
-      CALL iom_close(inum)
-
-      ebot_iwm(:,:) = ebot_iwm(:,:) * ssmask(:,:)
-      epyc_iwm(:,:) = epyc_iwm(:,:) * ssmask(:,:)
-      ecri_iwm(:,:) = ecri_iwm(:,:) * ssmask(:,:)
+      CALL fld_read( nit000, 1, sf_iwm )
+
+      ebot_iwm(:,:) = sf_iwm(1)%fnow(:,:,1) * ssmask(:,:) ! energy flux for high-mode wave breaking [W/m2]
+      epyc_iwm(:,:) = sf_iwm(2)%fnow(:,:,1) * ssmask(:,:) ! energy flux for pynocline-intensified wave breaking [W/m2]
+      ecri_iwm(:,:) = sf_iwm(3)%fnow(:,:,1) * ssmask(:,:) ! energy flux for critical slope wave breaking [W/m2]
+      hbot_iwm(:,:) = sf_iwm(4)%fnow(:,:,1)               ! spatially variable decay scale for high-mode wave breaking [m]
+      hcri_iwm(:,:) = sf_iwm(5)%fnow(:,:,1)               ! spatially variable decay scale for critical slope wave breaking [m]
 
       zbot = glob_sum( 'zdfiwm', e1e2t(:,:) * ebot_iwm(:,:) )
       zpyc = glob_sum( 'zdfiwm', e1e2t(:,:) * epyc_iwm(:,:) )
       zcri = glob_sum( 'zdfiwm', e1e2t(:,:) * ecri_iwm(:,:) )
+
       IF(lwp) THEN
          WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
