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

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
sbccpl.F90 in branches/2016/dev_r7012_ROBUST5_CNRS/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2016/dev_r7012_ROBUST5_CNRS/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90 @ 7162

Last change on this file since 7162 was 7162, checked in by cetlod, 8 years ago

new top interface : Add PISCES quota model

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