Ignore:
Timestamp:
Aug 17, 2006, 5:41:51 PM (18 years ago)
Author:
Laurent Fairhead
Message:

Inclusion des modifs de Y. Meurdesoif pour la version V3
LF

File:
1 edited

Legend:

Unmodified
Added
Removed
  • LMDZ4/branches/V3_test/libf/phylmd/interface_surf.F90

    r700 r704  
    2222! L. Fairhead, LMD, 02/2000
    2323
    24   USE ioipsl
     24!ym  USE ioipsl
    2525
    2626  IMPLICIT none
     
    4444! run_off      ruissellement total
    4545  REAL, ALLOCATABLE, DIMENSION(:),SAVE    :: run_off, run_off_lic
     46!$OMP THREADPRIVATE(run_off, run_off_lic)
    4647  real, allocatable, dimension(:),save    :: coastalflow, riverflow
     48!$OMP THREADPRIVATE(coastalflow, riverflow)
    4749!!$PB
    4850  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE :: tmp_rriv, tmp_rcoa,tmp_rlic
     51!$OMP THREADPRIVATE(tmp_rriv, tmp_rcoa,tmp_rlic)
    4952!! pour simuler la fonte des glaciers antarctiques
    5053  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE :: coeff_iceberg
     54!$OMP THREADPRIVATE(coeff_iceberg)
    5155  real, save                              :: surf_maille
     56!$OMP THREADPRIVATE(surf_maille)
    5257  real, save                              :: cte_flux_iceberg = 6.3e7
     58!$OMP THREADPRIVATE(cte_flux_iceberg) 
    5359  integer, save                           :: num_antarctic = 1
     60!$OMP THREADPRIVATE(num_antarctic)
    5461  REAL, save                              :: tau_calv
     62!$OMP THREADPRIVATE(tau_calv)
    5563!!$
    5664  CONTAINS
     
    7583      & evap, fluxsens, fluxlat, dflux_l, dflux_s, &             
    7684      & tsol_rad, tsurf_new, alb_new, alblw, emis_new, &
    77       & z0_new, pctsrf_new, agesno,fqcalving,ffonte, run_off_lic_0,&
     85      & z0_new, pctsrf_new, agesno,fqcalving,fqfonte,ffonte, run_off_lic_0,&
    7886!IM "slab" ocean
    7987      & flux_o, flux_g, tslab, seaice)
    8088
    8189
     90   USE dimphy,only : monocpu,jjphy_nb,omp_rank
    8291! Cette routine sert d'aiguillage entre l'atmosphere et la surface en general
    8392! (sols continentaux, oceans, glaces) pour les fluxs de chaleur et d'humidite.
     
    189198  real, dimension(klon), intent(INOUT) :: tslab
    190199  real, allocatable, dimension(:), save :: tmp_tslab
     200!$OMP THREADPRIVATE(tmp_tslab)
    191201  real, dimension(klon), intent(OUT) :: flux_o, flux_g
    192202  real, dimension(klon), intent(INOUT)        :: seaice ! glace de mer (kg/m2)
    193203  real, dimension(klon)                       :: siceh  ! hauteur glace de mer (m)
    194204  REAL, DIMENSION(klon), INTENT(INOUT) :: radsol,fder
     205 
     206!  real, dimension(klon), intent(IN) :: zmasq
    195207  real, dimension(klon), intent(IN) :: zmasq
    196208  real, dimension(klon), intent(IN) :: taux, tauy, rugos, rugoro
     
    221233!jld a rajouter   real, dimension(klon), intent(INOUT):: ffonte
    222234  real, dimension(klon), intent(INOUT):: ffonte
    223 ! Flux d'eau "perdue" par la surface et nécessaire pour que limiter la
    224 ! hauteur de neige, en kg/m2/s
    225 !jld a rajouter   real, dimension(klon), intent(INOUT):: fqcalving
    226   real, dimension(klon), intent(INOUT):: fqcalving
     235! Flux d'eau "perdue" par la surface et nessaire pour que limiter la
     236! hauteur de neige, en kg/m2/s. Et quantite d'eau de fonte de la calotte.
     237!jld a rajouter   real, dimension(klon), intent(INOUT):: fqcalving, fqfonte
     238  REAL, DIMENSION(klon), INTENT(INOUT):: fqcalving, fqfonte
    227239!IM: "slab" ocean
    228240  real, dimension(klon) :: new_dif_grnd
     
    232244  integer i
    233245  real, allocatable, dimension(:), save :: tmp_flux_o, tmp_flux_g
     246!$OMP THREADPRIVATE(tmp_flux_o, tmp_flux_g) 
    234247  real, allocatable, dimension(:), save :: tmp_radsol
     248!$OMP THREADPRIVATE(tmp_radsol)
    235249  real, allocatable, dimension(:,:), save :: tmp_pctsrf_slab
     250!$OMP THREADPRIVATE(tmp_pctsrf_slab)
    236251  real, allocatable, dimension(:), save :: tmp_seaice
    237 
     252!$OMP THREADPRIVATE(tmp_seaice)
    238253! Local
    239254  character (len = 20),save :: modname = 'interfsurf_hq'
     255!$OMP THREADPRIVATE(modname)
    240256  character (len = 80) :: abort_message
    241257  logical, save        :: first_call = .true.
     258!$OMP THREADPRIVATE(first_call) 
    242259  integer, save        :: error
     260!$OMP THREADPRIVATE(error) 
    243261  integer              :: ii, index
    244   logical,save              :: check = .false.
     262  logical,save              :: check = .true.
     263!$OMP THREADPRIVATE(check) 
    245264  real, dimension(klon):: cal, beta, dif_grnd, capsol
    246265!!$PB  real, parameter      :: calice=1.0/(5.1444e+06*0.15), tau_gl=86400.*5.
     
    258277  real, dimension(klon):: fder_prev
    259278  REAL, dimension(klon) :: bidule
     279  real, dimension(klon) :: ps_tmp,p1lay_tmp
     280  INTEGER :: j
    260281!
    261282!IM ?? quelques variables pour netcdf
     
    308329  ffonte(1:knon)=0.
    309330  fqcalving(1:knon)=0.
     331  fqfonte  (1:knon)=0.
     332
    310333
    311334  cal = 999999. ; beta = 999999. ; dif_grnd = 999999. ; capsol = 999999.
     
    406429
    407430!!$PB
    408       ALLOCATE (tmp_rriv(iim,jjm+1), stat=error)
     431      ALLOCATE (tmp_rriv(iim,jjphy_nb), stat=error)
    409432      if (error /= 0) then
    410433        abort_message='Pb allocation tmp_rriv'
    411434        call abort_gcm(modname,abort_message,1)
    412435      endif
    413       ALLOCATE (tmp_rcoa(iim,jjm+1), stat=error)
     436      tmp_rriv=0.
     437      ALLOCATE (tmp_rcoa(iim,jjphy_nb), stat=error)
    414438      if (error /= 0) then
    415439        abort_message='Pb allocation tmp_rcoa'
    416440        call abort_gcm(modname,abort_message,1)
    417441      endif
    418       ALLOCATE (tmp_rlic(iim,jjm+1), stat=error)
     442      tmp_rcoa=0.
     443!ym      ALLOCATE (tmp_rlic(iim,jjm+1), stat=error)
     444      ALLOCATE (tmp_rlic(iim,jjphy_nb), stat=error)
    419445      if (error /= 0) then
    420446        abort_message='Pb allocation tmp_rlic'
    421447        call abort_gcm(modname,abort_message,1)
    422448      endif
    423       tmp_rriv = 0.0
    424       tmp_rcoa = 0.0
    425       tmp_rlic = 0.0
    426 
     449      tmp_rlic=0.
    427450!!$
    428451    else if (size(coastalflow) /= knon) then
     
    448471     & alb_new, z0_new)
    449472
    450 ! calcul snow et qsurf, hydrol adapté
    451 !
     473! calcul snow et qsurf, hydrol adapt�!
    452474       CALL calbeta(dtime, nisurf, knon, snow, qsol, beta, capsol, dif_grnd)
    453475
     
    473495     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
    474496     &   tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
    475      &   fqcalving,ffonte, run_off_lic_0)
     497     &   fqcalving,fqfonte,ffonte, run_off_lic_0)
    476498
    477499
     
    490512!
    491513#ifdef CPP_VEGET
    492       call interfsol(itime, klon, dtime, date0, nisurf, knon, &
     514      p1lay_tmp(1:knon)=p1lay(1:knon)/100.
     515      ps_tmp(1:knon)=ps(1:knon)/100.
     516 
     517       call interfsol(itime, klon, dtime, date0, nisurf, knon, &
    493518     &  knindex, rlon, rlat, cufi, cvfi, iim, jjm, pctsrf, &
    494519     &  debut, lafin, ok_veget, &
     
    496521     &  tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
    497522     &  precip_rain, precip_snow, sollwdown, swnet, swdown, &
    498      &  tsurf, p1lay/100., ps/100., radsol, &
     523     &  tsurf, p1lay_tmp, ps_tmp, radsol, &
    499524     &  evap, fluxsens, fluxlat, &             
    500525     &  tsol_rad, tsurf_new, alb_new, alblw, &
     
    778803             &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
    779804             &   tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
    780              &   fqcalving,ffonte, run_off_lic_0)
     805             &   fqcalving,fqfonte,ffonte, run_off_lic_0)
    781806
    782807!     calcul albedo
     
    927952     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
    928953     &   tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
    929      &   fqcalving,ffonte, run_off_lic_0)
     954     &   fqcalving,fqfonte,ffonte, run_off_lic_0)
    930955
    931956! passage du run-off des glaciers calcule dans fonte_neige au coupleur
     
    10091034
    10101035  USE intersurf
    1011 
     1036  USE parallel, only : pole_nord,pole_sud
     1037  USE dimphy, klon_x=>klon
     1038  IMPLICIT NONE
    10121039! Cette routine sert d'interface entre le modele atmospherique et le
    10131040! modele de sol continental. Appel a sechiba
     
    11271154! offset pour calculer les point voisins
    11281155  integer, dimension(8,3), save :: off_ini
    1129   integer, dimension(8), save :: offset
    1130 ! Identifieurs des fichiers restart et histoire
     1156 ! Identifieurs des fichiers restart et histoire
    11311157  integer, save          :: rest_id, hist_id
    11321158  integer, save          :: rest_id_stom, hist_id_stom
     
    11441170  integer, dimension(:), save, allocatable :: ig, jg
    11451171  integer :: indi, indj
    1146   integer, dimension(klon) :: ktindex
     1172  integer, save, allocatable,dimension(:) :: ktindex
    11471173  REAL, dimension(klon) :: bidule
    11481174! Essai cdrag
    11491175  real, dimension(klon) :: cdrag
    1150 
     1176  integer :: jjb,jje,ijb,ije
     1177  INTEGER,SAVE :: offset
     1178  REAL, dimension(klon2) :: rlon_g,rlat_g
     1179  INTEGER, SAVE          :: orch_comm
    11511180#include "temps.inc"
    11521181#include "YOMCST.inc"
     
    11561185  if (check) write(lunout,*)'ok_veget = ',ok_veget
    11571186
    1158   ktindex(:) = knindex(:) + iim - 1
    1159 
     1187
     1188 
    11601189! initialisation
     1190 
    11611191  if (debut) then
    1162 
     1192    ALLOCATE(ktindex(klon))
    11631193  IF ( .NOT. allocated(albedo_keep)) THEN
    11641194     ALLOCATE(albedo_keep(klon))
     
    11831213   ig(klon) = 1
    11841214   jg(klon) = jjm + 1
    1185 !
    1186 !  Initialisation des offset   
    1187 !
    1188 ! offset bord ouest
    1189    off_ini(1,1) = - iim  ; off_ini(2,1) = - iim + 1; off_ini(3,1) = 1
    1190    off_ini(4,1) = iim + 1; off_ini(5,1) = iim      ; off_ini(6,1) = 2 * iim - 1
    1191    off_ini(7,1) = iim -1 ; off_ini(8,1) = - 1
    1192 ! offset point normal
    1193    off_ini(1,2) = - iim  ; off_ini(2,2) = - iim + 1; off_ini(3,2) = 1
    1194    off_ini(4,2) = iim + 1; off_ini(5,2) = iim      ; off_ini(6,2) = iim - 1
    1195    off_ini(7,2) = -1     ; off_ini(8,2) = - iim - 1
    1196 ! offset bord   est
    1197    off_ini(1,3) = - iim; off_ini(2,3) = - 2 * iim + 1; off_ini(3,3) = - iim + 1
    1198    off_ini(4,3) =  1   ; off_ini(5,3) = iim          ; off_ini(6,3) = iim - 1
    1199    off_ini(7,3) = -1   ; off_ini(8,3) = - iim - 1
    1200 !
    1201 ! Initialisation des correspondances point -> indices i,j
    1202 !
    1203     if (( .not. allocated(correspond))) then
    1204       allocate(correspond(iim,jjm+1), stat = error)
    1205       if (error /= 0) then
    1206         abort_message='Pb allocation correspond'
    1207         call abort_gcm(modname,abort_message,1)
    1208       endif     
    1209     endif
    1210 !
    1211 ! Attention aux poles
    1212 !
    1213     do igrid = 1, knon
    1214       index = ktindex(igrid)
    1215           jj = int((index - 1)/iim) + 1
    1216           ij = index - (jj - 1) * iim
    1217       correspond(ij,jj) = igrid
    1218     enddo
    1219 
    1220 ! Allouer et initialiser le tableau de coordonnees du sol
    1221 !
     1215
    12221216    if ((.not. allocated(lalo))) then
    12231217      allocate(lalo(knon,2), stat = error)
     
    12471241      lalo(igrid,2) = rlon(index)
    12481242      lalo(igrid,1) = rlat(index)
    1249       ij = index - int((index-1)/iim)*iim - 1
    1250       jj = 2 + int((index-1)/iim)
    1251       if (mod(index,iim) == 1 ) then
    1252         jj = 1 + int((index-1)/iim)
    1253         ij = iim
    1254       endif
    1255 !      lon_scat(ij,jj) = rlon(index)
    1256 !      lat_scat(ij,jj) = rlat(index)
     1243
    12571244    enddo
    1258     index = 1
    1259     do jj = 2, jjm
    1260       do ij = 1, iim
    1261         index = index + 1
    1262         lon_scat(ij,jj) = rlon(index)
    1263         lat_scat(ij,jj) = rlat(index)
     1245   
     1246
     1247   
     1248    Call GatherField(rlon,rlon_g,1)
     1249    Call GatherField(rlat,rlat_g,1)
     1250
     1251    IF (phy_rank==0) THEN
     1252      index = 1
     1253      do jj = 2, jjm
     1254        do ij = 1, iim
     1255          index = index + 1
     1256          lon_scat(ij,jj) = rlon_g(index)
     1257          lat_scat(ij,jj) = rlat_g(index)
     1258        enddo
    12641259      enddo
    1265     enddo
    1266     lon_scat(:,1) = lon_scat(:,2)
    1267     lat_scat(:,1) = rlat(1)
    1268     lon_scat(:,jjm+1) = lon_scat(:,2)
    1269     lat_scat(:,jjm+1) = rlat(klon)
    1270 ! Pb de correspondances de grilles!
    1271 !    do igrid = 1, knon
    1272 !      index = ktindex(igrid)
    1273 !      ij = ig(index)
    1274 !      jj = jg(index)
    1275 !      lon_scat(ij,jj) = rlon(index)
    1276 !      lat_scat(ij,jj) = rlat(index)
    1277 !    enddo
     1260     lon_scat(:,1) = lon_scat(:,2)
     1261     lat_scat(:,1) = rlat_g(1)
     1262     lon_scat(:,jjm+1) = lon_scat(:,2)
     1263     lat_scat(:,jjm+1) = rlat_g(klon2)
     1264   ENDIF
     1265   
    12781266
    12791267!
     
    13011289    enddo
    13021290
    1303     do igrid = 1, knon
    1304       iglob = ktindex(igrid)
    1305       if (mod(iglob, iim) == 1) then
    1306         offset = off_ini(:,1)
    1307       else if(mod(iglob, iim) == 0) then
    1308         offset = off_ini(:,3)
    1309       else
    1310         offset = off_ini(:,2)
    1311       endif
    1312       do i = 1, 8
    1313         index = iglob + offset(i)
    1314         ireal = (min(max(1, index - iim + 1), klon))
    1315         if (pctsrf(ireal, is_ter) > EPSFRA) then
    1316           jj = int((index - 1)/iim) + 1
    1317           ij = index - (jj - 1) * iim
    1318             neighbours(igrid, i) = correspond(ij, jj)
    1319         endif
    1320       enddo
    1321     enddo
     1291
     1292   CALL Init_neighbours(iim,jjm,knon,neighbours,knindex,pctsrf(:,is_ter))
    13221293
    13231294!
     
    13351306      resolution(igrid,2) = cvfi(ij)
    13361307    enddo 
    1337 !IM tester la resolution que recoit Orchidee
    1338     IF((maxval(resolution(:,2)) == 0.).OR. &
    1339    &   (maxval(resolution(:,1)) == 0.)) THEN
    1340      abort_message='STOP interfsol : resolution recue par Orchidee = 0.'
    1341      call abort_gcm(modname,abort_message,1)
    1342     ENDIF
    13431308
    13441309  endif                          ! (fin debut)
     
    13731338! Init Orchidee
    13741339!
     1340!  if (pole_nord) then
     1341!    offset=0
     1342!    ktindex(:)=ktindex(:)+iim-1
     1343!  else
     1344!    offset = klon_begin-1+iim-1
     1345!    ktindex(:)=ktindex(:)+MOD(offset,iim)
     1346!    offset=offset-MOD(offset,iim)
     1347!  endif
     1348 
     1349  PRINT *,'ORCHIDEE ------> KNON : ',knon
     1350 
     1351   
    13751352  if (debut) then
    1376     call intersurf_main (itime+itau_phy-1, iim, jjm+1, knon, ktindex, dtime, &
    1377      & lrestart_read, lrestart_write, lalo, &
    1378      & contfrac, neighbours, resolution, date0, &
    1379      & zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
    1380      & cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
    1381      & precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
    1382      & evap, fluxsens, fluxlat, coastalflow, riverflow, &
    1383      & tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
    1384      & lon_scat, lat_scat)
    1385 
     1353    CALL Get_orchidee_communicator(knon,orch_comm)
     1354    IF (knon /=0) THEN
     1355      CALL Init_orchidee_index(iim,knon,orch_comm,knindex,offset,ktindex)
     1356   
     1357      call intersurf_main (itime+itau_phy-1, iim, jjm+1,offset, knon, ktindex, &
     1358       & orch_comm,dtime, lrestart_read, lrestart_write, lalo, &
     1359       & contfrac, neighbours, resolution, date0, &
     1360       & zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
     1361       & cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
     1362       & precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
     1363       & evap, fluxsens, fluxlat, coastalflow, riverflow, &
     1364       & tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
     1365       & lon_scat, lat_scat)
     1366
     1367     ENDIF
    13861368!IM cf. JP +++
    13871369    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
     
    13911373
    13921374!IM cf. JP +++
    1393 !IM swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
    1394 !IM modification faite dans clmain
    1395     swdown_vrai(1:knon) = swdown(1:knon)
     1375!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
     1376  swdown_vrai(1:knon) = swdown(1:knon)
     1377
    13961378!IM cf. JP ---
    1397 
    1398   call intersurf_main (itime+itau_phy, iim, jjm+1, knon, ktindex, dtime, &
    1399      & lrestart_read, lrestart_write, lalo, &
    1400      & contfrac, neighbours, resolution, date0, &
    1401      & zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
    1402      & cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
    1403      & precip_rain, precip_snow, lwdown, swnet, swdown_vrai, ps, &
    1404      & evap, fluxsens, fluxlat, coastalflow, riverflow, &
    1405      & tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
    1406      & lon_scat, lat_scat)
    1407 
     1379    IF (knon /=0) THEN
     1380   
     1381      call intersurf_main (itime+itau_phy, iim, jjm+1,offset, knon, ktindex, &
     1382       & orch_comm,dtime, lrestart_read, lrestart_write, lalo, &
     1383       & contfrac, neighbours, resolution, date0, &
     1384       & zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
     1385       & cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
     1386       & precip_rain, precip_snow, lwdown, swnet, swdown_vrai, ps, &
     1387       & evap, fluxsens, fluxlat, coastalflow, riverflow, &
     1388       & tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
     1389       & lon_scat, lat_scat)
     1390
     1391    ENDIF
    14081392!IM cf. JP +++
    14091393    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
     
    14121396    bidule=0.
    14131397    bidule(1:knon)=riverflow(1:knon)
    1414     call gath2cpl(bidule, tmp_rriv, klon, knon,iim,jjm,knindex)
     1398    call gath2cpl(bidule, tmp_rriv, klon, knon,iim,jjphy_nb,knindex)
    14151399    bidule=0.
    14161400    bidule(1:knon)=coastalflow(1:knon)
    1417     call gath2cpl(bidule, tmp_rcoa, klon, knon,iim,jjm,knindex)
     1401    call gath2cpl(bidule, tmp_rcoa, klon, knon,iim,jjphy_nb,knindex)
    14181402    alb_new(1:knon) = albedo_out(1:knon,1)
    14191403    alblw(1:knon) = albedo_out(1:knon,2)
     
    14291413
    14301414  END SUBROUTINE interfsol
     1415 
     1416  SUBROUTINE Init_orchidee_index(iim,knon,orch_comm,knindex,offset,ktindex)
     1417  USE dimphy
     1418  IMPLICIT NONE
     1419    INTEGER,INTENT(IN)  :: iim
     1420    INTEGER,INTENT(IN)  :: knon
     1421    INTEGER,INTENT(IN)  :: orch_comm
     1422    INTEGER,INTENT(IN)  :: knindex(knon)
     1423    INTEGER,INTENT(OUT) :: offset
     1424    INTEGER,INTENT(OUT) :: ktindex(knon)
     1425
     1426#ifdef CPP_PARA
     1427    INCLUDE 'mpif.h'
     1428    INTEGER :: status(MPI_STATUS_SIZE)
     1429#endif
     1430    INTEGER :: MyLastPoint
     1431    INTEGER :: LastPoint
     1432    INTEGER :: mpi_rank
     1433    INTEGER :: mpi_size
     1434    INTEGER :: ierr   
     1435   
     1436    MyLastPoint=klon_begin-1+knindex(knon)+iim-1
     1437
     1438    IF (.NOT. monocpu) THEN
     1439#ifdef CPP_PARA   
     1440      call MPI_COMM_SIZE(orch_comm,mpi_size,ierr)
     1441      call MPI_COMM_RANK(orch_comm,mpi_rank,ierr)
     1442#endif
     1443    ELSE
     1444      mpi_rank=0
     1445      mpi_size=1
     1446    ENDIF
     1447   
     1448    IF (.NOT. monocpu) THEN
     1449      IF (mpi_rank /= 0) then
     1450#ifdef CPP_PARA
     1451        CALL MPI_RECV(LastPoint,1,MPI_INTEGER,mpi_rank-1,1234,orch_comm,status,ierr)
     1452#endif
     1453      ENDIF
     1454       
     1455      IF (mpi_rank /= mpi_size-1) THEN
     1456#ifdef CPP_PARA
     1457        CALL MPI_SEND(MyLastPoint,1,MPI_INTEGER,mpi_rank+1,1234,orch_comm,ierr) 
     1458#endif
     1459      ENDIF
     1460    ENDIF
     1461   
     1462    IF (mpi_rank==0) THEN
     1463      offset=0
     1464    ELSE
     1465     offset=LastPoint-MOD(LastPoint,iim)
     1466    ENDIF
     1467     
     1468    ktindex(:)=knindex(:)+(klon_begin+iim-1)-offset-1   
     1469   
     1470
     1471   END SUBROUTINE  Init_orchidee_index
     1472
     1473 
     1474  SUBROUTINE Get_orchidee_communicator(knon,orch_comm)
     1475  USE dimphy, only : phy_rank
     1476  USE parallel, only : COMM_LMDZ
     1477  IMPLICIT NONE
     1478#ifdef CPP_PARA
     1479    include 'mpif.h'
     1480#endif   
     1481    INTEGER,INTENT(IN)  :: knon
     1482    INTEGER,INTENT(OUT) :: orch_comm
     1483   
     1484    INTEGER :: color
     1485    INTEGER :: ierr
     1486   
     1487    IF (knon==0) THEN
     1488      color = 0
     1489    ELSE
     1490      color = 1
     1491    ENDIF
     1492
     1493#ifdef CPP_PARA   
     1494    CALL MPI_COMM_SPLIT(COMM_LMDZ,color,phy_rank,orch_comm,ierr)
     1495#endif
     1496   
     1497  END SUBROUTINE Get_orchidee_communicator
     1498   
     1499   
     1500  SUBROUTINE Init_neighbours(iim,jjm,knon,neighbours,ktindex,pctsrf)
     1501  USE parallel,only : COMM_LMDZ
     1502  USE dimphy
     1503  IMPLICIT NONE
     1504#ifdef CPP_PARA
     1505  include 'mpif.h'
     1506#endif
     1507  INTEGER :: iim,jjm
     1508  INTEGER :: knon
     1509  INTEGER :: neighbours(knon,8)
     1510  INTEGER :: ktindex(knon)
     1511  REAL :: pctsrf(klon)
     1512 
     1513  INTEGER :: knon_nb(0:phy_size-1)
     1514  INTEGER,DIMENSION(0:phy_size-1) :: displs,sendcount
     1515  INTEGER,ALLOCATABLE :: ktindex_g(:)
     1516  REAL*8  :: pctsrf_g(klon2)
     1517  INTEGER,ALLOCATABLE ::neighbours_g(:,:)
     1518  INTEGER :: knon_g
     1519  REAL*8 :: correspond(iim,jjm+1)
     1520  INTEGER :: i,igrid,jj,ij,iglob,ierr,ireal,index
     1521  integer, dimension(8,3) :: off_ini
     1522  integer, dimension(8)   :: offset 
     1523  INTEGER :: ktindex_p(knon)
     1524
     1525  IF (monocpu) THEN
     1526    knon_nb(:)=knon
     1527  ELSE 
     1528
     1529#ifdef CPP_PARA 
     1530    CALL MPI_GATHER(knon,1,MPI_INTEGER,knon_nb,1,MPI_INTEGER,0,COMM_LMDZ,ierr)
     1531#endif
     1532 
     1533  ENDIF
     1534   
     1535  IF (phy_rank==0) THEN
     1536    knon_g=sum(knon_nb(:))
     1537    ALLOCATE(ktindex_g(knon_g))
     1538    ALLOCATE(neighbours_g(knon_g,8))
     1539    neighbours_g(:,:)=-1
     1540    displs(0)=0
     1541    DO i=1,phy_size-1
     1542      displs(i)=displs(i-1)+knon_nb(i-1)
     1543    ENDDO 
     1544  ENDIF
     1545 
     1546  ktindex_p(:)=ktindex(:)+klon_begin-1+iim-1
     1547
     1548  IF (monocpu) THEN
     1549    ktindex_g(:)=ktindex_p(:)
     1550  ELSE
     1551
     1552#ifdef CPP_PARA 
     1553    CALL MPI_GATHERV(ktindex_p,knon,MPI_INTEGER,ktindex_g,knon_nb,displs,MPI_INTEGER,0,COMM_LMDZ,ierr)
     1554#endif
     1555
     1556  ENDIF
     1557     
     1558  CALL GatherField(pctsrf,pctsrf_g,1)
     1559 
     1560  IF (phy_rank==0) THEN
     1561!  Initialisation des offset   
     1562!
     1563! offset bord ouest
     1564   off_ini(1,1) = - iim  ; off_ini(2,1) = - iim + 1; off_ini(3,1) = 1
     1565   off_ini(4,1) = iim + 1; off_ini(5,1) = iim      ; off_ini(6,1) = 2 * iim - 1
     1566   off_ini(7,1) = iim -1 ; off_ini(8,1) = - 1
     1567! offset point normal
     1568   off_ini(1,2) = - iim  ; off_ini(2,2) = - iim + 1; off_ini(3,2) = 1
     1569   off_ini(4,2) = iim + 1; off_ini(5,2) = iim      ; off_ini(6,2) = iim - 1
     1570   off_ini(7,2) = -1     ; off_ini(8,2) = - iim - 1
     1571! offset bord   est
     1572   off_ini(1,3) = - iim; off_ini(2,3) = - 2 * iim + 1; off_ini(3,3) = - iim + 1
     1573   off_ini(4,3) =  1   ; off_ini(5,3) = iim          ; off_ini(6,3) = iim - 1
     1574   off_ini(7,3) = -1   ; off_ini(8,3) = - iim - 1
     1575!
     1576!
     1577! Attention aux poles
     1578!
     1579    do igrid = 1, knon_g
     1580      index = ktindex_g(igrid)
     1581          jj = int((index - 1)/iim) + 1
     1582          ij = index - (jj - 1) * iim
     1583      correspond(ij,jj) = igrid
     1584    enddo
     1585
     1586    do igrid = 1, knon_g
     1587      iglob = ktindex_g(igrid)
     1588      if (mod(iglob, iim) == 1) then
     1589        offset = off_ini(:,1)
     1590      else if(mod(iglob, iim) == 0) then
     1591        offset = off_ini(:,3)
     1592      else
     1593        offset = off_ini(:,2)
     1594      endif
     1595      do i = 1, 8
     1596        index = iglob + offset(i)
     1597        ireal = (min(max(1, index - iim + 1), klon2))
     1598        if (pctsrf_g(ireal) > EPSFRA) then
     1599          jj = int((index - 1)/iim) + 1
     1600          ij = index - (jj - 1) * iim
     1601            neighbours_g(igrid, i) = correspond(ij, jj)
     1602        endif
     1603      enddo
     1604    enddo
     1605
     1606!    DO i=0,phy_size-1
     1607!      displs(i)=displs(i)*8
     1608!      sendcount(i)=knon_nb(i)*8
     1609!    ENDDO
     1610 
     1611  ENDIF
     1612 
     1613  DO i=1,8
     1614    IF (monocpu) THEN
     1615      neighbours(:,i)=neighbours_g(:,i)
     1616    ELSE
     1617#ifdef CPP_PARA
     1618    CALL MPI_SCATTERV(neighbours_g(:,i),knon_nb,displs,MPI_INTEGER,neighbours(:,i),knon,MPI_INTEGER,0,COMM_LMDZ,ierr)
     1619#endif
     1620    ENDIF
     1621  ENDDO
     1622 
     1623  END SUBROUTINE Init_neighbours
    14311624#endif
    14321625!
     
    14451638      & pctsrf_new)
    14461639
     1640   USE ioipsl
     1641   USE dimphy, only : jjphy_nb, iiphy_begin,iiphy_end,phy_rank,phy_size, monocpu
     1642   USE iophy
     1643#ifdef CPP_PARA
     1644   USE parallel, only: pole_nord,pole_sud,COMM_LMDZ
     1645#endif
     1646#ifdef CPP_PSMILE
     1647   USE oasis
     1648#endif
     1649   USE write_field_phy
     1650   implicit none
     1651#include "indicesol.inc"
     1652#include "YOMCST.inc"
    14471653! Cette routine sert d'interface entre le modele atmospherique et un
    14481654! coupleur avec un modele d'ocean 'complet' derriere
     
    14991705!   alb_ice      albedo de la glace
    15001706!
    1501 #ifdef CPP_PSMILE 
    1502   USE oasis
    1503   integer :: il_time_secs !time in seconds
    1504 #endif
     1707
    15051708
    15061709! Parametres d'entree
     
    15601763  REAL, ALLOCATABLE, DIMENSION(:,:,:),SAVE :: tmp_tauy
    15611764! variables a passer au coupleur
    1562   real, dimension(iim, jjm+1) :: wri_sol_ice, wri_sol_sea, wri_nsol_ice
    1563   real, dimension(iim, jjm+1) :: wri_nsol_sea, wri_fder_ice, wri_evap_ice
    1564   REAL, DIMENSION(iim, jjm+1) :: wri_evap_sea, wri_rcoa, wri_rriv
    1565   REAL, DIMENSION(iim, jjm+1) :: wri_rain, wri_snow, wri_taux, wri_tauy
    1566 ! -- LOOP
    1567    REAL, DIMENSION(iim, jjm+1) :: wri_windsp
    1568 ! -- LOOP
    1569   REAL, DIMENSION(iim, jjm+1) :: wri_calv
    1570   REAL, DIMENSION(iim, jjm+1) :: wri_tauxx, wri_tauyy, wri_tauzz
    1571   REAL, DIMENSION(iim, jjm+1) :: tmp_lon, tmp_lat
     1765!ym  real, dimension(iim, jjm+1) :: wri_sol_ice, wri_sol_sea, wri_nsol_ice
     1766!ym  real, dimension(iim, jjm+1) :: wri_nsol_sea, wri_fder_ice, wri_evap_ice
     1767!ym  REAL, DIMENSION(iim, jjm+1) :: wri_evap_sea, wri_rcoa, wri_rriv
     1768!ym  REAL, DIMENSION(iim, jjm+1) :: wri_rain, wri_snow, wri_taux, wri_tauy
     1769!ym  REAL, DIMENSION(iim, jjm+1) :: wri_calv
     1770!ym  REAL, DIMENSION(iim, jjm+1) :: wri_tauxx, wri_tauyy, wri_tauzz
     1771!ym  REAL, DIMENSION(iim, jjm+1) :: tmp_lon, tmp_lat
     1772
     1773  real, dimension(iim, jjphy_nb) :: wri_sol_ice, wri_sol_sea, wri_nsol_ice
     1774  real, dimension(iim, jjphy_nb) :: wri_nsol_sea, wri_fder_ice, wri_evap_ice
     1775  REAL, DIMENSION(iim, jjphy_nb) :: wri_evap_sea, wri_rcoa, wri_rriv
     1776  REAL, DIMENSION(iim, jjphy_nb) :: wri_rain, wri_snow, wri_taux, wri_tauy
     1777  REAL, DIMENSION(iim, jjphy_nb) :: wri_calv
     1778  REAL, DIMENSION(iim, jjphy_nb) :: wri_tauxx, wri_tauyy, wri_tauzz
     1779  REAL, DIMENSION(iim, jjphy_nb) :: tmp_lon, tmp_lat
     1780  REAL, DIMENSION(iim, jjphy_nb) :: wri_windsp
     1781
    15721782! variables relues par le coupleur
    15731783! read_sic = fraction de glace
     
    15801790! l'avoir lu
    15811791  real, allocatable,dimension(:,:),save :: pctsrf_sav
    1582   real, dimension(iim, jjm+1, 2) :: tamp_srf
     1792  real, dimension(iim, jjphy_nb, 3) :: tamp_srf
    15831793  integer, allocatable, dimension(:), save :: tamp_ind
    15841794  real, allocatable, dimension(:,:),save :: tamp_zmasq
    1585   real, dimension(iim, jjm+1) :: deno
     1795  real, dimension(iim, jjphy_nb) :: deno
    15861796  integer                     :: idtime
    15871797  integer, allocatable,dimension(:),save :: unity
     
    16021812  integer :: nb_interf_cpl
    16031813! -- LOOP
     1814
     1815  real :: Up,Down
     1816  integer :: ierr
     1817  integer :: il_time_secs
     1818  real :: tmp_field(klon)
     1819 
    16041820#include "param_cou.h"
    16051821#include "inc_cpl.h"
    16061822#include "temps.inc"
    16071823#include "iniprint.h"
     1824
     1825#ifdef CPP_PARA
     1826  include 'mpif.h'
     1827  integer :: status(MPI_STATUS_SIZE)
     1828#endif
     1829
    16081830!
    16091831! Initialisation
     
    16421864! -- LOOP
    16431865    allocate(cpl_tauy(klon,2), stat = error); sum_error = sum_error + error
    1644     ALLOCATE(cpl_rriv(iim,jjm+1), stat=error); sum_error = sum_error + error
    1645     ALLOCATE(cpl_rcoa(iim,jjm+1), stat=error); sum_error = sum_error + error
    1646     ALLOCATE(cpl_rlic(iim,jjm+1), stat=error); sum_error = sum_error + error
     1866!ym    ALLOCATE(cpl_rriv(iim,jjm+1), stat=error); sum_error = sum_error + error
     1867!ym    ALLOCATE(cpl_rcoa(iim,jjm+1), stat=error); sum_error = sum_error + error
     1868!ym    ALLOCATE(cpl_rlic(iim,jjm+1), stat=error); sum_error = sum_error + error
     1869    ALLOCATE(cpl_rriv(iim,jjphy_nb), stat=error); sum_error = sum_error + error
     1870    ALLOCATE(cpl_rcoa(iim,jjphy_nb), stat=error); sum_error = sum_error + error
     1871    ALLOCATE(cpl_rlic(iim,jjphy_nb), stat=error); sum_error = sum_error + error
     1872
     1873
    16471874!!
    1648     allocate(read_sst(iim, jjm+1), stat = error); sum_error = sum_error + error
    1649     allocate(read_sic(iim, jjm+1), stat = error); sum_error = sum_error + error
    1650     allocate(read_sit(iim, jjm+1), stat = error); sum_error = sum_error + error
    1651     allocate(read_alb_sic(iim, jjm+1), stat = error); sum_error = sum_error + error
    1652 
     1875!ym    allocate(read_sst(iim, jjm+1), stat = error); sum_error = sum_error + error
     1876!ym    allocate(read_sic(iim, jjm+1), stat = error); sum_error = sum_error + error
     1877!ym    allocate(read_sit(iim, jjm+1), stat = error); sum_error = sum_error + error
     1878!ym    allocate(read_alb_sic(iim, jjm+1), stat = error); sum_error = sum_error + error
     1879    allocate(read_sst(iim, jjphy_nb), stat = error); sum_error = sum_error + error
     1880    allocate(read_sic(iim, jjphy_nb), stat = error); sum_error = sum_error + error
     1881    allocate(read_sit(iim, jjphy_nb), stat = error); sum_error = sum_error + error
     1882    allocate(read_alb_sic(iim, jjphy_nb), stat = error); sum_error = sum_error + error
     1883    read_sst=0.
     1884    read_sic=0.
     1885    read_sit=0.
     1886    read_alb_sic=0.
    16531887    if (sum_error /= 0) then
    16541888      abort_message='Pb allocation variables couplees'
     
    16641898    sum_error = 0
    16651899    allocate(tamp_ind(klon), stat = error); sum_error = sum_error + error
    1666     allocate(tamp_zmasq(iim, jjm+1), stat = error); sum_error = sum_error + error   
     1900!ym    allocate(tamp_zmasq(iim, jjm+1), stat = error); sum_error = sum_error + error   
     1901    allocate(tamp_zmasq(iim, jjphy_nb), stat = error); sum_error = sum_error + error   
     1902    tamp_zmasq=1.
     1903   
    16671904    do ig = 1, klon
    16681905      tamp_ind(ig) = ig
    16691906    enddo
    1670     call gath2cpl(zmasq, tamp_zmasq, klon, klon, iim, jjm, tamp_ind)
     1907    call gath2cpl(zmasq, tamp_zmasq, klon, klon, iim, jjphy_nb, tamp_ind)
    16711908!
    16721909! initialisation couplage
     
    16751912#ifdef CPP_COUPLE
    16761913#ifdef CPP_PSMILE
    1677     CALL inicma(iim, (jjm+1))
     1914   CALL inicma(iim, (jjm+1))
    16781915#else
     1916   if (.not. monocpu) then
     1917      abort_message='coupleur parallele uniquement avec PSMILE'
     1918      call abort_gcm(modname,abort_message,1)
     1919   endif
    16791920   call inicma(npas , nexca, idtime,(jjm+1)*iim)
    16801921#endif
     
    16831924! initialisation sorties netcdf
    16841925!
     1926 !ym  IO de check deconnect�pour le moment en //
     1927    IF (monocpu) THEN
    16851928    idayref = day_ini
    16861929    CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
     
    17211964    CALL histsync(nidcs)
    17221965
     1966    ENDIF    ! monocpu
     1967   
    17231968! pour simuler la fonte des glaciers antarctiques
    17241969!
    1725     surf_maille = (4. * rpi * ra**2) / (iim * (jjm +1))
    1726     ALLOCATE(coeff_iceberg(iim,jjm+1), stat=error)
    1727     if (error /= 0) then
    1728       abort_message='Pb allocation variable coeff_iceberg'
    1729       call abort_gcm(modname,abort_message,1)
    1730     endif
    1731     open (12,file='flux_iceberg',form='formatted',status='old')
    1732     read (12,*) coeff_iceberg
    1733     close (12)
    1734     num_antarctic = max(1, count(coeff_iceberg > 0))
     1970!ym => pour le moment, c'est en commentaire, donc je squizze
     1971
     1972!ym    surf_maille = (4. * rpi * ra**2) / (iim * (jjm +1))
     1973!ym    ALLOCATE(coeff_iceberg(iim,jjm+1), stat=error)
     1974!ym    if (error /= 0) then
     1975!ym      abort_message='Pb allocation variable coeff_iceberg'
     1976!ym      call abort_gcm(modname,abort_message,1)
     1977!ym    endif
     1978!ym    open (12,file='flux_iceberg',form='formatted',status='old')
     1979!ym    read (12,*) coeff_iceberg
     1980!ym    close (12)
     1981!ym    num_antarctic = max(1, count(coeff_iceberg > 0))
    17351982   
    17361983    first_appel = .false.
     
    17992046#ifdef CPP_PSMILE
    18002047      il_time_secs=(itime-1)*dtime
    1801       CALL fromcpl(il_time_secs, iim, (jjm+1),                           &
     2048      CALL fromcpl(il_time_secs, iim, jjphy_nb,                           &
    18022049     &        read_sst, read_sic, read_sit, read_alb_sic)
     2050      print *,read_sst
    18032051#else
     2052     if (.not. monocpu) then
     2053        abort_message='coupleur parallele uniquement avec PSMILE'
     2054        call abort_gcm(modname,abort_message,1)
     2055     endif
     2056
    18042057      call fromcpl(itime-1,(jjm+1)*iim,                                  &
    18052058     &        read_sst, read_sic, read_sit, read_alb_sic)
     
    18092062! sorties NETCDF des champs recus
    18102063!
    1811       ndexcs(:)=0
    1812       itau_w = itau_phy + itime
    1813       CALL histwrite(nidcs,cl_read(1),itau_w,read_sst,iim*(jjm+1),ndexcs)
    1814       CALL histwrite(nidcs,cl_read(2),itau_w,read_sic,iim*(jjm+1),ndexcs)
    1815       CALL histwrite(nidcs,cl_read(3),itau_w,read_alb_sic,iim*(jjm+1),ndexcs)
    1816       CALL histwrite(nidcs,cl_read(4),itau_w,read_sit,iim*(jjm+1),ndexcs)
    1817       CALL histsync(nidcs)
     2064!ym       ndexcs(:)=0
     2065!ym       itau_w = itau_phy + itime
     2066!ym       CALL histwrite(nidcs,cl_read(1),itau_w,read_sst,iim*(jjm+1),ndexcs)
     2067!ym       CALL histwrite(nidcs,cl_read(2),itau_w,read_sic,iim*(jjm+1),ndexcs)
     2068!ym       CALL histwrite(nidcs,cl_read(3),itau_w,read_alb_sic,iim*(jjm+1),ndexcs)
     2069!ym       CALL histwrite(nidcs,cl_read(4),itau_w,read_sit,iim*(jjm+1),ndexcs)
     2070!ym       CALL histsync(nidcs)
    18182071! pas utile      IF (npas-itime.LT.nexca )CALL histclo(nidcs)
    18192072
    1820       do j = 1, jjm + 1
    1821         do ig = 1, iim
     2073!ym      do j = 1, jjm + 1
     2074       do j = 1, jjphy_nb
     2075         do ig = 1, iim
    18222076          if (abs(1. - read_sic(ig,j)) < 0.00001) then
    18232077            read_sst(ig,j) = RTT - 1.8
     
    18382092! transformer read_sic en pctsrf_sav
    18392093!
    1840       call cpl2gath(read_sic, tamp_sic , klon, klon,iim,jjm, unity)
     2094      call cpl2gath(read_sic, tamp_sic , klon, klon,iim,jjphy_nb, unity)
    18412095      do ig = 1, klon
    18422096        IF (pctsrf(ig,is_oce) > epsfra .OR.            &
     
    18812135    if (nisurf == is_oce .and. (.not. cumul) ) then
    18822136      sum_error = 0
    1883       allocate(tmp_sols(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1884       allocate(tmp_nsol(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1885       allocate(tmp_rain(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1886       allocate(tmp_snow(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1887       allocate(tmp_evap(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1888       allocate(tmp_tsol(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1889       allocate(tmp_fder(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1890       allocate(tmp_albe(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1891       allocate(tmp_taux(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1892       allocate(tmp_tauy(iim,jjm+1,2), stat=error); sum_error = sum_error + error
    1893 ! -- LOOP
    1894        allocate(tmp_windsp(iim,jjm+1,2), stat=error); sum_error = sum_error + error
     2137      allocate(tmp_sols(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2138      allocate(tmp_nsol(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2139      allocate(tmp_rain(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2140      allocate(tmp_snow(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2141      allocate(tmp_evap(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2142      allocate(tmp_tsol(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2143      allocate(tmp_fder(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2144      allocate(tmp_albe(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2145      allocate(tmp_taux(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2146      allocate(tmp_tauy(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
     2147! -- LOOP
     2148       allocate(tmp_windsp(iim,jjphy_nb,2), stat=error); sum_error = sum_error + error
    18952149! -- LOOP
    18962150!!$      allocate(tmp_rriv(iim,jjm+1,2), stat=error); sum_error = sum_error + error
     
    19072161    cpl_index = 1
    19082162    if (nisurf == is_sic) cpl_index = 2
    1909     call gath2cpl(cpl_sols(1,cpl_index), tmp_sols(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1910     call gath2cpl(cpl_nsol(1,cpl_index), tmp_nsol(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1911     call gath2cpl(cpl_rain(1,cpl_index), tmp_rain(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1912     call gath2cpl(cpl_snow(1,cpl_index), tmp_snow(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1913     call gath2cpl(cpl_evap(1,cpl_index), tmp_evap(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1914     call gath2cpl(cpl_tsol(1,cpl_index), tmp_tsol(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1915     call gath2cpl(cpl_fder(1,cpl_index), tmp_fder(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1916     call gath2cpl(cpl_albe(1,cpl_index), tmp_albe(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1917     call gath2cpl(cpl_taux(1,cpl_index), tmp_taux(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
    1918 ! -- LOOP
    1919      call gath2cpl(cpl_windsp(1,cpl_index), tmp_windsp(1,1,cpl_index), klon, knon,iim,jjm,             knindex)
    1920 ! -- LOOP
    1921     call gath2cpl(cpl_tauy(1,cpl_index), tmp_tauy(1,1,cpl_index), klon, knon,iim,jjm,                  knindex)
     2163    call gath2cpl(cpl_sols(1,cpl_index), tmp_sols(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2164    call gath2cpl(cpl_nsol(1,cpl_index), tmp_nsol(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2165    call gath2cpl(cpl_rain(1,cpl_index), tmp_rain(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2166    call gath2cpl(cpl_snow(1,cpl_index), tmp_snow(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2167    call gath2cpl(cpl_evap(1,cpl_index), tmp_evap(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2168    call gath2cpl(cpl_tsol(1,cpl_index), tmp_tsol(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2169    call gath2cpl(cpl_fder(1,cpl_index), tmp_fder(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2170    call gath2cpl(cpl_albe(1,cpl_index), tmp_albe(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2171    call gath2cpl(cpl_taux(1,cpl_index), tmp_taux(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2172    call gath2cpl(cpl_tauy(1,cpl_index), tmp_tauy(1,1,cpl_index), klon, knon,iim,jjphy_nb,                  knindex)
     2173! -- LOOP
     2174     call gath2cpl(cpl_windsp(1,cpl_index), tmp_windsp(1,1,cpl_index), klon, knon,iim,jjphy_nb,            knindex)
     2175! -- LOOP
    19222176
    19232177!
     
    19302184       wri_windsp = 0.
    19312185! -- LOOP     
    1932       call gath2cpl(pctsrf(1,is_oce), tamp_srf(1,1,1), klon, klon, iim, jjm, tamp_ind)
    1933       call gath2cpl(pctsrf(1,is_sic), tamp_srf(1,1,2), klon, klon, iim, jjm, tamp_ind)
     2186      call gath2cpl(pctsrf(1,is_oce), tamp_srf(1,1,1), klon, klon, iim, jjphy_nb, tamp_ind)
     2187      call gath2cpl(pctsrf(1,is_sic), tamp_srf(1,1,2), klon, klon, iim, jjphy_nb, tamp_ind)
    19342188
    19352189      wri_sol_ice = tmp_sols(:,:,2)
     
    19472201      wri_rriv = cpl_rriv(:,:)
    19482202      wri_rcoa = cpl_rcoa(:,:)
    1949       DO j = 1, jjm + 1
    1950         wri_calv(:,j) = sum(cpl_rlic(:,j)) / iim
    1951       enddo
    1952 
     2203
     2204!ym  !! ATTENTION ICI
     2205     
     2206!ym      DO j = 1, jjm + 1
     2207!ym        wri_calv(:,j) = sum(cpl_rlic(:,j)) / iim
     2208!ym      enddo
     2209
     2210!Essai OM+JLD : ca marche !!!! (17 mars 2006)
     2211      tamp_srf(:,:,3)=0.
     2212      CALL gath2cpl( pctsrf(1,is_lic), tamp_srf(1,1,3), klon, klon, iim, jjphy_nb, tamp_ind)
     2213
     2214!YM pour retrouver resultat avant tamp_srf(:,3)=1.
     2215     
     2216      DO j = 1, jjphy_nb
     2217         wri_calv(:,j) = DOT_PRODUCT (cpl_rlic(1:iim,j), tamp_srf(1:iim,j,3)) / REAL(iim)
     2218      ENDDO
     2219
     2220!ym      wri_calv(:,:)=0.
     2221!ym      DO j = 1, jjphy_nb
     2222!ym        wri_calv(:,j) = sum(cpl_rlic(:,j))/iim
     2223!ym      enddo
     2224
     2225      IF (.NOT. monocpu) THEN
     2226        if (phy_rank /= 0) then
     2227#ifdef CPP_PARA
     2228          call MPI_RECV(Up,1,MPI_REAL8,phy_rank-1,1234,COMM_LMDZ,status,ierr)
     2229          call MPI_SEND(wri_calv(1,1),1,MPI_REAL8,phy_rank-1,1234,COMM_LMDZ,ierr)
     2230#endif
     2231        endif
     2232       
     2233        if (phy_rank /= phy_size-1) then
     2234#ifdef CPP_PARA
     2235          call MPI_SEND(wri_calv(1,jjphy_nb),1,MPI_REAL8,phy_rank+1,1234,COMM_LMDZ,ierr) 
     2236          call MPI_RECV(down,1,MPI_REAL8,phy_rank+1,1234,COMM_LMDZ,status,ierr)
     2237#endif
     2238        endif
     2239       
     2240        if (phy_rank /=0 .and. iiphy_begin /=1) then
     2241          Up=Up+wri_calv(iim,1)
     2242          wri_calv(:,1)=Up
     2243        endif
     2244     
     2245        if (phy_rank /=phy_size-1 .and. iiphy_end /= iim) then
     2246          Down=Down+wri_calv(1,jjphy_nb)
     2247          wri_calv(:,jjphy_nb)=Down     
     2248        endif
     2249      ENDIF
     2250     
    19532251      where (tamp_zmasq /= 1.)
    19542252        deno =  tamp_srf(:,:,1) + tamp_srf(:,:,2)
     
    19692267!      wri_calv = coeff_iceberg * cte_flux_iceberg / (num_antarctic * surf_maille)
    19702268!
    1971 ! on passe les coordonnées de la grille
    1972 !
    1973 
    1974       CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,tmp_lon)
    1975       CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,tmp_lat)
    1976 
    1977       DO i = 1, iim
    1978         tmp_lon(i,1) = rlon(i+1)
    1979         tmp_lon(i,jjm + 1) = rlon(i+1)
    1980       ENDDO
     2269! on passe les coordonn�s de la grille
     2270!
     2271
     2272!ym      CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,tmp_lon)
     2273!ym      CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,tmp_lat)
     2274
     2275      CALL phy2dyn(rlon,tmp_lon,1)
     2276      CALL phy2dyn(rlat,tmp_lat,1)
     2277     
     2278!ym      DO i = 1, iim
     2279!ym        tmp_lon(i,1) = rlon(i+1)
     2280!ym        tmp_lon(i,jjm + 1) = rlon(i+1)
     2281!ym      ENDDO
     2282
    19812283!
    19822284! sortie netcdf des champs pour le changement de repere
    19832285!
    1984       ndexct(:)=0
    1985       CALL histwrite(nidct,'tauxe',itau_w,wri_taux,iim*(jjm+1),ndexct)
    1986       CALL histwrite(nidct,'tauyn',itau_w,wri_tauy,iim*(jjm+1),ndexct)
    1987       CALL histwrite(nidct,'tmp_lon',itau_w,tmp_lon,iim*(jjm+1),ndexct)
    1988       CALL histwrite(nidct,'tmp_lat',itau_w,tmp_lat,iim*(jjm+1),ndexct)
    1989 
    1990 !
    1991 ! calcul 3 coordonnées du vent
    1992 !
    1993       CALL atm2geo (iim , jjm + 1, wri_taux, wri_tauy, tmp_lon, tmp_lat, &
     2286      IF (monocpu) THEN
     2287        ndexct(:)=0
     2288        CALL histwrite(nidct,'tauxe',itau_w,wri_taux,iim*(jjm+1),ndexct)
     2289        CALL histwrite(nidct,'tauyn',itau_w,wri_tauy,iim*(jjm+1),ndexct)
     2290        CALL histwrite(nidct,'tmp_lon',itau_w,tmp_lon,iim*(jjm+1),ndexct)
     2291        CALL histwrite(nidct,'tmp_lat',itau_w,tmp_lat,iim*(jjm+1),ndexct)
     2292      ENDIF 
     2293!
     2294! calcul 3 coordonn�s du vent
     2295!
     2296      CALL atm2geo (iim , jjphy_nb, wri_taux, wri_tauy, tmp_lon, tmp_lat, &
    19942297         & wri_tauxx, wri_tauyy, wri_tauzz )
    19952298!
     
    19972300! envoi au coupleur
    19982301!
     2302    IF (monocpu) THEN
    19992303      CALL histwrite(nidct,cl_writ(8),itau_w,wri_sol_ice,iim*(jjm+1),ndexct)
    20002304      CALL histwrite(nidct,cl_writ(9),itau_w,wri_sol_sea,iim*(jjm+1),ndexct)
     
    20192323! -- LOOP
    20202324      CALL histsync(nidct)
     2325    ENDIF
    20212326! pas utile      IF (lafin) CALL histclo(nidct)
    20222327#ifdef CPP_COUPLE
    20232328#ifdef CPP_PSMILE
    20242329      il_time_secs=(itime-1)*dtime
    2025 
     2330     
    20262331      CALL intocpl(il_time_secs, iim, jjm+1, wri_sol_ice, wri_sol_sea, wri_nsol_ice,&
    20272332      & wri_nsol_sea, wri_fder_ice, wri_evap_ice, wri_evap_sea, wri_rain, &
     
    20802385!
    20812386  if (nisurf == is_oce) then
    2082     call cpl2gath(read_sst, tsurf_new, klon, knon,iim,jjm, knindex)
     2387    call cpl2gath(read_sst, tsurf_new, klon, knon,iim,jjphy_nb, knindex)
    20832388  else if (nisurf == is_sic) then
    2084     call cpl2gath(read_sit, tsurf_new, klon, knon,iim,jjm, knindex)
    2085     call cpl2gath(read_alb_sic, alb_new, klon, knon,iim,jjm, knindex)
     2389    call cpl2gath(read_sit, tsurf_new, klon, knon,iim,jjphy_nb, knindex)
     2390    call cpl2gath(read_alb_sic, alb_new, klon, knon,iim,jjphy_nb, knindex)
    20862391  endif
    20872392  pctsrf_new(:,nisurf) = pctsrf_sav(:,nisurf)
    20882393 
     2394  if (mod(itime, nexca) == -1) then
     2395    tmp_field=0.
     2396    do i = 1, knon
     2397      ig = knindex(i)
     2398      tmp_field(ig) = 1.
     2399    enddo   
     2400    call WriteField_phy('knindex',tmp_field,1)
     2401   
     2402    tmp_field=0.
     2403    do i = 1, knon
     2404      ig = knindex(i)
     2405      tmp_field(ig) = tsurf_new(i)
     2406    enddo   
     2407    call WriteField_phy('tsurf_new',tmp_field,1)
     2408   
     2409    tmp_field=0.
     2410    do i = 1, knon
     2411      ig = knindex(i)
     2412      tmp_field(ig) = alb_new(i)
     2413    enddo   
     2414    call WriteField_phy('alb_new',tmp_field,1)
     2415   
     2416!    tmp_field=0.
     2417!   do i = 1, knon
     2418!      ig = knindex(i)
     2419!      tmp_field(ig) = pctsrf_new(i,nisurf)
     2420 !   enddo   
     2421    call WriteField_phy('pctsrf_new', pctsrf_new(:,nisurf),1)
     2422  endif
     2423!ym  do j=1,jjphy_nb
     2424!ym    do i=1,iim
     2425!ym      print *,phy_rank,'read_sst(',i,',',j,')=',read_sst(i,j)
     2426!ym    enddo
     2427!ym  enddo
     2428 
     2429!ym  do i=1,knon
     2430!ym    print *,phy_rank,'tsurf_new(',i,')=',tsurf_new(i)
     2431!ym  enddo
    20892432!  if (lafin) call quitcpl
    20902433
     
    23162659!
    23172660  SUBROUTINE interfoce_lim(itime, dtime, jour, &
    2318      & klon, nisurf, knon, knindex, &
     2661     & klon_xx, nisurf, knon, knindex, &
    23192662     & debut,  &
    2320      & lmt_sst, pctsrf_new)
     2663     & lmt_sst_p, pctsrf_new_p)
     2664     
     2665     USE dimphy,klon=>klon2,klon2=>klon
     2666
     2667#include "indicesol.inc"
    23212668
    23222669! Cette routine sert d'interface entre le modele atmospherique et un fichier
     
    23452692  real   , intent(IN) :: dtime
    23462693  integer, intent(IN) :: jour
     2694  integer, intent(in) :: klon_xx
    23472695  integer, intent(IN) :: nisurf
    23482696  integer, intent(IN) :: knon
    2349   integer, intent(IN) :: klon
    2350   integer, dimension(klon), intent(in) :: knindex
     2697  integer, dimension(klon2), intent(in) :: knindex
    23512698  logical, intent(IN) :: debut
    23522699
    23532700! Parametres de sortie
    2354   real, intent(out), dimension(klon) :: lmt_sst
    2355   real, intent(out), dimension(klon,nbsrf) :: pctsrf_new
     2701  real, intent(out), dimension(klon2) :: lmt_sst_p
     2702  real, intent(out), dimension(klon2,nbsrf) :: pctsrf_new_p
     2703
     2704!  real, dimension(klon) :: lmt_sst
     2705  real, dimension(klon,nbsrf) :: pctsrf_new
    23562706
    23572707! Variables locales
     
    23592709  INTEGER,save :: lmt_pas     ! frequence de lecture des conditions limites
    23602710                             ! (en pas de physique)
     2711!$OMP THREADPRIVATE(lmt_pas)
    23612712  logical,save :: deja_lu    ! pour indiquer que le jour a lire a deja
    23622713                             ! lu pour une surface precedente
     2714!$OMP THREADPRIVATE(deja_lu)
    23632715  integer,save :: jour_lu
     2716!$OMP THREADPRIVATE(jour_lu)
    23642717  integer      :: ierr
    23652718  character (len = 20) :: modname = 'interfoce_lim'
    23662719  character (len = 80) :: abort_message
    23672720  character (len = 20),save :: fich ='limit.nc'
     2721!$OMP THREADPRIVATE(fich)
    23682722  logical, save     :: newlmt = .TRUE.
     2723!$OMP THREADPRIVATE(newlmt)
    23692724  logical, save     :: check = .FALSE.
     2725!$OMP THREADPRIVATE(check)
    23702726! Champs lus dans le fichier de CL
    2371   real, allocatable , save, dimension(:) :: sst_lu, rug_lu, nat_lu
    2372   real, allocatable , save, dimension(:,:) :: pct_tmp
     2727  real, allocatable , save, dimension(:) :: sst_lu_p
     2728!$OMP THREADPRIVATE(sst_lu_p)
     2729  real, allocatable , save, dimension(:) :: sst_lu_mpi
     2730
     2731  real, allocatable , save, dimension(:,:) :: pct_tmp_p
     2732!$OMP THREADPRIVATE(pct_tmp_p)
     2733  real, allocatable , save, dimension(:,:) :: pct_tmp_mpi
     2734  real, dimension(klon,nbsrf) :: pct_tmp
     2735  real, dimension(klon) :: sst_lu
     2736  real, dimension(klon) :: nat_lu
    23732737!
    23742738! quelques variables pour netcdf
     
    23782742  integer, dimension(2) :: start, epais
    23792743!
    2380 ! Fin déclaration
    2381 !
    2382    
    2383   if (debut .and. .not. allocated(sst_lu)) then
     2744! Fin dlaration
     2745!
     2746 
     2747  if (debut .and. .not. allocated(sst_lu_p)) then
    23842748    lmt_pas = nint(86400./dtime * 1.0) ! pour une lecture une fois par jour
    23852749    jour_lu = jour - 1
    2386     allocate(sst_lu(klon))
    2387     allocate(nat_lu(klon))
    2388     allocate(pct_tmp(klon,nbsrf))
     2750    allocate(sst_lu_p(klon_omp))
     2751    allocate(pct_tmp_p(klon_omp,nbsrf))
    23892752  endif
    23902753
     
    23992762! Ouverture du fichier
    24002763!
     2764!$OMP MASTER
     2765    if (.not. allocated(sst_lu_mpi)) allocate(sst_lu_mpi(klon_mpi))
     2766    if (.not. allocated(pct_tmp_mpi)) allocate(pct_tmp_mpi(klon_mpi,nbsrf))
     2767   
     2768    if (phy_rank==0) then
     2769   
    24012770    fich = trim(fich)
    24022771    ierr = NF_OPEN (fich, NF_NOWRITE,nid)
     
    25382907!
    25392908    ierr = NF_CLOSE(nid)
    2540     deja_lu = .true.
    2541     jour_lu = jour
    2542   endif
     2909   endif ! phyrank
    25432910!
    25442911! Recopie des variables dans les champs de sortie
    25452912!
    2546   lmt_sst = 999999999.
     2913  call ScatterField(sst_lu,sst_lu_mpi,1)
     2914  call ScatterField(pct_tmp(:,is_oce),pct_tmp_mpi(:,is_oce),1)
     2915  call ScatterField(pct_tmp(:,is_sic),pct_tmp_mpi(:,is_sic),1)
     2916!$OMP END MASTER
     2917!$OMP BARRIER
     2918  call ScatterField_omp(sst_lu_mpi,sst_lu_p,1)
     2919  call ScatterField_omp(pct_tmp_mpi(:,is_oce),pct_tmp_p(:,is_oce),1)
     2920  call ScatterField_omp(pct_tmp_mpi(:,is_sic),pct_tmp_p(:,is_sic),1)
     2921   deja_lu = .true.
     2922   jour_lu = jour
     2923  endif   
     2924 
     2925  lmt_sst_p = 999999999.
     2926 
    25472927  do ii = 1, knon
    2548     lmt_sst(ii) = sst_lu(knindex(ii))
     2928    lmt_sst_p(ii) = sst_lu_p(knindex(ii))
    25492929  enddo
    25502930
    2551   pctsrf_new(:,is_oce) = pct_tmp(:,is_oce)
    2552   pctsrf_new(:,is_sic) = pct_tmp(:,is_sic)
     2931  do ii=1,klon2
     2932    pctsrf_new_p(ii,is_oce)=pct_tmp_p(ii,is_oce)
     2933    pctsrf_new_p(ii,is_sic)=pct_tmp_p(ii,is_sic)
     2934  enddo
     2935 
    25532936
    25542937  END SUBROUTINE interfoce_lim
     
    25582941!
    25592942  SUBROUTINE interfsur_lim(itime, dtime, jour, &
    2560      & klon, nisurf, knon, knindex, &
     2943     & klon_xx, nisurf, knon, knindex, &
    25612944     & debut,  &
    2562      & lmt_alb, lmt_rug)
     2945     & lmt_alb_p, lmt_rug_p)
     2946
     2947     USE dimphy,klon=>klon2,klon2=>klon
    25632948
    25642949! Cette routine sert d'interface entre le modele atmospherique et un fichier
     
    25802965!   lmt_sst      SST lues dans le fichier de CL
    25812966!   lmt_alb      Albedo lu
    2582 !   lmt_rug      longueur de rugosité lue
     2967!   lmt_rug      longueur de rugositlue
    25832968!   pctsrf_new   sous-maille fractionnelle
    25842969!
     
    25912976  integer, intent(IN) :: nisurf
    25922977  integer, intent(IN) :: knon
    2593   integer, intent(IN) :: klon
    2594   integer, dimension(klon), intent(in) :: knindex
     2978  integer, intent(IN) :: klon_xx
     2979  integer, dimension(klon2), intent(in) :: knindex
    25952980  logical, intent(IN) :: debut
    25962981
    25972982! Parametres de sortie
    2598   real, intent(out), dimension(klon) :: lmt_alb
    2599   real, intent(out), dimension(klon) :: lmt_rug
     2983  real, intent(out), dimension(klon2) :: lmt_alb_p
     2984  real, intent(out), dimension(klon2) :: lmt_rug_p
     2985
     2986!  real,  dimension(klon) :: lmt_alb
     2987!  real,  dimension(klon) :: lmt_rug
    26002988
    26012989! Variables locales
     
    26032991  integer,save :: lmt_pas     ! frequence de lecture des conditions limites
    26042992                             ! (en pas de physique)
     2993!$OMP THREADPRIVATE(lmt_pas)
    26052994  logical,save :: deja_lu_sur! pour indiquer que le jour a lire a deja
    26062995                             ! lu pour une surface precedente
     2996!$OMP THREADPRIVATE(deja_lu_sur)
    26072997  integer,save :: jour_lu_sur
     2998!$OMP THREADPRIVATE(jour_lu_sur)
    26082999  integer      :: ierr
    26093000  character (len = 20) :: modname = 'interfsur_lim'
    26103001  character (len = 80) :: abort_message
    26113002  character (len = 20),save :: fich ='limit.nc'
     3003!$OMP THREADPRIVATE(fich)
    26123004  logical,save     :: newlmt = .false.
     3005!$OMP THREADPRIVATE(newlmt)
    26133006  logical,save     :: check = .false.
     3007!$OMP THREADPRIVATE(check)
    26143008! Champs lus dans le fichier de CL
    2615   real, allocatable , save, dimension(:) :: alb_lu, rug_lu
     3009  real, allocatable , save, dimension(:) :: alb_lu_p, rug_lu_p
     3010!$OMP THREADPRIVATE(alb_lu_p, rug_lu_p)
     3011  real, allocatable , save, dimension(:) :: alb_lu_mpi, rug_lu_mpi
     3012  real, dimension(klon) :: alb_lu, rug_lu
    26163013!
    26173014! quelques variables pour netcdf
     
    26193016#include "netcdf.inc"
    26203017  integer ,save             :: nid, nvarid
     3018!$OMP THREADPRIVATE(nid, nvarid)
    26213019  integer, dimension(2),save :: start, epais
    2622 !
    2623 ! Fin déclaration
    2624 !
    2625    
     3020!$OMP THREADPRIVATE(start, epais)
     3021!
     3022! Fin d�laration
     3023!
     3024 
    26263025  if (debut) then
    26273026    lmt_pas = nint(86400./dtime * 1.0) ! pour une lecture une fois par jour
    26283027    jour_lu_sur = jour - 1
    2629     allocate(alb_lu(klon))
    2630     allocate(rug_lu(klon))
     3028    allocate(alb_lu_p(klon_omp))
     3029    allocate(rug_lu_p(klon_omp))
    26313030  endif
    26323031
     
    26393038! Tester d'abord si c'est le moment de lire le fichier
    26403039  if (mod(itime-1, lmt_pas) == 0 .and. .not. deja_lu_sur) then
     3040
     3041!$OMP MASTER
     3042    if (.not. allocated(alb_lu_mpi)) allocate(alb_lu_mpi(klon_mpi))
     3043    if (.not. allocated(rug_lu_mpi)) allocate(rug_lu_mpi(klon_mpi)) 
     3044  if (phy_rank==0) then
    26413045!
    26423046! Ouverture du fichier
     
    26753079    endif
    26763080!
    2677 ! Lecture rugosité
    2678 !
     3081! Lecture rugosit�!
    26793082    ierr = NF_INQ_VARID(nid, 'RUG', nvarid)
    26803083    if (ierr /= NF_NOERR) then
     
    26963099!
    26973100    ierr = NF_CLOSE(nid)
     3101
     3102
     3103  endif  !! phyrank
     3104
     3105    call ScatterField(alb_lu,alb_lu_mpi,1)
     3106    call ScatterField(rug_lu,rug_lu_mpi,1)
     3107!$OMP END MASTER
     3108!$OMP BARRIER
     3109
     3110    call ScatterField_omp(alb_lu_mpi,alb_lu_p,1)
     3111    call ScatterField_omp(rug_lu_mpi,rug_lu_p,1)
     3112   
    26983113    deja_lu_sur = .true.
    26993114    jour_lu_sur = jour
     3115
     3116
    27003117  endif
     3118 
    27013119!
    27023120! Recopie des variables dans les champs de sortie
     
    27043122!!$  lmt_alb(:) = 0.0
    27053123!!$  lmt_rug(:) = 0.0
    2706   lmt_alb(:) = 999999.
    2707   lmt_rug(:) = 999999.
     3124 
     3125  lmt_alb_p(:) = 999999.
     3126  lmt_rug_p(:) = 999999.
    27083127  DO ii = 1, knon
    2709     lmt_alb(ii) = alb_lu(knindex(ii))
    2710     lmt_rug(ii) = rug_lu(knindex(ii))
     3128    lmt_alb_p(ii) = alb_lu_p(knindex(ii))
     3129    lmt_rug_p(ii) = rug_lu_p(knindex(ii))
    27113130  enddo
     3131
    27123132
    27133133  END SUBROUTINE interfsur_lim
     
    27233143     & petAcoef, peqAcoef, petBcoef, peqBcoef, &
    27243144     & tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
    2725 
     3145     USE dimphy,only : omp_rank
    27263146! Cette routine calcule les fluxs en h et q a l'interface et eventuellement
    27273147! une temperature de surface (au cas ou ok_veget = false)
     
    27613181#include "FCTTRE.inc"
    27623182#include "indicesol.inc"
     3183#include "YOMCST.inc"
    27633184
    27643185! Parametres d'entree
     
    27943215!
    27953216  logical, save         :: check = .false.
     3217!$OMP THREADPRIVATE(check)
    27963218  character (len = 20)  :: modname = 'calcul_fluxs'
    27973219  logical, save         :: fonte_neige = .false.
     3220!$OMP THREADPRIVATE(fonte_neige)
    27983221  real, save            :: max_eau_sol = 150.0
     3222!$OMP THREADPRIVATE(max_eau_sol)
    27993223  character (len = 80) :: abort_message
    28003224  logical,save         :: first = .true.,second=.false.
     3225!$OMP THREADPRIVATE(first,second)
    28013226
    28023227  if (check) write(*,*)'Entree ', modname,' surface = ',nisurf
     
    29513376!#########################################################################
    29523377!
    2953   SUBROUTINE gath2cpl(champ_in, champ_out, klon, knon, iim, jjm, knindex)
    2954 
     3378  SUBROUTINE gath2cpl(champ_in, champ_out, klon, knon, iim, jmp1, knindex)
     3379  use dimphy, only: liste_i,liste_j,jjphy_begin,jjphy_nb,phy_rank,phy_size
     3380  implicit none
     3381 
    29553382! Cette routine ecrit un champ 'gathered' sur la grille 2D pour le passer
    29563383! au coupleur.
     
    29683395!
    29693396! input
    2970   integer                   :: klon, knon, iim, jjm
     3397  integer                   :: klon, knon, iim, jmp1
    29713398  real, dimension(klon)     :: champ_in
    29723399  integer, dimension(klon)  :: knindex
    29733400! output
    2974   real, dimension(iim,jjm+1)  :: champ_out
     3401  real, dimension(iim,jmp1)  :: champ_out
    29753402! local
    29763403  integer                   :: i, ig, j
     
    29823409    tamp(ig) = champ_in(i)
    29833410  enddo   
    2984   ig = 1
    2985   champ_out(:,1) = tamp(ig)
    2986   do j = 2, jjm
    2987     do i = 1, iim
    2988       ig = ig + 1
    2989       champ_out(i,j) = tamp(ig)
    2990     enddo
     3411
     3412!ym  ig = 1
     3413!ym  champ_out(:,1) = tamp(ig)
     3414!ym  do j = 2, jjm
     3415!ym    do i = 1, iim
     3416!ym      ig = ig + 1
     3417!ym      champ_out(i,j) = tamp(ig)
     3418!ym    enddo
     3419!ym  enddo
     3420!ym  ig = ig + 1
     3421!ym  champ_out(:,jjm+1) = tamp(ig)
     3422
     3423  do ig=1,klon
     3424    i=liste_i(ig)
     3425    j=liste_j(ig)-jjphy_begin+1
     3426    champ_out(i,j)=tamp(ig)
    29913427  enddo
    2992   ig = ig + 1
    2993   champ_out(:,jjm+1) = tamp(ig)
     3428 
     3429  if (phy_rank==0) champ_out(:,1)=tamp(1)
     3430  if (phy_rank==phy_size-1) champ_out(:,jjphy_nb)=tamp(klon)
    29943431
    29953432  END SUBROUTINE gath2cpl
     
    29973434!#########################################################################
    29983435!
    2999   SUBROUTINE cpl2gath(champ_in, champ_out, klon, knon, iim, jjm, knindex)
    3000 
     3436  SUBROUTINE cpl2gath(champ_in, champ_out, klon, knon, iim, jmp1, knindex)
     3437  use dimphy, only : liste_i, liste_j, jjphy_begin
     3438  implicit none
    30013439! Cette routine ecrit un champ 'gathered' sur la grille 2D pour le passer
    30023440! au coupleur.
     
    30143452!
    30153453! input
    3016   integer                   :: klon, knon, iim, jjm
    3017   real, dimension(iim,jjm+1)     :: champ_in
     3454  integer                   :: klon, knon, iim, jmp1
     3455  real, dimension(iim,jmp1)     :: champ_in
    30183456  integer, dimension(klon)  :: knindex
    30193457! output
     
    30243462  logical ,save                  :: check = .false.
    30253463
    3026   ig = 1
    3027   tamp(ig) = champ_in(1,1)
    3028   do j = 2, jjm
    3029     do i = 1, iim
    3030       ig = ig + 1
    3031       tamp(ig) = champ_in(i,j)
    3032     enddo
     3464!ym  ig = 1
     3465!ym  tamp(ig) = champ_in(1,1)
     3466!ym  do j = 2, jjm
     3467!ym    do i = 1, iim
     3468!ym      ig = ig + 1
     3469!ym      tamp(ig) = champ_in(i,j)
     3470!ym    enddo
     3471!ym  enddo
     3472!ym  ig = ig + 1
     3473!ym  tamp(ig) = champ_in(1,jjm+1)
     3474
     3475  do ig=1,klon
     3476   i=liste_i(ig)
     3477   j=liste_j(ig)-jjphy_begin+1
     3478   tamp(ig)=champ_in(i,j)
    30333479  enddo
    3034   ig = ig + 1
    3035   tamp(ig) = champ_in(1,jjm+1)
    3036 
     3480 
    30373481  do i = 1, knon
    30383482    ig = knindex(i)
     
    30563500 
    30573501  REAL, DIMENSION(nvm),SAVE :: init, decay
     3502!$OMP THREADPRIVATE(init, decay)
    30583503  REAL :: as
    30593504  DATA init /0.55, 0.14, 0.18, 0.29, 0.15, 0.15, 0.14, 0./
     
    30913536     & petAcoef, peqAcoef, petBcoef, peqBcoef, &
    30923537     & tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
    3093      & fqcalving,ffonte,run_off_lic_0)
     3538     & fqcalving,fqfonte,ffonte,run_off_lic_0)
    30943539
    30953540! Routine de traitement de la fonte de la neige dans le cas du traitement
    3096 ! de sol simplifié
    3097 !
     3541! de sol simplifi�!
    30983542! LF 03/2001
    30993543! input:
     
    31253569!   dflux_l      derivee du flux de chaleur latente  / Ts
    31263570! in/out:
    3127 !   run_off_lic_0 run off glacier du pas de temps précedent
     3571!   run_off_lic_0 run off glacier du pas de temps predent
    31283572!
    31293573
     
    31513595! Flux thermique utiliser pour fondre la neige
    31523596  real, dimension(klon), intent(INOUT):: ffonte
    3153 ! Flux d'eau "perdue" par la surface et necessaire pour que limiter la
    3154 ! hauteur de neige, en kg/m2/s
    3155   real, dimension(klon), intent(INOUT):: fqcalving
     3597! Flux d'eau "perdu" par la surface et necessaire pour que limiter la
     3598! hauteur de neige, en kg/m2/s. Et flux d'eau de fonte de la calotte.
     3599  REAL, DIMENSION(klon), INTENT(INOUT):: fqcalving, fqfonte
    31563600  real, dimension(klon), intent(INOUT):: run_off_lic_0
    31573601! Variables locales
     
    31803624!
    31813625  logical, save         :: check = .FALSE.
     3626!$OMP THREADPRIVATE(check)
    31823627  character (len = 20)  :: modname = 'fonte_neige'
    31833628  logical, save         :: neige_fond = .false.
     3629!$OMP THREADPRIVATE(neige_fond)
    31843630  real, save            :: max_eau_sol = 150.0
     3631!$OMP THREADPRIVATE(max_eau_sol)
    31853632  character (len = 80) :: abort_message
    31863633  logical,save         :: first = .true.,second=.false.
     3634!$OMP THREADPRIVATE(first,second)
    31873635  real                 :: coeff_rel
    31883636#include "FCTTRE.inc"
     
    32743722      fq_fonte = MIN( MAX((tsurf_new(i)-RTT )/chasno,0.0),snow(i))
    32753723      ffonte(i) = fq_fonte * RLMLT/dtime
     3724      fqfonte(i) = fq_fonte/dtime
    32763725      snow(i) = max(0., snow(i) - fq_fonte)
    32773726      bil_eau_s(i) = bil_eau_s(i) + fq_fonte
     
    32823731        fq_fonte = MAX((tsurf_new(i)-RTT )/chaice,0.0)
    32833732        ffonte(i) = ffonte(i) + fq_fonte * RLMLT/dtime
    3284         bil_eau_s(i) = bil_eau_s(i) + fq_fonte
     3733        IF ( ok_lic_melt ) THEN
     3734           fqfonte(i) = fqfonte(i) + fq_fonte/dtime
     3735           bil_eau_s(i) = bil_eau_s(i) + fq_fonte
     3736        ENDIF
    32853737        tsurf_new(i) = RTT
    32863738      ENDIF
     
    33003752 &                        (1. - coeff_rel) * run_off_lic_0(i)
    33013753      run_off_lic_0(i) = run_off_lic(i)
    3302       run_off_lic(i) = run_off_lic(i) + bil_eau_s(i)/dtime
     3754      run_off_lic(i) = run_off_lic(i) + fqfonte(i)/dtime
    33033755    endif
    33043756  enddo
Note: See TracChangeset for help on using the changeset viewer.