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

source: branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90 @ 5327

Last change on this file since 5327 was 5311, checked in by cetlod, 9 years ago

dev_r5204_CNRS_PISCES_dcy : define specific grid for zonal mean

  • Property svn:keywords set to Id
File size: 94.3 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 sbcdcy          ! surface boundary condition: diurnal cycle
24   USE phycst          ! physical constants
25#if defined key_lim3
26   USE ice             ! ice variables
27#endif
28#if defined key_lim2
29   USE par_ice_2       ! ice parameters
30   USE ice_2           ! ice variables
31#endif
32   USE cpl_oasis3      ! OASIS3 coupling
33   USE geo2ocean       !
34   USE oce   , ONLY : tsn, un, vn
35   USE albedo          !
36   USE in_out_manager  ! I/O manager
37   USE iom             ! NetCDF library
38   USE lib_mpp         ! distribued memory computing library
39   USE wrk_nemo        ! work arrays
40   USE timing          ! Timing
41   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
42#if defined key_cpl_carbon_cycle
43   USE p4zflx, ONLY : oce_co2
44#endif
45#if defined key_cice
46   USE ice_domain_size, only: ncat
47#endif
48   IMPLICIT NONE
49   PRIVATE
50!EM XIOS-OASIS-MCT compliance
51   PUBLIC   sbc_cpl_init       ! routine called by sbcmod.F90
52   PUBLIC   sbc_cpl_rcv        ! routine called by sbc_ice_lim(_2).F90
53   PUBLIC   sbc_cpl_snd        ! routine called by step.F90
54   PUBLIC   sbc_cpl_ice_tau    ! routine called by sbc_ice_lim(_2).F90
55   PUBLIC   sbc_cpl_ice_flx    ! routine called by sbc_ice_lim(_2).F90
56   PUBLIC   sbc_cpl_alloc      ! routine called in sbcice_cice.F90
57
58   INTEGER, PARAMETER ::   jpr_otx1   =  1            ! 3 atmosphere-ocean stress components on grid 1
59   INTEGER, PARAMETER ::   jpr_oty1   =  2            !
60   INTEGER, PARAMETER ::   jpr_otz1   =  3            !
61   INTEGER, PARAMETER ::   jpr_otx2   =  4            ! 3 atmosphere-ocean stress components on grid 2
62   INTEGER, PARAMETER ::   jpr_oty2   =  5            !
63   INTEGER, PARAMETER ::   jpr_otz2   =  6            !
64   INTEGER, PARAMETER ::   jpr_itx1   =  7            ! 3 atmosphere-ice   stress components on grid 1
65   INTEGER, PARAMETER ::   jpr_ity1   =  8            !
66   INTEGER, PARAMETER ::   jpr_itz1   =  9            !
67   INTEGER, PARAMETER ::   jpr_itx2   = 10            ! 3 atmosphere-ice   stress components on grid 2
68   INTEGER, PARAMETER ::   jpr_ity2   = 11            !
69   INTEGER, PARAMETER ::   jpr_itz2   = 12            !
70   INTEGER, PARAMETER ::   jpr_qsroce = 13            ! Qsr above the ocean
71   INTEGER, PARAMETER ::   jpr_qsrice = 14            ! Qsr above the ice
72   INTEGER, PARAMETER ::   jpr_qsrmix = 15 
73   INTEGER, PARAMETER ::   jpr_qnsoce = 16            ! Qns above the ocean
74   INTEGER, PARAMETER ::   jpr_qnsice = 17            ! Qns above the ice
75   INTEGER, PARAMETER ::   jpr_qnsmix = 18
76   INTEGER, PARAMETER ::   jpr_rain   = 19            ! total liquid precipitation (rain)
77   INTEGER, PARAMETER ::   jpr_snow   = 20            ! solid precipitation over the ocean (snow)
78   INTEGER, PARAMETER ::   jpr_tevp   = 21            ! total evaporation
79   INTEGER, PARAMETER ::   jpr_ievp   = 22            ! solid evaporation (sublimation)
80   INTEGER, PARAMETER ::   jpr_sbpr   = 23            ! sublimation - liquid precipitation - solid precipitation
81   INTEGER, PARAMETER ::   jpr_semp   = 24            ! solid freshwater budget (sublimation - snow)
82   INTEGER, PARAMETER ::   jpr_oemp   = 25            ! ocean freshwater budget (evap - precip)
83   INTEGER, PARAMETER ::   jpr_w10m   = 26            ! 10m wind
84   INTEGER, PARAMETER ::   jpr_dqnsdt = 27            ! d(Q non solar)/d(temperature)
85   INTEGER, PARAMETER ::   jpr_rnf    = 28            ! runoffs
86   INTEGER, PARAMETER ::   jpr_cal    = 29            ! calving
87   INTEGER, PARAMETER ::   jpr_taum   = 30            ! wind stress module
88   INTEGER, PARAMETER ::   jpr_co2    = 31
89   INTEGER, PARAMETER ::   jpr_topm   = 32            ! topmeltn
90   INTEGER, PARAMETER ::   jpr_botm   = 33            ! botmeltn
91   INTEGER, PARAMETER ::   jprcv      = 33            ! total number of fields received
92
93   INTEGER, PARAMETER ::   jps_fice   =  1            ! ice fraction
94   INTEGER, PARAMETER ::   jps_toce   =  2            ! ocean temperature
95   INTEGER, PARAMETER ::   jps_tice   =  3            ! ice   temperature
96   INTEGER, PARAMETER ::   jps_tmix   =  4            ! mixed temperature (ocean+ice)
97   INTEGER, PARAMETER ::   jps_albice =  5            ! ice   albedo
98   INTEGER, PARAMETER ::   jps_albmix =  6            ! mixed albedo
99   INTEGER, PARAMETER ::   jps_hice   =  7            ! ice  thickness
100   INTEGER, PARAMETER ::   jps_hsnw   =  8            ! snow thickness
101   INTEGER, PARAMETER ::   jps_ocx1   =  9            ! ocean current on grid 1
102   INTEGER, PARAMETER ::   jps_ocy1   = 10            !
103   INTEGER, PARAMETER ::   jps_ocz1   = 11            !
104   INTEGER, PARAMETER ::   jps_ivx1   = 12            ! ice   current on grid 1
105   INTEGER, PARAMETER ::   jps_ivy1   = 13            !
106   INTEGER, PARAMETER ::   jps_ivz1   = 14            !
107   INTEGER, PARAMETER ::   jps_co2    = 15
108   INTEGER, PARAMETER ::   jpsnd      = 15            ! total number of fields sended
109
110   !                                                         !!** namelist namsbc_cpl **
111   TYPE ::   FLD_C
112      CHARACTER(len = 32) ::   cldes                  ! desciption of the coupling strategy
113      CHARACTER(len = 32) ::   clcat                  ! multiple ice categories strategy
114      CHARACTER(len = 32) ::   clvref                 ! reference of vector ('spherical' or 'cartesian')
115      CHARACTER(len = 32) ::   clvor                  ! orientation of vector fields ('eastward-northward' or 'local grid')
116      CHARACTER(len = 32) ::   clvgrd                 ! grids on which is located the vector fields
117   END TYPE FLD_C
118   ! Send to the atmosphere                           !
119   TYPE(FLD_C) ::   sn_snd_temp, sn_snd_alb, sn_snd_thick, sn_snd_crt, sn_snd_co2                       
120   ! Received from the atmosphere                     !
121   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
122   TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2                       
123   ! Other namelist parameters                        !
124   INTEGER     ::   nn_cplmodel            ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
125   LOGICAL     ::   ln_usecplmask          !  use a coupling mask file to merge data received from several models
126                                           !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
127
128   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: xcplmask
129
130   TYPE ::   DYNARR     
131      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z3   
132   END TYPE DYNARR
133
134   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                      ! all fields recieved from the atmosphere
135
136   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   albedo_oce_mix     ! ocean albedo sent to atmosphere (mix clear/overcast sky)
137
138   INTEGER , ALLOCATABLE, SAVE, DIMENSION(    :) ::   nrcvinfo           ! OASIS info argument
139
140   !! Substitution
141#  include "vectopt_loop_substitute.h90"
142   !!----------------------------------------------------------------------
143   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
144   !! $Id$
145   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
146   !!----------------------------------------------------------------------
147
148CONTAINS
149 
150   INTEGER FUNCTION sbc_cpl_alloc()
151      !!----------------------------------------------------------------------
152      !!             ***  FUNCTION sbc_cpl_alloc  ***
153      !!----------------------------------------------------------------------
154      INTEGER :: ierr(3)
155      !!----------------------------------------------------------------------
156      ierr(:) = 0
157      !
158      ALLOCATE( albedo_oce_mix(jpi,jpj), nrcvinfo(jprcv),  STAT=ierr(1) )
159     
160#if ! defined key_lim3 && ! defined key_lim2 && ! defined key_cice
161      ALLOCATE( a_i(jpi,jpj,1) , STAT=ierr(2) )  ! used in sbcice_if.F90 (done here as there is no sbc_ice_if_init)
162#endif
163      ALLOCATE( xcplmask(jpi,jpj,nn_cplmodel) , STAT=ierr(3) )
164      !
165      sbc_cpl_alloc = MAXVAL( ierr )
166      IF( lk_mpp            )   CALL mpp_sum ( sbc_cpl_alloc )
167      IF( sbc_cpl_alloc > 0 )   CALL ctl_warn('sbc_cpl_alloc: allocation of arrays failed')
168      !
169   END FUNCTION sbc_cpl_alloc
170
171
172   SUBROUTINE sbc_cpl_init( k_ice )     
173      !!----------------------------------------------------------------------
174      !!             ***  ROUTINE sbc_cpl_init  ***
175      !!
176      !! ** Purpose :   Initialisation of send and received information from
177      !!                the atmospheric component
178      !!
179      !! ** Method  : * Read namsbc_cpl namelist
180      !!              * define the receive interface
181      !!              * define the send    interface
182      !!              * initialise the OASIS coupler
183      !!----------------------------------------------------------------------
184      INTEGER, INTENT(in) ::   k_ice    ! ice management in the sbc (=0/1/2/3)
185      !!
186      INTEGER ::   jn   ! dummy loop index
187      INTEGER ::   ios  ! Local integer output status for namelist read
188      INTEGER ::   inum 
189      REAL(wp), POINTER, DIMENSION(:,:) ::   zacs, zaos
190      !!
191      NAMELIST/namsbc_cpl/  sn_snd_temp, sn_snd_alb   , sn_snd_thick, sn_snd_crt   , sn_snd_co2,      &
192         &                  sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau  , sn_rcv_dqnsdt, sn_rcv_qsr,      &
193         &                  sn_rcv_qns , sn_rcv_emp   , sn_rcv_rnf  , sn_rcv_cal   , sn_rcv_iceflx,   &
194         &                  sn_rcv_co2 , nn_cplmodel  , ln_usecplmask
195      !!---------------------------------------------------------------------
196      !
197      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_init')
198      !
199      CALL wrk_alloc( jpi,jpj, zacs, zaos )
200
201      ! ================================ !
202      !      Namelist informations       !
203      ! ================================ !
204
205      REWIND( numnam_ref )              ! Namelist namsbc_cpl in reference namelist : Variables for OASIS coupling
206      READ  ( numnam_ref, namsbc_cpl, IOSTAT = ios, ERR = 901)
207901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist', lwp )
208
209      REWIND( numnam_cfg )              ! Namelist namsbc_cpl in configuration namelist : Variables for OASIS coupling
210      READ  ( numnam_cfg, namsbc_cpl, IOSTAT = ios, ERR = 902 )
211902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist', lwp )
212      IF(lwm) WRITE ( numond, namsbc_cpl )
213
214      IF(lwp) THEN                        ! control print
215         WRITE(numout,*)
216         WRITE(numout,*)'sbc_cpl_init : namsbc_cpl namelist '
217         WRITE(numout,*)'~~~~~~~~~~~~'
218         WRITE(numout,*)'  received fields (mutiple ice categogies)'
219         WRITE(numout,*)'      10m wind module                 = ', TRIM(sn_rcv_w10m%cldes  ), ' (', TRIM(sn_rcv_w10m%clcat  ), ')'
220         WRITE(numout,*)'      stress module                   = ', TRIM(sn_rcv_taumod%cldes), ' (', TRIM(sn_rcv_taumod%clcat), ')'
221         WRITE(numout,*)'      surface stress                  = ', TRIM(sn_rcv_tau%cldes   ), ' (', TRIM(sn_rcv_tau%clcat   ), ')'
222         WRITE(numout,*)'                     - referential    = ', sn_rcv_tau%clvref
223         WRITE(numout,*)'                     - orientation    = ', sn_rcv_tau%clvor
224         WRITE(numout,*)'                     - mesh           = ', sn_rcv_tau%clvgrd
225         WRITE(numout,*)'      non-solar heat flux sensitivity = ', TRIM(sn_rcv_dqnsdt%cldes), ' (', TRIM(sn_rcv_dqnsdt%clcat), ')'
226         WRITE(numout,*)'      solar heat flux                 = ', TRIM(sn_rcv_qsr%cldes   ), ' (', TRIM(sn_rcv_qsr%clcat   ), ')'
227         WRITE(numout,*)'      non-solar heat flux             = ', TRIM(sn_rcv_qns%cldes   ), ' (', TRIM(sn_rcv_qns%clcat   ), ')'
228         WRITE(numout,*)'      freshwater budget               = ', TRIM(sn_rcv_emp%cldes   ), ' (', TRIM(sn_rcv_emp%clcat   ), ')'
229         WRITE(numout,*)'      runoffs                         = ', TRIM(sn_rcv_rnf%cldes   ), ' (', TRIM(sn_rcv_rnf%clcat   ), ')'
230         WRITE(numout,*)'      calving                         = ', TRIM(sn_rcv_cal%cldes   ), ' (', TRIM(sn_rcv_cal%clcat   ), ')'
231         WRITE(numout,*)'      sea ice heat fluxes             = ', TRIM(sn_rcv_iceflx%cldes), ' (', TRIM(sn_rcv_iceflx%clcat), ')'
232         WRITE(numout,*)'      atm co2                         = ', TRIM(sn_rcv_co2%cldes   ), ' (', TRIM(sn_rcv_co2%clcat   ), ')'
233         WRITE(numout,*)'  sent fields (multiple ice categories)'
234         WRITE(numout,*)'      surface temperature             = ', TRIM(sn_snd_temp%cldes  ), ' (', TRIM(sn_snd_temp%clcat  ), ')'
235         WRITE(numout,*)'      albedo                          = ', TRIM(sn_snd_alb%cldes   ), ' (', TRIM(sn_snd_alb%clcat   ), ')'
236         WRITE(numout,*)'      ice/snow thickness              = ', TRIM(sn_snd_thick%cldes ), ' (', TRIM(sn_snd_thick%clcat ), ')'
237         WRITE(numout,*)'      surface current                 = ', TRIM(sn_snd_crt%cldes   ), ' (', TRIM(sn_snd_crt%clcat   ), ')'
238         WRITE(numout,*)'                      - referential   = ', sn_snd_crt%clvref 
239         WRITE(numout,*)'                      - orientation   = ', sn_snd_crt%clvor
240         WRITE(numout,*)'                      - mesh          = ', sn_snd_crt%clvgrd
241         WRITE(numout,*)'      oce co2 flux                    = ', TRIM(sn_snd_co2%cldes   ), ' (', TRIM(sn_snd_co2%clcat   ), ')'
242         WRITE(numout,*)'  nn_cplmodel                         = ', nn_cplmodel
243         WRITE(numout,*)'  ln_usecplmask                       = ', ln_usecplmask
244      ENDIF
245
246      !                                   ! allocate sbccpl arrays
247      IF( sbc_cpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_cpl_alloc : unable to allocate arrays' )
248     
249      ! ================================ !
250      !   Define the receive interface   !
251      ! ================================ !
252      nrcvinfo(:) = OASIS_idle   ! needed by nrcvinfo(jpr_otx1) if we do not receive ocean stress
253
254      ! for each field: define the OASIS name                              (srcv(:)%clname)
255      !                 define receive or not from the namelist parameters (srcv(:)%laction)
256      !                 define the north fold type of lbc                  (srcv(:)%nsgn)
257
258      ! default definitions of srcv
259      srcv(:)%laction = .FALSE.   ;   srcv(:)%clgrid = 'T'   ;   srcv(:)%nsgn = 1.   ;   srcv(:)%nct = 1
260
261      !                                                      ! ------------------------- !
262      !                                                      ! ice and ocean wind stress !   
263      !                                                      ! ------------------------- !
264      !                                                           ! Name
265      srcv(jpr_otx1)%clname = 'O_OTaux1'      ! 1st ocean component on grid ONE (T or U)
266      srcv(jpr_oty1)%clname = 'O_OTauy1'      ! 2nd   -      -         -     -
267      srcv(jpr_otz1)%clname = 'O_OTauz1'      ! 3rd   -      -         -     -
268      srcv(jpr_otx2)%clname = 'O_OTaux2'      ! 1st ocean component on grid TWO (V)
269      srcv(jpr_oty2)%clname = 'O_OTauy2'      ! 2nd   -      -         -     -
270      srcv(jpr_otz2)%clname = 'O_OTauz2'      ! 3rd   -      -         -     -
271      !
272      srcv(jpr_itx1)%clname = 'O_ITaux1'      ! 1st  ice  component on grid ONE (T, F, I or U)
273      srcv(jpr_ity1)%clname = 'O_ITauy1'      ! 2nd   -      -         -     -
274      srcv(jpr_itz1)%clname = 'O_ITauz1'      ! 3rd   -      -         -     -
275      srcv(jpr_itx2)%clname = 'O_ITaux2'      ! 1st  ice  component on grid TWO (V)
276      srcv(jpr_ity2)%clname = 'O_ITauy2'      ! 2nd   -      -         -     -
277      srcv(jpr_itz2)%clname = 'O_ITauz2'      ! 3rd   -      -         -     -
278      !
279      ! Vectors: change of sign at north fold ONLY if on the local grid
280      IF( TRIM( sn_rcv_tau%clvor ) == 'local grid' )   srcv(jpr_otx1:jpr_itz2)%nsgn = -1.
281     
282      !                                                           ! Set grid and action
283      SELECT CASE( TRIM( sn_rcv_tau%clvgrd ) )      !  'T', 'U,V', 'U,V,I', 'U,V,F', 'T,I', 'T,F', or 'T,U,V'
284      CASE( 'T' ) 
285         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
286         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
287         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
288      CASE( 'U,V' ) 
289         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
290         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
291         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'U'        ! ice components given at U-point
292         srcv(jpr_itx2:jpr_itz2)%clgrid  = 'V'        !           and           V-point
293         srcv(jpr_otx1:jpr_itz2)%laction = .TRUE.     ! receive oce and ice components on both grid 1 & 2
294      CASE( 'U,V,T' )
295         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
296         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
297         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'T'        ! ice components given at T-point
298         srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
299         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
300      CASE( 'U,V,I' )
301         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
302         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
303         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'I'        ! ice components given at I-point
304         srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
305         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
306      CASE( 'U,V,F' )
307         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'U'        ! oce components given at U-point
308         srcv(jpr_otx2:jpr_otz2)%clgrid  = 'V'        !           and           V-point
309         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'F'        ! ice components given at F-point
310         srcv(jpr_otx1:jpr_otz2)%laction = .TRUE.     ! receive oce components on grid 1 & 2
311         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1 only
312      CASE( 'T,I' ) 
313         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
314         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'I'        ! ice components given at I-point
315         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
316         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
317      CASE( 'T,F' ) 
318         srcv(jpr_otx1:jpr_itz2)%clgrid  = 'T'        ! oce and ice components given at T-point
319         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'F'        ! ice components given at F-point
320         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1
321         srcv(jpr_itx1:jpr_itz1)%laction = .TRUE.     ! receive ice components on grid 1
322      CASE( 'T,U,V' )
323         srcv(jpr_otx1:jpr_otz1)%clgrid  = 'T'        ! oce components given at T-point
324         srcv(jpr_itx1:jpr_itz1)%clgrid  = 'U'        ! ice components given at U-point
325         srcv(jpr_itx2:jpr_itz2)%clgrid  = 'V'        !           and           V-point
326         srcv(jpr_otx1:jpr_otz1)%laction = .TRUE.     ! receive oce components on grid 1 only
327         srcv(jpr_itx1:jpr_itz2)%laction = .TRUE.     ! receive ice components on grid 1 & 2
328      CASE default   
329         CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_tau%clvgrd' )
330      END SELECT
331      !
332      IF( TRIM( sn_rcv_tau%clvref ) == 'spherical' )   &           ! spherical: 3rd component not received
333         &     srcv( (/jpr_otz1, jpr_otz2, jpr_itz1, jpr_itz2/) )%laction = .FALSE. 
334      !
335      IF( TRIM( sn_rcv_tau%clvor  ) == 'local grid' ) THEN        ! already on local grid -> no need of the second grid
336            srcv(jpr_otx2:jpr_otz2)%laction = .FALSE. 
337            srcv(jpr_itx2:jpr_itz2)%laction = .FALSE. 
338            srcv(jpr_oty1)%clgrid = srcv(jpr_oty2)%clgrid   ! not needed but cleaner...
339            srcv(jpr_ity1)%clgrid = srcv(jpr_ity2)%clgrid   ! not needed but cleaner...
340      ENDIF
341      !
342      IF( TRIM( sn_rcv_tau%cldes ) /= 'oce and ice' ) THEN        ! 'oce and ice' case ocean stress on ocean mesh used
343         srcv(jpr_itx1:jpr_itz2)%laction = .FALSE.    ! ice components not received
344         srcv(jpr_itx1)%clgrid = 'U'                  ! ocean stress used after its transformation
345         srcv(jpr_ity1)%clgrid = 'V'                  ! i.e. it is always at U- & V-points for i- & j-comp. resp.
346      ENDIF
347       
348      !                                                      ! ------------------------- !
349      !                                                      !    freshwater budget      !   E-P
350      !                                                      ! ------------------------- !
351      ! we suppose that atmosphere modele do not make the difference between precipiration (liquide or solid)
352      ! over ice of free ocean within the same atmospheric cell.cd
353      srcv(jpr_rain)%clname = 'OTotRain'      ! Rain = liquid precipitation
354      srcv(jpr_snow)%clname = 'OTotSnow'      ! Snow = solid precipitation
355      srcv(jpr_tevp)%clname = 'OTotEvap'      ! total evaporation (over oce + ice sublimation)
356      srcv(jpr_ievp)%clname = 'OIceEvap'      ! evaporation over ice = sublimation
357      srcv(jpr_sbpr)%clname = 'OSubMPre'      ! sublimation - liquid precipitation - solid precipitation
358      srcv(jpr_semp)%clname = 'OISubMSn'      ! ice solid water budget = sublimation - solid precipitation
359      srcv(jpr_oemp)%clname = 'OOEvaMPr'      ! ocean water budget = ocean Evap - ocean precip
360      SELECT CASE( TRIM( sn_rcv_emp%cldes ) )
361      CASE( 'oce only'      )   ;   srcv(                                 jpr_oemp   )%laction = .TRUE. 
362      CASE( 'conservative'  )
363         srcv( (/jpr_rain, jpr_snow, jpr_ievp, jpr_tevp/) )%laction = .TRUE.
364         IF ( k_ice <= 1 )  srcv(jpr_ievp)%laction = .FALSE.
365      CASE( 'oce and ice'   )   ;   srcv( (/jpr_ievp, jpr_sbpr, jpr_semp, jpr_oemp/) )%laction = .TRUE.
366      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_emp%cldes' )
367      END SELECT
368
369      !                                                      ! ------------------------- !
370      !                                                      !     Runoffs & Calving     !   
371      !                                                      ! ------------------------- !
372      srcv(jpr_rnf   )%clname = 'O_Runoff'   ;   IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' )   srcv(jpr_rnf)%laction = .TRUE.
373! This isn't right - really just want ln_rnf_emp changed
374!                                                 IF( TRIM( sn_rcv_rnf%cldes ) == 'climato' )   THEN   ;   ln_rnf = .TRUE.
375!                                                 ELSE                                                 ;   ln_rnf = .FALSE.
376!                                                 ENDIF
377      srcv(jpr_cal   )%clname = 'OCalving'   ;   IF( TRIM( sn_rcv_cal%cldes ) == 'coupled' )   srcv(jpr_cal)%laction = .TRUE.
378
379      !                                                      ! ------------------------- !
380      !                                                      !    non solar radiation    !   Qns
381      !                                                      ! ------------------------- !
382      srcv(jpr_qnsoce)%clname = 'O_QnsOce'
383      srcv(jpr_qnsice)%clname = 'O_QnsIce'
384      srcv(jpr_qnsmix)%clname = 'O_QnsMix'
385      SELECT CASE( TRIM( sn_rcv_qns%cldes ) )
386      CASE( 'oce only'      )   ;   srcv(               jpr_qnsoce   )%laction = .TRUE.
387      CASE( 'conservative'  )   ;   srcv( (/jpr_qnsice, jpr_qnsmix/) )%laction = .TRUE.
388      CASE( 'oce and ice'   )   ;   srcv( (/jpr_qnsice, jpr_qnsoce/) )%laction = .TRUE.
389      CASE( 'mixed oce-ice' )   ;   srcv(               jpr_qnsmix   )%laction = .TRUE. 
390      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qns%cldes' )
391      END SELECT
392      IF( TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' .AND. jpl > 1 ) &
393         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qns%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
394      !                                                      ! ------------------------- !
395      !                                                      !    solar radiation        !   Qsr
396      !                                                      ! ------------------------- !
397      srcv(jpr_qsroce)%clname = 'O_QsrOce'
398      srcv(jpr_qsrice)%clname = 'O_QsrIce'
399      srcv(jpr_qsrmix)%clname = 'O_QsrMix'
400      SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )
401      CASE( 'oce only'      )   ;   srcv(               jpr_qsroce   )%laction = .TRUE.
402      CASE( 'conservative'  )   ;   srcv( (/jpr_qsrice, jpr_qsrmix/) )%laction = .TRUE.
403      CASE( 'oce and ice'   )   ;   srcv( (/jpr_qsrice, jpr_qsroce/) )%laction = .TRUE.
404      CASE( 'mixed oce-ice' )   ;   srcv(               jpr_qsrmix   )%laction = .TRUE. 
405      CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qsr%cldes' )
406      END SELECT
407      IF( TRIM( sn_rcv_qsr%cldes ) == 'mixed oce-ice' .AND. jpl > 1 ) &
408         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qsr%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
409      !                                                      ! ------------------------- !
410      !                                                      !   non solar sensitivity   !   d(Qns)/d(T)
411      !                                                      ! ------------------------- !
412      srcv(jpr_dqnsdt)%clname = 'O_dQnsdT'   
413      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'coupled' )   srcv(jpr_dqnsdt)%laction = .TRUE.
414      !
415      ! non solar sensitivity mandatory for LIM ice model
416      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. k_ice /= 0 .AND. k_ice /= 4) &
417         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_dqnsdt%cldes must be coupled in namsbc_cpl namelist' )
418      ! non solar sensitivity mandatory for mixed oce-ice solar radiation coupling technique
419      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' ) &
420         CALL ctl_stop( 'sbc_cpl_init: namsbc_cpl namelist mismatch between sn_rcv_qns%cldes and sn_rcv_dqnsdt%cldes' )
421      !                                                      ! ------------------------- !
422      !                                                      !      10m wind module      !   
423      !                                                      ! ------------------------- !
424      srcv(jpr_w10m)%clname = 'O_Wind10'   ;   IF( TRIM(sn_rcv_w10m%cldes  ) == 'coupled' )   srcv(jpr_w10m)%laction = .TRUE. 
425      !
426      !                                                      ! ------------------------- !
427      !                                                      !   wind stress module      !   
428      !                                                      ! ------------------------- !
429      srcv(jpr_taum)%clname = 'O_TauMod'   ;   IF( TRIM(sn_rcv_taumod%cldes) == 'coupled' )   srcv(jpr_taum)%laction = .TRUE.
430      lhftau = srcv(jpr_taum)%laction
431
432      !                                                      ! ------------------------- !
433      !                                                      !      Atmospheric CO2      !
434      !                                                      ! ------------------------- !
435      srcv(jpr_co2 )%clname = 'O_AtmCO2'   ;   IF( TRIM(sn_rcv_co2%cldes   ) == 'coupled' )    srcv(jpr_co2 )%laction = .TRUE.
436      !                                                      ! ------------------------- !
437      !                                                      !   topmelt and botmelt     !   
438      !                                                      ! ------------------------- !
439      srcv(jpr_topm )%clname = 'OTopMlt'
440      srcv(jpr_botm )%clname = 'OBotMlt'
441      IF( TRIM(sn_rcv_iceflx%cldes) == 'coupled' ) THEN
442         IF ( TRIM( sn_rcv_iceflx%clcat ) == 'yes' ) THEN
443            srcv(jpr_topm:jpr_botm)%nct = jpl
444         ELSE
445            CALL ctl_stop( 'sbc_cpl_init: sn_rcv_iceflx%clcat should always be set to yes currently' )
446         ENDIF
447         srcv(jpr_topm:jpr_botm)%laction = .TRUE.
448      ENDIF
449
450      ! Allocate all parts of frcv used for received fields
451      DO jn = 1, jprcv
452         IF ( srcv(jn)%laction ) ALLOCATE( frcv(jn)%z3(jpi,jpj,srcv(jn)%nct) )
453      END DO
454      ! Allocate taum part of frcv which is used even when not received as coupling field
455      IF ( .NOT. srcv(jpr_taum)%laction ) ALLOCATE( frcv(jpr_taum)%z3(jpi,jpj,srcv(jpr_taum)%nct) )
456      ! Allocate itx1 and ity1 as they are used in sbc_cpl_ice_tau even if srcv(jpr_itx1)%laction = .FALSE.
457      IF( k_ice /= 0 ) THEN
458         IF ( .NOT. srcv(jpr_itx1)%laction ) ALLOCATE( frcv(jpr_itx1)%z3(jpi,jpj,srcv(jpr_itx1)%nct) )
459         IF ( .NOT. srcv(jpr_ity1)%laction ) ALLOCATE( frcv(jpr_ity1)%z3(jpi,jpj,srcv(jpr_ity1)%nct) )
460      END IF
461
462      ! ================================ !
463      !     Define the send interface    !
464      ! ================================ !
465      ! for each field: define the OASIS name                           (ssnd(:)%clname)
466      !                 define send or not from the namelist parameters (ssnd(:)%laction)
467      !                 define the north fold type of lbc               (ssnd(:)%nsgn)
468     
469      ! default definitions of nsnd
470      ssnd(:)%laction = .FALSE.   ;   ssnd(:)%clgrid = 'T'   ;   ssnd(:)%nsgn = 1.  ; ssnd(:)%nct = 1
471         
472      !                                                      ! ------------------------- !
473      !                                                      !    Surface temperature    !
474      !                                                      ! ------------------------- !
475      ssnd(jps_toce)%clname = 'O_SSTSST'
476      ssnd(jps_tice)%clname = 'O_TepIce'
477      ssnd(jps_tmix)%clname = 'O_TepMix'
478      SELECT CASE( TRIM( sn_snd_temp%cldes ) )
479      CASE( 'none'         )       ! nothing to do
480      CASE( 'oce only'             )   ;   ssnd(   jps_toce             )%laction = .TRUE.
481      CASE( 'weighted oce and ice' )
482         ssnd( (/jps_toce, jps_tice/) )%laction = .TRUE.
483         IF ( TRIM( sn_snd_temp%clcat ) == 'yes' )  ssnd(jps_tice)%nct = jpl
484      CASE( 'mixed oce-ice'        )   ;   ssnd(   jps_tmix             )%laction = .TRUE.
485      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_temp%cldes' )
486      END SELECT
487     
488      !                                                      ! ------------------------- !
489      !                                                      !          Albedo           !
490      !                                                      ! ------------------------- !
491      ssnd(jps_albice)%clname = 'O_AlbIce' 
492      ssnd(jps_albmix)%clname = 'O_AlbMix'
493      SELECT CASE( TRIM( sn_snd_alb%cldes ) )
494      CASE( 'none'          )       ! nothing to do
495      CASE( 'weighted ice'  )   ;   ssnd(jps_albice)%laction = .TRUE.
496      CASE( 'mixed oce-ice' )   ;   ssnd(jps_albmix)%laction = .TRUE.
497      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_alb%cldes' )
498      END SELECT
499      !
500      ! Need to calculate oceanic albedo if
501      !     1. sending mixed oce-ice albedo or
502      !     2. receiving mixed oce-ice solar radiation
503      IF ( TRIM ( sn_snd_alb%cldes ) == 'mixed oce-ice' .OR. TRIM ( sn_rcv_qsr%cldes ) == 'mixed oce-ice' ) THEN
504         CALL albedo_oce( zaos, zacs )
505         ! Due to lack of information on nebulosity : mean clear/overcast sky
506         albedo_oce_mix(:,:) = ( zacs(:,:) + zaos(:,:) ) * 0.5
507      ENDIF
508
509      !                                                      ! ------------------------- !
510      !                                                      !  Ice fraction & Thickness !
511      !                                                      ! ------------------------- !
512      ssnd(jps_fice)%clname = 'OIceFrc'
513      ssnd(jps_hice)%clname = 'OIceTck'
514      ssnd(jps_hsnw)%clname = 'OSnwTck'
515      IF( k_ice /= 0 ) THEN
516         ssnd(jps_fice)%laction = .TRUE.                  ! if ice treated in the ocean (even in climato case)
517! Currently no namelist entry to determine sending of multi-category ice fraction so use the thickness entry for now
518         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_fice)%nct = jpl
519      ENDIF
520
521      SELECT CASE ( TRIM( sn_snd_thick%cldes ) )
522      CASE( 'none'         )       ! nothing to do
523      CASE( 'ice and snow' ) 
524         ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
525         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) THEN
526            ssnd(jps_hice:jps_hsnw)%nct = jpl
527         ELSE
528            IF ( jpl > 1 ) THEN
529CALL ctl_stop( 'sbc_cpl_init: use weighted ice and snow option for sn_snd_thick%cldes if not exchanging category fields' )
530            ENDIF
531         ENDIF
532      CASE ( 'weighted ice and snow' ) 
533         ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
534         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_hice:jps_hsnw)%nct = jpl
535      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_thick%cldes' )
536      END SELECT
537
538      !                                                      ! ------------------------- !
539      !                                                      !      Surface current      !
540      !                                                      ! ------------------------- !
541      !        ocean currents              !            ice velocities
542      ssnd(jps_ocx1)%clname = 'O_OCurx1'   ;   ssnd(jps_ivx1)%clname = 'O_IVelx1'
543      ssnd(jps_ocy1)%clname = 'O_OCury1'   ;   ssnd(jps_ivy1)%clname = 'O_IVely1'
544      ssnd(jps_ocz1)%clname = 'O_OCurz1'   ;   ssnd(jps_ivz1)%clname = 'O_IVelz1'
545      !
546      ssnd(jps_ocx1:jps_ivz1)%nsgn = -1.   ! vectors: change of the sign at the north fold
547
548      IF( sn_snd_crt%clvgrd == 'U,V' ) THEN
549         ssnd(jps_ocx1)%clgrid = 'U' ; ssnd(jps_ocy1)%clgrid = 'V'
550      ELSE IF( sn_snd_crt%clvgrd /= 'T' ) THEN 
551         CALL ctl_stop( 'sn_snd_crt%clvgrd must be equal to T' )
552         ssnd(jps_ocx1:jps_ivz1)%clgrid  = 'T'      ! all oce and ice components on the same unique grid
553      ENDIF
554      ssnd(jps_ocx1:jps_ivz1)%laction = .TRUE.   ! default: all are send
555      IF( TRIM( sn_snd_crt%clvref ) == 'spherical' )   ssnd( (/jps_ocz1, jps_ivz1/) )%laction = .FALSE. 
556      IF( TRIM( sn_snd_crt%clvor ) == 'eastward-northward' ) ssnd(jps_ocx1:jps_ivz1)%nsgn = 1.
557      SELECT CASE( TRIM( sn_snd_crt%cldes ) )
558      CASE( 'none'                 )   ;   ssnd(jps_ocx1:jps_ivz1)%laction = .FALSE.
559      CASE( 'oce only'             )   ;   ssnd(jps_ivx1:jps_ivz1)%laction = .FALSE.
560      CASE( 'weighted oce and ice' )   !   nothing to do
561      CASE( 'mixed oce-ice'        )   ;   ssnd(jps_ivx1:jps_ivz1)%laction = .FALSE.
562      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_crt%cldes' )
563      END SELECT
564
565      !                                                      ! ------------------------- !
566      !                                                      !          CO2 flux         !
567      !                                                      ! ------------------------- !
568      ssnd(jps_co2)%clname = 'O_CO2FLX' ;  IF( TRIM(sn_snd_co2%cldes) == 'coupled' )    ssnd(jps_co2 )%laction = .TRUE.
569      !
570      ! ================================ !
571      !   initialisation of the coupler  !
572      ! ================================ !
573
574      CALL cpl_define(jprcv, jpsnd,nn_cplmodel)           
575      IF (ln_usecplmask) THEN
576         xcplmask(:,:,:) = 0.
577         CALL iom_open( 'cplmask', inum )
578         CALL iom_get( inum, jpdom_unknown, 'cplmask', xcplmask(1:nlci,1:nlcj,1:nn_cplmodel),   &
579            &          kstart = (/ mig(1),mjg(1),1 /), kcount = (/ nlci,nlcj,nn_cplmodel /) )
580         CALL iom_close( inum )
581      ELSE
582         xcplmask(:,:,:) = 1.
583      ENDIF
584      !
585      ncpl_qsr_freq = INT( 86400  &
586         &         / ( cpl_freq( 'O_QsrOce' ) + cpl_freq( 'O_QsrMix' ) + cpl_freq( 'S_QsrOce' ) + cpl_freq( 'S_QsrMix' ) ) )
587      !
588      IF( ln_dm2dc .AND. ncpl_qsr_freq /= 1 )   &
589         &   CALL ctl_stop( 'sbc_cpl_init: diurnal cycle reconstruction (ln_dm2dc) needs daily couping for solar radiation' )
590
591      !
592      !
593      CALL wrk_dealloc( jpi,jpj, zacs, zaos )
594      !
595      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_init')
596      !
597   END SUBROUTINE sbc_cpl_init
598
599
600   SUBROUTINE sbc_cpl_rcv( kt, k_fsbc, k_ice )     
601      !!----------------------------------------------------------------------
602      !!             ***  ROUTINE sbc_cpl_rcv  ***
603      !!
604      !! ** Purpose :   provide the stress over the ocean and, if no sea-ice,
605      !!                provide the ocean heat and freshwater fluxes.
606      !!
607      !! ** Method  : - Receive all the atmospheric fields (stored in frcv array). called at each time step.
608      !!                OASIS controls if there is something do receive or not. nrcvinfo contains the info
609      !!                to know if the field was really received or not
610      !!
611      !!              --> If ocean stress was really received:
612      !!
613      !!                  - transform the received ocean stress vector from the received
614      !!                 referential and grid into an atmosphere-ocean stress in
615      !!                 the (i,j) ocean referencial and at the ocean velocity point.
616      !!                    The received stress are :
617      !!                     - defined by 3 components (if cartesian coordinate)
618      !!                            or by 2 components (if spherical)
619      !!                     - oriented along geographical   coordinate (if eastward-northward)
620      !!                            or  along the local grid coordinate (if local grid)
621      !!                     - given at U- and V-point, resp.   if received on 2 grids
622      !!                            or at T-point               if received on 1 grid
623      !!                    Therefore and if necessary, they are successively
624      !!                  processed in order to obtain them
625      !!                     first  as  2 components on the sphere
626      !!                     second as  2 components oriented along the local grid
627      !!                     third  as  2 components on the U,V grid
628      !!
629      !!              -->
630      !!
631      !!              - In 'ocean only' case, non solar and solar ocean heat fluxes
632      !!             and total ocean freshwater fluxes 
633      !!
634      !! ** Method  :   receive all fields from the atmosphere and transform
635      !!              them into ocean surface boundary condition fields
636      !!
637      !! ** Action  :   update  utau, vtau   ocean stress at U,V grid
638      !!                        taum         wind stress module at T-point
639      !!                        wndm         wind speed  module at T-point over free ocean or leads in presence of sea-ice
640      !!                        qns          non solar heat fluxes including emp heat content    (ocean only case)
641      !!                                     and the latent heat flux of solid precip. melting
642      !!                        qsr          solar ocean heat fluxes   (ocean only case)
643      !!                        emp          upward mass flux [evap. - precip. (- runoffs) (- calving)] (ocean only case)
644      !!----------------------------------------------------------------------
645      INTEGER, INTENT(in) ::   kt       ! ocean model time step index
646      INTEGER, INTENT(in) ::   k_fsbc   ! frequency of sbc (-> ice model) computation
647      INTEGER, INTENT(in) ::   k_ice    ! ice management in the sbc (=0/1/2/3)
648      !!
649      LOGICAL ::    llnewtx, llnewtau      ! update wind stress components and module??
650      INTEGER  ::   ji, jj, jn             ! dummy loop indices
651      INTEGER  ::   isec                   ! number of seconds since nit000 (assuming rdttra did not change since nit000)
652      REAL(wp) ::   zcumulneg, zcumulpos   ! temporary scalars     
653      REAL(wp) ::   zcoef                  ! temporary scalar
654      REAL(wp) ::   zrhoa  = 1.22          ! Air density kg/m3
655      REAL(wp) ::   zcdrag = 1.5e-3        ! drag coefficient
656      REAL(wp) ::   zzx, zzy               ! temporary variables
657      REAL(wp), POINTER, DIMENSION(:,:) ::   ztx, zty 
658      !!----------------------------------------------------------------------
659      !
660      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_rcv')
661      !
662      CALL wrk_alloc( jpi,jpj, ztx, zty )
663      !                                                 ! Receive all the atmos. fields (including ice information)
664      isec = ( kt - nit000 ) * NINT( rdttra(1) )             ! date of exchanges
665      DO jn = 1, jprcv                                       ! received fields sent by the atmosphere
666         IF( srcv(jn)%laction )   CALL cpl_rcv( jn, isec, frcv(jn)%z3, xcplmask, nrcvinfo(jn) )
667      END DO
668
669      !                                                      ! ========================= !
670      IF( srcv(jpr_otx1)%laction ) THEN                      !  ocean stress components  !
671         !                                                   ! ========================= !
672         ! define frcv(jpr_otx1)%z3(:,:,1) and frcv(jpr_oty1)%z3(:,:,1): stress at U/V point along model grid
673         ! => need to be done only when we receive the field
674         IF(  nrcvinfo(jpr_otx1) == OASIS_Rcv ) THEN
675            !
676            IF( TRIM( sn_rcv_tau%clvref ) == 'cartesian' ) THEN            ! 2 components on the sphere
677               !                                                       ! (cartesian to spherical -> 3 to 2 components)
678               !
679               CALL geo2oce( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), frcv(jpr_otz1)%z3(:,:,1),   &
680                  &          srcv(jpr_otx1)%clgrid, ztx, zty )
681               frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 1st grid
682               frcv(jpr_oty1)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 1st grid
683               !
684               IF( srcv(jpr_otx2)%laction ) THEN
685                  CALL geo2oce( frcv(jpr_otx2)%z3(:,:,1), frcv(jpr_oty2)%z3(:,:,1), frcv(jpr_otz2)%z3(:,:,1),   &
686                     &          srcv(jpr_otx2)%clgrid, ztx, zty )
687                  frcv(jpr_otx2)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 2nd grid
688                  frcv(jpr_oty2)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 2nd grid
689               ENDIF
690               !
691            ENDIF
692            !
693            IF( TRIM( sn_rcv_tau%clvor ) == 'eastward-northward' ) THEN   ! 2 components oriented along the local grid
694               !                                                       ! (geographical to local grid -> rotate the components)
695               CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->i', ztx )   
696               IF( srcv(jpr_otx2)%laction ) THEN
697                  CALL rot_rep( frcv(jpr_otx2)%z3(:,:,1), frcv(jpr_oty2)%z3(:,:,1), srcv(jpr_otx2)%clgrid, 'en->j', zty )   
698               ELSE 
699                  CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->j', zty ) 
700               ENDIF
701               frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
702               frcv(jpr_oty1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 2nd grid
703            ENDIF
704            !                             
705            IF( srcv(jpr_otx1)%clgrid == 'T' ) THEN
706               DO jj = 2, jpjm1                                          ! T ==> (U,V)
707                  DO ji = fs_2, fs_jpim1   ! vector opt.
708                     frcv(jpr_otx1)%z3(ji,jj,1) = 0.5 * ( frcv(jpr_otx1)%z3(ji+1,jj  ,1) + frcv(jpr_otx1)%z3(ji,jj,1) )
709                     frcv(jpr_oty1)%z3(ji,jj,1) = 0.5 * ( frcv(jpr_oty1)%z3(ji  ,jj+1,1) + frcv(jpr_oty1)%z3(ji,jj,1) )
710                  END DO
711               END DO
712               CALL lbc_lnk( frcv(jpr_otx1)%z3(:,:,1), 'U',  -1. )   ;   CALL lbc_lnk( frcv(jpr_oty1)%z3(:,:,1), 'V',  -1. )
713            ENDIF
714            llnewtx = .TRUE.
715         ELSE
716            llnewtx = .FALSE.
717         ENDIF
718         !                                                   ! ========================= !
719      ELSE                                                   !   No dynamical coupling   !
720         !                                                   ! ========================= !
721         frcv(jpr_otx1)%z3(:,:,1) = 0.e0                               ! here simply set to zero
722         frcv(jpr_oty1)%z3(:,:,1) = 0.e0                               ! an external read in a file can be added instead
723         llnewtx = .TRUE.
724         !
725      ENDIF
726     
727      !                                                      ! ========================= !
728      !                                                      !    wind stress module     !   (taum)
729      !                                                      ! ========================= !
730      !
731      IF( .NOT. srcv(jpr_taum)%laction ) THEN                    ! compute wind stress module from its components if not received
732         ! => need to be done only when otx1 was changed
733         IF( llnewtx ) THEN
734!CDIR NOVERRCHK
735            DO jj = 2, jpjm1
736!CDIR NOVERRCHK
737               DO ji = fs_2, fs_jpim1   ! vect. opt.
738                  zzx = frcv(jpr_otx1)%z3(ji-1,jj  ,1) + frcv(jpr_otx1)%z3(ji,jj,1)
739                  zzy = frcv(jpr_oty1)%z3(ji  ,jj-1,1) + frcv(jpr_oty1)%z3(ji,jj,1)
740                  frcv(jpr_taum)%z3(ji,jj,1) = 0.5 * SQRT( zzx * zzx + zzy * zzy )
741               END DO
742            END DO
743            CALL lbc_lnk( frcv(jpr_taum)%z3(:,:,1), 'T', 1. )
744            llnewtau = .TRUE.
745         ELSE
746            llnewtau = .FALSE.
747         ENDIF
748      ELSE
749         llnewtau = nrcvinfo(jpr_taum) == OASIS_Rcv
750         ! Stress module can be negative when received (interpolation problem)
751         IF( llnewtau ) THEN
752            frcv(jpr_taum)%z3(:,:,1) = MAX( 0._wp, frcv(jpr_taum)%z3(:,:,1) )
753         ENDIF
754      ENDIF
755     
756      !                                                      ! ========================= !
757      !                                                      !      10 m wind speed      !   (wndm)
758      !                                                      ! ========================= !
759      !
760      IF( .NOT. srcv(jpr_w10m)%laction ) THEN                    ! compute wind spreed from wind stress module if not received 
761         ! => need to be done only when taumod was changed
762         IF( llnewtau ) THEN
763            zcoef = 1. / ( zrhoa * zcdrag ) 
764!CDIR NOVERRCHK
765            DO jj = 1, jpj
766!CDIR NOVERRCHK
767               DO ji = 1, jpi 
768                  wndm(ji,jj) = SQRT( frcv(jpr_taum)%z3(ji,jj,1) * zcoef )
769               END DO
770            END DO
771         ENDIF
772      ELSE
773         IF ( nrcvinfo(jpr_w10m) == OASIS_Rcv ) wndm(:,:) = frcv(jpr_w10m)%z3(:,:,1)
774      ENDIF
775
776      ! u(v)tau and taum will be modified by ice model
777      ! -> need to be reset before each call of the ice/fsbc     
778      IF( MOD( kt-1, k_fsbc ) == 0 ) THEN
779         !
780         utau(:,:) = frcv(jpr_otx1)%z3(:,:,1)
781         vtau(:,:) = frcv(jpr_oty1)%z3(:,:,1)
782         taum(:,:) = frcv(jpr_taum)%z3(:,:,1)
783         CALL iom_put( "taum_oce", taum )   ! output wind stress module
784         
785      ENDIF
786
787#if defined key_cpl_carbon_cycle
788      !                                                              ! atmosph. CO2 (ppm)
789      IF( srcv(jpr_co2)%laction )   atm_co2(:,:) = frcv(jpr_co2)%z3(:,:,1)
790#endif
791
792      !                                                      ! ========================= !
793      IF( k_ice <= 1 ) THEN                                  !  heat & freshwater fluxes ! (Ocean only case)
794         !                                                   ! ========================= !
795         !
796         !                                                       ! total freshwater fluxes over the ocean (emp)
797         SELECT CASE( TRIM( sn_rcv_emp%cldes ) )                                    ! evaporation - precipitation
798         CASE( 'conservative' )
799            emp(:,:) = frcv(jpr_tevp)%z3(:,:,1) - ( frcv(jpr_rain)%z3(:,:,1) + frcv(jpr_snow)%z3(:,:,1) )
800         CASE( 'oce only', 'oce and ice' )
801            emp(:,:) = frcv(jpr_oemp)%z3(:,:,1)
802         CASE default
803            CALL ctl_stop( 'sbc_cpl_rcv: wrong definition of sn_rcv_emp%cldes' )
804         END SELECT
805         !
806         !                                                        ! runoffs and calving (added in emp)
807         IF( srcv(jpr_rnf)%laction )   emp(:,:) = emp(:,:) - frcv(jpr_rnf)%z3(:,:,1)
808         IF( srcv(jpr_cal)%laction )   emp(:,:) = emp(:,:) - frcv(jpr_cal)%z3(:,:,1)
809         !
810!!gm :  this seems to be internal cooking, not sure to need that in a generic interface
811!!gm                                       at least should be optional...
812!!         IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' ) THEN     ! add to the total freshwater budget
813!!            ! remove negative runoff
814!!            zcumulpos = SUM( MAX( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
815!!            zcumulneg = SUM( MIN( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
816!!            IF( lk_mpp )   CALL mpp_sum( zcumulpos )   ! sum over the global domain
817!!            IF( lk_mpp )   CALL mpp_sum( zcumulneg )
818!!            IF( zcumulpos /= 0. ) THEN                 ! distribute negative runoff on positive runoff grid points
819!!               zcumulneg = 1.e0 + zcumulneg / zcumulpos
820!!               frcv(jpr_rnf)%z3(:,:,1) = MAX( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * zcumulneg
821!!            ENDIF     
822!!            ! add runoff to e-p
823!!            emp(:,:) = emp(:,:) - frcv(jpr_rnf)%z3(:,:,1)
824!!         ENDIF
825!!gm  end of internal cooking
826         !
827         !                                                       ! non solar heat flux over the ocean (qns)
828         IF( srcv(jpr_qnsoce)%laction )   qns(:,:) = frcv(jpr_qnsoce)%z3(:,:,1)
829         IF( srcv(jpr_qnsmix)%laction )   qns(:,:) = frcv(jpr_qnsmix)%z3(:,:,1)
830         ! update qns over the free ocean with:
831         qns(:,:) =  qns(:,:) - emp(:,:) * sst_m(:,:) * rcp            ! remove heat content due to mass flux (assumed to be at SST)
832         IF( srcv(jpr_snow  )%laction )   THEN
833              qns(:,:) = qns(:,:) - frcv(jpr_snow)%z3(:,:,1) * lfus    ! energy for melting solid precipitation over the free ocean
834         ENDIF
835
836         !                                                       ! solar flux over the ocean          (qsr)
837         IF( srcv(jpr_qsroce)%laction )   qsr(:,:) = frcv(jpr_qsroce)%z3(:,:,1)
838         IF( srcv(jpr_qsrmix)%laction )   qsr(:,:) = frcv(jpr_qsrmix)%z3(:,:,1)
839         IF( ln_dm2dc )   qsr(:,:) = sbc_dcy( qsr )                           ! modify qsr to include the diurnal cycle
840         !
841 
842      ENDIF
843      !
844      CALL wrk_dealloc( jpi,jpj, ztx, zty )
845      !
846      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_rcv')
847      !
848   END SUBROUTINE sbc_cpl_rcv
849   
850
851   SUBROUTINE sbc_cpl_ice_tau( p_taui, p_tauj )     
852      !!----------------------------------------------------------------------
853      !!             ***  ROUTINE sbc_cpl_ice_tau  ***
854      !!
855      !! ** Purpose :   provide the stress over sea-ice in coupled mode
856      !!
857      !! ** Method  :   transform the received stress from the atmosphere into
858      !!             an atmosphere-ice stress in the (i,j) ocean referencial
859      !!             and at the velocity point of the sea-ice model (cp_ice_msh):
860      !!                'C'-grid : i- (j-) components given at U- (V-) point
861      !!                'I'-grid : B-grid lower-left corner: both components given at I-point
862      !!
863      !!                The received stress are :
864      !!                 - defined by 3 components (if cartesian coordinate)
865      !!                        or by 2 components (if spherical)
866      !!                 - oriented along geographical   coordinate (if eastward-northward)
867      !!                        or  along the local grid coordinate (if local grid)
868      !!                 - given at U- and V-point, resp.   if received on 2 grids
869      !!                        or at a same point (T or I) if received on 1 grid
870      !!                Therefore and if necessary, they are successively
871      !!             processed in order to obtain them
872      !!                 first  as  2 components on the sphere
873      !!                 second as  2 components oriented along the local grid
874      !!                 third  as  2 components on the cp_ice_msh point
875      !!
876      !!                Except in 'oce and ice' case, only one vector stress field
877      !!             is received. It has already been processed in sbc_cpl_rcv
878      !!             so that it is now defined as (i,j) components given at U-
879      !!             and V-points, respectively. Therefore, only the third
880      !!             transformation is done and only if the ice-grid is a 'I'-grid.
881      !!
882      !! ** Action  :   return ptau_i, ptau_j, the stress over the ice at cp_ice_msh point
883      !!----------------------------------------------------------------------
884      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_taui   ! i- & j-components of atmos-ice stress [N/m2]
885      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_tauj   ! at I-point (B-grid) or U & V-point (C-grid)
886      !!
887      INTEGER ::   ji, jj                          ! dummy loop indices
888      INTEGER ::   itx                             ! index of taux over ice
889      REAL(wp), POINTER, DIMENSION(:,:) ::   ztx, zty 
890      !!----------------------------------------------------------------------
891      !
892      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_tau')
893      !
894      CALL wrk_alloc( jpi,jpj, ztx, zty )
895
896      IF( srcv(jpr_itx1)%laction ) THEN   ;   itx =  jpr_itx1   
897      ELSE                                ;   itx =  jpr_otx1
898      ENDIF
899
900      ! do something only if we just received the stress from atmosphere
901      IF(  nrcvinfo(itx) == OASIS_Rcv ) THEN
902
903         !                                                      ! ======================= !
904         IF( srcv(jpr_itx1)%laction ) THEN                      !   ice stress received   !
905            !                                                   ! ======================= !
906           
907            IF( TRIM( sn_rcv_tau%clvref ) == 'cartesian' ) THEN            ! 2 components on the sphere
908               !                                                       ! (cartesian to spherical -> 3 to 2 components)
909               CALL geo2oce(  frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), frcv(jpr_itz1)%z3(:,:,1),   &
910                  &          srcv(jpr_itx1)%clgrid, ztx, zty )
911               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 1st grid
912               frcv(jpr_ity1)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 1st grid
913               !
914               IF( srcv(jpr_itx2)%laction ) THEN
915                  CALL geo2oce( frcv(jpr_itx2)%z3(:,:,1), frcv(jpr_ity2)%z3(:,:,1), frcv(jpr_itz2)%z3(:,:,1),   &
916                     &          srcv(jpr_itx2)%clgrid, ztx, zty )
917                  frcv(jpr_itx2)%z3(:,:,1) = ztx(:,:)   ! overwrite 1st comp. on the 2nd grid
918                  frcv(jpr_ity2)%z3(:,:,1) = zty(:,:)   ! overwrite 2nd comp. on the 2nd grid
919               ENDIF
920               !
921            ENDIF
922            !
923            IF( TRIM( sn_rcv_tau%clvor ) == 'eastward-northward' ) THEN   ! 2 components oriented along the local grid
924               !                                                       ! (geographical to local grid -> rotate the components)
925               CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->i', ztx )   
926               IF( srcv(jpr_itx2)%laction ) THEN
927                  CALL rot_rep( frcv(jpr_itx2)%z3(:,:,1), frcv(jpr_ity2)%z3(:,:,1), srcv(jpr_itx2)%clgrid, 'en->j', zty )   
928               ELSE
929                  CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->j', zty ) 
930               ENDIF
931               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
932               frcv(jpr_ity1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 1st grid
933            ENDIF
934            !                                                   ! ======================= !
935         ELSE                                                   !     use ocean stress    !
936            !                                                   ! ======================= !
937            frcv(jpr_itx1)%z3(:,:,1) = frcv(jpr_otx1)%z3(:,:,1)
938            frcv(jpr_ity1)%z3(:,:,1) = frcv(jpr_oty1)%z3(:,:,1)
939            !
940         ENDIF
941
942         !                                                      ! ======================= !
943         !                                                      !     put on ice grid     !
944         !                                                      ! ======================= !
945         !   
946         !                                                  j+1   j     -----V---F
947         ! ice stress on ice velocity point (cp_ice_msh)                 !       |
948         ! (C-grid ==>(U,V) or B-grid ==> I or F)                 j      |   T   U
949         !                                                               |       |
950         !                                                   j    j-1   -I-------|
951         !                                               (for I)         |       |
952         !                                                              i-1  i   i
953         !                                                               i      i+1 (for I)
954         SELECT CASE ( cp_ice_msh )
955            !
956         CASE( 'I' )                                         ! B-grid ==> I
957            SELECT CASE ( srcv(jpr_itx1)%clgrid )
958            CASE( 'U' )
959               DO jj = 2, jpjm1                                   ! (U,V) ==> I
960                  DO ji = 2, jpim1   ! NO vector opt.
961                     p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji-1,jj  ,1) + frcv(jpr_itx1)%z3(ji-1,jj-1,1) )
962                     p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji  ,jj-1,1) + frcv(jpr_ity1)%z3(ji-1,jj-1,1) )
963                  END DO
964               END DO
965            CASE( 'F' )
966               DO jj = 2, jpjm1                                   ! F ==> I
967                  DO ji = 2, jpim1   ! NO vector opt.
968                     p_taui(ji,jj) = frcv(jpr_itx1)%z3(ji-1,jj-1,1)
969                     p_tauj(ji,jj) = frcv(jpr_ity1)%z3(ji-1,jj-1,1)
970                  END DO
971               END DO
972            CASE( 'T' )
973               DO jj = 2, jpjm1                                   ! T ==> I
974                  DO ji = 2, jpim1   ! NO vector opt.
975                     p_taui(ji,jj) = 0.25 * ( frcv(jpr_itx1)%z3(ji,jj  ,1) + frcv(jpr_itx1)%z3(ji-1,jj  ,1)   &
976                        &                   + frcv(jpr_itx1)%z3(ji,jj-1,1) + frcv(jpr_itx1)%z3(ji-1,jj-1,1) ) 
977                     p_tauj(ji,jj) = 0.25 * ( frcv(jpr_ity1)%z3(ji,jj  ,1) + frcv(jpr_ity1)%z3(ji-1,jj  ,1)   &
978                        &                   + frcv(jpr_oty1)%z3(ji,jj-1,1) + frcv(jpr_ity1)%z3(ji-1,jj-1,1) )
979                  END DO
980               END DO
981            CASE( 'I' )
982               p_taui(:,:) = frcv(jpr_itx1)%z3(:,:,1)                   ! I ==> I
983               p_tauj(:,:) = frcv(jpr_ity1)%z3(:,:,1)
984            END SELECT
985            IF( srcv(jpr_itx1)%clgrid /= 'I' ) THEN
986               CALL lbc_lnk( p_taui, 'I',  -1. )   ;   CALL lbc_lnk( p_tauj, 'I',  -1. )
987            ENDIF
988            !
989         CASE( 'F' )                                         ! B-grid ==> F
990            SELECT CASE ( srcv(jpr_itx1)%clgrid )
991            CASE( 'U' )
992               DO jj = 2, jpjm1                                   ! (U,V) ==> F
993                  DO ji = fs_2, fs_jpim1   ! vector opt.
994                     p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji,jj,1) + frcv(jpr_itx1)%z3(ji  ,jj+1,1) )
995                     p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji,jj,1) + frcv(jpr_ity1)%z3(ji+1,jj  ,1) )
996                  END DO
997               END DO
998            CASE( 'I' )
999               DO jj = 2, jpjm1                                   ! I ==> F
1000                  DO ji = 2, jpim1   ! NO vector opt.
1001                     p_taui(ji,jj) = frcv(jpr_itx1)%z3(ji+1,jj+1,1)
1002                     p_tauj(ji,jj) = frcv(jpr_ity1)%z3(ji+1,jj+1,1)
1003                  END DO
1004               END DO
1005            CASE( 'T' )
1006               DO jj = 2, jpjm1                                   ! T ==> F
1007                  DO ji = 2, jpim1   ! NO vector opt.
1008                     p_taui(ji,jj) = 0.25 * ( frcv(jpr_itx1)%z3(ji,jj  ,1) + frcv(jpr_itx1)%z3(ji+1,jj  ,1)   &
1009                        &                   + frcv(jpr_itx1)%z3(ji,jj+1,1) + frcv(jpr_itx1)%z3(ji+1,jj+1,1) ) 
1010                     p_tauj(ji,jj) = 0.25 * ( frcv(jpr_ity1)%z3(ji,jj  ,1) + frcv(jpr_ity1)%z3(ji+1,jj  ,1)   &
1011                        &                   + frcv(jpr_ity1)%z3(ji,jj+1,1) + frcv(jpr_ity1)%z3(ji+1,jj+1,1) )
1012                  END DO
1013               END DO
1014            CASE( 'F' )
1015               p_taui(:,:) = frcv(jpr_itx1)%z3(:,:,1)                   ! F ==> F
1016               p_tauj(:,:) = frcv(jpr_ity1)%z3(:,:,1)
1017            END SELECT
1018            IF( srcv(jpr_itx1)%clgrid /= 'F' ) THEN
1019               CALL lbc_lnk( p_taui, 'F',  -1. )   ;   CALL lbc_lnk( p_tauj, 'F',  -1. )
1020            ENDIF
1021            !
1022         CASE( 'C' )                                         ! C-grid ==> U,V
1023            SELECT CASE ( srcv(jpr_itx1)%clgrid )
1024            CASE( 'U' )
1025               p_taui(:,:) = frcv(jpr_itx1)%z3(:,:,1)                   ! (U,V) ==> (U,V)
1026               p_tauj(:,:) = frcv(jpr_ity1)%z3(:,:,1)
1027            CASE( 'F' )
1028               DO jj = 2, jpjm1                                   ! F ==> (U,V)
1029                  DO ji = fs_2, fs_jpim1   ! vector opt.
1030                     p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji,jj,1) + frcv(jpr_itx1)%z3(ji  ,jj-1,1) )
1031                     p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(jj,jj,1) + frcv(jpr_ity1)%z3(ji-1,jj  ,1) )
1032                  END DO
1033               END DO
1034            CASE( 'T' )
1035               DO jj = 2, jpjm1                                   ! T ==> (U,V)
1036                  DO ji = fs_2, fs_jpim1   ! vector opt.
1037                     p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji+1,jj  ,1) + frcv(jpr_itx1)%z3(ji,jj,1) )
1038                     p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji  ,jj+1,1) + frcv(jpr_ity1)%z3(ji,jj,1) )
1039                  END DO
1040               END DO
1041            CASE( 'I' )
1042               DO jj = 2, jpjm1                                   ! I ==> (U,V)
1043                  DO ji = 2, jpim1   ! NO vector opt.
1044                     p_taui(ji,jj) = 0.5 * ( frcv(jpr_itx1)%z3(ji+1,jj+1,1) + frcv(jpr_itx1)%z3(ji+1,jj  ,1) )
1045                     p_tauj(ji,jj) = 0.5 * ( frcv(jpr_ity1)%z3(ji+1,jj+1,1) + frcv(jpr_ity1)%z3(ji  ,jj+1,1) )
1046                  END DO
1047               END DO
1048            END SELECT
1049            IF( srcv(jpr_itx1)%clgrid /= 'U' ) THEN
1050               CALL lbc_lnk( p_taui, 'U',  -1. )   ;   CALL lbc_lnk( p_tauj, 'V',  -1. )
1051            ENDIF
1052         END SELECT
1053
1054      ENDIF
1055      !   
1056      CALL wrk_dealloc( jpi,jpj, ztx, zty )
1057      !
1058      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_ice_tau')
1059      !
1060   END SUBROUTINE sbc_cpl_ice_tau
1061   
1062
1063   SUBROUTINE sbc_cpl_ice_flx( p_frld  , kt, palbi   , psst    , pist    )
1064      !!----------------------------------------------------------------------
1065      !!             ***  ROUTINE sbc_cpl_ice_flx  ***
1066      !!
1067      !! ** Purpose :   provide the heat and freshwater fluxes of the
1068      !!              ocean-ice system.
1069      !!
1070      !! ** Method  :   transform the fields received from the atmosphere into
1071      !!             surface heat and fresh water boundary condition for the
1072      !!             ice-ocean system. The following fields are provided:
1073      !!              * total non solar, solar and freshwater fluxes (qns_tot,
1074      !!             qsr_tot and emp_tot) (total means weighted ice-ocean flux)
1075      !!             NB: emp_tot include runoffs and calving.
1076      !!              * fluxes over ice (qns_ice, qsr_ice, emp_ice) where
1077      !!             emp_ice = sublimation - solid precipitation as liquid
1078      !!             precipitation are re-routed directly to the ocean and
1079      !!             runoffs and calving directly enter the ocean.
1080      !!              * solid precipitation (sprecip), used to add to qns_tot
1081      !!             the heat lost associated to melting solid precipitation
1082      !!             over the ocean fraction.
1083      !!       ===>> CAUTION here this changes the net heat flux received from
1084      !!             the atmosphere
1085      !!
1086      !!                  - the fluxes have been separated from the stress as
1087      !!                 (a) they are updated at each ice time step compare to
1088      !!                 an update at each coupled time step for the stress, and
1089      !!                 (b) the conservative computation of the fluxes over the
1090      !!                 sea-ice area requires the knowledge of the ice fraction
1091      !!                 after the ice advection and before the ice thermodynamics,
1092      !!                 so that the stress is updated before the ice dynamics
1093      !!                 while the fluxes are updated after it.
1094      !!
1095      !! ** Action  :   update at each nf_ice time step:
1096      !!                   qns_tot, qsr_tot  non-solar and solar total heat fluxes
1097      !!                   qns_ice, qsr_ice  non-solar and solar heat fluxes over the ice
1098      !!                   emp_tot            total evaporation - precipitation(liquid and solid) (-runoff)(-calving)
1099      !!                   emp_ice            ice sublimation - solid precipitation over the ice
1100      !!                   dqns_ice           d(non-solar heat flux)/d(Temperature) over the ice
1101      !!                   sprecip             solid precipitation over the ocean 
1102      !!----------------------------------------------------------------------
1103      INTEGER,  INTENT(in   ), OPTIONAL         ::   kt     !  time-step
1104      REAL(wp), INTENT(in   ), DIMENSION(:,:)   ::   p_frld     ! lead fraction                [0 to 1]
1105      ! optional arguments, used only in 'mixed oce-ice' case
1106      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi   ! all skies ice albedo
1107      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst    ! sea surface temperature     [Celsius]
1108      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist    ! ice surface temperature     [Kelvin]
1109      !
1110      INTEGER ::   it, jl   ! dummy loop index
1111      REAL(wp), POINTER, DIMENSION(:,:) ::   zcptn, ztmp, zicefr
1112      !!----------------------------------------------------------------------
1113      !
1114      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_flx')
1115      !
1116      CALL wrk_alloc( jpi,jpj, zcptn, ztmp, zicefr )
1117
1118      IF( PRESENT( kt ) ) it = kt
1119
1120      zicefr(:,:) = 1.- p_frld(:,:)
1121      zcptn(:,:) = rcp * sst_m(:,:)
1122      !
1123      !                                                      ! ========================= !
1124      !                                                      !    freshwater budget      !   (emp)
1125      !                                                      ! ========================= !
1126      !
1127      !                                                           ! total Precipitations - total Evaporation (emp_tot)
1128      !                                                           ! solid precipitation  - sublimation       (emp_ice)
1129      !                                                           ! solid Precipitation                      (sprecip)
1130      SELECT CASE( TRIM( sn_rcv_emp%cldes ) )
1131      CASE( 'conservative'  )   ! received fields: jpr_rain, jpr_snow, jpr_ievp, jpr_tevp
1132         sprecip(:,:) = frcv(jpr_snow)%z3(:,:,1)                 ! May need to ensure positive here
1133         tprecip(:,:) = frcv(jpr_rain)%z3(:,:,1) + sprecip (:,:) ! May need to ensure positive here
1134         emp_tot(:,:) = frcv(jpr_tevp)%z3(:,:,1) - tprecip(:,:)
1135         emp_ice(:,:) = frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_snow)%z3(:,:,1)
1136            CALL iom_put( 'rain'         , frcv(jpr_rain)%z3(:,:,1)              )   ! liquid precipitation
1137         IF( iom_use('hflx_rain_cea') )   &
1138            CALL iom_put( 'hflx_rain_cea', frcv(jpr_rain)%z3(:,:,1) * zcptn(:,:) )   ! heat flux from liq. precip.
1139         IF( iom_use('evap_ao_cea') .OR. iom_use('hflx_evap_cea') )   &
1140            ztmp(:,:) = frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:)
1141         IF( iom_use('evap_ao_cea'  ) )   &
1142            CALL iom_put( 'evap_ao_cea'  , ztmp                   )   ! ice-free oce evap (cell average)
1143         IF( iom_use('hflx_evap_cea') )   &
1144            CALL iom_put( 'hflx_evap_cea', ztmp(:,:) * zcptn(:,:) )   ! heat flux from from evap (cell average)
1145      CASE( 'oce and ice'   )   ! received fields: jpr_sbpr, jpr_semp, jpr_oemp, jpr_ievp
1146         emp_tot(:,:) = p_frld(:,:) * frcv(jpr_oemp)%z3(:,:,1) + zicefr(:,:) * frcv(jpr_sbpr)%z3(:,:,1)
1147         emp_ice(:,:) = frcv(jpr_semp)%z3(:,:,1)
1148         sprecip(:,:) = - frcv(jpr_semp)%z3(:,:,1) + frcv(jpr_ievp)%z3(:,:,1)
1149      END SELECT
1150
1151         CALL iom_put( 'snowpre'    , sprecip                                )   ! Snow
1152      IF( iom_use('snow_ao_cea') )   &
1153         CALL iom_put( 'snow_ao_cea', sprecip(:,:) * p_frld(:,:)             )   ! Snow        over ice-free ocean  (cell average)
1154      IF( iom_use('snow_ai_cea') )   &
1155         CALL iom_put( 'snow_ai_cea', sprecip(:,:) * zicefr(:,:)             )   ! Snow        over sea-ice         (cell average)
1156      IF( iom_use('subl_ai_cea') )   &
1157         CALL iom_put( 'subl_ai_cea', frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) )   ! Sublimation over sea-ice         (cell average)
1158      !   
1159      !                                                           ! runoffs and calving (put in emp_tot)
1160      IF( srcv(jpr_rnf)%laction ) THEN
1161         emp_tot(:,:) = emp_tot(:,:) - frcv(jpr_rnf)%z3(:,:,1)
1162            CALL iom_put( 'runoffs'      , frcv(jpr_rnf)%z3(:,:,1)              )   ! rivers
1163         IF( iom_use('hflx_rnf_cea') )   &
1164            CALL iom_put( 'hflx_rnf_cea' , frcv(jpr_rnf)%z3(:,:,1) * zcptn(:,:) )   ! heat flux from rivers
1165      ENDIF
1166      IF( srcv(jpr_cal)%laction ) THEN
1167         emp_tot(:,:) = emp_tot(:,:) - frcv(jpr_cal)%z3(:,:,1)
1168         CALL iom_put( 'calving', frcv(jpr_cal)%z3(:,:,1) )
1169      ENDIF
1170      !
1171!!gm :  this seems to be internal cooking, not sure to need that in a generic interface
1172!!gm                                       at least should be optional...
1173!!       ! remove negative runoff                            ! sum over the global domain
1174!!       zcumulpos = SUM( MAX( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
1175!!       zcumulneg = SUM( MIN( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
1176!!       IF( lk_mpp )   CALL mpp_sum( zcumulpos )
1177!!       IF( lk_mpp )   CALL mpp_sum( zcumulneg )
1178!!       IF( zcumulpos /= 0. ) THEN                          ! distribute negative runoff on positive runoff grid points
1179!!          zcumulneg = 1.e0 + zcumulneg / zcumulpos
1180!!          frcv(jpr_rnf)%z3(:,:,1) = MAX( frcv(jpr_rnf)%z3(:,:,1), 0.e0 ) * zcumulneg
1181!!       ENDIF     
1182!!       emp_tot(:,:) = emp_tot(:,:) - frcv(jpr_rnf)%z3(:,:,1)   ! add runoff to e-p
1183!!
1184!!gm  end of internal cooking
1185
1186      !                                                      ! ========================= !
1187      SELECT CASE( TRIM( sn_rcv_qns%cldes ) )                !   non solar heat fluxes   !   (qns)
1188      !                                                      ! ========================= !
1189      CASE( 'oce only' )                                     ! the required field is directly provided
1190         qns_tot(:,:  ) = frcv(jpr_qnsoce)%z3(:,:,1)
1191      CASE( 'conservative' )                                      ! the required fields are directly provided
1192         qns_tot(:,:  ) = frcv(jpr_qnsmix)%z3(:,:,1)
1193         IF ( TRIM(sn_rcv_qns%clcat) == 'yes' ) THEN
1194            qns_ice(:,:,1:jpl) = frcv(jpr_qnsice)%z3(:,:,1:jpl)
1195         ELSE
1196            ! Set all category values equal for the moment
1197            DO jl=1,jpl
1198               qns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1)
1199            ENDDO
1200         ENDIF
1201      CASE( 'oce and ice' )       ! the total flux is computed from ocean and ice fluxes
1202         qns_tot(:,:  ) =  p_frld(:,:) * frcv(jpr_qnsoce)%z3(:,:,1)
1203         IF ( TRIM(sn_rcv_qns%clcat) == 'yes' ) THEN
1204            DO jl=1,jpl
1205               qns_tot(:,:   ) = qns_tot(:,:) + a_i(:,:,jl) * frcv(jpr_qnsice)%z3(:,:,jl)   
1206               qns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,jl)
1207            ENDDO
1208         ELSE
1209            qns_tot(:,:   ) = qns_tot(:,:) + zicefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
1210            DO jl=1,jpl
1211               qns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1)
1212            ENDDO
1213         ENDIF
1214      CASE( 'mixed oce-ice' )     ! the ice flux is cumputed from the total flux, the SST and ice informations
1215! ** NEED TO SORT OUT HOW THIS SHOULD WORK IN THE MULTI-CATEGORY CASE - CURRENTLY NOT ALLOWED WHEN INTERFACE INITIALISED **
1216         qns_tot(:,:  ) = frcv(jpr_qnsmix)%z3(:,:,1)
1217         qns_ice(:,:,1) = frcv(jpr_qnsmix)%z3(:,:,1)    &
1218            &            + frcv(jpr_dqnsdt)%z3(:,:,1) * ( pist(:,:,1) - ( (rt0 + psst(:,:  ) ) * p_frld(:,:)   &
1219            &                                                   +          pist(:,:,1)   * zicefr(:,:) ) )
1220      END SELECT
1221      ztmp(:,:) = p_frld(:,:) * sprecip(:,:) * lfus
1222      qns_tot(:,:) = qns_tot(:,:)                         &            ! qns_tot update over free ocean with:
1223         &          - ztmp(:,:)                           &            ! remove the latent heat flux of solid precip. melting
1224         &          - (  emp_tot(:,:)                     &            ! remove the heat content of mass flux (assumed to be at SST)
1225         &             - emp_ice(:,:) * zicefr(:,:)  ) * zcptn(:,:) 
1226      IF( iom_use('hflx_snow_cea') )   &
1227         CALL iom_put( 'hflx_snow_cea', ztmp + sprecip(:,:) * zcptn(:,:) )   ! heat flux from snow (cell average)
1228!!gm
1229!!    currently it is taken into account in leads budget but not in the qns_tot, and thus not in
1230!!    the flux that enter the ocean....
1231!!    moreover 1 - it is not diagnose anywhere....
1232!!             2 - it is unclear for me whether this heat lost is taken into account in the atmosphere or not...
1233!!
1234!! similar job should be done for snow and precipitation temperature
1235      !                                     
1236      IF( srcv(jpr_cal)%laction ) THEN                            ! Iceberg melting
1237         ztmp(:,:) = frcv(jpr_cal)%z3(:,:,1) * lfus               ! add the latent heat of iceberg melting
1238         qns_tot(:,:) = qns_tot(:,:) - ztmp(:,:)
1239         IF( iom_use('hflx_cal_cea') )   &
1240            CALL iom_put( 'hflx_cal_cea', ztmp + frcv(jpr_cal)%z3(:,:,1) * zcptn(:,:) )   ! heat flux from calving
1241      ENDIF
1242
1243      !                                                      ! ========================= !
1244      SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )                !      solar heat fluxes    !   (qsr)
1245      !                                                      ! ========================= !
1246      CASE( 'oce only' )
1247         qsr_tot(:,:  ) = MAX( 0._wp , frcv(jpr_qsroce)%z3(:,:,1) )
1248      CASE( 'conservative' )
1249         qsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
1250         IF ( TRIM(sn_rcv_qsr%clcat) == 'yes' ) THEN
1251            qsr_ice(:,:,1:jpl) = frcv(jpr_qsrice)%z3(:,:,1:jpl)
1252         ELSE
1253            ! Set all category values equal for the moment
1254            DO jl=1,jpl
1255               qsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
1256            ENDDO
1257         ENDIF
1258         qsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
1259         qsr_ice(:,:,1) = frcv(jpr_qsrice)%z3(:,:,1)
1260      CASE( 'oce and ice' )
1261         qsr_tot(:,:  ) =  p_frld(:,:) * frcv(jpr_qsroce)%z3(:,:,1)
1262         IF ( TRIM(sn_rcv_qsr%clcat) == 'yes' ) THEN
1263            DO jl=1,jpl
1264               qsr_tot(:,:   ) = qsr_tot(:,:) + a_i(:,:,jl) * frcv(jpr_qsrice)%z3(:,:,jl)   
1265               qsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,jl)
1266            ENDDO
1267         ELSE
1268            qsr_tot(:,:   ) = qsr_tot(:,:) + zicefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
1269            DO jl=1,jpl
1270               qsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
1271            ENDDO
1272         ENDIF
1273      CASE( 'mixed oce-ice' )
1274         qsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
1275! ** NEED TO SORT OUT HOW THIS SHOULD WORK IN THE MULTI-CATEGORY CASE - CURRENTLY NOT ALLOWED WHEN INTERFACE INITIALISED **
1276!       Create solar heat flux over ice using incoming solar heat flux and albedos
1277!       ( see OASIS3 user guide, 5th edition, p39 )
1278         qsr_ice(:,:,1) = frcv(jpr_qsrmix)%z3(:,:,1) * ( 1.- palbi(:,:,1) )   &
1279            &            / (  1.- ( albedo_oce_mix(:,:  ) * p_frld(:,:)       &
1280            &                     + palbi         (:,:,1) * zicefr(:,:) ) )
1281      END SELECT
1282      !
1283      IF( ln_dm2dc ) THEN   ! modify qsr to include the diurnal cycle
1284         qsr_tot(:,:  ) = sbc_dcy( qsr_tot(:,:  ) )
1285         DO jl=1,jpl
1286            qsr_ice(:,:,jl) = sbc_dcy( qsr_ice(:,:,jl) )
1287         ENDDO
1288      ENDIF
1289      !
1290      SELECT CASE( TRIM( sn_rcv_dqnsdt%cldes ) )             !          d(qns)/dt        !
1291      !                                                      ! ========================= !
1292      CASE ('coupled')
1293         IF ( TRIM(sn_rcv_dqnsdt%clcat) == 'yes' ) THEN
1294            dqns_ice(:,:,1:jpl) = frcv(jpr_dqnsdt)%z3(:,:,1:jpl)
1295         ELSE
1296            ! Set all category values equal for the moment
1297            DO jl=1,jpl
1298               dqns_ice(:,:,jl) = frcv(jpr_dqnsdt)%z3(:,:,1)
1299            ENDDO
1300         ENDIF
1301      END SELECT
1302
1303      !                                                      ! ========================= !
1304      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )             !    topmelt and botmelt    !
1305      !                                                      ! ========================= !
1306      CASE ('coupled')
1307         topmelt(:,:,:)=frcv(jpr_topm)%z3(:,:,:)
1308         botmelt(:,:,:)=frcv(jpr_botm)%z3(:,:,:)
1309      END SELECT
1310
1311      ! Surface transimission parameter io (Maykut Untersteiner , 1971 ; Ebert and Curry, 1993 )
1312      ! Used for LIM2 and LIM3
1313      ! Coupled case: since cloud cover is not received from atmosphere
1314      !               ===> used prescribed cloud fraction representative for polar oceans in summer (0.81)
1315      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
1316      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
1317
1318      CALL wrk_dealloc( jpi,jpj, zcptn, ztmp, zicefr )
1319      !
1320      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_ice_flx')
1321      !
1322   END SUBROUTINE sbc_cpl_ice_flx
1323
1324
1325   SUBROUTINE sbc_cpl_snd( kt )
1326      !!----------------------------------------------------------------------
1327      !!             ***  ROUTINE sbc_cpl_snd  ***
1328      !!
1329      !! ** Purpose :   provide the ocean-ice informations to the atmosphere
1330      !!
1331      !! ** Method  :   send to the atmosphere through a call to cpl_snd
1332      !!              all the needed fields (as defined in sbc_cpl_init)
1333      !!----------------------------------------------------------------------
1334      INTEGER, INTENT(in) ::   kt
1335      !
1336      INTEGER ::   ji, jj, jl   ! dummy loop indices
1337      INTEGER ::   isec, info   ! local integer
1338      REAL(wp), POINTER, DIMENSION(:,:)   ::   zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1
1339      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmp3, ztmp4   
1340      !!----------------------------------------------------------------------
1341      !
1342      IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_snd')
1343      !
1344      CALL wrk_alloc( jpi,jpj, zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
1345      CALL wrk_alloc( jpi,jpj,jpl, ztmp3, ztmp4 )
1346
1347      isec = ( kt - nit000 ) * NINT(rdttra(1))        ! date of exchanges
1348
1349      zfr_l(:,:) = 1.- fr_i(:,:)
1350      !                                                      ! ------------------------- !
1351      !                                                      !    Surface temperature    !   in Kelvin
1352      !                                                      ! ------------------------- !
1353      IF( ssnd(jps_toce)%laction .OR. ssnd(jps_tice)%laction .OR. ssnd(jps_tmix)%laction ) THEN
1354         SELECT CASE( sn_snd_temp%cldes)
1355         CASE( 'oce only'             )   ;   ztmp1(:,:) =   tsn(:,:,1,jp_tem) + rt0
1356         CASE( 'weighted oce and ice' )   ;   ztmp1(:,:) = ( tsn(:,:,1,jp_tem) + rt0 ) * zfr_l(:,:)   
1357            SELECT CASE( sn_snd_temp%clcat )
1358            CASE( 'yes' )   
1359               ztmp3(:,:,1:jpl) = tn_ice(:,:,1:jpl) * a_i(:,:,1:jpl)
1360            CASE( 'no' )
1361               ztmp3(:,:,:) = 0.0
1362               DO jl=1,jpl
1363                  ztmp3(:,:,1) = ztmp3(:,:,1) + tn_ice(:,:,jl) * a_i(:,:,jl)
1364               ENDDO
1365            CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' )
1366            END SELECT
1367         CASE( 'mixed oce-ice'        )   
1368            ztmp1(:,:) = ( tsn(:,:,1,jp_tem) + rt0 ) * zfr_l(:,:) 
1369            DO jl=1,jpl
1370               ztmp1(:,:) = ztmp1(:,:) + tn_ice(:,:,jl) * a_i(:,:,jl)
1371            ENDDO
1372         CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%cldes' )
1373         END SELECT
1374         IF( ssnd(jps_toce)%laction )   CALL cpl_snd( jps_toce, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
1375         IF( ssnd(jps_tice)%laction )   CALL cpl_snd( jps_tice, isec, ztmp3, info )
1376         IF( ssnd(jps_tmix)%laction )   CALL cpl_snd( jps_tmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
1377      ENDIF
1378      !                                                      ! ------------------------- !
1379      !                                                      !           Albedo          !
1380      !                                                      ! ------------------------- !
1381      IF( ssnd(jps_albice)%laction ) THEN                         ! ice
1382         ztmp3(:,:,1:jpl) = alb_ice(:,:,1:jpl) * a_i(:,:,1:jpl)
1383         CALL cpl_snd( jps_albice, isec, ztmp3, info )
1384      ENDIF
1385      IF( ssnd(jps_albmix)%laction ) THEN                         ! mixed ice-ocean
1386         ztmp1(:,:) = albedo_oce_mix(:,:) * zfr_l(:,:)
1387         DO jl=1,jpl
1388            ztmp1(:,:) = ztmp1(:,:) + alb_ice(:,:,jl) * a_i(:,:,jl)
1389         ENDDO
1390         CALL cpl_snd( jps_albmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
1391      ENDIF
1392      !                                                      ! ------------------------- !
1393      !                                                      !  Ice fraction & Thickness !
1394      !                                                      ! ------------------------- !
1395      ! Send ice fraction field
1396      IF( ssnd(jps_fice)%laction ) THEN
1397         SELECT CASE( sn_snd_thick%clcat )
1398         CASE( 'yes' )   ;   ztmp3(:,:,1:jpl) =  a_i(:,:,1:jpl)
1399         CASE( 'no'  )   ;   ztmp3(:,:,1    ) = fr_i(:,:      )
1400         CASE default    ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
1401         END SELECT
1402         CALL cpl_snd( jps_fice, isec, ztmp3, info )
1403      ENDIF
1404
1405      ! Send ice and snow thickness field
1406      IF( ssnd(jps_hice)%laction .OR. ssnd(jps_hsnw)%laction ) THEN
1407         SELECT CASE( sn_snd_thick%cldes)
1408         CASE( 'none'                  )       ! nothing to do
1409         CASE( 'weighted ice and snow' )   
1410            SELECT CASE( sn_snd_thick%clcat )
1411            CASE( 'yes' )   
1412               ztmp3(:,:,1:jpl) =  ht_i(:,:,1:jpl) * a_i(:,:,1:jpl)
1413               ztmp4(:,:,1:jpl) =  ht_s(:,:,1:jpl) * a_i(:,:,1:jpl)
1414            CASE( 'no' )
1415               ztmp3(:,:,:) = 0.0   ;  ztmp4(:,:,:) = 0.0
1416               DO jl=1,jpl
1417                  ztmp3(:,:,1) = ztmp3(:,:,1) + ht_i(:,:,jl) * a_i(:,:,jl)
1418                  ztmp4(:,:,1) = ztmp4(:,:,1) + ht_s(:,:,jl) * a_i(:,:,jl)
1419               ENDDO
1420            CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
1421            END SELECT
1422         CASE( 'ice and snow'         )   
1423            ztmp3(:,:,1:jpl) = ht_i(:,:,1:jpl)
1424            ztmp4(:,:,1:jpl) = ht_s(:,:,1:jpl)
1425         CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%cldes' )
1426         END SELECT
1427         IF( ssnd(jps_hice)%laction )   CALL cpl_snd( jps_hice, isec, ztmp3, info )
1428         IF( ssnd(jps_hsnw)%laction )   CALL cpl_snd( jps_hsnw, isec, ztmp4, info )
1429      ENDIF
1430      !
1431#if defined key_cpl_carbon_cycle
1432      !                                                      ! ------------------------- !
1433      !                                                      !  CO2 flux from PISCES     !
1434      !                                                      ! ------------------------- !
1435      IF( ssnd(jps_co2)%laction )   CALL cpl_snd( jps_co2, isec, RESHAPE ( oce_co2, (/jpi,jpj,1/) ) , info )
1436      !
1437#endif
1438      !                                                      ! ------------------------- !
1439      IF( ssnd(jps_ocx1)%laction ) THEN                      !      Surface current      !
1440         !                                                   ! ------------------------- !
1441         !   
1442         !                                                  j+1   j     -----V---F
1443         ! surface velocity always sent from T point                     !       |
1444         !                                                        j      |   T   U
1445         !                                                               |       |
1446         !                                                   j    j-1   -I-------|
1447         !                                               (for I)         |       |
1448         !                                                              i-1  i   i
1449         !                                                               i      i+1 (for I)
1450         SELECT CASE( TRIM( sn_snd_crt%cldes ) )
1451         CASE( 'oce only'             )      ! C-grid ==> T
1452            DO jj = 2, jpjm1
1453               DO ji = fs_2, fs_jpim1   ! vector opt.
1454                  zotx1(ji,jj) = 0.5 * ( un(ji,jj,1) + un(ji-1,jj  ,1) )
1455                  zoty1(ji,jj) = 0.5 * ( vn(ji,jj,1) + vn(ji  ,jj-1,1) ) 
1456               END DO
1457            END DO
1458         CASE( 'weighted oce and ice' )   
1459            SELECT CASE ( cp_ice_msh )
1460            CASE( 'C' )                      ! Ocean and Ice on C-grid ==> T
1461               DO jj = 2, jpjm1
1462                  DO ji = fs_2, fs_jpim1   ! vector opt.
1463                     zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj) 
1464                     zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj)
1465                     zitx1(ji,jj) = 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj)
1466                     zity1(ji,jj) = 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj)
1467                  END DO
1468               END DO
1469            CASE( 'I' )                      ! Ocean on C grid, Ice on I-point (B-grid) ==> T
1470               DO jj = 2, jpjm1
1471                  DO ji = 2, jpim1   ! NO vector opt.
1472                     zotx1(ji,jj) = 0.5  * ( un(ji,jj,1)      + un(ji-1,jj  ,1) ) * zfr_l(ji,jj) 
1473                     zoty1(ji,jj) = 0.5  * ( vn(ji,jj,1)      + vn(ji  ,jj-1,1) ) * zfr_l(ji,jj) 
1474                     zitx1(ji,jj) = 0.25 * ( u_ice(ji+1,jj+1) + u_ice(ji,jj+1)                     &
1475                        &                  + u_ice(ji+1,jj  ) + u_ice(ji,jj  )  ) *  fr_i(ji,jj)
1476                     zity1(ji,jj) = 0.25 * ( v_ice(ji+1,jj+1) + v_ice(ji,jj+1)                     &
1477                        &                  + v_ice(ji+1,jj  ) + v_ice(ji,jj  )  ) *  fr_i(ji,jj)
1478                  END DO
1479               END DO
1480            CASE( 'F' )                      ! Ocean on C grid, Ice on F-point (B-grid) ==> T
1481               DO jj = 2, jpjm1
1482                  DO ji = 2, jpim1   ! NO vector opt.
1483                     zotx1(ji,jj) = 0.5  * ( un(ji,jj,1)      + un(ji-1,jj  ,1) ) * zfr_l(ji,jj) 
1484                     zoty1(ji,jj) = 0.5  * ( vn(ji,jj,1)      + vn(ji  ,jj-1,1) ) * zfr_l(ji,jj) 
1485                     zitx1(ji,jj) = 0.25 * ( u_ice(ji-1,jj-1) + u_ice(ji,jj-1)                     &
1486                        &                  + u_ice(ji-1,jj  ) + u_ice(ji,jj  )  ) *  fr_i(ji,jj)
1487                     zity1(ji,jj) = 0.25 * ( v_ice(ji-1,jj-1) + v_ice(ji,jj-1)                     &
1488                        &                  + v_ice(ji-1,jj  ) + v_ice(ji,jj  )  ) *  fr_i(ji,jj)
1489                  END DO
1490               END DO
1491            END SELECT
1492            CALL lbc_lnk( zitx1, 'T', -1. )   ;   CALL lbc_lnk( zity1, 'T', -1. )
1493         CASE( 'mixed oce-ice'        )
1494            SELECT CASE ( cp_ice_msh )
1495            CASE( 'C' )                      ! Ocean and Ice on C-grid ==> T
1496               DO jj = 2, jpjm1
1497                  DO ji = fs_2, fs_jpim1   ! vector opt.
1498                     zotx1(ji,jj) = 0.5 * ( un   (ji,jj,1) + un   (ji-1,jj  ,1) ) * zfr_l(ji,jj)   &
1499                        &         + 0.5 * ( u_ice(ji,jj  ) + u_ice(ji-1,jj    ) ) *  fr_i(ji,jj)
1500                     zoty1(ji,jj) = 0.5 * ( vn   (ji,jj,1) + vn   (ji  ,jj-1,1) ) * zfr_l(ji,jj)   &
1501                        &         + 0.5 * ( v_ice(ji,jj  ) + v_ice(ji  ,jj-1  ) ) *  fr_i(ji,jj)
1502                  END DO
1503               END DO
1504            CASE( 'I' )                      ! Ocean on C grid, Ice on I-point (B-grid) ==> T
1505               DO jj = 2, jpjm1
1506                  DO ji = 2, jpim1   ! NO vector opt.
1507                     zotx1(ji,jj) = 0.5  * ( un(ji,jj,1)      + un(ji-1,jj  ,1) ) * zfr_l(ji,jj)   &   
1508                        &         + 0.25 * ( u_ice(ji+1,jj+1) + u_ice(ji,jj+1)                     &
1509                        &                  + u_ice(ji+1,jj  ) + u_ice(ji,jj  )  ) *  fr_i(ji,jj)
1510                     zoty1(ji,jj) = 0.5  * ( vn(ji,jj,1)      + vn(ji  ,jj-1,1) ) * zfr_l(ji,jj)   & 
1511                        &         + 0.25 * ( v_ice(ji+1,jj+1) + v_ice(ji,jj+1)                     &
1512                        &                  + v_ice(ji+1,jj  ) + v_ice(ji,jj  )  ) *  fr_i(ji,jj)
1513                  END DO
1514               END DO
1515            CASE( 'F' )                      ! Ocean on C grid, Ice on F-point (B-grid) ==> T
1516               DO jj = 2, jpjm1
1517                  DO ji = 2, jpim1   ! NO vector opt.
1518                     zotx1(ji,jj) = 0.5  * ( un(ji,jj,1)      + un(ji-1,jj  ,1) ) * zfr_l(ji,jj)   &   
1519                        &         + 0.25 * ( u_ice(ji-1,jj-1) + u_ice(ji,jj-1)                     &
1520                        &                  + u_ice(ji-1,jj  ) + u_ice(ji,jj  )  ) *  fr_i(ji,jj)
1521                     zoty1(ji,jj) = 0.5  * ( vn(ji,jj,1)      + vn(ji  ,jj-1,1) ) * zfr_l(ji,jj)   & 
1522                        &         + 0.25 * ( v_ice(ji-1,jj-1) + v_ice(ji,jj-1)                     &
1523                        &                  + v_ice(ji-1,jj  ) + v_ice(ji,jj  )  ) *  fr_i(ji,jj)
1524                  END DO
1525               END DO
1526            END SELECT
1527         END SELECT
1528         CALL lbc_lnk( zotx1, ssnd(jps_ocx1)%clgrid, -1. )   ;   CALL lbc_lnk( zoty1, ssnd(jps_ocy1)%clgrid, -1. )
1529         !
1530         !
1531         IF( TRIM( sn_snd_crt%clvor ) == 'eastward-northward' ) THEN             ! Rotation of the components
1532            !                                                                     ! Ocean component
1533            CALL rot_rep( zotx1, zoty1, ssnd(jps_ocx1)%clgrid, 'ij->e', ztmp1 )       ! 1st component
1534            CALL rot_rep( zotx1, zoty1, ssnd(jps_ocx1)%clgrid, 'ij->n', ztmp2 )       ! 2nd component
1535            zotx1(:,:) = ztmp1(:,:)                                                   ! overwrite the components
1536            zoty1(:,:) = ztmp2(:,:)
1537            IF( ssnd(jps_ivx1)%laction ) THEN                                     ! Ice component
1538               CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->e', ztmp1 )    ! 1st component
1539               CALL rot_rep( zitx1, zity1, ssnd(jps_ivx1)%clgrid, 'ij->n', ztmp2 )    ! 2nd component
1540               zitx1(:,:) = ztmp1(:,:)                                                ! overwrite the components
1541               zity1(:,:) = ztmp2(:,:)
1542            ENDIF
1543         ENDIF
1544         !
1545         ! spherical coordinates to cartesian -> 2 components to 3 components
1546         IF( TRIM( sn_snd_crt%clvref ) == 'cartesian' ) THEN
1547            ztmp1(:,:) = zotx1(:,:)                     ! ocean currents
1548            ztmp2(:,:) = zoty1(:,:)
1549            CALL oce2geo ( ztmp1, ztmp2, 'T', zotx1, zoty1, zotz1 )
1550            !
1551            IF( ssnd(jps_ivx1)%laction ) THEN           ! ice velocities
1552               ztmp1(:,:) = zitx1(:,:)
1553               ztmp1(:,:) = zity1(:,:)
1554               CALL oce2geo ( ztmp1, ztmp2, 'T', zitx1, zity1, zitz1 )
1555            ENDIF
1556         ENDIF
1557         !
1558         IF( ssnd(jps_ocx1)%laction )   CALL cpl_snd( jps_ocx1, isec, RESHAPE ( zotx1, (/jpi,jpj,1/) ), info )   ! ocean x current 1st grid
1559         IF( ssnd(jps_ocy1)%laction )   CALL cpl_snd( jps_ocy1, isec, RESHAPE ( zoty1, (/jpi,jpj,1/) ), info )   ! ocean y current 1st grid
1560         IF( ssnd(jps_ocz1)%laction )   CALL cpl_snd( jps_ocz1, isec, RESHAPE ( zotz1, (/jpi,jpj,1/) ), info )   ! ocean z current 1st grid
1561         !
1562         IF( ssnd(jps_ivx1)%laction )   CALL cpl_snd( jps_ivx1, isec, RESHAPE ( zitx1, (/jpi,jpj,1/) ), info )   ! ice   x current 1st grid
1563         IF( ssnd(jps_ivy1)%laction )   CALL cpl_snd( jps_ivy1, isec, RESHAPE ( zity1, (/jpi,jpj,1/) ), info )   ! ice   y current 1st grid
1564         IF( ssnd(jps_ivz1)%laction )   CALL cpl_snd( jps_ivz1, isec, RESHAPE ( zitz1, (/jpi,jpj,1/) ), info )   ! ice   z current 1st grid
1565         !
1566      ENDIF
1567      !
1568      CALL wrk_dealloc( jpi,jpj, zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
1569      CALL wrk_dealloc( jpi,jpj,jpl, ztmp3, ztmp4 )
1570      !
1571      IF( nn_timing == 1 )  CALL timing_stop('sbc_cpl_snd')
1572      !
1573   END SUBROUTINE sbc_cpl_snd
1574   
1575   !!======================================================================
1576END MODULE sbccpl
Note: See TracBrowser for help on using the repository browser.