source: LMDZ6/trunk/libf/phydev/iophy.F90 @ 5040

Last change on this file since 5040 was 4729, checked in by fhourdin, 13 months ago

Corrections phydev.

  • 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:keywords set to Id
File size: 12.8 KB
Line 
1!
2! $Id: iophy.F90 4729 2023-10-22 09:07:29Z evignon $
3!
4module iophy
5 
6! abd  REAL,private,allocatable,dimension(:),save :: io_lat
7! abd  REAL,private,allocatable,dimension(:),save :: io_lon
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 
14
15! interfaces for both IOIPSL and XIOS
16  INTERFACE histwrite_phy
17    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_xios,histwrite3d_xios
18  END INTERFACE
19
20! interfaces for both IOIPSL and XIOS
21  INTERFACE histbeg_phy_all
22    MODULE PROCEDURE histbeg_phy, histbeg_phyxios
23  END INTERFACE
24
25contains
26
27  subroutine init_iophy_new(rlat,rlon)
28  USE dimphy, only: klon
29  USE mod_phys_lmdz_para, only: gather, bcast, &
30                                jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
31                                mpi_size, mpi_rank, klon_mpi, &
32                                is_sequential, is_south_pole_dyn
33  USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo
34  USE print_control_mod, ONLY: lunout, prt_level
35  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
36#ifdef CPP_IOIPSL
37  USE ioipsl, only: flio_dom_set
38#endif
39  use wxios, only: wxios_domain_param, using_xios
40  implicit none
41    real,dimension(klon),intent(in) :: rlon
42    real,dimension(klon),intent(in) :: rlat
43
44    REAL,dimension(klon_glo)        :: rlat_glo
45    REAL,dimension(klon_glo)        :: rlon_glo
46   
47    INTEGER,DIMENSION(2) :: ddid
48    INTEGER,DIMENSION(2) :: dsg
49    INTEGER,DIMENSION(2) :: dsl
50    INTEGER,DIMENSION(2) :: dpf
51    INTEGER,DIMENSION(2) :: dpl
52    INTEGER,DIMENSION(2) :: dhs
53    INTEGER,DIMENSION(2) :: dhe
54    INTEGER :: i   
55    integer :: data_ibegin,data_iend
56
57    CALL gather(rlat,rlat_glo)
58    CALL bcast(rlat_glo)
59    CALL gather(rlon,rlon_glo)
60    CALL bcast(rlon_glo)
61   
62!$OMP MASTER 
63    ALLOCATE(io_lat(nbp_lat))
64    io_lat(1)=rlat_glo(1)
65    io_lat(nbp_lat)=rlat_glo(klon_glo)
66    IF ((nbp_lon*nbp_lat) > 1) then
67      DO i=2,nbp_lat-1
68        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
69      ENDDO
70    ENDIF
71
72    ALLOCATE(io_lon(nbp_lon))
73    IF ((nbp_lon*nbp_lat) > 1) THEN
74      io_lon(:)=rlon_glo(2:nbp_lon+1)
75    ELSE
76      io_lon(1)=rlon_glo(1)
77    ENDIF
78!! (I) dtnb   : total number of domains
79!! (I) dnb    : domain number
80!! (I) did(:) : distributed dimensions identifiers
81!!              (up to 5 dimensions are supported)
82!! (I) dsg(:) : total number of points for each dimension
83!! (I) dsl(:) : local number of points for each dimension
84!! (I) dpf(:) : position of first local point for each dimension
85!! (I) dpl(:) : position of last local point for each dimension
86!! (I) dhs(:) : start halo size for each dimension
87!! (I) dhe(:) : end halo size for each dimension
88!! (C) cdnm   : Model domain definition name.
89!!              The names actually supported are :
90!!              "BOX", "APPLE", "ORANGE".
91!!              These names are case insensitive.
92    ddid=(/ 1,2 /)
93    dsg=(/ nbp_lon, nbp_lat /)
94    dsl=(/ nbp_lon, jj_nb /)
95    dpf=(/ 1,jj_begin /)
96    dpl=(/ nbp_lon, jj_end /)
97    dhs=(/ ii_begin-1,0 /)
98    if (mpi_rank==mpi_size-1) then
99      dhe=(/0,0/)
100    else
101      dhe=(/ nbp_lon-ii_end,0 /) 
102    endif
103   
104#ifndef CPP_IOIPSL_NO_OUTPUT
105    call flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
106                      'APPLE',phys_domain_id)
107#endif
108    IF (using_xios) THEN
109      ! Set values for the mask:
110      IF (mpi_rank == 0) THEN
111          data_ibegin = 0
112      ELSE
113          data_ibegin = ii_begin - 1
114      END IF
115
116      IF (mpi_rank == mpi_size-1) THEN
117          data_iend = nbp_lon
118      ELSE
119          data_iend = ii_end + 1
120      END IF
121
122      if (prt_level>=10) then
123        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
124        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
125        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
126        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
127        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
128      endif
129
130      ! Initialize the XIOS domain coreesponding to this process:
131       CALL wxios_domain_param("dom_glo")
132!      CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
133!                              1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
134!                              klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
135!                              io_lat, io_lon,is_south_pole_dyn,mpi_rank)
136    ENDIF
137!$OMP END MASTER
138     
139  END SUBROUTINE init_iophy_new
140 
141!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
142 
143  subroutine histbeg_phy(name,itau0,zjulian,dtime,nhori,nid_day)
144  USE mod_phys_lmdz_para, only: is_sequential, jj_begin, jj_end, jj_nb
145  use ioipsl, only: histbeg
146  USE print_control_mod, ONLY: prt_level, lunout
147  USE mod_grid_phy_lmdz, ONLY: nbp_lon
148  implicit none
149   
150    character*(*), intent(IN) :: name
151    integer, intent(in) :: itau0
152    real,intent(in) :: zjulian
153    real,intent(in) :: dtime
154    integer,intent(out) :: nhori
155    integer,intent(out) :: nid_day
156
157!$OMP MASTER   
158    if (is_sequential) then
159      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
160                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
161    else
162      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
163                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
164    endif
165!$OMP END MASTER
166 
167  end subroutine histbeg_phy
168
169!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
170
171
172! SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
173 SUBROUTINE histbeg_phyxios(name,ffreq,lev)
174  USE mod_phys_lmdz_para, only: is_using_mpi, is_mpi_root
175  use wxios, only: wxios_add_file
176  IMPLICIT NONE
177   
178    character*(*), INTENT(IN) :: name
179!    integer, INTENT(IN) :: itau0
180!    REAL,INTENT(IN) :: zjulian
181!    REAL,INTENT(IN) :: dtime
182    character(LEN=*), INTENT(IN) :: ffreq
183    INTEGER,INTENT(IN) :: lev
184!    integer,intent(out) :: nhori
185!    integer,intent(out) :: nid_day
186
187!$OMP MASTER   
188
189    ! ug OMP en chantier...
190    IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
191        ! ug Création du fichier
192        CALL wxios_add_file(name, ffreq, lev)
193    END IF
194
195!$OMP END MASTER
196 
197  END SUBROUTINE histbeg_phyxios
198
199
200!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
201 
202  subroutine histwrite2d_phy(nid,lpoint,name,itau,field)
203  USE dimphy, only: klon
204  USE mod_phys_lmdz_para, only: Gather_omp, grid1Dto2D_mpi, &
205                                is_sequential, klon_mpi_begin, klon_mpi_end, &
206                                jj_nb, klon_mpi
207  USE ioipsl, only: histwrite
208  USE mod_grid_phy_lmdz, ONLY: nbp_lon
209  implicit none
210   
211    integer,intent(in) :: nid
212    logical,intent(in) :: lpoint
213    character*(*), intent(IN) :: name
214    integer, intent(in) :: itau
215    real,dimension(:),intent(in) :: field
216    REAL,dimension(klon_mpi) :: buffer_omp
217    INTEGER, allocatable, dimension(:) :: index2d
218    REAL :: Field2d(nbp_lon,jj_nb)
219
220    integer :: ip
221    real,allocatable,dimension(:) :: fieldok
222
223    IF (size(field)/=klon) CALL abort_physic('iophy::histwrite2d','Field first dimension not equal to klon',1)
224   
225    CALL Gather_omp(field,buffer_omp)   
226!$OMP MASTER
227    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
228    if(.NOT.lpoint) THEN
229     ALLOCATE(index2d(nbp_lon*jj_nb))
230     ALLOCATE(fieldok(nbp_lon*jj_nb))
231     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
232    else
233     ALLOCATE(fieldok(npstn))
234     ALLOCATE(index2d(npstn))
235
236     if(is_sequential) then
237!     klon_mpi_begin=1
238!     klon_mpi_end=klon
239      DO ip=1, npstn
240       fieldok(ip)=buffer_omp(nptabij(ip))
241      ENDDO
242     else
243      DO ip=1, npstn
244!     print*,'histwrite2d is_sequential npstn ip name nptabij',npstn,ip,name,nptabij(ip)
245       IF(nptabij(ip).GE.klon_mpi_begin.AND. &
246          nptabij(ip).LE.klon_mpi_end) THEN
247         fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
248       ENDIF
249      ENDDO
250     endif
251     CALL histwrite(nid,name,itau,fieldok,npstn,index2d)
252!
253    endif
254    deallocate(index2d)
255    deallocate(fieldok)
256!$OMP END MASTER   
257  end subroutine histwrite2d_phy
258
259!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
260
261  subroutine histwrite3d_phy(nid,lpoint,name,itau,field)
262  USE dimphy, only: klon
263  USE mod_phys_lmdz_para, only: Gather_omp, grid1Dto2D_mpi, &
264                                is_sequential, klon_mpi_begin, klon_mpi_end, &
265                                jj_nb, klon_mpi
266  USE ioipsl, only: histwrite
267  USE mod_grid_phy_lmdz, ONLY: nbp_lon
268  implicit none
269   
270    integer,intent(in) :: nid
271    logical,intent(in) :: lpoint
272    character*(*), intent(IN) :: name
273    integer, intent(in) :: itau
274    real,dimension(:,:),intent(in) :: field  ! --> field(klon,:)
275    REAL,dimension(klon_mpi,size(field,2)) :: buffer_omp
276    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
277    INTEGER :: ip, n, nlev
278    INTEGER, ALLOCATABLE, dimension(:) :: index3d
279    real,allocatable, dimension(:,:) :: fieldok
280
281    IF (size(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first dimension not equal to klon',1)
282    nlev=size(field,2)
283
284    CALL Gather_omp(field,buffer_omp)
285!$OMP MASTER
286    CALL grid1Dto2D_mpi(buffer_omp,field3d)
287    if(.NOT.lpoint) THEN
288     ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
289     ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
290     CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
291    else
292      nlev=size(field,2)
293      ALLOCATE(index3d(npstn*nlev))
294      ALLOCATE(fieldok(npstn,nlev))
295
296      if(is_sequential) then
297!      klon_mpi_begin=1
298!      klon_mpi_end=klon
299       DO n=1, nlev
300       DO ip=1, npstn
301        fieldok(ip,n)=buffer_omp(nptabij(ip),n)
302       ENDDO
303       ENDDO
304      else
305       DO n=1, nlev
306       DO ip=1, npstn
307        IF(nptabij(ip).GE.klon_mpi_begin.AND. &
308         nptabij(ip).LE.klon_mpi_end) THEN
309         fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
310        ENDIF
311       ENDDO
312       ENDDO
313      endif
314      CALL histwrite(nid,name,itau,fieldok,npstn*nlev,index3d)
315    endif
316  deallocate(index3d)
317  deallocate(fieldok)
318!$OMP END MASTER   
319  end subroutine histwrite3d_phy
320
321!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
322
323! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
324
325  SUBROUTINE histwrite2d_xios(field_name,field)
326  USE dimphy, only: klon
327  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
328                                jj_nb, klon_mpi
329  USE lmdz_xios, only: xios_send_field
330  USE print_control_mod, ONLY: prt_level, lunout
331  USE mod_grid_phy_lmdz, ONLY: nbp_lon
332  IMPLICIT NONE
333
334    CHARACTER(LEN=*), INTENT(IN) :: field_name
335    REAL, DIMENSION(:), INTENT(IN) :: field
336     
337    REAL,DIMENSION(klon_mpi) :: buffer_omp
338    REAL :: Field2d(nbp_lon,jj_nb)
339
340    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',trim(field_name)
341
342    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
343   
344    CALL Gather_omp(field,buffer_omp)   
345!$OMP MASTER
346    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
347   
348    CALL xios_send_field(field_name, Field2d)
349!$OMP END MASTER   
350
351    IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',trim(field_name)
352  END SUBROUTINE histwrite2d_xios
353
354!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
355
356! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
357
358  SUBROUTINE histwrite3d_xios(field_name, field)
359  USE dimphy, only: klon, klev
360  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
361                                jj_nb, klon_mpi
362  USE lmdz_xios, only: xios_send_field
363  USE print_control_mod, ONLY: prt_level,lunout
364  USE mod_grid_phy_lmdz, ONLY: nbp_lon
365
366  IMPLICIT NONE
367
368    CHARACTER(LEN=*), INTENT(IN) :: field_name
369    REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
370
371    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
372    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
373    INTEGER :: ip, n, nlev
374
375  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d_xios ',trim(field_name)
376
377    !Et on.... écrit
378    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
379    nlev=SIZE(field,2)
380
381
382    CALL Gather_omp(field,buffer_omp)
383!$OMP MASTER
384    CALL grid1Dto2D_mpi(buffer_omp,field3d)
385
386    CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
387!$OMP END MASTER   
388
389    IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',trim(field_name)
390  END SUBROUTINE histwrite3d_xios
391
392end module iophy
Note: See TracBrowser for help on using the repository browser.