SCALE-RM
mod_atmos_phy_ae_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_ae_vars_setup
35 
41 
42  !-----------------------------------------------------------------------------
43  !
44  !++ Public parameters & variables
45  !
46  logical, public :: atmos_phy_ae_restart_output = .false.
47 
48  character(len=H_LONG), public :: atmos_phy_ae_restart_in_basename = ''
49  logical, public :: atmos_phy_ae_restart_in_postfix_timelabel = .false.
50  character(len=H_LONG), public :: atmos_phy_ae_restart_out_basename = ''
51  logical, public :: atmos_phy_ae_restart_out_postfix_timelabel = .true.
52  character(len=H_MID), public :: atmos_phy_ae_restart_out_title = 'ATMOS_PHY_AE restart'
53  character(len=H_SHORT), public :: atmos_phy_ae_restart_out_dtype = 'DEFAULT'
54 
55  real(RP), public, allocatable :: atmos_phy_ae_rhoq_t(:,:,:,:) ! tendency rho*QTRC [kg/kg/s]
56 
57  real(RP), public, allocatable :: atmos_phy_ae_ccn(:,:,:) ! cloud condensation nuclei [/m3]
58  real(RP), public, allocatable :: atmos_phy_ae_ccn_t(:,:,:) ! tendency CCN [/m3/s]
59  real(RP), public, allocatable :: atmos_phy_ae_emit(:,:,:,:) ! emission of aerosol and gas
60  !-----------------------------------------------------------------------------
61  !
62  !++ Private procedure
63  !
64  !-----------------------------------------------------------------------------
65  !
66  !++ Private parameters & variables
67  !
68  integer, private, parameter :: vmax = 1
69  integer, private, parameter :: i_ccn = 1
70 
71  character(len=H_SHORT), private :: var_name(vmax)
72  character(len=H_MID), private :: var_desc(vmax)
73  character(len=H_SHORT), private :: var_unit(vmax)
74  integer, private :: var_id(vmax)
75  integer, private :: restart_fid = -1 ! file ID
76 
77  data var_name / 'CCN' /
78  data var_desc / 'cloud condensation nuclei' /
79  data var_unit / 'num/m3' /
80 
81  !-----------------------------------------------------------------------------
82 contains
83  !-----------------------------------------------------------------------------
85  subroutine atmos_phy_ae_vars_setup
86  use scale_process, only: &
88  use scale_const, only: &
89  undef => const_undef
90  use scale_atmos_phy_ae, only: &
91  qa_ae, &
92  qs_ae, &
93  qe_ae
94  implicit none
95 
96  namelist / param_atmos_phy_ae_vars / &
104 
105  integer :: ierr
106  integer :: iv
107  !---------------------------------------------------------------------------
108 
109  if( io_l ) write(io_fid_log,*)
110  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS PHY_AE] / Origin[SCALE-RM]'
111 
112  allocate( atmos_phy_ae_rhoq_t(ka,ia,ja,qs_ae:qe_ae) )
113  atmos_phy_ae_rhoq_t(:,:,:, :) = undef
114 
115  allocate( atmos_phy_ae_ccn(ka,ia,ja) )
116  atmos_phy_ae_ccn(:,:,:) = undef
117 
118  allocate( atmos_phy_ae_ccn_t(ka,ia,ja) )
119  atmos_phy_ae_ccn_t(:,:,:) = undef
120 
121  allocate( atmos_phy_ae_emit(ka,ia,ja,qa_ae) )
122  atmos_phy_ae_emit(:,:,:,:) = 0.0_rp
123 
124  !--- read namelist
125  rewind(io_fid_conf)
126  read(io_fid_conf,nml=param_atmos_phy_ae_vars,iostat=ierr)
127  if( ierr < 0 ) then !--- missing
128  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
129  elseif( ierr > 0 ) then !--- fatal error
130  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_PHY_AE_VARS. Check!'
131  call prc_mpistop
132  endif
133  if( io_nml ) write(io_fid_nml,nml=param_atmos_phy_ae_vars)
134 
135  if( io_l ) write(io_fid_log,*)
136  if( io_l ) write(io_fid_log,*) '*** [ATMOS_PHY_AE] prognostic/diagnostic variables'
137  if( io_l ) write(io_fid_log,'(1x,A,A24,A,A48,A,A12,A)') &
138  '*** |', 'VARNAME ','|', &
139  'DESCRIPTION ', '[', 'UNIT ', ']'
140  do iv = 1, vmax
141  if( io_l ) write(io_fid_log,'(1x,A,I3,A,A24,A,A48,A,A12,A)') &
142  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
143  enddo
144 
145  if( io_l ) write(io_fid_log,*)
146  if ( atmos_phy_ae_restart_in_basename /= '' ) then
147  if( io_l ) write(io_fid_log,*) '*** Restart input? : YES, file = ', trim(atmos_phy_ae_restart_in_basename)
148  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_ae_restart_in_postfix_timelabel
149  else
150  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
151  endif
153  .AND. atmos_phy_ae_restart_out_basename /= '' ) then
154  if( io_l ) write(io_fid_log,*) '*** Restart output? : YES, file = ', trim(atmos_phy_ae_restart_out_basename)
155  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_ae_restart_out_postfix_timelabel
156  else
157  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
159  endif
160 
161  return
162  end subroutine atmos_phy_ae_vars_setup
163 
164  !-----------------------------------------------------------------------------
166  subroutine atmos_phy_ae_vars_fillhalo
167  use scale_comm, only: &
168  comm_vars8, &
169  comm_wait
170  implicit none
171 
172  integer :: i, j
173  !---------------------------------------------------------------------------
174 
175  do j = js, je
176  do i = is, ie
177  atmos_phy_ae_ccn( 1:ks-1,i,j) = atmos_phy_ae_ccn(ks,i,j)
178  atmos_phy_ae_ccn(ke+1:ka, i,j) = atmos_phy_ae_ccn(ke,i,j)
179  enddo
180  enddo
181 
182  call comm_vars8( atmos_phy_ae_ccn(:,:,:), 1 )
183  call comm_wait ( atmos_phy_ae_ccn(:,:,:), 1 )
184 
185  return
186  end subroutine atmos_phy_ae_vars_fillhalo
187 
188  !-----------------------------------------------------------------------------
191  use scale_time, only: &
193  use scale_fileio, only: &
195  implicit none
196 
197  character(len=19) :: timelabel
198  character(len=H_LONG) :: basename
199  !---------------------------------------------------------------------------
200 
201  if( io_l ) write(io_fid_log,*)
202  if( io_l ) write(io_fid_log,*) '*** Open restart file (ATMOS_PHY_AE) ***'
203 
204  if ( atmos_phy_ae_restart_in_basename /= '' ) then
205 
207  call time_gettimelabel( timelabel )
208  basename = trim(atmos_phy_ae_restart_in_basename)//'_'//trim(timelabel)
209  else
210  basename = trim(atmos_phy_ae_restart_in_basename)
211  endif
212 
213  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
214 
215  call fileio_open( restart_fid, basename )
216  else
217  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_PHY_AE is not specified.'
218  endif
219 
220  return
221  end subroutine atmos_phy_ae_vars_restart_open
222 
223  !-----------------------------------------------------------------------------
226  use scale_rm_statistics, only: &
228  stat_total
229  use scale_fileio, only: &
230  fileio_read, &
232  implicit none
233 
234  real(RP) :: total
235  integer :: i, j
236  !---------------------------------------------------------------------------
237 
238  if ( restart_fid /= -1 ) then
239  if( io_l ) write(io_fid_log,*)
240  if( io_l ) write(io_fid_log,*) '*** Read from restart file (ATMOS_PHY_AE) ***'
241 
242  call fileio_read( atmos_phy_ae_ccn(:,:,:), & ! [OUT]
243  restart_fid, var_name(1), 'ZXY', step=1 ) ! [IN]
244 
245  if ( io_aggregate ) then
246  call fileio_flush( restart_fid ) ! X/Y halos have been read from file
247 
248  ! fill K halos
249  do j = 1, ja
250  do i = 1, ia
251  atmos_phy_ae_ccn( 1:ks-1,i,j) = atmos_phy_ae_ccn(ks,i,j)
252  atmos_phy_ae_ccn(ke+1:ka, i,j) = atmos_phy_ae_ccn(ke,i,j)
253  enddo
254  enddo
255  else
257  end if
258 
259  if ( statistics_checktotal ) then
260  call stat_total( total, atmos_phy_ae_ccn(:,:,:), var_name(1) )
261  end if
262  else
263  if( io_l ) write(io_fid_log,*) '*** invlaid restart file ID for ATMOS_PHY_AE.'
264  endif
265 
266  return
267  end subroutine atmos_phy_ae_vars_restart_read
268 
269  !-----------------------------------------------------------------------------
272  use scale_time, only: &
274  use scale_fileio, only: &
276  implicit none
277 
278  character(len=19) :: timelabel
279  character(len=H_LONG) :: basename
280  !---------------------------------------------------------------------------
281 
282  if ( atmos_phy_ae_restart_out_basename /= '' ) then
283 
284  if( io_l ) write(io_fid_log,*)
285  if( io_l ) write(io_fid_log,*) '*** Create restart file (ATMOS_PHY_AE) ***'
286 
288  call time_gettimelabel( timelabel )
289  basename = trim(atmos_phy_ae_restart_out_basename)//'_'//trim(timelabel)
290  else
291  basename = trim(atmos_phy_ae_restart_out_basename)
292  endif
293 
294  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
295 
296  call fileio_create( restart_fid, & ! [OUT]
298 
299  endif
300 
301  return
302  end subroutine atmos_phy_ae_vars_restart_create
303 
304  !-----------------------------------------------------------------------------
307  use scale_fileio, only: &
309  implicit none
310 
311  if ( restart_fid /= -1 ) then
312  call fileio_enddef( restart_fid ) ! [IN]
313  endif
314 
315  return
316  end subroutine atmos_phy_ae_vars_restart_enddef
317 
318  !-----------------------------------------------------------------------------
321  use scale_fileio, only: &
323  implicit none
324  !---------------------------------------------------------------------------
325 
326  if ( restart_fid /= -1 ) then
327  if( io_l ) write(io_fid_log,*)
328  if( io_l ) write(io_fid_log,*) '*** Close restart file (ATMOS_PHY_AE) ***'
329 
330  call fileio_close( restart_fid ) ! [IN]
331 
332  restart_fid = -1
333  endif
334 
335  return
336  end subroutine atmos_phy_ae_vars_restart_close
337 
338  !-----------------------------------------------------------------------------
341  use scale_fileio, only: &
343  implicit none
344  !---------------------------------------------------------------------------
345 
346  if ( restart_fid /= -1 ) then
347  call fileio_def_var( restart_fid, var_id(1), var_name(1), var_desc(1), var_unit(1), &
348  'ZXY', atmos_phy_ae_restart_out_dtype ) ! [IN]
349  endif
350 
351  return
352  end subroutine atmos_phy_ae_vars_restart_def_var
353 
354  !-----------------------------------------------------------------------------
357  use scale_rm_statistics, only: &
359  stat_total
360  use scale_fileio, only: &
361  fileio_write_var
362  implicit none
363 
364  real(RP) :: total
365  !---------------------------------------------------------------------------
366 
367  if ( restart_fid /= -1 ) then
368 
370 
371  if ( statistics_checktotal ) then
372  call stat_total( total, atmos_phy_ae_ccn(:,:,:), var_name(1) )
373  end if
374 
375  call fileio_write_var( restart_fid, var_id(1), atmos_phy_ae_ccn(:,:,:), &
376  var_name(1), 'ZXY' ) ! [IN]
377 
378  endif
379 
380  return
381  end subroutine atmos_phy_ae_vars_restart_write
382 
383 end module mod_atmos_phy_ae_vars
logical, public atmos_phy_ae_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
character(len=h_long), public atmos_phy_ae_restart_in_basename
Basename of the input file.
integer, public is
start point of inner domain: x, local
subroutine, public atmos_phy_ae_vars_restart_create
Create restart file.
logical, public statistics_checktotal
calc&report variable totals to logfile?
subroutine, public atmos_phy_ae_vars_fillhalo
HALO Communication.
integer, public je
end point of inner domain: y, local
subroutine, public prc_mpistop
Abort MPI.
module ATMOSPHERE / Physics Aerosol Microphysics
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)
logical, public atmos_phy_ae_restart_output
output restart file?
module STDIO
Definition: scale_stdio.F90:12
integer, public ke
end point of inner domain: z, local
logical, public atmos_phy_ae_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
module FILE I/O (netcdf)
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
integer, public ka
of whole cells: z, local, with HALO
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ae_emit
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
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ae_rhoq_t
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ae_ccn
character(len=h_mid), public atmos_phy_ae_restart_out_title
title of the output file
subroutine, public atmos_phy_ae_vars_restart_enddef
Exit netCDF define mode.
module CONSTANT
Definition: scale_const.F90:14
character(len=h_short), public atmos_phy_ae_restart_out_dtype
REAL4 or REAL8.
integer, public ks
start point of inner domain: z, local
subroutine, public atmos_phy_ae_vars_setup
Setup.
subroutine, public atmos_phy_ae_vars_restart_read
Read restart.
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_ae_vars_restart_def_var
Write restart.
subroutine, public atmos_phy_ae_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_ae_vars_restart_close
Close restart file.
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
character(len=h_long), public atmos_phy_ae_restart_out_basename
Basename of the output file.
module ATMOSPHERE / Physics Aerosol Microphysics
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
subroutine, public atmos_phy_ae_vars_restart_open
Open restart file for read.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ae_ccn_t
integer, public ja
of whole cells: y, local, with HALO