source: LMDZ6/trunk/libf/phylmd/cpl_mod.F90 @ 3479

Last change on this file since 3479 was 3473, checked in by Laurent Fairhead, 5 years ago

Missing initialisation and misplaced IF/ELSE/ENDIF block in cpl_mod
AC, LF

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.8 KB
Line 
1!
2MODULE cpl_mod
3!
4! This module excahanges and transforms all fields that should be recieved or sent to
5! coupler. The transformation of the fields are done from the grid 1D-array in phylmd
6! to the regular 2D grid accepted by the coupler. Cumulation of the fields for each
7! timestep is done in here.
8!
9! Each type of surface that recevie fields from the coupler have a subroutine named
10! cpl_receive_XXX_fields and each surface that have fields to be sent to the coupler
11! have a subroutine named cpl_send_XXX_fields.
12!
13!*************************************************************************************
14
15! Use statements
16!*************************************************************************************
17  USE dimphy, ONLY : klon
18  USE mod_phys_lmdz_para
19  USE ioipsl
20  USE iophy
21
22! The module oasis is always used. Without the cpp key CPP_COUPLE only the parameters
23! in the module are compiled and not the subroutines.
24  USE oasis
25  USE write_field_phy
26  USE time_phylmdz_mod, ONLY: day_step_phy
27 
28! Global attributes
29!*************************************************************************************
30  IMPLICIT NONE
31  PRIVATE
32
33  ! All subroutine are public except cpl_send_all
34  PUBLIC :: cpl_init, cpl_receive_frac, cpl_receive_ocean_fields, cpl_receive_seaice_fields, &
35       cpl_send_ocean_fields, cpl_send_seaice_fields, cpl_send_land_fields, &
36       cpl_send_landice_fields, gath2cpl
37 
38
39! Declaration of module variables
40!*************************************************************************************
41! variable for coupling period
42  INTEGER, SAVE :: nexca
43  !$OMP THREADPRIVATE(nexca)
44
45! variables for cumulating fields during a coupling periode :
46  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_sols, cpl_nsol, cpl_rain
47  !$OMP THREADPRIVATE(cpl_sols,cpl_nsol,cpl_rain)
48  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_snow, cpl_evap, cpl_tsol
49  !$OMP THREADPRIVATE(cpl_snow,cpl_evap,cpl_tsol)
50  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_fder, cpl_albe, cpl_taux, cpl_tauy
51  !$OMP THREADPRIVATE(cpl_fder,cpl_albe,cpl_taux,cpl_tauy)
52  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp
53  !$OMP THREADPRIVATE(cpl_windsp)
54  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_sens_rain, cpl_sens_snow
55  !$OMP THREADPRIVATE(cpl_sens_rain, cpl_sens_snow)
56  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_taumod
57  !$OMP THREADPRIVATE(cpl_taumod)
58  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_atm_co2
59  !$OMP THREADPRIVATE(cpl_atm_co2)
60  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_rriv2D, cpl_rcoa2D, cpl_rlic2D
61  !$OMP THREADPRIVATE(cpl_rriv2D,cpl_rcoa2D,cpl_rlic2D)
62
63! variables read from coupler :
64  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_sst     ! sea surface temperature
65  !$OMP THREADPRIVATE(read_sst)
66  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_sit     ! sea ice temperature
67  !$OMP THREADPRIVATE(read_sit)
68  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_sic     ! sea ice fraction
69  !$OMP THREADPRIVATE(read_sic)
70  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_alb_sic ! albedo at sea ice
71  !$OMP THREADPRIVATE(read_alb_sic)
72  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_u0, read_v0 ! ocean surface current
73  !$OMP THREADPRIVATE(read_u0,read_v0)
74  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_co2     ! ocean co2 flux
75  !$OMP THREADPRIVATE(read_co2)
76  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE  :: unity
77  !$OMP THREADPRIVATE(unity)
78  INTEGER, SAVE                             :: nidct, nidcs
79  !$OMP THREADPRIVATE(nidct,nidcs)
80
81! variables to be sent to the coupler
82  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_sols2D, cpl_nsol2D, cpl_rain2D
83  !$OMP THREADPRIVATE(cpl_sols2D, cpl_nsol2D, cpl_rain2D)
84  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_snow2D, cpl_evap2D, cpl_tsol2D
85  !$OMP THREADPRIVATE(cpl_snow2D, cpl_evap2D, cpl_tsol2D)
86  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_fder2D, cpl_albe2D
87  !$OMP THREADPRIVATE(cpl_fder2D, cpl_albe2D)
88  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_taux2D, cpl_tauy2D
89  !$OMP THREADPRIVATE(cpl_taux2D, cpl_tauy2D)
90  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_taumod2D
91  !$OMP THREADPRIVATE(cpl_taumod2D)
92  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp2D
93  !$OMP THREADPRIVATE(cpl_windsp2D)
94  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE   :: cpl_sens_rain2D, cpl_sens_snow2D
95  !$OMP THREADPRIVATE(cpl_sens_rain2D, cpl_sens_snow2D)
96  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_atm_co22D
97  !$OMP THREADPRIVATE(cpl_atm_co22D)
98
99!!!!!!!!!! variable for calving
100  INTEGER, PARAMETER :: nb_zone_calving = 3
101  REAL,ALLOCATABLE, DIMENSION(:,:,:),SAVE :: area_calving
102  !$OMP THREADPRIVATE(area_calving)
103  REAL,ALLOCATABLE, DIMENSION(:,:),SAVE :: cell_area2D
104  !$OMP THREADPRIVATE(cell_area2D)
105  INTEGER, SAVE :: ind_calving(nb_zone_calving)
106  !$OMP THREADPRIVATE(ind_calving)
107
108  LOGICAL,SAVE :: cpl_old_calving
109  !$OMP THREADPRIVATE(cpl_old_calving)
110 
111CONTAINS
112!
113!************************************************************************************
114!
115  SUBROUTINE cpl_init(dtime, rlon, rlat)
116    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
117    USE surface_data
118    USE indice_sol_mod
119    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid1dTo2d_glo, klon_glo, grid_type, unstructured, regular_lonlat
120    USE time_phylmdz_mod, ONLY: annee_ref, day_ini, itau_phy, itaufin_phy
121    USE print_control_mod, ONLY: lunout
122    USE geometry_mod, ONLY : longitude_deg, latitude_deg, ind_cell_glo, cell_area
123    USE ioipsl_getin_p_mod, ONLY: getin_p
124
125! Input arguments
126!*************************************************************************************
127    REAL, INTENT(IN)                  :: dtime
128    REAL, DIMENSION(klon), INTENT(IN) :: rlon, rlat
129
130! Local variables
131!*************************************************************************************
132    INTEGER                           :: error, sum_error, ig, i
133    INTEGER                           :: jf, nhoridct
134    INTEGER                           :: nhoridcs
135    INTEGER                           :: idtime
136    INTEGER                           :: idayref
137    INTEGER                           :: npas ! only for OASIS2
138    REAL                              :: zjulian
139    REAL, DIMENSION(nbp_lon,nbp_lat)  :: zx_lon, zx_lat
140    CHARACTER(len = 20)               :: modname = 'cpl_init'
141    CHARACTER(len = 80)               :: abort_message
142    CHARACTER(len=80)                 :: clintocplnam, clfromcplnam
143    REAL, DIMENSION(klon_mpi)         :: rlon_mpi, rlat_mpi, cell_area_mpi
144    INTEGER, DIMENSION(klon_mpi)           :: ind_cell_glo_mpi
145    REAL, DIMENSION(nbp_lon,jj_nb)         :: lon2D, lat2D
146    INTEGER :: mask_calving(nbp_lon,jj_nb,nb_zone_calving)
147    REAL :: pos
148
149!***************************************
150! Use old calving or not (default no)
151    cpl_old_calving=.FALSE.
152    CALL getin_p("cpl_old_calving",cpl_old_calving)
153
154
155!*************************************************************************************
156! Calculate coupling period
157!
158!*************************************************************************************
159     
160    npas = itaufin_phy
161!    nexca = 86400 / dtime
162    nexca = t_coupl / dtime
163    WRITE(lunout,*)' ##### Ocean couple #####'
164    WRITE(lunout,*)' Valeurs des pas de temps'
165    WRITE(lunout,*)' npas = ', npas
166    WRITE(lunout,*)' nexca = ', nexca
167   
168!*************************************************************************************
169! Allocate variables
170!
171!*************************************************************************************
172    error = 0
173    sum_error = 0
174
175    ALLOCATE(unity(klon), stat = error)
176    sum_error = sum_error + error
177    ALLOCATE(cpl_sols(klon,2), stat = error)
178    sum_error = sum_error + error
179    ALLOCATE(cpl_nsol(klon,2), stat = error)
180    sum_error = sum_error + error
181    ALLOCATE(cpl_rain(klon,2), stat = error)
182    sum_error = sum_error + error
183    ALLOCATE(cpl_snow(klon,2), stat = error)
184    sum_error = sum_error + error
185    ALLOCATE(cpl_evap(klon,2), stat = error)
186    sum_error = sum_error + error
187    ALLOCATE(cpl_tsol(klon,2), stat = error)
188    sum_error = sum_error + error
189    ALLOCATE(cpl_fder(klon,2), stat = error)
190    sum_error = sum_error + error
191    ALLOCATE(cpl_albe(klon,2), stat = error)
192    sum_error = sum_error + error
193    ALLOCATE(cpl_taux(klon,2), stat = error)
194    sum_error = sum_error + error
195    ALLOCATE(cpl_tauy(klon,2), stat = error)
196    sum_error = sum_error + error
197    ALLOCATE(cpl_windsp(klon,2), stat = error)
198    sum_error = sum_error + error
199    ALLOCATE(cpl_taumod(klon,2), stat = error)
200    sum_error = sum_error + error
201    ALLOCATE(cpl_sens_rain(klon,2), stat = error)
202    sum_error = sum_error + error
203    ALLOCATE(cpl_sens_snow(klon,2), stat = error)
204    sum_error = sum_error + error
205    ALLOCATE(cpl_rriv2D(nbp_lon,jj_nb), stat=error)
206    sum_error = sum_error + error
207    ALLOCATE(cpl_rcoa2D(nbp_lon,jj_nb), stat=error)
208    sum_error = sum_error + error
209    ALLOCATE(cpl_rlic2D(nbp_lon,jj_nb), stat=error)
210    sum_error = sum_error + error
211    ALLOCATE(read_sst(nbp_lon, jj_nb), stat = error)
212    sum_error = sum_error + error
213    ALLOCATE(read_sic(nbp_lon, jj_nb), stat = error)
214    sum_error = sum_error + error
215    ALLOCATE(read_sit(nbp_lon, jj_nb), stat = error)
216    sum_error = sum_error + error
217    ALLOCATE(read_alb_sic(nbp_lon, jj_nb), stat = error)
218    sum_error = sum_error + error
219    ALLOCATE(read_u0(nbp_lon, jj_nb), stat = error)
220    sum_error = sum_error + error
221    ALLOCATE(read_v0(nbp_lon, jj_nb), stat = error)
222    sum_error = sum_error + error
223
224    IF (carbon_cycle_cpl) THEN
225       ALLOCATE(read_co2(nbp_lon, jj_nb), stat = error)
226       sum_error = sum_error + error
227       ALLOCATE(cpl_atm_co2(klon,2), stat = error)
228       sum_error = sum_error + error
229
230! Allocate variable in carbon_cycle_mod
231       IF (.NOT.ALLOCATED(fco2_ocn_day)) ALLOCATE(fco2_ocn_day(klon), stat = error)
232       sum_error = sum_error + error
233    ENDIF
234
235! calving initialization
236    ALLOCATE(area_calving(nbp_lon, jj_nb, nb_zone_calving), stat = error)
237    sum_error = sum_error + error
238    ALLOCATE(cell_area2D(nbp_lon, jj_nb), stat = error)   
239    sum_error = sum_error + error
240
241
242    CALL gather_omp(longitude_deg,rlon_mpi)
243    CALL gather_omp(latitude_deg,rlat_mpi)
244    CALL gather_omp(ind_cell_glo,ind_cell_glo_mpi)
245    CALL gather_omp(cell_area,cell_area_mpi)
246     
247    IF (is_omp_master) THEN
248      CALL Grid1DTo2D_mpi(rlon_mpi,lon2D)
249      CALL Grid1DTo2D_mpi(rlat_mpi,lat2D)
250      CALL Grid1DTo2D_mpi(cell_area_mpi,cell_area2D)
251      mask_calving(:,:,:) = 0
252      WHERE ( lat2D >= 40) mask_calving(:,:,1) = 1
253      WHERE ( lat2D < 40 .AND. lat2D > -50) mask_calving(:,:,2) = 1
254      WHERE ( lat2D <= -50) mask_calving(:,:,3) = 1
255   
256   
257      DO i=1,nb_zone_calving
258        area_calving(:,:,i)=mask_calving(:,:,i)*cell_area2D(:,:)
259        pos=1
260        IF (i>1) pos = 1 + ((nbp_lon*nbp_lat-1)*(i-1))/(nb_zone_calving-1)
261     
262        ind_calving(i)=0
263        IF (grid_type==unstructured) THEN
264
265          DO ig=1,klon_mpi
266            IF (ind_cell_glo_mpi(ig)==pos) ind_calving(i)=ig
267          ENDDO
268
269        ELSE IF (grid_type==regular_lonlat) THEN
270          IF ((ij_begin<=pos .AND. ij_end>=pos) .OR. (ij_begin<=pos .AND. is_south_pole_dyn )) THEN
271            ind_calving(i)=pos-(jj_begin-1)*nbp_lon
272          ENDIF
273        ENDIF
274     
275      ENDDO
276    ENDIF
277   
278           
279    IF (sum_error /= 0) THEN
280       abort_message='Pb allocation variables couplees'
281       CALL abort_physic(modname,abort_message,1)
282    ENDIF
283!*************************************************************************************
284! Initialize the allocated varaibles
285!
286!*************************************************************************************
287    DO ig = 1, klon
288       unity(ig) = ig
289    ENDDO
290
291!*************************************************************************************
292! Initialize coupling
293!
294!*************************************************************************************
295    idtime = INT(dtime)
296#ifdef CPP_COUPLE
297    CALL inicma
298#endif
299
300!*************************************************************************************
301! initialize NetCDF output
302!
303!*************************************************************************************
304    IF (is_sequential) THEN
305       idayref = day_ini
306       CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
307       CALL grid1dTo2d_glo(rlon,zx_lon)
308       DO i = 1, nbp_lon
309          zx_lon(i,1) = rlon(i+1)
310          zx_lon(i,nbp_lat) = rlon(i+1)
311       ENDDO
312       CALL grid1dTo2d_glo(rlat,zx_lat)
313       clintocplnam="cpl_atm_tauflx"
314       CALL histbeg(clintocplnam,nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:),&
315            1,nbp_lon,1,nbp_lat, itau_phy,zjulian,dtime,nhoridct,nidct)
316! no vertical axis
317       CALL histdef(nidct, 'tauxe','tauxe', &
318            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
319       CALL histdef(nidct, 'tauyn','tauyn', &
320            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
321       CALL histdef(nidct, 'tmp_lon','tmp_lon', &
322            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
323       CALL histdef(nidct, 'tmp_lat','tmp_lat', &
324            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
325       DO jf=1,maxsend
326         IF (infosend(i)%action) THEN
327             CALL histdef(nidct, infosend(i)%name ,infosend(i)%name , &
328                "-",nbp_lon,nbp_lat,nhoridct,1,1,1,-99,32,"inst",dtime,dtime)
329         ENDIF
330       ENDDO
331       CALL histend(nidct)
332       CALL histsync(nidct)
333       
334       clfromcplnam="cpl_atm_sst"
335       CALL histbeg(clfromcplnam,nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:),1,nbp_lon,1,nbp_lat, &
336            0,zjulian,dtime,nhoridcs,nidcs)
337! no vertical axis
338       DO jf=1,maxrecv
339         IF (inforecv(i)%action) THEN
340             CALL histdef(nidcs,inforecv(i)%name ,inforecv(i)%name , &
341                "-",nbp_lon,nbp_lat,nhoridcs,1,1,1,-99,32,"inst",dtime,dtime)
342         ENDIF
343       ENDDO
344       CALL histend(nidcs)
345       CALL histsync(nidcs)
346
347    ENDIF    ! is_sequential
348   
349
350!*************************************************************************************
351! compatibility test
352!
353!*************************************************************************************
354    IF (carbon_cycle_cpl .AND. version_ocean=='opa8') THEN
355       abort_message='carbon_cycle_cpl does not work with opa8'
356       CALL abort_physic(modname,abort_message,1)
357    ENDIF
358
359  END SUBROUTINE cpl_init
360 
361!
362!*************************************************************************************
363!
364 
365  SUBROUTINE cpl_receive_frac(itime, dtime, pctsrf, is_modified)
366! This subroutine receives from coupler for both ocean and seaice
367! 4 fields : read_sst, read_sic, read_sit and read_alb_sic.
368! The new sea-ice-land-landice fraction is returned. The others fields
369! are stored in this module.
370    USE surface_data
371    USE geometry_mod, ONLY : longitude_deg, latitude_deg
372    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
373    USE indice_sol_mod
374    USE time_phylmdz_mod, ONLY: start_time, itau_phy
375    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
376
377    INCLUDE "YOMCST.h"
378
379! Arguments
380!************************************************************************************
381    INTEGER, INTENT(IN)                        :: itime
382    REAL, INTENT(IN)                           :: dtime
383    REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: pctsrf
384    LOGICAL, INTENT(OUT)                       :: is_modified
385
386! Local variables
387!************************************************************************************
388    INTEGER                                 :: j, i, time_sec
389    INTEGER                                 :: itau_w
390    INTEGER, DIMENSION(nbp_lon*nbp_lat)     :: ndexcs
391    CHARACTER(len = 20)                     :: modname = 'cpl_receive_frac'
392    CHARACTER(len = 80)                     :: abort_message
393    REAL, DIMENSION(klon)                   :: read_sic1D
394    REAL, DIMENSION(nbp_lon,jj_nb,maxrecv)      :: tab_read_flds
395    REAL, DIMENSION(klon,nbsrf)             :: pctsrf_old
396    REAL, DIMENSION(klon_mpi)               :: rlon_mpi, rlat_mpi
397    REAL, DIMENSION(nbp_lon,jj_nb)             :: tmp_lon, tmp_lat
398    REAL, DIMENSION(nbp_lon,jj_nb)             :: tmp_r0
399
400!*************************************************************************************
401! Start calculation
402! Get fields from coupler
403!
404!*************************************************************************************
405
406    is_modified=.FALSE.
407
408! Check if right moment to receive from coupler
409    IF (MOD(itime, nexca) == 1) THEN
410       is_modified=.TRUE.
411 
412       time_sec=(itime-1)*dtime
413#ifdef CPP_COUPLE
414!$OMP MASTER
415    CALL fromcpl(time_sec, tab_read_flds)
416!$OMP END MASTER
417#endif
418   
419! NetCDF output of received fields
420       IF (is_sequential) THEN
421          ndexcs(:) = 0
422          itau_w = itau_phy + itime + start_time * day_step_phy
423          DO i = 1, maxrecv
424            IF (inforecv(i)%action) THEN
425                CALL histwrite(nidcs,inforecv(i)%name,itau_w,tab_read_flds(:,:,i),nbp_lon*(nbp_lat),ndexcs)
426            ENDIF
427          ENDDO
428       ENDIF
429
430
431! Save each field in a 2D array.
432!$OMP MASTER
433       read_sst(:,:)     = tab_read_flds(:,:,idr_sisutw)  ! Sea surface temperature
434       read_sic(:,:)     = tab_read_flds(:,:,idr_icecov)  ! Sea ice concentration
435       read_alb_sic(:,:) = tab_read_flds(:,:,idr_icealw)  ! Albedo at sea ice
436       read_sit(:,:)     = tab_read_flds(:,:,idr_icetem)  ! Sea ice temperature
437!$OMP END MASTER
438
439       IF (cpl_current) THEN
440
441! Transform the longitudes and latitudes on 2D arrays
442          CALL gather_omp(longitude_deg,rlon_mpi)
443          CALL gather_omp(latitude_deg,rlat_mpi)
444!$OMP MASTER
445          CALL Grid1DTo2D_mpi(rlon_mpi,tmp_lon)
446          CALL Grid1DTo2D_mpi(rlat_mpi,tmp_lat)
447
448! Transform the currents from cartesian to spheric coordinates
449! tmp_r0 should be zero
450          CALL geo2atm(nbp_lon, jj_nb, tab_read_flds(:,:,idr_curenx), &
451             tab_read_flds(:,:,idr_cureny), tab_read_flds(:,:,idr_curenz), &
452               tmp_lon, tmp_lat, &
453               read_u0(:,:), read_v0(:,:), tmp_r0(:,:))
454!$OMP END MASTER
455
456      ELSE
457          read_u0(:,:) = 0.
458          read_v0(:,:) = 0.
459      ENDIF
460
461       IF (carbon_cycle_cpl) THEN
462!$OMP MASTER
463           read_co2(:,:) = tab_read_flds(:,:,idr_oceco2) ! CO2 flux
464!$OMP END MASTER
465       ENDIF
466
467!*************************************************************************************
468!  Transform seaice fraction (read_sic : ocean-seaice mask) into global
469!  fraction (pctsrf : ocean-seaice-land-landice mask)
470!
471!*************************************************************************************
472       CALL cpl2gath(read_sic, read_sic1D, klon, unity)
473
474       pctsrf_old(:,:) = pctsrf(:,:)
475       DO i = 1, klon
476          ! treatment only of points with ocean and/or seaice
477          ! old land-ocean mask can not be changed
478          IF (pctsrf_old(i,is_oce) + pctsrf_old(i,is_sic) > 0.) THEN
479             pctsrf(i,is_sic) = (pctsrf_old(i,is_oce) + pctsrf_old(i,is_sic)) &
480                  * read_sic1D(i)
481             pctsrf(i,is_oce) = (pctsrf_old(i,is_oce) + pctsrf_old(i,is_sic)) &
482                  - pctsrf(i,is_sic)
483          ENDIF
484       ENDDO
485
486    ENDIF ! if time to receive
487
488  END SUBROUTINE cpl_receive_frac
489
490!
491!*************************************************************************************
492!
493
494  SUBROUTINE cpl_receive_ocean_fields(knon, knindex, tsurf_new, u0_new, v0_new)
495!
496! This routine returns the field for the ocean that has been read from the coupler
497! (done earlier with cpl_receive_frac). The field is the temperature.
498! The temperature is transformed into 1D array with valid points from index 1 to knon.
499!
500    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
501    USE indice_sol_mod
502
503! Input arguments
504!*************************************************************************************
505    INTEGER, INTENT(IN)                     :: knon
506    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
507
508! Output arguments
509!*************************************************************************************
510    REAL, DIMENSION(klon), INTENT(OUT)      :: tsurf_new
511    REAL, DIMENSION(klon), INTENT(OUT)      :: u0_new
512    REAL, DIMENSION(klon), INTENT(OUT)      :: v0_new
513
514! Local variables
515!*************************************************************************************
516    INTEGER                  :: i
517    INTEGER, DIMENSION(klon) :: index
518    REAL, DIMENSION(klon)    :: sic_new
519
520!*************************************************************************************
521! Transform read_sst into compressed 1D variable tsurf_new
522!
523!*************************************************************************************
524    CALL cpl2gath(read_sst, tsurf_new, knon, knindex)
525    CALL cpl2gath(read_sic, sic_new, knon, knindex)
526    CALL cpl2gath(read_u0, u0_new, knon, knindex)
527    CALL cpl2gath(read_v0, v0_new, knon, knindex)
528
529!*************************************************************************************
530! Transform read_co2 into uncompressed 1D variable fco2_ocn_day added directly in
531! the module carbon_cycle_mod
532!
533!*************************************************************************************
534    IF (carbon_cycle_cpl) THEN
535       DO i=1,klon
536          index(i)=i
537       ENDDO
538       CALL cpl2gath(read_co2, fco2_ocn_day, klon, index)
539    ENDIF
540
541!*************************************************************************************
542! The fields received from the coupler have to be weighted with the fraction of ocean
543! in relation to the total sea-ice+ocean
544!
545!*************************************************************************************
546    DO i=1, knon
547       tsurf_new(i) = tsurf_new(i)/(1. - sic_new(i))
548    ENDDO
549
550  END SUBROUTINE cpl_receive_ocean_fields
551
552!
553!*************************************************************************************
554!
555
556  SUBROUTINE cpl_receive_seaice_fields(knon, knindex, &
557       tsurf_new, alb_new, u0_new, v0_new)
558!
559! This routine returns the fields for the seaice that have been read from the coupler
560! (done earlier with cpl_receive_frac). These fields are the temperature and
561! albedo at sea ice surface and fraction of sea ice.
562! The fields are transformed into 1D arrays with valid points from index 1 to knon.
563!
564
565! Input arguments
566!*************************************************************************************
567    INTEGER, INTENT(IN)                     :: knon
568    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
569
570! Output arguments
571!*************************************************************************************
572    REAL, DIMENSION(klon), INTENT(OUT)      :: tsurf_new
573    REAL, DIMENSION(klon), INTENT(OUT)      :: alb_new
574    REAL, DIMENSION(klon), INTENT(OUT)      :: u0_new
575    REAL, DIMENSION(klon), INTENT(OUT)      :: v0_new
576
577! Local variables
578!*************************************************************************************
579    INTEGER               :: i
580    REAL, DIMENSION(klon) :: sic_new
581
582!*************************************************************************************
583! Transform fields read from coupler from 2D into compressed 1D variables
584!
585!*************************************************************************************
586    CALL cpl2gath(read_sit, tsurf_new, knon, knindex)
587    CALL cpl2gath(read_alb_sic, alb_new, knon, knindex)
588    CALL cpl2gath(read_sic, sic_new, knon, knindex)
589    CALL cpl2gath(read_u0, u0_new, knon, knindex)
590    CALL cpl2gath(read_v0, v0_new, knon, knindex)
591
592!*************************************************************************************
593! The fields received from the coupler have to be weighted with the sea-ice
594! concentration (in relation to the total sea-ice + ocean).
595!
596!*************************************************************************************
597    DO i= 1, knon
598       tsurf_new(i) = tsurf_new(i) / sic_new(i)
599       alb_new(i)   = alb_new(i)   / sic_new(i)
600    ENDDO
601
602  END SUBROUTINE cpl_receive_seaice_fields
603
604!
605!*************************************************************************************
606!
607
608  SUBROUTINE cpl_send_ocean_fields(itime, knon, knindex, &
609       swdown, lwdown, fluxlat, fluxsens, &
610       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy, windsp,&
611       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
612!
613! This subroutine cumulates some fields for each time-step during a coupling
614! period. At last time-step in a coupling period the fields are transformed to the
615! grid accepted by the coupler. No sending to the coupler will be done from here
616! (it is done in cpl_send_seaice_fields).
617!
618    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
619    USE indice_sol_mod
620    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
621
622! Input arguments
623!*************************************************************************************
624    INTEGER, INTENT(IN)                     :: itime
625    INTEGER, INTENT(IN)                     :: knon
626    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
627    REAL, DIMENSION(klon), INTENT(IN)       :: swdown, lwdown
628    REAL, DIMENSION(klon), INTENT(IN)       :: fluxlat, fluxsens
629    REAL, DIMENSION(klon), INTENT(IN)       :: precip_rain, precip_snow
630    REAL, DIMENSION(klon), INTENT(IN)       :: evap, tsurf, fder, albsol
631    REAL, DIMENSION(klon), INTENT(IN)       :: taux, tauy, windsp
632    REAL, DIMENSION(klon), INTENT(IN)       :: sens_prec_liq, sens_prec_sol
633    REAL, DIMENSION(klon), INTENT(IN)       :: lat_prec_liq, lat_prec_sol
634
635! Local variables
636!*************************************************************************************
637    INTEGER                                 :: cpl_index, ig
638    INTEGER                                 :: error, sum_error
639    CHARACTER(len = 25)                     :: modname = 'cpl_send_ocean_fields'
640    CHARACTER(len = 80)                     :: abort_message
641
642!*************************************************************************************
643! Start calculation
644! The ocean points are saved with second array index=1
645!
646!*************************************************************************************
647    cpl_index = 1
648
649!*************************************************************************************
650! Reset fields to zero in the beginning of a new coupling period
651!
652!*************************************************************************************
653    IF (MOD(itime, nexca) == 1) THEN
654       cpl_sols(1:knon,cpl_index) = 0.0
655       cpl_nsol(1:knon,cpl_index) = 0.0
656       cpl_rain(1:knon,cpl_index) = 0.0
657       cpl_snow(1:knon,cpl_index) = 0.0
658       cpl_evap(1:knon,cpl_index) = 0.0
659       cpl_tsol(1:knon,cpl_index) = 0.0
660       cpl_fder(1:knon,cpl_index) = 0.0
661       cpl_albe(1:knon,cpl_index) = 0.0
662       cpl_taux(1:knon,cpl_index) = 0.0
663       cpl_tauy(1:knon,cpl_index) = 0.0
664       cpl_windsp(1:knon,cpl_index) = 0.0
665       cpl_sens_rain(1:knon,cpl_index) = 0.0
666       cpl_sens_snow(1:knon,cpl_index) = 0.0
667       cpl_taumod(1:knon,cpl_index) = 0.0
668       IF (carbon_cycle_cpl) cpl_atm_co2(1:knon,cpl_index) = 0.0
669    ENDIF
670       
671!*************************************************************************************
672! Cumulate at each time-step
673!
674!*************************************************************************************   
675    DO ig = 1, knon
676       cpl_sols(ig,cpl_index) = cpl_sols(ig,cpl_index) + &
677            swdown(ig)      / REAL(nexca)
678       cpl_nsol(ig,cpl_index) = cpl_nsol(ig,cpl_index) + &
679            (lwdown(ig) + fluxlat(ig) +fluxsens(ig)) / REAL(nexca)
680       cpl_rain(ig,cpl_index) = cpl_rain(ig,cpl_index) + &
681            precip_rain(ig) / REAL(nexca)
682       cpl_snow(ig,cpl_index) = cpl_snow(ig,cpl_index) + &
683            precip_snow(ig) / REAL(nexca)
684       cpl_evap(ig,cpl_index) = cpl_evap(ig,cpl_index) + &
685            evap(ig)        / REAL(nexca)
686       cpl_tsol(ig,cpl_index) = cpl_tsol(ig,cpl_index) + &
687            tsurf(ig)       / REAL(nexca)
688       cpl_fder(ig,cpl_index) = cpl_fder(ig,cpl_index) + &
689            fder(ig)        / REAL(nexca)
690       cpl_albe(ig,cpl_index) = cpl_albe(ig,cpl_index) + &
691            albsol(ig)      / REAL(nexca)
692       cpl_taux(ig,cpl_index) = cpl_taux(ig,cpl_index) + &
693            taux(ig)        / REAL(nexca)
694       cpl_tauy(ig,cpl_index) = cpl_tauy(ig,cpl_index) + &
695            tauy(ig)        / REAL(nexca)     
696       cpl_windsp(ig,cpl_index) = cpl_windsp(ig,cpl_index) + &
697            windsp(ig)      / REAL(nexca)
698       cpl_sens_rain(ig,cpl_index) = cpl_sens_rain(ig,cpl_index) + &
699            sens_prec_liq(ig)      / REAL(nexca)
700       cpl_sens_snow(ig,cpl_index) = cpl_sens_snow(ig,cpl_index) + &
701            sens_prec_sol(ig)      / REAL(nexca)
702       cpl_taumod(ig,cpl_index) =   cpl_taumod(ig,cpl_index) + &
703          SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / REAL (nexca)
704
705       IF (carbon_cycle_cpl) THEN
706          cpl_atm_co2(ig,cpl_index) = cpl_atm_co2(ig,cpl_index) + &
707               co2_send(knindex(ig))/ REAL(nexca)
708!!---OB: this is correct but why knindex ??
709       ENDIF
710     ENDDO
711
712!*************************************************************************************
713! If the time-step corresponds to the end of coupling period the
714! fields are transformed to the 2D grid.
715! No sending to the coupler (it is done from cpl_send_seaice_fields).
716!
717!*************************************************************************************
718    IF (MOD(itime, nexca) == 0) THEN
719
720       IF (.NOT. ALLOCATED(cpl_sols2D)) THEN
721          sum_error = 0
722          ALLOCATE(cpl_sols2D(nbp_lon,jj_nb,2), stat=error)
723          sum_error = sum_error + error
724          ALLOCATE(cpl_nsol2D(nbp_lon,jj_nb,2), stat=error)
725          sum_error = sum_error + error
726          ALLOCATE(cpl_rain2D(nbp_lon,jj_nb,2), stat=error)
727          sum_error = sum_error + error
728          ALLOCATE(cpl_snow2D(nbp_lon,jj_nb,2), stat=error)
729          sum_error = sum_error + error
730          ALLOCATE(cpl_evap2D(nbp_lon,jj_nb,2), stat=error)
731          sum_error = sum_error + error
732          ALLOCATE(cpl_tsol2D(nbp_lon,jj_nb,2), stat=error)
733          sum_error = sum_error + error
734          ALLOCATE(cpl_fder2D(nbp_lon,jj_nb,2), stat=error)
735          sum_error = sum_error + error
736          ALLOCATE(cpl_albe2D(nbp_lon,jj_nb,2), stat=error)
737          sum_error = sum_error + error
738          ALLOCATE(cpl_taux2D(nbp_lon,jj_nb,2), stat=error)
739          sum_error = sum_error + error
740          ALLOCATE(cpl_tauy2D(nbp_lon,jj_nb,2), stat=error)
741          sum_error = sum_error + error
742          ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
743          sum_error = sum_error + error
744          ALLOCATE(cpl_sens_rain2D(nbp_lon,jj_nb,2), stat=error)
745          sum_error = sum_error + error
746          ALLOCATE(cpl_sens_snow2D(nbp_lon,jj_nb,2), stat=error)
747          sum_error = sum_error + error
748          ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
749          sum_error = sum_error + error
750         
751          IF (carbon_cycle_cpl) THEN
752             ALLOCATE(cpl_atm_co22D(nbp_lon,jj_nb), stat=error)
753             sum_error = sum_error + error
754          ENDIF
755
756          IF (sum_error /= 0) THEN
757             abort_message='Pb allocation variables couplees pour l''ecriture'
758             CALL abort_physic(modname,abort_message,1)
759          ENDIF
760       ENDIF
761       
762
763       CALL gath2cpl(cpl_sols(:,cpl_index), cpl_sols2D(:,:,cpl_index), &
764            knon, knindex)
765
766       CALL gath2cpl(cpl_nsol(:,cpl_index), cpl_nsol2D(:,:,cpl_index), &
767            knon, knindex)
768
769       CALL gath2cpl(cpl_rain(:,cpl_index), cpl_rain2D(:,:,cpl_index), &
770            knon, knindex)
771
772       CALL gath2cpl(cpl_snow(:,cpl_index), cpl_snow2D(:,:,cpl_index), &
773            knon, knindex)
774
775       CALL gath2cpl(cpl_evap(:,cpl_index), cpl_evap2D(:,:,cpl_index), &
776            knon, knindex)
777
778! cpl_tsol2D(:,:,:) not used!
779       CALL gath2cpl(cpl_tsol(:,cpl_index), cpl_tsol2D(:,:, cpl_index), &
780            knon, knindex)
781
782! cpl_fder2D(:,:,1) not used, only cpl_fder(:,:,2)!
783       CALL gath2cpl(cpl_fder(:,cpl_index), cpl_fder2D(:,:,cpl_index), &
784            knon, knindex)
785
786! cpl_albe2D(:,:,:) not used!
787       CALL gath2cpl(cpl_albe(:,cpl_index), cpl_albe2D(:,:,cpl_index), &
788            knon, knindex)
789
790       CALL gath2cpl(cpl_taux(:,cpl_index), cpl_taux2D(:,:,cpl_index), &
791            knon, knindex)
792
793       CALL gath2cpl(cpl_tauy(:,cpl_index), cpl_tauy2D(:,:,cpl_index), &
794            knon, knindex)
795
796       CALL gath2cpl(cpl_windsp(:,cpl_index), cpl_windsp2D(:,:), &
797            knon, knindex)
798
799       CALL gath2cpl(cpl_sens_rain(:,cpl_index), cpl_sens_rain2D(:,:,cpl_index), &
800            knon, knindex)
801
802       CALL gath2cpl(cpl_sens_snow(:,cpl_index), cpl_sens_snow2D(:,:,cpl_index), &
803            knon, knindex)
804
805       CALL gath2cpl(cpl_taumod(:,cpl_index), cpl_taumod2D(:,:,cpl_index), &
806            knon, knindex)
807
808       IF (carbon_cycle_cpl) &
809            CALL gath2cpl(cpl_atm_co2(:,cpl_index), cpl_atm_co22D(:,:), knon, knindex)
810   ENDIF
811
812  END SUBROUTINE cpl_send_ocean_fields
813
814!
815!*************************************************************************************
816!
817
818  SUBROUTINE cpl_send_seaice_fields(itime, dtime, knon, knindex, &
819       pctsrf, lafin, rlon, rlat, &
820       swdown, lwdown, fluxlat, fluxsens, &
821       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy,&
822       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
823!
824! This subroutine cumulates some fields for each time-step during a coupling
825! period. At last time-step in a coupling period the fields are transformed to the
826! grid accepted by the coupler. All fields for all types of surfaces are sent to
827! the coupler.
828!
829    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
830    USE indice_sol_mod
831    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
832
833! Input arguments
834!*************************************************************************************
835    INTEGER, INTENT(IN)                     :: itime
836    INTEGER, INTENT(IN)                     :: knon
837    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
838    REAL, INTENT(IN)                        :: dtime
839    REAL, DIMENSION(klon), INTENT(IN)       :: rlon, rlat
840    REAL, DIMENSION(klon), INTENT(IN)       :: swdown, lwdown
841    REAL, DIMENSION(klon), INTENT(IN)       :: fluxlat, fluxsens
842    REAL, DIMENSION(klon), INTENT(IN)       :: precip_rain, precip_snow
843    REAL, DIMENSION(klon), INTENT(IN)       :: evap, tsurf, fder
844    REAL, DIMENSION(klon), INTENT(IN)       :: albsol, taux, tauy
845    REAL, DIMENSION(klon,nbsrf), INTENT(IN) :: pctsrf
846    REAL, DIMENSION(klon), INTENT(IN)       :: sens_prec_liq, sens_prec_sol
847    REAL, DIMENSION(klon), INTENT(IN)       :: lat_prec_liq, lat_prec_sol
848    LOGICAL, INTENT(IN)                     :: lafin
849
850! Local variables
851!*************************************************************************************
852    INTEGER                                 :: cpl_index, ig
853    INTEGER                                 :: error, sum_error
854    CHARACTER(len = 25)                     :: modname = 'cpl_send_seaice_fields'
855    CHARACTER(len = 80)                     :: abort_message
856    REAL, DIMENSION(klon)                   :: cpl_fder_tmp
857
858!*************************************************************************************
859! Start calulation
860! The sea-ice points are saved with second array index=2
861!
862!*************************************************************************************
863    cpl_index = 2
864
865!*************************************************************************************
866! Reset fields to zero in the beginning of a new coupling period
867!
868!*************************************************************************************
869    IF (MOD(itime, nexca) == 1) THEN
870       cpl_sols(1:knon,cpl_index) = 0.0
871       cpl_nsol(1:knon,cpl_index) = 0.0
872       cpl_rain(1:knon,cpl_index) = 0.0
873       cpl_snow(1:knon,cpl_index) = 0.0
874       cpl_evap(1:knon,cpl_index) = 0.0
875       cpl_tsol(1:knon,cpl_index) = 0.0
876       cpl_fder(1:knon,cpl_index) = 0.0
877       cpl_albe(1:knon,cpl_index) = 0.0
878       cpl_taux(1:knon,cpl_index) = 0.0
879       cpl_tauy(1:knon,cpl_index) = 0.0
880       cpl_sens_rain(1:knon,cpl_index) = 0.0
881       cpl_sens_snow(1:knon,cpl_index) = 0.0
882       cpl_taumod(1:knon,cpl_index) = 0.0
883    ENDIF
884       
885!*************************************************************************************
886! Cumulate at each time-step
887!
888!*************************************************************************************   
889    DO ig = 1, knon
890       cpl_sols(ig,cpl_index) = cpl_sols(ig,cpl_index) + &
891            swdown(ig)      / REAL(nexca)
892       cpl_nsol(ig,cpl_index) = cpl_nsol(ig,cpl_index) + &
893            (lwdown(ig) + fluxlat(ig) +fluxsens(ig)) / REAL(nexca)
894       cpl_rain(ig,cpl_index) = cpl_rain(ig,cpl_index) + &
895            precip_rain(ig) / REAL(nexca)
896       cpl_snow(ig,cpl_index) = cpl_snow(ig,cpl_index) + &
897            precip_snow(ig) / REAL(nexca)
898       cpl_evap(ig,cpl_index) = cpl_evap(ig,cpl_index) + &
899            evap(ig)        / REAL(nexca)
900       cpl_tsol(ig,cpl_index) = cpl_tsol(ig,cpl_index) + &
901            tsurf(ig)       / REAL(nexca)
902       cpl_fder(ig,cpl_index) = cpl_fder(ig,cpl_index) + &
903            fder(ig)        / REAL(nexca)
904       cpl_albe(ig,cpl_index) = cpl_albe(ig,cpl_index) + &
905            albsol(ig)      / REAL(nexca)
906       cpl_taux(ig,cpl_index) = cpl_taux(ig,cpl_index) + &
907            taux(ig)        / REAL(nexca)
908       cpl_tauy(ig,cpl_index) = cpl_tauy(ig,cpl_index) + &
909            tauy(ig)        / REAL(nexca)     
910       cpl_sens_rain(ig,cpl_index) = cpl_sens_rain(ig,cpl_index) + &
911            sens_prec_liq(ig)      / REAL(nexca)
912       cpl_sens_snow(ig,cpl_index) = cpl_sens_snow(ig,cpl_index) + &
913            sens_prec_sol(ig)      / REAL(nexca)
914       cpl_taumod(ig,cpl_index) = cpl_taumod(ig,cpl_index) + &
915            SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / REAL(nexca)
916    ENDDO
917
918!*************************************************************************************
919! If the time-step corresponds to the end of coupling period the
920! fields are transformed to the 2D grid and all fields are sent to coupler.
921!
922!*************************************************************************************
923    IF (MOD(itime, nexca) == 0) THEN
924       IF (.NOT. ALLOCATED(cpl_sols2D)) THEN
925          sum_error = 0
926          ALLOCATE(cpl_sols2D(nbp_lon,jj_nb,2), stat=error)
927          sum_error = sum_error + error
928          ALLOCATE(cpl_nsol2D(nbp_lon,jj_nb,2), stat=error)
929          sum_error = sum_error + error
930          ALLOCATE(cpl_rain2D(nbp_lon,jj_nb,2), stat=error)
931          sum_error = sum_error + error
932          ALLOCATE(cpl_snow2D(nbp_lon,jj_nb,2), stat=error)
933          sum_error = sum_error + error
934          ALLOCATE(cpl_evap2D(nbp_lon,jj_nb,2), stat=error)
935          sum_error = sum_error + error
936          ALLOCATE(cpl_tsol2D(nbp_lon,jj_nb,2), stat=error)
937          sum_error = sum_error + error
938          ALLOCATE(cpl_fder2D(nbp_lon,jj_nb,2), stat=error)
939          sum_error = sum_error + error
940          ALLOCATE(cpl_albe2D(nbp_lon,jj_nb,2), stat=error)
941          sum_error = sum_error + error
942          ALLOCATE(cpl_taux2D(nbp_lon,jj_nb,2), stat=error)
943          sum_error = sum_error + error
944          ALLOCATE(cpl_tauy2D(nbp_lon,jj_nb,2), stat=error)
945          sum_error = sum_error + error
946          ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
947          sum_error = sum_error + error
948          ALLOCATE(cpl_sens_rain2D(nbp_lon,jj_nb,2), stat=error)
949          sum_error = sum_error + error
950          ALLOCATE(cpl_sens_snow2D(nbp_lon,jj_nb,2), stat=error)
951          sum_error = sum_error + error
952          ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
953          sum_error = sum_error + error
954
955          IF (carbon_cycle_cpl) THEN
956             ALLOCATE(cpl_atm_co22D(nbp_lon,jj_nb), stat=error)
957             sum_error = sum_error + error
958          ENDIF
959
960          IF (sum_error /= 0) THEN
961             abort_message='Pb allocation variables couplees pour l''ecriture'
962             CALL abort_physic(modname,abort_message,1)
963          ENDIF
964       ENDIF
965
966       CALL gath2cpl(cpl_sols(:,cpl_index), cpl_sols2D(:,:,cpl_index), &
967            knon, knindex)
968
969       CALL gath2cpl(cpl_nsol(:,cpl_index), cpl_nsol2D(:,:,cpl_index), &
970            knon, knindex)
971
972       CALL gath2cpl(cpl_rain(:,cpl_index), cpl_rain2D(:,:,cpl_index), &
973            knon, knindex)
974
975       CALL gath2cpl(cpl_snow(:,cpl_index), cpl_snow2D(:,:,cpl_index), &
976            knon, knindex)
977
978       CALL gath2cpl(cpl_evap(:,cpl_index), cpl_evap2D(:,:,cpl_index), &
979            knon, knindex)
980
981! cpl_tsol2D(:,:,:) not used!
982       CALL gath2cpl(cpl_tsol(:,cpl_index), cpl_tsol2D(:,:, cpl_index), &
983            knon, knindex)
984
985       ! Set default value and decompress before gath2cpl
986       cpl_fder_tmp(:) = -20.
987       DO ig = 1, knon
988          cpl_fder_tmp(knindex(ig))=cpl_fder(ig,cpl_index)
989       ENDDO
990       CALL gath2cpl(cpl_fder_tmp(:), cpl_fder2D(:,:,cpl_index), &
991            klon, unity)
992
993! cpl_albe2D(:,:,:) not used!
994       CALL gath2cpl(cpl_albe(:,cpl_index), cpl_albe2D(:,:,cpl_index), &
995            knon, knindex)
996
997       CALL gath2cpl(cpl_taux(:,cpl_index), cpl_taux2D(:,:,cpl_index), &
998            knon, knindex)
999
1000       CALL gath2cpl(cpl_tauy(:,cpl_index), cpl_tauy2D(:,:,cpl_index), &
1001            knon, knindex)
1002
1003       CALL gath2cpl(cpl_sens_rain(:,cpl_index), cpl_sens_rain2D(:,:,cpl_index), &
1004            knon, knindex)
1005
1006       CALL gath2cpl(cpl_sens_snow(:,cpl_index), cpl_sens_snow2D(:,:,cpl_index), &
1007            knon, knindex)
1008
1009       CALL gath2cpl(cpl_taumod(:,cpl_index), cpl_taumod2D(:,:,cpl_index), &
1010            knon, knindex)
1011
1012       ! Send all fields
1013       CALL cpl_send_all(itime, dtime, pctsrf, lafin, rlon, rlat)
1014    ENDIF
1015
1016  END SUBROUTINE cpl_send_seaice_fields
1017
1018!
1019!*************************************************************************************
1020!
1021
1022  SUBROUTINE cpl_send_land_fields(itime, knon, knindex, rriv_in, rcoa_in)
1023!
1024! This subroutine cumulates some fields for each time-step during a coupling
1025! period. At last time-step in a coupling period the fields are transformed to the
1026! grid accepted by the coupler. No sending to the coupler will be done from here
1027! (it is done in cpl_send_seaice_fields).
1028!
1029    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1030
1031! Input arguments
1032!*************************************************************************************
1033    INTEGER, INTENT(IN)                       :: itime
1034    INTEGER, INTENT(IN)                       :: knon
1035    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
1036    REAL, DIMENSION(klon), INTENT(IN)         :: rriv_in
1037    REAL, DIMENSION(klon), INTENT(IN)         :: rcoa_in
1038
1039! Local variables
1040!*************************************************************************************
1041    REAL, DIMENSION(nbp_lon,jj_nb)             :: rriv2D
1042    REAL, DIMENSION(nbp_lon,jj_nb)             :: rcoa2D
1043
1044!*************************************************************************************
1045! Rearrange fields in 2D variables
1046! First initialize to zero to avoid unvalid points causing problems
1047!
1048!*************************************************************************************
1049!$OMP MASTER
1050    rriv2D(:,:) = 0.0
1051    rcoa2D(:,:) = 0.0
1052!$OMP END MASTER
1053    CALL gath2cpl(rriv_in, rriv2D, knon, knindex)
1054    CALL gath2cpl(rcoa_in, rcoa2D, knon, knindex)
1055
1056!*************************************************************************************
1057! Reset cumulated fields to zero in the beginning of a new coupling period
1058!
1059!*************************************************************************************
1060    IF (MOD(itime, nexca) == 1) THEN
1061!$OMP MASTER
1062       cpl_rriv2D(:,:) = 0.0
1063       cpl_rcoa2D(:,:) = 0.0
1064!$OMP END MASTER
1065    ENDIF
1066
1067!*************************************************************************************
1068! Cumulate : Following fields should be cumulated at each time-step
1069!
1070!*************************************************************************************   
1071!$OMP MASTER
1072    cpl_rriv2D(:,:) = cpl_rriv2D(:,:) + rriv2D(:,:) / REAL(nexca)
1073    cpl_rcoa2D(:,:) = cpl_rcoa2D(:,:) + rcoa2D(:,:) / REAL(nexca)
1074!$OMP END MASTER
1075
1076  END SUBROUTINE cpl_send_land_fields
1077
1078!
1079!*************************************************************************************
1080!
1081
1082  SUBROUTINE cpl_send_landice_fields(itime, knon, knindex, rlic_in)
1083! This subroutine cumulates the field for melting ice for each time-step
1084! during a coupling period. This routine will not send to coupler. Sending
1085! will be done in cpl_send_seaice_fields.
1086!
1087
1088    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1089
1090! Input varibales
1091!*************************************************************************************
1092    INTEGER, INTENT(IN)                       :: itime
1093    INTEGER, INTENT(IN)                       :: knon
1094    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
1095    REAL, DIMENSION(klon), INTENT(IN)         :: rlic_in
1096
1097! Local varibales
1098!*************************************************************************************
1099    REAL, DIMENSION(nbp_lon,jj_nb)             :: rlic2D
1100
1101!*************************************************************************************
1102! Rearrange field in a 2D variable
1103! First initialize to zero to avoid unvalid points causing problems
1104!
1105!*************************************************************************************
1106!$OMP MASTER
1107    rlic2D(:,:) = 0.0
1108!$OMP END MASTER
1109    CALL gath2cpl(rlic_in, rlic2D, knon, knindex)
1110
1111!*************************************************************************************
1112! Reset field to zero in the beginning of a new coupling period
1113!
1114!*************************************************************************************
1115    IF (MOD(itime, nexca) == 1) THEN
1116!$OMP MASTER
1117       cpl_rlic2D(:,:) = 0.0
1118!$OMP END MASTER
1119    ENDIF
1120
1121!*************************************************************************************
1122! Cumulate : Melting ice should be cumulated at each time-step
1123!
1124!*************************************************************************************   
1125!$OMP MASTER
1126    cpl_rlic2D(:,:) = cpl_rlic2D(:,:) + rlic2D(:,:) / REAL(nexca)
1127!$OMP END MASTER
1128
1129  END SUBROUTINE cpl_send_landice_fields
1130
1131!
1132!*************************************************************************************
1133!
1134
1135  SUBROUTINE cpl_send_all(itime, dtime, pctsrf, lafin, rlon, rlat)
1136! This routine will send fields for all different surfaces to the coupler.
1137! This subroutine should be executed after calculations by the last surface(sea-ice),
1138! all calculations at the different surfaces have to be done before.
1139!   
1140    USE surface_data
1141    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
1142    USE indice_sol_mod
1143    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1144    USE time_phylmdz_mod, ONLY: start_time, itau_phy
1145! Some includes
1146!   
1147! Input arguments
1148!*************************************************************************************
1149    INTEGER, INTENT(IN)                                  :: itime
1150    REAL, INTENT(IN)                                     :: dtime
1151    REAL, DIMENSION(klon), INTENT(IN)                    :: rlon, rlat
1152    REAL, DIMENSION(klon,nbsrf), INTENT(IN)              :: pctsrf
1153    LOGICAL, INTENT(IN)                                  :: lafin
1154   
1155! Local variables
1156!*************************************************************************************
1157    INTEGER                                              :: error, sum_error, i,j,k
1158    INTEGER                                              :: itau_w
1159    INTEGER                                              :: time_sec
1160    INTEGER, DIMENSION(nbp_lon*(nbp_lat))                      :: ndexct
1161    REAL                                                 :: Up, Down
1162    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_lon, tmp_lat
1163    REAL, DIMENSION(nbp_lon, jj_nb, 4)                       :: pctsrf2D
1164    REAL, DIMENSION(nbp_lon, jj_nb)                          :: deno
1165    CHARACTER(len = 20)                                  :: modname = 'cpl_send_all'
1166    CHARACTER(len = 80)                                  :: abort_message
1167   
1168! Variables with fields to coupler
1169    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_taux
1170    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_tauy
1171    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_calv
1172! Table with all fields to send to coupler
1173    REAL, DIMENSION(nbp_lon, jj_nb, maxsend)                 :: tab_flds
1174    REAL, DIMENSION(klon_mpi)                                :: rlon_mpi, rlat_mpi
1175    REAL  :: calving(nb_zone_calving)
1176    REAL  :: calving_glo(nb_zone_calving)
1177   
1178#ifdef CPP_MPI
1179    INCLUDE 'mpif.h'
1180    INTEGER, DIMENSION(MPI_STATUS_SIZE)                  :: status
1181#endif
1182
1183! End definitions
1184!*************************************************************************************
1185   
1186
1187
1188!*************************************************************************************
1189! All fields are stored in a table tab_flds(:,:,:)
1190! First store the fields which are already on the right format
1191!
1192!*************************************************************************************
1193!$OMP MASTER
1194    tab_flds(:,:,ids_windsp) = cpl_windsp2D(:,:)
1195    tab_flds(:,:,ids_shfice) = cpl_sols2D(:,:,2)
1196    tab_flds(:,:,ids_nsfice) = cpl_nsol2D(:,:,2)
1197    tab_flds(:,:,ids_dflxdt) = cpl_fder2D(:,:,2)
1198    tab_flds(:,:,ids_qraioc) = cpl_sens_rain2D(:,:,1)
1199    tab_flds(:,:,ids_qsnooc) = cpl_sens_snow2D(:,:,1)
1200    tab_flds(:,:,ids_qraiic) = cpl_sens_rain2D(:,:,2)
1201    tab_flds(:,:,ids_qsnoic) = cpl_sens_snow2D(:,:,2)
1202   
1203    IF (version_ocean=='nemo') THEN
1204       tab_flds(:,:,ids_liqrun) = (cpl_rriv2D(:,:) + cpl_rcoa2D(:,:))
1205       IF (carbon_cycle_cpl) tab_flds(:,:,ids_atmco2)=cpl_atm_co22D(:,:)
1206    ELSE IF (version_ocean=='opa8') THEN
1207       tab_flds(:,:,ids_shfoce) = cpl_sols2D(:,:,1)
1208       tab_flds(:,:,ids_nsfoce) = cpl_nsol2D(:,:,1)
1209       tab_flds(:,:,ids_icevap) = cpl_evap2D(:,:,2)
1210       tab_flds(:,:,ids_ocevap) = cpl_evap2D(:,:,1)
1211       tab_flds(:,:,ids_runcoa) = cpl_rcoa2D(:,:)
1212       tab_flds(:,:,ids_rivflu) = cpl_rriv2D(:,:)
1213    ENDIF
1214
1215!*************************************************************************************
1216! Transform the fraction of sub-surfaces from 1D to 2D array
1217!
1218!*************************************************************************************
1219    pctsrf2D(:,:,:) = 0.
1220!$OMP END MASTER
1221    CALL gath2cpl(pctsrf(:,is_oce), pctsrf2D(:,:,is_oce), klon, unity)
1222    CALL gath2cpl(pctsrf(:,is_sic), pctsrf2D(:,:,is_sic), klon, unity)
1223    CALL gath2cpl(pctsrf(:,is_lic), pctsrf2D(:,:,is_lic), klon, unity)
1224
1225!*************************************************************************************
1226! Calculate the average calving per latitude
1227! Store calving in tab_flds(:,:,19)
1228!
1229!*************************************************************************************     
1230    IF (is_omp_root) THEN
1231
1232      IF (cpl_old_calving) THEN   ! use old calving
1233
1234        DO j = 1, jj_nb
1235           tmp_calv(:,j) = DOT_PRODUCT (cpl_rlic2D(1:nbp_lon,j), &
1236                pctsrf2D(1:nbp_lon,j,is_lic)) / REAL(nbp_lon)
1237        ENDDO
1238   
1239   
1240        IF (is_parallel) THEN
1241           IF (.NOT. is_north_pole_dyn) THEN
1242#ifdef CPP_MPI
1243              CALL MPI_RECV(Up,1,MPI_REAL_LMDZ,mpi_rank-1,1234,COMM_LMDZ_PHY,status,error)
1244              CALL MPI_SEND(tmp_calv(1,1),1,MPI_REAL_LMDZ,mpi_rank-1,1234,COMM_LMDZ_PHY,error)
1245#endif
1246           ENDIF
1247       
1248           IF (.NOT. is_south_pole_dyn) THEN
1249#ifdef CPP_MPI
1250              CALL MPI_SEND(tmp_calv(1,jj_nb),1,MPI_REAL_LMDZ,mpi_rank+1,1234,COMM_LMDZ_PHY,error)
1251              CALL MPI_RECV(down,1,MPI_REAL_LMDZ,mpi_rank+1,1234,COMM_LMDZ_PHY,status,error)
1252#endif
1253           ENDIF
1254         
1255           IF (.NOT. is_north_pole_dyn .AND. ii_begin /=1) THEN
1256              Up=Up+tmp_calv(nbp_lon,1)
1257              tmp_calv(:,1)=Up
1258           ENDIF
1259           
1260           IF (.NOT. is_south_pole_dyn .AND. ii_end /= nbp_lon) THEN
1261              Down=Down+tmp_calv(1,jj_nb)
1262              tmp_calv(:,jj_nb)=Down
1263           ENDIF
1264        ENDIF
1265        tab_flds(:,:,ids_calvin) = tmp_calv(:,:)
1266
1267      ELSE
1268
1269        DO k=1,nb_zone_calving
1270          calving(k)=0
1271          DO j = 1, jj_nb
1272            calving(k)= calving(k)+DOT_PRODUCT(cpl_rlic2D(:,j)*area_calving(:,j,k),pctsrf2D(:,j,is_lic))
1273          ENDDO
1274        ENDDO
1275      ENDIF
1276     
1277#ifdef CPP_MPI
1278      CALL MPI_ALLREDUCE(calving, calving_glo, nb_zone_calving, MPI_REAL_LMDZ, MPI_SUM, COMM_LMDZ_PHY, error)
1279#endif
1280     
1281      tab_flds(:,:,ids_calvin) = 0
1282      DO k=1,nb_zone_calving
1283        IF (ind_calving(k)>0 ) THEN
1284          j=(ind_calving(k)-1)/nbp_lon + 1
1285          i=MOD(ind_calving(k)-1,nbp_lon)+1
1286          tab_flds(i,j,ids_calvin) = calving_glo(k)
1287        ENDIF
1288      ENDDO
1289
1290!*************************************************************************************
1291! Calculate total flux for snow, rain and wind with weighted addition using the
1292! fractions of ocean and seaice.
1293!
1294!*************************************************************************************   
1295       ! fraction oce+seaice
1296       deno =  pctsrf2D(:,:,is_oce) + pctsrf2D(:,:,is_sic)
1297
1298       IF (version_ocean=='nemo') THEN
1299          tab_flds(:,:,ids_shftot)  = 0.0
1300          tab_flds(:,:,ids_nsftot) = 0.0
1301          tab_flds(:,:,ids_totrai) = 0.0
1302          tab_flds(:,:,ids_totsno) = 0.0
1303          tab_flds(:,:,ids_toteva) = 0.0
1304          tab_flds(:,:,ids_taumod) = 0.0
1305 
1306          tmp_taux(:,:)    = 0.0
1307          tmp_tauy(:,:)    = 0.0
1308          ! For all valid grid cells containing some fraction of ocean or sea-ice
1309          WHERE ( deno(:,:) /= 0 )
1310             tmp_taux = cpl_taux2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1311                  cpl_taux2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1312             tmp_tauy = cpl_tauy2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1313                  cpl_tauy2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1314
1315             tab_flds(:,:,ids_shftot) = cpl_sols2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1316                  cpl_sols2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1317             tab_flds(:,:,ids_nsftot) = cpl_nsol2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1318                  cpl_nsol2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1319             tab_flds(:,:,ids_totrai) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1320                  cpl_rain2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1321             tab_flds(:,:,ids_totsno) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1322                  cpl_snow2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1323             tab_flds(:,:,ids_toteva) = cpl_evap2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1324                  cpl_evap2D(:,:,2)  * pctsrf2D(:,:,is_sic) / deno(:,:)
1325             tab_flds(:,:,ids_taumod) = cpl_taumod2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1326                  cpl_taumod2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1327             
1328         ENDWHERE
1329
1330          tab_flds(:,:,ids_icevap) = cpl_evap2D(:,:,2)
1331         
1332       ELSE IF (version_ocean=='opa8') THEN
1333          ! Store fields for rain and snow in tab_flds(:,:,15) and tab_flds(:,:,16)
1334          tab_flds(:,:,ids_totrai) = 0.0
1335          tab_flds(:,:,ids_totsno) = 0.0
1336          tmp_taux(:,:)    = 0.0
1337          tmp_tauy(:,:)    = 0.0
1338          ! For all valid grid cells containing some fraction of ocean or sea-ice
1339          WHERE ( deno(:,:) /= 0 )
1340             tab_flds(:,:,ids_totrai) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1341                  cpl_rain2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1342             tab_flds(:,:,ids_totsno) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1343                  cpl_snow2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1344             
1345             tmp_taux = cpl_taux2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1346                  cpl_taux2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1347             tmp_tauy = cpl_tauy2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
1348                  cpl_tauy2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
1349          ENDWHERE
1350       ENDIF
1351
1352    ENDIF ! is_omp_root
1353 
1354!*************************************************************************************
1355! Transform the wind components from local atmospheric 2D coordinates to geocentric
1356! 3D coordinates.
1357! Store the resulting wind components in tab_flds(:,:,1:6)
1358!*************************************************************************************
1359
1360! Transform the longitudes and latitudes on 2D arrays
1361   
1362    CALL gather_omp(rlon,rlon_mpi)
1363    CALL gather_omp(rlat,rlat_mpi)
1364!$OMP MASTER
1365    CALL Grid1DTo2D_mpi(rlon_mpi,tmp_lon)
1366    CALL Grid1DTo2D_mpi(rlat_mpi,tmp_lat)
1367!$OMP END MASTER   
1368
1369    IF (is_sequential) THEN
1370       IF (is_north_pole_dyn) tmp_lon(:,1)     = tmp_lon(:,2)
1371       IF (is_south_pole_dyn) tmp_lon(:,nbp_lat) = tmp_lon(:,nbp_lat-1)
1372    ENDIF
1373     
1374! NetCDF output of the wind before transformation of coordinate system
1375    IF (is_sequential) THEN
1376       ndexct(:) = 0
1377       itau_w = itau_phy + itime + start_time * day_step_phy
1378       CALL histwrite(nidct,'tauxe',itau_w,tmp_taux,nbp_lon*(nbp_lat),ndexct)
1379       CALL histwrite(nidct,'tauyn',itau_w,tmp_tauy,nbp_lon*(nbp_lat),ndexct)
1380       CALL histwrite(nidct,'tmp_lon',itau_w,tmp_lon,nbp_lon*(nbp_lat),ndexct)
1381       CALL histwrite(nidct,'tmp_lat',itau_w,tmp_lat,nbp_lon*(nbp_lat),ndexct)
1382    ENDIF
1383
1384! Transform the wind from spherical atmospheric 2D coordinates to geocentric
1385! cartesian 3D coordinates
1386!$OMP MASTER
1387    CALL atm2geo (nbp_lon, jj_nb, tmp_taux, tmp_tauy, tmp_lon, tmp_lat, &
1388         tab_flds(:,:,ids_tauxxu), tab_flds(:,:,ids_tauyyu), tab_flds(:,:,ids_tauzzu) )
1389   
1390    tab_flds(:,:,ids_tauxxv)  = tab_flds(:,:,ids_tauxxu)
1391    tab_flds(:,:,ids_tauyyv)  = tab_flds(:,:,ids_tauyyu)
1392    tab_flds(:,:,ids_tauzzv)  = tab_flds(:,:,ids_tauzzu)
1393!$OMP END MASTER
1394
1395!*************************************************************************************
1396! NetCDF output of all fields just before sending to coupler.
1397!
1398!*************************************************************************************
1399    IF (is_sequential) THEN
1400        DO j=1,maxsend
1401          IF (infosend(j)%action) CALL histwrite(nidct,infosend(j)%name, itau_w, &
1402             tab_flds(:,:,j),nbp_lon*(nbp_lat),ndexct)
1403        ENDDO
1404    ENDIF
1405!*************************************************************************************
1406! Send the table of all fields
1407!
1408!*************************************************************************************
1409    time_sec=(itime-1)*dtime
1410#ifdef CPP_COUPLE
1411!$OMP MASTER
1412    CALL intocpl(time_sec, lafin, tab_flds(:,:,:))
1413!$OMP END MASTER
1414#endif
1415
1416!*************************************************************************************
1417! Finish with some dellocate
1418!
1419!************************************************************************************* 
1420    sum_error=0
1421    DEALLOCATE(cpl_sols2D, cpl_nsol2D, cpl_rain2D, cpl_snow2D, stat=error )
1422    sum_error = sum_error + error
1423    DEALLOCATE(cpl_evap2D, cpl_tsol2D, cpl_fder2D, cpl_albe2D, stat=error )
1424    sum_error = sum_error + error
1425    DEALLOCATE(cpl_taux2D, cpl_tauy2D, cpl_windsp2D, cpl_taumod2D, stat=error )
1426    sum_error = sum_error + error
1427    DEALLOCATE(cpl_sens_rain2D, cpl_sens_snow2D, stat=error)
1428    sum_error = sum_error + error
1429
1430   
1431    IF (carbon_cycle_cpl) THEN
1432       DEALLOCATE(cpl_atm_co22D, stat=error )
1433       sum_error = sum_error + error
1434    ENDIF
1435
1436    IF (sum_error /= 0) THEN
1437       abort_message='Pb in deallocation of cpl_xxxx2D coupling variables'
1438       CALL abort_physic(modname,abort_message,1)
1439    ENDIF
1440   
1441  END SUBROUTINE cpl_send_all
1442!
1443!*************************************************************************************
1444!
1445  SUBROUTINE cpl2gath(champ_in, champ_out, knon, knindex)
1446  USE mod_phys_lmdz_para
1447! Cette routine transforme un champs de la grille 2D recu du coupleur sur la grille
1448! 'gathered' (la grille physiq comprime).
1449!
1450!
1451! input:         
1452!   champ_in     champ sur la grille 2D
1453!   knon         nombre de points dans le domaine a traiter
1454!   knindex      index des points de la surface a traiter
1455!
1456! output:
1457!   champ_out    champ sur la grille 'gatherd'
1458!
1459    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1460
1461! Input
1462    INTEGER, INTENT(IN)                       :: knon
1463    REAL, DIMENSION(nbp_lon,jj_nb), INTENT(IN)    :: champ_in
1464    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
1465
1466! Output
1467    REAL, DIMENSION(klon_mpi), INTENT(OUT)        :: champ_out
1468
1469! Local
1470    INTEGER                                   :: i, ig
1471    REAL, DIMENSION(klon_mpi)                 :: temp_mpi
1472    REAL, DIMENSION(klon)                     :: temp_omp
1473
1474!*************************************************************************************
1475!
1476   
1477
1478! Transform from 2 dimensions (nbp_lon,jj_nb) to 1 dimension (klon)
1479!$OMP MASTER
1480    CALL Grid2Dto1D_mpi(champ_in,temp_mpi)
1481!$OMP END MASTER
1482
1483    CALL scatter_omp(temp_mpi,temp_omp)
1484   
1485! Compress from klon to knon
1486    DO i = 1, knon
1487       ig = knindex(i)
1488       champ_out(i) = temp_omp(ig)
1489    ENDDO
1490
1491  END SUBROUTINE cpl2gath
1492!
1493!*************************************************************************************
1494!
1495  SUBROUTINE gath2cpl(champ_in, champ_out, knon, knindex)
1496  USE mod_phys_lmdz_para
1497! Cette routine ecrit un champ 'gathered' sur la grille 2D pour le passer
1498! au coupleur.
1499!
1500! input:         
1501!   champ_in     champ sur la grille gathere       
1502!   knon         nombre de points dans le domaine a traiter
1503!   knindex      index des points de la surface a traiter
1504!
1505! output:
1506!   champ_out    champ sur la grille 2D
1507!
1508    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1509   
1510! Input arguments
1511!*************************************************************************************
1512    INTEGER, INTENT(IN)                    :: knon
1513    REAL, DIMENSION(klon), INTENT(IN)      :: champ_in
1514    INTEGER, DIMENSION(klon), INTENT(IN)   :: knindex
1515
1516! Output arguments
1517!*************************************************************************************
1518    REAL, DIMENSION(nbp_lon,jj_nb), INTENT(OUT) :: champ_out
1519
1520! Local variables
1521!*************************************************************************************
1522    INTEGER                                :: i, ig
1523    REAL, DIMENSION(klon)                  :: temp_omp
1524    REAL, DIMENSION(klon_mpi)              :: temp_mpi
1525!*************************************************************************************
1526
1527! Decompress from knon to klon
1528    temp_omp = 0.
1529    DO i = 1, knon
1530       ig = knindex(i)
1531       temp_omp(ig) = champ_in(i)
1532    ENDDO
1533
1534! Transform from 1 dimension (klon) to 2 dimensions (nbp_lon,jj_nb)
1535    CALL gather_omp(temp_omp,temp_mpi)
1536
1537!$OMP MASTER   
1538    CALL Grid1Dto2D_mpi(temp_mpi,champ_out)
1539   
1540    IF (is_north_pole_dyn) champ_out(:,1)=temp_mpi(1)
1541    IF (is_south_pole_dyn) champ_out(:,jj_nb)=temp_mpi(klon)
1542!$OMP END MASTER
1543   
1544  END SUBROUTINE gath2cpl
1545!
1546!*************************************************************************************
1547!
1548END MODULE cpl_mod
1549
Note: See TracBrowser for help on using the repository browser.