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

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

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_pkg/src/OCE/SBC/sbccpl.F90 @ 13311

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

Save dev changes for concurrent LFRIC + GO8 running

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