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

source: branches/UKMO/test_moci_test_suite_namelist_read/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90 @ 9366

Last change on this file since 9366 was 9366, checked in by andmirek, 6 years ago

#2050 first version. Compiled OK in moci test suite

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