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_fillhalo
35 
41 
42  !-----------------------------------------------------------------------------
43  !
44  !++ Public parameters & variables
45  !
46  logical, public :: atmos_dyn_restart_output = .false.
47 
48  character(len=H_LONG), public :: atmos_dyn_restart_in_basename = ''
49  logical, public :: atmos_dyn_restart_in_aggregate
50  logical, public :: atmos_dyn_restart_in_postfix_timelabel = .false.
51  character(len=H_LONG), public :: atmos_dyn_restart_out_basename = ''
53  logical, public :: atmos_dyn_restart_out_postfix_timelabel = .true.
54  character(len=H_MID), public :: atmos_dyn_restart_out_title = 'ATMOS_DYN restart'
55  character(len=H_SHORT), public :: atmos_dyn_restart_out_dtype = 'DEFAULT'
56 
57  ! prognostic variables
58  real(rp), public, allocatable :: prog(:,:,:,:)
59 
60  !-----------------------------------------------------------------------------
61  !
62  !++ Private procedure
63  !
64  !-----------------------------------------------------------------------------
65  !
66  !++ Private parameters & variables
67  !
68  integer, private, parameter :: vmax = 100
69  character(len=H_SHORT), private :: var_name(vmax)
70  character(len=H_MID), private :: var_desc(vmax)
71  character(len=H_SHORT), private :: var_unit(vmax)
72  integer, private :: var_id(vmax)
73  integer, private :: restart_fid = -1 ! file ID
74 
75  !-----------------------------------------------------------------------------
76 contains
77  !-----------------------------------------------------------------------------
79  subroutine atmos_dyn_vars_setup
80  use scale_prc, only: &
81  prc_abort
82  use scale_const, only: &
83  undef => const_undef
84  use mod_atmos_admin, only: &
86  use scale_atmos_dyn_tstep_short, only: &
88  implicit none
89 
90  namelist / param_atmos_dyn_vars / &
100 
101  integer :: ierr
102  integer :: iv
103  !---------------------------------------------------------------------------
104 
105  log_newline
106  log_info("ATMOS_DYN_vars_setup",*) 'Setup'
107 
108  !--- read namelist
109  rewind(io_fid_conf)
110  read(io_fid_conf,nml=param_atmos_dyn_vars,iostat=ierr)
111  if( ierr < 0 ) then !--- missing
112  log_info("ATMOS_DYN_vars_setup",*) 'Not found namelist. Default used.'
113  elseif( ierr > 0 ) then !--- fatal error
114  log_error("ATMOS_DYN_vars_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_DYN_VARS. Check!'
115  call prc_abort
116  endif
117  log_nml(param_atmos_dyn_vars)
118 
120  va, & ! [OUT]
121  var_name, & ! [OUT]
122  var_desc, & ! [OUT]
123  var_unit ) ! [OUT]
124 
125  if ( va > 0 ) then ! additional prognostic variables
126 
127  if ( va > vmax ) then
128  log_error("ATMOS_DYN_vars_setup",*) 'number of the prognostic variables is exceed the limit', va, ' > ', vmax
129  call prc_abort
130  endif
131  allocate( prog(ka,ia,ja,va) )
132  prog(:,:,:,:) = undef
133 
134  log_newline
135  log_info("ATMOS_DYN_vars_setup",*) '[ATMOS_DYN] prognostic/diagnostic variables'
136  log_info_cont('(1x,A,A24,A,A48,A,A12,A)') &
137  ' |', 'VARNAME ','|', &
138  'DESCRIPTION ', '[', 'UNIT ', ']'
139  do iv = 1, va
140  log_info_cont('(1x,A,I3,A,A24,A,A48,A,A12,A)') &
141  'NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
142  enddo
143 
144  log_newline
145  if ( atmos_dyn_restart_in_basename /= '' ) then
146  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : YES, file = ', trim(atmos_dyn_restart_in_basename)
147  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_in_postfix_timelabel
148  else
149  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : NO'
150  endif
152  .AND. atmos_dyn_restart_out_basename /= '' ) then
153  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : YES, file = ', trim(atmos_dyn_restart_out_basename)
154  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_out_postfix_timelabel
155  else
156  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : NO'
157  atmos_dyn_restart_output = .false.
158  endif
159 
160  else ! no additional prognostic variables
161 
162  allocate( prog(ka,ia,ja,1) ) ! for safety
163  prog(:,:,:,:) = undef
164  atmos_dyn_restart_output = .false.
165 
166  endif
167 
168  return
169  end subroutine atmos_dyn_vars_setup
170 
171  !-----------------------------------------------------------------------------
173  subroutine atmos_dyn_vars_fillhalo
174  use scale_comm_cartesc, only: &
175  comm_vars8, &
176  comm_wait
177  implicit none
178 
179  integer :: i, j, iv
180  !---------------------------------------------------------------------------
181 
182  do iv = 1, va
183  do j = js, je
184  do i = is, ie
185  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
186  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
187  enddo
188  enddo
189 
190  call comm_vars8( prog(:,:,:,iv), iv )
191  enddo
192 
193  do iv = 1, va
194  call comm_wait ( prog(:,:,:,iv), iv )
195  enddo
196 
197  return
198  end subroutine atmos_dyn_vars_fillhalo
199 
200  !-----------------------------------------------------------------------------
202  subroutine atmos_dyn_vars_restart_open
203  use scale_time, only: &
205  use scale_file_cartesc, only: &
207  implicit none
208 
209  character(len=19) :: timelabel
210  character(len=H_LONG) :: basename
211  !---------------------------------------------------------------------------
212 
213  if ( va < 1 ) return
214 
215  log_newline
216  log_info("ATMOS_DYN_vars_restart_open",*) 'Open restart file (ATMOS_DYN) '
217 
218  if ( atmos_dyn_restart_in_basename /= '' ) then
219 
221  call time_gettimelabel( timelabel )
222  basename = trim(atmos_dyn_restart_in_basename)//'_'//trim(timelabel)
223  else
224  basename = trim(atmos_dyn_restart_in_basename)
225  endif
226 
227  log_info("ATMOS_DYN_vars_restart_open",*) 'basename: ', trim(basename)
228 
229  call file_cartesc_open( basename, restart_fid, aggregate=atmos_dyn_restart_in_aggregate )
230  else
231  log_info("ATMOS_DYN_vars_restart_open",*) 'restart file for ATMOS_DYN is not specified.'
232  endif
233 
234  return
235  end subroutine atmos_dyn_vars_restart_open
236 
237  !-----------------------------------------------------------------------------
239  subroutine atmos_dyn_vars_restart_read
240  use scale_prc, only: &
241  prc_abort
242  use scale_file, only: &
244  use scale_file_cartesc, only: &
245  file_cartesc_read, &
247  implicit none
248 
249  integer :: i, j, iv
250  !---------------------------------------------------------------------------
251 
252  if ( restart_fid /= -1 ) then
253  log_newline
254  log_info("ATMOS_DYN_vars_restart_read",*) 'Read from restart file (ATMOS_DYN) '
255 
256  do iv = 1, va
257  call file_cartesc_read( restart_fid, var_name(iv), 'ZXY', & ! [IN]
258  prog(:,:,:,iv) ) ! [OUT]
259  enddo
260 
261  if ( file_get_aggregate(restart_fid) ) then
262  call file_cartesc_flush( restart_fid )
263  ! X/Y halos have been read from file
264 
265  ! fill K halos
266  do iv = 1, va
267  do j = 1, ja
268  do i = 1, ia
269  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
270  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
271  enddo
272  enddo
273  enddo
274  else
276  end if
277 
279 
280  else
281  if ( va > 0 ) then
282  log_error("ATMOS_DYN_vars_restart_read",*) 'invalid restart file ID for ATMOS_DYN.'
283  call prc_abort
284  end if
285  endif
286 
287  return
288  end subroutine atmos_dyn_vars_restart_read
289 
292  use scale_time, only: &
294  use scale_file_cartesc, only: &
296  implicit none
297 
298  character(len=19) :: timelabel
299  character(len=H_LONG) :: basename
300  !---------------------------------------------------------------------------
301 
302  if ( va < 1 ) return
303 
304  if ( atmos_dyn_restart_out_basename /= '' ) then
305 
306  log_newline
307  log_info("ATMOS_DYN_vars_restart_create",*) 'Create restart file (ATMOS_DYN) '
308 
310  call time_gettimelabel( timelabel )
311  basename = trim(atmos_dyn_restart_out_basename)//'_'//trim(timelabel)
312  else
313  basename = trim(atmos_dyn_restart_out_basename)
314  endif
315 
316  log_info("ATMOS_DYN_vars_restart_create",*) 'basename: ', trim(basename)
317 
318  call file_cartesc_create( &
320  restart_fid, & ! [OUT]
321  aggregate=atmos_dyn_restart_out_aggregate ) ! [IN]
322 
323  endif
324 
325  return
326  end subroutine atmos_dyn_vars_restart_create
327 
328  !-----------------------------------------------------------------------------
331  use scale_file_cartesc, only: &
333  implicit none
334 
335  if ( restart_fid /= -1 .and. va > 0 ) then
336  call file_cartesc_enddef( restart_fid ) ! [IN]
337  endif
338 
339  return
340  end subroutine atmos_dyn_vars_restart_enddef
341 
342  !-----------------------------------------------------------------------------
345  use scale_file_cartesc, only: &
347  implicit none
348  !---------------------------------------------------------------------------
349 
350  if ( restart_fid /= -1 ) then
351  log_newline
352  log_info("ATMOS_DYN_vars_restart_close",*) 'Close restart file (ATMOS_DYN) '
353 
354  call file_cartesc_close( restart_fid ) ! [IN]
355 
356  restart_fid = -1
357  endif
358 
359  return
360  end subroutine atmos_dyn_vars_restart_close
361 
362  !-----------------------------------------------------------------------------
365  use scale_file_cartesc, only: &
367  implicit none
368 
369  integer iv
370  !---------------------------------------------------------------------------
371 
372  if ( restart_fid /= -1 ) then
373 
374  do iv = 1, va
375  call file_cartesc_def_var( restart_fid, var_name(iv), var_desc(iv), var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype, &
376  var_id(iv) )
377  enddo
378 
379  endif
380 
381  return
382  end subroutine atmos_dyn_vars_restart_def_var
383 
384  !-----------------------------------------------------------------------------
387  use scale_file_cartesc, only: &
388  file_cartesc_write_var
389  implicit none
390 
391  integer :: iv
392  !---------------------------------------------------------------------------
393 
394  if ( restart_fid /= -1 ) then
395 
397 
399 
400  do iv = 1, va
401  call file_cartesc_write_var( restart_fid, var_id(iv), prog(:,:,:,iv), var_name(iv), 'ZXY' ) ! [IN]
402  enddo
403 
404  endif
405 
406  return
407  end subroutine atmos_dyn_vars_restart_write
408 
409  subroutine atmos_dyn_vars_check
410  use scale_statistics, only: &
411  statistics_total
412  use scale_atmos_grid_cartesc_real, only: &
415  implicit none
416  integer :: iv
417 
418  do iv = 1, va
419  call valcheck( ka, ks, ke, ia, is, ie, ja, js, je, &
420  prog(:,:,:,iv), & ! (in)
421  -1.0e20_rp, 1.0e20_rp, var_name(iv), & ! (in)
422  __file__, __line__ ) ! (in)
423  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
424  prog(:,:,:,iv), var_name(iv), & ! (in)
425  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
427  enddo
428 
429  return
430  end subroutine atmos_dyn_vars_check
431 
432 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:342
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:410
scale_index
module Index
Definition: scale_index.F90:11
scale_file_cartesc::file_cartesc_enddef
subroutine, public file_cartesc_enddef(fid)
Exit netCDF file define mode.
Definition: scale_file_cartesC.F90:943
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:3307
mod_atmos_dyn_vars::prog
real(rp), dimension(:,:,:,:), allocatable, public prog
Definition: mod_atmos_dyn_vars.F90:58
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:240
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:203
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:292
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:83
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:50
scale_file_cartesc::file_cartesc_close
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
Definition: scale_file_cartesC.F90:1023
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:52
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:387
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:53
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:174
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:48
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:49
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:331
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:51
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:345
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:780
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:365
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_open
subroutine, public file_cartesc_open(basename, fid, aggregate)
open a netCDF file for read
Definition: scale_file_cartesC.F90:746
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:997
scale_time::time_gettimelabel
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:91
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:4844
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:55
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:54
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:87
scale_const::const_undef
real(rp), public const_undef
Definition: scale_const.F90:41
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:56
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:46
mod_atmos_dyn_vars::atmos_dyn_vars_setup
subroutine, public atmos_dyn_vars_setup
Setup.
Definition: mod_atmos_dyn_vars.F90:80