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/2021/ticket2607_r14608_halo1_halo2_compatibility/src/OCE/SBC – NEMO

source: NEMO/branches/2021/ticket2607_r14608_halo1_halo2_compatibility/src/OCE/SBC/sbccpl.F90 @ 14807

Last change on this file since 14807 was 14807, checked in by hadcv, 3 years ago

#2607: Merge in trunk changes to r14778 (ticket2607_r14608_halo1_halo2_compatibility branch)

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