SCALE-RM
mod_atmos_phy_ch_vars.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
12 !-------------------------------------------------------------------------------
13 #include "inc_openmp.h"
15  !-----------------------------------------------------------------------------
16  !
17  !++ used modules
18  !
19  use scale_precision
20  use scale_stdio
21  use scale_prof
23  use scale_tracer
24  !-----------------------------------------------------------------------------
25  implicit none
26  private
27  !-----------------------------------------------------------------------------
28  !
29  !++ Public procedure
30  !
31  public :: atmos_phy_ch_vars_setup
35 
41 
42  !-----------------------------------------------------------------------------
43  !
44  !++ Public parameters & variables
45  !
46  logical, public :: atmos_phy_ch_restart_output = .false.
47 
48  character(len=H_LONG), public :: atmos_phy_ch_restart_in_basename = ''
49  logical, public :: atmos_phy_ch_restart_in_postfix_timelabel = .false.
50  character(len=H_LONG), public :: atmos_phy_ch_restart_out_basename = ''
51  logical, public :: atmos_phy_ch_restart_out_postfix_timelabel = .true.
52  character(len=H_MID), public :: atmos_phy_ch_restart_out_title = 'ATMOS_PHY_CH restart'
53  character(len=H_SHORT), public :: atmos_phy_ch_restart_out_dtype = 'DEFAULT'
54 
55  real(RP), public, allocatable :: atmos_phy_ch_rhoq_t(:,:,:,:) ! tendency QTRC [kg/kg/s]
56 
57  real(RP), public, allocatable :: atmos_phy_ch_o3(:,:,:) ! ozone [PPM]
58 
59  !-----------------------------------------------------------------------------
60  !
61  !++ Private procedure
62  !
63  !-----------------------------------------------------------------------------
64  !
65  !++ Private parameters & variables
66  !
67  integer, private, parameter :: vmax = 1
68  integer, private, parameter :: i_o3 = 1
69 
70  character(len=H_SHORT), private :: var_name(vmax)
71  character(len=H_MID), private :: var_desc(vmax)
72  character(len=H_SHORT), private :: var_unit(vmax)
73  integer, private :: var_id(vmax)
74  integer, private :: restart_fid = -1 ! file ID
75 
76  data var_name / 'O3' /
77  data var_desc / 'Ozone' /
78  data var_unit / 'PPM' /
79 
80  !-----------------------------------------------------------------------------
81 contains
82  !-----------------------------------------------------------------------------
84  subroutine atmos_phy_ch_vars_setup
85  use scale_process, only: &
87  use scale_const, only: &
88  undef => const_undef
89  implicit none
90 
91  namelist / param_atmos_phy_ch_vars / &
99 
100  integer :: ierr
101  integer :: iv
102  !---------------------------------------------------------------------------
103 
104  if( io_l ) write(io_fid_log,*)
105  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS PHY_CH] / Origin[SCALE-RM]'
106 
107  allocate( atmos_phy_ch_rhoq_t(ka,ia,ja,qa) )
108  atmos_phy_ch_rhoq_t(:,:,:,:) = undef
109 
110  allocate( atmos_phy_ch_o3(ka,ia,ja) )
111  atmos_phy_ch_o3(:,:,:) = undef
112 
113  !--- read namelist
114  rewind(io_fid_conf)
115  read(io_fid_conf,nml=param_atmos_phy_ch_vars,iostat=ierr)
116  if( ierr < 0 ) then !--- missing
117  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
118  elseif( ierr > 0 ) then !--- fatal error
119  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_PHY_CH_VARS. Check!'
120  call prc_mpistop
121  endif
122  if( io_nml ) write(io_fid_nml,nml=param_atmos_phy_ch_vars)
123 
124  if( io_l ) write(io_fid_log,*)
125  if( io_l ) write(io_fid_log,*) '*** [ATMOS_PHY_CH] prognostic/diagnostic variables'
126  if( io_l ) write(io_fid_log,'(1x,A,A24,A,A48,A,A12,A)') &
127  '*** |', 'VARNAME ','|', &
128  'DESCRIPTION ', '[', 'UNIT ', ']'
129  do iv = 1, vmax
130  if( io_l ) write(io_fid_log,'(1x,A,I3,A,A24,A,A48,A,A12,A)') &
131  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
132  enddo
133 
134  if( io_l ) write(io_fid_log,*)
135  if ( atmos_phy_ch_restart_in_basename /= '' ) then
136  if( io_l ) write(io_fid_log,*) '*** Restart input? : YES, file = ', trim(atmos_phy_ch_restart_in_basename)
137  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_ch_restart_in_postfix_timelabel
138  else
139  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
140  endif
142  .AND. atmos_phy_ch_restart_out_basename /= '' ) then
143  if( io_l ) write(io_fid_log,*) '*** Restart output? : YES, file = ', trim(atmos_phy_ch_restart_out_basename)
144  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_ch_restart_out_postfix_timelabel
145  else
146  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
148  endif
149 
150  return
151  end subroutine atmos_phy_ch_vars_setup
152 
153  !-----------------------------------------------------------------------------
155  subroutine atmos_phy_ch_vars_fillhalo
156  use scale_comm, only: &
157  comm_vars8, &
158  comm_wait
159  implicit none
160 
161  integer :: i, j
162  !---------------------------------------------------------------------------
163 
164  do j = js, je
165  do i = is, ie
166  atmos_phy_ch_o3( 1:ks-1,i,j) = atmos_phy_ch_o3(ks,i,j)
167  atmos_phy_ch_o3(ke+1:ka, i,j) = atmos_phy_ch_o3(ke,i,j)
168  enddo
169  enddo
170 
171  call comm_vars8( atmos_phy_ch_o3(:,:,:), 1 )
172  call comm_wait ( atmos_phy_ch_o3(:,:,:), 1 )
173 
174  return
175  end subroutine atmos_phy_ch_vars_fillhalo
176 
177  !-----------------------------------------------------------------------------
180  use scale_time, only: &
182  use scale_fileio, only: &
184  implicit none
185 
186  character(len=19) :: timelabel
187  character(len=H_LONG) :: basename
188  !---------------------------------------------------------------------------
189 
190  if( io_l ) write(io_fid_log,*)
191  if( io_l ) write(io_fid_log,*) '*** Open restart file (ATMOS_PHY_CH) ***'
192 
193  if ( atmos_phy_ch_restart_in_basename /= '' ) then
194 
196  call time_gettimelabel( timelabel )
197  basename = trim(atmos_phy_ch_restart_in_basename)//'_'//trim(timelabel)
198  else
199  basename = trim(atmos_phy_ch_restart_in_basename)
200  endif
201 
202  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
203 
204  call fileio_open( restart_fid, basename )
205  else
206  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_PHY_CH is not specified.'
207  endif
208 
209  return
210  end subroutine atmos_phy_ch_vars_restart_open
211 
212  !-----------------------------------------------------------------------------
215  use scale_rm_statistics, only: &
217  stat_total
218  use scale_fileio, only: &
219  fileio_read, &
221  implicit none
222 
223  real(RP) :: total
224  integer :: i, j
225  !---------------------------------------------------------------------------
226 
227  if ( restart_fid /= -1 ) then
228  if( io_l ) write(io_fid_log,*)
229  if( io_l ) write(io_fid_log,*) '*** Read from restart file (ATMOS_PHY_CH) ***'
230 
231  call fileio_read( atmos_phy_ch_o3(:,:,:), & ! [OUT]
232  restart_fid, var_name(1), 'ZXY', step=1 ) ! [IN]
233 
234  if ( io_aggregate ) then
235  call fileio_flush( restart_fid ) ! X/Y halos have been read from file
236 
237  ! fill K halos
238  do j = 1, ja
239  do i = 1, ia
240  atmos_phy_ch_o3( 1:ks-1,i,j) = atmos_phy_ch_o3(ks,i,j)
241  atmos_phy_ch_o3(ke+1:ka, i,j) = atmos_phy_ch_o3(ke,i,j)
242  enddo
243  enddo
244  else
246  end if
247 
248  if ( statistics_checktotal ) then
249  call stat_total( total, atmos_phy_ch_o3(:,:,:), var_name(1) )
250  end if
251  else
252  if( io_l ) write(io_fid_log,*) '*** invalid restart file for ATMOS_PHY_CH.'
253  endif
254 
255  return
256  end subroutine atmos_phy_ch_vars_restart_read
257 
258  !-----------------------------------------------------------------------------
261  use scale_time, only: &
263  use scale_fileio, only: &
265  implicit none
266 
267  character(len=19) :: timelabel
268  character(len=H_LONG) :: basename
269  !---------------------------------------------------------------------------
270 
271  if ( atmos_phy_ch_restart_out_basename /= '' ) then
272 
273  if( io_l ) write(io_fid_log,*)
274  if( io_l ) write(io_fid_log,*) '*** Create restart file (ATMOS_PHY_CH) ***'
275 
277  call time_gettimelabel( timelabel )
278  basename = trim(atmos_phy_ch_restart_out_basename)//'_'//trim(timelabel)
279  else
280  basename = trim(atmos_phy_ch_restart_out_basename)
281  endif
282 
283  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
284 
285  call fileio_create( restart_fid, & ! [OUT]
287 
288  endif
289 
290  return
291  end subroutine atmos_phy_ch_vars_restart_create
292 
293  !-----------------------------------------------------------------------------
296  use scale_fileio, only: &
298  implicit none
299 
300  if ( restart_fid /= -1 ) then
301  call fileio_enddef( restart_fid ) ! [IN]
302  endif
303 
304  return
305  end subroutine atmos_phy_ch_vars_restart_enddef
306 
307  !-----------------------------------------------------------------------------
310  use scale_fileio, only: &
312  implicit none
313  !---------------------------------------------------------------------------
314 
315  if ( restart_fid /= -1 ) then
316  if( io_l ) write(io_fid_log,*)
317  if( io_l ) write(io_fid_log,*) '*** Close restart file (ATMOS_PHY_CH) ***'
318 
319  call fileio_close( restart_fid ) ! [IN]
320 
321  restart_fid = -1
322  endif
323 
324  return
325  end subroutine atmos_phy_ch_vars_restart_close
326 
327  !-----------------------------------------------------------------------------
330  use scale_fileio, only: &
332  implicit none
333  !---------------------------------------------------------------------------
334 
335  if ( restart_fid /= -1 ) then
336  call fileio_def_var( restart_fid, var_id(1), var_name(1), var_desc(1), &
337  var_unit(1), 'ZXY', atmos_phy_ch_restart_out_dtype ) ! [IN]
338  endif
339 
340  return
341  end subroutine atmos_phy_ch_vars_restart_def_var
342 
343  !-----------------------------------------------------------------------------
346  use scale_rm_statistics, only: &
348  stat_total
349  use scale_fileio, only: &
350  fileio_write_var
351  implicit none
352 
353  real(RP) :: total
354  !---------------------------------------------------------------------------
355 
356  if ( restart_fid /= -1 ) then
357 
359 
360  if ( statistics_checktotal ) then
361  call stat_total( total, atmos_phy_ch_o3(:,:,:), var_name(1) )
362  end if
363 
364  call fileio_write_var( restart_fid, var_id(1), atmos_phy_ch_o3(:,:,:), &
365  var_name(1), 'ZXY' ) ! [IN]
366 
367  endif
368 
369  return
370  end subroutine atmos_phy_ch_vars_restart_write
371 
372 end module mod_atmos_phy_ch_vars
integer, public is
start point of inner domain: x, local
logical, public statistics_checktotal
calc&report variable totals to logfile?
character(len=h_mid), public atmos_phy_ch_restart_out_title
title of the output file
integer, public je
end point of inner domain: y, local
subroutine, public atmos_phy_ch_vars_setup
Setup.
subroutine, public prc_mpistop
Abort MPI.
subroutine, public atmos_phy_ch_vars_restart_close
Close restart file.
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:61
subroutine, public fileio_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
module STDIO
Definition: scale_stdio.F90:12
subroutine, public atmos_phy_ch_vars_restart_enddef
Exit netCDF define mode.
subroutine, public atmos_phy_ch_vars_restart_def_var
Write restart.
integer, public ke
end point of inner domain: z, local
integer, public qa
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ch_o3
module FILE I/O (netcdf)
logical, public atmos_phy_ch_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
real(rp), public const_undef
Definition: scale_const.F90:43
module Statistics
module grid index
logical, public io_nml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:62
module TRACER
integer, public ia
of whole cells: x, local, with HALO
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:90
subroutine, public atmos_phy_ch_vars_fillhalo
HALO Communication.
integer, public ka
of whole cells: z, local, with HALO
logical, public atmos_phy_ch_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
logical, public atmos_phy_ch_restart_output
output restart file?
character(len=h_short), public atmos_phy_ch_restart_out_dtype
REAL4 or REAL8.
character(len=h_long), public atmos_phy_ch_restart_out_basename
Basename of the output file.
subroutine, public fileio_create(fid, basename, title, datatype, date, subsec, append, nozcoord)
Create/open a netCDF file.
module COMMUNICATION
Definition: scale_comm.F90:23
integer, public js
start point of inner domain: y, local
module TIME
Definition: scale_time.F90:15
module PROCESS
module CONSTANT
Definition: scale_const.F90:14
integer, public ks
start point of inner domain: z, local
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ch_rhoq_t
module Atmosphere / Physics Chemistry
subroutine, public fileio_enddef(fid)
Exit netCDF file define mode.
module profiler
Definition: scale_prof.F90:10
integer, public ie
end point of inner domain: x, local
logical, public io_aggregate
do parallel I/O through PnetCDF
Definition: scale_stdio.F90:66
subroutine, public fileio_open(fid, basename)
open a netCDF file for read
module PRECISION
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps)
Define a variable to file.
subroutine, public atmos_phy_ch_vars_restart_write
Write restart.
subroutine, public fileio_close(fid)
Close a netCDF file.
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
subroutine, public atmos_phy_ch_vars_restart_create
Create restart file.
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
subroutine, public atmos_phy_ch_vars_restart_open
Open restart file for read.
subroutine, public atmos_phy_ch_vars_restart_read
Read restart.
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
character(len=h_long), public atmos_phy_ch_restart_in_basename
Basename of the input file.
integer, public ja
of whole cells: y, local, with HALO