SCALE-RM
mod_atmos_dyn_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
20  use scale_debug
22  use scale_index
23  use scale_tracer
24  !-----------------------------------------------------------------------------
25  implicit none
26  private
27  !-----------------------------------------------------------------------------
28  !
29  !++ Public procedure
30  !
31  public :: atmos_dyn_vars_setup
32  public :: atmos_dyn_vars_finalize
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_aggregate
51  logical, public :: atmos_dyn_restart_in_postfix_timelabel = .false.
52  character(len=H_LONG), public :: atmos_dyn_restart_out_basename = ''
54  logical, public :: atmos_dyn_restart_out_postfix_timelabel = .true.
55  character(len=H_MID), public :: atmos_dyn_restart_out_title = 'ATMOS_DYN restart'
56  character(len=H_SHORT), public :: atmos_dyn_restart_out_dtype = 'DEFAULT'
57 
58  ! prognostic variables
59  real(rp), public, allocatable :: prog(:,:,:,:)
60 
61  !-----------------------------------------------------------------------------
62  !
63  !++ Private procedure
64  !
65  !-----------------------------------------------------------------------------
66  !
67  !++ Private parameters & variables
68  !
69  integer, private, parameter :: vmax = 100
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  !-----------------------------------------------------------------------------
77 contains
78  !-----------------------------------------------------------------------------
80  subroutine atmos_dyn_vars_setup
81  use scale_prc, only: &
82  prc_abort
83  use scale_const, only: &
84  undef => const_undef
85  use mod_atmos_admin, only: &
87  use scale_atmos_dyn_tstep_short, only: &
89  implicit none
90 
91  namelist / param_atmos_dyn_vars / &
101 
102  integer :: ierr
103  integer :: iv
104  !---------------------------------------------------------------------------
105 
106  log_newline
107  log_info("ATMOS_DYN_vars_setup",*) 'Setup'
108 
109  !--- read namelist
110  rewind(io_fid_conf)
111  read(io_fid_conf,nml=param_atmos_dyn_vars,iostat=ierr)
112  if( ierr < 0 ) then !--- missing
113  log_info("ATMOS_DYN_vars_setup",*) 'Not found namelist. Default used.'
114  elseif( ierr > 0 ) then !--- fatal error
115  log_error("ATMOS_DYN_vars_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_DYN_VARS. Check!'
116  call prc_abort
117  endif
118  log_nml(param_atmos_dyn_vars)
119 
121  va, & ! [OUT]
122  var_name, & ! [OUT]
123  var_desc, & ! [OUT]
124  var_unit ) ! [OUT]
125 
126  if ( va > 0 ) then ! additional prognostic variables
127 
128  if ( va > vmax ) then
129  log_error("ATMOS_DYN_vars_setup",*) 'number of the prognostic variables is exceed the limit', va, ' > ', vmax
130  call prc_abort
131  endif
132  allocate( prog(ka,ia,ja,va) )
133  prog(:,:,:,:) = undef
134 
135  log_newline
136  log_info("ATMOS_DYN_vars_setup",*) '[ATMOS_DYN] prognostic/diagnostic variables'
137  log_info_cont('(1x,A,A24,A,A48,A,A12,A)') &
138  ' |', 'VARNAME ','|', &
139  'DESCRIPTION ', '[', 'UNIT ', ']'
140  do iv = 1, va
141  log_info_cont('(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  log_newline
146  if ( atmos_dyn_restart_in_basename /= '' ) then
147  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : YES, file = ', trim(atmos_dyn_restart_in_basename)
148  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_in_postfix_timelabel
149  else
150  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : NO'
151  endif
153  .AND. atmos_dyn_restart_out_basename /= '' ) then
154  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : YES, file = ', trim(atmos_dyn_restart_out_basename)
155  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_out_postfix_timelabel
156  else
157  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : NO'
158  atmos_dyn_restart_output = .false.
159  endif
160 
161  else ! no additional prognostic variables
162 
163  allocate( prog(ka,ia,ja,1) ) ! for safety
164  prog(:,:,:,:) = undef
165  atmos_dyn_restart_output = .false.
166 
167  endif
168 
169  !$acc enter data create(PROG)
170 
171  return
172  end subroutine atmos_dyn_vars_setup
173 
174  !-----------------------------------------------------------------------------
176  subroutine atmos_dyn_vars_finalize
177  implicit none
178  !---------------------------------------------------------------------------
179 
180  log_newline
181  log_info("ATMOS_DYN_vars_finalize",*) 'Finalize'
182 
183  if ( allocated( prog ) ) then
184  !$acc exit data delete(PROG)
185  deallocate( prog )
186  end if
187 
188  return
189  end subroutine atmos_dyn_vars_finalize
190 
191  !-----------------------------------------------------------------------------
193  subroutine atmos_dyn_vars_fillhalo
194  use scale_comm_cartesc, only: &
195  comm_vars8, &
196  comm_wait
197  implicit none
198 
199  integer :: i, j, iv
200  !---------------------------------------------------------------------------
201 
202  do iv = 1, va
203  !acc kernels
204  do j = js, je
205  do i = is, ie
206  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
207  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
208  enddo
209  enddo
210  !acc end kernels
211 
212  call comm_vars8( prog(:,:,:,iv), iv )
213  enddo
214 
215  do iv = 1, va
216  call comm_wait ( prog(:,:,:,iv), iv )
217  enddo
218 
219  return
220  end subroutine atmos_dyn_vars_fillhalo
221 
222  !-----------------------------------------------------------------------------
224  subroutine atmos_dyn_vars_restart_open
225  use scale_time, only: &
227  use scale_file_cartesc, only: &
229  implicit none
230 
231  character(len=19) :: timelabel
232  character(len=H_LONG) :: basename
233  !---------------------------------------------------------------------------
234 
235  if ( va < 1 ) return
236 
237  log_newline
238  log_info("ATMOS_DYN_vars_restart_open",*) 'Open restart file (ATMOS_DYN) '
239 
240  if ( atmos_dyn_restart_in_basename /= '' ) then
241 
243  call time_gettimelabel( timelabel )
244  basename = trim(atmos_dyn_restart_in_basename)//'_'//trim(timelabel)
245  else
246  basename = trim(atmos_dyn_restart_in_basename)
247  endif
248 
249  log_info("ATMOS_DYN_vars_restart_open",*) 'basename: ', trim(basename)
250 
251  call file_cartesc_open( basename, restart_fid, aggregate=atmos_dyn_restart_in_aggregate )
252  else
253  log_info("ATMOS_DYN_vars_restart_open",*) 'restart file for ATMOS_DYN is not specified.'
254  endif
255 
256  return
257  end subroutine atmos_dyn_vars_restart_open
258 
259  !-----------------------------------------------------------------------------
261  subroutine atmos_dyn_vars_restart_read
262  use scale_prc, only: &
263  prc_abort
264  use scale_file, only: &
266  use scale_file_cartesc, only: &
267  file_cartesc_read, &
269  implicit none
270 
271  integer :: i, j, iv
272  !---------------------------------------------------------------------------
273 
274  if ( restart_fid /= -1 ) then
275  log_newline
276  log_info("ATMOS_DYN_vars_restart_read",*) 'Read from restart file (ATMOS_DYN) '
277 
278  do iv = 1, va
279  call file_cartesc_read( restart_fid, var_name(iv), 'ZXY', & ! [IN]
280  prog(:,:,:,iv) ) ! [OUT]
281  enddo
282 
283  if ( file_get_aggregate(restart_fid) ) then
284  call file_cartesc_flush( restart_fid )
285  !$acc update device(PROG)
286  ! X/Y halos have been read from file
287 
288  ! fill K halos
289  !acc kernels copy(PROG)
290  do iv = 1, va
291  do j = 1, ja
292  do i = 1, ia
293  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
294  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
295  enddo
296  enddo
297  enddo
298  !acc end kernels
299  else
301  end if
302 
304 
305  else
306  if ( va > 0 ) then
307  log_error("ATMOS_DYN_vars_restart_read",*) 'invalid restart file ID for ATMOS_DYN.'
308  call prc_abort
309  end if
310  endif
311 
312  return
313  end subroutine atmos_dyn_vars_restart_read
314 
317  use scale_time, only: &
319  use scale_file_cartesc, only: &
321  implicit none
322 
323  character(len=19) :: timelabel
324  character(len=H_LONG) :: basename
325  !---------------------------------------------------------------------------
326 
327  if ( va < 1 ) return
328 
329  if ( atmos_dyn_restart_out_basename /= '' ) then
330 
331  log_newline
332  log_info("ATMOS_DYN_vars_restart_create",*) 'Create restart file (ATMOS_DYN) '
333 
335  call time_gettimelabel( timelabel )
336  basename = trim(atmos_dyn_restart_out_basename)//'_'//trim(timelabel)
337  else
338  basename = trim(atmos_dyn_restart_out_basename)
339  endif
340 
341  log_info("ATMOS_DYN_vars_restart_create",*) 'basename: ', trim(basename)
342 
343  call file_cartesc_create( &
345  restart_fid, & ! [OUT]
346  aggregate=atmos_dyn_restart_out_aggregate ) ! [IN]
347 
348  endif
349 
350  return
351  end subroutine atmos_dyn_vars_restart_create
352 
353  !-----------------------------------------------------------------------------
356  use scale_file_cartesc, only: &
358  implicit none
359 
360  if ( restart_fid /= -1 .and. va > 0 ) then
361  call file_cartesc_enddef( restart_fid ) ! [IN]
362  endif
363 
364  return
365  end subroutine atmos_dyn_vars_restart_enddef
366 
367  !-----------------------------------------------------------------------------
370  use scale_file_cartesc, only: &
372  implicit none
373  !---------------------------------------------------------------------------
374 
375  if ( restart_fid /= -1 ) then
376  log_newline
377  log_info("ATMOS_DYN_vars_restart_close",*) 'Close restart file (ATMOS_DYN) '
378 
379  call file_cartesc_close( restart_fid ) ! [IN]
380 
381  restart_fid = -1
382  endif
383 
384  return
385  end subroutine atmos_dyn_vars_restart_close
386 
387  !-----------------------------------------------------------------------------
390  use scale_file_cartesc, only: &
392  implicit none
393 
394  integer iv
395  !---------------------------------------------------------------------------
396 
397  if ( restart_fid /= -1 ) then
398 
399  do iv = 1, va
400  call file_cartesc_def_var( restart_fid, var_name(iv), var_desc(iv), var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype, &
401  var_id(iv) )
402  enddo
403 
404  endif
405 
406  return
407  end subroutine atmos_dyn_vars_restart_def_var
408 
409  !-----------------------------------------------------------------------------
412  use scale_file_cartesc, only: &
413  file_cartesc_write_var
414  implicit none
415 
416  integer :: iv
417  !---------------------------------------------------------------------------
418 
419  if ( restart_fid /= -1 ) then
420 
422 
424 
425  !$acc update host(PROG)
426  do iv = 1, va
427  call file_cartesc_write_var( restart_fid, var_id(iv), prog(:,:,:,iv), var_name(iv), 'ZXY' ) ! [IN]
428  enddo
429 
430  endif
431 
432  return
433  end subroutine atmos_dyn_vars_restart_write
434 
435  subroutine atmos_dyn_vars_check
436  use scale_statistics, only: &
437  statistics_total
438  use scale_atmos_grid_cartesc_real, only: &
441  implicit none
442  integer :: iv
443 
444  do iv = 1, va
445  call valcheck( ka, ks, ke, ia, is, ie, ja, js, je, &
446  prog(:,:,:,iv), & ! (in)
447  -1.0e20_rp, 1.0e20_rp, var_name(iv), & ! (in)
448  __file__, __line__ ) ! (in)
449  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
450  prog(:,:,:,iv), var_name(iv), & ! (in)
451  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
453  enddo
454 
455  return
456  end subroutine atmos_dyn_vars_check
457 
458 end module mod_atmos_dyn_vars
scale_statistics
module Statistics
Definition: scale_statistics.F90:11
scale_atmos_grid_cartesc_index::ke
integer, public ke
end point of inner domain: z, local
Definition: scale_atmos_grid_cartesC_index.F90:52
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:350
mod_atmos_dyn_vars
module Atmosphere / Dynamics
Definition: mod_atmos_dyn_vars.F90:12
mod_atmos_dyn_vars::atmos_dyn_vars_check
subroutine atmos_dyn_vars_check
Definition: mod_atmos_dyn_vars.F90:436
scale_index
module Index
Definition: scale_index.F90:11
mod_atmos_dyn_vars::atmos_dyn_vars_finalize
subroutine, public atmos_dyn_vars_finalize
Finalize.
Definition: mod_atmos_dyn_vars.F90:177
scale_file_cartesc::file_cartesc_enddef
subroutine, public file_cartesc_enddef(fid)
Exit netCDF file define mode.
Definition: scale_file_cartesC.F90:964
scale_file_cartesc::file_cartesc_def_var
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.
Definition: scale_file_cartesC.F90:3360
mod_atmos_dyn_vars::prog
real(rp), dimension(:,:,:,:), allocatable, public prog
Definition: mod_atmos_dyn_vars.F90:59
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_atmos_grid_cartesc_index::ka
integer, public ka
Definition: scale_atmos_grid_cartesC_index.F90:47
mod_atmos_admin
module ATMOS admin
Definition: mod_atmos_admin.F90:11
mod_atmos_dyn_vars::atmos_dyn_vars_restart_read
subroutine, public atmos_dyn_vars_restart_read
Read restart.
Definition: mod_atmos_dyn_vars.F90:262
scale_atmos_grid_cartesc_real
module Atmosphere GRID CartesC Real(real space)
Definition: scale_atmos_grid_cartesC_real.F90:11
scale_file
module file
Definition: scale_file.F90:15
scale_index::va
integer, public va
Definition: scale_index.F90:35
scale_prc
module PROCESS
Definition: scale_prc.F90:11
mod_atmos_dyn_vars::atmos_dyn_vars_restart_open
subroutine, public atmos_dyn_vars_restart_open
Open restart file for read.
Definition: mod_atmos_dyn_vars.F90:225
scale_precision::rp
integer, parameter, public rp
Definition: scale_precision.F90:41
scale_atmos_grid_cartesc_index::ie
integer, public ie
end point of inner domain: x, local
Definition: scale_atmos_grid_cartesC_index.F90:54
scale_io
module STDIO
Definition: scale_io.F90:10
mod_atmos_dyn_vars::atmos_dyn_vars_restart_create
subroutine, public atmos_dyn_vars_restart_create
Create restart file.
Definition: mod_atmos_dyn_vars.F90:317
scale_atmos_grid_cartesc_index
module atmosphere / grid / cartesC index
Definition: scale_atmos_grid_cartesC_index.F90:12
scale_const
module CONSTANT
Definition: scale_const.F90:11
scale_atmos_grid_cartesc_index::ia
integer, public ia
Definition: scale_atmos_grid_cartesC_index.F90:48
scale_atmos_grid_cartesc_real::atmos_grid_cartesc_real_vol
real(rp), dimension(:,:,:), allocatable, public atmos_grid_cartesc_real_vol
control volume (zxy) [m3]
Definition: scale_atmos_grid_cartesC_real.F90:84
mod_atmos_dyn_vars::atmos_dyn_restart_in_postfix_timelabel
logical, public atmos_dyn_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
Definition: mod_atmos_dyn_vars.F90:51
scale_file_cartesc::file_cartesc_close
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
Definition: scale_file_cartesC.F90:1044
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_atmos_grid_cartesc_index::is
integer, public is
start point of inner domain: x, local
Definition: scale_atmos_grid_cartesC_index.F90:53
mod_atmos_dyn_vars::atmos_dyn_restart_out_aggregate
logical, public atmos_dyn_restart_out_aggregate
Switch to use aggregate file.
Definition: mod_atmos_dyn_vars.F90:53
scale_atmos_grid_cartesc_index::ja
integer, public ja
Definition: scale_atmos_grid_cartesC_index.F90:49
scale_time
module TIME
Definition: scale_time.F90:11
scale_atmos_dyn_tstep_short
module Atmosphere / Dynamical scheme
Definition: scale_atmos_dyn_tstep_short.F90:12
mod_atmos_dyn_vars::atmos_dyn_vars_restart_write
subroutine, public atmos_dyn_vars_restart_write
Write variables to restart file.
Definition: mod_atmos_dyn_vars.F90:412
mod_atmos_dyn_vars::atmos_dyn_restart_out_postfix_timelabel
logical, public atmos_dyn_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
Definition: mod_atmos_dyn_vars.F90:54
scale_tracer
module TRACER
Definition: scale_tracer.F90:12
mod_atmos_dyn_vars::atmos_dyn_vars_fillhalo
subroutine, public atmos_dyn_vars_fillhalo
HALO Communication.
Definition: mod_atmos_dyn_vars.F90:194
mod_atmos_dyn_vars::atmos_dyn_restart_in_basename
character(len=h_long), public atmos_dyn_restart_in_basename
Basename of the input file.
Definition: mod_atmos_dyn_vars.F90:49
mod_atmos_dyn_vars::atmos_dyn_restart_in_aggregate
logical, public atmos_dyn_restart_in_aggregate
Switch to use aggregate file.
Definition: mod_atmos_dyn_vars.F90:50
mod_atmos_dyn_vars::atmos_dyn_vars_restart_enddef
subroutine, public atmos_dyn_vars_restart_enddef
Exit netCDF define mode.
Definition: mod_atmos_dyn_vars.F90:356
scale_atmos_grid_cartesc_index::ks
integer, public ks
start point of inner domain: z, local
Definition: scale_atmos_grid_cartesC_index.F90:51
mod_atmos_dyn_vars::atmos_dyn_restart_out_basename
character(len=h_long), public atmos_dyn_restart_out_basename
Basename of the output file.
Definition: mod_atmos_dyn_vars.F90:52
scale_debug
module DEBUG
Definition: scale_debug.F90:11
mod_atmos_dyn_vars::atmos_dyn_vars_restart_close
subroutine, public atmos_dyn_vars_restart_close
Close restart file.
Definition: mod_atmos_dyn_vars.F90:370
scale_file_cartesc::file_cartesc_create
subroutine, public file_cartesc_create(basename, title, datatype, fid, date, subsec, haszcoord, append, aggregate, single)
Create/open a netCDF file.
Definition: scale_file_cartesC.F90:796
mod_atmos_dyn_vars::atmos_dyn_vars_restart_def_var
subroutine, public atmos_dyn_vars_restart_def_var
Define variables in restart file.
Definition: mod_atmos_dyn_vars.F90:390
mod_atmos_admin::atmos_dyn_type
character(len=h_short), public atmos_dyn_type
Definition: mod_atmos_admin.F90:35
scale_file_cartesc::file_cartesc_flush
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
Definition: scale_file_cartesC.F90:1018
scale_time::time_gettimelabel
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:93
scale_comm_cartesc
module COMMUNICATION
Definition: scale_comm_cartesC.F90:11
scale_atmos_dyn_tstep_short::atmos_dyn_tstep_short_regist
subroutine, public atmos_dyn_tstep_short_regist(ATMOS_DYN_TYPE, VA_out, VAR_NAME, VAR_DESC, VAR_UNIT)
Register.
Definition: scale_atmos_dyn_tstep_short.F90:158
scale_atmos_grid_cartesc_index::js
integer, public js
start point of inner domain: y, local
Definition: scale_atmos_grid_cartesC_index.F90:55
scale_file::file_get_aggregate
logical function, public file_get_aggregate(fid)
Definition: scale_file.F90:6316
scale_file_cartesc::file_cartesc_open
subroutine, public file_cartesc_open(basename, fid, single, aggregate)
open a netCDF file for read
Definition: scale_file_cartesC.F90:760
mod_atmos_dyn_vars::atmos_dyn_restart_out_dtype
character(len=h_short), public atmos_dyn_restart_out_dtype
REAL4 or REAL8.
Definition: mod_atmos_dyn_vars.F90:56
mod_atmos_dyn_vars::atmos_dyn_restart_out_title
character(len=h_mid), public atmos_dyn_restart_out_title
title of the output file
Definition: mod_atmos_dyn_vars.F90:55
scale_atmos_grid_cartesc_real::atmos_grid_cartesc_real_totvol
real(rp), public atmos_grid_cartesc_real_totvol
total volume (zxy, local) [m3]
Definition: scale_atmos_grid_cartesC_real.F90:88
scale_const::const_undef
real(rp), public const_undef
Definition: scale_const.F90:43
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:57
scale_atmos_grid_cartesc_index::je
integer, public je
end point of inner domain: y, local
Definition: scale_atmos_grid_cartesC_index.F90:56
scale_file_cartesc
module file / cartesianC
Definition: scale_file_cartesC.F90:11
mod_atmos_dyn_vars::atmos_dyn_restart_output
logical, public atmos_dyn_restart_output
output restart file?
Definition: mod_atmos_dyn_vars.F90:47
mod_atmos_dyn_vars::atmos_dyn_vars_setup
subroutine, public atmos_dyn_vars_setup
Setup.
Definition: mod_atmos_dyn_vars.F90:81