source: LMDZ5/trunk/libf/phylmd/iophy.F90 @ 2957

Last change on this file since 2957 was 2856, checked in by oboucher, 8 years ago

One more small omission for previous two commits

  • 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: 45.3 KB
RevLine 
[879]1!
[1897]2! $Id: iophy.F90 2856 2017-04-14 14:49:58Z jbmadeleine $
[879]3!
[1807]4MODULE iophy
5
[1797]6! abd  REAL,private,allocatable,DIMENSION(:),save :: io_lat
7! abd  REAL,private,allocatable,DIMENSION(:),save :: io_lon
[1791]8  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lat
9  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lon
10  INTEGER, SAVE :: phys_domain_id
11  INTEGER, SAVE :: npstn
12  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE :: nptabij
13  INTEGER, SAVE :: itau_iophy
14
15!$OMP THREADPRIVATE(itau_iophy)
[1852]16
17#ifdef CPP_XIOS
[629]18  INTERFACE histwrite_phy
[2660]19!#ifdef CPP_XIOSnew
[2645]20    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios,histwrite0d_xios
[2660]21!#else
22!    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios
23!#endif
24
[1852]25  END INTERFACE
26#else
27  INTERFACE histwrite_phy
[1791]28    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old
[1001]29  END INTERFACE
[1852]30#endif
[629]31
[1539]32  INTERFACE histbeg_phy_all
[1825]33    MODULE PROCEDURE histbeg_phy,histbeg_phyxios,histbeg_phy_points
[1539]34  END INTERFACE
[1001]35
[1539]36
[1797]37CONTAINS
[629]38
[1797]39! ug Routine pour définir itau_iophy depuis phys_output_write_mod:
40  SUBROUTINE set_itau_iophy(ito)
41      IMPLICIT NONE
42      INTEGER, INTENT(IN) :: ito
43      itau_iophy = ito
44  END SUBROUTINE
45
46  SUBROUTINE init_iophy_new(rlat,rlon)
[2854]47  USE dimphy, ONLY: klon
48  USE mod_phys_lmdz_para, ONLY: gather, bcast, &
[1897]49                                jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
50                                mpi_size, mpi_rank, klon_mpi, &
[2429]51                                is_sequential, is_south_pole_dyn
[2854]52  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
[2319]53  USE print_control_mod, ONLY: prt_level,lunout
[1897]54#ifdef CPP_IOIPSL
[2854]55  USE ioipsl, ONLY: flio_dom_set
[1897]56#endif
57#ifdef CPP_XIOS
[2854]58  USE wxios, ONLY: wxios_domain_param
[1897]59#endif
[1797]60  IMPLICIT NONE
61    REAL,DIMENSION(klon),INTENT(IN) :: rlon
62    REAL,DIMENSION(klon),INTENT(IN) :: rlat
[1001]63
[1797]64    REAL,DIMENSION(klon_glo)        :: rlat_glo
65    REAL,DIMENSION(klon_glo)        :: rlon_glo
[1001]66   
67    INTEGER,DIMENSION(2) :: ddid
68    INTEGER,DIMENSION(2) :: dsg
69    INTEGER,DIMENSION(2) :: dsl
70    INTEGER,DIMENSION(2) :: dpf
71    INTEGER,DIMENSION(2) :: dpl
72    INTEGER,DIMENSION(2) :: dhs
73    INTEGER,DIMENSION(2) :: dhe
74    INTEGER :: i   
[1852]75    INTEGER :: data_ibegin, data_iend
[1001]76
77    CALL gather(rlat,rlat_glo)
78    CALL bcast(rlat_glo)
79    CALL gather(rlon,rlon_glo)
80    CALL bcast(rlon_glo)
81   
82!$OMP MASTER 
[2350]83    ALLOCATE(io_lat(nbp_lat))
84    IF (klon_glo == 1) THEN
85      io_lat(1)=rlat_glo(1)
86    ELSE
87      io_lat(1)=rlat_glo(1)
88      io_lat(nbp_lat)=rlat_glo(klon_glo)
[2344]89      DO i=2,nbp_lat-1
90        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
[1001]91      ENDDO
92    ENDIF
93
[2344]94    ALLOCATE(io_lon(nbp_lon))
95    IF (klon_glo == 1) THEN
96      io_lon(1)=rlon_glo(1)
97    ELSE
98      io_lon(1:nbp_lon)=rlon_glo(2:nbp_lon+1)
99    ENDIF
100
[1852]101!! (I) dtnb   : total number of domains
102!! (I) dnb    : domain number
103!! (I) did(:) : distributed dimensions identifiers
104!!              (up to 5 dimensions are supported)
105!! (I) dsg(:) : total number of points for each dimension
106!! (I) dsl(:) : local number of points for each dimension
107!! (I) dpf(:) : position of first local point for each dimension
108!! (I) dpl(:) : position of last local point for each dimension
109!! (I) dhs(:) : start halo size for each dimension
110!! (I) dhe(:) : end halo size for each dimension
111!! (C) cdnm   : Model domain definition name.
112!!              The names actually supported are :
113!!              "BOX", "APPLE", "ORANGE".
114!!              These names are case insensitive.
[1001]115
116    ddid=(/ 1,2 /)
[2344]117    dsg=(/ nbp_lon, nbp_lat /)
118    dsl=(/ nbp_lon, jj_nb /)
[1001]119    dpf=(/ 1,jj_begin /)
[2344]120    dpl=(/ nbp_lon, jj_end /)
[1001]121    dhs=(/ ii_begin-1,0 /)
[1797]122    IF (mpi_rank==mpi_size-1) THEN
[1001]123      dhe=(/0,0/)
[1797]124    ELSE
[2344]125      dhe=(/ nbp_lon-ii_end,0 /) 
[1797]126    ENDIF
[1852]127
[2097]128#ifndef CPP_IOIPSL_NO_OUTPUT   
[1797]129    CALL flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
[1001]130                      'APPLE',phys_domain_id)
[1852]131#endif
[1825]132#ifdef CPP_XIOS
[1897]133    ! Set values for the mask:
[1852]134    IF (mpi_rank == 0) THEN
135        data_ibegin = 0
136    ELSE
137        data_ibegin = ii_begin - 1
[2854]138    ENDIF
[1852]139
140    IF (mpi_rank == mpi_size-1) THEN
141        data_iend = nbp_lon
142    ELSE
143        data_iend = ii_end + 1
[2854]144    ENDIF
[1852]145
[2854]146    IF (prt_level>=10) THEN
[1897]147      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
148      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
149      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
150      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
[2429]151      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
[2854]152    ENDIF
[1852]153
[1897]154    ! Initialize the XIOS domain coreesponding to this process:
[1852]155    CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
156                            1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
157                            klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
[2429]158                            io_lat, io_lon,is_south_pole_dyn,mpi_rank)
[1825]159#endif
[1001]160!$OMP END MASTER
161     
[1797]162  END SUBROUTINE init_iophy_new
[1001]163
[1797]164  SUBROUTINE init_iophy(lat,lon)
[2854]165  USE mod_phys_lmdz_para, ONLY: jj_begin, jj_end, ii_begin, ii_end, jj_nb, &
[1897]166                                mpi_size, mpi_rank
[2854]167  USE ioipsl, ONLY: flio_dom_set
[2344]168  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1797]169  IMPLICIT NONE
[2344]170    REAL,DIMENSION(nbp_lon),INTENT(IN) :: lon
171    REAL,DIMENSION(nbp_lat),INTENT(IN) :: lat
[766]172
173    INTEGER,DIMENSION(2) :: ddid
174    INTEGER,DIMENSION(2) :: dsg
175    INTEGER,DIMENSION(2) :: dsl
176    INTEGER,DIMENSION(2) :: dpf
177    INTEGER,DIMENSION(2) :: dpl
178    INTEGER,DIMENSION(2) :: dhs
179    INTEGER,DIMENSION(2) :: dhe
180
181!$OMP MASTER 
[2854]182    ALLOCATE(io_lat(nbp_lat))
[629]183    io_lat(:)=lat(:)
[2854]184    ALLOCATE(io_lon(nbp_lon))
[629]185    io_lon(:)=lon(:)
[1331]186   
[766]187    ddid=(/ 1,2 /)
[2344]188    dsg=(/ nbp_lon, nbp_lat /)
189    dsl=(/ nbp_lon, jj_nb /)
[776]190    dpf=(/ 1,jj_begin /)
[2344]191    dpl=(/ nbp_lon, jj_end /)
[776]192    dhs=(/ ii_begin-1,0 /)
[2854]193    IF (mpi_rank==mpi_size-1) THEN
[766]194      dhe=(/0,0/)
[2854]195    ELSE
[2344]196      dhe=(/ nbp_lon-ii_end,0 /) 
[2854]197    ENDIF
[766]198   
[2097]199#ifndef CPP_IOIPSL_NO_OUTPUT
[776]200    call flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
[766]201                      'APPLE',phys_domain_id)
[1852]202#endif
[766]203!$OMP END MASTER
204     
[2854]205  END SUBROUTINE init_iophy
[1825]206
207 SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
[1897]208!  USE dimphy
[2854]209  USE mod_phys_lmdz_para, ONLY: is_sequential, is_using_mpi, is_mpi_root, &
[1897]210                                jj_begin, jj_end, jj_nb
[2344]211  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]212  USE ioipsl, ONLY: histbeg
[1897]213#ifdef CPP_XIOS
[2854]214  USE wxios, ONLY: wxios_add_file
[1897]215#endif
[1825]216  IMPLICIT NONE
[2114]217  include 'clesphys.h'
[1825]218   
[2854]219    CHARACTER*(*), INTENT(IN) :: name
220    INTEGER, INTENT(IN) :: itau0
[1825]221    REAL,INTENT(IN) :: zjulian
222    REAL,INTENT(IN) :: dtime
[2854]223    CHARACTER(LEN=*), INTENT(IN) :: ffreq
[1825]224    INTEGER,INTENT(IN) :: lev
[2854]225    INTEGER,INTENT(OUT) :: nhori
226    INTEGER,INTENT(OUT) :: nid_day
[1825]227
228!$OMP MASTER   
[2854]229    IF (is_sequential) THEN
[2344]230      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
231                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
[2854]232    ELSE
[2344]233      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
234                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
[2854]235    ENDIF
[1825]236
237#ifdef CPP_XIOS
238    ! ug OMP en chantier...
239    IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
240        ! ug Création du fichier
[2114]241      IF (.not. ok_all_xml) THEN
[1825]242        CALL wxios_add_file(name, ffreq, lev)
[2114]243      ENDIF
[2854]244    ENDIF
[1825]245#endif
246!$OMP END MASTER
[629]247 
[1825]248  END SUBROUTINE histbeg_phyxios
249 
[1797]250  SUBROUTINE histbeg_phy(name,itau0,zjulian,dtime,nhori,nid_day)
[1897]251
[2854]252  USE mod_phys_lmdz_para, ONLY: jj_begin, jj_end, jj_nb, is_sequential
[2344]253  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]254  USE ioipsl, ONLY: histbeg
[1897]255
[1797]256  IMPLICIT NONE
[629]257   
[2854]258    CHARACTER*(*), INTENT(IN) :: name
259    INTEGER, INTENT(IN) :: itau0
[1797]260    REAL,INTENT(IN) :: zjulian
261    REAL,INTENT(IN) :: dtime
[2854]262    INTEGER,INTENT(OUT) :: nhori
263    INTEGER,INTENT(OUT) :: nid_day
[766]264
265!$OMP MASTER   
[2097]266#ifndef CPP_IOIPSL_NO_OUTPUT
[2854]267    IF (is_sequential) THEN
[2344]268      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
269                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
[2854]270    ELSE
[2344]271      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
272                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
[2854]273    ENDIF
[1852]274#endif
[766]275!$OMP END MASTER
[629]276 
[1797]277  END SUBROUTINE histbeg_phy
[1539]278
[1825]279
[1797]280  SUBROUTINE histbeg_phy_points(rlon,rlat,pim,tabij,ipt,jpt, &
[1539]281             plon,plat,plon_bounds,plat_bounds, &
282             nname,itau0,zjulian,dtime,nnhori,nnid_day)
[2854]283  USE dimphy, ONLY: klon
284  USE mod_phys_lmdz_para, ONLY: gather, bcast, &
[1897]285                                is_sequential, klon_mpi_begin, klon_mpi_end, &
286                                mpi_rank
[2854]287  USE mod_grid_phy_lmdz, ONLY: klon_glo, nbp_lon, nbp_lat
288  USE ioipsl, ONLY: histbeg
[1897]289
[1797]290  IMPLICIT NONE
[1539]291
[1797]292    REAL,DIMENSION(klon),INTENT(IN) :: rlon
293    REAL,DIMENSION(klon),INTENT(IN) :: rlat
[2854]294    INTEGER, INTENT(IN) :: itau0
[1797]295    REAL,INTENT(IN) :: zjulian
296    REAL,INTENT(IN) :: dtime
[2854]297    INTEGER, INTENT(IN) :: pim
298    INTEGER, intent(out) :: nnhori
299    CHARACTER(len=20), INTENT(IN) :: nname
300    INTEGER, INTENT(OUT) :: nnid_day
301    INTEGER :: i
[1797]302    REAL,DIMENSION(klon_glo)        :: rlat_glo
303    REAL,DIMENSION(klon_glo)        :: rlon_glo
304    INTEGER, DIMENSION(pim), INTENT(IN)  :: tabij
305    REAL,DIMENSION(pim), INTENT(IN) :: plat, plon
306    INTEGER,DIMENSION(pim), INTENT(IN) :: ipt, jpt
307    REAL,DIMENSION(pim,2), intent(out) :: plat_bounds, plon_bounds
[1539]308
309    INTEGER, SAVE :: tabprocbeg, tabprocend
310!$OMP THREADPRIVATE(tabprocbeg, tabprocend)
311    INTEGER :: ip
312    INTEGER, PARAMETER :: nip=1
313    INTEGER :: npproc
[1797]314    REAL, allocatable, DIMENSION(:) :: npplat, npplon
315    REAL, allocatable, DIMENSION(:,:) :: npplat_bounds, npplon_bounds
[2344]316    REAL, DIMENSION(nbp_lon,nbp_lat) :: zx_lon, zx_lat
[1539]317
318    CALL gather(rlat,rlat_glo)
319    CALL bcast(rlat_glo)
320    CALL gather(rlon,rlon_glo)
321    CALL bcast(rlon_glo)
322
323!$OMP MASTER
324    DO i=1,pim
325
326!    print*,'CFMIP_iophy i tabij lon lat',i,tabij(i),plon(i),plat(i)
327
328     plon_bounds(i,1)=rlon_glo(tabij(i)-1)
329     plon_bounds(i,2)=rlon_glo(tabij(i)+1)
[2854]330     IF (plon_bounds(i,2).LE.0..AND.plon_bounds(i,1).GE.0.) THEN
331      IF (rlon_glo(tabij(i)).GE.0.) THEN
[1539]332       plon_bounds(i,2)=-1*plon_bounds(i,2)
[2854]333      ENDIF
334     ENDIF
335     IF (plon_bounds(i,2).GE.0..AND.plon_bounds(i,1).LE.0.) THEN
336      IF (rlon_glo(tabij(i)).LE.0.) THEN
[1539]337       plon_bounds(i,2)=-1*plon_bounds(i,2)
[2854]338      ENDIF
339     ENDIF
[1539]340!
[2344]341     IF ( tabij(i).LE.nbp_lon) THEN
[1539]342      plat_bounds(i,1)=rlat_glo(tabij(i))
343     ELSE
[2344]344      plat_bounds(i,1)=rlat_glo(tabij(i)-nbp_lon)
[1539]345     ENDIF
[2344]346     plat_bounds(i,2)=rlat_glo(tabij(i)+nbp_lon)
[1539]347!
348!    print*,'CFMIP_iophy point i lon lon_bds',i,plon_bounds(i,1),rlon_glo(tabij(i)),plon_bounds(i,2)
349!    print*,'CFMIP_iophy point i lat lat_bds',i,plat_bounds(i,1),rlat_glo(tabij(i)),plat_bounds(i,2)
350!
351    ENDDO
352    if (is_sequential) then
353
354     npstn=pim
355     IF(.NOT. ALLOCATED(nptabij)) THEN
356      ALLOCATE(nptabij(pim))
357     ENDIF
358     DO i=1,pim
359      nptabij(i)=tabij(i)
360     ENDDO
361
[2344]362       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon_glo,zx_lon)
[2854]363       IF ((nbp_lon*nbp_lat).GT.1) THEN
[2344]364       DO i = 1, nbp_lon
[1539]365         zx_lon(i,1) = rlon_glo(i+1)
[2344]366         zx_lon(i,nbp_lat) = rlon_glo(i+1)
[1539]367       ENDDO
[2854]368       ENDIF
[2344]369       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat_glo,zx_lat)
[1539]370
371    DO i=1,pim
372!    print*,'CFMIP_iophy i tabij lon lat',i,tabij(i),plon(i),plat(i)
373
374     plon_bounds(i,1)=zx_lon(ipt(i)-1,jpt(i))
375     plon_bounds(i,2)=zx_lon(ipt(i)+1,jpt(i))
376
[2854]377     IF (ipt(i).EQ.1) THEN
[2344]378      plon_bounds(i,1)=zx_lon(nbp_lon,jpt(i))
[1539]379      plon_bounds(i,2)=360.+zx_lon(ipt(i)+1,jpt(i))
[2854]380     ENDIF
[1539]381 
[2854]382     IF (ipt(i).EQ.nbp_lon) THEN
[1539]383      plon_bounds(i,2)=360.+zx_lon(1,jpt(i))
[2854]384     ENDIF
[1539]385
386     plat_bounds(i,1)=zx_lat(ipt(i),jpt(i)-1)
387     plat_bounds(i,2)=zx_lat(ipt(i),jpt(i)+1)
388
[2854]389     IF (jpt(i).EQ.1) THEN
[1539]390      plat_bounds(i,1)=zx_lat(ipt(i),1)+0.001
391      plat_bounds(i,2)=zx_lat(ipt(i),1)-0.001
[2854]392     ENDIF
[1539]393 
[2854]394     IF (jpt(i).EQ.nbp_lat) THEN
[2344]395      plat_bounds(i,1)=zx_lat(ipt(i),nbp_lat)+0.001
396      plat_bounds(i,2)=zx_lat(ipt(i),nbp_lat)-0.001
[2854]397     ENDIF
[1539]398!
399!    print*,'CFMIP_iophy point i lon lon_bds',i,plon_bounds(i,1),rlon(tabij(i)),plon_bounds(i,2)
400!    print*,'CFMIP_iophy point i lat lat_bds',i,plat_bounds(i,1),rlat(tabij(i)),plat_bounds(i,2)
401!
402    ENDDO
[1897]403
[2097]404#ifndef CPP_IOIPSL_NO_OUTPUT
[1539]405     call histbeg(nname,pim,plon,plon_bounds, &
406                           plat,plat_bounds, &
407                           itau0, zjulian, dtime, nnhori, nnid_day)
[1852]408#endif
[2854]409    ELSE
[1539]410     npproc=0
411     DO ip=1, pim
412      tabprocbeg=klon_mpi_begin
413      tabprocend=klon_mpi_end
414      IF(tabij(ip).GE.tabprocbeg.AND.tabij(ip).LE.tabprocend) THEN
415       npproc=npproc+1
416       npstn=npproc
417      ENDIF
418     ENDDO
419!    print*,'CFMIP_iophy mpi_rank npstn',mpi_rank,npstn
420     IF(.NOT. ALLOCATED(nptabij)) THEN
421      ALLOCATE(nptabij(npstn))
422      ALLOCATE(npplon(npstn), npplat(npstn))
423      ALLOCATE(npplon_bounds(npstn,2), npplat_bounds(npstn,2))
424     ENDIF
425     npproc=0
426     DO ip=1, pim
427      IF(tabij(ip).GE.tabprocbeg.AND.tabij(ip).LE.tabprocend) THEN
428       npproc=npproc+1
429       nptabij(npproc)=tabij(ip)
430!      print*,'mpi_rank npproc ip plon plat tabij=',mpi_rank,npproc,ip, &
431!      plon(ip),plat(ip),tabij(ip)
432       npplon(npproc)=plon(ip)
433       npplat(npproc)=plat(ip)
434       npplon_bounds(npproc,1)=plon_bounds(ip,1)
435       npplon_bounds(npproc,2)=plon_bounds(ip,2)
436       npplat_bounds(npproc,1)=plat_bounds(ip,1)
437       npplat_bounds(npproc,2)=plat_bounds(ip,2)
438!!!
439!!! print qui sert a reordonner les points stations selon l'ordre CFMIP
440!!! ne pas enlever
441        print*,'iophy_mpi rank ip lon lat',mpi_rank,ip,plon(ip),plat(ip)
442!!!
443      ENDIF
444     ENDDO
[2097]445#ifndef CPP_IOIPSL_NO_OUTPUT
[1539]446     call histbeg(nname,npstn,npplon,npplon_bounds, &
447                            npplat,npplat_bounds, &
448                            itau0,zjulian,dtime,nnhori,nnid_day,phys_domain_id)
[1852]449#endif
[2854]450    ENDIF
[1539]451!$OMP END MASTER
452
[2854]453  END SUBROUTINE histbeg_phy_points
[1807]454
455
456  SUBROUTINE histdef2d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
457
[2854]458    USE ioipsl, ONLY: histdef
459    USE mod_phys_lmdz_para, ONLY: jj_nb
460    USE phys_output_var_mod, ONLY: type_ecri, zoutm, zdtime_moy, lev_files, &
461                                   nid_files, nhorim, swaero_diag, dryaod_diag, nfiles
[2344]462    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]463    USE aero_mod, ONLY : naero_tot, name_aero_tau
464
[1807]465    IMPLICIT NONE
466
467    INCLUDE "clesphys.h"
468
469    INTEGER                          :: iff
[2854]470    INTEGER                          :: naero
[1807]471    LOGICAL                          :: lpoint
472    INTEGER, DIMENSION(nfiles)       :: flag_var
[2854]473    CHARACTER(LEN=20)                :: nomvar
[1807]474    CHARACTER(LEN=*)                 :: titrevar
475    CHARACTER(LEN=*)                 :: unitvar
476
477    REAL zstophym
478
479    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
480       zstophym=zoutm(iff)
481    ELSE
482       zstophym=zdtime_moy
483    ENDIF
484
485    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
486    CALL conf_physoutputs(nomvar,flag_var)
487
488    IF(.NOT.lpoint) THEN 
489       IF ( flag_var(iff)<=lev_files(iff) ) THEN
490          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
[2344]491               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
[1807]492               type_ecri(iff), zstophym,zoutm(iff))               
493       ENDIF
494    ELSE
495       IF ( flag_var(iff)<=lev_files(iff) ) THEN
496          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
497               npstn,1,nhorim(iff), 1,1,1, -99, 32, &
498               type_ecri(iff), zstophym,zoutm(iff))               
499       ENDIF
500    ENDIF
501
502    ! Set swaero_diag=true if at least one of the concerned variables are defined
[2854]503    IF (nomvar=='topswad' .OR. nomvar=='topswad0' .OR. nomvar=='solswad' .OR. nomvar=='solswad0' .OR. &
504        nomvar=='toplwad' .OR. nomvar=='toplwad0' .OR. nomvar=='sollwad' .OR. nomvar=='sollwad0' .OR. &
505        nomvar=='topswai' .OR. nomvar=='solswai' ) THEN
506       IF  ( flag_var(iff)<=lev_files(iff) ) swaero_diag=.TRUE.
507    ENDIF
[1807]508
[2854]509    ! Set dryaod_diag=true if at least one of the concerned variables are defined
[2856]510    IF (nomvar=='dryod550aer') THEN
511      IF  ( flag_var(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
512    ENDIF
[2854]513    DO naero = 1, naero_tot-1
514      IF (nomvar=='dryod550_'//name_aero_tau(naero)) THEN
515        IF  ( flag_var(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
516      ENDIF
517    ENDDO
[1807]518
[2854]519  END SUBROUTINE histdef2d_old
[1807]520
521  SUBROUTINE histdef3d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
522
[2854]523    USE ioipsl, ONLY: histdef
524    USE dimphy, ONLY: klev
525    USE mod_phys_lmdz_para, ONLY: jj_nb
526    USE phys_output_var_mod, ONLY: type_ecri, zoutm, lev_files, nid_files, &
[1897]527                                   nhorim, zdtime_moy, levmin, levmax, &
528                                   nvertm, nfiles
[2344]529    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1807]530    IMPLICIT NONE
531
532    INCLUDE "clesphys.h"
533
534    INTEGER                          :: iff
535    LOGICAL                          :: lpoint
536    INTEGER, DIMENSION(nfiles)       :: flag_var
537    CHARACTER(LEN=20)                 :: nomvar
538    CHARACTER(LEN=*)                 :: titrevar
539    CHARACTER(LEN=*)                 :: unitvar
540
541    REAL zstophym
542
543    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
544    CALL conf_physoutputs(nomvar,flag_var)
545
546    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
547       zstophym=zoutm(iff)
548    ELSE
549       zstophym=zdtime_moy
550    ENDIF
551
552    IF(.NOT.lpoint) THEN
553       IF ( flag_var(iff)<=lev_files(iff) ) THEN
554          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
[2344]555               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
[1807]556               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, type_ecri(iff), &
557               zstophym, zoutm(iff))
558       ENDIF
559    ELSE
560       IF ( flag_var(iff)<=lev_files(iff) ) THEN
561          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
562               npstn,1,nhorim(iff), klev, levmin(iff), &
563               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
564               type_ecri(iff), zstophym,zoutm(iff))
565       ENDIF
566    ENDIF
567  END SUBROUTINE histdef3d_old
568
569  SUBROUTINE histdef2d (iff,var)
570
[2854]571    USE ioipsl, ONLY: histdef
572    USE mod_phys_lmdz_para, ONLY: jj_nb
573    USE phys_output_var_mod, ONLY: ctrl_out, type_ecri_files, zoutm, zdtime_moy, &
[1897]574                                   clef_stations, phys_out_filenames, lev_files, &
[2854]575                                   nid_files, nhorim, swaero_diag, dryaod_diag
[2319]576    USE print_control_mod, ONLY: prt_level,lunout
[2344]577    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]578    USE aero_mod, ONLY : naero_tot, name_aero_tau
[1897]579#ifdef CPP_XIOS
[2854]580    USE wxios, ONLY: wxios_add_field_to_file
[1897]581#endif
[1807]582    IMPLICIT NONE
583
584    INCLUDE "clesphys.h"
585
586    INTEGER                          :: iff
[2854]587    INTEGER                          :: naero
[1807]588    TYPE(ctrl_out)                   :: var
589
590    REAL zstophym
591    CHARACTER(LEN=20) :: typeecrit
592
593    ! ug On récupère le type écrit de la structure:
594    !       Assez moche, à refaire si meilleure méthode...
595    IF (INDEX(var%type_ecrit(iff), "once") > 0) THEN
596       typeecrit = 'once'
597    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
598       typeecrit = 't_min(X)'
599    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
600       typeecrit = 't_max(X)'
601    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
602       typeecrit = 'inst(X)'
603    ELSE
604       typeecrit = type_ecri_files(iff)
605    ENDIF
606
607    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
608       zstophym=zoutm(iff)
609    ELSE
610       zstophym=zdtime_moy
611    ENDIF
612
613    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
614    CALL conf_physoutputs(var%name, var%flag)
615
616    IF(.NOT.clef_stations(iff)) THEN 
[1852]617
[1825]618#ifdef CPP_XIOS
[2114]619      IF (.not. ok_all_xml) THEN
620        IF ( var%flag(iff)<=lev_files(iff) ) THEN
621          CALL wxios_add_field_to_file(var%name, 2, iff, phys_out_filenames(iff), &
622          var%description, var%unit, var%flag(iff), typeecrit)
623          IF (prt_level >= 10) THEN
624            WRITE(lunout,*) 'histdef2d: call wxios_add_field_to_file var%name iff: ', &
625                            trim(var%name),iff
626          ENDIF
[2001]627        ENDIF
628      ENDIF
[1825]629#endif
[2097]630#ifndef CPP_IOIPSL_NO_OUTPUT
[1825]631
[1807]632       IF ( var%flag(iff)<=lev_files(iff) ) THEN
633          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
[2344]634               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
[1807]635               typeecrit, zstophym,zoutm(iff))               
636       ENDIF
637    ELSE
638       IF ( var%flag(iff)<=lev_files(iff)) THEN
639          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
640               npstn,1,nhorim(iff), 1,1,1, -99, 32, &
641               typeecrit, zstophym,zoutm(iff))               
642       ENDIF
[1852]643#endif
[1807]644    ENDIF
645
[2854]646    ! Set swaero_diag=true if at least one of the concerned variables are defined
[2529]647    !--OB 30/05/2016 use wider set of variables
648    IF ( var%name=='topswad' .OR. var%name=='topswad0' .OR. var%name=='solswad' .OR. var%name=='solswad0' .OR. &
649         var%name=='topswai' .OR. var%name=='solswai'  .OR. ( iflag_rrtm==1 .AND. (                            &
650         var%name=='toplwad' .OR. var%name=='toplwad0' .OR. var%name=='sollwad' .OR. var%name=='sollwad0' .OR. &
651         var%name=='toplwai' .OR. var%name=='sollwai'  ) ) ) THEN
[2854]652       IF  ( var%flag(iff)<=lev_files(iff) ) swaero_diag=.TRUE.
653    ENDIF
654
655    ! set dryaod_dry=true if at least one of the concerned variables are defined
656    IF (var%name=='dryod550aer') THEN
657      IF  ( var%flag(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
658    ENDIF
659    !
660    DO naero = 1, naero_tot-1
661      IF (var%name=='dryod550_'//name_aero_tau(naero)) THEN
662        IF  ( var%flag(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
663      ENDIF
664    ENDDO
[1807]665  END SUBROUTINE histdef2d
[2001]666
[1807]667  SUBROUTINE histdef3d (iff,var)
668
[2854]669    USE ioipsl, ONLY: histdef
670    USE dimphy, ONLY: klev
671    USE mod_phys_lmdz_para, ONLY: jj_nb
672    USE phys_output_var_mod, ONLY: ctrl_out, type_ecri_files, zoutm, zdtime_moy, &
[1897]673                                   clef_stations, phys_out_filenames, lev_files, &
[2854]674                                   nid_files, nhorim, swaero_diag, dryaod_diag, levmin, &
[1897]675                                   levmax, nvertm
[2311]676    USE print_control_mod, ONLY: prt_level,lunout
[2344]677    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1897]678#ifdef CPP_XIOS
[2854]679    USE wxios, ONLY: wxios_add_field_to_file
[1897]680#endif
[1807]681    IMPLICIT NONE
682
683    INCLUDE "clesphys.h"
684
685    INTEGER                          :: iff
686    TYPE(ctrl_out)                   :: var
687
688    REAL zstophym
689    CHARACTER(LEN=20) :: typeecrit
690
691    ! ug On récupère le type écrit de la structure:
692    !       Assez moche, à refaire si meilleure méthode...
693    IF (INDEX(var%type_ecrit(iff), "once") > 0) THEN
694       typeecrit = 'once'
695    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
696       typeecrit = 't_min(X)'
697    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
698       typeecrit = 't_max(X)'
699    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
700       typeecrit = 'inst(X)'
701    ELSE
702       typeecrit = type_ecri_files(iff)
703    ENDIF
704
705
706    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
707    CALL conf_physoutputs(var%name,var%flag)
708
709    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
710       zstophym=zoutm(iff)
711    ELSE
712       zstophym=zdtime_moy
713    ENDIF
714
715    IF(.NOT.clef_stations(iff)) THEN
[1852]716
[1825]717#ifdef CPP_XIOS
[2114]718       IF (.not. ok_all_xml) THEN
719         IF ( var%flag(iff)<=lev_files(iff) ) THEN
720         CALL wxios_add_field_to_file(var%name, 3, iff, phys_out_filenames(iff), &
721         var%description, var%unit, var%flag(iff), typeecrit)
722           IF (prt_level >= 10) THEN
723             WRITE(lunout,*) 'histdef3d: call wxios_add_field_to_file var%name iff: ', &
724                             trim(var%name),iff
725           ENDIF
726         ENDIF
727       ENDIF
[1825]728#endif
[2097]729#ifndef CPP_IOIPSL_NO_OUTPUT
[1825]730
[1807]731       IF ( var%flag(iff)<=lev_files(iff) ) THEN
732          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
[2344]733               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
[1807]734               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, typeecrit, &
735               zstophym, zoutm(iff))
736       ENDIF
737    ELSE
738       IF ( var%flag(iff)<=lev_files(iff)) THEN
739          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
740               npstn,1,nhorim(iff), klev, levmin(iff), &
741               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
742               typeecrit, zstophym,zoutm(iff))
743       ENDIF
[1852]744#endif
[1807]745    ENDIF
746  END SUBROUTINE histdef3d
747
748  SUBROUTINE conf_physoutputs(nam_var,flag_var)
749!!! Lecture des noms et niveau de sortie des variables dans output.def
750    !   en utilisant les routines getin de IOIPSL 
[2854]751    USE ioipsl, ONLY: getin
752    USE phys_output_var_mod, ONLY: nfiles
[2311]753    USE print_control_mod, ONLY: prt_level,lunout
[1807]754    IMPLICIT NONE
755
756    CHARACTER(LEN=20)                :: nam_var
757    INTEGER, DIMENSION(nfiles)      :: flag_var
758
759    IF(prt_level>10) WRITE(lunout,*)'Avant getin: nam_var flag_var ',nam_var,flag_var(:)
760    CALL getin('flag_'//nam_var,flag_var)
761    CALL getin('name_'//nam_var,nam_var)
762    IF(prt_level>10) WRITE(lunout,*)'Apres getin: nam_var flag_var ',nam_var,flag_var(:)
763
764  END SUBROUTINE conf_physoutputs
765
[1539]766 
[1791]767  SUBROUTINE histwrite2d_phy_old(nid,lpoint,name,itau,field)
[2854]768  USE dimphy, ONLY: klon
769  USE mod_phys_lmdz_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
[1897]770                                is_sequential, klon_mpi_begin, klon_mpi_end, &
771                                jj_nb, klon_mpi
[2854]772  USE ioipsl, ONLY: histwrite
[2311]773  USE print_control_mod, ONLY: prt_level,lunout
[2344]774  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1791]775  IMPLICIT NONE
[629]776   
[2854]777    INTEGER,INTENT(IN) :: nid
778    LOGICAL,INTENT(IN) :: lpoint
779    CHARACTER*(*), INTENT(IN) :: name
780    INTEGER, INTENT(IN) :: itau
[1797]781    REAL,DIMENSION(:),INTENT(IN) :: field
782    REAL,DIMENSION(klon_mpi) :: buffer_omp
783    INTEGER, allocatable, DIMENSION(:) :: index2d
[2344]784    REAL :: Field2d(nbp_lon,jj_nb)
[1331]785
[2854]786    INTEGER :: ip
787    REAL,ALLOCATABLE,DIMENSION(:) :: fieldok
[1539]788
[2311]789    IF (size(field)/=klon) CALL abort_physic('iophy::histwrite2d','Field first DIMENSION not equal to klon',1)
[776]790   
791    CALL Gather_omp(field,buffer_omp)   
[766]792!$OMP MASTER
[1331]793    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
[1539]794    if(.NOT.lpoint) THEN
[2344]795     ALLOCATE(index2d(nbp_lon*jj_nb))
796     ALLOCATE(fieldok(nbp_lon*jj_nb))
[1897]797     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[2344]798     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
[1897]799     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2854]800    ELSE
[1539]801     ALLOCATE(fieldok(npstn))
802     ALLOCATE(index2d(npstn))
803
[2854]804     IF (is_sequential) THEN
[1539]805!     klon_mpi_begin=1
806!     klon_mpi_end=klon
807      DO ip=1, npstn
808       fieldok(ip)=buffer_omp(nptabij(ip))
809      ENDDO
[2854]810     ELSE
[1539]811      DO ip=1, npstn
812!     print*,'histwrite2d is_sequential npstn ip name nptabij',npstn,ip,name,nptabij(ip)
813       IF(nptabij(ip).GE.klon_mpi_begin.AND. &
814          nptabij(ip).LE.klon_mpi_end) THEN
815         fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
816       ENDIF
817      ENDDO
[2854]818     ENDIF
[1897]819     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[1539]820     CALL histwrite(nid,name,itau,fieldok,npstn,index2d)
[1897]821     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[1539]822!
[2854]823    ENDIF
824    DEALLOCATE(index2d)
825    DEALLOCATE(fieldok)
[1791]826!$OMP END MASTER   
[1331]827
[1791]828 
[2854]829  END SUBROUTINE histwrite2d_phy_old
[1791]830
[1797]831  SUBROUTINE histwrite3d_phy_old(nid,lpoint,name,itau,field)
[2854]832  USE dimphy, ONLY: klon
833  USE mod_phys_lmdz_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
[1897]834                                is_sequential, klon_mpi_begin, klon_mpi_end, &
835                                jj_nb, klon_mpi
[2344]836  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]837  USE ioipsl, ONLY: histwrite
[2311]838  USE print_control_mod, ONLY: prt_level,lunout
[1797]839  IMPLICIT NONE
[629]840   
[2854]841    INTEGER,INTENT(IN) :: nid
842    LOGICAL,INTENT(IN) :: lpoint
843    CHARACTER*(*), INTENT(IN) :: name
844    INTEGER, INTENT(IN) :: itau
[1797]845    REAL,DIMENSION(:,:),INTENT(IN) :: field  ! --> field(klon,:)
846    REAL,DIMENSION(klon_mpi,size(field,2)) :: buffer_omp
[2344]847    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
[1539]848    INTEGER :: ip, n, nlev
[1797]849    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
850    REAL,allocatable, DIMENSION(:,:) :: fieldok
[1539]851
[1791]852
[2311]853    IF (size(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
[1331]854    nlev=size(field,2)
[1539]855
[776]856    CALL Gather_omp(field,buffer_omp)
[766]857!$OMP MASTER
[1331]858    CALL grid1Dto2D_mpi(buffer_omp,field3d)
[2854]859    IF (.NOT.lpoint) THEN
[2344]860     ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
861     ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[1897]862     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[2344]863     CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
[1897]864     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2854]865   ELSE
[1539]866      nlev=size(field,2)
867      ALLOCATE(index3d(npstn*nlev))
868      ALLOCATE(fieldok(npstn,nlev))
869
[2854]870      IF (is_sequential) THEN
[1539]871!      klon_mpi_begin=1
872!      klon_mpi_end=klon
873       DO n=1, nlev
874       DO ip=1, npstn
875        fieldok(ip,n)=buffer_omp(nptabij(ip),n)
876       ENDDO
877       ENDDO
[2854]878      ELSE
[1539]879       DO n=1, nlev
880       DO ip=1, npstn
881        IF(nptabij(ip).GE.klon_mpi_begin.AND. &
882         nptabij(ip).LE.klon_mpi_end) THEN
883         fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
884        ENDIF
885       ENDDO
886       ENDDO
[2854]887      ENDIF
[1897]888      IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[1539]889      CALL histwrite(nid,name,itau,fieldok,npstn*nlev,index3d)
[1897]890      IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2854]891    ENDIF
892  DEALLOCATE(index3d)
893  DEALLOCATE(fieldok)
[766]894!$OMP END MASTER   
[1791]895
[2854]896  END SUBROUTINE histwrite3d_phy_old
[1791]897
898
[1807]899
900
[1791]901! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
902  SUBROUTINE histwrite2d_phy(var,field, STD_iff)
[2854]903  USE dimphy, ONLY: klon
904  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1dto2d_mpi, &
[1897]905                                jj_nb, klon_mpi, klon_mpi_begin, &
906                                klon_mpi_end, is_sequential
[2854]907  USE ioipsl, ONLY: histwrite
908  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
[1897]909                                 nfiles, vars_defined, clef_stations, &
910                                 nid_files
[2311]911  USE print_control_mod, ONLY: prt_level,lunout
[2344]912  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1791]913#ifdef CPP_XIOS
[2854]914  USE xios, ONLY: xios_send_field
[1791]915#endif
916
[1825]917
[1791]918  IMPLICIT NONE
[2114]919  include 'clesphys.h'
[1791]920
[1807]921    TYPE(ctrl_out), INTENT(IN) :: var
922    REAL, DIMENSION(:), INTENT(IN) :: field
923    INTEGER, INTENT(IN), OPTIONAL :: STD_iff ! ug RUSTINE POUR LES STD LEVS.....
[1791]924     
[1807]925    INTEGER :: iff, iff_beg, iff_end
[2001]926    LOGICAL, SAVE  :: firstx
927!$OMP THREADPRIVATE(firstx)
928
[1797]929    REAL,DIMENSION(klon_mpi) :: buffer_omp
930    INTEGER, allocatable, DIMENSION(:) :: index2d
[2344]931    REAL :: Field2d(nbp_lon,jj_nb)
[1791]932
933    INTEGER :: ip
934    REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
935
[2001]936    IF (prt_level >= 10) THEN
937      WRITE(lunout,*)'Begin histwrite2d_phy for ',trim(var%name)
938    ENDIF
[1791]939! ug RUSTINE POUR LES STD LEVS.....
940      IF (PRESENT(STD_iff)) THEN
941            iff_beg = STD_iff
942            iff_end = STD_iff
943      ELSE
944            iff_beg = 1
945            iff_end = nfiles
[2854]946      ENDIF
[1791]947
[1807]948  ! On regarde si on est dans la phase de définition ou d'écriture:
[2854]949  IF (.NOT.vars_defined) THEN
[1821]950!$OMP MASTER
[1807]951      !Si phase de définition.... on définit
[2114]952      IF (.not. ok_all_xml) THEN
[2854]953      IF (prt_level >= 10) THEN
954      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to define ", trim(var%name)
955      ENDIF
[1807]956      DO iff=iff_beg, iff_end
957         IF (clef_files(iff)) THEN
958            CALL histdef2d(iff, var)
959         ENDIF
960      ENDDO
[2114]961      ENDIF
[1821]962!$OMP END MASTER
[1807]963  ELSE
964
965    !Et sinon on.... écrit
[2311]966    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon',1)
[1791]967   
[2854]968    IF (prt_level >= 10) THEn
969      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to gather and write ", trim(var%name)
970    ENDIF
[1897]971   
972    CALL Gather_omp(field,buffer_omp)
[1791]973!$OMP MASTER
974    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
[1897]975
[1791]976! La boucle sur les fichiers:
[2001]977      firstx=.true.
[2114]978
979      IF (ok_all_xml) THEN
980#ifdef CPP_XIOS
[2854]981          IF (prt_level >= 10) THEN
982             write(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)                       
983          ENDIF
[2114]984          CALL xios_send_field(var%name, Field2d)
[2854]985          IF (prt_level >= 10) THEN
986             WRITE (lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ', trim(var%name)                       
987          ENDIF
[2114]988#else
[2311]989        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
[2114]990#endif
991      ELSE 
992        DO iff=iff_beg, iff_end
[1791]993            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
[2001]994
995#ifdef CPP_XIOS
996               IF (firstx) THEN
[2854]997                  IF (prt_level >= 10) THEN
998                     WRITE (lunout,*)'Dans iophy histwrite2D,iff,var%name ', iff,trim(var%name)                       
999                     WRITE (lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
1000                  ENDIF
[2002]1001                  CALL xios_send_field(var%name, Field2d)
[2001]1002                  firstx=.false.
1003               ENDIF
1004#endif
1005
[2854]1006                  IF (.NOT.clef_stations(iff)) THEN
[2344]1007                        ALLOCATE(index2d(nbp_lon*jj_nb))
1008                        ALLOCATE(fieldok(nbp_lon*jj_nb))
[2097]1009#ifndef CPP_IOIPSL_NO_OUTPUT
[2344]1010                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,nbp_lon*jj_nb,index2d)
[1852]1011#endif
[2001]1012!#ifdef CPP_XIOS
1013!                        IF (iff == iff_beg) THEN
1014!                          if (prt_level >= 10) then
[2002]1015!                            write(lunout,*)"histwrite2d_phy: .NOT.clef_stations(iff) and iff==iff_beg, call xios_send_field"
[2001]1016!                          endif
[2002]1017!                          CALL xios_send_field(var%name, Field2d)
[2001]1018!                        ENDIF
1019!#endif
[1791]1020                  ELSE
1021                        ALLOCATE(fieldok(npstn))
1022                        ALLOCATE(index2d(npstn))
1023
1024                        IF (is_sequential) THEN
[1897]1025                          DO ip=1, npstn
1026                            fieldok(ip)=buffer_omp(nptabij(ip))
1027                          ENDDO
1028                        ELSE
[1791]1029                              DO ip=1, npstn
[1897]1030                                write(lunout,*)'histwrite2d_phy is_sequential npstn ip namenptabij',npstn,ip,var%name,nptabij(ip)
[1791]1031                                     IF(nptabij(ip).GE.klon_mpi_begin.AND. &
1032                                        nptabij(ip).LE.klon_mpi_end) THEN
1033                                       fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
1034                                     ENDIF
1035                              ENDDO
[1897]1036                       ENDIF ! of IF (is_sequential)
[2097]1037#ifndef CPP_IOIPSL_NO_OUTPUT
[2854]1038                       IF (prt_level >= 10) THEn
[1897]1039                         write(lunout,*)"histwrite2d_phy: clef_stations(iff) and iff==iff_beg, call wxios_write_2D"
[2854]1040                       ENDIF
[1791]1041                       CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn,index2d)
[1852]1042#endif
[1897]1043                  ENDIF ! of IF(.NOT.clef_stations(iff))
[1791]1044                 
[2854]1045                DEALLOCATE(index2d)
1046                DEALLOCATE(fieldok)
[1791]1047            ENDIF !levfiles
[2114]1048        ENDDO ! of DO iff=iff_beg, iff_end
1049      ENDIF
[1791]1050!$OMP END MASTER   
[1807]1051  ENDIF ! vars_defined
[1897]1052  IF (prt_level >= 10) WRITE(lunout,*)'End histwrite2d_phy ',trim(var%name)
[1791]1053  END SUBROUTINE histwrite2d_phy
1054
1055
1056! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
[1807]1057  SUBROUTINE histwrite3d_phy(var, field, STD_iff)
[2854]1058  USE dimphy, ONLY: klon, klev
1059  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1dto2d_mpi, &
[1897]1060                                jj_nb, klon_mpi, klon_mpi_begin, &
1061                                klon_mpi_end, is_sequential
[2854]1062  USE ioipsl, ONLY: histwrite
1063  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
[1897]1064                                 nfiles, vars_defined, clef_stations, &
1065                                 nid_files
[2344]1066  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1791]1067#ifdef CPP_XIOS
[2854]1068  USE xios, ONLY: xios_send_field
[1791]1069#endif
[2311]1070  USE print_control_mod, ONLY: prt_level,lunout
[1791]1071
1072  IMPLICIT NONE
[2114]1073  include 'clesphys.h'
[1791]1074
[1807]1075    TYPE(ctrl_out), INTENT(IN) :: var
1076    REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
1077    INTEGER, INTENT(IN), OPTIONAL :: STD_iff ! ug RUSTINE POUR LES STD LEVS.....
1078     
[1828]1079    INTEGER :: iff, iff_beg, iff_end
[2001]1080    LOGICAL, SAVE  :: firstx
1081!$OMP THREADPRIVATE(firstx)
[1791]1082    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
[2344]1083    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
[2001]1084    INTEGER :: ip, n, nlev, nlevx
[1791]1085    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1086    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1087
[1897]1088  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d ',var%name
[1791]1089
[1828]1090! ug RUSTINE POUR LES STD LEVS.....
1091      IF (PRESENT(STD_iff)) THEN
1092            iff_beg = STD_iff
1093            iff_end = STD_iff
1094      ELSE
1095            iff_beg = 1
1096            iff_end = nfiles
[2854]1097      ENDIF
[1828]1098
[1807]1099  ! On regarde si on est dans la phase de définition ou d'écriture:
1100  IF(.NOT.vars_defined) THEN
1101      !Si phase de définition.... on définit
[1821]1102!$OMP MASTER
[1828]1103      DO iff=iff_beg, iff_end
[1807]1104        IF (clef_files(iff)) THEN
1105          CALL histdef3d(iff, var)
1106        ENDIF
1107      ENDDO
[1821]1108!$OMP END MASTER
[1807]1109  ELSE
1110    !Et sinon on.... écrit
[2311]1111    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
[1807]1112    nlev=SIZE(field,2)
[2854]1113    IF (nlev.EQ.klev+1) THEN
[2001]1114        nlevx=klev
[2854]1115    ELSE
[2001]1116        nlevx=nlev
[2854]1117    ENDIF
[1791]1118
1119    CALL Gather_omp(field,buffer_omp)
1120!$OMP MASTER
1121    CALL grid1Dto2D_mpi(buffer_omp,field3d)
1122
1123
1124! BOUCLE SUR LES FICHIERS
[2001]1125     firstx=.true.
[2114]1126
1127      IF (ok_all_xml) THEN
1128#ifdef CPP_XIOS
[2854]1129          IF (prt_level >= 10) THEN
[2114]1130             write(lunout,*)'Dans iophy histwrite3D,var%name ',&
1131                             trim(var%name)                       
[2854]1132          ENDIF
[2137]1133          CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
[2114]1134#else
[2311]1135        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
[2114]1136#endif
1137      ELSE 
1138
1139
[1828]1140     DO iff=iff_beg, iff_end
[1791]1141            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
[2001]1142#ifdef CPP_XIOS
1143              IF (firstx) THEN
[2854]1144                IF (prt_level >= 10) THEn
1145                  WRITE (lunout,*)'Dans iophy, histwrite3D iff nlev klev firstx', &
[2001]1146                                  iff,nlev,klev, firstx                       
[2854]1147                  WRITE (lunout,*)'histwrite3d_phy: call xios_send_field for ', &
[2001]1148                                  trim(var%name), ' with iim jjm nlevx = ', &
[2344]1149                                  nbp_lon,jj_nb,nlevx
[2854]1150                ENDIF
[2002]1151                CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
[2001]1152                            firstx=.false.
1153              ENDIF
1154#endif
[1791]1155                IF (.NOT.clef_stations(iff)) THEN
[2344]1156                        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
1157                        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[1852]1158
[2097]1159#ifndef CPP_IOIPSL_NO_OUTPUT
[2344]1160                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,nbp_lon*jj_nb*nlev,index3d)
[1852]1161#endif
[1825]1162
[2001]1163!#ifdef CPP_XIOS
1164!                        IF (iff == 1) THEN
[2002]1165!                              CALL xios_send_field(var%name, Field3d(:,:,1:klev))
[2001]1166!                        ENDIF
1167!#endif
1168!                       
[1791]1169                ELSE
1170                        nlev=size(field,2)
1171                        ALLOCATE(index3d(npstn*nlev))
1172                        ALLOCATE(fieldok(npstn,nlev))
1173
1174                        IF (is_sequential) THEN
1175                              DO n=1, nlev
1176                                    DO ip=1, npstn
1177                                          fieldok(ip,n)=buffer_omp(nptabij(ip),n)
1178                                    ENDDO
1179                              ENDDO
1180                        ELSE
1181                              DO n=1, nlev
1182                                    DO ip=1, npstn
1183                                                IF(nptabij(ip).GE.klon_mpi_begin.AND. &
1184                                                      nptabij(ip).LE.klon_mpi_end) THEN
1185                                                fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
1186                                          ENDIF
1187                                    ENDDO
1188                              ENDDO
1189                        ENDIF
[2097]1190#ifndef CPP_IOIPSL_NO_OUTPUT
[1791]1191                        CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn*nlev,index3d)
[1852]1192#endif
[1791]1193                  ENDIF
[2854]1194                  DEALLOCATE(index3d)
1195                  DEALLOCATE(fieldok)
[1791]1196            ENDIF
1197      ENDDO
[2114]1198      ENDIF
[1791]1199!$OMP END MASTER   
[1807]1200  ENDIF ! vars_defined
[1897]1201  IF (prt_level >= 10) write(lunout,*)'End histrwrite3d ',var%name
[1791]1202  END SUBROUTINE histwrite3d_phy
1203 
[1852]1204
1205! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
1206#ifdef CPP_XIOS
1207  SUBROUTINE histwrite2d_xios(field_name,field)
[2854]1208  USE dimphy, ONLY: klon
1209  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1Dto2D_mpi, &
[1897]1210                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1211                                jj_nb, klon_mpi
[2344]1212  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2854]1213  USE xios, ONLY: xios_send_field
[2311]1214  USE print_control_mod, ONLY: prt_level,lunout
[1852]1215
1216  IMPLICIT NONE
1217
1218    CHARACTER(LEN=*), INTENT(IN) :: field_name
1219    REAL, DIMENSION(:), INTENT(IN) :: field
1220     
1221    REAL,DIMENSION(klon_mpi) :: buffer_omp
1222    INTEGER, allocatable, DIMENSION(:) :: index2d
[2344]1223    REAL :: Field2d(nbp_lon,jj_nb)
[1852]1224
1225    INTEGER :: ip
1226    REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
1227
[1897]1228    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',field_name
[1852]1229
1230    !Et sinon on.... écrit
[2311]1231    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
[1852]1232   
1233    CALL Gather_omp(field,buffer_omp)   
1234!$OMP MASTER
1235    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
1236   
1237!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1238!ATTENTION, STATIONS PAS GEREES !
1239!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1240    !IF(.NOT.clef_stations(iff)) THEN
1241    IF (.TRUE.) THEN
[2344]1242        ALLOCATE(index2d(nbp_lon*jj_nb))
1243        ALLOCATE(fieldok(nbp_lon*jj_nb))
[1852]1244
1245
[2002]1246        CALL xios_send_field(field_name, Field2d)
[1852]1247
1248    ELSE
1249        ALLOCATE(fieldok(npstn))
1250        ALLOCATE(index2d(npstn))
1251
1252        IF (is_sequential) THEN
1253            DO ip=1, npstn
1254                fieldok(ip)=buffer_omp(nptabij(ip))
1255            ENDDO
1256        ELSE
1257            DO ip=1, npstn
1258                PRINT*,'histwrite2d_xios is_sequential npstn ip namenptabij',npstn,ip,field_name,nptabij(ip)
1259                IF(nptabij(ip).GE.klon_mpi_begin.AND. &
1260                nptabij(ip).LE.klon_mpi_end) THEN
1261                    fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
1262                ENDIF
1263            ENDDO
1264        ENDIF
1265
1266    ENDIF
1267                 
[2854]1268    DEALLOCATE(index2d)
1269    DEALLOCATE(fieldok)
[1852]1270!$OMP END MASTER   
1271
[1897]1272  IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',field_name
[1852]1273  END SUBROUTINE histwrite2d_xios
1274
1275
1276! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
1277  SUBROUTINE histwrite3d_xios(field_name, field)
[2854]1278  USE dimphy, ONLY: klon, klev
1279  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1Dto2D_mpi, &
[1897]1280                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1281                                jj_nb, klon_mpi
[2854]1282  USE xios, ONLY: xios_send_field
[2344]1283  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2311]1284  USE print_control_mod, ONLY: prt_level,lunout
[1852]1285
1286  IMPLICIT NONE
1287
1288    CHARACTER(LEN=*), INTENT(IN) :: field_name
1289    REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
1290
1291    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
[2344]1292    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
[1852]1293    INTEGER :: ip, n, nlev
1294    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1295    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1296
[1897]1297  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d_xios ',field_name
[1852]1298
1299    !Et on.... écrit
[2311]1300    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
[1852]1301    nlev=SIZE(field,2)
1302
1303
1304    CALL Gather_omp(field,buffer_omp)
1305!$OMP MASTER
1306    CALL grid1Dto2D_mpi(buffer_omp,field3d)
1307
1308!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1309!ATTENTION, STATIONS PAS GEREES !
1310!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1311    !IF (.NOT.clef_stations(iff)) THEN
1312    IF(.TRUE.)THEN
[2344]1313        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
1314        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[2002]1315        CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
[1852]1316                       
1317    ELSE
1318        nlev=size(field,2)
1319        ALLOCATE(index3d(npstn*nlev))
1320        ALLOCATE(fieldok(npstn,nlev))
1321
1322        IF (is_sequential) THEN
1323            DO n=1, nlev
1324                DO ip=1, npstn
1325                    fieldok(ip,n)=buffer_omp(nptabij(ip),n)
1326                ENDDO
1327            ENDDO
1328        ELSE
1329            DO n=1, nlev
1330                DO ip=1, npstn
1331                    IF(nptabij(ip).GE.klon_mpi_begin.AND. &
1332                    nptabij(ip).LE.klon_mpi_end) THEN
1333                        fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
1334                    ENDIF
1335                ENDDO
1336            ENDDO
1337        ENDIF
1338    ENDIF
[2854]1339    DEALLOCATE(index3d)
1340    DEALLOCATE(fieldok)
[1852]1341!$OMP END MASTER   
1342
[1897]1343  IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',field_name
[1852]1344  END SUBROUTINE histwrite3d_xios
[2645]1345
[2660]1346#ifdef CPP_XIOS
[2645]1347  SUBROUTINE histwrite0d_xios(field_name, field)
[2854]1348  USE xios, ONLY: xios_send_field
[2645]1349  IMPLICIT NONE
1350
1351    CHARACTER(LEN=*), INTENT(IN) :: field_name
1352    REAL, INTENT(IN) :: field ! --> scalar
1353
1354!$OMP MASTER
[2660]1355   CALL xios_send_field(field_name, field)
[2645]1356!$OMP END MASTER
1357
1358  END SUBROUTINE histwrite0d_xios
[1852]1359#endif
[2660]1360
1361#endif
[629]1362end module iophy
Note: See TracBrowser for help on using the repository browser.