New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
sbccpl.F90 in NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage2/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage2/src/OCE/SBC/sbccpl.F90 @ 13443

Last change on this file since 13443 was 13443, checked in by frrh, 4 years ago

Commit changes which allow first working 2 way coupling exchanges between GO8
and LFRic aquaplanet.

File size: 157.1 KB
Line 
1MODULE sbccpl
2   !!======================================================================
3   !!                       ***  MODULE  sbccpl  ***
4   !! Surface Boundary Condition :  momentum, heat and freshwater fluxes in coupled mode
5   !!======================================================================
6   !! History :  2.0  ! 2007-06  (R. Redler, N. Keenlyside, W. Park) Original code split into flxmod & taumod
7   !!            3.0  ! 2008-02  (G. Madec, C Talandier)  surface module
8   !!            3.1  ! 2009_02  (G. Madec, S. Masson, E. Maisonave, A. Caubel) generic coupled interface
9   !!            3.4  ! 2011_11  (C. Harris) more flexibility + multi-category fields
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   namsbc_cpl      : coupled formulation namlist
14   !!   sbc_cpl_init    : initialisation of the coupled exchanges
15   !!   sbc_cpl_rcv     : receive fields from the atmosphere over the ocean (ocean only)
16   !!                     receive stress from the atmosphere over the ocean (ocean-ice case)
17   !!   sbc_cpl_ice_tau : receive stress from the atmosphere over ice
18   !!   sbc_cpl_ice_flx : receive fluxes from the atmosphere over ice
19   !!   sbc_cpl_snd     : send     fields to the atmosphere
20   !!----------------------------------------------------------------------
21   USE dom_oce         ! ocean space and time domain
22   USE sbc_oce         ! Surface boundary condition: ocean fields
23   USE trc_oce         ! share SMS/Ocean variables
24   USE sbc_ice         ! Surface boundary condition: ice fields
25   USE sbcapr          ! Stochastic param. : ???
26   USE sbcdcy          ! surface boundary condition: diurnal cycle
27   USE sbcwave         ! surface boundary condition: waves
28   USE phycst          ! physical constants
29#if defined key_si3
30   USE ice            ! ice variables
31#endif
32   USE cpl_oasis3     ! OASIS3 coupling
33   USE geo2ocean      !
34   USE oce     , ONLY : tsn, un, vn, sshn, ub, vb, sshb, fraqsr_1lev
35   USE ocealb         !
36   USE eosbn2         !
37   USE sbcrnf  , ONLY : l_rnfcpl
38   USE sbcisf  , ONLY : l_isfcpl
39#if defined key_cice
40   USE ice_domain_size, only: ncat
41#endif
42#if defined key_si3
43   USE icethd_dh      ! for CALL ice_thd_snwblow
44#endif
45   !
46   USE in_out_manager ! I/O manager
47   USE iom            ! NetCDF library
48   USE lib_mpp        ! distribued memory computing library
49   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
50
51   IMPLICIT NONE
52   PRIVATE
53
54   PUBLIC   sbc_cpl_init      ! routine called by sbcmod.F90
55   PUBLIC   sbc_cpl_rcv       ! routine called by icestp.F90
56   PUBLIC   sbc_cpl_snd       ! routine called by step.F90
57   PUBLIC   sbc_cpl_ice_tau   ! routine called by icestp.F90
58   PUBLIC   sbc_cpl_ice_flx   ! routine called by icestp.F90
59   PUBLIC   sbc_cpl_alloc     ! routine called in sbcice_cice.F90
60
61   INTEGER, PARAMETER ::   jpr_otx1   =  1   ! 3 atmosphere-ocean stress components on grid 1
62   INTEGER, PARAMETER ::   jpr_oty1   =  2   !
63   INTEGER, PARAMETER ::   jpr_otz1   =  3   !
64   INTEGER, PARAMETER ::   jpr_otx2   =  4   ! 3 atmosphere-ocean stress components on grid 2
65   INTEGER, PARAMETER ::   jpr_oty2   =  5   !
66   INTEGER, PARAMETER ::   jpr_otz2   =  6   !
67   INTEGER, PARAMETER ::   jpr_itx1   =  7   ! 3 atmosphere-ice   stress components on grid 1
68   INTEGER, PARAMETER ::   jpr_ity1   =  8   !
69   INTEGER, PARAMETER ::   jpr_itz1   =  9   !
70   INTEGER, PARAMETER ::   jpr_itx2   = 10   ! 3 atmosphere-ice   stress components on grid 2
71   INTEGER, PARAMETER ::   jpr_ity2   = 11   !
72   INTEGER, PARAMETER ::   jpr_itz2   = 12   !
73   INTEGER, PARAMETER ::   jpr_qsroce = 13   ! Qsr above the ocean
74   INTEGER, PARAMETER ::   jpr_qsrice = 14   ! Qsr above the ice
75   INTEGER, PARAMETER ::   jpr_qsrmix = 15 
76   INTEGER, PARAMETER ::   jpr_qnsoce = 16   ! Qns above the ocean
77   INTEGER, PARAMETER ::   jpr_qnsice = 17   ! Qns above the ice
78   INTEGER, PARAMETER ::   jpr_qnsmix = 18
79   INTEGER, PARAMETER ::   jpr_rain   = 19   ! total liquid precipitation (rain)
80   INTEGER, PARAMETER ::   jpr_snow   = 20   ! solid precipitation over the ocean (snow)
81   INTEGER, PARAMETER ::   jpr_tevp   = 21   ! total evaporation
82   INTEGER, PARAMETER ::   jpr_ievp   = 22   ! solid evaporation (sublimation)
83   INTEGER, PARAMETER ::   jpr_sbpr   = 23   ! sublimation - liquid precipitation - solid precipitation
84   INTEGER, PARAMETER ::   jpr_semp   = 24   ! solid freshwater budget (sublimation - snow)
85   INTEGER, PARAMETER ::   jpr_oemp   = 25   ! ocean freshwater budget (evap - precip)
86   INTEGER, PARAMETER ::   jpr_w10m   = 26   ! 10m wind
87   INTEGER, PARAMETER ::   jpr_dqnsdt = 27   ! d(Q non solar)/d(temperature)
88   INTEGER, PARAMETER ::   jpr_rnf    = 28   ! runoffs
89   INTEGER, PARAMETER ::   jpr_cal    = 29   ! calving
90   INTEGER, PARAMETER ::   jpr_taum   = 30   ! wind stress module
91   INTEGER, PARAMETER ::   jpr_co2    = 31
92   INTEGER, PARAMETER ::   jpr_topm   = 32   ! topmeltn
93   INTEGER, PARAMETER ::   jpr_botm   = 33   ! botmeltn
94   INTEGER, PARAMETER ::   jpr_sflx   = 34   ! salt flux
95   INTEGER, PARAMETER ::   jpr_toce   = 35   ! ocean temperature
96   INTEGER, PARAMETER ::   jpr_soce   = 36   ! ocean salinity
97   INTEGER, PARAMETER ::   jpr_ocx1   = 37   ! ocean current on grid 1
98   INTEGER, PARAMETER ::   jpr_ocy1   = 38   !
99   INTEGER, PARAMETER ::   jpr_ssh    = 39   ! sea surface height
100   INTEGER, PARAMETER ::   jpr_fice   = 40   ! ice fraction         
101   INTEGER, PARAMETER ::   jpr_e3t1st = 41   ! first T level thickness
102   INTEGER, PARAMETER ::   jpr_fraqsr = 42   ! fraction of solar net radiation absorbed in the first ocean level
103   INTEGER, PARAMETER ::   jpr_mslp   = 43   ! mean sea level pressure
104   INTEGER, PARAMETER ::   jpr_hsig   = 44   ! Hsig
105   INTEGER, PARAMETER ::   jpr_phioc  = 45   ! Wave=>ocean energy flux
106   INTEGER, PARAMETER ::   jpr_sdrftx = 46   ! Stokes drift on grid 1
107   INTEGER, PARAMETER ::   jpr_sdrfty = 47   ! Stokes drift on grid 2
108   INTEGER, PARAMETER ::   jpr_wper   = 48   ! Mean wave period
109   INTEGER, PARAMETER ::   jpr_wnum   = 49   ! Mean wavenumber
110   INTEGER, PARAMETER ::   jpr_tauwoc = 50   ! Stress fraction adsorbed by waves
111   INTEGER, PARAMETER ::   jpr_wdrag  = 51   ! Neutral surface drag coefficient
112   INTEGER, PARAMETER ::   jpr_isf    = 52
113   INTEGER, PARAMETER ::   jpr_icb    = 53
114   INTEGER, PARAMETER ::   jpr_wfreq  = 54   ! Wave peak frequency
115   INTEGER, PARAMETER ::   jpr_tauwx  = 55   ! x component of the ocean stress from waves
116   INTEGER, PARAMETER ::   jpr_tauwy  = 56   ! y component of the ocean stress from waves
117   INTEGER, PARAMETER ::   jpr_ts_ice = 57   ! Sea ice surface temp
118   INTEGER, PARAMETER ::   jpr_dummy_t = 58  ! Dummy test incoming coupling tracer grid field
119
120   INTEGER, PARAMETER ::   jprcv      = 58   ! total number of fields received 
121
122   INTEGER, PARAMETER ::   jps_fice   =  1   ! ice fraction sent to the atmosphere
123   INTEGER, PARAMETER ::   jps_toce   =  2   ! ocean temperature
124   INTEGER, PARAMETER ::   jps_tice   =  3   ! ice   temperature
125   INTEGER, PARAMETER ::   jps_tmix   =  4   ! mixed temperature (ocean+ice)
126   INTEGER, PARAMETER ::   jps_albice =  5   ! ice   albedo
127   INTEGER, PARAMETER ::   jps_albmix =  6   ! mixed albedo
128   INTEGER, PARAMETER ::   jps_hice   =  7   ! ice  thickness
129   INTEGER, PARAMETER ::   jps_hsnw   =  8   ! snow thickness
130   INTEGER, PARAMETER ::   jps_ocx1   =  9   ! ocean current on grid 1
131   INTEGER, PARAMETER ::   jps_ocy1   = 10   !
132   INTEGER, PARAMETER ::   jps_ocz1   = 11   !
133   INTEGER, PARAMETER ::   jps_ivx1   = 12   ! ice   current on grid 1
134   INTEGER, PARAMETER ::   jps_ivy1   = 13   !
135   INTEGER, PARAMETER ::   jps_ivz1   = 14   !
136   INTEGER, PARAMETER ::   jps_co2    = 15
137   INTEGER, PARAMETER ::   jps_soce   = 16   ! ocean salinity
138   INTEGER, PARAMETER ::   jps_ssh    = 17   ! sea surface height
139   INTEGER, PARAMETER ::   jps_qsroce = 18   ! Qsr above the ocean
140   INTEGER, PARAMETER ::   jps_qnsoce = 19   ! Qns above the ocean
141   INTEGER, PARAMETER ::   jps_oemp   = 20   ! ocean freshwater budget (evap - precip)
142   INTEGER, PARAMETER ::   jps_sflx   = 21   ! salt flux
143   INTEGER, PARAMETER ::   jps_otx1   = 22   ! 2 atmosphere-ocean stress components on grid 1
144   INTEGER, PARAMETER ::   jps_oty1   = 23   !
145   INTEGER, PARAMETER ::   jps_rnf    = 24   ! runoffs
146   INTEGER, PARAMETER ::   jps_taum   = 25   ! wind stress module
147   INTEGER, PARAMETER ::   jps_fice2  = 26   ! ice fraction sent to OPA (by SAS when doing SAS-OPA coupling)
148   INTEGER, PARAMETER ::   jps_e3t1st = 27   ! first level depth (vvl)
149   INTEGER, PARAMETER ::   jps_fraqsr = 28   ! fraction of solar net radiation absorbed in the first ocean level
150   INTEGER, PARAMETER ::   jps_ficet  = 29   ! total ice fraction 
151   INTEGER, PARAMETER ::   jps_ocxw   = 30   ! currents on grid 1 
152   INTEGER, PARAMETER ::   jps_ocyw   = 31   ! currents on grid 2
153   INTEGER, PARAMETER ::   jps_wlev   = 32   ! water level
154   INTEGER, PARAMETER ::   jps_fice1  = 33   ! first-order ice concentration (for semi-implicit coupling of atmos-ice fluxes)
155   INTEGER, PARAMETER ::   jps_a_p    = 34   ! meltpond area
156   INTEGER, PARAMETER ::   jps_ht_p   = 35   ! meltpond thickness
157   INTEGER, PARAMETER ::   jps_kice   = 36   ! sea ice effective conductivity
158   INTEGER, PARAMETER ::   jps_sstfrz = 37   ! sea surface freezing temperature
159   INTEGER, PARAMETER ::   jps_ttilyr = 38   ! sea ice top layer temp
160   INTEGER, PARAMETER ::   jps_dummy_t = 39  ! Dummy test outgoing coupling tracer grid field
161
162   INTEGER, PARAMETER ::   jpsnd      = 39   ! total number of fields sent
163
164   !                                  !!** namelist namsbc_cpl **
165   TYPE ::   FLD_C                     !   
166      CHARACTER(len = 32) ::   cldes      ! desciption of the coupling strategy
167      CHARACTER(len = 32) ::   clcat      ! multiple ice categories strategy
168      CHARACTER(len = 32) ::   clvref     ! reference of vector ('spherical' or 'cartesian')
169      CHARACTER(len = 32) ::   clvor      ! orientation of vector fields ('eastward-northward' or 'local grid')
170      CHARACTER(len = 32) ::   clvgrd     ! grids on which is located the vector fields
171   END TYPE FLD_C
172   !                                   ! Send to the atmosphere 
173   TYPE(FLD_C) ::   sn_snd_temp  , sn_snd_alb , sn_snd_thick, sn_snd_crt   , sn_snd_co2,  &
174      &             sn_snd_thick1, sn_snd_cond, sn_snd_mpnd , sn_snd_sstfrz, sn_snd_ttilyr
175   !                                   ! Received from the atmosphere
176   TYPE(FLD_C) ::   sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau, sn_rcv_tauw, sn_rcv_dqnsdt, sn_rcv_qsr,  &
177      &             sn_rcv_qns , sn_rcv_emp   , sn_rcv_rnf, sn_rcv_ts_ice
178   TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2, sn_rcv_mslp, sn_rcv_icb, sn_rcv_isf
179   ! Send to waves
180   TYPE(FLD_C) ::   sn_snd_ifrac, sn_snd_crtw, sn_snd_wlev 
181   ! Received from waves
182   TYPE(FLD_C) ::   sn_rcv_hsig, sn_rcv_phioc, sn_rcv_sdrfx, sn_rcv_sdrfy, sn_rcv_wper, sn_rcv_wnum, sn_rcv_tauwoc, &
183                    sn_rcv_wdrag, sn_rcv_wfreq
184   !                                   ! Other namelist parameters
185   INTEGER     ::   nn_cplmodel           ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
186   LOGICAL     ::   ln_usecplmask         !  use a coupling mask file to merge data received from several models
187                                          !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
188   TYPE ::   DYNARR     
189      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3   
190   END TYPE DYNARR
191
192   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                ! all fields recieved from the atmosphere
193
194   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   alb_oce_mix    ! ocean albedo sent to atmosphere (mix clear/overcast sky)
195
196   REAL(wp) ::   rpref = 101000._wp   ! reference atmospheric pressure[N/m2]
197   REAL(wp) ::   r1_grau              ! = 1.e0 / (grav * rau0)
198
199   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:) ::   nrcvinfo           ! OASIS info argument
200
201   !! Substitution
202#  include "vectopt_loop_substitute.h90"
203   !!----------------------------------------------------------------------
204   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
205   !! $Id$
206   !! Software governed by the CeCILL license (see ./LICENSE)
207   !!----------------------------------------------------------------------
208CONTAINS
209 
210   INTEGER FUNCTION sbc_cpl_alloc()
211      !!----------------------------------------------------------------------
212      !!             ***  FUNCTION sbc_cpl_alloc  ***
213      !!----------------------------------------------------------------------
214      INTEGER :: ierr(4)
215      !!----------------------------------------------------------------------
216      ierr(:) = 0
217      !
218      ALLOCATE( alb_oce_mix(jpi,jpj), nrcvinfo(jprcv),  STAT=ierr(1) )
219     
220#if ! defined key_si3 && ! defined key_cice
221      ALLOCATE( a_i(jpi,jpj,1) , STAT=ierr(2) )  ! used in sbcice_if.F90 (done here as there is no sbc_ice_if_init)
222#endif
223      ALLOCATE( xcplmask(jpi,jpj,0:nn_cplmodel) , STAT=ierr(3) )
224      !
225      IF( .NOT. ln_apr_dyn ) ALLOCATE( ssh_ib(jpi,jpj), ssh_ibb(jpi,jpj), apr(jpi, jpj), STAT=ierr(4) ) 
226
227      sbc_cpl_alloc = MAXVAL( ierr )
228      CALL mpp_sum ( 'sbccpl', sbc_cpl_alloc )
229      IF( sbc_cpl_alloc > 0 )   CALL ctl_warn('sbc_cpl_alloc: allocation of arrays failed')
230      !
231   END FUNCTION sbc_cpl_alloc
232
233
234   SUBROUTINE sbc_cpl_init( k_ice )     
235      !!----------------------------------------------------------------------
236      !!             ***  ROUTINE sbc_cpl_init  ***
237      !!
238      !! ** Purpose :   Initialisation of send and received information from
239      !!                the atmospheric component
240      !!
241      !! ** Method  : * Read namsbc_cpl namelist
242      !!              * define the receive interface
243      !!              * define the send    interface
244      !!              * initialise the OASIS coupler
245      !!----------------------------------------------------------------------
246      INTEGER, INTENT(in) ::   k_ice   ! ice management in the sbc (=0/1/2/3)
247      !
248      INTEGER ::   jn          ! dummy loop index
249      INTEGER ::   ios, inum   ! Local integer
250      REAL(wp), DIMENSION(jpi,jpj) ::   zacs, zaos
251      !!
252      NAMELIST/namsbc_cpl/  sn_snd_temp  , sn_snd_alb   , sn_snd_thick, sn_snd_crt   , sn_snd_co2  ,   & 
253         &                  sn_snd_ttilyr, sn_snd_cond  , sn_snd_mpnd , sn_snd_sstfrz, sn_snd_thick1,  & 
254         &                  sn_snd_ifrac , sn_snd_crtw  , sn_snd_wlev , sn_rcv_hsig  , sn_rcv_phioc,   & 
255         &                  sn_rcv_w10m  , sn_rcv_taumod, sn_rcv_tau  , sn_rcv_dqnsdt, sn_rcv_qsr  ,   & 
256         &                  sn_rcv_sdrfx , sn_rcv_sdrfy , sn_rcv_wper , sn_rcv_wnum  , sn_rcv_tauwoc,  &
257         &                  sn_rcv_wdrag , sn_rcv_qns   , sn_rcv_emp  , sn_rcv_rnf   , sn_rcv_cal  ,   &
258         &                  sn_rcv_iceflx, sn_rcv_co2   , nn_cplmodel , ln_usecplmask, sn_rcv_mslp ,   &
259         &                  sn_rcv_icb   , sn_rcv_isf   , sn_rcv_wfreq , sn_rcv_tauw, nn_cats_cpl  ,   &
260         &                  sn_rcv_ts_ice
261
262      !!---------------------------------------------------------------------
263      !
264      ! ================================ !
265      !      Namelist informations       !
266      ! ================================ !
267      !
268      REWIND( numnam_ref )              ! Namelist namsbc_cpl in reference namelist : Variables for OASIS coupling
269      READ  ( numnam_ref, namsbc_cpl, IOSTAT = ios, ERR = 901)
270901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist' )
271      !
272      REWIND( numnam_cfg )              ! Namelist namsbc_cpl in configuration namelist : Variables for OASIS coupling
273      READ  ( numnam_cfg, namsbc_cpl, IOSTAT = ios, ERR = 902 )
274902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist' )
275      IF(lwm) WRITE ( numond, namsbc_cpl )
276      !
277      IF(lwp) THEN                        ! control print
278         WRITE(numout,*)
279         WRITE(numout,*)'sbc_cpl_init : namsbc_cpl namelist '
280         WRITE(numout,*)'~~~~~~~~~~~~'
281      ENDIF
282      IF( lwp .AND. (ln_cpl .OR. ln_couple_test) ) THEN                        ! control print
283         WRITE(numout,*)'  received fields (mutiple ice categogies)'
284         WRITE(numout,*)'      10m wind module                 = ', TRIM(sn_rcv_w10m%cldes  ), ' (', TRIM(sn_rcv_w10m%clcat  ), ')'
285         WRITE(numout,*)'      stress module                   = ', TRIM(sn_rcv_taumod%cldes), ' (', TRIM(sn_rcv_taumod%clcat), ')'
286         WRITE(numout,*)'      surface stress                  = ', TRIM(sn_rcv_tau%cldes   ), ' (', TRIM(sn_rcv_tau%clcat   ), ')'
287         WRITE(numout,*)'                     - referential    = ', sn_rcv_tau%clvref
288         WRITE(numout,*)'                     - orientation    = ', sn_rcv_tau%clvor
289         WRITE(numout,*)'                     - mesh           = ', sn_rcv_tau%clvgrd
290         WRITE(numout,*)'      non-solar heat flux sensitivity = ', TRIM(sn_rcv_dqnsdt%cldes), ' (', TRIM(sn_rcv_dqnsdt%clcat), ')'
291         WRITE(numout,*)'      solar heat flux                 = ', TRIM(sn_rcv_qsr%cldes   ), ' (', TRIM(sn_rcv_qsr%clcat   ), ')'
292         WRITE(numout,*)'      non-solar heat flux             = ', TRIM(sn_rcv_qns%cldes   ), ' (', TRIM(sn_rcv_qns%clcat   ), ')'
293         WRITE(numout,*)'      freshwater budget               = ', TRIM(sn_rcv_emp%cldes   ), ' (', TRIM(sn_rcv_emp%clcat   ), ')'
294         WRITE(numout,*)'      runoffs                         = ', TRIM(sn_rcv_rnf%cldes   ), ' (', TRIM(sn_rcv_rnf%clcat   ), ')'
295         WRITE(numout,*)'      calving                         = ', TRIM(sn_rcv_cal%cldes   ), ' (', TRIM(sn_rcv_cal%clcat   ), ')'
296         WRITE(numout,*)'      iceberg                         = ', TRIM(sn_rcv_icb%cldes   ), ' (', TRIM(sn_rcv_icb%clcat   ), ')'
297         WRITE(numout,*)'      ice shelf                       = ', TRIM(sn_rcv_isf%cldes   ), ' (', TRIM(sn_rcv_isf%clcat   ), ')'
298         WRITE(numout,*)'      sea ice heat fluxes             = ', TRIM(sn_rcv_iceflx%cldes), ' (', TRIM(sn_rcv_iceflx%clcat), ')'
299         WRITE(numout,*)'      atm co2                         = ', TRIM(sn_rcv_co2%cldes   ), ' (', TRIM(sn_rcv_co2%clcat   ), ')'
300         WRITE(numout,*)'      significant wave heigth         = ', TRIM(sn_rcv_hsig%cldes  ), ' (', TRIM(sn_rcv_hsig%clcat  ), ')' 
301         WRITE(numout,*)'      wave to oce energy flux         = ', TRIM(sn_rcv_phioc%cldes ), ' (', TRIM(sn_rcv_phioc%clcat ), ')' 
302         WRITE(numout,*)'      Surface Stokes drift grid u     = ', TRIM(sn_rcv_sdrfx%cldes ), ' (', TRIM(sn_rcv_sdrfx%clcat ), ')' 
303         WRITE(numout,*)'      Surface Stokes drift grid v     = ', TRIM(sn_rcv_sdrfy%cldes ), ' (', TRIM(sn_rcv_sdrfy%clcat ), ')' 
304         WRITE(numout,*)'      Mean wave period                = ', TRIM(sn_rcv_wper%cldes  ), ' (', TRIM(sn_rcv_wper%clcat  ), ')' 
305         WRITE(numout,*)'      Mean wave number                = ', TRIM(sn_rcv_wnum%cldes  ), ' (', TRIM(sn_rcv_wnum%clcat  ), ')' 
306         WRITE(numout,*)'      Wave peak frequency             = ', TRIM(sn_rcv_wfreq%cldes ), ' (', TRIM(sn_rcv_wfreq%clcat ), ')'
307         WRITE(numout,*)'      Stress frac adsorbed by waves   = ', TRIM(sn_rcv_tauwoc%cldes), ' (', TRIM(sn_rcv_tauwoc%clcat ), ')' 
308         WRITE(numout,*)'      Stress components by waves      = ', TRIM(sn_rcv_tauw%cldes  ), ' (', TRIM(sn_rcv_tauw%clcat  ), ')'
309         WRITE(numout,*)'      Neutral surf drag coefficient   = ', TRIM(sn_rcv_wdrag%cldes ), ' (', TRIM(sn_rcv_wdrag%clcat ), ')' 
310         WRITE(numout,*)'      Sea ice surface skin temperature= ', TRIM(sn_rcv_ts_ice%cldes), ' (', TRIM(sn_rcv_ts_ice%clcat), ')' 
311         WRITE(numout,*)'  sent fields (multiple ice categories)'
312         WRITE(numout,*)'      surface temperature             = ', TRIM(sn_snd_temp%cldes  ), ' (', TRIM(sn_snd_temp%clcat  ), ')'
313         WRITE(numout,*)'      top ice layer temperature       = ', TRIM(sn_snd_ttilyr%cldes), ' (', TRIM(sn_snd_ttilyr%clcat), ')'
314         WRITE(numout,*)'      albedo                          = ', TRIM(sn_snd_alb%cldes   ), ' (', TRIM(sn_snd_alb%clcat   ), ')'
315         WRITE(numout,*)'      ice/snow thickness              = ', TRIM(sn_snd_thick%cldes ), ' (', TRIM(sn_snd_thick%clcat ), ')'
316         WRITE(numout,*)'      total ice fraction              = ', TRIM(sn_snd_ifrac%cldes ), ' (', TRIM(sn_snd_ifrac%clcat ), ')' 
317         WRITE(numout,*)'      surface current                 = ', TRIM(sn_snd_crt%cldes   ), ' (', TRIM(sn_snd_crt%clcat   ), ')'
318         WRITE(numout,*)'                      - referential   = ', sn_snd_crt%clvref 
319         WRITE(numout,*)'                      - orientation   = ', sn_snd_crt%clvor
320         WRITE(numout,*)'                      - mesh          = ', sn_snd_crt%clvgrd
321         WRITE(numout,*)'      oce co2 flux                    = ', TRIM(sn_snd_co2%cldes   ), ' (', TRIM(sn_snd_co2%clcat   ), ')'
322         WRITE(numout,*)'      ice effective conductivity      = ', TRIM(sn_snd_cond%cldes  ), ' (', TRIM(sn_snd_cond%clcat  ), ')'
323         WRITE(numout,*)'      meltponds fraction and depth    = ', TRIM(sn_snd_mpnd%cldes  ), ' (', TRIM(sn_snd_mpnd%clcat  ), ')'
324         WRITE(numout,*)'      sea surface freezing temp       = ', TRIM(sn_snd_sstfrz%cldes), ' (', TRIM(sn_snd_sstfrz%clcat), ')'
325         WRITE(numout,*)'      water level                     = ', TRIM(sn_snd_wlev%cldes  ), ' (', TRIM(sn_snd_wlev%clcat  ), ')' 
326         WRITE(numout,*)'      mean sea level pressure         = ', TRIM(sn_rcv_mslp%cldes  ), ' (', TRIM(sn_rcv_mslp%clcat  ), ')' 
327         WRITE(numout,*)'      surface current to waves        = ', TRIM(sn_snd_crtw%cldes  ), ' (', TRIM(sn_snd_crtw%clcat  ), ')' 
328         WRITE(numout,*)'                      - referential   = ', sn_snd_crtw%clvref 
329         WRITE(numout,*)'                      - orientation   = ', sn_snd_crtw%clvor 
330         WRITE(numout,*)'                      - mesh          = ', sn_snd_crtw%clvgrd 
331         WRITE(numout,*)'  nn_cplmodel                         = ', nn_cplmodel
332         WRITE(numout,*)'  ln_usecplmask                       = ', ln_usecplmask
333         WRITE(numout,*)'  nn_cats_cpl                         = ', nn_cats_cpl
334      ENDIF
335
336      !                                   ! allocate sbccpl arrays
337      IF( sbc_cpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_cpl_alloc : unable to allocate arrays' )
338     
339      ! ================================ !
340      !   Define the receive interface   !
341      ! ================================ !
342      nrcvinfo(:) = OASIS_idle   ! needed by nrcvinfo(jpr_otx1) if we do not receive ocean stress
343
344      ! for each field: define the OASIS name                              (srcv(:)%clname)
345      !                 define receive or not from the namelist parameters (srcv(:)%laction)
346      !                 define the north fold type of lbc                  (srcv(:)%nsgn)
347
348      ! default definitions of srcv
349      srcv(:)%laction = .FALSE.   ;   srcv(:)%clgrid = 'T'   ;   srcv(:)%nsgn = 1.   ;   srcv(:)%nct = 1
350
351      !                                                      ! ------------------------- !
352      !                                                      ! ice and ocean wind stress !   
353      !                                                      ! ------------------------- !
354      !                                                           ! Name
355      srcv(jpr_otx1)%clname = 'O_OTaux1'      ! 1st ocean component on grid ONE (T or U)
356      srcv(jpr_oty1)%clname = 'O_OTauy1'      ! 2nd   -      -         -     -
357      srcv(jpr_otz1)%clname = 'O_OTauz1'      ! 3rd   -      -         -     -
358      srcv(jpr_otx2)%clname = 'O_OTaux2'      ! 1st ocean component on grid TWO (V)
359      srcv(jpr_oty2)%clname = 'O_OTauy2'      ! 2nd   -      -         -     -
360      srcv(jpr_otz2)%clname = 'O_OTauz2'      ! 3rd   -      -         -     -
361      !
362      srcv(jpr_itx1)%clname = 'O_ITaux1'      ! 1st  ice  component on grid ONE (T, F, I or U)
363      srcv(jpr_ity1)%clname = 'O_ITauy1'      ! 2nd   -      -         -     -
364      srcv(jpr_itz1)%clname = 'O_ITauz1'      ! 3rd   -      -         -     -
365      srcv(jpr_itx2)%clname = 'O_ITaux2'      ! 1st  ice  component on grid TWO (V)
366      srcv(jpr_ity2)%clname = 'O_ITauy2'      ! 2nd   -      -         -     -
367      srcv(jpr_itz2)%clname = 'O_ITauz2'      ! 3rd   -      -         -     -
368      !
369      ! Vectors: change of sign at north fold ONLY if on the local grid
370      IF( TRIM( sn_rcv_tau%cldes ) == 'oce only' .OR. TRIM(sn_rcv_tau%cldes ) == 'oce and ice') THEN ! avoid working with the atmospheric fields if they are not coupled
371      IF( TRIM( sn_rcv_tau%clvor ) == 'local grid' )   srcv(jpr_otx1:jpr_itz2)%nsgn = -1.
372     
373      !                                                           ! Set grid and action
374      SELECT CASE( TRIM( sn_rcv_tau%clvgrd ) )      !  'T', 'U,V', 'U,V,I', 'U,V,F', 'T,I', 'T,F', or 'T,U,V'
375      CASE( 'T' ) 
376         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
377         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
378         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
379      CASE( 'U,V' ) 
380         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
381         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
382         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'U'        ! ice components given at U-point
383         srcv(jpr_itx2:jpr_itz2)%clgrid  = 'V'        !           and           V-point
384         srcv(jpr_otx1:jpr_itz2)%laction = .TRUE.     ! receive oce and ice components on both grid 1 & 2
385      CASE( 'U,V,T' )
386         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
387         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
388         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'T'        ! ice components given at T-point
389         srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
390         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
391      CASE( 'U,V,I' )
392         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
393         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
394         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'I'        ! ice components given at I-point
395         srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
396         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
397      CASE( 'U,V,F' )
398         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
399         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
400         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'F'        ! ice components given at F-point
401         !srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
402! Currently needed for HadGEM3 - but shouldn't affect anyone else for the moment
403         srcv(jpr_otx1)%laction = .TRUE. 
404         srcv(jpr_oty1)%laction = .TRUE.
405!
406         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
407      CASE( 'T,I' ) 
408         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
409         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'I'        ! ice components given at I-point
410         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
411         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
412      CASE( 'T,F' ) 
413         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
414         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'F'        ! ice components given at F-point
415         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
416         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
417      CASE( 'T,U,V' )
418         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'T'        ! oce components given at T-point
419         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'U'        ! ice components given at U-point
420         srcv(jpr_itx2:jpr_itz2)%clgrid  = 'V'        !           and           V-point
421         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1 only
422         srcv(jpr_itx1:jpr_itz2)%laction = .TRUE.     ! receive ice components on grid 1 & 2
423      CASE default   
424         CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_tau%clvgrd' )
425      END SELECT
426      !
427      IF( TRIM( sn_rcv_tau%clvref ) == 'spherical' )   &           ! spherical: 3rd component not received
428         &     srcv( (/jpr_otz1, jpr_otz2, jpr_itz1, jpr_itz2/) )%laction = .FALSE. 
429      !
430      IF( TRIM( sn_rcv_tau%clvor  ) == 'local grid' ) THEN        ! already on local grid -> no need of the second grid
431            srcv(jpr_otx2:jpr_otz2)%laction = .FALSE. 
432            srcv(jpr_itx2:jpr_itz2)%laction = .FALSE. 
433            srcv(jpr_oty1)%clgrid = srcv(jpr_oty2)%clgrid   ! not needed but cleaner...
434            srcv(jpr_ity1)%clgrid = srcv(jpr_ity2)%clgrid   ! not needed but cleaner...
435      ENDIF
436      !
437      IF( TRIM( sn_rcv_tau%cldes ) /= 'oce and ice' ) THEN        ! 'oce and ice' case ocean stress on ocean mesh used
438         srcv(jpr_itx1:jpr_itz2)%laction = .FALSE.    ! ice components not received
439         srcv(jpr_itx1)%clgrid = 'U'                  ! ocean stress used after its transformation
440         srcv(jpr_ity1)%clgrid = 'V'                  ! i.e. it is always at U- & V-points for i- & j-comp. resp.
441      ENDIF
442      ENDIF
443
444      !                                                      ! ------------------------- !
445      !                                                      !    freshwater budget      !   E-P
446      !                                                      ! ------------------------- !
447      ! we suppose that atmosphere modele do not make the difference between precipiration (liquide or solid)
448      ! over ice of free ocean within the same atmospheric cell.cd
449      srcv(jpr_rain)%clname = 'OTotRain'      ! Rain = liquid precipitation
450      srcv(jpr_snow)%clname = 'OTotSnow'      ! Snow = solid precipitation
451      srcv(jpr_tevp)%clname = 'OTotEvap'      ! total evaporation (over oce + ice sublimation)
452      srcv(jpr_ievp)%clname = 'OIceEvap'      ! evaporation over ice = sublimation
453      srcv(jpr_sbpr)%clname = 'OSubMPre'      ! sublimation - liquid precipitation - solid precipitation
454      srcv(jpr_semp)%clname = 'OISubMSn'      ! ice solid water budget = sublimation - solid precipitation
455      srcv(jpr_oemp)%clname = 'OOEvaMPr'      ! ocean water budget = ocean Evap - ocean precip
456      SELECT CASE( TRIM( sn_rcv_emp%cldes ) )
457      CASE( 'none'          )       ! nothing to do
458      CASE( 'oce only'      )   ;   srcv(jpr_oemp)%laction = .TRUE. 
459      CASE( 'conservative'  )
460         srcv( (/jpr_rain, jpr_snow, jpr_ievp, jpr_tevp/) )%laction = .TRUE.
461         IF ( k_ice <= 1 )  srcv(jpr_ievp)%laction = .FALSE.
462      CASE( 'oce and ice'   )   ;   srcv( (/jpr_ievp, jpr_sbpr, jpr_semp, jpr_oemp/) )%laction = .TRUE.
463      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_emp%cldes' )
464      END SELECT
465      !
466      !                                                      ! ------------------------- !
467      !                                                      !     Runoffs & Calving     !   
468      !                                                      ! ------------------------- !
469      srcv(jpr_rnf   )%clname = 'O_Runoff'
470      IF (ln_cpl) THEN ! Don't perform this code if coupling is not active!
471         IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' ) THEN
472            srcv(jpr_rnf)%laction = .TRUE.
473            l_rnfcpl              = .TRUE.                      ! -> no need to read runoffs in sbcrnf
474            ln_rnf                = nn_components /= jp_iam_sas ! -> force to go through sbcrnf if not sas
475            IF(lwp) WRITE(numout,*)
476            IF(lwp) WRITE(numout,*) '   runoffs received from oasis -> force ln_rnf = ', ln_rnf
477         ENDIF
478      ENDIF 
479      !
480      srcv(jpr_cal)%clname = 'OCalving'   ;  IF( TRIM( sn_rcv_cal%cldes) == 'coupled' )   srcv(jpr_cal)%laction = .TRUE.
481      srcv(jpr_isf)%clname = 'OIcshelf'   ;  IF( TRIM( sn_rcv_isf%cldes) == 'coupled' )   srcv(jpr_isf)%laction = .TRUE.
482      srcv(jpr_icb)%clname = 'OIceberg'   ;  IF( TRIM( sn_rcv_icb%cldes) == 'coupled' )   srcv(jpr_icb)%laction = .TRUE.
483
484      IF( srcv(jpr_isf)%laction .AND. ln_isf ) THEN
485         l_isfcpl             = .TRUE.                      ! -> no need to read isf in sbcisf
486         IF(lwp) WRITE(numout,*)
487         IF(lwp) WRITE(numout,*) '   iceshelf received from oasis '
488      ENDIF
489      !
490      !                                                      ! ------------------------- !
491      !                                                      !    non solar radiation    !   Qns
492      !                                                      ! ------------------------- !
493      srcv(jpr_qnsoce)%clname = 'O_QnsOce'
494      srcv(jpr_qnsice)%clname = 'O_QnsIce'
495      srcv(jpr_qnsmix)%clname = 'O_QnsMix'
496      SELECT CASE( TRIM( sn_rcv_qns%cldes ) )
497      CASE( 'none'          )       ! nothing to do
498      CASE( 'oce only'      )   ;   srcv(               jpr_qnsoce   )%laction = .TRUE.
499      CASE( 'conservative'  )   ;   srcv( (/jpr_qnsice, jpr_qnsmix/) )%laction = .TRUE.
500      CASE( 'oce and ice'   )   ;   srcv( (/jpr_qnsice, jpr_qnsoce/) )%laction = .TRUE.
501      CASE( 'mixed oce-ice' )   ;   srcv(               jpr_qnsmix   )%laction = .TRUE. 
502      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qns%cldes' )
503      END SELECT
504      IF( TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' .AND. nn_cats_cpl > 1 ) &
505         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qns%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
506      !
507      !                                                      ! ------------------------- !
508      !                                                      !    solar radiation        !   Qsr
509      !                                                      ! ------------------------- !
510      srcv(jpr_qsroce)%clname = 'O_QsrOce'
511      srcv(jpr_qsrice)%clname = 'O_QsrIce'
512      srcv(jpr_qsrmix)%clname = 'O_QsrMix'
513      SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )
514      CASE( 'none'          )       ! nothing to do
515      CASE( 'oce only'      )   ;   srcv(               jpr_qsroce   )%laction = .TRUE.
516      CASE( 'conservative'  )   ;   srcv( (/jpr_qsrice, jpr_qsrmix/) )%laction = .TRUE.
517      CASE( 'oce and ice'   )   ;   srcv( (/jpr_qsrice, jpr_qsroce/) )%laction = .TRUE.
518      CASE( 'mixed oce-ice' )   ;   srcv(               jpr_qsrmix   )%laction = .TRUE. 
519      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qsr%cldes' )
520      END SELECT
521      IF( TRIM( sn_rcv_qsr%cldes ) == 'mixed oce-ice' .AND. nn_cats_cpl > 1 ) &
522         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qsr%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
523      !
524      !                                                      ! ------------------------- !
525      !                                                      !   non solar sensitivity   !   d(Qns)/d(T)
526      !                                                      ! ------------------------- !
527      srcv(jpr_dqnsdt)%clname = 'O_dQnsdT'   
528      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'coupled' )   srcv(jpr_dqnsdt)%laction = .TRUE.
529      !
530      ! non solar sensitivity mandatory for mixed oce-ice solar radiation coupling technique
531      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' )  &
532         &   CALL ctl_stop( 'sbc_cpl_init: namsbc_cpl namelist mismatch between sn_rcv_qns%cldes and sn_rcv_dqnsdt%cldes' )
533      !
534      !                                                      ! ------------------------- !
535      !                                                      !      10m wind module      !   
536      !                                                      ! ------------------------- !
537      srcv(jpr_w10m)%clname = 'O_Wind10'   ;   IF( TRIM(sn_rcv_w10m%cldes  ) == 'coupled' )   srcv(jpr_w10m)%laction = .TRUE. 
538      !
539      !                                                      ! ------------------------- !
540      !                                                      !   wind stress module      !   
541      !                                                      ! ------------------------- !
542      srcv(jpr_taum)%clname = 'O_TauMod'   ;   IF( TRIM(sn_rcv_taumod%cldes) == 'coupled' )   srcv(jpr_taum)%laction = .TRUE.
543      lhftau = srcv(jpr_taum)%laction
544      !
545      !                                                      ! ------------------------- !
546      !                                                      !      Atmospheric CO2      !
547      !                                                      ! ------------------------- !
548      srcv(jpr_co2 )%clname = 'O_AtmCO2'   
549      IF (ln_cpl) THEN ! Not needed if we're not coupling
550         IF( TRIM(sn_rcv_co2%cldes   ) == 'coupled' )  THEN
551            srcv(jpr_co2 )%laction = .TRUE.
552            l_co2cpl = .TRUE.
553            IF(lwp) WRITE(numout,*)
554            IF(lwp) WRITE(numout,*) '   Atmospheric pco2 received from oasis '
555            IF(lwp) WRITE(numout,*)
556         ENDIF
557      ENDIF
558      !
559      !                                                      ! ------------------------- !
560      !                                                      ! Mean Sea Level Pressure   !
561      !                                                      ! ------------------------- !
562      srcv(jpr_mslp)%clname = 'O_MSLP'     ;   IF( TRIM(sn_rcv_mslp%cldes  ) == 'coupled' )    srcv(jpr_mslp)%laction = .TRUE. 
563      !
564      !                                                      ! ------------------------- !
565      !                                                      !  ice topmelt and botmelt  !   
566      !                                                      ! ------------------------- !
567      srcv(jpr_topm )%clname = 'OTopMlt'
568      srcv(jpr_botm )%clname = 'OBotMlt'
569      IF( TRIM(sn_rcv_iceflx%cldes) == 'coupled' ) THEN
570         IF ( TRIM( sn_rcv_iceflx%clcat ) == 'yes' ) THEN
571            srcv(jpr_topm:jpr_botm)%nct = nn_cats_cpl
572         ELSE
573            CALL ctl_stop( 'sbc_cpl_init: sn_rcv_iceflx%clcat should always be set to yes currently' )
574         ENDIF
575         srcv(jpr_topm:jpr_botm)%laction = .TRUE.
576      ENDIF
577      !                                                      ! ------------------------- !
578      !                                                      !    ice skin temperature   !   
579      !                                                      ! ------------------------- !
580      srcv(jpr_ts_ice)%clname = 'OTsfIce'    ! needed by Met Office
581      IF ( TRIM( sn_rcv_ts_ice%cldes ) == 'ice' )   srcv(jpr_ts_ice)%laction = .TRUE.
582      IF ( TRIM( sn_rcv_ts_ice%clcat ) == 'yes' )   srcv(jpr_ts_ice)%nct     = nn_cats_cpl
583      IF ( TRIM( sn_rcv_emp%clcat    ) == 'yes' )   srcv(jpr_ievp)%nct       = nn_cats_cpl
584
585      !                                                      ! ------------------------- !
586      !                                                      !      Wave breaking        !   
587      !                                                      ! ------------------------- !
588      srcv(jpr_hsig)%clname  = 'O_Hsigwa'    ! significant wave height
589      IF( TRIM(sn_rcv_hsig%cldes  ) == 'coupled' )  THEN
590         srcv(jpr_hsig)%laction = .TRUE.
591         cpl_hsig = .TRUE.
592      ENDIF
593      srcv(jpr_phioc)%clname = 'O_PhiOce'    ! wave to ocean energy
594      IF( TRIM(sn_rcv_phioc%cldes ) == 'coupled' )  THEN
595         srcv(jpr_phioc)%laction = .TRUE.
596         cpl_phioc = .TRUE.
597      ENDIF
598      srcv(jpr_sdrftx)%clname = 'O_Sdrfx'    ! Stokes drift in the u direction
599      IF( TRIM(sn_rcv_sdrfx%cldes ) == 'coupled' )  THEN
600         srcv(jpr_sdrftx)%laction = .TRUE.
601         cpl_sdrftx = .TRUE.
602      ENDIF
603      srcv(jpr_sdrfty)%clname = 'O_Sdrfy'    ! Stokes drift in the v direction
604      IF( TRIM(sn_rcv_sdrfy%cldes ) == 'coupled' )  THEN
605         srcv(jpr_sdrfty)%laction = .TRUE.
606         cpl_sdrfty = .TRUE.
607      ENDIF
608      srcv(jpr_wper)%clname = 'O_WPer'       ! mean wave period
609      IF( TRIM(sn_rcv_wper%cldes  ) == 'coupled' )  THEN
610         srcv(jpr_wper)%laction = .TRUE.
611         cpl_wper = .TRUE.
612      ENDIF
613      srcv(jpr_wfreq)%clname = 'O_WFreq'     ! wave peak frequency
614      IF( TRIM(sn_rcv_wfreq%cldes ) == 'coupled' )  THEN
615         srcv(jpr_wfreq)%laction = .TRUE.
616         cpl_wfreq = .TRUE.
617      ENDIF
618      srcv(jpr_wnum)%clname = 'O_WNum'       ! mean wave number
619      IF( TRIM(sn_rcv_wnum%cldes ) == 'coupled' )  THEN
620         srcv(jpr_wnum)%laction = .TRUE.
621         cpl_wnum = .TRUE.
622      ENDIF
623      srcv(jpr_tauwoc)%clname = 'O_TauOce'   ! stress fraction adsorbed by the wave
624      IF( TRIM(sn_rcv_tauwoc%cldes ) == 'coupled' )  THEN
625         srcv(jpr_tauwoc)%laction = .TRUE.
626         cpl_tauwoc = .TRUE.
627      ENDIF
628      srcv(jpr_tauwx)%clname = 'O_Tauwx'      ! ocean stress from wave in the x direction
629      srcv(jpr_tauwy)%clname = 'O_Tauwy'      ! ocean stress from wave in the y direction
630      IF( TRIM(sn_rcv_tauw%cldes ) == 'coupled' )  THEN
631         srcv(jpr_tauwx)%laction = .TRUE.
632         srcv(jpr_tauwy)%laction = .TRUE.
633         cpl_tauw = .TRUE.
634      ENDIF
635      srcv(jpr_wdrag)%clname = 'O_WDrag'     ! neutral surface drag coefficient
636      IF( TRIM(sn_rcv_wdrag%cldes ) == 'coupled' )  THEN
637         srcv(jpr_wdrag)%laction = .TRUE.
638         cpl_wdrag = .TRUE.
639      ENDIF
640      IF( srcv(jpr_tauwoc)%laction .AND. srcv(jpr_tauwx)%laction .AND. srcv(jpr_tauwy)%laction ) &
641            CALL ctl_stop( 'More than one method for modifying the ocean stress has been selected ', &
642                                     '(sn_rcv_tauwoc=coupled and sn_rcv_tauw=coupled)' )
643      !
644      !                                                      ! ------------------------------- !
645      !                                                      !   OPA-SAS coupling - rcv by opa !   
646      !                                                      ! ------------------------------- !
647      srcv(jpr_sflx)%clname = 'O_SFLX'
648      srcv(jpr_fice)%clname = 'RIceFrc'
649      !
650      IF( nn_components == jp_iam_opa ) THEN    ! OPA coupled to SAS via OASIS: force received field by OPA (sent by SAS)
651         srcv(:)%laction = .FALSE.   ! force default definition in case of opa <-> sas coupling
652         srcv(:)%clgrid  = 'T'       ! force default definition in case of opa <-> sas coupling
653         srcv(:)%nsgn    = 1.        ! force default definition in case of opa <-> sas coupling
654         srcv( (/jpr_qsroce, jpr_qnsoce, jpr_oemp, jpr_sflx, jpr_fice, jpr_otx1, jpr_oty1, jpr_taum/) )%laction = .TRUE.
655         srcv(jpr_otx1)%clgrid = 'U'        ! oce components given at U-point
656         srcv(jpr_oty1)%clgrid = 'V'        !           and           V-point
657         ! Vectors: change of sign at north fold ONLY if on the local grid
658         srcv( (/jpr_otx1,jpr_oty1/) )%nsgn = -1.
659         sn_rcv_tau%clvgrd = 'U,V'
660         sn_rcv_tau%clvor = 'local grid'
661         sn_rcv_tau%clvref = 'spherical'
662         sn_rcv_emp%cldes = 'oce only'
663         !
664         IF(lwp) THEN                        ! control print
665            WRITE(numout,*)
666            WRITE(numout,*)'               Special conditions for SAS-OPA coupling  '
667            WRITE(numout,*)'               OPA component  '
668            WRITE(numout,*)
669            WRITE(numout,*)'  received fields from SAS component '
670            WRITE(numout,*)'                  ice cover '
671            WRITE(numout,*)'                  oce only EMP  '
672            WRITE(numout,*)'                  salt flux  '
673            WRITE(numout,*)'                  mixed oce-ice solar flux  '
674            WRITE(numout,*)'                  mixed oce-ice non solar flux  '
675            WRITE(numout,*)'                  wind stress U,V on local grid and sperical coordinates '
676            WRITE(numout,*)'                  wind stress module'
677            WRITE(numout,*)
678         ENDIF
679      ENDIF
680      !                                                      ! -------------------------------- !
681      !                                                      !   OPA-SAS coupling - rcv by sas  !   
682      !                                                      ! -------------------------------- !
683      srcv(jpr_toce  )%clname = 'I_SSTSST'
684      srcv(jpr_soce  )%clname = 'I_SSSal'
685      srcv(jpr_ocx1  )%clname = 'I_OCurx1'
686      srcv(jpr_ocy1  )%clname = 'I_OCury1'
687      srcv(jpr_ssh   )%clname = 'I_SSHght'
688      srcv(jpr_e3t1st)%clname = 'I_E3T1st'   
689      srcv(jpr_fraqsr)%clname = 'I_FraQsr'   
690      !
691      IF( nn_components == jp_iam_sas ) THEN
692         IF( .NOT. ln_cpl ) srcv(:)%laction = .FALSE.   ! force default definition in case of opa <-> sas coupling
693         IF( .NOT. ln_cpl ) srcv(:)%clgrid  = 'T'       ! force default definition in case of opa <-> sas coupling
694         IF( .NOT. ln_cpl ) srcv(:)%nsgn    = 1.        ! force default definition in case of opa <-> sas coupling
695         srcv( (/jpr_toce, jpr_soce, jpr_ssh, jpr_fraqsr, jpr_ocx1, jpr_ocy1/) )%laction = .TRUE.
696         srcv( jpr_e3t1st )%laction = .NOT.ln_linssh
697         srcv(jpr_ocx1)%clgrid = 'U'        ! oce components given at U-point
698         srcv(jpr_ocy1)%clgrid = 'V'        !           and           V-point
699         ! Vectors: change of sign at north fold ONLY if on the local grid
700         srcv(jpr_ocx1:jpr_ocy1)%nsgn = -1.
701         ! Change first letter to couple with atmosphere if already coupled OPA
702         ! this is nedeed as each variable name used in the namcouple must be unique:
703         ! for example O_Runoff received by OPA from SAS and therefore O_Runoff received by SAS from the Atmosphere
704         DO jn = 1, jprcv
705            IF ( srcv(jn)%clname(1:1) == "O" ) srcv(jn)%clname = "S"//srcv(jn)%clname(2:LEN(srcv(jn)%clname))
706         END DO
707         !
708         IF(lwp) THEN                        ! control print
709            WRITE(numout,*)
710            WRITE(numout,*)'               Special conditions for SAS-OPA coupling  '
711            WRITE(numout,*)'               SAS component  '
712            WRITE(numout,*)
713            IF( .NOT. ln_cpl ) THEN
714               WRITE(numout,*)'  received fields from OPA component '
715            ELSE
716               WRITE(numout,*)'  Additional received fields from OPA component : '
717            ENDIF
718            WRITE(numout,*)'               sea surface temperature (Celsius) '
719            WRITE(numout,*)'               sea surface salinity ' 
720            WRITE(numout,*)'               surface currents ' 
721            WRITE(numout,*)'               sea surface height ' 
722            WRITE(numout,*)'               thickness of first ocean T level '       
723            WRITE(numout,*)'               fraction of solar net radiation absorbed in the first ocean level'
724            WRITE(numout,*)
725         ENDIF
726      ENDIF
727
728
729      IF (ln_couple_test) THEN
730         ! If we're just running a test coupled job then set all
731         ! actions to false for all fields apart from our test field(s)
732         srcv(:)%laction = .FALSE.
733
734
735         srcv(jpr_dummy_t)%clname = 'R_OC_DUMMY_T'   
736         srcv(jpr_dummy_t)%laction = .TRUE.
737      ENDIF
738
739      ! =================================================== !
740      ! Allocate all parts of frcv used for received fields !
741      ! =================================================== !
742      DO jn = 1, jprcv
743         IF ( srcv(jn)%laction ) ALLOCATE( frcv(jn)%z3(jpi,jpj,srcv(jn)%nct) )
744      END DO
745      ! Allocate taum part of frcv which is used even when not received as coupling field
746      IF ( .NOT. srcv(jpr_taum)%laction ) ALLOCATE( frcv(jpr_taum)%z3(jpi,jpj,srcv(jpr_taum)%nct) )
747      ! Allocate w10m part of frcv which is used even when not received as coupling field
748      IF ( .NOT. srcv(jpr_w10m)%laction ) ALLOCATE( frcv(jpr_w10m)%z3(jpi,jpj,srcv(jpr_w10m)%nct) )
749      ! Allocate jpr_otx1 part of frcv which is used even when not received as coupling field
750      IF ( .NOT. srcv(jpr_otx1)%laction ) ALLOCATE( frcv(jpr_otx1)%z3(jpi,jpj,srcv(jpr_otx1)%nct) )
751      IF ( .NOT. srcv(jpr_oty1)%laction ) ALLOCATE( frcv(jpr_oty1)%z3(jpi,jpj,srcv(jpr_oty1)%nct) )
752      ! Allocate itx1 and ity1 as they are used in sbc_cpl_ice_tau even if srcv(jpr_itx1)%laction = .FALSE.
753      IF( k_ice /= 0 ) THEN
754         IF ( .NOT. srcv(jpr_itx1)%laction ) ALLOCATE( frcv(jpr_itx1)%z3(jpi,jpj,srcv(jpr_itx1)%nct) )
755         IF ( .NOT. srcv(jpr_ity1)%laction ) ALLOCATE( frcv(jpr_ity1)%z3(jpi,jpj,srcv(jpr_ity1)%nct) )
756      END IF
757
758
759
760
761
762      ! ================================ !
763      !     Define the send interface    !
764      ! ================================ !
765      ! for each field: define the OASIS name                           (ssnd(:)%clname)
766      !                 define send or not from the namelist parameters (ssnd(:)%laction)
767      !                 define the north fold type of lbc               (ssnd(:)%nsgn)
768     
769      ! default definitions of nsnd
770      ssnd(:)%laction = .FALSE.   ;   ssnd(:)%clgrid = 'T'   ;   ssnd(:)%nsgn = 1.  ; ssnd(:)%nct = 1
771         
772      !                                                      ! ------------------------- !
773      !                                                      !    Surface temperature    !
774      !                                                      ! ------------------------- !
775      ssnd(jps_toce)%clname   = 'O_SSTSST'
776      ssnd(jps_tice)%clname   = 'O_TepIce'
777      ssnd(jps_ttilyr)%clname = 'O_TtiLyr'
778      ssnd(jps_tmix)%clname   = 'O_TepMix'
779      SELECT CASE( TRIM( sn_snd_temp%cldes ) )
780      CASE( 'none'                                 )       ! nothing to do
781      CASE( 'oce only'                             )   ;   ssnd( jps_toce )%laction = .TRUE.
782      CASE( 'oce and ice' , 'weighted oce and ice' , 'oce and weighted ice' )
783         ssnd( (/jps_toce, jps_tice/) )%laction = .TRUE.
784         IF ( TRIM( sn_snd_temp%clcat ) == 'yes' )  ssnd(jps_tice)%nct = nn_cats_cpl
785      CASE( 'mixed oce-ice'                        )   ;   ssnd( jps_tmix )%laction = .TRUE.
786      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_temp%cldes' )
787      END SELECT
788           
789      !                                                      ! ------------------------- !
790      !                                                      !          Albedo           !
791      !                                                      ! ------------------------- !
792      ssnd(jps_albice)%clname = 'O_AlbIce' 
793      ssnd(jps_albmix)%clname = 'O_AlbMix'
794      SELECT CASE( TRIM( sn_snd_alb%cldes ) )
795      CASE( 'none'                 )     ! nothing to do
796      CASE( 'ice' , 'weighted ice' )   ; ssnd(jps_albice)%laction = .TRUE.
797      CASE( 'mixed oce-ice'        )   ; ssnd(jps_albmix)%laction = .TRUE.
798      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_alb%cldes' )
799      END SELECT
800      !
801      ! Need to calculate oceanic albedo if
802      !     1. sending mixed oce-ice albedo or
803      !     2. receiving mixed oce-ice solar radiation
804      IF ( TRIM ( sn_snd_alb%cldes ) == 'mixed oce-ice' .OR. TRIM ( sn_rcv_qsr%cldes ) == 'mixed oce-ice' ) THEN
805         CALL oce_alb( zaos, zacs )
806         ! Due to lack of information on nebulosity : mean clear/overcast sky
807         alb_oce_mix(:,:) = ( zacs(:,:) + zaos(:,:) ) * 0.5
808      ENDIF
809      !                                                      ! ------------------------- !
810      !                                                      !  Ice fraction & Thickness !
811      !                                                      ! ------------------------- !
812      ssnd(jps_fice)%clname  = 'OIceFrc'
813      ssnd(jps_ficet)%clname = 'OIceFrcT' 
814      ssnd(jps_hice)%clname  = 'OIceTck'
815      ssnd(jps_a_p)%clname   = 'OPndFrc'
816      ssnd(jps_ht_p)%clname  = 'OPndTck'
817      ssnd(jps_hsnw)%clname  = 'OSnwTck'
818      ssnd(jps_fice1)%clname = 'OIceFrd'
819      IF( k_ice /= 0 ) THEN
820         ssnd(jps_fice)%laction  = .TRUE.                 ! if ice treated in the ocean (even in climato case)
821         ssnd(jps_fice1)%laction = .TRUE.                 ! First-order regridded ice concentration, to be used producing atmos-to-ice fluxes (Met Office requirement)
822! Currently no namelist entry to determine sending of multi-category ice fraction so use the thickness entry for now
823         IF ( TRIM( sn_snd_thick%clcat  ) == 'yes' ) ssnd(jps_fice)%nct  = nn_cats_cpl
824         IF ( TRIM( sn_snd_thick1%clcat ) == 'yes' ) ssnd(jps_fice1)%nct = nn_cats_cpl
825      ENDIF
826     
827      IF (TRIM( sn_snd_ifrac%cldes )  == 'coupled') ssnd(jps_ficet)%laction = .TRUE. 
828
829      SELECT CASE ( TRIM( sn_snd_thick%cldes ) )
830      CASE( 'none'         )       ! nothing to do
831      CASE( 'ice and snow' ) 
832         ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
833         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) THEN
834            ssnd(jps_hice:jps_hsnw)%nct = nn_cats_cpl
835         ENDIF
836      CASE ( 'weighted ice and snow' ) 
837         ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
838         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_hice:jps_hsnw)%nct = nn_cats_cpl
839      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_thick%cldes' )
840      END SELECT
841
842      !                                                      ! ------------------------- !
843      !                                                      !      Ice Meltponds        !
844      !                                                      ! ------------------------- !
845      ! Needed by Met Office
846      ssnd(jps_a_p)%clname  = 'OPndFrc'   
847      ssnd(jps_ht_p)%clname = 'OPndTck'   
848      SELECT CASE ( TRIM( sn_snd_mpnd%cldes ) ) 
849      CASE ( 'none' ) 
850         ssnd(jps_a_p)%laction  = .FALSE. 
851         ssnd(jps_ht_p)%laction = .FALSE. 
852      CASE ( 'ice only' ) 
853         ssnd(jps_a_p)%laction  = .TRUE. 
854         ssnd(jps_ht_p)%laction = .TRUE. 
855         IF ( TRIM( sn_snd_mpnd%clcat ) == 'yes' ) THEN
856            ssnd(jps_a_p)%nct  = nn_cats_cpl 
857            ssnd(jps_ht_p)%nct = nn_cats_cpl 
858         ELSE
859            IF ( nn_cats_cpl > 1 ) THEN
860               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_mpnd%cldes if not exchanging category fields' ) 
861            ENDIF
862         ENDIF
863      CASE ( 'weighted ice' ) 
864         ssnd(jps_a_p)%laction  = .TRUE. 
865         ssnd(jps_ht_p)%laction = .TRUE. 
866         IF ( TRIM( sn_snd_mpnd%clcat ) == 'yes' ) THEN
867            ssnd(jps_a_p)%nct  = nn_cats_cpl 
868            ssnd(jps_ht_p)%nct = nn_cats_cpl 
869         ENDIF
870      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_mpnd%cldes; '//sn_snd_mpnd%cldes ) 
871      END SELECT 
872 
873      !                                                      ! ------------------------- !
874      !                                                      !      Surface current      !
875      !                                                      ! ------------------------- !
876      !        ocean currents              !            ice velocities
877      ssnd(jps_ocx1)%clname = 'O_OCurx1'   ;   ssnd(jps_ivx1)%clname = 'O_IVelx1'
878      ssnd(jps_ocy1)%clname = 'O_OCury1'   ;   ssnd(jps_ivy1)%clname = 'O_IVely1'
879      ssnd(jps_ocz1)%clname = 'O_OCurz1'   ;   ssnd(jps_ivz1)%clname = 'O_IVelz1'
880      ssnd(jps_ocxw)%clname = 'O_OCurxw' 
881      ssnd(jps_ocyw)%clname = 'O_OCuryw' 
882      !
883      ssnd(jps_ocx1:jps_ivz1)%nsgn = -1.   ! vectors: change of the sign at the north fold
884
885      IF( sn_snd_crt%clvgrd == 'U,V' ) THEN
886         ssnd(jps_ocx1)%clgrid = 'U' ; ssnd(jps_ocy1)%clgrid = 'V'
887      ELSE IF( sn_snd_crt%clvgrd /= 'T' ) THEN 
888         CALL ctl_stop( 'sn_snd_crt%clvgrd must be equal to T' )
889         ssnd(jps_ocx1:jps_ivz1)%clgrid  = 'T'      ! all oce and ice components on the same unique grid
890      ENDIF
891      ssnd(jps_ocx1:jps_ivz1)%laction = .TRUE.   ! default: all are send
892      IF( TRIM( sn_snd_crt%clvref ) == 'spherical' )   ssnd( (/jps_ocz1, jps_ivz1/) )%laction = .FALSE. 
893      IF( TRIM( sn_snd_crt%clvor ) == 'eastward-northward' ) ssnd(jps_ocx1:jps_ivz1)%nsgn = 1.
894      SELECT CASE( TRIM( sn_snd_crt%cldes ) )
895      CASE( 'none'                 )   ;   ssnd(jps_ocx1:jps_ivz1)%laction = .FALSE.
896      CASE( 'oce only'             )   ;   ssnd(jps_ivx1:jps_ivz1)%laction = .FALSE.
897      CASE( 'weighted oce and ice' )   !   nothing to do
898      CASE( 'mixed oce-ice'        )   ;   ssnd(jps_ivx1:jps_ivz1)%laction = .FALSE.
899      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_crt%cldes' )
900      END SELECT
901
902      ssnd(jps_ocxw:jps_ocyw)%nsgn = -1.   ! vectors: change of the sign at the north fold
903       
904      IF( sn_snd_crtw%clvgrd == 'U,V' ) THEN
905         ssnd(jps_ocxw)%clgrid = 'U' ; ssnd(jps_ocyw)%clgrid = 'V' 
906      ELSE IF( sn_snd_crtw%clvgrd /= 'T' ) THEN
907         CALL ctl_stop( 'sn_snd_crtw%clvgrd must be equal to T' ) 
908      ENDIF
909      IF( TRIM( sn_snd_crtw%clvor ) == 'eastward-northward' ) ssnd(jps_ocxw:jps_ocyw)%nsgn = 1. 
910      SELECT CASE( TRIM( sn_snd_crtw%cldes ) ) 
911         CASE( 'none'                 )   ; ssnd(jps_ocxw:jps_ocyw)%laction = .FALSE. 
912         CASE( 'oce only'             )   ; ssnd(jps_ocxw:jps_ocyw)%laction = .TRUE. 
913         CASE( 'weighted oce and ice' )   !   nothing to do
914         CASE( 'mixed oce-ice'        )   ; ssnd(jps_ivx1:jps_ivz1)%laction = .FALSE. 
915         CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_crtw%cldes' ) 
916      END SELECT 
917
918      !                                                      ! ------------------------- !
919      !                                                      !          CO2 flux         !
920      !                                                      ! ------------------------- !
921      ssnd(jps_co2)%clname = 'O_CO2FLX' ;  IF( TRIM(sn_snd_co2%cldes) == 'coupled' )    ssnd(jps_co2 )%laction = .TRUE.
922      !
923      !                                                      ! ------------------------- !
924      !                                                      ! Sea surface freezing temp !
925      !                                                      ! ------------------------- !
926      ! needed by Met Office
927      ssnd(jps_sstfrz)%clname = 'O_SSTFrz' ; IF( TRIM(sn_snd_sstfrz%cldes) == 'coupled' )  ssnd(jps_sstfrz)%laction = .TRUE. 
928      !
929      !                                                      ! ------------------------- !
930      !                                                      !    Ice conductivity       !
931      !                                                      ! ------------------------- !
932      ! needed by Met Office
933      ! Note that ultimately we will move to passing an ocean effective conductivity as well so there
934      ! will be some changes to the parts of the code which currently relate only to ice conductivity
935      ssnd(jps_ttilyr )%clname = 'O_TtiLyr' 
936      SELECT CASE ( TRIM( sn_snd_ttilyr%cldes ) ) 
937      CASE ( 'none' ) 
938         ssnd(jps_ttilyr)%laction = .FALSE. 
939      CASE ( 'ice only' ) 
940         ssnd(jps_ttilyr)%laction = .TRUE. 
941         IF ( TRIM( sn_snd_ttilyr%clcat ) == 'yes' ) THEN
942            ssnd(jps_ttilyr)%nct = nn_cats_cpl 
943         ELSE
944            IF ( nn_cats_cpl > 1 ) THEN
945               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_ttilyr%cldes if not exchanging category fields' ) 
946            ENDIF
947         ENDIF
948      CASE ( 'weighted ice' ) 
949         ssnd(jps_ttilyr)%laction = .TRUE. 
950         IF ( TRIM( sn_snd_ttilyr%clcat ) == 'yes' ) ssnd(jps_ttilyr)%nct = nn_cats_cpl 
951      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_ttilyr%cldes;'//sn_snd_ttilyr%cldes ) 
952      END SELECT
953
954      ssnd(jps_kice )%clname = 'OIceKn' 
955      SELECT CASE ( TRIM( sn_snd_cond%cldes ) ) 
956      CASE ( 'none' ) 
957         ssnd(jps_kice)%laction = .FALSE. 
958      CASE ( 'ice only' ) 
959         ssnd(jps_kice)%laction = .TRUE. 
960         IF ( TRIM( sn_snd_cond%clcat ) == 'yes' ) THEN
961            ssnd(jps_kice)%nct = nn_cats_cpl 
962         ELSE
963            IF ( nn_cats_cpl > 1 ) THEN
964               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_cond%cldes if not exchanging category fields' ) 
965            ENDIF
966         ENDIF
967      CASE ( 'weighted ice' ) 
968         ssnd(jps_kice)%laction = .TRUE. 
969         IF ( TRIM( sn_snd_cond%clcat ) == 'yes' ) ssnd(jps_kice)%nct = nn_cats_cpl 
970      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_cond%cldes;'//sn_snd_cond%cldes ) 
971      END SELECT 
972      !
973      !                                                      ! ------------------------- !
974      !                                                      !     Sea surface height    !
975      !                                                      ! ------------------------- !
976      ssnd(jps_wlev)%clname = 'O_Wlevel' ;  IF( TRIM(sn_snd_wlev%cldes) == 'coupled' )   ssnd(jps_wlev)%laction = .TRUE. 
977
978      !                                                      ! ------------------------------- !
979      !                                                      !   OPA-SAS coupling - snd by opa !   
980      !                                                      ! ------------------------------- !
981      ssnd(jps_ssh   )%clname = 'O_SSHght' 
982      ssnd(jps_soce  )%clname = 'O_SSSal' 
983      ssnd(jps_e3t1st)%clname = 'O_E3T1st'   
984      ssnd(jps_fraqsr)%clname = 'O_FraQsr'
985      !
986      IF( nn_components == jp_iam_opa ) THEN
987         ssnd(:)%laction = .FALSE.   ! force default definition in case of opa <-> sas coupling
988         ssnd( (/jps_toce, jps_soce, jps_ssh, jps_fraqsr, jps_ocx1, jps_ocy1/) )%laction = .TRUE.
989         ssnd( jps_e3t1st )%laction = .NOT.ln_linssh
990         ! vector definition: not used but cleaner...
991         ssnd(jps_ocx1)%clgrid  = 'U'        ! oce components given at U-point
992         ssnd(jps_ocy1)%clgrid  = 'V'        !           and           V-point
993         sn_snd_crt%clvgrd = 'U,V'
994         sn_snd_crt%clvor = 'local grid'
995         sn_snd_crt%clvref = 'spherical'
996         !
997         IF(lwp) THEN                        ! control print
998            WRITE(numout,*)
999            WRITE(numout,*)'  sent fields to SAS component '
1000            WRITE(numout,*)'               sea surface temperature (T before, Celsius) '
1001            WRITE(numout,*)'               sea surface salinity ' 
1002            WRITE(numout,*)'               surface currents U,V on local grid and spherical coordinates' 
1003            WRITE(numout,*)'               sea surface height ' 
1004            WRITE(numout,*)'               thickness of first ocean T level '       
1005            WRITE(numout,*)'               fraction of solar net radiation absorbed in the first ocean level'
1006            WRITE(numout,*)
1007         ENDIF
1008      ENDIF
1009      !                                                      ! ------------------------------- !
1010      !                                                      !   OPA-SAS coupling - snd by sas !   
1011      !                                                      ! ------------------------------- !
1012      ssnd(jps_sflx  )%clname = 'I_SFLX'     
1013      ssnd(jps_fice2 )%clname = 'IIceFrc'
1014      ssnd(jps_qsroce)%clname = 'I_QsrOce'   
1015      ssnd(jps_qnsoce)%clname = 'I_QnsOce'   
1016      ssnd(jps_oemp  )%clname = 'IOEvaMPr' 
1017      ssnd(jps_otx1  )%clname = 'I_OTaux1'   
1018      ssnd(jps_oty1  )%clname = 'I_OTauy1'   
1019      ssnd(jps_rnf   )%clname = 'I_Runoff'   
1020      ssnd(jps_taum  )%clname = 'I_TauMod'   
1021      !
1022      IF( nn_components == jp_iam_sas ) THEN
1023         IF( .NOT. ln_cpl ) ssnd(:)%laction = .FALSE.   ! force default definition in case of opa <-> sas coupling
1024         ssnd( (/jps_qsroce, jps_qnsoce, jps_oemp, jps_fice2, jps_sflx, jps_otx1, jps_oty1, jps_taum/) )%laction = .TRUE.
1025         !
1026         ! Change first letter to couple with atmosphere if already coupled with sea_ice
1027         ! this is nedeed as each variable name used in the namcouple must be unique:
1028         ! for example O_SSTSST sent by OPA to SAS and therefore S_SSTSST sent by SAS to the Atmosphere
1029         DO jn = 1, jpsnd
1030            IF ( ssnd(jn)%clname(1:1) == "O" ) ssnd(jn)%clname = "S"//ssnd(jn)%clname(2:LEN(ssnd(jn)%clname))
1031         END DO
1032         !
1033         IF(lwp) THEN                        ! control print
1034            WRITE(numout,*)
1035            IF( .NOT. ln_cpl ) THEN
1036               WRITE(numout,*)'  sent fields to OPA component '
1037            ELSE
1038               WRITE(numout,*)'  Additional sent fields to OPA component : '
1039            ENDIF
1040            WRITE(numout,*)'                  ice cover '
1041            WRITE(numout,*)'                  oce only EMP  '
1042            WRITE(numout,*)'                  salt flux  '
1043            WRITE(numout,*)'                  mixed oce-ice solar flux  '
1044            WRITE(numout,*)'                  mixed oce-ice non solar flux  '
1045            WRITE(numout,*)'                  wind stress U,V components'
1046            WRITE(numout,*)'                  wind stress module'
1047         ENDIF
1048      ENDIF
1049
1050      IF (ln_couple_test) THEN
1051         ! If we're just running a test coupled job then set all
1052         ! actions to false for all fields apart from our test field(s)
1053         ssnd(:)%laction = .FALSE.
1054
1055
1056         ssnd(jps_dummy_t)%clname = 'S_OC_DUMMY_T'   
1057         ssnd(jps_dummy_t)%laction = .TRUE.
1058      ENDIF
1059
1060
1061      !
1062      ! ================================ !
1063      !   initialisation of the coupler  !
1064      ! ================================ !
1065
1066      ! If ln_cpl is false, clearly we don't want to call cpl_dfine!
1067      IF (ln_cpl .OR. ln_couple_test) THEN
1068           write(numout,*) "RSRH call cpl_define", ln_cpl ,ln_couple_test ; flush(numout)
1069         CALL cpl_define(jprcv, jpsnd, nn_cplmodel)
1070
1071      ENDIF     
1072           write(numout,*) "RSRH after cpl_define", ln_cpl ,ln_couple_test ; flush(numout)
1073
1074
1075      IF (ln_usecplmask) THEN
1076         xcplmask(:,:,:) = 0.
1077         CALL iom_open( 'cplmask', inum )
1078         CALL iom_get( inum, jpdom_unknown, 'cplmask', xcplmask(1:nlci,1:nlcj,1:nn_cplmodel),   &
1079            &          kstart = (/ mig(1),mjg(1),1 /), kcount = (/ nlci,nlcj,nn_cplmodel /) )
1080         CALL iom_close( inum )
1081      ELSE
1082         xcplmask(:,:,:) = 1.
1083      ENDIF
1084      xcplmask(:,:,0) = 1. - SUM( xcplmask(:,:,1:nn_cplmodel), dim = 3 )
1085      !
1086      ncpl_qsr_freq = cpl_freq( 'O_QsrOce' ) + cpl_freq( 'O_QsrMix' ) + cpl_freq( 'I_QsrOce' ) + cpl_freq( 'I_QsrMix' )
1087      IF( ln_dm2dc .AND. ln_cpl .AND. ncpl_qsr_freq /= 86400 )   &
1088         &   CALL ctl_stop( 'sbc_cpl_init: diurnal cycle reconstruction (ln_dm2dc) needs daily couping for solar radiation' )
1089      IF( ln_dm2dc .AND. ln_cpl ) ncpl_qsr_freq = 86400 / ncpl_qsr_freq
1090      !
1091   END SUBROUTINE sbc_cpl_init
1092
1093
1094   SUBROUTINE sbc_cpl_rcv( kt, k_fsbc, k_ice )     
1095      !!----------------------------------------------------------------------
1096      !!             ***  ROUTINE sbc_cpl_rcv  ***
1097      !!
1098      !! ** Purpose :   provide the stress over the ocean and, if no sea-ice,
1099      !!                provide the ocean heat and freshwater fluxes.
1100      !!
1101      !! ** Method  : - Receive all the atmospheric fields (stored in frcv array). called at each time step.
1102      !!                OASIS controls if there is something do receive or not. nrcvinfo contains the info
1103      !!                to know if the field was really received or not
1104      !!
1105      !!              --> If ocean stress was really received:
1106      !!
1107      !!                  - transform the received ocean stress vector from the received
1108      !!                 referential and grid into an atmosphere-ocean stress in
1109      !!                 the (i,j) ocean referencial and at the ocean velocity point.
1110      !!                    The received stress are :
1111      !!                     - defined by 3 components (if cartesian coordinate)
1112      !!                            or by 2 components (if spherical)
1113      !!                     - oriented along geographical   coordinate (if eastward-northward)
1114      !!                            or  along the local grid coordinate (if local grid)
1115      !!                     - given at U- and V-point, resp.   if received on 2 grids
1116      !!                            or at T-point               if received on 1 grid
1117      !!                    Therefore and if necessary, they are successively
1118      !!                  processed in order to obtain them
1119      !!                     first  as  2 components on the sphere
1120      !!                     second as  2 components oriented along the local grid
1121      !!                     third  as  2 components on the U,V grid
1122      !!
1123      !!              -->
1124      !!
1125      !!              - In 'ocean only' case, non solar and solar ocean heat fluxes
1126      !!             and total ocean freshwater fluxes 
1127      !!
1128      !! ** Method  :   receive all fields from the atmosphere and transform
1129      !!              them into ocean surface boundary condition fields
1130      !!
1131      !! ** Action  :   update  utau, vtau   ocean stress at U,V grid
1132      !!                        taum         wind stress module at T-point
1133      !!                        wndm         wind speed  module at T-point over free ocean or leads in presence of sea-ice
1134      !!                        qns          non solar heat fluxes including emp heat content    (ocean only case)
1135      !!                                     and the latent heat flux of solid precip. melting
1136      !!                        qsr          solar ocean heat fluxes   (ocean only case)
1137      !!                        emp          upward mass flux [evap. - precip. (- runoffs) (- calving)] (ocean only case)
1138      !!----------------------------------------------------------------------
1139      USE zdf_oce,  ONLY :   ln_zdfswm
1140      !
1141      INTEGER, INTENT(in) ::   kt          ! ocean model time step index
1142      INTEGER, INTENT(in) ::   k_fsbc      ! frequency of sbc (-> ice model) computation
1143      INTEGER, INTENT(in) ::   k_ice       ! ice management in the sbc (=0/1/2/3)
1144      !!
1145      LOGICAL  ::   llnewtx, llnewtau      ! update wind stress components and module??
1146      INTEGER  ::   ji, jj, jn             ! dummy loop indices
1147      INTEGER  ::   isec                   ! number of seconds since nit000 (assuming rdttra did not change since nit000)
1148      INTEGER  ::   ikchoix
1149      REAL(wp) ::   zcumulneg, zcumulpos   ! temporary scalars     
1150      REAL(wp) ::   zcoef                  ! temporary scalar
1151      REAL(wp) ::   zrhoa  = 1.22          ! Air density kg/m3
1152      REAL(wp) ::   zcdrag = 1.5e-3        ! drag coefficient
1153      REAL(wp) ::   zzx, zzy               ! temporary variables
1154      REAL(wp), DIMENSION(jpi,jpj) ::   ztx, zty, zmsk, zemp, zqns, zqsr, ztx2, zty2
1155      !!----------------------------------------------------------------------
1156      !
1157      IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
1158      !
1159      !                                                      ! ======================================================= !
1160      !                                                      ! Receive all the atmos. fields (including ice information)
1161      !                                                      ! ======================================================= !
1162      isec = ( kt - nit000 ) * NINT( rdt )                      ! date of exchanges
1163
1164
1165      WRITE(numout,*) "RSRH in sbc_cpl_rcv" ; flush(numout)
1166
1167      DO jn = 1, jprcv                                          ! received fields sent by the atmosphere
1168
1169        WRITE(numout,*) "RSRH in sbc_cpl_rcv for field" ,jn, srcv(jn)%laction ;flush(numout)
1170
1171         IF( srcv(jn)%laction ) THEN
1172        WRITE(numout,*) "RSRH call cpl_rcv for field", jn, srcv(jn)%laction ;flush(numout)
1173               CALL cpl_rcv( jn, isec, frcv(jn)%z3, xcplmask(:,:,1:nn_cplmodel), nrcvinfo(jn) )
1174        WRITE(numout,*) "RSRH  done cpl_rcv for field", jn, srcv(jn)%laction, nrcvinfo(jn) ;flush(numout)
1175         ENDIF
1176      END DO
1177
1178      WRITE(numout,*) "RSRH in sbc_cpl_rcv after all gets" ; flush(numout)
1179      !                                                      ! ========================= !
1180      IF( srcv(jpr_otx1)%laction ) THEN                      !  ocean stress components  !
1181         !                                                   ! ========================= !
1182         ! define frcv(jpr_otx1)%z3(:,:,1) and frcv(jpr_oty1)%z3(:,:,1): stress at U/V point along model grid
1183         ! => need to be done only when we receive the field
1184         IF(  nrcvinfo(jpr_otx1) == OASIS_Rcv ) THEN
1185            !
1186            IF( TRIM( sn_rcv_tau%clvref ) == 'cartesian' ) THEN            ! 2 components on the sphere
1187               !                                                       ! (cartesian to spherical -> 3 to 2 components)
1188               !
1189               CALL geo2oce( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), frcv(jpr_otz1)%z3(:,:,1),   &
1190                  &          srcv(jpr_otx1)%clgrid, ztx, zty )
1191               frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 1st grid
1192               frcv(jpr_oty1)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 1st grid
1193               !
1194               IF( srcv(jpr_otx2)%laction ) THEN
1195                  CALL geo2oce( frcv(jpr_otx2)%z3(:,:,1), frcv(jpr_oty2)%z3(:,:,1), frcv(jpr_otz2)%z3(:,:,1),   &
1196                     &          srcv(jpr_otx2)%clgrid, ztx, zty )
1197                  frcv(jpr_otx2)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 2nd grid
1198                  frcv(jpr_oty2)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 2nd grid
1199               ENDIF
1200               !
1201            ENDIF
1202            !
1203            IF( TRIM( sn_rcv_tau%clvor ) == 'eastward-northward' ) THEN   ! 2 components oriented along the local grid
1204               !                                                       ! (geographical to local grid -> rotate the components)
1205               IF( srcv(jpr_otx1)%clgrid == 'U' .AND. (.NOT. srcv(jpr_otx2)%laction) ) THEN
1206                  ! Temporary code for HadGEM3 - will be removed eventually.
1207        ! Only applies when we have only taux on U grid and tauy on V grid
1208             DO jj=2,jpjm1
1209                DO ji=2,jpim1
1210                     ztx(ji,jj)=0.25*vmask(ji,jj,1)                &
1211                        *(frcv(jpr_otx1)%z3(ji,jj,1)+frcv(jpr_otx1)%z3(ji-1,jj,1)    &
1212                        +frcv(jpr_otx1)%z3(ji,jj+1,1)+frcv(jpr_otx1)%z3(ji-1,jj+1,1))
1213                     zty(ji,jj)=0.25*umask(ji,jj,1)                &
1214                        *(frcv(jpr_oty1)%z3(ji,jj,1)+frcv(jpr_oty1)%z3(ji+1,jj,1)    &
1215                        +frcv(jpr_oty1)%z3(ji,jj-1,1)+frcv(jpr_oty1)%z3(ji+1,jj-1,1))
1216                ENDDO
1217             ENDDO
1218                   
1219             ikchoix = 1
1220             CALL repcmo (frcv(jpr_otx1)%z3(:,:,1),zty,ztx,frcv(jpr_oty1)%z3(:,:,1),ztx2,zty2,ikchoix)
1221             CALL lbc_lnk ('jpr_otx1', ztx2,'U', -1. )
1222             CALL lbc_lnk ('jpr_oty1', zty2,'V', -1. )
1223             frcv(jpr_otx1)%z3(:,:,1)=ztx2(:,:)
1224             frcv(jpr_oty1)%z3(:,:,1)=zty2(:,:)
1225          ELSE
1226             CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->i', ztx )   
1227             frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
1228             IF( srcv(jpr_otx2)%laction ) THEN
1229                CALL rot_rep( frcv(jpr_otx2)%z3(:,:,1), frcv(jpr_oty2)%z3(:,:,1), srcv(jpr_otx2)%clgrid, 'en->j', zty )   
1230             ELSE
1231                CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->j', zty ) 
1232             ENDIF
1233          frcv(jpr_oty1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 2nd grid 
1234               ENDIF
1235            ENDIF
1236            !                             
1237            IF( srcv(jpr_otx1)%clgrid == 'T' ) THEN
1238               DO jj = 2, jpjm1                                          ! T ==> (U,V)
1239                  DO ji = fs_2, fs_jpim1   ! vector opt.
1240                     frcv(jpr_otx1)%z3(ji,jj,1) = 0.5 * ( frcv(jpr_otx1)%z3(ji+1,jj  ,1) + frcv(jpr_otx1)%z3(ji,jj,1) )
1241                     frcv(jpr_oty1)%z3(ji,jj,1) = 0.5 * ( frcv(jpr_oty1)%z3(ji  ,jj+1,1) + frcv(jpr_oty1)%z3(ji,jj,1) )
1242                  END DO
1243               END DO
1244               CALL lbc_lnk_multi( 'sbccpl', frcv(jpr_otx1)%z3(:,:,1), 'U',  -1., frcv(jpr_oty1)%z3(:,:,1), 'V',  -1. )
1245            ENDIF
1246            llnewtx = .TRUE.
1247         ELSE
1248            llnewtx = .FALSE.
1249         ENDIF
1250         !                                                   ! ========================= !
1251      ELSE                                                   !   No dynamical coupling   !
1252         !                                                   ! ========================= !
1253         frcv(jpr_otx1)%z3(:,:,1) = 0.e0                               ! here simply set to zero
1254         frcv(jpr_oty1)%z3(:,:,1) = 0.e0                               ! an external read in a file can be added instead
1255         llnewtx = .TRUE.
1256         !
1257      ENDIF
1258      !                                                      ! ========================= !
1259      !                                                      !    wind stress module     !   (taum)
1260      !                                                      ! ========================= !
1261      IF( .NOT. srcv(jpr_taum)%laction ) THEN                    ! compute wind stress module from its components if not received
1262         ! => need to be done only when otx1 was changed
1263         IF( llnewtx ) THEN
1264            DO jj = 2, jpjm1
1265               DO ji = fs_2, fs_jpim1   ! vect. opt.
1266                  zzx = frcv(jpr_otx1)%z3(ji-1,jj  ,1) + frcv(jpr_otx1)%z3(ji,jj,1)
1267                  zzy = frcv(jpr_oty1)%z3(ji  ,jj-1,1) + frcv(jpr_oty1)%z3(ji,jj,1)
1268                  frcv(jpr_taum)%z3(ji,jj,1) = 0.5 * SQRT( zzx * zzx + zzy * zzy )
1269               END DO
1270            END DO
1271            CALL lbc_lnk( 'sbccpl', frcv(jpr_taum)%z3(:,:,1), 'T', 1. )
1272            llnewtau = .TRUE.
1273         ELSE
1274            llnewtau = .FALSE.
1275         ENDIF
1276      ELSE
1277         llnewtau = nrcvinfo(jpr_taum) == OASIS_Rcv
1278         ! Stress module can be negative when received (interpolation problem)
1279         IF( llnewtau ) THEN
1280            frcv(jpr_taum)%z3(:,:,1) = MAX( 0._wp, frcv(jpr_taum)%z3(:,:,1) )
1281         ENDIF
1282      ENDIF
1283      !
1284      !                                                      ! ========================= !
1285      !                                                      !      10 m wind speed      !   (wndm)
1286      !                                                      ! ========================= !
1287      IF( .NOT. srcv(jpr_w10m)%laction ) THEN                    ! compute wind spreed from wind stress module if not received 
1288         ! => need to be done only when taumod was changed
1289         IF( llnewtau ) THEN
1290            zcoef = 1. / ( zrhoa * zcdrag ) 
1291            DO jj = 1, jpj
1292               DO ji = 1, jpi 
1293                  frcv(jpr_w10m)%z3(ji,jj,1) = SQRT( frcv(jpr_taum)%z3(ji,jj,1) * zcoef )
1294               END DO
1295            END DO
1296         ENDIF
1297      ENDIF
1298
1299      ! u(v)tau and taum will be modified by ice model
1300      ! -> need to be reset before each call of the ice/fsbc     
1301      IF( MOD( kt-1, k_fsbc ) == 0 ) THEN
1302         !
1303         IF( ln_mixcpl ) THEN
1304            utau(:,:) = utau(:,:) * xcplmask(:,:,0) + frcv(jpr_otx1)%z3(:,:,1) * zmsk(:,:)
1305            vtau(:,:) = vtau(:,:) * xcplmask(:,:,0) + frcv(jpr_oty1)%z3(:,:,1) * zmsk(:,:)
1306            taum(:,:) = taum(:,:) * xcplmask(:,:,0) + frcv(jpr_taum)%z3(:,:,1) * zmsk(:,:)
1307            wndm(:,:) = wndm(:,:) * xcplmask(:,:,0) + frcv(jpr_w10m)%z3(:,:,1) * zmsk(:,:)
1308         ELSE
1309            utau(:,:) = frcv(jpr_otx1)%z3(:,:,1)
1310            vtau(:,:) = frcv(jpr_oty1)%z3(:,:,1)
1311            taum(:,:) = frcv(jpr_taum)%z3(:,:,1)
1312            wndm(:,:) = frcv(jpr_w10m)%z3(:,:,1)
1313         ENDIF
1314         CALL iom_put( "taum_oce", taum )   ! output wind stress module
1315         
1316      ENDIF
1317
1318      !                                                      ! ================== !
1319      !                                                      ! atmosph. CO2 (ppm) !
1320      !                                                      ! ================== !
1321      IF( srcv(jpr_co2)%laction )   atm_co2(:,:) = frcv(jpr_co2)%z3(:,:,1)
1322      !
1323      !                                                      ! ================== !
1324      !                                                      !   ice skin temp.   !
1325      !                                                      ! ================== !
1326#if defined key_si3
1327      ! needed by Met Office
1328      IF( srcv(jpr_ts_ice)%laction ) THEN
1329         WHERE    ( frcv(jpr_ts_ice)%z3(:,:,:) > 0.0  )   ;   tsfc_ice(:,:,:) = 0.0 
1330         ELSEWHERE( frcv(jpr_ts_ice)%z3(:,:,:) < -60. )   ;   tsfc_ice(:,:,:) = -60.
1331         ELSEWHERE                                        ;   tsfc_ice(:,:,:) = frcv(jpr_ts_ice)%z3(:,:,:)
1332         END WHERE
1333      ENDIF 
1334#endif
1335      !                                                      ! ========================= !
1336      !                                                      ! Mean Sea Level Pressure   !   (taum)
1337      !                                                      ! ========================= !
1338      IF( srcv(jpr_mslp)%laction ) THEN                    ! UKMO SHELF effect of atmospheric pressure on SSH
1339          IF( kt /= nit000 )   ssh_ibb(:,:) = ssh_ib(:,:)    !* Swap of ssh_ib fields
1340
1341          r1_grau = 1.e0 / (grav * rau0)               !* constant for optimization
1342          ssh_ib(:,:) = - ( frcv(jpr_mslp)%z3(:,:,1) - rpref ) * r1_grau    ! equivalent ssh (inverse barometer)
1343          apr   (:,:) =     frcv(jpr_mslp)%z3(:,:,1)                         !atmospheric pressure
1344   
1345          IF( kt == nit000 ) ssh_ibb(:,:) = ssh_ib(:,:)  ! correct this later (read from restart if possible)
1346      END IF 
1347      !
1348      IF( ln_sdw ) THEN  ! Stokes Drift correction activated
1349      !                                                      ! ========================= !
1350      !                                                      !       Stokes drift u      !
1351      !                                                      ! ========================= !
1352         IF( srcv(jpr_sdrftx)%laction ) ut0sd(:,:) = frcv(jpr_sdrftx)%z3(:,:,1)
1353      !
1354      !                                                      ! ========================= !
1355      !                                                      !       Stokes drift v      !
1356      !                                                      ! ========================= !
1357         IF( srcv(jpr_sdrfty)%laction ) vt0sd(:,:) = frcv(jpr_sdrfty)%z3(:,:,1)
1358      !
1359      !                                                      ! ========================= !
1360      !                                                      !      Wave mean period     !
1361      !                                                      ! ========================= !
1362         IF( srcv(jpr_wper)%laction ) wmp(:,:) = frcv(jpr_wper)%z3(:,:,1)
1363      !
1364      !                                                      ! ========================= !
1365      !                                                      !  Significant wave height  !
1366      !                                                      ! ========================= !
1367         IF( srcv(jpr_hsig)%laction ) hsw(:,:) = frcv(jpr_hsig)%z3(:,:,1)
1368      !
1369      !                                                      ! ========================= ! 
1370      !                                                      !    Wave peak frequency    !
1371      !                                                      ! ========================= ! 
1372         IF( srcv(jpr_wfreq)%laction ) wfreq(:,:) = frcv(jpr_wfreq)%z3(:,:,1)
1373      !
1374      !                                                      ! ========================= !
1375      !                                                      !    Vertical mixing Qiao   !
1376      !                                                      ! ========================= !
1377         IF( srcv(jpr_wnum)%laction .AND. ln_zdfswm ) wnum(:,:) = frcv(jpr_wnum)%z3(:,:,1)
1378
1379         ! Calculate the 3D Stokes drift both in coupled and not fully uncoupled mode
1380         IF( srcv(jpr_sdrftx)%laction .OR. srcv(jpr_sdrfty)%laction .OR. srcv(jpr_wper)%laction &
1381                                      .OR. srcv(jpr_hsig)%laction   .OR. srcv(jpr_wfreq)%laction) THEN
1382            CALL sbc_stokes()
1383         ENDIF
1384      ENDIF
1385      !                                                      ! ========================= !
1386      !                                                      ! Stress adsorbed by waves  !
1387      !                                                      ! ========================= !
1388      IF( srcv(jpr_tauwoc)%laction .AND. ln_tauwoc ) tauoc_wave(:,:) = frcv(jpr_tauwoc)%z3(:,:,1)
1389
1390      !                                                      ! ========================= ! 
1391      !                                                      ! Stress component by waves !
1392      !                                                      ! ========================= ! 
1393      IF( srcv(jpr_tauwx)%laction .AND. srcv(jpr_tauwy)%laction .AND. ln_tauw ) THEN
1394         tauw_x(:,:) = frcv(jpr_tauwx)%z3(:,:,1)
1395         tauw_y(:,:) = frcv(jpr_tauwy)%z3(:,:,1)
1396      ENDIF
1397
1398      !                                                      ! ========================= !
1399      !                                                      !   Wave drag coefficient   !
1400      !                                                      ! ========================= !
1401      IF( srcv(jpr_wdrag)%laction .AND. ln_cdgw )   cdn_wave(:,:) = frcv(jpr_wdrag)%z3(:,:,1)
1402
1403      !  Fields received by SAS when OASIS coupling
1404      !  (arrays no more filled at sbcssm stage)
1405      !                                                      ! ================== !
1406      !                                                      !        SSS         !
1407      !                                                      ! ================== !
1408      IF( srcv(jpr_soce)%laction ) THEN                      ! received by sas in case of opa <-> sas coupling
1409         sss_m(:,:) = frcv(jpr_soce)%z3(:,:,1)
1410         CALL iom_put( 'sss_m', sss_m )
1411      ENDIF
1412      !                                               
1413      !                                                      ! ================== !
1414      !                                                      !        SST         !
1415      !                                                      ! ================== !
1416      IF( srcv(jpr_toce)%laction ) THEN                      ! received by sas in case of opa <-> sas coupling
1417         sst_m(:,:) = frcv(jpr_toce)%z3(:,:,1)
1418         IF( srcv(jpr_soce)%laction .AND. l_useCT ) THEN    ! make sure that sst_m is the potential temperature
1419            sst_m(:,:) = eos_pt_from_ct( sst_m(:,:), sss_m(:,:) )
1420         ENDIF
1421      ENDIF
1422      !                                                      ! ================== !
1423      !                                                      !        SSH         !
1424      !                                                      ! ================== !
1425      IF( srcv(jpr_ssh )%laction ) THEN                      ! received by sas in case of opa <-> sas coupling
1426         ssh_m(:,:) = frcv(jpr_ssh )%z3(:,:,1)
1427         CALL iom_put( 'ssh_m', ssh_m )
1428      ENDIF
1429      !                                                      ! ================== !
1430      !                                                      !  surface currents  !
1431      !                                                      ! ================== !
1432      IF( srcv(jpr_ocx1)%laction ) THEN                      ! received by sas in case of opa <-> sas coupling
1433         ssu_m(:,:) = frcv(jpr_ocx1)%z3(:,:,1)
1434         ub (:,:,1) = ssu_m(:,:)                             ! will be used in icestp in the call of ice_forcing_tau
1435         un (:,:,1) = ssu_m(:,:)                             ! will be used in sbc_cpl_snd if atmosphere coupling
1436         CALL iom_put( 'ssu_m', ssu_m )
1437      ENDIF
1438      IF( srcv(jpr_ocy1)%laction ) THEN
1439         ssv_m(:,:) = frcv(jpr_ocy1)%z3(:,:,1)
1440         vb (:,:,1) = ssv_m(:,:)                             ! will be used in icestp in the call of ice_forcing_tau
1441         vn (:,:,1) = ssv_m(:,:)                             ! will be used in sbc_cpl_snd if atmosphere coupling
1442         CALL iom_put( 'ssv_m', ssv_m )
1443      ENDIF
1444      !                                                      ! ======================== !
1445      !                                                      !  first T level thickness !
1446      !                                                      ! ======================== !
1447      IF( srcv(jpr_e3t1st )%laction ) THEN                   ! received by sas in case of opa <-> sas coupling
1448         e3t_m(:,:) = frcv(jpr_e3t1st )%z3(:,:,1)
1449         CALL iom_put( 'e3t_m', e3t_m(:,:) )
1450      ENDIF
1451      !                                                      ! ================================ !
1452      !                                                      !  fraction of solar net radiation !
1453      !                                                      ! ================================ !
1454      IF( srcv(jpr_fraqsr)%laction ) THEN                    ! received by sas in case of opa <-> sas coupling
1455         frq_m(:,:) = frcv(jpr_fraqsr)%z3(:,:,1)
1456         CALL iom_put( 'frq_m', frq_m )
1457      ENDIF
1458     
1459      !                                                      ! ========================= !
1460      IF( k_ice <= 1 .AND. MOD( kt-1, k_fsbc ) == 0 ) THEN   !  heat & freshwater fluxes ! (Ocean only case)
1461         !                                                   ! ========================= !
1462         !
1463         !                                                       ! total freshwater fluxes over the ocean (emp)
1464         IF( srcv(jpr_oemp)%laction .OR. srcv(jpr_rain)%laction ) THEN
1465            SELECT CASE( TRIM( sn_rcv_emp%cldes ) )                                    ! evaporation - precipitation
1466            CASE( 'conservative' )
1467               zemp(:,:) = frcv(jpr_tevp)%z3(:,:,1) - ( frcv(jpr_rain)%z3(:,:,1) + frcv(jpr_snow)%z3(:,:,1) )
1468            CASE( 'oce only', 'oce and ice' )
1469               zemp(:,:) = frcv(jpr_oemp)%z3(:,:,1)
1470            CASE default
1471               CALL ctl_stop( 'sbc_cpl_rcv: wrong definition of sn_rcv_emp%cldes' )
1472            END SELECT
1473         ELSE
1474            zemp(:,:) = 0._wp
1475         ENDIF
1476         !
1477         !                                                        ! runoffs and calving (added in emp)
1478         IF( srcv(jpr_rnf)%laction )     rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
1479         IF( srcv(jpr_cal)%laction )     zemp(:,:) = zemp(:,:) - frcv(jpr_cal)%z3(:,:,1)
1480 
1481         IF( srcv(jpr_icb)%laction )  THEN
1482             fwficb(:,:) = frcv(jpr_icb)%z3(:,:,1)
1483             rnf(:,:)    = rnf(:,:) + fwficb(:,:)   ! iceberg added to runfofs
1484         ENDIF
1485         IF( srcv(jpr_isf)%laction )  fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)  ! fresh water flux from the isf (fwfisf <0 mean melting) 
1486       
1487         IF( ln_mixcpl ) THEN   ;   emp(:,:) = emp(:,:) * xcplmask(:,:,0) + zemp(:,:) * zmsk(:,:)
1488         ELSE                   ;   emp(:,:) =                              zemp(:,:)
1489         ENDIF
1490         !
1491         !                                                       ! non solar heat flux over the ocean (qns)
1492         IF(      srcv(jpr_qnsoce)%laction ) THEN   ;   zqns(:,:) = frcv(jpr_qnsoce)%z3(:,:,1)
1493         ELSE IF( srcv(jpr_qnsmix)%laction ) THEN   ;   zqns(:,:) = frcv(jpr_qnsmix)%z3(:,:,1)
1494         ELSE                                       ;   zqns(:,:) = 0._wp
1495         END IF
1496         ! update qns over the free ocean with:
1497         IF( nn_components /= jp_iam_opa ) THEN
1498            zqns(:,:) =  zqns(:,:) - zemp(:,:) * sst_m(:,:) * rcp         ! remove heat content due to mass flux (assumed to be at SST)
1499            IF( srcv(jpr_snow  )%laction ) THEN
1500               zqns(:,:) = zqns(:,:) - frcv(jpr_snow)%z3(:,:,1) * rLfus   ! energy for melting solid precipitation over the free ocean
1501            ENDIF
1502         ENDIF
1503         !
1504         IF( srcv(jpr_icb)%laction )  zqns(:,:) = zqns(:,:) - frcv(jpr_icb)%z3(:,:,1) * rLfus ! remove heat content associated to iceberg melting
1505         !
1506         IF( ln_mixcpl ) THEN   ;   qns(:,:) = qns(:,:) * xcplmask(:,:,0) + zqns(:,:) * zmsk(:,:)
1507         ELSE                   ;   qns(:,:) =                              zqns(:,:)
1508         ENDIF
1509
1510         !                                                       ! solar flux over the ocean          (qsr)
1511         IF     ( srcv(jpr_qsroce)%laction ) THEN   ;   zqsr(:,:) = frcv(jpr_qsroce)%z3(:,:,1)
1512         ELSE IF( srcv(jpr_qsrmix)%laction ) then   ;   zqsr(:,:) = frcv(jpr_qsrmix)%z3(:,:,1)
1513         ELSE                                       ;   zqsr(:,:) = 0._wp
1514         ENDIF
1515         IF( ln_dm2dc .AND. ln_cpl )   zqsr(:,:) = sbc_dcy( zqsr )   ! modify qsr to include the diurnal cycle
1516         IF( ln_mixcpl ) THEN   ;   qsr(:,:) = qsr(:,:) * xcplmask(:,:,0) + zqsr(:,:) * zmsk(:,:)
1517         ELSE                   ;   qsr(:,:) =                              zqsr(:,:)
1518         ENDIF
1519         !
1520         ! salt flux over the ocean (received by opa in case of opa <-> sas coupling)
1521         IF( srcv(jpr_sflx )%laction )   sfx(:,:) = frcv(jpr_sflx  )%z3(:,:,1)
1522         ! Ice cover  (received by opa in case of opa <-> sas coupling)
1523         IF( srcv(jpr_fice )%laction )   fr_i(:,:) = frcv(jpr_fice )%z3(:,:,1)
1524         !
1525      ENDIF
1526      !
1527   END SUBROUTINE sbc_cpl_rcv
1528   
1529
1530   SUBROUTINE sbc_cpl_ice_tau( p_taui, p_tauj )     
1531      !!----------------------------------------------------------------------
1532      !!             ***  ROUTINE sbc_cpl_ice_tau  ***
1533      !!
1534      !! ** Purpose :   provide the stress over sea-ice in coupled mode
1535      !!
1536      !! ** Method  :   transform the received stress from the atmosphere into
1537      !!             an atmosphere-ice stress in the (i,j) ocean referencial
1538      !!             and at the velocity point of the sea-ice model:
1539      !!                'C'-grid : i- (j-) components given at U- (V-) point
1540      !!
1541      !!                The received stress are :
1542      !!                 - defined by 3 components (if cartesian coordinate)
1543      !!                        or by 2 components (if spherical)
1544      !!                 - oriented along geographical   coordinate (if eastward-northward)
1545      !!                        or  along the local grid coordinate (if local grid)
1546      !!                 - given at U- and V-point, resp.   if received on 2 grids
1547      !!                        or at a same point (T or I) if received on 1 grid
1548      !!                Therefore and if necessary, they are successively
1549      !!             processed in order to obtain them
1550      !!                 first  as  2 components on the sphere
1551      !!                 second as  2 components oriented along the local grid
1552      !!                 third  as  2 components on the ice grid point
1553      !!
1554      !!                Except in 'oce and ice' case, only one vector stress field
1555      !!             is received. It has already been processed in sbc_cpl_rcv
1556      !!             so that it is now defined as (i,j) components given at U-
1557      !!             and V-points, respectively. 
1558      !!
1559      !! ** Action  :   return ptau_i, ptau_j, the stress over the ice
1560      !!----------------------------------------------------------------------
1561      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_taui   ! i- & j-components of atmos-ice stress [N/m2]
1562      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_tauj   ! at I-point (B-grid) or U & V-point (C-grid)
1563      !!
1564      INTEGER ::   ji, jj   ! dummy loop indices
1565      INTEGER ::   itx      ! index of taux over ice
1566      REAL(wp), DIMENSION(jpi,jpj) ::   ztx, zty 
1567      !!----------------------------------------------------------------------
1568      !
1569      IF( srcv(jpr_itx1)%laction ) THEN   ;   itx =  jpr_itx1   
1570      ELSE                                ;   itx =  jpr_otx1
1571      ENDIF
1572
1573      ! do something only if we just received the stress from atmosphere
1574      IF(  nrcvinfo(itx) == OASIS_Rcv ) THEN
1575         !                                                      ! ======================= !
1576         IF( srcv(jpr_itx1)%laction ) THEN                      !   ice stress received   !
1577            !                                                   ! ======================= !
1578           
1579            IF( TRIM( sn_rcv_tau%clvref ) == 'cartesian' ) THEN            ! 2 components on the sphere
1580               !                                                       ! (cartesian to spherical -> 3 to 2 components)
1581               CALL geo2oce(  frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), frcv(jpr_itz1)%z3(:,:,1),   &
1582                  &          srcv(jpr_itx1)%clgrid, ztx, zty )
1583               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 1st grid
1584               frcv(jpr_ity1)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 1st grid
1585               !
1586               IF( srcv(jpr_itx2)%laction ) THEN
1587                  CALL geo2oce( frcv(jpr_itx2)%z3(:,:,1), frcv(jpr_ity2)%z3(:,:,1), frcv(jpr_itz2)%z3(:,:,1),   &
1588                     &          srcv(jpr_itx2)%clgrid, ztx, zty )
1589                  frcv(jpr_itx2)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 2nd grid
1590                  frcv(jpr_ity2)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 2nd grid
1591               ENDIF
1592               !
1593            ENDIF
1594            !
1595            IF( TRIM( sn_rcv_tau%clvor ) == 'eastward-northward' ) THEN   ! 2 components oriented along the local grid
1596               !                                                       ! (geographical to local grid -> rotate the components)
1597               CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->i', ztx )   
1598               IF( srcv(jpr_itx2)%laction ) THEN
1599                  CALL rot_rep( frcv(jpr_itx2)%z3(:,:,1), frcv(jpr_ity2)%z3(:,:,1), srcv(jpr_itx2)%clgrid, 'en->j', zty )   
1600               ELSE
1601                  CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->j', zty ) 
1602               ENDIF
1603               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
1604               frcv(jpr_ity1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 1st grid
1605            ENDIF
1606            !                                                   ! ======================= !
1607         ELSE                                                   !     use ocean stress    !
1608            !                                                   ! ======================= !
1609            frcv(jpr_itx1)%z3(:,:,1) = frcv(jpr_otx1)%z3(:,:,1)
1610            frcv(jpr_ity1)%z3(:,:,1) = frcv(jpr_oty1)%z3(:,:,1)
1611            !
1612         ENDIF
1613         !                                                      ! ======================= !
1614         !                                                      !     put on ice grid     !
1615         !                                                      ! ======================= !
1616         !   
1617         !                                                  j+1   j     -----V---F
1618         ! ice stress on ice velocity point                              !       |
1619         ! (C-grid ==>(U,V))                                      j      |   T   U
1620         !                                                               |       |
1621         !                                                   j    j-1   -I-------|
1622         !                                               (for I)         |       |
1623         !                                                              i-1  i   i
1624         !                                                               i      i+1 (for I)
1625         SELECT CASE ( srcv(jpr_itx1)%clgrid )
1626         CASE( 'U' )
1627            p_taui(:,:) = frcv(jpr_itx1)%z3(:,:,1)                   ! (U,V) ==> (U,V)
1628            p_tauj(:,:) = frcv(jpr_ity1)%z3(:,:,1)
1629         CASE( 'F' )
1630            DO jj = 2, jpjm1                                   ! F ==> (U,V)
1631               DO ji = fs_2, fs_jpim1   ! vector opt.
1632                  p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji,jj,1) + frcv(jpr_itx1)%z3(ji  ,jj-1,1) )
1633                  p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji,jj,1) + frcv(jpr_ity1)%z3(ji-1,jj  ,1) )
1634               END DO
1635            END DO
1636         CASE( 'T' )
1637            DO jj = 2, jpjm1                                   ! T ==> (U,V)
1638               DO ji = fs_2, fs_jpim1   ! vector opt.
1639                  p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji+1,jj  ,1) + frcv(jpr_itx1)%z3(ji,jj,1) )
1640                  p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji  ,jj+1,1) + frcv(jpr_ity1)%z3(ji,jj,1) )
1641               END DO
1642            END DO
1643         CASE( 'I' )
1644            DO jj = 2, jpjm1                                   ! I ==> (U,V)
1645               DO ji = 2, jpim1   ! NO vector opt.
1646                  p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji+1,jj+1,1) + frcv(jpr_itx1)%z3(ji+1,jj  ,1) )
1647                  p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji+1,jj+1,1) + frcv(jpr_ity1)%z3(ji  ,jj+1,1) )
1648               END DO
1649            END DO
1650         END SELECT
1651         IF( srcv(jpr_itx1)%clgrid /= 'U' ) THEN
1652            CALL lbc_lnk_multi( 'sbccpl', p_taui, 'U',  -1., p_tauj, 'V',  -1. )
1653         ENDIF
1654         
1655      ENDIF
1656      !
1657   END SUBROUTINE sbc_cpl_ice_tau
1658   
1659
1660   SUBROUTINE sbc_cpl_ice_flx( picefr, palbi, psst, pist, phs, phi )
1661      !!----------------------------------------------------------------------
1662      !!             ***  ROUTINE sbc_cpl_ice_flx  ***
1663      !!
1664      !! ** Purpose :   provide the heat and freshwater fluxes of the ocean-ice system
1665      !!
1666      !! ** Method  :   transform the fields received from the atmosphere into
1667      !!             surface heat and fresh water boundary condition for the
1668      !!             ice-ocean system. The following fields are provided:
1669      !!               * total non solar, solar and freshwater fluxes (qns_tot,
1670      !!             qsr_tot and emp_tot) (total means weighted ice-ocean flux)
1671      !!             NB: emp_tot include runoffs and calving.
1672      !!               * fluxes over ice (qns_ice, qsr_ice, emp_ice) where
1673      !!             emp_ice = sublimation - solid precipitation as liquid
1674      !!             precipitation are re-routed directly to the ocean and
1675      !!             calving directly enter the ocean (runoffs are read but included in trasbc.F90)
1676      !!               * solid precipitation (sprecip), used to add to qns_tot
1677      !!             the heat lost associated to melting solid precipitation
1678      !!             over the ocean fraction.
1679      !!               * heat content of rain, snow and evap can also be provided,
1680      !!             otherwise heat flux associated with these mass flux are
1681      !!             guessed (qemp_oce, qemp_ice)
1682      !!
1683      !!             - the fluxes have been separated from the stress as
1684      !!               (a) they are updated at each ice time step compare to
1685      !!               an update at each coupled time step for the stress, and
1686      !!               (b) the conservative computation of the fluxes over the
1687      !!               sea-ice area requires the knowledge of the ice fraction
1688      !!               after the ice advection and before the ice thermodynamics,
1689      !!               so that the stress is updated before the ice dynamics
1690      !!               while the fluxes are updated after it.
1691      !!
1692      !! ** Details
1693      !!             qns_tot = (1-a) * qns_oce + a * qns_ice               => provided
1694      !!                     + qemp_oce + qemp_ice                         => recalculated and added up to qns
1695      !!
1696      !!             qsr_tot = (1-a) * qsr_oce + a * qsr_ice               => provided
1697      !!
1698      !!             emp_tot = emp_oce + emp_ice                           => calving is provided and added to emp_tot (and emp_oce).
1699      !!                                                                      runoff (which includes rivers+icebergs) and iceshelf
1700      !!                                                                      are provided but not included in emp here. Only runoff will
1701      !!                                                                      be included in emp in other parts of NEMO code
1702      !! ** Action  :   update at each nf_ice time step:
1703      !!                   qns_tot, qsr_tot  non-solar and solar total heat fluxes
1704      !!                   qns_ice, qsr_ice  non-solar and solar heat fluxes over the ice
1705      !!                   emp_tot           total evaporation - precipitation(liquid and solid) (-calving)
1706      !!                   emp_ice           ice sublimation - solid precipitation over the ice
1707      !!                   dqns_ice          d(non-solar heat flux)/d(Temperature) over the ice
1708      !!                   sprecip           solid precipitation over the ocean 
1709      !!----------------------------------------------------------------------
1710      REAL(wp), INTENT(in), DIMENSION(:,:)             ::   picefr     ! ice fraction                [0 to 1]
1711      !                                                !!           ! optional arguments, used only in 'mixed oce-ice' case
1712      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   palbi      ! all skies ice albedo
1713      REAL(wp), INTENT(in), DIMENSION(:,:  ), OPTIONAL ::   psst       ! sea surface temperature     [Celsius]
1714      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   pist       ! ice surface temperature     [Kelvin]
1715      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   phs        ! snow depth                  [m]
1716      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   phi        ! ice thickness               [m]
1717      !
1718      INTEGER  ::   ji, jj, jl   ! dummy loop index
1719      REAL(wp) ::   ztri         ! local scalar
1720      REAL(wp), DIMENSION(jpi,jpj)     ::   zcptn, zcptrain, zcptsnw, ziceld, zmsk, zsnw
1721      REAL(wp), DIMENSION(jpi,jpj)     ::   zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip  , zevap_oce, zdevap_ice
1722      REAL(wp), DIMENSION(jpi,jpj)     ::   zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice
1723      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zqns_ice, zqsr_ice, zdqns_ice, zqevap_ice, zevap_ice    !!gm , zfrqsr_tr_i
1724      !!----------------------------------------------------------------------
1725      !
1726      IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
1727      ziceld(:,:) = 1._wp - picefr(:,:)
1728      zcptn (:,:) = rcp * sst_m(:,:)
1729      !
1730      !                                                      ! ========================= !
1731      !                                                      !    freshwater budget      !   (emp_tot)
1732      !                                                      ! ========================= !
1733      !
1734      !                                                           ! solid Precipitation                                (sprecip)
1735      !                                                           ! liquid + solid Precipitation                       (tprecip)
1736      !                                                           ! total Evaporation - total Precipitation            (emp_tot)
1737      !                                                           ! sublimation - solid precipitation (cell average)   (emp_ice)
1738      SELECT CASE( TRIM( sn_rcv_emp%cldes ) )
1739      CASE( 'conservative' )   ! received fields: jpr_rain, jpr_snow, jpr_ievp, jpr_tevp
1740         zsprecip(:,:) =   frcv(jpr_snow)%z3(:,:,1)                  ! May need to ensure positive here
1741         ztprecip(:,:) =   frcv(jpr_rain)%z3(:,:,1) + zsprecip(:,:)  ! May need to ensure positive here
1742         zemp_tot(:,:) =   frcv(jpr_tevp)%z3(:,:,1) - ztprecip(:,:)
1743         zemp_ice(:,:) = ( frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_snow)%z3(:,:,1) ) * picefr(:,:)
1744      CASE( 'oce and ice'   )   ! received fields: jpr_sbpr, jpr_semp, jpr_oemp, jpr_ievp
1745         zemp_tot(:,:) = ziceld(:,:) * frcv(jpr_oemp)%z3(:,:,1) + picefr(:,:) * frcv(jpr_sbpr)%z3(:,:,1)
1746         zemp_ice(:,:) = frcv(jpr_semp)%z3(:,:,1) * picefr(:,:)
1747         zsprecip(:,:) = frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_semp)%z3(:,:,1)
1748         ztprecip(:,:) = frcv(jpr_semp)%z3(:,:,1) - frcv(jpr_sbpr)%z3(:,:,1) + zsprecip(:,:)
1749      CASE( 'none'      )       ! Not available as for now: needs additional coding below when computing zevap_oce
1750      !                         ! since fields received are not defined with none option
1751         CALL ctl_stop( 'STOP', 'sbccpl/sbc_cpl_ice_flx: some fields are not defined. Change sn_rcv_emp value in namelist namsbc_cpl' )
1752      END SELECT
1753
1754#if defined key_si3
1755      ! zsnw = snow fraction over ice after wind blowing (=picefr if no blowing)
1756      zsnw(:,:) = 0._wp   ;   CALL ice_thd_snwblow( ziceld, zsnw )
1757     
1758      ! --- evaporation minus precipitation corrected (because of wind blowing on snow) --- !
1759      zemp_ice(:,:) = zemp_ice(:,:) + zsprecip(:,:) * ( picefr(:,:) - zsnw(:,:) )  ! emp_ice = A * sublimation - zsnw * sprecip
1760      zemp_oce(:,:) = zemp_tot(:,:) - zemp_ice(:,:)                                ! emp_oce = emp_tot - emp_ice
1761
1762      ! --- evaporation over ocean (used later for qemp) --- !
1763      zevap_oce(:,:) = frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:)
1764
1765      ! --- evaporation over ice (kg/m2/s) --- !
1766      DO jl=1,jpl
1767         IF (sn_rcv_emp%clcat == 'yes') THEN   ;   zevap_ice(:,:,jl) = frcv(jpr_ievp)%z3(:,:,jl)
1768         ELSE                                  ;   zevap_ice(:,:,jl) = frcv(jpr_ievp)%z3(:,:,1 )   ;   ENDIF
1769      ENDDO
1770
1771      ! since the sensitivity of evap to temperature (devap/dT) is not prescribed by the atmosphere, we set it to 0
1772      ! therefore, sublimation is not redistributed over the ice categories when no subgrid scale fluxes are provided by atm.
1773      zdevap_ice(:,:) = 0._wp
1774     
1775      ! --- Continental fluxes --- !
1776      IF( srcv(jpr_rnf)%laction ) THEN   ! runoffs (included in emp later on)
1777         rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
1778      ENDIF
1779      IF( srcv(jpr_cal)%laction ) THEN   ! calving (put in emp_tot and emp_oce)
1780         zemp_tot(:,:) = zemp_tot(:,:) - frcv(jpr_cal)%z3(:,:,1)
1781         zemp_oce(:,:) = zemp_oce(:,:) - frcv(jpr_cal)%z3(:,:,1)
1782      ENDIF
1783      IF( srcv(jpr_icb)%laction ) THEN   ! iceberg added to runoffs
1784         fwficb(:,:) = frcv(jpr_icb)%z3(:,:,1)
1785         rnf(:,:)    = rnf(:,:) + fwficb(:,:)
1786      ENDIF
1787      IF( srcv(jpr_isf)%laction ) THEN   ! iceshelf (fwfisf <0 mean melting)
1788        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1) 
1789      ENDIF
1790
1791      IF( ln_mixcpl ) THEN
1792         emp_tot(:,:) = emp_tot(:,:) * xcplmask(:,:,0) + zemp_tot(:,:) * zmsk(:,:)
1793         emp_ice(:,:) = emp_ice(:,:) * xcplmask(:,:,0) + zemp_ice(:,:) * zmsk(:,:)
1794         emp_oce(:,:) = emp_oce(:,:) * xcplmask(:,:,0) + zemp_oce(:,:) * zmsk(:,:)
1795         sprecip(:,:) = sprecip(:,:) * xcplmask(:,:,0) + zsprecip(:,:) * zmsk(:,:)
1796         tprecip(:,:) = tprecip(:,:) * xcplmask(:,:,0) + ztprecip(:,:) * zmsk(:,:)
1797         DO jl = 1, jpl
1798            evap_ice (:,:,jl) = evap_ice (:,:,jl) * xcplmask(:,:,0) + zevap_ice (:,:,jl) * zmsk(:,:)
1799            devap_ice(:,:,jl) = devap_ice(:,:,jl) * xcplmask(:,:,0) + zdevap_ice(:,:)    * zmsk(:,:)
1800         END DO
1801      ELSE
1802         emp_tot (:,:)   = zemp_tot (:,:)
1803         emp_ice (:,:)   = zemp_ice (:,:)
1804         emp_oce (:,:)   = zemp_oce (:,:)     
1805         sprecip (:,:)   = zsprecip (:,:)
1806         tprecip (:,:)   = ztprecip (:,:)
1807         evap_ice(:,:,:) = zevap_ice(:,:,:)
1808         DO jl = 1, jpl
1809            devap_ice(:,:,jl) = zdevap_ice(:,:)
1810         END DO
1811      ENDIF
1812
1813#else
1814      zsnw(:,:) = picefr(:,:)
1815      ! --- Continental fluxes --- !
1816      IF( srcv(jpr_rnf)%laction ) THEN   ! runoffs (included in emp later on)
1817         rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
1818      ENDIF
1819      IF( srcv(jpr_cal)%laction ) THEN   ! calving (put in emp_tot)
1820         zemp_tot(:,:) = zemp_tot(:,:) - frcv(jpr_cal)%z3(:,:,1)
1821      ENDIF
1822      IF( srcv(jpr_icb)%laction ) THEN   ! iceberg added to runoffs
1823         fwficb(:,:) = frcv(jpr_icb)%z3(:,:,1)
1824         rnf(:,:)    = rnf(:,:) + fwficb(:,:)
1825      ENDIF
1826      IF( srcv(jpr_isf)%laction ) THEN   ! iceshelf (fwfisf <0 mean melting)
1827        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)
1828      ENDIF
1829      !
1830      IF( ln_mixcpl ) THEN
1831         emp_tot(:,:) = emp_tot(:,:) * xcplmask(:,:,0) + zemp_tot(:,:) * zmsk(:,:)
1832         emp_ice(:,:) = emp_ice(:,:) * xcplmask(:,:,0) + zemp_ice(:,:) * zmsk(:,:)
1833         sprecip(:,:) = sprecip(:,:) * xcplmask(:,:,0) + zsprecip(:,:) * zmsk(:,:)
1834         tprecip(:,:) = tprecip(:,:) * xcplmask(:,:,0) + ztprecip(:,:) * zmsk(:,:)
1835      ELSE
1836         emp_tot(:,:) =                                  zemp_tot(:,:)
1837         emp_ice(:,:) =                                  zemp_ice(:,:)
1838         sprecip(:,:) =                                  zsprecip(:,:)
1839         tprecip(:,:) =                                  ztprecip(:,:)
1840      ENDIF
1841      !
1842#endif
1843
1844      ! outputs
1845!!      IF( srcv(jpr_rnf)%laction )   CALL iom_put( 'runoffs' , rnf(:,:) * tmask(:,:,1)                                 )  ! runoff
1846!!      IF( srcv(jpr_isf)%laction )   CALL iom_put( 'iceshelf_cea', -fwfisf(:,:) * tmask(:,:,1)                         )  ! iceshelf
1847      IF( srcv(jpr_cal)%laction )   CALL iom_put( 'calving_cea' , frcv(jpr_cal)%z3(:,:,1) * tmask(:,:,1)                )  ! calving
1848      IF( srcv(jpr_icb)%laction )   CALL iom_put( 'iceberg_cea' , frcv(jpr_icb)%z3(:,:,1) * tmask(:,:,1)                )  ! icebergs
1849      IF( iom_use('snowpre') )      CALL iom_put( 'snowpre'     , sprecip(:,:)                                          )  ! Snow
1850      IF( iom_use('precip') )       CALL iom_put( 'precip'      , tprecip(:,:)                                          )  ! total  precipitation
1851      IF( iom_use('rain') )         CALL iom_put( 'rain'        , tprecip(:,:) - sprecip(:,:)                           )  ! liquid precipitation
1852      IF( iom_use('snow_ao_cea') )  CALL iom_put( 'snow_ao_cea' , sprecip(:,:) * ( 1._wp - zsnw(:,:) )                  )  ! Snow over ice-free ocean  (cell average)
1853      IF( iom_use('snow_ai_cea') )  CALL iom_put( 'snow_ai_cea' , sprecip(:,:) *           zsnw(:,:)                    )  ! Snow over sea-ice         (cell average)
1854      IF( iom_use('subl_ai_cea') )  CALL iom_put( 'subl_ai_cea' , frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:) * tmask(:,:,1) )  ! Sublimation over sea-ice (cell average)
1855      IF( iom_use('evap_ao_cea') )  CALL iom_put( 'evap_ao_cea' , ( frcv(jpr_tevp)%z3(:,:,1)  &
1856         &                                                        - frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:) ) * tmask(:,:,1) )  ! ice-free oce evap (cell average)
1857      ! note: runoff output is done in sbcrnf (which includes icebergs too) and iceshelf output is done in sbcisf
1858      !
1859      !                                                      ! ========================= !
1860      SELECT CASE( TRIM( sn_rcv_qns%cldes ) )                !   non solar heat fluxes   !   (qns)
1861      !                                                      ! ========================= !
1862      CASE( 'oce only' )         ! the required field is directly provided
1863         zqns_tot(:,:) = frcv(jpr_qnsoce)%z3(:,:,1)
1864      CASE( 'conservative' )     ! the required fields are directly provided
1865         zqns_tot(:,:) = frcv(jpr_qnsmix)%z3(:,:,1)
1866         IF ( TRIM(sn_rcv_qns%clcat) == 'yes' ) THEN
1867            zqns_ice(:,:,1:jpl) = frcv(jpr_qnsice)%z3(:,:,1:jpl)
1868         ELSE
1869            DO jl = 1, jpl
1870               zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1) ! Set all category values equal
1871            END DO
1872         ENDIF
1873      CASE( 'oce and ice' )      ! the total flux is computed from ocean and ice fluxes
1874         zqns_tot(:,:) =  ziceld(:,:) * frcv(jpr_qnsoce)%z3(:,:,1)
1875         IF ( TRIM(sn_rcv_qns%clcat) == 'yes' ) THEN
1876            DO jl=1,jpl
1877               zqns_tot(:,:   ) = zqns_tot(:,:) + a_i(:,:,jl) * frcv(jpr_qnsice)%z3(:,:,jl)   
1878               zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,jl)
1879            ENDDO
1880         ELSE
1881            qns_tot(:,:) = qns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
1882            DO jl = 1, jpl
1883               zqns_tot(:,:   ) = zqns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
1884               zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1)
1885            END DO
1886         ENDIF
1887      CASE( 'mixed oce-ice' )    ! the ice flux is cumputed from the total flux, the SST and ice informations
1888! ** NEED TO SORT OUT HOW THIS SHOULD WORK IN THE MULTI-CATEGORY CASE - CURRENTLY NOT ALLOWED WHEN INTERFACE INITIALISED **
1889         zqns_tot(:,:  ) = frcv(jpr_qnsmix)%z3(:,:,1)
1890         zqns_ice(:,:,1) = frcv(jpr_qnsmix)%z3(:,:,1)    &
1891            &            + frcv(jpr_dqnsdt)%z3(:,:,1) * ( pist(:,:,1) - ( (rt0 + psst(:,:  ) ) * ziceld(:,:)   &
1892            &                                           + pist(:,:,1) * picefr(:,:) ) )
1893      END SELECT
1894      !                                     
1895      ! --- calving (removed from qns_tot) --- !
1896      IF( srcv(jpr_cal)%laction )   zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_cal)%z3(:,:,1) * rLfus  ! remove latent heat of calving
1897                                                                                                     ! we suppose it melts at 0deg, though it should be temp. of surrounding ocean
1898      ! --- iceberg (removed from qns_tot) --- !
1899      IF( srcv(jpr_icb)%laction )   zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_icb)%z3(:,:,1) * rLfus  ! remove latent heat of iceberg melting
1900
1901#if defined key_si3     
1902      ! --- non solar flux over ocean --- !
1903      !         note: ziceld cannot be = 0 since we limit the ice concentration to amax
1904      zqns_oce = 0._wp
1905      WHERE( ziceld /= 0._wp )   zqns_oce(:,:) = ( zqns_tot(:,:) - SUM( a_i * zqns_ice, dim=3 ) ) / ziceld(:,:)
1906
1907      ! Heat content per unit mass of snow (J/kg)
1908      WHERE( SUM( a_i, dim=3 ) > 1.e-10 )   ;   zcptsnw(:,:) = rcpi * SUM( (tn_ice - rt0) * a_i, dim=3 ) / SUM( a_i, dim=3 )
1909      ELSEWHERE                             ;   zcptsnw(:,:) = zcptn(:,:)
1910      ENDWHERE
1911      ! Heat content per unit mass of rain (J/kg)
1912      zcptrain(:,:) = rcp * ( SUM( (tn_ice(:,:,:) - rt0) * a_i(:,:,:), dim=3 ) + sst_m(:,:) * ziceld(:,:) ) 
1913
1914      ! --- enthalpy of snow precip over ice in J/m3 (to be used in 1D-thermo) --- !
1915      zqprec_ice(:,:) = rhos * ( zcptsnw(:,:) - rLfus )
1916
1917      ! --- heat content of evap over ice in W/m2 (to be used in 1D-thermo) --- !
1918      DO jl = 1, jpl
1919         zqevap_ice(:,:,jl) = 0._wp ! should be -evap * ( ( Tice - rt0 ) * rcpi ) but atm. does not take it into account
1920      END DO
1921
1922      ! --- heat flux associated with emp (W/m2) --- !
1923      zqemp_oce(:,:) = -  zevap_oce(:,:)                                      *   zcptn   (:,:)   &        ! evap
1924         &             + ( ztprecip(:,:) - zsprecip(:,:) )                    *   zcptrain(:,:)   &        ! liquid precip
1925         &             +   zsprecip(:,:)                   * ( 1._wp - zsnw ) * ( zcptsnw (:,:) - rLfus )  ! solid precip over ocean + snow melting
1926      zqemp_ice(:,:) =     zsprecip(:,:)                   * zsnw             * ( zcptsnw (:,:) - rLfus )  ! solid precip over ice (qevap_ice=0 since atm. does not take it into account)
1927!!    zqemp_ice(:,:) = -   frcv(jpr_ievp)%z3(:,:,1)        * picefr(:,:)      *   zcptsnw (:,:)   &        ! ice evap
1928!!       &             +   zsprecip(:,:)                   * zsnw             * zqprec_ice(:,:) * r1_rhos  ! solid precip over ice
1929     
1930      ! --- total non solar flux (including evap/precip) --- !
1931      zqns_tot(:,:) = zqns_tot(:,:) + zqemp_ice(:,:) + zqemp_oce(:,:)
1932
1933      ! --- in case both coupled/forced are active, we must mix values --- !
1934      IF( ln_mixcpl ) THEN
1935         qns_tot(:,:) = qns_tot(:,:) * xcplmask(:,:,0) + zqns_tot(:,:)* zmsk(:,:)
1936         qns_oce(:,:) = qns_oce(:,:) * xcplmask(:,:,0) + zqns_oce(:,:)* zmsk(:,:)
1937         DO jl=1,jpl
1938            qns_ice  (:,:,jl) = qns_ice  (:,:,jl) * xcplmask(:,:,0) +  zqns_ice  (:,:,jl)* zmsk(:,:)
1939            qevap_ice(:,:,jl) = qevap_ice(:,:,jl) * xcplmask(:,:,0) +  zqevap_ice(:,:,jl)* zmsk(:,:)
1940         ENDDO
1941         qprec_ice(:,:) = qprec_ice(:,:) * xcplmask(:,:,0) + zqprec_ice(:,:)* zmsk(:,:)
1942         qemp_oce (:,:) =  qemp_oce(:,:) * xcplmask(:,:,0) +  zqemp_oce(:,:)* zmsk(:,:)
1943         qemp_ice (:,:) =  qemp_ice(:,:) * xcplmask(:,:,0) +  zqemp_ice(:,:)* zmsk(:,:)
1944      ELSE
1945         qns_tot  (:,:  ) = zqns_tot  (:,:  )
1946         qns_oce  (:,:  ) = zqns_oce  (:,:  )
1947         qns_ice  (:,:,:) = zqns_ice  (:,:,:)
1948         qevap_ice(:,:,:) = zqevap_ice(:,:,:)
1949         qprec_ice(:,:  ) = zqprec_ice(:,:  )
1950         qemp_oce (:,:  ) = zqemp_oce (:,:  )
1951         qemp_ice (:,:  ) = zqemp_ice (:,:  )
1952      ENDIF
1953
1954#else
1955      zcptsnw (:,:) = zcptn(:,:)
1956      zcptrain(:,:) = zcptn(:,:)
1957     
1958      ! clem: this formulation is certainly wrong... but better than it was...
1959      zqns_tot(:,:) = zqns_tot(:,:)                             &          ! zqns_tot update over free ocean with:
1960         &          - (  ziceld(:,:) * zsprecip(:,:) * rLfus )  &          ! remove the latent heat flux of solid precip. melting
1961         &          - (  zemp_tot(:,:)                          &          ! remove the heat content of mass flux (assumed to be at SST)
1962         &             - zemp_ice(:,:) ) * zcptn(:,:) 
1963
1964     IF( ln_mixcpl ) THEN
1965         qns_tot(:,:) = qns(:,:) * ziceld(:,:) + SUM( qns_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
1966         qns_tot(:,:) = qns_tot(:,:) * xcplmask(:,:,0) +  zqns_tot(:,:)* zmsk(:,:)
1967         DO jl=1,jpl
1968            qns_ice(:,:,jl) = qns_ice(:,:,jl) * xcplmask(:,:,0) +  zqns_ice(:,:,jl)* zmsk(:,:)
1969         ENDDO
1970      ELSE
1971         qns_tot(:,:  ) = zqns_tot(:,:  )
1972         qns_ice(:,:,:) = zqns_ice(:,:,:)
1973      ENDIF
1974
1975#endif
1976      ! outputs
1977      IF ( srcv(jpr_cal)%laction       ) CALL iom_put('hflx_cal_cea'    , - frcv(jpr_cal)%z3(:,:,1) * rLfus )                      ! latent heat from calving
1978      IF ( srcv(jpr_icb)%laction       ) CALL iom_put('hflx_icb_cea'    , - frcv(jpr_icb)%z3(:,:,1) * rLfus )                      ! latent heat from icebergs melting
1979      IF ( iom_use('hflx_rain_cea')    ) CALL iom_put('hflx_rain_cea'   , ( tprecip(:,:) - sprecip(:,:) ) * zcptrain(:,:) )        ! heat flux from rain (cell average)
1980      IF ( iom_use('hflx_evap_cea')    ) CALL iom_put('hflx_evap_cea'   , ( frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) &
1981           &                                                              * picefr(:,:) ) * zcptn(:,:) * tmask(:,:,1) )            ! heat flux from evap (cell average)
1982      IF ( iom_use('hflx_snow_cea')    ) CALL iom_put('hflx_snow_cea'   , sprecip(:,:) * ( zcptsnw(:,:) - rLfus )  )               ! heat flux from snow (cell average)
1983      IF ( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea', sprecip(:,:) * ( zcptsnw(:,:) - rLfus ) &
1984           &                                                              * ( 1._wp - zsnw(:,:) )                  )               ! heat flux from snow (over ocean)
1985      IF ( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea', sprecip(:,:) * ( zcptsnw(:,:) - rLfus ) & 
1986           &                                                              *           zsnw(:,:)                    )               ! heat flux from snow (over ice)
1987      ! note: hflx for runoff and iceshelf are done in sbcrnf and sbcisf resp.
1988      !
1989      !                                                      ! ========================= !
1990      SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )                !      solar heat fluxes    !   (qsr)
1991      !                                                      ! ========================= !
1992      CASE( 'oce only' )
1993         zqsr_tot(:,:  ) = MAX( 0._wp , frcv(jpr_qsroce)%z3(:,:,1) )
1994      CASE( 'conservative' )
1995         zqsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
1996         IF ( TRIM(sn_rcv_qsr%clcat) == 'yes' ) THEN
1997            zqsr_ice(:,:,1:jpl) = frcv(jpr_qsrice)%z3(:,:,1:jpl)
1998         ELSE
1999            ! Set all category values equal for the moment
2000            DO jl = 1, jpl
2001               zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
2002            END DO
2003         ENDIF
2004         zqsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
2005         zqsr_ice(:,:,1) = frcv(jpr_qsrice)%z3(:,:,1)
2006      CASE( 'oce and ice' )
2007         zqsr_tot(:,:  ) =  ziceld(:,:) * frcv(jpr_qsroce)%z3(:,:,1)
2008         IF ( TRIM(sn_rcv_qsr%clcat) == 'yes' ) THEN
2009            DO jl = 1, jpl
2010               zqsr_tot(:,:   ) = zqsr_tot(:,:) + a_i(:,:,jl) * frcv(jpr_qsrice)%z3(:,:,jl)   
2011               zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,jl)
2012            END DO
2013         ELSE
2014            qsr_tot(:,:   ) = qsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
2015            DO jl = 1, jpl
2016               zqsr_tot(:,:   ) = zqsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
2017               zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
2018            END DO
2019         ENDIF
2020      CASE( 'mixed oce-ice' )
2021         zqsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
2022! ** NEED TO SORT OUT HOW THIS SHOULD WORK IN THE MULTI-CATEGORY CASE - CURRENTLY NOT ALLOWED WHEN INTERFACE INITIALISED **
2023!       Create solar heat flux over ice using incoming solar heat flux and albedos
2024!       ( see OASIS3 user guide, 5th edition, p39 )
2025         zqsr_ice(:,:,1) = frcv(jpr_qsrmix)%z3(:,:,1) * ( 1.- palbi(:,:,1) )   &
2026            &            / (  1.- ( alb_oce_mix(:,:  ) * ziceld(:,:)       &
2027            &                     + palbi      (:,:,1) * picefr(:,:) ) )
2028      CASE( 'none'      )       ! Not available as for now: needs additional coding 
2029      !                         ! since fields received, here zqsr_tot,  are not defined with none option
2030         CALL ctl_stop( 'STOP', 'sbccpl/sbc_cpl_ice_flx: some fields are not defined. Change sn_rcv_qsr value in namelist namsbc_cpl' )
2031      END SELECT
2032      IF( ln_dm2dc .AND. ln_cpl ) THEN   ! modify qsr to include the diurnal cycle
2033         zqsr_tot(:,:  ) = sbc_dcy( zqsr_tot(:,:  ) )
2034         DO jl = 1, jpl
2035            zqsr_ice(:,:,jl) = sbc_dcy( zqsr_ice(:,:,jl) )
2036         END DO
2037      ENDIF
2038
2039#if defined key_si3
2040      ! --- solar flux over ocean --- !
2041      !         note: ziceld cannot be = 0 since we limit the ice concentration to amax
2042      zqsr_oce = 0._wp
2043      WHERE( ziceld /= 0._wp )  zqsr_oce(:,:) = ( zqsr_tot(:,:) - SUM( a_i * zqsr_ice, dim=3 ) ) / ziceld(:,:)
2044
2045      IF( ln_mixcpl ) THEN   ;   qsr_oce(:,:) = qsr_oce(:,:) * xcplmask(:,:,0) +  zqsr_oce(:,:)* zmsk(:,:)
2046      ELSE                   ;   qsr_oce(:,:) = zqsr_oce(:,:)   ;   ENDIF
2047#endif
2048
2049      IF( ln_mixcpl ) THEN
2050         qsr_tot(:,:) = qsr(:,:) * ziceld(:,:) + SUM( qsr_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
2051         qsr_tot(:,:) = qsr_tot(:,:) * xcplmask(:,:,0) +  zqsr_tot(:,:)* zmsk(:,:)
2052         DO jl = 1, jpl
2053            qsr_ice(:,:,jl) = qsr_ice(:,:,jl) * xcplmask(:,:,0) +  zqsr_ice(:,:,jl)* zmsk(:,:)
2054         END DO
2055      ELSE
2056         qsr_tot(:,:  ) = zqsr_tot(:,:  )
2057         qsr_ice(:,:,:) = zqsr_ice(:,:,:)
2058      ENDIF
2059
2060      !                                                      ! ========================= !
2061      SELECT CASE( TRIM( sn_rcv_dqnsdt%cldes ) )             !          d(qns)/dt        !
2062      !                                                      ! ========================= !
2063      CASE ('coupled')
2064         IF ( TRIM(sn_rcv_dqnsdt%clcat) == 'yes' ) THEN
2065            zdqns_ice(:,:,1:jpl) = frcv(jpr_dqnsdt)%z3(:,:,1:jpl)
2066         ELSE
2067            ! Set all category values equal for the moment
2068            DO jl=1,jpl
2069               zdqns_ice(:,:,jl) = frcv(jpr_dqnsdt)%z3(:,:,1)
2070            ENDDO
2071         ENDIF
2072      END SELECT
2073     
2074      IF( ln_mixcpl ) THEN
2075         DO jl=1,jpl
2076            dqns_ice(:,:,jl) = dqns_ice(:,:,jl) * xcplmask(:,:,0) + zdqns_ice(:,:,jl) * zmsk(:,:)
2077         ENDDO
2078      ELSE
2079         dqns_ice(:,:,:) = zdqns_ice(:,:,:)
2080      ENDIF
2081
2082#if defined key_si3     
2083      !                                                      ! ========================= !
2084      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )             !  ice topmelt and botmelt  !
2085      !                                                      ! ========================= !
2086      CASE ('coupled')
2087         qml_ice(:,:,:) = frcv(jpr_topm)%z3(:,:,:)
2088         qcn_ice(:,:,:) = frcv(jpr_botm)%z3(:,:,:)
2089      END SELECT
2090      !
2091      !                                                      ! ========================= !
2092      !                                                      !      Transmitted Qsr      !   [W/m2]
2093      !                                                      ! ========================= !
2094      IF( .NOT.ln_cndflx ) THEN                              !==  No conduction flux as surface forcing  ==!
2095         !
2096         !                    ! ===> used prescribed cloud fraction representative for polar oceans in summer (0.81)
2097         ztri = 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice    ! surface transmission parameter (Grenfell Maykut 77)
2098         !
2099         qtr_ice_top(:,:,:) = ztri * qsr_ice(:,:,:)
2100         WHERE( phs(:,:,:) >= 0.0_wp )   qtr_ice_top(:,:,:) = 0._wp            ! snow fully opaque
2101         WHERE( phi(:,:,:) <= 0.1_wp )   qtr_ice_top(:,:,:) = qsr_ice(:,:,:)   ! thin ice transmits all solar radiation
2102         !     
2103      ELSEIF( ln_cndflx .AND. .NOT.ln_cndemulate ) THEN      !==  conduction flux as surface forcing  ==!
2104         !
2105         !                    ! ===> here we must receive the qtr_ice_top array from the coupler
2106         !                           for now just assume zero (fully opaque ice)
2107         qtr_ice_top(:,:,:) = 0._wp
2108         !
2109      ENDIF
2110      !
2111#endif
2112      !
2113   END SUBROUTINE sbc_cpl_ice_flx
2114   
2115   
2116   SUBROUTINE sbc_cpl_snd( kt )
2117      !!----------------------------------------------------------------------
2118      !!             ***  ROUTINE sbc_cpl_snd  ***
2119      !!
2120      !! ** Purpose :   provide the ocean-ice informations to the atmosphere
2121      !!
2122      !! ** Method  :   send to the atmosphere through a call to cpl_snd
2123      !!              all the needed fields (as defined in sbc_cpl_init)
2124      !!----------------------------------------------------------------------
2125      INTEGER, INTENT(in) ::   kt
2126      !
2127      INTEGER ::   ji, jj, jl   ! dummy loop indices
2128      INTEGER ::   ikchoix
2129      INTEGER ::   isec, info   ! local integer
2130      REAL(wp) ::   zumax, zvmax
2131      REAL(wp), DIMENSION(jpi,jpj)     ::   zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1
2132      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   ztmp3, ztmp4   
2133      !!----------------------------------------------------------------------
2134      !
2135      isec = ( kt - nit000 ) * NINT( rdt )        ! date of exchanges
2136
2137      zfr_l(:,:) = 1.- fr_i(:,:)
2138      !                                                      ! ------------------------- !
2139      !                                                      !    Surface temperature    !   in Kelvin
2140      !                                                      ! ------------------------- !
2141      IF( ssnd(jps_toce)%laction .OR. ssnd(jps_tice)%laction .OR. ssnd(jps_tmix)%laction ) THEN
2142         
2143         IF ( nn_components == jp_iam_opa ) THEN
2144            ztmp1(:,:) = tsn(:,:,1,jp_tem)   ! send temperature as it is (potential or conservative) -> use of l_useCT on the received part
2145         ELSE
2146            ! we must send the surface potential temperature
2147            IF( l_useCT )  THEN    ;   ztmp1(:,:) = eos_pt_from_ct( tsn(:,:,1,jp_tem), tsn(:,:,1,jp_sal) )
2148            ELSE                   ;   ztmp1(:,:) = tsn(:,:,1,jp_tem)
2149            ENDIF
2150            !
2151            SELECT CASE( sn_snd_temp%cldes)
2152            CASE( 'oce only'             )   ;   ztmp1(:,:) =   ztmp1(:,:) + rt0
2153            CASE( 'oce and ice'          )   ;   ztmp1(:,:) =   ztmp1(:,:) + rt0
2154               SELECT CASE( sn_snd_temp%clcat )
2155               CASE( 'yes' )   
2156                  ztmp3(:,:,1:jpl) = tn_ice(:,:,1:jpl)
2157               CASE( 'no' )
2158                  WHERE( SUM( a_i, dim=3 ) /= 0. )
2159                     ztmp3(:,:,1) = SUM( tn_ice * a_i, dim=3 ) / SUM( a_i, dim=3 )
2160                  ELSEWHERE
2161                     ztmp3(:,:,1) = rt0
2162                  END WHERE
2163               CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' )
2164               END SELECT
2165            CASE( 'weighted oce and ice' )   ;   ztmp1(:,:) = ( ztmp1(:,:) + rt0 ) * zfr_l(:,:)   
2166               SELECT CASE( sn_snd_temp%clcat )
2167               CASE( 'yes' )   
2168                  ztmp3(:,:,1:jpl) = tn_ice(:,:,1:jpl) * a_i(:,:,1:jpl)
2169               CASE( 'no' )
2170                  ztmp3(:,:,:) = 0.0
2171                  DO jl=1,jpl
2172                     ztmp3(:,:,1) = ztmp3(:,:,1) + tn_ice(:,:,jl) * a_i(:,:,jl)
2173                  ENDDO
2174               CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' )
2175               END SELECT
2176            CASE( 'oce and weighted ice')    ;   ztmp1(:,:) =   tsn(:,:,1,jp_tem) + rt0 
2177               SELECT CASE( sn_snd_temp%clcat ) 
2178               CASE( 'yes' )   
2179                  ztmp3(:,:,1:jpl) = tn_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
2180               CASE( 'no' ) 
2181                  ztmp3(:,:,:) = 0.0 
2182                  DO jl=1,jpl 
2183                     ztmp3(:,:,1) = ztmp3(:,:,1) + tn_ice(:,:,jl) * a_i(:,:,jl) 
2184                  ENDDO 
2185               CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' ) 
2186               END SELECT
2187            CASE( 'mixed oce-ice'        )   
2188               ztmp1(:,:) = ( ztmp1(:,:) + rt0 ) * zfr_l(:,:) 
2189               DO jl=1,jpl
2190                  ztmp1(:,:) = ztmp1(:,:) + tn_ice(:,:,jl) * a_i(:,:,jl)
2191               ENDDO
2192            CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%cldes' )
2193            END SELECT
2194         ENDIF
2195         IF( ssnd(jps_toce)%laction )   CALL cpl_snd( jps_toce, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
2196         IF( ssnd(jps_tice)%laction )   CALL cpl_snd( jps_tice, isec, ztmp3, info )
2197         IF( ssnd(jps_tmix)%laction )   CALL cpl_snd( jps_tmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
2198      ENDIF
2199      !
2200      !                                                      ! ------------------------- !
2201      !                                                      ! 1st layer ice/snow temp.  !
2202      !                                                      ! ------------------------- !
2203#if defined key_si3
2204      ! needed by  Met Office
2205      IF( ssnd(jps_ttilyr)%laction) THEN
2206         SELECT CASE( sn_snd_ttilyr%cldes)
2207         CASE ('weighted ice')
2208            ztmp3(:,:,1:jpl) = t1_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
2209         CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_ttilyr%cldes' )
2210         END SELECT
2211         IF( ssnd(jps_ttilyr)%laction )   CALL cpl_snd( jps_ttilyr, isec, ztmp3, info )
2212      ENDIF
2213#endif
2214      !                                                      ! ------------------------- !
2215      !                                                      !           Albedo          !
2216      !                                                      ! ------------------------- !
2217      IF( ssnd(jps_albice)%laction ) THEN                         ! ice
2218          SELECT CASE( sn_snd_alb%cldes )
2219          CASE( 'ice' )
2220             SELECT CASE( sn_snd_alb%clcat )
2221             CASE( 'yes' )   
2222                ztmp3(:,:,1:jpl) = alb_ice(:,:,1:jpl)
2223             CASE( 'no' )
2224                WHERE( SUM( a_i, dim=3 ) /= 0. )
2225                   ztmp1(:,:) = SUM( alb_ice (:,:,1:jpl) * a_i(:,:,1:jpl), dim=3 ) / SUM( a_i(:,:,1:jpl), dim=3 )
2226                ELSEWHERE
2227                   ztmp1(:,:) = alb_oce_mix(:,:)
2228                END WHERE
2229             CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_alb%clcat' )
2230             END SELECT
2231          CASE( 'weighted ice' )   ;
2232             SELECT CASE( sn_snd_alb%clcat )
2233             CASE( 'yes' )   
2234                ztmp3(:,:,1:jpl) =  alb_ice(:,:,1:jpl) * a_i(:,:,1:jpl)
2235             CASE( 'no' )
2236                WHERE( fr_i (:,:) > 0. )
2237                   ztmp1(:,:) = SUM (  alb_ice(:,:,1:jpl) * a_i(:,:,1:jpl), dim=3 )
2238                ELSEWHERE
2239                   ztmp1(:,:) = 0.
2240                END WHERE
2241             CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_ice%clcat' )
2242             END SELECT
2243          CASE default      ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_alb%cldes' )
2244         END SELECT
2245
2246         SELECT CASE( sn_snd_alb%clcat )
2247            CASE( 'yes' )   
2248               CALL cpl_snd( jps_albice, isec, ztmp3, info )      !-> MV this has never been checked in coupled mode
2249            CASE( 'no'  )   
2250               CALL cpl_snd( jps_albice, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info ) 
2251         END SELECT
2252      ENDIF
2253
2254      IF( ssnd(jps_albmix)%laction ) THEN                         ! mixed ice-ocean
2255         ztmp1(:,:) = alb_oce_mix(:,:) * zfr_l(:,:)
2256         DO jl = 1, jpl
2257            ztmp1(:,:) = ztmp1(:,:) + alb_ice(:,:,jl) * a_i(:,:,jl)
2258         END DO
2259         CALL cpl_snd( jps_albmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
2260      ENDIF
2261      !                                                      ! ------------------------- !
2262      !                                                      !  Ice fraction & Thickness !
2263      !                                                      ! ------------------------- !
2264      ! Send ice fraction field to atmosphere
2265      IF( ssnd(jps_fice)%laction ) THEN
2266         SELECT CASE( sn_snd_thick%clcat )
2267         CASE( 'yes' )   ;   ztmp3(:,:,1:jpl) =  a_i(:,:,1:jpl)
2268         CASE( 'no'  )   ;   ztmp3(:,:,1    ) = fr_i(:,:      )
2269         CASE default    ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
2270         END SELECT
2271         IF( ssnd(jps_fice)%laction )   CALL cpl_snd( jps_fice, isec, ztmp3, info )
2272      ENDIF
2273
2274      IF( ssnd(jps_fice1)%laction ) THEN
2275         SELECT CASE( sn_snd_thick1%clcat )
2276         CASE( 'yes' )   ;   ztmp3(:,:,1:jpl) =  a_i(:,:,1:jpl)
2277         CASE( 'no'  )   ;   ztmp3(:,:,1    ) = fr_i(:,:      )
2278         CASE default    ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick1%clcat' )
2279         END SELECT
2280         CALL cpl_snd( jps_fice1, isec, ztmp3, info )
2281      ENDIF
2282     
2283      ! Send ice fraction field to OPA (sent by SAS in SAS-OPA coupling)
2284      IF( ssnd(jps_fice2)%laction ) THEN
2285         ztmp3(:,:,1) = fr_i(:,:)
2286         IF( ssnd(jps_fice2)%laction )   CALL cpl_snd( jps_fice2, isec, ztmp3, info )
2287      ENDIF
2288
2289      ! Send ice and snow thickness field
2290      IF( ssnd(jps_hice)%laction .OR. ssnd(jps_hsnw)%laction ) THEN
2291         SELECT CASE( sn_snd_thick%cldes)
2292         CASE( 'none'                  )       ! nothing to do
2293         CASE( 'weighted ice and snow' )   
2294            SELECT CASE( sn_snd_thick%clcat )
2295            CASE( 'yes' )   
2296               ztmp3(:,:,1:jpl) =  h_i(:,:,1:jpl) * a_i(:,:,1:jpl)
2297               ztmp4(:,:,1:jpl) =  h_s(:,:,1:jpl) * a_i(:,:,1:jpl)
2298            CASE( 'no' )
2299               ztmp3(:,:,:) = 0.0   ;  ztmp4(:,:,:) = 0.0
2300               DO jl=1,jpl
2301                  ztmp3(:,:,1) = ztmp3(:,:,1) + h_i(:,:,jl) * a_i(:,:,jl)
2302                  ztmp4(:,:,1) = ztmp4(:,:,1) + h_s(:,:,jl) * a_i(:,:,jl)
2303               ENDDO
2304            CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
2305            END SELECT
2306         CASE( 'ice and snow'         )   
2307            SELECT CASE( sn_snd_thick%clcat )
2308            CASE( 'yes' )
2309               ztmp3(:,:,1:jpl) = h_i(:,:,1:jpl)
2310               ztmp4(:,:,1:jpl) = h_s(:,:,1:jpl)
2311            CASE( 'no' )
2312               WHERE( SUM( a_i, dim=3 ) /= 0. )
2313                  ztmp3(:,:,1) = SUM( h_i * a_i, dim=3 ) / SUM( a_i, dim=3 )
2314                  ztmp4(:,:,1) = SUM( h_s * a_i, dim=3 ) / SUM( a_i, dim=3 )
2315               ELSEWHERE
2316                 ztmp3(:,:,1) = 0.
2317                 ztmp4(:,:,1) = 0.
2318               END WHERE
2319            CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
2320            END SELECT
2321         CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%cldes' )
2322         END SELECT
2323         IF( ssnd(jps_hice)%laction )   CALL cpl_snd( jps_hice, isec, ztmp3, info )
2324         IF( ssnd(jps_hsnw)%laction )   CALL cpl_snd( jps_hsnw, isec, ztmp4, info )
2325      ENDIF
2326
2327#if defined key_si3
2328      !                                                      ! ------------------------- !
2329      !                                                      !      Ice melt ponds       !
2330      !                                                      ! ------------------------- !
2331      ! needed by Met Office
2332      IF( ssnd(jps_a_p)%laction .OR. ssnd(jps_ht_p)%laction ) THEN
2333         SELECT CASE( sn_snd_mpnd%cldes) 
2334         CASE( 'ice only' ) 
2335            SELECT CASE( sn_snd_mpnd%clcat ) 
2336            CASE( 'yes' ) 
2337               ztmp3(:,:,1:jpl) =  a_ip(:,:,1:jpl)
2338               ztmp4(:,:,1:jpl) =  v_ip(:,:,1:jpl) 
2339            CASE( 'no' ) 
2340               ztmp3(:,:,:) = 0.0 
2341               ztmp4(:,:,:) = 0.0 
2342               DO jl=1,jpl 
2343                 ztmp3(:,:,1) = ztmp3(:,:,1) + a_ip(:,:,jpl) 
2344                 ztmp4(:,:,1) = ztmp4(:,:,1) + v_ip(:,:,jpl) 
2345               ENDDO 
2346            CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_mpnd%clcat' ) 
2347            END SELECT 
2348         CASE default      ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_mpnd%cldes' )     
2349         END SELECT 
2350         IF( ssnd(jps_a_p)%laction  )   CALL cpl_snd( jps_a_p , isec, ztmp3, info )     
2351         IF( ssnd(jps_ht_p)%laction )   CALL cpl_snd( jps_ht_p, isec, ztmp4, info )     
2352      ENDIF 
2353      !
2354      !                                                      ! ------------------------- !
2355      !                                                      !     Ice conductivity      !
2356      !                                                      ! ------------------------- !
2357      ! needed by Met Office
2358      IF( ssnd(jps_kice)%laction ) THEN
2359         SELECT CASE( sn_snd_cond%cldes) 
2360         CASE( 'weighted ice' )   
2361            SELECT CASE( sn_snd_cond%clcat ) 
2362            CASE( 'yes' )   
2363          ztmp3(:,:,1:jpl) =  cnd_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
2364            CASE( 'no' ) 
2365               ztmp3(:,:,:) = 0.0 
2366               DO jl=1,jpl 
2367                 ztmp3(:,:,1) = ztmp3(:,:,1) + cnd_ice(:,:,jl) * a_i(:,:,jl) 
2368               ENDDO 
2369            CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_cond%clcat' ) 
2370            END SELECT
2371         CASE( 'ice only' )   
2372           ztmp3(:,:,1:jpl) = cnd_ice(:,:,1:jpl) 
2373         CASE default      ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_cond%cldes' )     
2374         END SELECT
2375         IF( ssnd(jps_kice)%laction )   CALL cpl_snd( jps_kice, isec, ztmp3, info ) 
2376      ENDIF 
2377#endif
2378
2379      !                                                      ! ------------------------- !
2380      !                                                      !  CO2 flux from PISCES     !
2381      !                                                      ! ------------------------- !
2382      IF( ssnd(jps_co2)%laction .AND. l_co2cpl )   CALL cpl_snd( jps_co2, isec, RESHAPE ( oce_co2, (/jpi,jpj,1/) ) , info )
2383      !
2384      !                                                      ! ------------------------- !
2385      IF( ssnd(jps_ocx1)%laction ) THEN                      !      Surface current      !
2386         !                                                   ! ------------------------- !
2387         !   
2388         !                                                  j+1   j     -----V---F
2389         ! surface velocity always sent from T point                     !       |
2390         ! [except for HadGEM3]                                   j      |   T   U
2391         !                                                               |       |
2392         !                                                   j    j-1   -I-------|
2393         !                                               (for I)         |       |
2394         !                                                              i-1  i   i
2395         !                                                               i      i+1 (for I)
2396         IF( nn_components == jp_iam_opa ) THEN
2397            zotx1(:,:) = un(:,:,1) 
2398            zoty1(:,:) = vn(:,:,1) 
2399         ELSE       
2400            SELECT CASE( TRIM( sn_snd_crt%cldes ) )
2401            CASE( 'oce only'             )      ! C-grid ==> T
2402               IF ( TRIM( sn_snd_crt%clvgrd ) == 'T' ) THEN
2403                  DO jj = 2, jpjm1
2404                     DO ji = fs_2, fs_jpim1   ! vector opt.
2405                        zotx1(ji,jj) = 0.5 * ( un(ji,jj,1) + un(ji-1,jj  ,1) )
2406                        zoty1(ji,jj) = 0.5 * ( vn(ji,jj,1) + vn(ji  ,jj-1,1) ) 
2407                     END DO
2408                  END DO
2409               ELSE
2410! Temporarily Changed for UKV
2411                  DO jj = 2, jpjm1
2412                     DO ji = 2, jpim1
2413                        zotx1(ji,jj) = un(ji,jj,1)
2414                        zoty1(ji,jj) = vn(ji,jj,1)
2415                     END DO
2416                  END DO
2417               ENDIF
2418            CASE( 'weighted oce and ice' )      ! Ocean and Ice on C-grid ==> T 
2419               DO jj = 2, jpjm1
2420                  DO ji = fs_2, fs_jpim1   ! vector opt.
2421                     zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj) 
2422                     zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj)
2423                     zitx1(ji,jj) = 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj)
2424                     zity1(ji,jj) = 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj)
2425                  END DO
2426               END DO
2427               CALL lbc_lnk_multi( 'sbccpl', zitx1, 'T', -1., zity1, 'T', -1. )
2428            CASE( 'mixed oce-ice'        )      ! Ocean and Ice on C-grid ==> T
2429               DO jj = 2, jpjm1
2430                  DO ji = fs_2, fs_jpim1   ! vector opt.
2431                     zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj)   &
2432                        &         + 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj)
2433                     zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj)   &
2434                        &         + 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj)
2435                  END DO
2436               END DO
2437            END SELECT
2438            CALL lbc_lnk_multi( 'sbccpl', zotx1, ssnd(jps_ocx1)%clgrid, -1.,  zoty1, ssnd(jps_ocy1)%clgrid, -1. )
2439            !
2440         ENDIF
2441         !
2442         !
2443         IF( TRIM( sn_snd_crt%clvor ) == 'eastward-northward' ) THEN             ! Rotation of the components
2444            !                                                                     ! Ocean component
2445            IF ( TRIM( sn_snd_crt%clvgrd ) == 'T' ) THEN
2446               CALL rot_rep( zotx1, zoty1, ssnd(jps_ocx1)%clgrid, 'ij->e', ztmp1 )       ! 1st component
2447               CALL rot_rep( zotx1, zoty1, ssnd(jps_ocx1)%clgrid, 'ij->n', ztmp2 )       ! 2nd component
2448               zotx1(:,:) = ztmp1(:,:)                                                   ! overwrite the components
2449               zoty1(:,:) = ztmp2(:,:)
2450               IF( ssnd(jps_ivx1)%laction ) THEN                                  ! Ice component
2451                  CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->e', ztmp1 )    ! 1st component
2452                  CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->n', ztmp2 )    ! 2nd component
2453                  zitx1(:,:) = ztmp1(:,:)                                                ! overwrite the components
2454                  zity1(:,:) = ztmp2(:,:)
2455               ENDIF
2456            ELSE
2457               ! Temporary code for HadGEM3 - will be removed eventually.
2458               ! Only applies when we want uvel on U grid and vvel on V grid
2459               ! Rotate U and V onto geographic grid before sending.
2460
2461               DO jj=2,jpjm1
2462                  DO ji=2,jpim1
2463                     ztmp1(ji,jj)=0.25*vmask(ji,jj,1)                  &
2464                          *(zotx1(ji,jj)+zotx1(ji-1,jj)    &
2465                          +zotx1(ji,jj+1)+zotx1(ji-1,jj+1))
2466                     ztmp2(ji,jj)=0.25*umask(ji,jj,1)                  &
2467                          *(zoty1(ji,jj)+zoty1(ji+1,jj)    &
2468                          +zoty1(ji,jj-1)+zoty1(ji+1,jj-1))
2469                  ENDDO
2470               ENDDO
2471               
2472               ! Ensure any N fold and wrap columns are updated
2473               CALL lbc_lnk('zotx1', ztmp1, 'V', -1.0)
2474               CALL lbc_lnk('zoty1', ztmp2, 'U', -1.0)
2475               
2476               ikchoix = -1
2477               CALL repcmo (zotx1,ztmp2,ztmp1,zoty1,zotx1,zoty1,ikchoix)
2478           ENDIF
2479         ENDIF
2480         !
2481         ! spherical coordinates to cartesian -> 2 components to 3 components
2482         IF( TRIM( sn_snd_crt%clvref ) == 'cartesian' ) THEN
2483            ztmp1(:,:) = zotx1(:,:)                     ! ocean currents
2484            ztmp2(:,:) = zoty1(:,:)
2485            CALL oce2geo ( ztmp1, ztmp2, 'T', zotx1, zoty1, zotz1 )
2486            !
2487            IF( ssnd(jps_ivx1)%laction ) THEN           ! ice velocities
2488               ztmp1(:,:) = zitx1(:,:)
2489               ztmp1(:,:) = zity1(:,:)
2490               CALL oce2geo ( ztmp1, ztmp2, 'T', zitx1, zity1, zitz1 )
2491            ENDIF
2492         ENDIF
2493         !
2494         IF( ssnd(jps_ocx1)%laction )   CALL cpl_snd( jps_ocx1, isec, RESHAPE ( zotx1, (/jpi,jpj,1/) ), info )   ! ocean x current 1st grid
2495         IF( ssnd(jps_ocy1)%laction )   CALL cpl_snd( jps_ocy1, isec, RESHAPE ( zoty1, (/jpi,jpj,1/) ), info )   ! ocean y current 1st grid
2496         IF( ssnd(jps_ocz1)%laction )   CALL cpl_snd( jps_ocz1, isec, RESHAPE ( zotz1, (/jpi,jpj,1/) ), info )   ! ocean z current 1st grid
2497         !
2498         IF( ssnd(jps_ivx1)%laction )   CALL cpl_snd( jps_ivx1, isec, RESHAPE ( zitx1, (/jpi,jpj,1/) ), info )   ! ice   x current 1st grid
2499         IF( ssnd(jps_ivy1)%laction )   CALL cpl_snd( jps_ivy1, isec, RESHAPE ( zity1, (/jpi,jpj,1/) ), info )   ! ice   y current 1st grid
2500         IF( ssnd(jps_ivz1)%laction )   CALL cpl_snd( jps_ivz1, isec, RESHAPE ( zitz1, (/jpi,jpj,1/) ), info )   ! ice   z current 1st grid
2501         !
2502      ENDIF
2503      !
2504      !                                                      ! ------------------------- !
2505      !                                                      !  Surface current to waves !
2506      !                                                      ! ------------------------- !
2507      IF( ssnd(jps_ocxw)%laction .OR. ssnd(jps_ocyw)%laction ) THEN 
2508          !     
2509          !                                                  j+1  j     -----V---F
2510          ! surface velocity always sent from T point                    !       |
2511          !                                                       j      |   T   U
2512          !                                                              |       |
2513          !                                                   j   j-1   -I-------|
2514          !                                               (for I)        |       |
2515          !                                                             i-1  i   i
2516          !                                                              i      i+1 (for I)
2517          SELECT CASE( TRIM( sn_snd_crtw%cldes ) ) 
2518          CASE( 'oce only'             )      ! C-grid ==> T
2519             DO jj = 2, jpjm1 
2520                DO ji = fs_2, fs_jpim1   ! vector opt.
2521                   zotx1(ji,jj) = 0.5 * ( un(ji,jj,1) + un(ji-1,jj  ,1) ) 
2522                   zoty1(ji,jj) = 0.5 * ( vn(ji,jj,1) + vn(ji , jj-1,1) ) 
2523                END DO
2524             END DO
2525          CASE( 'weighted oce and ice' )      ! Ocean and Ice on C-grid ==> T   
2526             DO jj = 2, jpjm1 
2527                DO ji = fs_2, fs_jpim1   ! vector opt.
2528                   zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj)   
2529                   zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj) 
2530                   zitx1(ji,jj) = 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj) 
2531                   zity1(ji,jj) = 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj) 
2532                END DO
2533             END DO
2534             CALL lbc_lnk_multi( 'sbccpl', zitx1, 'T', -1.,  zity1, 'T', -1. ) 
2535          CASE( 'mixed oce-ice'        )      ! Ocean and Ice on C-grid ==> T 
2536             DO jj = 2, jpjm1 
2537                DO ji = fs_2, fs_jpim1   ! vector opt.
2538                   zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj)   & 
2539                      &         + 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj) 
2540                   zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj)   & 
2541                      &         + 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj) 
2542                END DO
2543             END DO
2544          END SELECT
2545         CALL lbc_lnk_multi( 'sbccpl', zotx1, ssnd(jps_ocxw)%clgrid, -1., zoty1, ssnd(jps_ocyw)%clgrid, -1. ) 
2546         !
2547         !
2548         IF( TRIM( sn_snd_crtw%clvor ) == 'eastward-northward' ) THEN             ! Rotation of the components
2549         !                                                                        ! Ocean component
2550            CALL rot_rep( zotx1, zoty1, ssnd(jps_ocxw)%clgrid, 'ij->e', ztmp1 )       ! 1st component 
2551            CALL rot_rep( zotx1, zoty1, ssnd(jps_ocxw)%clgrid, 'ij->n', ztmp2 )       ! 2nd component 
2552            zotx1(:,:) = ztmp1(:,:)                                                   ! overwrite the components 
2553            zoty1(:,:) = ztmp2(:,:) 
2554            IF( ssnd(jps_ivx1)%laction ) THEN                                     ! Ice component
2555               CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->e', ztmp1 )    ! 1st component 
2556               CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->n', ztmp2 )    ! 2nd component 
2557               zitx1(:,:) = ztmp1(:,:)                                                ! overwrite the components 
2558               zity1(:,:) = ztmp2(:,:) 
2559            ENDIF
2560         ENDIF 
2561         !
2562!         ! spherical coordinates to cartesian -> 2 components to 3 components
2563!         IF( TRIM( sn_snd_crtw%clvref ) == 'cartesian' ) THEN
2564!            ztmp1(:,:) = zotx1(:,:)                     ! ocean currents
2565!            ztmp2(:,:) = zoty1(:,:)
2566!            CALL oce2geo ( ztmp1, ztmp2, 'T', zotx1, zoty1, zotz1 )
2567!            !
2568!            IF( ssnd(jps_ivx1)%laction ) THEN           ! ice velocities
2569!               ztmp1(:,:) = zitx1(:,:)
2570!               ztmp1(:,:) = zity1(:,:)
2571!               CALL oce2geo ( ztmp1, ztmp2, 'T', zitx1, zity1, zitz1 )
2572!            ENDIF
2573!         ENDIF
2574         !
2575         IF( ssnd(jps_ocxw)%laction )   CALL cpl_snd( jps_ocxw, isec, RESHAPE ( zotx1, (/jpi,jpj,1/) ), info )   ! ocean x current 1st grid
2576         IF( ssnd(jps_ocyw)%laction )   CALL cpl_snd( jps_ocyw, isec, RESHAPE ( zoty1, (/jpi,jpj,1/) ), info )   ! ocean y current 1st grid
2577         
2578      ENDIF 
2579      !
2580      IF( ssnd(jps_ficet)%laction ) THEN
2581         CALL cpl_snd( jps_ficet, isec, RESHAPE ( fr_i, (/jpi,jpj,1/) ), info ) 
2582      END IF 
2583      !                                                      ! ------------------------- !
2584      !                                                      !   Water levels to waves   !
2585      !                                                      ! ------------------------- !
2586      IF( ssnd(jps_wlev)%laction ) THEN
2587         IF( ln_apr_dyn ) THEN 
2588            IF( kt /= nit000 ) THEN 
2589               ztmp1(:,:) = sshb(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) ) 
2590            ELSE 
2591               ztmp1(:,:) = sshb(:,:) 
2592            ENDIF 
2593         ELSE 
2594            ztmp1(:,:) = sshn(:,:) 
2595         ENDIF 
2596         CALL cpl_snd( jps_wlev  , isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info ) 
2597      END IF 
2598      !
2599      !  Fields sent by OPA to SAS when doing OPA<->SAS coupling
2600      !                                                        ! SSH
2601      IF( ssnd(jps_ssh )%laction )  THEN
2602         !                          ! removed inverse barometer ssh when Patm
2603         !                          forcing is used (for sea-ice dynamics)
2604         IF( ln_apr_dyn ) THEN   ;   ztmp1(:,:) = sshb(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) )
2605         ELSE                    ;   ztmp1(:,:) = sshn(:,:)
2606         ENDIF
2607         CALL cpl_snd( jps_ssh   , isec, RESHAPE ( ztmp1            , (/jpi,jpj,1/) ), info )
2608
2609      ENDIF
2610      !                                                        ! SSS
2611      IF( ssnd(jps_soce  )%laction )  THEN
2612         CALL cpl_snd( jps_soce  , isec, RESHAPE ( tsn(:,:,1,jp_sal), (/jpi,jpj,1/) ), info )
2613      ENDIF
2614      !                                                        ! first T level thickness
2615      IF( ssnd(jps_e3t1st )%laction )  THEN
2616         CALL cpl_snd( jps_e3t1st, isec, RESHAPE ( e3t_n(:,:,1)   , (/jpi,jpj,1/) ), info )
2617      ENDIF
2618      !                                                        ! Qsr fraction
2619      IF( ssnd(jps_fraqsr)%laction )  THEN
2620         CALL cpl_snd( jps_fraqsr, isec, RESHAPE ( fraqsr_1lev(:,:) , (/jpi,jpj,1/) ), info )
2621      ENDIF
2622      !
2623      !  Fields sent by SAS to OPA when OASIS coupling
2624      !                                                        ! Solar heat flux
2625      IF( ssnd(jps_qsroce)%laction )  CALL cpl_snd( jps_qsroce, isec, RESHAPE ( qsr , (/jpi,jpj,1/) ), info )
2626      IF( ssnd(jps_qnsoce)%laction )  CALL cpl_snd( jps_qnsoce, isec, RESHAPE ( qns , (/jpi,jpj,1/) ), info )
2627      IF( ssnd(jps_oemp  )%laction )  CALL cpl_snd( jps_oemp  , isec, RESHAPE ( emp , (/jpi,jpj,1/) ), info )
2628      IF( ssnd(jps_sflx  )%laction )  CALL cpl_snd( jps_sflx  , isec, RESHAPE ( sfx , (/jpi,jpj,1/) ), info )
2629      IF( ssnd(jps_otx1  )%laction )  CALL cpl_snd( jps_otx1  , isec, RESHAPE ( utau, (/jpi,jpj,1/) ), info )
2630      IF( ssnd(jps_oty1  )%laction )  CALL cpl_snd( jps_oty1  , isec, RESHAPE ( vtau, (/jpi,jpj,1/) ), info )
2631      IF( ssnd(jps_rnf   )%laction )  CALL cpl_snd( jps_rnf   , isec, RESHAPE ( rnf , (/jpi,jpj,1/) ), info )
2632      IF( ssnd(jps_taum  )%laction )  CALL cpl_snd( jps_taum  , isec, RESHAPE ( taum, (/jpi,jpj,1/) ), info )
2633
2634#if defined key_si3
2635      !                                                      ! ------------------------- !
2636      !                                                      ! Sea surface freezing temp !
2637      !                                                      ! ------------------------- !
2638      ! needed by Met Office
2639      CALL eos_fzp(tsn(:,:,1,jp_sal), sstfrz)
2640      ztmp1(:,:) = sstfrz(:,:) + rt0
2641      IF( ssnd(jps_sstfrz)%laction )  CALL cpl_snd( jps_sstfrz, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info)
2642#endif
2643
2644      WRITE(numout,*) "RSRH at send for ocean dummy_t"; flush(numout)
2645
2646      IF ( ssnd(jps_dummy_t)%laction ) THEN
2647         ! RSRH Just set up some arbitrary test pattern for now
2648         ztmp1(:,:) = 1.23456
2649      WRITE(numout,*) "RSRH call send for ocean dummy_t"; flush(numout)
2650         CALL cpl_snd( jps_dummy_t, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
2651      WRITE(numout,*) "RSRH done send for ocean dummy_t", info; flush(numout)
2652      ENDIF
2653
2654      !
2655   END SUBROUTINE sbc_cpl_snd
2656   
2657   !!======================================================================
2658END MODULE sbccpl
Note: See TracBrowser for help on using the repository browser.