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
21  use scale_index
22  use scale_tracer
23  !-----------------------------------------------------------------------------
24  implicit none
25  private
26  !-----------------------------------------------------------------------------
27  !
28  !++ Public procedure
29  !
30  public :: atmos_dyn_vars_setup
31  public :: atmos_dyn_vars_fillhalo
34 
40 
41  !-----------------------------------------------------------------------------
42  !
43  !++ Public parameters & variables
44  !
45  logical, public :: atmos_dyn_restart_output = .false.
46 
47  character(len=H_LONG), public :: atmos_dyn_restart_in_basename = ''
48  logical, public :: atmos_dyn_restart_in_aggregate
49  logical, public :: atmos_dyn_restart_in_postfix_timelabel = .false.
50  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_prc, only: &
80  prc_abort
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 / &
99 
100  integer :: ierr
101  integer :: iv
102  !---------------------------------------------------------------------------
103 
104  log_newline
105  log_info("ATMOS_DYN_vars_setup",*) 'Setup'
106 
107  !--- read namelist
108  rewind(io_fid_conf)
109  read(io_fid_conf,nml=param_atmos_dyn_vars,iostat=ierr)
110  if( ierr < 0 ) then !--- missing
111  log_info("ATMOS_DYN_vars_setup",*) 'Not found namelist. Default used.'
112  elseif( ierr > 0 ) then !--- fatal error
113  log_error("ATMOS_DYN_vars_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_DYN_VARS. Check!'
114  call prc_abort
115  endif
116  log_nml(param_atmos_dyn_vars)
117 
119  va, & ! [OUT]
120  var_name, & ! [OUT]
121  var_desc, & ! [OUT]
122  var_unit ) ! [OUT]
123 
124  if ( va > 0 ) then ! additional prognostic variables
125 
126  if ( va > vmax ) then
127  log_error("ATMOS_DYN_vars_setup",*) 'number of the prognostic variables is exceed the limit', va, ' > ', vmax
128  call prc_abort
129  endif
130  allocate( prog(ka,ia,ja,va) )
131  prog(:,:,:,:) = undef
132 
133  log_newline
134  log_info("ATMOS_DYN_vars_setup",*) '[ATMOS_DYN] prognostic/diagnostic variables'
135  log_info_cont('(1x,A,A24,A,A48,A,A12,A)') &
136  ' |', 'VARNAME ','|', &
137  'DESCRIPTION ', '[', 'UNIT ', ']'
138  do iv = 1, va
139  log_info_cont('(1x,A,I3,A,A24,A,A48,A,A12,A)') &
140  'NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
141  enddo
142 
143  log_newline
144  if ( atmos_dyn_restart_in_basename /= '' ) then
145  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : YES, file = ', trim(atmos_dyn_restart_in_basename)
146  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_in_postfix_timelabel
147  else
148  log_info("ATMOS_DYN_vars_setup",*) 'Restart input? : NO'
149  endif
151  .AND. atmos_dyn_restart_out_basename /= '' ) then
152  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : YES, file = ', trim(atmos_dyn_restart_out_basename)
153  log_info("ATMOS_DYN_vars_setup",*) 'Add timelabel? : ', atmos_dyn_restart_out_postfix_timelabel
154  else
155  log_info("ATMOS_DYN_vars_setup",*) 'Restart output? : NO'
156  atmos_dyn_restart_output = .false.
157  endif
158 
159  else ! no additional prognostic variables
160 
161  allocate( prog(ka,ia,ja,1) ) ! for safety
162  prog(:,:,:,:) = undef
163  atmos_dyn_restart_output = .false.
164 
165  endif
166 
167  return
168  end subroutine atmos_dyn_vars_setup
169 
170  !-----------------------------------------------------------------------------
172  subroutine atmos_dyn_vars_fillhalo
173  use scale_comm_cartesc, only: &
174  comm_vars8, &
175  comm_wait
176  implicit none
177 
178  integer :: i, j, iv
179  !---------------------------------------------------------------------------
180 
181  do iv = 1, va
182  do j = js, je
183  do i = is, ie
184  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
185  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
186  enddo
187  enddo
188 
189  call comm_vars8( prog(:,:,:,iv), iv )
190  enddo
191 
192  do iv = 1, va
193  call comm_wait ( prog(:,:,:,iv), iv )
194  enddo
195 
196  return
197  end subroutine atmos_dyn_vars_fillhalo
198 
199  !-----------------------------------------------------------------------------
201  subroutine atmos_dyn_vars_restart_open
202  use scale_time, only: &
204  use scale_file_cartesc, only: &
206  implicit none
207 
208  character(len=19) :: timelabel
209  character(len=H_LONG) :: basename
210  !---------------------------------------------------------------------------
211 
212  if ( va < 1 ) return
213 
214  log_newline
215  log_info("ATMOS_DYN_vars_restart_open",*) 'Open restart file (ATMOS_DYN) '
216 
217  if ( atmos_dyn_restart_in_basename /= '' ) then
218 
220  call time_gettimelabel( timelabel )
221  basename = trim(atmos_dyn_restart_in_basename)//'_'//trim(timelabel)
222  else
223  basename = trim(atmos_dyn_restart_in_basename)
224  endif
225 
226  log_info("ATMOS_DYN_vars_restart_open",*) 'basename: ', trim(basename)
227 
228  call file_cartesc_open( basename, restart_fid, aggregate=atmos_dyn_restart_in_aggregate )
229  else
230  log_info("ATMOS_DYN_vars_restart_open",*) 'restart file for ATMOS_DYN is not specified.'
231  endif
232 
233  return
234  end subroutine atmos_dyn_vars_restart_open
235 
236  !-----------------------------------------------------------------------------
238  subroutine atmos_dyn_vars_restart_read
239  use scale_prc, only: &
240  prc_abort
241  use scale_statistics, only: &
243  statistics_total
244  use scale_atmos_grid_cartesc_real, only: &
247  use scale_file, only: &
249  use scale_file_cartesc, only: &
250  file_cartesc_read, &
252  implicit none
253 
254  integer :: i, j, iv
255  !---------------------------------------------------------------------------
256 
257  if ( restart_fid /= -1 ) then
258  log_newline
259  log_info("ATMOS_DYN_vars_restart_read",*) 'Read from restart file (ATMOS_DYN) '
260 
261  do iv = 1, va
262  call file_cartesc_read( restart_fid, var_name(iv), 'ZXY', & ! [IN]
263  prog(:,:,:,iv) ) ! [OUT]
264  enddo
265 
266  if ( file_get_aggregate(restart_fid) ) then
267  call file_cartesc_flush( restart_fid )
268  ! X/Y halos have been read from file
269 
270  ! fill K halos
271  do iv = 1, va
272  do j = 1, ja
273  do i = 1, ia
274  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
275  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
276  enddo
277  enddo
278  enddo
279  else
281  end if
282 
283  if ( statistics_checktotal ) then
284  do iv = 1, va
285  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
286  prog(:,:,:,iv), var_name(iv), & ! (in)
287  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
289  enddo
290  endif
291  else
292  if ( va > 0 ) then
293  log_error("ATMOS_DYN_vars_restart_read",*) 'invalid restart file ID for ATMOS_DYN.'
294  call prc_abort
295  end if
296  endif
297 
298  return
299  end subroutine atmos_dyn_vars_restart_read
300 
303  use scale_time, only: &
305  use scale_file_cartesc, only: &
307  implicit none
308 
309  character(len=19) :: timelabel
310  character(len=H_LONG) :: basename
311  !---------------------------------------------------------------------------
312 
313  if ( va < 1 ) return
314 
315  if ( atmos_dyn_restart_out_basename /= '' ) then
316 
317  log_newline
318  log_info("ATMOS_DYN_vars_restart_create",*) 'Create restart file (ATMOS_DYN) '
319 
321  call time_gettimelabel( timelabel )
322  basename = trim(atmos_dyn_restart_out_basename)//'_'//trim(timelabel)
323  else
324  basename = trim(atmos_dyn_restart_out_basename)
325  endif
326 
327  log_info("ATMOS_DYN_vars_restart_create",*) 'basename: ', trim(basename)
328 
329  call file_cartesc_create( &
331  restart_fid, & ! [OUT]
332  aggregate=atmos_dyn_restart_out_aggregate ) ! [IN]
333 
334  endif
335 
336  return
337  end subroutine atmos_dyn_vars_restart_create
338 
339  !-----------------------------------------------------------------------------
342  use scale_file_cartesc, only: &
344  implicit none
345 
346  if ( restart_fid /= -1 .and. va > 0 ) then
347  call file_cartesc_enddef( restart_fid ) ! [IN]
348  endif
349 
350  return
351  end subroutine atmos_dyn_vars_restart_enddef
352 
353  !-----------------------------------------------------------------------------
356  use scale_file_cartesc, only: &
358  implicit none
359  !---------------------------------------------------------------------------
360 
361  if ( restart_fid /= -1 ) then
362  log_newline
363  log_info("ATMOS_DYN_vars_restart_close",*) 'Close restart file (ATMOS_DYN) '
364 
365  call file_cartesc_close( restart_fid ) ! [IN]
366 
367  restart_fid = -1
368  endif
369 
370  return
371  end subroutine atmos_dyn_vars_restart_close
372 
373  !-----------------------------------------------------------------------------
376  use scale_file_cartesc, only: &
378  implicit none
379 
380  integer iv
381  !---------------------------------------------------------------------------
382 
383  if ( restart_fid /= -1 ) then
384 
385  do iv = 1, va
386  call file_cartesc_def_var( restart_fid, var_name(iv), var_desc(iv), var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype, &
387  var_id(iv) )
388  enddo
389 
390  endif
391 
392  return
393  end subroutine atmos_dyn_vars_restart_def_var
394 
395  !-----------------------------------------------------------------------------
398  use scale_statistics, only: &
400  statistics_total
401  use scale_atmos_grid_cartesc_real, only: &
404  use scale_file_cartesc, only: &
405  file_cartesc_write_var
406  implicit none
407 
408  integer :: iv
409  !---------------------------------------------------------------------------
410 
411  if ( restart_fid /= -1 ) then
412 
414 
415  if ( statistics_checktotal ) then
416  do iv = 1, va
417  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
418  prog(:,:,:,iv), var_name(iv), & ! (in)
419  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
421  enddo
422  endif
423 
424  do iv = 1, va
425  call file_cartesc_write_var( restart_fid, var_id(iv), prog(:,:,:,iv), var_name(iv), 'ZXY' ) ! [IN]
426  enddo
427 
428  endif
429 
430  return
431  end subroutine atmos_dyn_vars_restart_write
432 
433 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?
subroutine, public atmos_dyn_vars_restart_def_var
Define variables in restart file.
subroutine, public atmos_dyn_vars_restart_open
Open restart file for read.
integer, public va
Definition: scale_index.F90:35
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.
integer, public ia
of whole cells: x, local, with HALO
subroutine, public atmos_dyn_vars_restart_enddef
Exit netCDF define mode.
module Atmosphere / Dynamics
subroutine, public atmos_dyn_vars_restart_close
Close restart file.
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
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?
logical, public statistics_checktotal
calc&report variable totals to logfile?
subroutine, public atmos_dyn_vars_fillhalo
HALO Communication.
character(len=h_mid), public atmos_dyn_restart_out_title
title of the output file
logical, public atmos_dyn_restart_in_aggregate
Switch to use aggregate 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
module Index
Definition: scale_index.F90:11
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:94
logical, public atmos_dyn_restart_output
output restart file?
module atmosphere / grid / cartesC index
integer, public ke
end point of inner domain: z, local
module PROCESS
Definition: scale_prc.F90:11
integer, public je
end point of inner domain: y, local
subroutine, public file_cartesc_enddef(fid)
Exit netCDF file define mode.
module TIME
Definition: scale_time.F90:16
subroutine, public atmos_dyn_vars_restart_read
Read restart.
integer, public ks
start point of inner domain: z, local
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
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.
subroutine, public atmos_dyn_vars_setup
Setup.
logical function, public file_get_aggregate(fid)
module profiler
Definition: scale_prof.F90:11
module Atmosphere GRID CartesC Real(real space)
module PRECISION
module file / cartesianC
integer, public ka
of whole cells: z, local, with HALO
character(len=h_short), public atmos_dyn_type
module Statistics
module STDIO
Definition: scale_io.F90:10
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
logical, public atmos_dyn_restart_out_aggregate
Switch to use aggregate file.
subroutine, public file_cartesc_open(basename, fid, aggregate)
open a netCDF file for read
subroutine, public atmos_dyn_vars_restart_create
Create restart file.
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
character(len=h_long), public atmos_dyn_restart_out_basename
Basename of the output file.