source: LMDZ5/branches/testing/libf/phylmd/iophy.F90 @ 5403

Last change on this file since 5403 was 2870, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2842:2865 into testing branch

  • 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!
[1910]2! $Id: iophy.F90 2870 2017-05-04 07:31:05Z abarral $
[879]3!
[1864]4MODULE iophy
5
6! abd  REAL,private,allocatable,DIMENSION(:),save :: io_lat
7! abd  REAL,private,allocatable,DIMENSION(:),save :: io_lon
[1795]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)
[1864]16
17#ifdef CPP_XIOS
[629]18  INTERFACE histwrite_phy
[2669]19!#ifdef CPP_XIOSnew
20    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios,histwrite0d_xios
21!#else
22!    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios
23!#endif
24
[1864]25  END INTERFACE
26#else
27  INTERFACE histwrite_phy
[1795]28    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old
[1001]29  END INTERFACE
[1864]30#endif
[629]31
[1539]32  INTERFACE histbeg_phy_all
[1864]33    MODULE PROCEDURE histbeg_phy,histbeg_phyxios,histbeg_phy_points
[1539]34  END INTERFACE
[1001]35
[1539]36
[1864]37CONTAINS
[629]38
[1864]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)
[2870]47  USE dimphy, ONLY: klon
48  USE mod_phys_lmdz_para, ONLY: gather, bcast, &
[1910]49                                jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
50                                mpi_size, mpi_rank, klon_mpi, &
[2435]51                                is_sequential, is_south_pole_dyn
[2870]52  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
[2408]53  USE print_control_mod, ONLY: prt_level,lunout
[1910]54#ifdef CPP_IOIPSL
[2870]55  USE ioipsl, ONLY: flio_dom_set
[1910]56#endif
57#ifdef CPP_XIOS
[2870]58  USE wxios, ONLY: wxios_domain_param
[1910]59#endif
[1864]60  IMPLICIT NONE
61    REAL,DIMENSION(klon),INTENT(IN) :: rlon
62    REAL,DIMENSION(klon),INTENT(IN) :: rlat
63
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   
[1864]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 
[2408]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)
89      DO i=2,nbp_lat-1
90        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
[1001]91      ENDDO
92    ENDIF
93
[2408]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
[1864]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 /)
[2408]117    dsg=(/ nbp_lon, nbp_lat /)
118    dsl=(/ nbp_lon, jj_nb /)
[1001]119    dpf=(/ 1,jj_begin /)
[2408]120    dpl=(/ nbp_lon, jj_end /)
[1001]121    dhs=(/ ii_begin-1,0 /)
[1864]122    IF (mpi_rank==mpi_size-1) THEN
[1001]123      dhe=(/0,0/)
[1864]124    ELSE
[2408]125      dhe=(/ nbp_lon-ii_end,0 /) 
[1864]126    ENDIF
127
[2160]128#ifndef CPP_IOIPSL_NO_OUTPUT   
[1864]129    CALL flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
[1001]130                      'APPLE',phys_domain_id)
[1864]131#endif
132#ifdef CPP_XIOS
[1910]133    ! Set values for the mask:
[1864]134    IF (mpi_rank == 0) THEN
135        data_ibegin = 0
136    ELSE
137        data_ibegin = ii_begin - 1
[2870]138    ENDIF
[1001]139
[1864]140    IF (mpi_rank == mpi_size-1) THEN
141        data_iend = nbp_lon
142    ELSE
143        data_iend = ii_end + 1
[2870]144    ENDIF
[1864]145
[2870]146    IF (prt_level>=10) THEN
[1910]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
[2435]151      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
[2870]152    ENDIF
[1864]153
[1910]154    ! Initialize the XIOS domain coreesponding to this process:
[1864]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,             &
[2435]158                            io_lat, io_lon,is_south_pole_dyn,mpi_rank)
[1864]159#endif
[1001]160!$OMP END MASTER
161     
[1864]162  END SUBROUTINE init_iophy_new
[1001]163
[1864]164  SUBROUTINE init_iophy(lat,lon)
[2870]165  USE mod_phys_lmdz_para, ONLY: jj_begin, jj_end, ii_begin, ii_end, jj_nb, &
[1910]166                                mpi_size, mpi_rank
[2870]167  USE ioipsl, ONLY: flio_dom_set
[2408]168  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1864]169  IMPLICIT NONE
[2408]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 
[2870]182    ALLOCATE(io_lat(nbp_lat))
[629]183    io_lat(:)=lat(:)
[2870]184    ALLOCATE(io_lon(nbp_lon))
[629]185    io_lon(:)=lon(:)
[1331]186   
[766]187    ddid=(/ 1,2 /)
[2408]188    dsg=(/ nbp_lon, nbp_lat /)
189    dsl=(/ nbp_lon, jj_nb /)
[776]190    dpf=(/ 1,jj_begin /)
[2408]191    dpl=(/ nbp_lon, jj_end /)
[776]192    dhs=(/ ii_begin-1,0 /)
[2870]193    IF (mpi_rank==mpi_size-1) THEN
[766]194      dhe=(/0,0/)
[2870]195    ELSE
[2408]196      dhe=(/ nbp_lon-ii_end,0 /) 
[2870]197    ENDIF
[766]198   
[2160]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)
[1864]202#endif
203!$OMP END MASTER
204     
[2870]205  END SUBROUTINE init_iophy
[629]206
[1864]207 SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
[1910]208!  USE dimphy
[2870]209  USE mod_phys_lmdz_para, ONLY: is_sequential, is_using_mpi, is_mpi_root, &
[1910]210                                jj_begin, jj_end, jj_nb
[2408]211  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]212  USE ioipsl, ONLY: histbeg
[1910]213#ifdef CPP_XIOS
[2870]214  USE wxios, ONLY: wxios_add_file
[1910]215#endif
[1864]216  IMPLICIT NONE
[2160]217  include 'clesphys.h'
[1864]218   
[2870]219    CHARACTER*(*), INTENT(IN) :: name
220    INTEGER, INTENT(IN) :: itau0
[1864]221    REAL,INTENT(IN) :: zjulian
222    REAL,INTENT(IN) :: dtime
[2870]223    CHARACTER(LEN=*), INTENT(IN) :: ffreq
[1864]224    INTEGER,INTENT(IN) :: lev
[2870]225    INTEGER,INTENT(OUT) :: nhori
226    INTEGER,INTENT(OUT) :: nid_day
[1864]227
228!$OMP MASTER   
[2870]229    IF (is_sequential) THEN
[2408]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)
[2870]232    ELSE
[2408]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)
[2870]235    ENDIF
[1864]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
[2160]241      IF (.not. ok_all_xml) THEN
[1864]242        CALL wxios_add_file(name, ffreq, lev)
[2160]243      ENDIF
[2870]244    ENDIF
[1864]245#endif
[766]246!$OMP END MASTER
[629]247 
[1864]248  END SUBROUTINE histbeg_phyxios
249 
250  SUBROUTINE histbeg_phy(name,itau0,zjulian,dtime,nhori,nid_day)
[1910]251
[2870]252  USE mod_phys_lmdz_para, ONLY: jj_begin, jj_end, jj_nb, is_sequential
[2408]253  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]254  USE ioipsl, ONLY: histbeg
[1910]255
[1864]256  IMPLICIT NONE
[629]257   
[2870]258    CHARACTER*(*), INTENT(IN) :: name
259    INTEGER, INTENT(IN) :: itau0
[1864]260    REAL,INTENT(IN) :: zjulian
261    REAL,INTENT(IN) :: dtime
[2870]262    INTEGER,INTENT(OUT) :: nhori
263    INTEGER,INTENT(OUT) :: nid_day
[766]264
265!$OMP MASTER   
[2160]266#ifndef CPP_IOIPSL_NO_OUTPUT
[2870]267    IF (is_sequential) THEN
[2408]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)
[2870]270    ELSE
[2408]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)
[2870]273    ENDIF
[1864]274#endif
[766]275!$OMP END MASTER
[629]276 
[1864]277  END SUBROUTINE histbeg_phy
[1539]278
[1864]279
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)
[2870]283  USE dimphy, ONLY: klon
284  USE mod_phys_lmdz_para, ONLY: gather, bcast, &
[1910]285                                is_sequential, klon_mpi_begin, klon_mpi_end, &
286                                mpi_rank
[2870]287  USE mod_grid_phy_lmdz, ONLY: klon_glo, nbp_lon, nbp_lat
288  USE ioipsl, ONLY: histbeg
[1910]289
[1864]290  IMPLICIT NONE
[1539]291
[1864]292    REAL,DIMENSION(klon),INTENT(IN) :: rlon
293    REAL,DIMENSION(klon),INTENT(IN) :: rlat
[2870]294    INTEGER, INTENT(IN) :: itau0
[1864]295    REAL,INTENT(IN) :: zjulian
296    REAL,INTENT(IN) :: dtime
[2870]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
[1864]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
[1864]314    REAL, allocatable, DIMENSION(:) :: npplat, npplon
315    REAL, allocatable, DIMENSION(:,:) :: npplat_bounds, npplon_bounds
[2408]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)
[2870]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)
[2870]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)
[2870]338      ENDIF
339     ENDIF
[1539]340!
[2408]341     IF ( tabij(i).LE.nbp_lon) THEN
[1539]342      plat_bounds(i,1)=rlat_glo(tabij(i))
343     ELSE
[2408]344      plat_bounds(i,1)=rlat_glo(tabij(i)-nbp_lon)
[1539]345     ENDIF
[2408]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
[2408]362       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon_glo,zx_lon)
[2870]363       IF ((nbp_lon*nbp_lat).GT.1) THEN
[2408]364       DO i = 1, nbp_lon
[1539]365         zx_lon(i,1) = rlon_glo(i+1)
[2408]366         zx_lon(i,nbp_lat) = rlon_glo(i+1)
[1539]367       ENDDO
[2870]368       ENDIF
[2408]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
[2870]377     IF (ipt(i).EQ.1) THEN
[2408]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))
[2870]380     ENDIF
[1539]381 
[2870]382     IF (ipt(i).EQ.nbp_lon) THEN
[1539]383      plon_bounds(i,2)=360.+zx_lon(1,jpt(i))
[2870]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
[2870]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
[2870]392     ENDIF
[1539]393 
[2870]394     IF (jpt(i).EQ.nbp_lat) THEN
[2408]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
[2870]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
[1910]403
[2160]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)
[1864]408#endif
[2870]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
[2160]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)
[1864]449#endif
[2870]450    ENDIF
[1539]451!$OMP END MASTER
452
[2870]453  END SUBROUTINE histbeg_phy_points
[1864]454
455
456  SUBROUTINE histdef2d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
457
[2870]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
[2408]462    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]463    USE aero_mod, ONLY : naero_tot, name_aero_tau
464
[1864]465    IMPLICIT NONE
466
467    INCLUDE "clesphys.h"
468
469    INTEGER                          :: iff
[2870]470    INTEGER                          :: naero
[1864]471    LOGICAL                          :: lpoint
472    INTEGER, DIMENSION(nfiles)       :: flag_var
[2870]473    CHARACTER(LEN=20)                :: nomvar
[1864]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, &
[2408]491               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
[1864]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
[2870]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
[1864]508
[2870]509    ! Set dryaod_diag=true if at least one of the concerned variables are defined
510    IF (nomvar=='dryod550aer') THEN
511      IF  ( flag_var(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
512    ENDIF
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
[1864]518
[2870]519  END SUBROUTINE histdef2d_old
[1864]520
521  SUBROUTINE histdef3d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
522
[2870]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, &
[1910]527                                   nhorim, zdtime_moy, levmin, levmax, &
528                                   nvertm, nfiles
[2408]529    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1864]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, &
[2408]555               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
[1864]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
[2870]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, &
[1910]574                                   clef_stations, phys_out_filenames, lev_files, &
[2870]575                                   nid_files, nhorim, swaero_diag, dryaod_diag
[2408]576    USE print_control_mod, ONLY: prt_level,lunout
577    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]578    USE aero_mod, ONLY : naero_tot, name_aero_tau
[1910]579#ifdef CPP_XIOS
[2870]580    USE wxios, ONLY: wxios_add_field_to_file
[1910]581#endif
[1864]582    IMPLICIT NONE
583
584    INCLUDE "clesphys.h"
585
586    INTEGER                          :: iff
[2870]587    INTEGER                          :: naero
[1864]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 
617
618#ifdef CPP_XIOS
[2160]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
[2056]627        ENDIF
628      ENDIF
[1864]629#endif
[2160]630#ifndef CPP_IOIPSL_NO_OUTPUT
[1864]631
632       IF ( var%flag(iff)<=lev_files(iff) ) THEN
633          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
[2408]634               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
[1864]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
643#endif
644    ENDIF
645
[2870]646    ! Set swaero_diag=true if at least one of the concerned variables are defined
[2542]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
[2870]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
[1864]665  END SUBROUTINE histdef2d
[2056]666
[1864]667  SUBROUTINE histdef3d (iff,var)
668
[2870]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, &
[1910]673                                   clef_stations, phys_out_filenames, lev_files, &
[2870]674                                   nid_files, nhorim, swaero_diag, dryaod_diag, levmin, &
[1910]675                                   levmax, nvertm
[2408]676    USE print_control_mod, ONLY: prt_level,lunout
677    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1910]678#ifdef CPP_XIOS
[2870]679    USE wxios, ONLY: wxios_add_field_to_file
[1910]680#endif
[1864]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
716
717#ifdef CPP_XIOS
[2160]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
[1864]728#endif
[2160]729#ifndef CPP_IOIPSL_NO_OUTPUT
[1864]730
731       IF ( var%flag(iff)<=lev_files(iff) ) THEN
732          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
[2408]733               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
[1864]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
744#endif
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 
[2870]751    USE ioipsl, ONLY: getin
752    USE phys_output_var_mod, ONLY: nfiles
[2408]753    USE print_control_mod, ONLY: prt_level,lunout
[1864]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 
[1795]767  SUBROUTINE histwrite2d_phy_old(nid,lpoint,name,itau,field)
[2870]768  USE dimphy, ONLY: klon
769  USE mod_phys_lmdz_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
[1910]770                                is_sequential, klon_mpi_begin, klon_mpi_end, &
771                                jj_nb, klon_mpi
[2870]772  USE ioipsl, ONLY: histwrite
[2408]773  USE print_control_mod, ONLY: prt_level,lunout
774  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1795]775  IMPLICIT NONE
[629]776   
[2870]777    INTEGER,INTENT(IN) :: nid
778    LOGICAL,INTENT(IN) :: lpoint
779    CHARACTER*(*), INTENT(IN) :: name
780    INTEGER, INTENT(IN) :: itau
[1864]781    REAL,DIMENSION(:),INTENT(IN) :: field
782    REAL,DIMENSION(klon_mpi) :: buffer_omp
783    INTEGER, allocatable, DIMENSION(:) :: index2d
[2408]784    REAL :: Field2d(nbp_lon,jj_nb)
[1331]785
[2870]786    INTEGER :: ip
787    REAL,ALLOCATABLE,DIMENSION(:) :: fieldok
[1539]788
[2408]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
[2408]795     ALLOCATE(index2d(nbp_lon*jj_nb))
796     ALLOCATE(fieldok(nbp_lon*jj_nb))
[1910]797     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[2408]798     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
[1910]799     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2870]800    ELSE
[1539]801     ALLOCATE(fieldok(npstn))
802     ALLOCATE(index2d(npstn))
803
[2870]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
[2870]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
[2870]818     ENDIF
[1910]819     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[1539]820     CALL histwrite(nid,name,itau,fieldok,npstn,index2d)
[1910]821     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[1539]822!
[2870]823    ENDIF
824    DEALLOCATE(index2d)
825    DEALLOCATE(fieldok)
[1795]826!$OMP END MASTER   
[1331]827
[1795]828 
[2870]829  END SUBROUTINE histwrite2d_phy_old
[1795]830
[1864]831  SUBROUTINE histwrite3d_phy_old(nid,lpoint,name,itau,field)
[2870]832  USE dimphy, ONLY: klon
833  USE mod_phys_lmdz_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
[1910]834                                is_sequential, klon_mpi_begin, klon_mpi_end, &
835                                jj_nb, klon_mpi
[2408]836  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]837  USE ioipsl, ONLY: histwrite
[2408]838  USE print_control_mod, ONLY: prt_level,lunout
[1864]839  IMPLICIT NONE
[629]840   
[2870]841    INTEGER,INTENT(IN) :: nid
842    LOGICAL,INTENT(IN) :: lpoint
843    CHARACTER*(*), INTENT(IN) :: name
844    INTEGER, INTENT(IN) :: itau
[1864]845    REAL,DIMENSION(:,:),INTENT(IN) :: field  ! --> field(klon,:)
846    REAL,DIMENSION(klon_mpi,size(field,2)) :: buffer_omp
[2408]847    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
[1539]848    INTEGER :: ip, n, nlev
[1864]849    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
850    REAL,allocatable, DIMENSION(:,:) :: fieldok
[1539]851
[1795]852
[2408]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)
[2870]859    IF (.NOT.lpoint) THEN
[2408]860     ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
861     ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[1910]862     IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[2408]863     CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
[1910]864     IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2870]865   ELSE
[1539]866      nlev=size(field,2)
867      ALLOCATE(index3d(npstn*nlev))
868      ALLOCATE(fieldok(npstn,nlev))
869
[2870]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
[2870]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
[2870]887      ENDIF
[1910]888      IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
[1539]889      CALL histwrite(nid,name,itau,fieldok,npstn*nlev,index3d)
[1910]890      IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
[2870]891    ENDIF
892  DEALLOCATE(index3d)
893  DEALLOCATE(fieldok)
[766]894!$OMP END MASTER   
[1795]895
[2870]896  END SUBROUTINE histwrite3d_phy_old
[1795]897
898
[1864]899
900
[1795]901! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
902  SUBROUTINE histwrite2d_phy(var,field, STD_iff)
[2870]903  USE dimphy, ONLY: klon
904  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1dto2d_mpi, &
[1910]905                                jj_nb, klon_mpi, klon_mpi_begin, &
906                                klon_mpi_end, is_sequential
[2870]907  USE ioipsl, ONLY: histwrite
908  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
[1910]909                                 nfiles, vars_defined, clef_stations, &
910                                 nid_files
[2408]911  USE print_control_mod, ONLY: prt_level,lunout
912  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1795]913#ifdef CPP_XIOS
[2870]914  USE xios, ONLY: xios_send_field
[1795]915#endif
916
[1864]917
[1795]918  IMPLICIT NONE
[2160]919  include 'clesphys.h'
[1795]920
[1864]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.....
[1795]924     
[1864]925    INTEGER :: iff, iff_beg, iff_end
[2056]926    LOGICAL, SAVE  :: firstx
927!$OMP THREADPRIVATE(firstx)
928
[1864]929    REAL,DIMENSION(klon_mpi) :: buffer_omp
930    INTEGER, allocatable, DIMENSION(:) :: index2d
[2408]931    REAL :: Field2d(nbp_lon,jj_nb)
[1795]932
933    INTEGER :: ip
934    REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
935
[2056]936    IF (prt_level >= 10) THEN
937      WRITE(lunout,*)'Begin histwrite2d_phy for ',trim(var%name)
938    ENDIF
[1795]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
[2870]946      ENDIF
[1795]947
[1864]948  ! On regarde si on est dans la phase de définition ou d'écriture:
[2870]949  IF (.NOT.vars_defined) THEN
[1864]950!$OMP MASTER
951      !Si phase de définition.... on définit
[2160]952      IF (.not. ok_all_xml) THEN
[2870]953      IF (prt_level >= 10) THEN
954      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to define ", trim(var%name)
955      ENDIF
[1864]956      DO iff=iff_beg, iff_end
957         IF (clef_files(iff)) THEN
958            CALL histdef2d(iff, var)
959         ENDIF
960      ENDDO
[2160]961      ENDIF
[1864]962!$OMP END MASTER
963  ELSE
964
965    !Et sinon on.... écrit
[2408]966    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon',1)
[1795]967   
[2870]968    IF (prt_level >= 10) THEn
969      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to gather and write ", trim(var%name)
970    ENDIF
[1910]971   
972    CALL Gather_omp(field,buffer_omp)
[1795]973!$OMP MASTER
974    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
[1910]975
[1795]976! La boucle sur les fichiers:
[2056]977      firstx=.true.
[2160]978
979      IF (ok_all_xml) THEN
980#ifdef CPP_XIOS
[2870]981          IF (prt_level >= 10) THEN
982             write(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)                       
983          ENDIF
[2160]984          CALL xios_send_field(var%name, Field2d)
[2870]985          IF (prt_level >= 10) THEN
986             WRITE (lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ', trim(var%name)                       
987          ENDIF
[2160]988#else
[2408]989        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
[2160]990#endif
991      ELSE 
992        DO iff=iff_beg, iff_end
[1795]993            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
[2056]994
995#ifdef CPP_XIOS
996               IF (firstx) THEN
[2870]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
[2056]1001                  CALL xios_send_field(var%name, Field2d)
1002                  firstx=.false.
1003               ENDIF
1004#endif
1005
[2870]1006                  IF (.NOT.clef_stations(iff)) THEN
[2408]1007                        ALLOCATE(index2d(nbp_lon*jj_nb))
1008                        ALLOCATE(fieldok(nbp_lon*jj_nb))
[2160]1009#ifndef CPP_IOIPSL_NO_OUTPUT
[2408]1010                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,nbp_lon*jj_nb,index2d)
[1864]1011#endif
[2056]1012!#ifdef CPP_XIOS
1013!                        IF (iff == iff_beg) THEN
1014!                          if (prt_level >= 10) then
1015!                            write(lunout,*)"histwrite2d_phy: .NOT.clef_stations(iff) and iff==iff_beg, call xios_send_field"
1016!                          endif
1017!                          CALL xios_send_field(var%name, Field2d)
1018!                        ENDIF
1019!#endif
[1795]1020                  ELSE
1021                        ALLOCATE(fieldok(npstn))
1022                        ALLOCATE(index2d(npstn))
1023
1024                        IF (is_sequential) THEN
[1910]1025                          DO ip=1, npstn
1026                            fieldok(ip)=buffer_omp(nptabij(ip))
1027                          ENDDO
1028                        ELSE
[1795]1029                              DO ip=1, npstn
[1910]1030                                write(lunout,*)'histwrite2d_phy is_sequential npstn ip namenptabij',npstn,ip,var%name,nptabij(ip)
[1795]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
[1910]1036                       ENDIF ! of IF (is_sequential)
[2160]1037#ifndef CPP_IOIPSL_NO_OUTPUT
[2870]1038                       IF (prt_level >= 10) THEn
[1910]1039                         write(lunout,*)"histwrite2d_phy: clef_stations(iff) and iff==iff_beg, call wxios_write_2D"
[2870]1040                       ENDIF
[1795]1041                       CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn,index2d)
[1864]1042#endif
[1910]1043                  ENDIF ! of IF(.NOT.clef_stations(iff))
[1795]1044                 
[2870]1045                DEALLOCATE(index2d)
1046                DEALLOCATE(fieldok)
[1795]1047            ENDIF !levfiles
[2160]1048        ENDDO ! of DO iff=iff_beg, iff_end
1049      ENDIF
[1795]1050!$OMP END MASTER   
[1864]1051  ENDIF ! vars_defined
[1910]1052  IF (prt_level >= 10) WRITE(lunout,*)'End histwrite2d_phy ',trim(var%name)
[1795]1053  END SUBROUTINE histwrite2d_phy
1054
1055
1056! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
[1864]1057  SUBROUTINE histwrite3d_phy(var, field, STD_iff)
[2870]1058  USE dimphy, ONLY: klon, klev
1059  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1dto2d_mpi, &
[1910]1060                                jj_nb, klon_mpi, klon_mpi_begin, &
1061                                klon_mpi_end, is_sequential
[2870]1062  USE ioipsl, ONLY: histwrite
1063  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
[1910]1064                                 nfiles, vars_defined, clef_stations, &
1065                                 nid_files
[2408]1066  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[1795]1067#ifdef CPP_XIOS
[2870]1068  USE xios, ONLY: xios_send_field
[1795]1069#endif
[2408]1070  USE print_control_mod, ONLY: prt_level,lunout
[1795]1071
1072  IMPLICIT NONE
[2160]1073  include 'clesphys.h'
[1795]1074
[1864]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     
1079    INTEGER :: iff, iff_beg, iff_end
[2056]1080    LOGICAL, SAVE  :: firstx
1081!$OMP THREADPRIVATE(firstx)
[1795]1082    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
[2408]1083    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
[2056]1084    INTEGER :: ip, n, nlev, nlevx
[1795]1085    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1086    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1087
[1910]1088  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d ',var%name
[1795]1089
[1864]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
[2870]1097      ENDIF
[1795]1098
[1864]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
1102!$OMP MASTER
1103      DO iff=iff_beg, iff_end
1104        IF (clef_files(iff)) THEN
1105          CALL histdef3d(iff, var)
1106        ENDIF
1107      ENDDO
1108!$OMP END MASTER
1109  ELSE
1110    !Et sinon on.... écrit
[2408]1111    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
[1864]1112    nlev=SIZE(field,2)
[2870]1113    IF (nlev.EQ.klev+1) THEN
[2056]1114        nlevx=klev
[2870]1115    ELSE
[2056]1116        nlevx=nlev
[2870]1117    ENDIF
[1795]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
[2056]1125     firstx=.true.
[2160]1126
1127      IF (ok_all_xml) THEN
1128#ifdef CPP_XIOS
[2870]1129          IF (prt_level >= 10) THEN
[2160]1130             write(lunout,*)'Dans iophy histwrite3D,var%name ',&
1131                             trim(var%name)                       
[2870]1132          ENDIF
[2160]1133          CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
1134#else
[2408]1135        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
[2160]1136#endif
1137      ELSE 
1138
1139
[1864]1140     DO iff=iff_beg, iff_end
[1795]1141            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
[2056]1142#ifdef CPP_XIOS
1143              IF (firstx) THEN
[2870]1144                IF (prt_level >= 10) THEn
1145                  WRITE (lunout,*)'Dans iophy, histwrite3D iff nlev klev firstx', &
[2056]1146                                  iff,nlev,klev, firstx                       
[2870]1147                  WRITE (lunout,*)'histwrite3d_phy: call xios_send_field for ', &
[2056]1148                                  trim(var%name), ' with iim jjm nlevx = ', &
[2408]1149                                  nbp_lon,jj_nb,nlevx
[2870]1150                ENDIF
[2056]1151                CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
1152                            firstx=.false.
1153              ENDIF
1154#endif
[1795]1155                IF (.NOT.clef_stations(iff)) THEN
[2408]1156                        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
1157                        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[1864]1158
[2160]1159#ifndef CPP_IOIPSL_NO_OUTPUT
[2408]1160                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,nbp_lon*jj_nb*nlev,index3d)
[1864]1161#endif
1162
[2056]1163!#ifdef CPP_XIOS
1164!                        IF (iff == 1) THEN
1165!                              CALL xios_send_field(var%name, Field3d(:,:,1:klev))
1166!                        ENDIF
1167!#endif
1168!                       
[1795]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
[2160]1190#ifndef CPP_IOIPSL_NO_OUTPUT
[1795]1191                        CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn*nlev,index3d)
[1864]1192#endif
[1795]1193                  ENDIF
[2870]1194                  DEALLOCATE(index3d)
1195                  DEALLOCATE(fieldok)
[1795]1196            ENDIF
1197      ENDDO
[2160]1198      ENDIF
[1795]1199!$OMP END MASTER   
[1864]1200  ENDIF ! vars_defined
[1910]1201  IF (prt_level >= 10) write(lunout,*)'End histrwrite3d ',var%name
[1795]1202  END SUBROUTINE histwrite3d_phy
1203 
[1864]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)
[2870]1208  USE dimphy, ONLY: klon
1209  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1Dto2D_mpi, &
[1910]1210                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1211                                jj_nb, klon_mpi
[2408]1212  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
[2870]1213  USE xios, ONLY: xios_send_field
[2408]1214  USE print_control_mod, ONLY: prt_level,lunout
[1864]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
[2408]1223    REAL :: Field2d(nbp_lon,jj_nb)
[1864]1224
1225    INTEGER :: ip
1226    REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
1227
[1910]1228    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',field_name
[1864]1229
1230    !Et sinon on.... écrit
[2408]1231    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
[1864]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
[2408]1242        ALLOCATE(index2d(nbp_lon*jj_nb))
1243        ALLOCATE(fieldok(nbp_lon*jj_nb))
[1864]1244
1245
[2056]1246        CALL xios_send_field(field_name, Field2d)
[1864]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                 
[2870]1268    DEALLOCATE(index2d)
1269    DEALLOCATE(fieldok)
[1864]1270!$OMP END MASTER   
1271
[1910]1272  IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',field_name
[1864]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)
[2870]1278  USE dimphy, ONLY: klon, klev
1279  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1Dto2D_mpi, &
[1910]1280                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1281                                jj_nb, klon_mpi
[2870]1282  USE xios, ONLY: xios_send_field
[2408]1283  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
1284  USE print_control_mod, ONLY: prt_level,lunout
[1864]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
[2408]1292    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
[1864]1293    INTEGER :: ip, n, nlev
1294    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1295    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1296
[1910]1297  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d_xios ',field_name
[1864]1298
1299    !Et on.... écrit
[2408]1300    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
[1864]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
[2408]1313        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
1314        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
[2056]1315        CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
[1864]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
[2870]1339    DEALLOCATE(index3d)
1340    DEALLOCATE(fieldok)
[1864]1341!$OMP END MASTER   
1342
[1910]1343  IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',field_name
[1864]1344  END SUBROUTINE histwrite3d_xios
[2669]1345
1346#ifdef CPP_XIOS
1347  SUBROUTINE histwrite0d_xios(field_name, field)
[2870]1348  USE xios, ONLY: xios_send_field
[2669]1349  IMPLICIT NONE
1350
1351    CHARACTER(LEN=*), INTENT(IN) :: field_name
1352    REAL, INTENT(IN) :: field ! --> scalar
1353
1354!$OMP MASTER
1355   CALL xios_send_field(field_name, field)
1356!$OMP END MASTER
1357
1358  END SUBROUTINE histwrite0d_xios
[1864]1359#endif
[2669]1360
1361#endif
[629]1362end module iophy
Note: See TracBrowser for help on using the repository browser.