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  character(len=H_LONG), public :: atmos_dyn_restart_out_basename = ''
51  character(len=H_MID), public :: atmos_dyn_restart_out_title = 'ATMOS_DYN restart'
52  character(len=H_MID), public :: atmos_dyn_restart_out_dtype = 'DEFAULT'
53 
54  ! prognostic variables
55  real(RP), public, allocatable :: prog(:,:,:,:)
56 
57  !-----------------------------------------------------------------------------
58  !
59  !++ Private procedure
60  !
61  !-----------------------------------------------------------------------------
62  !
63  !++ Private parameters & variables
64  !
65  integer, private, parameter :: vmax = 100
66  character(len=H_SHORT), private :: var_name(vmax)
67  character(len=H_MID), private :: var_desc(vmax)
68  character(len=H_SHORT), private :: var_unit(vmax)
69  integer, private :: var_id(vmax)
70  integer, private :: restart_fid = -1 ! file ID
71 
72  !-----------------------------------------------------------------------------
73 contains
74  !-----------------------------------------------------------------------------
76  subroutine atmos_dyn_vars_setup
77  use scale_process, only: &
79  use scale_const, only: &
80  undef => const_undef
81  use mod_atmos_admin, only: &
83  use scale_atmos_dyn_tstep_short, only: &
85  implicit none
86 
87  namelist / param_atmos_dyn_vars / &
93 
94  integer :: ierr
95  integer :: iv
96  !---------------------------------------------------------------------------
97 
98  if( io_l ) write(io_fid_log,*)
99  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS DYN] / Origin[SCALE-RM]'
100 
101  !--- read namelist
102  rewind(io_fid_conf)
103  read(io_fid_conf,nml=param_atmos_dyn_vars,iostat=ierr)
104  if( ierr < 0 ) then !--- missing
105  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
106  elseif( ierr > 0 ) then !--- fatal error
107  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_DYN_VARS. Check!'
108  call prc_mpistop
109  endif
110  if( io_lnml ) write(io_fid_log,nml=param_atmos_dyn_vars)
111 
113  va, & ! [OUT]
114  var_name, & ! [OUT]
115  var_desc, & ! [OUT]
116  var_unit ) ! [OUT]
117 
118  if ( va > 0 ) then ! additional prognostic variables
119 
120  if ( va > vmax ) then
121  write(*,*) 'xxx number of the prognostic variables is exceed the limit', va, ' > ', vmax
122  call prc_mpistop
123  endif
124  allocate( prog(ka,ia,ja,va) )
125  prog(:,:,:,:) = undef
126 
127  if( io_l ) write(io_fid_log,*)
128  if( io_l ) write(io_fid_log,*) '*** [ATMOS_DYN] prognostic/diagnostic variables'
129  if( io_l ) write(io_fid_log,'(1x,A,A15,A,A32,3(A))') &
130  '*** |','VARNAME ','|', 'DESCRIPTION ','[', 'UNIT ',']'
131  do iv = 1, va
132  if( io_l ) write(io_fid_log,'(1x,A,i3,A,A15,A,A32,3(A))') &
133  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
134  enddo
135 
136  if( io_l ) write(io_fid_log,*)
137 
138  if ( atmos_dyn_restart_in_basename /= '' ) then
139  if( io_l ) write(io_fid_log,*) '*** Restart input? : ', trim(atmos_dyn_restart_in_basename)
140  else
141  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
142  endif
143 
145  .AND. atmos_dyn_restart_out_basename /= '' ) then
146  if( io_l ) write(io_fid_log,*) '*** Restart output? : ', trim(atmos_dyn_restart_out_basename)
147  else
148  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
149  atmos_dyn_restart_output = .false.
150  endif
151 
152  else ! no additional prognostic variables
153 
154  allocate( prog(ka,ia,ja,1) ) ! for safety
155  prog(:,:,:,:) = undef
156  atmos_dyn_restart_output = .false.
157 
158  endif
159 
160  return
161  end subroutine atmos_dyn_vars_setup
162 
163  !-----------------------------------------------------------------------------
165  subroutine atmos_dyn_vars_fillhalo
166  use scale_comm, only: &
167  comm_vars8, &
168  comm_wait
169  implicit none
170 
171  integer :: i, j, iv
172  !---------------------------------------------------------------------------
173 
174  do iv = 1, va
175  do j = js, je
176  do i = is, ie
177  prog( 1:ks-1,i,j,iv) = prog(ks,i,j,iv)
178  prog(ke+1:ka, i,j,iv) = prog(ke,i,j,iv)
179  enddo
180  enddo
181 
182  call comm_vars8( prog(:,:,:,iv), iv )
183  enddo
184 
185  do iv = 1, va
186  call comm_wait ( prog(:,:,:,iv), iv )
187  enddo
188 
189  return
190  end subroutine atmos_dyn_vars_fillhalo
191 
192  !-----------------------------------------------------------------------------
194  subroutine atmos_dyn_vars_restart_read
195  use scale_fileio, only: &
196  fileio_read
197  use scale_rm_statistics, only: &
198  stat_total
199  implicit none
200 
201  real(RP) :: total
202  integer :: iv
203  !---------------------------------------------------------------------------
204 
205  if( io_l ) write(io_fid_log,*)
206  if( io_l ) write(io_fid_log,*) '*** Input restart file (ATMOS_DYN) ***'
207 
208  if ( atmos_dyn_restart_in_basename /= '' ) then
209  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(atmos_dyn_restart_in_basename)
210 
211  do iv = 1, va
212  call fileio_read( prog(:,:,:,iv), & ! [OUT]
213  atmos_dyn_restart_in_basename, var_name(iv), 'ZXY', step=1 ) ! [IN]
214 
215  enddo
216 
218 
219  do iv = 1, va
220  call stat_total( total, prog(:,:,:,iv), var_name(iv) )
221  enddo
222  else
223  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_DYN is not specified.'
224  endif
225 
226  return
227  end subroutine atmos_dyn_vars_restart_read
228 
229  !-----------------------------------------------------------------------------
232  use scale_time, only: &
234  use scale_fileio, only: &
235  fileio_write
236  implicit none
237 
238  character(len=20) :: timelabel
239  character(len=H_LONG) :: basename
240  integer :: iv
241  !---------------------------------------------------------------------------
242 
243  if ( atmos_dyn_restart_out_basename /= '' ) then
244 
245  call time_gettimelabel( timelabel )
246  write(basename,'(A,A,A)') trim(atmos_dyn_restart_out_basename), '_', trim(timelabel)
247 
248  if( io_l ) write(io_fid_log,*)
249  if( io_l ) write(io_fid_log,*) '*** Output restart file (ATMOS_DYN) ***'
250  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
251 
252  do iv = 1, va
253  call fileio_write( prog(:,:,:,iv), basename, atmos_dyn_restart_out_title, & ! [IN]
254  var_name(iv), var_desc(iv), var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype ) ! [IN]
255  enddo
256 
257  endif
258 
259  return
260  end subroutine atmos_dyn_vars_restart_write
261 
262  !-----------------------------------------------------------------------------
265  use scale_time, only: &
267  use scale_fileio, only: &
269  implicit none
270 
271  character(len=20) :: timelabel
272  character(len=H_LONG) :: basename
273  integer :: iv
274  !---------------------------------------------------------------------------
275 
276  if ( atmos_dyn_restart_out_basename /= '' ) then
277 
278  call time_gettimelabel( timelabel )
279  write(basename,'(A,A,A)') trim(atmos_dyn_restart_out_basename), '_', trim(timelabel)
280 
281  if( io_l ) write(io_fid_log,*)
282  if( io_l ) write(io_fid_log,*) '*** Output restart file (ATMOS_DYN) ***'
283  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
284 
285  call fileio_create(restart_fid, basename, atmos_dyn_restart_out_title, &
287  endif
288 
289  return
290  end subroutine atmos_dyn_vars_restart_create
291 
292  !-----------------------------------------------------------------------------
295  use scale_fileio, only: &
297  implicit none
298 
299  if ( restart_fid .NE. -1 ) then
300  call fileio_enddef( restart_fid ) ! [IN]
301  endif
302 
303  return
304  end subroutine atmos_dyn_vars_restart_enddef
305 
306  !-----------------------------------------------------------------------------
309  use scale_fileio, only: &
311  implicit none
312 
313  if ( restart_fid .NE. -1 ) then
314  call fileio_close( restart_fid ) ! [IN]
315  restart_fid = -1
316  endif
317 
318  return
319  end subroutine atmos_dyn_vars_restart_close
320 
321  !-----------------------------------------------------------------------------
324  use scale_fileio, only: &
326  implicit none
327 
328  integer iv
329  !---------------------------------------------------------------------------
330 
331  if ( restart_fid .NE. -1 ) then
332 
333  do iv = 1, va
334  call fileio_def_var( restart_fid, var_id(iv), var_name(iv), var_desc(iv), &
335  var_unit(iv), 'ZXY', atmos_dyn_restart_out_dtype ) ! [IN]
336  enddo
337 
338  endif
339 
340  return
341  end subroutine atmos_dyn_vars_restart_def_var
342 
343  !-----------------------------------------------------------------------------
346  use scale_fileio, only: &
347  fileio_write_var
348  implicit none
349 
350  integer iv
351  !---------------------------------------------------------------------------
352 
353  if ( restart_fid .NE. -1 ) then
354 
355  do iv = 1, va
356  call fileio_write_var( restart_fid, var_id(iv), prog(:,:,:,iv), var_name(iv), 'ZXY' ) ! [IN]
357  enddo
358 
359  endif
360 
361  return
362  end subroutine atmos_dyn_vars_restart_write_var
363 
364 end module mod_atmos_dyn_vars
module ATMOS admin
integer, public is
start point of inner domain: x, local
subroutine, public atmos_dyn_vars_restart_def_var
Define variables in restart file.
integer, public je
end point of inner domain: y, local
subroutine, public prc_mpistop
Abort MPI.
integer, public va
Definition: scale_index.F90:38
module Atmosphere / Dynamical scheme
character(len=h_long), public atmos_dyn_restart_in_basename
basename of the restart file
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
subroutine, public atmos_dyn_vars_restart_enddef
Exit netCDF define mode.
module Atmosphere / Dynamics
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 restart.
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
module TRACER
module Index
Definition: scale_index.F90:14
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv)
Define a variable to file.
integer, public ia
of x whole cells (local, with HALO)
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:90
integer, public ka
of z whole cells (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_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
module PRECISION
character(len=h_short), public atmos_dyn_type
subroutine, public fileio_close(fid)
Close a netCDF file.
subroutine, public atmos_dyn_vars_restart_write_var
Write variables to restart 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
character(len=h_mid), public atmos_dyn_restart_out_dtype
REAL4 or REAL8.
subroutine, public atmos_dyn_vars_restart_create
Create restart file.
character(len=h_long), public atmos_dyn_restart_out_basename
basename of the output file
integer, public ja
of y whole cells (local, with HALO)