SCALE-RM
mod_atmos_dyn_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_index
24  use scale_tracer
25  !-----------------------------------------------------------------------------
26  implicit none
27  private
28  !-----------------------------------------------------------------------------
29  !
30  !++ Public procedure
31  !
32  public :: atmos_dyn_vars_setup
33  public :: atmos_dyn_vars_fillhalo
36 
42 
43  !-----------------------------------------------------------------------------
44  !
45  !++ Public parameters & variables
46  !
47  logical, public :: atmos_dyn_restart_output = .false.
48 
49  character(len=H_LONG), public :: atmos_dyn_restart_in_basename = ''
50  logical, public :: atmos_dyn_restart_in_postfix_timelabel = .false.
51  character(len=H_LONG), public :: atmos_dyn_restart_out_basename = ''
52  logical, public :: atmos_dyn_restart_out_postfix_timelabel = .true.
53  character(len=H_MID), public :: atmos_dyn_restart_out_title = 'ATMOS_DYN restart'
54  character(len=H_SHORT), public :: atmos_dyn_restart_out_dtype = 'DEFAULT'
55 
56  ! prognostic variables
57  real(RP), public, allocatable :: prog(:,:,:,:)
58 
59  !-----------------------------------------------------------------------------
60  !
61  !++ Private procedure
62  !
63  !-----------------------------------------------------------------------------
64  !
65  !++ Private parameters & variables
66  !
67  integer, private, parameter :: vmax = 100
68  character(len=H_SHORT), private :: var_name(vmax)
69  character(len=H_MID), private :: var_desc(vmax)
70  character(len=H_SHORT), private :: var_unit(vmax)
71  integer, private :: var_id(vmax)
72  integer, private :: restart_fid = -1 ! file ID
73 
74  !-----------------------------------------------------------------------------
75 contains
76  !-----------------------------------------------------------------------------
78  subroutine atmos_dyn_vars_setup
79  use scale_process, only: &
81  use scale_const, only: &
82  undef => const_undef
83  use mod_atmos_admin, only: &
85  use scale_atmos_dyn_tstep_short, only: &
87  implicit none
88 
89  namelist / param_atmos_dyn_vars / &
97 
98  integer :: ierr
99  integer :: iv
100  !---------------------------------------------------------------------------
101 
102  if( io_l ) write(io_fid_log,*)
103  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS DYN] / Origin[SCALE-RM]'
104 
105  !--- read namelist
106  rewind(io_fid_conf)
107  read(io_fid_conf,nml=param_atmos_dyn_vars,iostat=ierr)
108  if( ierr < 0 ) then !--- missing
109  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
110  elseif( ierr > 0 ) then !--- fatal error
111  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_DYN_VARS. Check!'
112  call prc_mpistop
113  endif
114  if( io_nml ) write(io_fid_nml,nml=param_atmos_dyn_vars)
115 
117  va, & ! [OUT]
118  var_name, & ! [OUT]
119  var_desc, & ! [OUT]
120  var_unit ) ! [OUT]
121 
122  if ( va > 0 ) then ! additional prognostic variables
123 
124  if ( va > vmax ) then
125  write(*,*) 'xxx number of the prognostic variables is exceed the limit', va, ' > ', vmax
126  call prc_mpistop
127  endif
128  allocate( prog(ka,ia,ja,va) )
129  prog(:,:,:,:) = undef
130 
131  if( io_l ) write(io_fid_log,*)
132  if( io_l ) write(io_fid_log,*) '*** [ATMOS_DYN] prognostic/diagnostic variables'
133  if( io_l ) write(io_fid_log,'(1x,A,A24,A,A48,A,A12,A)') &
134  '*** |', 'VARNAME ','|', &
135  'DESCRIPTION ', '[', 'UNIT ', ']'
136  do iv = 1, va
137  if( io_l ) write(io_fid_log,'(1x,A,I3,A,A24,A,A48,A,A12,A)') &
138  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
139  enddo
140 
141  if( io_l ) write(io_fid_log,*)
142  if ( atmos_dyn_restart_in_basename /= '' ) then
143  if( io_l ) write(io_fid_log,*) '*** Restart input? : YES, file = ', trim(atmos_dyn_restart_in_basename)
144  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_dyn_restart_in_postfix_timelabel
145  else
146  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
147  endif
149  .AND. atmos_dyn_restart_out_basename /= '' ) then
150  if( io_l ) write(io_fid_log,*) '*** Restart output? : YES, file = ', trim(atmos_dyn_restart_out_basename)
151  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_dyn_restart_out_postfix_timelabel
152  else
153  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
154  atmos_dyn_restart_output = .false.
155  endif
156 
157  else ! no additional prognostic variables
158 
159  allocate( prog(ka,ia,ja,1) ) ! for safety
160  prog(:,:,:,:) = undef
161  atmos_dyn_restart_output = .false.
162 
163  endif
164 
165  return
166  end subroutine atmos_dyn_vars_setup
167 
168  !-----------------------------------------------------------------------------
170  subroutine atmos_dyn_vars_fillhalo
171  use scale_comm, only: &
172  comm_vars8, &
173  comm_wait
174  implicit none
175 
176  integer :: i, j, iv
177  !---------------------------------------------------------------------------
178 
179  do iv = 1, va
180  do j = js, je
181  do i = is, ie
182  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
183  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
184  enddo
185  enddo
186 
187  call comm_vars8( prog(:,:,:,iv), iv )
188  enddo
189 
190  do iv = 1, va
191  call comm_wait ( prog(:,:,:,iv), iv )
192  enddo
193 
194  return
195  end subroutine atmos_dyn_vars_fillhalo
196 
197  !-----------------------------------------------------------------------------
199  subroutine atmos_dyn_vars_restart_open
200  use scale_time, only: &
202  use scale_fileio, only: &
204  implicit none
205 
206  character(len=19) :: timelabel
207  character(len=H_LONG) :: basename
208  !---------------------------------------------------------------------------
209 
210  if( io_l ) write(io_fid_log,*)
211  if( io_l ) write(io_fid_log,*) '*** Open restart file (ATMOS_DYN) ***'
212 
213  if ( atmos_dyn_restart_in_basename /= '' ) then
214 
216  call time_gettimelabel( timelabel )
217  basename = trim(atmos_dyn_restart_in_basename)//'_'//trim(timelabel)
218  else
219  basename = trim(atmos_dyn_restart_in_basename)
220  endif
221 
222  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
223 
224  call fileio_open( restart_fid, basename )
225  else
226  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_DYN is not specified.'
227  endif
228 
229  return
230  end subroutine atmos_dyn_vars_restart_open
231 
232  !-----------------------------------------------------------------------------
234  subroutine atmos_dyn_vars_restart_read
235  use scale_rm_statistics, only: &
237  stat_total
238  use scale_fileio, only: &
239  fileio_read, &
241  implicit none
242 
243  real(RP) :: total
244  integer :: i, j, iv
245  !---------------------------------------------------------------------------
246 
247  if ( restart_fid /= -1 ) then
248  if( io_l ) write(io_fid_log,*)
249  if( io_l ) write(io_fid_log,*) '*** Read from restart file (ATMOS_DYN) ***'
250 
251  do iv = 1, va
252  call fileio_read( prog(:,:,:,iv), & ! [OUT]
253  restart_fid, var_name(iv), 'ZXY', step=1 ) ! [IN]
254  enddo
255 
256  if ( io_aggregate ) then
257  call fileio_flush( restart_fid )
258  ! X/Y halos have been read from file
259 
260  ! fill K halos
261  do iv = 1, va
262  do j = 1, ja
263  do i = 1, ia
264  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
265  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
266  enddo
267  enddo
268  enddo
269  else
271  end if
272 
273  if ( statistics_checktotal ) then
274  do iv = 1, va
275  call stat_total( total, prog(:,:,:,iv), var_name(iv) )
276  enddo
277  endif
278  else
279  if( io_l ) write(io_fid_log,*) '*** invalid restart file ID for ATMOS_DYN.'
280  endif
281 
282  return
283  end subroutine atmos_dyn_vars_restart_read
284 
287  use scale_time, only: &
289  use scale_fileio, only: &
291  implicit none
292 
293  character(len=19) :: timelabel
294  character(len=H_LONG) :: basename
295  !---------------------------------------------------------------------------
296 
297  if ( atmos_dyn_restart_out_basename /= '' ) then
298 
299  if( io_l ) write(io_fid_log,*)
300  if( io_l ) write(io_fid_log,*) '*** Create restart file (ATMOS_DYN) ***'
301 
303  call time_gettimelabel( timelabel )
304  basename = trim(atmos_dyn_restart_out_basename)//'_'//trim(timelabel)
305  else
306  basename = trim(atmos_dyn_restart_out_basename)
307  endif
308 
309  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
310 
311  call fileio_create( restart_fid, & ! [OUT]
313 
314  endif
315 
316  return
317  end subroutine atmos_dyn_vars_restart_create
318 
319  !-----------------------------------------------------------------------------
322  use scale_fileio, only: &
324  implicit none
325 
326  if ( restart_fid /= -1 ) then
327  call fileio_enddef( restart_fid ) ! [IN]
328  endif
329 
330  return
331  end subroutine atmos_dyn_vars_restart_enddef
332 
333  !-----------------------------------------------------------------------------
336  use scale_fileio, only: &
338  implicit none
339  !---------------------------------------------------------------------------
340 
341  if ( restart_fid /= -1 ) then
342  if( io_l ) write(io_fid_log,*)
343  if( io_l ) write(io_fid_log,*) '*** Close restart file (ATMOS_DYN) ***'
344 
345  call fileio_close( restart_fid ) ! [IN]
346 
347  restart_fid = -1
348  endif
349 
350  return
351  end subroutine atmos_dyn_vars_restart_close
352 
353  !-----------------------------------------------------------------------------
356  use scale_fileio, only: &
358  implicit none
359 
360  integer iv
361  !---------------------------------------------------------------------------
362 
363  if ( restart_fid /= -1 ) then
364 
365  do iv = 1, va
366  call fileio_def_var( restart_fid, var_id(iv), var_name(iv), var_desc(iv), &
367  var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype ) ! [IN]
368  enddo
369 
370  endif
371 
372  return
373  end subroutine atmos_dyn_vars_restart_def_var
374 
375  !-----------------------------------------------------------------------------
378  use scale_rm_statistics, only: &
380  stat_total
381  use scale_fileio, only: &
382  fileio_write_var
383  implicit none
384 
385  real(RP) :: total
386  integer :: iv
387  !---------------------------------------------------------------------------
388 
389  if ( restart_fid /= -1 ) then
390 
392 
393  if ( statistics_checktotal ) then
394  do iv = 1, va
395  call stat_total( total, prog(:,:,:,iv), var_name(iv) )
396  enddo
397  endif
398 
399  do iv = 1, va
400  call fileio_write_var( restart_fid, var_id(iv), prog(:,:,:,iv), var_name(iv), 'ZXY' ) ! [IN]
401  enddo
402 
403  endif
404 
405  return
406  end subroutine atmos_dyn_vars_restart_write
407 
408 end module mod_atmos_dyn_vars
module ATMOS admin
logical, public atmos_dyn_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
integer, public is
start point of inner domain: x, local
subroutine, public atmos_dyn_vars_restart_def_var
Define variables in restart file.
logical, public statistics_checktotal
calc&report variable totals to logfile?
integer, public je
end point of inner domain: y, local
subroutine, public atmos_dyn_vars_restart_open
Open restart file for read.
subroutine, public prc_mpistop
Abort MPI.
integer, public va
Definition: scale_index.F90:38
character(len=h_short), public atmos_dyn_restart_out_dtype
REAL4 or REAL8.
module Atmosphere / Dynamical scheme
character(len=h_long), public atmos_dyn_restart_in_basename
Basename of the input file.
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:61
subroutine, public atmos_dyn_vars_restart_enddef
Exit netCDF define mode.
module Atmosphere / Dynamics
subroutine, public fileio_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
subroutine, public atmos_dyn_vars_restart_close
Close restart file.
module STDIO
Definition: scale_stdio.F90:12
integer, public ke
end point of inner domain: z, local
subroutine, public atmos_dyn_vars_restart_write
Write variables to restart file.
logical, public atmos_dyn_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
module FILE I/O (netcdf)
subroutine, public atmos_dyn_vars_fillhalo
HALO Communication.
character(len=h_mid), public atmos_dyn_restart_out_title
title of the output 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
module Index
Definition: scale_index.F90:14
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
logical, public atmos_dyn_restart_output
output restart 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
subroutine, public atmos_dyn_vars_restart_read
Read restart.
module PROCESS
subroutine, public atmos_dyn_tstep_short_regist(ATMOS_DYN_TYPE, VA_out, VAR_NAME, VAR_DESC, VAR_UNIT)
Register.
real(rp), dimension(:,:,:,:), allocatable, public prog
module CONSTANT
Definition: scale_const.F90:14
integer, public ks
start point of inner domain: z, local
subroutine, public atmos_dyn_vars_setup
Setup.
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.
character(len=h_short), public atmos_dyn_type
subroutine, public fileio_close(fid)
Close a netCDF file.
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
subroutine, public atmos_dyn_vars_restart_create
Create restart file.
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
character(len=h_long), public atmos_dyn_restart_out_basename
Basename of the output file.
integer, public ja
of whole cells: y, local, with HALO