source: trunk/LMDZ.TITAN/libf/phytitan/xios_output_mod.F90 @ 1862

Last change on this file since 1862 was 1626, checked in by emillour, 8 years ago

Generic GCM:

Improving XIOS outputs, add the scalar case.
EM

File size: 8.5 KB
Line 
1MODULE xios_output_mod
2
3 IMPLICIT NONE
4 
5 INTEGER,PRIVATE,SAVE :: time_it=0 ! store number of iterations with calls to XIOS since start
6! does not need to be threadprivate; managed by omp master
7
8 CHARACTER(LEN=*), PARAMETER :: context_id= "LMDZ" ! same as in context_lmdz_physics.xml
9 
10#ifdef CPP_XIOS
11
12 INTERFACE send_xios_field
13    MODULE PROCEDURE histwrite0d_xios,histwrite2d_xios,histwrite3d_xios
14 END INTERFACE
15 
16
17CONTAINS
18
19  SUBROUTINE initialize_xios_output(day,timeofday,dtphys,daysec,&
20                                    presnivs,pseudoalt)
21!  USE mod_phys_lmdz_para, only: gather, bcast, &
22!                                jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
23!                                mpi_size, mpi_rank, klon_mpi, &
24!                                is_sequential, is_south_pole_dyn
25  USE mod_phys_lmdz_para, ONLY: jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
26                                mpi_size, mpi_rank, klon_mpi, &
27                                is_sequential, is_south_pole_dyn
28  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
29  USE print_control_mod, ONLY: lunout, prt_level
30  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
31  USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
32  USE nrtype, ONLY: pi
33  USE wxios
34  IMPLICIT NONE
35 
36  REAL,INTENT(IN) :: day ! Number of elapsed sols since reference Ls=0.
37  REAL,INTENT(IN) :: timeofday ! "Universal time", given as fraction of sol (e.g.: 0.5 for noon).
38  REAL,INTENT(IN) :: dtphys ! physics time step (s)
39  REAL,INTENT(IN) :: daysec ! lengthof a standard day (s)
40  REAL,INTENT(IN) :: presnivs(:) ! vertical grid approximate pressure (Pa)
41  REAL,INTENT(IN) :: pseudoalt(:) ! vertical grid approximate altitude (km)
42 
43 
44  INTEGER :: data_ibegin, data_iend
45  TYPE(xios_duration) :: timestep
46  TYPE(xios_date) :: time_origin
47  TYPE(xios_date) :: start_date
48 
49!$OMP BARRIER
50!$OMP MASTER
51
52    ! 1. Declare available vertical axes to be used in output files:
53    IF (prt_level>=10) WRITE(lunout,*) "initialize_xios_output: call xios_set_axis_attr for presnivs"
54    CALL xios_set_axis_attr("presnivs", n_glo=size(presnivs), value=presnivs,&
55                            unit="Pa",positive="down")
56    IF (prt_level>=10) WRITE(lunout,*) "initialize_xios_output: call xios_set_axis_attr for altitude"
57    CALL xios_set_axis_attr("altitude", n_glo=size(pseudoalt), value=pseudoalt,&
58                            unit="km",positive="up")
59   
60    ! 2. Declare horizontal domain
61    ! Set values for the mask:
62    IF (mpi_rank == 0) THEN
63        data_ibegin = 0
64    ELSE
65        data_ibegin = ii_begin - 1
66    END IF
67
68    IF (mpi_rank == mpi_size-1) THEN
69        data_iend = nbp_lon
70    ELSE
71        data_iend = ii_end + 1
72    END IF
73
74    if (prt_level>=10) then
75      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
76      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
77      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
78      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
79      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
80    endif
81
82    ! Initialize the XIOS domain coreesponding to this process:
83    if (prt_level>=10) write(lunout,*) "initialize_xios_output: call wxios_domain_param"
84    CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
85                            1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
86                            klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
87                            lat_reg*(180./pi), lon_reg*(180./pi),                       &
88                            is_south_pole_dyn,mpi_rank)
89
90    ! 3. Declare calendar and time step
91    if (prt_level>=10) write(lunout,*) "initialize_xios_output: build calendar"
92    timestep%second=dtphys
93    ! time origin of the simulation (default: 1st year/1st month/1st day, Ls=0)
94    time_origin=xios_date(1,1,1,0,0,0)
95    ! start date of the simulation (i.e time elapsed since last Ls=0)
96    start_date=xios_date(1,1,1,0,0,nint((day+timeofday)*daysec))
97    CALL xios_define_calendar(type="user_defined", &
98                              timestep=timestep, &
99                              day_length=nint(daysec), &
100                              start_date=start_date, &
101                              time_origin=time_origin, &
102                              month_lengths=[30,30,30,30,30,30,30,30,30,30,30,30])
103   
104    ! 4. Finalize the context:
105    if (prt_level>=10) write(*,*) "initialize_xios_output: call wxios_closedef"
106    CALL wxios_closedef()
107
108!$OMP END MASTER
109!$OMP BARRIER
110 
111  END SUBROUTINE initialize_xios_output
112
113!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
114
115  SUBROUTINE finalize_xios_output
116  USE xios
117  IMPLICIT NONE
118!$OMP BARRIER   
119!$OMP MASTER
120    CALL xios_context_finalize
121!$OMP END MASTER   
122!$OMP BARRIER   
123 
124  END SUBROUTINE finalize_xios_output
125
126!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
127
128  SUBROUTINE update_xios_timestep
129  USE xios
130  IMPLICIT NONE
131    CALL set_xios_context
132!$OMP MASTER
133    time_it=time_it+1
134    CALL xios_update_calendar(time_it)
135!$OMP END MASTER   
136  END SUBROUTINE update_xios_timestep
137
138!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
139
140  SUBROUTINE set_xios_context
141  USE XIOS
142  IMPLICIT NONE
143    TYPE(xios_context) :: ctx_hdl
144
145!$OMP MASTER
146    CALL xios_get_handle(context_id,ctx_hdl)
147    CALL xios_set_current_context(ctx_hdl)
148!$OMP END MASTER   
149  END SUBROUTINE set_xios_context
150
151!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
152
153  SUBROUTINE histwrite0d_xios(field_name,field)
154  USE xios, ONLY: xios_send_field
155  USE print_control_mod, ONLY: prt_level, lunout
156  IMPLICIT NONE
157 
158    CHARACTER(LEN=*), INTENT(IN) :: field_name
159    REAL, INTENT(IN) :: field
160   
161    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite0d_xios ',trim(field_name)
162   
163!$OMP MASTER
164    CALL xios_send_field(field_name,field)
165!$OMP END MASTER
166   
167    IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite0d_xios ',trim(field_name)
168   
169  END SUBROUTINE histwrite0d_xios
170
171!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
172
173  SUBROUTINE histwrite2d_xios(field_name,field)
174  USE dimphy, only: klon
175  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
176                                jj_nb, klon_mpi
177  USE xios, only: xios_send_field
178  USE print_control_mod, ONLY: prt_level, lunout
179  USE mod_grid_phy_lmdz, ONLY: nbp_lon
180  IMPLICIT NONE
181
182    CHARACTER(LEN=*), INTENT(IN) :: field_name
183    REAL, DIMENSION(:), INTENT(IN) :: field
184     
185    REAL,DIMENSION(klon_mpi) :: buffer_omp
186    REAL :: Field2d(nbp_lon,jj_nb)
187
188    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',trim(field_name)
189
190    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
191   
192    CALL Gather_omp(field,buffer_omp)   
193!$OMP MASTER
194    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
195   
196    CALL xios_send_field(field_name, Field2d)
197!$OMP END MASTER   
198
199    IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',trim(field_name)
200  END SUBROUTINE histwrite2d_xios
201
202!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
203
204  SUBROUTINE histwrite3d_xios(field_name, field)
205  USE dimphy, only: klon, klev
206  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
207                                jj_nb, klon_mpi
208  USE xios, only: xios_send_field
209  USE print_control_mod, ONLY: prt_level,lunout
210  USE mod_grid_phy_lmdz, ONLY: nbp_lon
211
212  IMPLICIT NONE
213
214    CHARACTER(LEN=*), INTENT(IN) :: field_name
215    REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
216
217    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
218    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
219    INTEGER :: ip, n, nlev
220
221  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d_xios ',trim(field_name)
222
223    !Et on.... écrit
224    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
225    nlev=SIZE(field,2)
226
227
228    CALL Gather_omp(field,buffer_omp)
229!$OMP MASTER
230    CALL grid1Dto2D_mpi(buffer_omp,field3d)
231
232    CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
233!$OMP END MASTER   
234
235    IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',trim(field_name)
236  END SUBROUTINE histwrite3d_xios
237
238#endif
239
240END MODULE xios_output_mod
Note: See TracBrowser for help on using the repository browser.