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 branches/2016/dev_INGV_METO_merge_2016/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2016/dev_INGV_METO_merge_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90 @ 7391

Last change on this file since 7391 was 7391, checked in by timgraham, 7 years ago

Merged in dev_r7012_ROBUST5_CNRS

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