source: trunk/LMDZ.MARS/libf/phymars/xios_output_mod.F90 @ 2514

Last change on this file since 2514 was 2514, checked in by romain.vande, 4 years ago

Mars Dynamico : _ update of r2507: correct ztime_fin for dynamico

_ Test for no writting Diagfi for Dynamico
_ Correction for Xios output : Change of calendar : start_date=0 as a diagfi, timestep for output physic=1s, day_length=ndtphys, it is needed to have output in days in the xml to have the correct time

File size: 9.7 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,mlayer)
21  USE mod_phys_lmdz_para, ONLY: jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
22                                mpi_size, mpi_rank, klon_mpi, &
23                                is_sequential, is_south_pole_dyn
24  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid_type, unstructured
25  USE print_control_mod, ONLY: lunout, prt_level
26  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
27  USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
28  USE nrtype, ONLY: pi
29#ifdef CPP_XIOS
30  USE xios
31#endif
32  USE wxios, ONLY: wxios_domain_param, wxios_domain_param_unstructured, wxios_closedef
33  IMPLICIT NONE
34 
35  REAL,INTENT(IN) :: day ! Number of elapsed sols since reference Ls=0.
36  REAL,INTENT(IN) :: timeofday ! "Universal time", given as fraction of sol (e.g.: 0.5 for noon).
37  REAL,INTENT(IN) :: dtphys ! physics time step (s)
38  REAL,INTENT(IN) :: daysec ! lengthof a standard day (s)
39  REAL,INTENT(IN) :: presnivs(:) ! vertical grid approximate pressure (Pa)
40  REAL,INTENT(IN) :: pseudoalt(:) ! vertical grid approximate altitude (km)
41  REAL,INTENT(IN) :: mlayer(:) ! soil layer depth at intermediate level (m)
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    IF (prt_level>=10) WRITE(lunout,*) "initialize_xios_output: call xios_set_axis_attr for soil"
60    CALL xios_set_axis_attr("soil_layers", n_glo=size(mlayer), value=mlayer,&
61                            unit="m",positive="down")
62   
63    ! 2. Declare horizontal domain
64    ! Set values for the mask:
65!    IF (mpi_rank == 0) THEN
66!        data_ibegin = 0
67!    ELSE
68!        data_ibegin = ii_begin - 1
69!    END IF
70
71!    IF (mpi_rank == mpi_size-1) THEN
72!        data_iend = nbp_lon
73!    ELSE
74!        data_iend = ii_end + 1
75!    END IF
76
77!    if (prt_level>=10) then
78!      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
79!      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
80!      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
81!      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
82!      write(lunout,*) "initialize_xios_output: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
83!    endif
84
85!$OMP END MASTER
86!$OMP BARRIER
87    ! Initialize the XIOS domain coreesponding to this process:
88    if (prt_level>=10) write(lunout,*) "initialize_xios_output: call wxios_domain_param"
89!    CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
90!                            1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
91!                            klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
92!                            lat_reg*(180./pi), lon_reg*(180./pi),                       &
93!                            is_south_pole_dyn,mpi_rank)
94
95    IF (grid_type==unstructured) THEN
96      CALL wxios_domain_param_unstructured("dom_glo")
97    ELSE
98      CALL wxios_domain_param("dom_glo")
99    ENDIF
100
101!$OMP MASTER
102    ! 3. Declare calendar and time step
103    if (prt_level>=10) then
104     write(lunout,*) "initialize_xios_output: build calendar"
105    endif
106    timestep%second=1
107    if (nint(dtphys).ne.dtphys) then
108      write(*,*) "initialize_xios_output: warning physics timestep is not an integer!"
109    endif
110    if (nint(daysec).ne.daysec) then
111      write(*,*) "initialize_xios_output: warning day length is not an integer!"
112    endif
113    ! Important: do no operations involving dates and calendars
114    ! before defining the calendar!
115    CALL xios_define_calendar(type="user_defined", &
116                              timestep=timestep, &
117                              day_length=nint(daysec/dtphys), &
118                              month_lengths=[61,66,66,65,60,54,50,46,47,47,51,56])
119    !NB: it would make more sense to define months and their length in the
120    ! xml files and not to have them hard coded here.... to be improved...
121   
122    ! time origin of the simulation (default: 1st year/1st month/1st day, Ls=0)
123    time_origin=xios_date(1,1,1,0,0,0)
124    CALL xios_set_time_origin(time_origin=time_origin)
125!    if (prt_level>=10) then
126     write(lunout,*) "initialize_xios_output: time_origin=",time_origin
127!    endif
128
129    ! Now define the start time of this simulation
130    ! NB: we substract dtphys because we want to set the origin of the time axis
131    start_date=time_origin
132    call xios_set_start_date(start_date=start_date)
133    if (prt_level>=10) then
134     write(lunout,*) "initialize_xios_output: start_date=",start_date
135    endif
136
137    ! 4. Finalize the context:
138    if (prt_level>=10) write(*,*) "initialize_xios_output: call wxios_closedef"
139    CALL wxios_closedef()
140    if (prt_level>=10) write(*,*) "initialize_xios_output: after call wxios_closedef"
141
142!$OMP END MASTER
143!$OMP BARRIER
144 
145  END SUBROUTINE initialize_xios_output
146
147!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
148
149  SUBROUTINE finalize_xios_output
150  USE xios
151  IMPLICIT NONE
152!$OMP BARRIER   
153!$OMP MASTER
154    CALL xios_context_finalize
155!$OMP END MASTER   
156!$OMP BARRIER   
157 
158  END SUBROUTINE finalize_xios_output
159
160!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
161
162  SUBROUTINE update_xios_timestep
163  USE xios
164  IMPLICIT NONE
165    CALL set_xios_context
166!$OMP MASTER
167    time_it=time_it+1
168    CALL xios_update_calendar(time_it)
169!$OMP END MASTER   
170  END SUBROUTINE update_xios_timestep
171
172!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
173
174  SUBROUTINE set_xios_context
175  USE XIOS
176  IMPLICIT NONE
177    TYPE(xios_context) :: ctx_hdl
178
179!$OMP MASTER
180    CALL xios_get_handle(context_id,ctx_hdl)
181    CALL xios_set_current_context(ctx_hdl)
182!$OMP END MASTER   
183  END SUBROUTINE set_xios_context
184
185!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
186
187  SUBROUTINE histwrite0d_xios(field_name,field)
188  USE xios, ONLY: xios_send_field
189  USE print_control_mod, ONLY: prt_level, lunout
190  IMPLICIT NONE
191 
192    CHARACTER(LEN=*), INTENT(IN) :: field_name
193    REAL, INTENT(IN) :: field
194   
195    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite0d_xios ',trim(field_name)
196   
197!$OMP MASTER
198    CALL xios_send_field(field_name,field)
199!$OMP END MASTER
200   
201    IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite0d_xios ',trim(field_name)
202   
203  END SUBROUTINE histwrite0d_xios
204
205!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
206
207  SUBROUTINE histwrite2d_xios(field_name,field)
208  USE dimphy, only: klon
209  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
210                                jj_nb, klon_mpi
211  USE xios, only: xios_send_field
212  USE print_control_mod, ONLY: prt_level, lunout
213  USE mod_grid_phy_lmdz, ONLY: nbp_lon
214  IMPLICIT NONE
215
216    CHARACTER(LEN=*), INTENT(IN) :: field_name
217    REAL, DIMENSION(:), INTENT(IN) :: field
218     
219    REAL,DIMENSION(klon_mpi) :: buffer_omp
220    REAL :: Field2d(nbp_lon,jj_nb)
221
222    IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',trim(field_name)
223
224    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
225   
226    CALL Gather_omp(field,buffer_omp)   
227!$OMP MASTER
228    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
229   
230    CALL xios_send_field(field_name, Field2d)
231!$OMP END MASTER   
232
233    IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',trim(field_name)
234  END SUBROUTINE histwrite2d_xios
235
236!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
237
238  SUBROUTINE histwrite3d_xios(field_name, field)
239  USE dimphy, only: klon, klev
240  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
241                                jj_nb, klon_mpi
242  USE xios, only: xios_send_field
243  USE print_control_mod, ONLY: prt_level,lunout
244  USE mod_grid_phy_lmdz, ONLY: nbp_lon
245
246  IMPLICIT NONE
247
248    CHARACTER(LEN=*), INTENT(IN) :: field_name
249    REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
250
251    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
252    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
253    INTEGER :: ip, n, nlev
254
255  IF (prt_level >= 10) write(lunout,*)'Begin histrwrite3d_xios ',trim(field_name)
256
257    !Et on.... écrit
258    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
259    nlev=SIZE(field,2)
260
261
262    CALL Gather_omp(field,buffer_omp)
263!$OMP MASTER
264    CALL grid1Dto2D_mpi(buffer_omp,field3d)
265
266    CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
267!$OMP END MASTER   
268
269    IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',trim(field_name)
270  END SUBROUTINE histwrite3d_xios
271
272#endif
273
274END MODULE xios_output_mod
Note: See TracBrowser for help on using the repository browser.