SCALE-RM
mod_atmos_phy_ch_vars.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 !-------------------------------------------------------------------------------
11 #include "scalelib.h"
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use scale_precision
18  use scale_io
19  use scale_prof
21  use scale_tracer
22  !-----------------------------------------------------------------------------
23  implicit none
24  private
25  !-----------------------------------------------------------------------------
26  !
27  !++ Public procedure
28  !
29  public :: atmos_phy_ch_vars_setup
33 
39 
40  !-----------------------------------------------------------------------------
41  !
42  !++ Public parameters & variables
43  !
44  logical, public :: atmos_phy_ch_restart_output = .false.
45 
46  character(len=H_LONG), public :: atmos_phy_ch_restart_in_basename = ''
48  logical, public :: atmos_phy_ch_restart_in_postfix_timelabel = .false.
49  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  integer, public :: qa_ch = 0
60  integer, public :: qs_ch = -1
61  integer, public :: qe_ch = -2
62 
63  !-----------------------------------------------------------------------------
64  !
65  !++ Private procedure
66  !
67  !-----------------------------------------------------------------------------
68  !
69  !++ Private parameters & variables
70  !
71  integer, private, parameter :: vmax = 1
72  integer, private, parameter :: i_o3 = 1
73 
74  character(len=H_SHORT), private :: var_name(vmax)
75  character(len=H_MID), private :: var_desc(vmax)
76  character(len=H_SHORT), private :: var_unit(vmax)
77  integer, private :: var_id(vmax)
78  integer, private :: restart_fid = -1 ! file ID
79 
80  data var_name / 'O3' /
81  data var_desc / 'Ozone' /
82  data var_unit / 'PPM' /
83 
84  !-----------------------------------------------------------------------------
85 contains
86  !-----------------------------------------------------------------------------
88  subroutine atmos_phy_ch_vars_setup
89  use scale_prc, only: &
90  prc_abort
91  use scale_const, only: &
92  undef => const_undef
93  implicit none
94 
95  namelist / param_atmos_phy_ch_vars / &
105 
106  integer :: ierr
107  integer :: iv
108  !---------------------------------------------------------------------------
109 
110  log_newline
111  log_info("ATMOS_PHY_CH_vars_setup",*) 'Setup'
112 
113  allocate( atmos_phy_ch_rhoq_t(ka,ia,ja,qs_ch:qe_ch) )
114  atmos_phy_ch_rhoq_t(:,:,:,:) = undef
115 
116  allocate( atmos_phy_ch_o3(ka,ia,ja) )
117  atmos_phy_ch_o3(:,:,:) = undef
118 
119  !--- read namelist
120  rewind(io_fid_conf)
121  read(io_fid_conf,nml=param_atmos_phy_ch_vars,iostat=ierr)
122  if( ierr < 0 ) then !--- missing
123  log_info("ATMOS_PHY_CH_vars_setup",*) 'Not found namelist. Default used.'
124  elseif( ierr > 0 ) then !--- fatal error
125  log_error("ATMOS_PHY_CH_vars_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_PHY_CH_VARS. Check!'
126  call prc_abort
127  endif
128  log_nml(param_atmos_phy_ch_vars)
129 
130  log_newline
131  log_info("ATMOS_PHY_CH_vars_setup",*) '[ATMOS_PHY_CH] prognostic/diagnostic variables'
132  log_info_cont('(1x,A,A24,A,A48,A,A12,A)') &
133  ' |', 'VARNAME ','|', &
134  'DESCRIPTION ', '[', 'UNIT ', ']'
135  do iv = 1, vmax
136  log_info_cont('(1x,A,I3,A,A24,A,A48,A,A12,A)') &
137  'NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
138  enddo
139 
140  log_newline
141  if ( atmos_phy_ch_restart_in_basename /= '' ) then
142  log_info("ATMOS_PHY_CH_vars_setup",*) 'Restart input? : YES, file = ', trim(atmos_phy_ch_restart_in_basename)
143  log_info("ATMOS_PHY_CH_vars_setup",*) 'Add timelabel? : ', atmos_phy_ch_restart_in_postfix_timelabel
144  else
145  log_info("ATMOS_PHY_CH_vars_setup",*) 'Restart input? : NO'
146  endif
148  .AND. atmos_phy_ch_restart_out_basename /= '' ) then
149  log_info("ATMOS_PHY_CH_vars_setup",*) 'Restart output? : YES, file = ', trim(atmos_phy_ch_restart_out_basename)
150  log_info("ATMOS_PHY_CH_vars_setup",*) 'Add timelabel? : ', atmos_phy_ch_restart_out_postfix_timelabel
151  else
152  log_info("ATMOS_PHY_CH_vars_setup",*) 'Restart output? : NO'
154  endif
155 
156  return
157  end subroutine atmos_phy_ch_vars_setup
158 
159  !-----------------------------------------------------------------------------
161  subroutine atmos_phy_ch_vars_fillhalo
162  use scale_comm_cartesc, only: &
163  comm_vars8, &
164  comm_wait
165  implicit none
166 
167  integer :: i, j
168  !---------------------------------------------------------------------------
169 
170  do j = js, je
171  do i = is, ie
172  atmos_phy_ch_o3( 1:ks-1,i,j) = atmos_phy_ch_o3(ks,i,j)
173  atmos_phy_ch_o3(ke+1:ka, i,j) = atmos_phy_ch_o3(ke,i,j)
174  enddo
175  enddo
176 
177  call comm_vars8( atmos_phy_ch_o3(:,:,:), 1 )
178  call comm_wait ( atmos_phy_ch_o3(:,:,:), 1 )
179 
180  return
181  end subroutine atmos_phy_ch_vars_fillhalo
182 
183  !-----------------------------------------------------------------------------
186  use scale_time, only: &
188  use scale_file_cartesc, only: &
190  implicit none
191 
192  character(len=19) :: timelabel
193  character(len=H_LONG) :: basename
194  !---------------------------------------------------------------------------
195 
196  log_newline
197  log_info("ATMOS_PHY_CH_vars_restart_open",*) 'Open restart file (ATMOS_PHY_CH) '
198 
199  if ( atmos_phy_ch_restart_in_basename /= '' ) then
200 
202  call time_gettimelabel( timelabel )
203  basename = trim(atmos_phy_ch_restart_in_basename)//'_'//trim(timelabel)
204  else
205  basename = trim(atmos_phy_ch_restart_in_basename)
206  endif
207 
208  log_info("ATMOS_PHY_CH_vars_restart_open",*) 'basename: ', trim(basename)
209 
210  call file_cartesc_open( basename, restart_fid, aggregate=atmos_phy_ch_restart_in_aggregate )
211  else
212  log_info("ATMOS_PHY_CH_vars_restart_open",*) 'restart file for ATMOS_PHY_CH is not specified.'
213  endif
214 
215  return
216  end subroutine atmos_phy_ch_vars_restart_open
217 
218  !-----------------------------------------------------------------------------
221  use scale_statistics, only: &
223  statistics_total
224  use scale_file, only: &
226  use scale_file_cartesc, only: &
227  file_cartesc_read, &
229  use scale_atmos_grid_cartesc_real, only: &
232  implicit none
233 
234  integer :: i, j
235  !---------------------------------------------------------------------------
236 
237  if ( restart_fid /= -1 ) then
238  log_newline
239  log_info("ATMOS_PHY_CH_vars_restart_read",*) 'Read from restart file (ATMOS_PHY_CH) '
240 
241  call file_cartesc_read( restart_fid, var_name(1), 'ZXY', & ! [IN]
242  atmos_phy_ch_o3(:,:,:) ) ! [OUT]
243 
244  if ( file_get_aggregate( restart_fid) ) then
245  call file_cartesc_flush( restart_fid ) ! X/Y halos have been read from file
246 
247  ! fill K halos
248  do j = 1, ja
249  do i = 1, ia
250  atmos_phy_ch_o3( 1:ks-1,i,j) = atmos_phy_ch_o3(ks,i,j)
251  atmos_phy_ch_o3(ke+1:ka, i,j) = atmos_phy_ch_o3(ke,i,j)
252  enddo
253  enddo
254  else
256  end if
257 
258  if ( statistics_checktotal ) then
259  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
260  atmos_phy_ch_o3(:,:,:), var_name(1), & ! (in)
261  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
263  end if
264  else
265  log_info("ATMOS_PHY_CH_vars_restart_read",*) 'invalid restart file for ATMOS_PHY_CH.'
266  endif
267 
268  return
269  end subroutine atmos_phy_ch_vars_restart_read
270 
271  !-----------------------------------------------------------------------------
274  use scale_time, only: &
276  use scale_file_cartesc, only: &
278  implicit none
279 
280  character(len=19) :: timelabel
281  character(len=H_LONG) :: basename
282  !---------------------------------------------------------------------------
283 
284  if ( atmos_phy_ch_restart_out_basename /= '' ) then
285 
286  log_newline
287  log_info("ATMOS_PHY_CH_vars_restart_create",*) 'Create restart file (ATMOS_PHY_CH) '
288 
290  call time_gettimelabel( timelabel )
291  basename = trim(atmos_phy_ch_restart_out_basename)//'_'//trim(timelabel)
292  else
293  basename = trim(atmos_phy_ch_restart_out_basename)
294  endif
295 
296  log_info("ATMOS_PHY_CH_vars_restart_create",*) 'basename: ', trim(basename)
297 
298  call file_cartesc_create( &
300  restart_fid, & ! [OUT]
301  aggregate=atmos_phy_ch_restart_out_aggregate ) ! [IN]
302 
303  endif
304 
305  return
306  end subroutine atmos_phy_ch_vars_restart_create
307 
308  !-----------------------------------------------------------------------------
311  use scale_file_cartesc, only: &
313  implicit none
314 
315  if ( restart_fid /= -1 ) then
316  call file_cartesc_enddef( restart_fid ) ! [IN]
317  endif
318 
319  return
320  end subroutine atmos_phy_ch_vars_restart_enddef
321 
322  !-----------------------------------------------------------------------------
325  use scale_file_cartesc, only: &
327  implicit none
328  !---------------------------------------------------------------------------
329 
330  if ( restart_fid /= -1 ) then
331  log_newline
332  log_info("ATMOS_PHY_CH_vars_restart_close",*) 'Close restart file (ATMOS_PHY_CH) '
333 
334  call file_cartesc_close( restart_fid ) ! [IN]
335 
336  restart_fid = -1
337  endif
338 
339  return
340  end subroutine atmos_phy_ch_vars_restart_close
341 
342  !-----------------------------------------------------------------------------
345  use scale_file_cartesc, only: &
347  implicit none
348  !---------------------------------------------------------------------------
349 
350  if ( restart_fid /= -1 ) then
351  call file_cartesc_def_var( restart_fid, var_name(1), var_desc(1), var_unit(1), 'ZXY', atmos_phy_ch_restart_out_dtype, &
352  var_id(1) )
353  endif
354 
355  return
356  end subroutine atmos_phy_ch_vars_restart_def_var
357 
358  !-----------------------------------------------------------------------------
361  use scale_statistics, only: &
363  statistics_total
364  use scale_file_cartesc, only: &
365  file_cartesc_write_var
366  use scale_atmos_grid_cartesc_real, only: &
369  implicit none
370 
371  !---------------------------------------------------------------------------
372 
373  if ( restart_fid /= -1 ) then
374 
376 
377  if ( statistics_checktotal ) then
378  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
379  atmos_phy_ch_o3(:,:,:), var_name(1), & ! (in)
380  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
382  end if
383 
384  call file_cartesc_write_var( restart_fid, var_id(1), atmos_phy_ch_o3(:,:,:), var_name(1), 'ZXY' ) ! [IN]
385 
386  endif
387 
388  return
389  end subroutine atmos_phy_ch_vars_restart_write
390 
391 end module mod_atmos_phy_ch_vars
character(len=h_mid), public atmos_phy_ch_restart_out_title
title of the output file
subroutine, public atmos_phy_ch_vars_setup
Setup.
subroutine, public atmos_phy_ch_vars_restart_close
Close restart file.
integer, public ia
of whole cells: x, local, with HALO
subroutine, public atmos_phy_ch_vars_restart_enddef
Exit netCDF define mode.
subroutine, public atmos_phy_ch_vars_restart_def_var
Write restart.
real(rp), dimension(:,:,:), allocatable, public atmos_grid_cartesc_real_vol
control volume (zxy) [m3]
real(rp), public atmos_grid_cartesc_real_totvol
total volume (zxy, local) [m3]
integer, public ja
of whole cells: y, local, with HALO
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:55
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ch_o3
logical, public statistics_checktotal
calc&report variable totals to logfile?
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:41
module COMMUNICATION
integer, public is
start point of inner domain: x, local
module file
Definition: scale_file.F90:15
integer, public ie
end point of inner domain: x, local
subroutine, public file_cartesc_create(basename, title, datatype, fid, date, subsec, haszcoord, append, aggregate, single)
Create/open a netCDF file.
module TRACER
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:94
subroutine, public atmos_phy_ch_vars_fillhalo
HALO Communication.
logical, public atmos_phy_ch_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
module atmosphere / grid / cartesC index
integer, public ke
end point of inner domain: z, local
logical, public atmos_phy_ch_restart_output
output restart file?
module PROCESS
Definition: scale_prc.F90:11
integer, public je
end point of inner domain: y, local
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 file_cartesc_enddef(fid)
Exit netCDF file define mode.
module TIME
Definition: scale_time.F90:16
integer, public ks
start point of inner domain: z, local
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:338
module CONSTANT
Definition: scale_const.F90:11
integer, public js
start point of inner domain: y, local
subroutine, public file_cartesc_def_var(fid, varname, desc, unit, dim_type, datatype, vid, standard_name, timeintv, nsteps, cell_measures)
Define a variable to file.
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ch_rhoq_t
logical function, public file_get_aggregate(fid)
module Atmosphere / Physics Chemistry
module profiler
Definition: scale_prof.F90:11
module Atmosphere GRID CartesC Real(real space)
module PRECISION
module file / cartesianC
logical, public atmos_phy_ch_restart_in_aggregate
Switch to use aggregate file.
integer, public ka
of whole cells: z, local, with HALO
subroutine, public atmos_phy_ch_vars_restart_write
Write restart.
module Statistics
subroutine, public atmos_phy_ch_vars_restart_create
Create restart file.
module STDIO
Definition: scale_io.F90:10
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
subroutine, public atmos_phy_ch_vars_restart_open
Open restart file for read.
subroutine, public atmos_phy_ch_vars_restart_read
Read restart.
subroutine, public file_cartesc_open(basename, fid, aggregate)
open a netCDF file for read
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
logical, public atmos_phy_ch_restart_out_aggregate
Switch to use aggregate file.
character(len=h_long), public atmos_phy_ch_restart_in_basename
Basename of the input file.