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 trunk/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90 @ 7788

Last change on this file since 7788 was 7788, checked in by cetlod, 7 years ago

trunk : representation of ice shelf melting in coupled mode

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