SCALE-RM
scale_atmos_phy_rd_offline.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
11 !-------------------------------------------------------------------------------
12 #include "scalelib.h"
14  !-----------------------------------------------------------------------------
15  !
16  !++ used modules
17  !
18  use scale_precision
19  use scale_io
20  use scale_prof
22  !-----------------------------------------------------------------------------
23  implicit none
24  private
25  !-----------------------------------------------------------------------------
26  !
27  !++ Public procedure
28  !
31 
32  !-----------------------------------------------------------------------------
33  !
34  !++ Public parameters & variables
35  !
36  !-----------------------------------------------------------------------------
37  !
38  !++ Private procedure
39  !
40  !-----------------------------------------------------------------------------
41  !
42  !++ Private parameters & variables
43  !
44  !-----------------------------------------------------------------------------
45  integer, private, parameter :: num_vars_3d = 4
46  integer, private, parameter :: num_vars_2d = 4
47  integer, private, parameter :: num_vars_2d_op = 4 ! optional
48 
49  real(RP), private :: ATMOS_PHY_RD_offline_diffuse_rate = 0.5_rp
50  real(RP), private :: ATMOS_PHY_RD_offline_NIR_rate = 0.5_rp
51 
52  logical, private :: vars_2d_exist(num_vars_2d_op)
53 
54 contains
55  !-----------------------------------------------------------------------------
58  use scale_prc, only: &
59  prc_abort
60  use scale_file_external_input, only: &
62  use scale_const, only: &
63  undef => const_undef
64  implicit none
65 
66  character(len=H_SHORT) :: vars_3d (num_vars_3d)
67  character(len=H_SHORT) :: vars_2d (num_vars_2d)
68  character(len=H_SHORT) :: vars_2d_op(num_vars_2d_op)
69 
70  data vars_3d / 'RFLX_LW_up', 'RFLX_LW_dn', 'RFLX_SW_up', 'RFLX_SW_dn' /
71  data vars_2d / 'SFLX_LW_up', 'SFLX_LW_dn', 'SFLX_SW_up', 'SFLX_SW_dn' /
72  data vars_2d_op / 'SFLX_NIR_dn_dir', 'SFLX_NIR_dn_dif', 'SFLX_VIS_dn_dir', 'SFLX_VIS_dn_dif' /
73 
74  character(len=H_LONG) :: atmos_phy_rd_offline_basename = ''
75  logical :: atmos_phy_rd_offline_basename_add_num = .false.
76  integer :: atmos_phy_rd_offline_number_of_files = 1
77  character(len=H_SHORT) :: atmos_phy_rd_offline_axistype = 'XYZ'
78  logical :: atmos_phy_rd_offline_enable_periodic_year = .false.
79  logical :: atmos_phy_rd_offline_enable_periodic_month = .false.
80  logical :: atmos_phy_rd_offline_enable_periodic_day = .false.
81  integer :: atmos_phy_rd_offline_step_fixed = 0
82  real(rp) :: atmos_phy_rd_offline_offset = 0.0_rp
83  real(rp) :: atmos_phy_rd_offline_defval ! = UNDEF
84  logical :: atmos_phy_rd_offline_check_coordinates = .true.
85  integer :: atmos_phy_rd_offline_step_limit = 0
86 
87  namelist / param_atmos_phy_rd_offline / &
88  atmos_phy_rd_offline_basename, &
89  atmos_phy_rd_offline_basename_add_num, &
90  atmos_phy_rd_offline_number_of_files, &
91  atmos_phy_rd_offline_axistype, &
92  atmos_phy_rd_offline_enable_periodic_year, &
93  atmos_phy_rd_offline_enable_periodic_month, &
94  atmos_phy_rd_offline_enable_periodic_day, &
95  atmos_phy_rd_offline_step_fixed, &
96  atmos_phy_rd_offline_offset, &
97  atmos_phy_rd_offline_defval, &
98  atmos_phy_rd_offline_check_coordinates, &
99  atmos_phy_rd_offline_step_limit, &
100  atmos_phy_rd_offline_diffuse_rate, &
101  atmos_phy_rd_offline_nir_rate
102 
103  integer :: n, ierr
104  !---------------------------------------------------------------------------
105 
106  log_newline
107  log_info("ATMOS_PHY_RD_offline_setup",*) 'Setup'
108  log_info("ATMOS_PHY_RD_offline_setup",*) 'Offline radiation process'
109 
110  atmos_phy_rd_offline_defval = undef
111 
112  !--- read namelist
113  rewind(io_fid_conf)
114  read(io_fid_conf,nml=param_atmos_phy_rd_offline,iostat=ierr)
115  if( ierr < 0 ) then !--- missing
116  log_info("ATMOS_PHY_RD_offline_setup",*) 'Not found namelist. Default used.'
117  elseif( ierr > 0 ) then !--- fatal error
118  log_error("ATMOS_PHY_RD_offline_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_PHY_RD_OFFLINE. Check!'
119  call prc_abort
120  endif
121  log_nml(param_atmos_phy_rd_offline)
122 
123  if ( atmos_phy_rd_offline_basename == '' ) then
124  log_error("ATMOS_PHY_RD_offline_setup",*) 'ATMOS_PHY_RD_offline_basename is necessary'
125  call prc_abort
126  end if
127 
128  do n = 1, num_vars_3d
129  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
130  atmos_phy_rd_offline_basename_add_num, & ! [IN]
131  atmos_phy_rd_offline_number_of_files, & ! [IN]
132  vars_3d(n), & ! [IN]
133  atmos_phy_rd_offline_axistype, & ! [IN]
134  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
135  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
136  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
137  atmos_phy_rd_offline_step_fixed, & ! [IN]
138  atmos_phy_rd_offline_offset, & ! [IN]
139  atmos_phy_rd_offline_defval, & ! [IN]
140  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
141  step_limit = atmos_phy_rd_offline_step_limit ) ! [IN]
142  end do
143 
144  do n = 1, num_vars_2d
145  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
146  atmos_phy_rd_offline_basename_add_num, & ! [IN]
147  atmos_phy_rd_offline_number_of_files, & ! [IN]
148  vars_2d(n), & ! [IN]
149  'XY', & ! [IN]
150  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
151  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
152  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
153  atmos_phy_rd_offline_step_fixed, & ! [IN]
154  atmos_phy_rd_offline_offset, & ! [IN]
155  atmos_phy_rd_offline_defval, & ! [IN]
156  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
157  step_limit = atmos_phy_rd_offline_step_limit ) ! [IN]
158  end do
159 
160  do n = 1, num_vars_2d_op
161  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
162  atmos_phy_rd_offline_basename_add_num, & ! [IN]
163  atmos_phy_rd_offline_number_of_files, & ! [IN]
164  vars_2d_op(n), & ! [IN]
165  'XY', & ! [IN]
166  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
167  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
168  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
169  atmos_phy_rd_offline_step_fixed, & ! [IN]
170  atmos_phy_rd_offline_offset, & ! [IN]
171  atmos_phy_rd_offline_defval, & ! [IN]
172  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
173  step_limit = atmos_phy_rd_offline_step_limit, & ! [IN]
174  exist = vars_2d_exist(n) ) ! [OUT]
175  if ( vars_2d_exist(n) ) then
176  log_info("ATMOS_PHY_RD_offline_setup",*) '', trim(vars_2d_op(n)), ' found.'
177  else
178  log_info("ATMOS_PHY_RD_offline_setup",*) '', trim(vars_2d_op(n)), ' not found.'
179  end if
180  end do
181 
182  return
183  end subroutine atmos_phy_rd_offline_setup
184 
185  !-----------------------------------------------------------------------------
187  subroutine atmos_phy_rd_offline_flux( &
188  KA, KS, KE, IA, IS, IE, JA, JS, JE, &
189  time_now, &
190  flux_rad, &
191  SFLX_rad_dn )
192  use scale_prc, only: &
193  prc_abort
194  use scale_file_external_input, only: &
195  file_external_input_update
196  use scale_atmos_phy_rd_common, only: &
197  i_sw, &
198  i_lw, &
199  i_dn, &
200  i_up
201  implicit none
202 
203  integer, intent(in) :: ka, ks, ke
204  integer, intent(in) :: ia, is, ie
205  integer, intent(in) :: ja, js, je
206  real(dp), intent(in) :: time_now
207  real(rp), intent(out) :: flux_rad (ka,ia,ja,2,2)
208  real(rp), intent(out) :: sflx_rad_dn(ia,ja,n_rad_dir,n_rad_rgn)
209 
210  real(rp) :: buffer(ia,ja)
211  logical :: error, error_sum, error_sflx
212 
213  integer :: i, j
214  !---------------------------------------------------------------------------
215 
216  log_progress(*) 'atmosphere / physics / radiation / offline'
217 
218  ! [note] external data input is now support only SCALE-RM
219 
220  error_sum = .false.
221 
222  ! 3D
223  call file_external_input_update( 'RFLX_LW_up', time_now, flux_rad(:,:,:,i_lw,i_up), error )
224  error_sum = ( error .OR. error_sum )
225 
226  call file_external_input_update( 'RFLX_LW_dn', time_now, flux_rad(:,:,:,i_lw,i_dn), error )
227  error_sum = ( error .OR. error_sum )
228 
229  call file_external_input_update( 'RFLX_SW_up', time_now, flux_rad(:,:,:,i_sw,i_up), error )
230  error_sum = ( error .OR. error_sum )
231 
232  call file_external_input_update( 'RFLX_SW_dn', time_now, flux_rad(:,:,:,i_sw,i_dn), error )
233  error_sum = ( error .OR. error_sum )
234 
235 
236  ! 2D
237  call file_external_input_update( 'SFLX_LW_up', time_now, buffer(:,:), error )
238  if ( error ) then
239  error_sum = .true.
240  else
241  !$omp parallel do default(none) OMP_SCHEDULE_ &
242  !$omp private(i,j) &
243  !$omp shared(KS,IS,IE,JS,JE) &
244  !$omp shared(flux_rad,buffer)
245  do j = js, je
246  do i = is, ie
247  flux_rad(ks-1,i,j,i_lw,i_up) = buffer(i,j)
248  end do
249  end do
250  end if
251 
252  call file_external_input_update( 'SFLX_LW_dn', time_now, buffer(:,:), error )
253  if ( error ) then
254  error_sum = .true.
255  else
256  !$omp parallel do default(none) OMP_SCHEDULE_ &
257  !$omp private(i,j) &
258  !$omp shared(KS,IS,IE,JS,JE) &
259  !$omp shared(flux_rad,buffer)
260  do j = js, je
261  do i = is, ie
262  flux_rad(ks-1,i,j,i_lw,i_dn) = buffer(i,j)
263  end do
264  end do
265  end if
266 
267  call file_external_input_update( 'SFLX_SW_up', time_now, buffer(:,:), error )
268  if ( error ) then
269  error_sum = .true.
270  else
271  !$omp parallel do default(none) OMP_SCHEDULE_ &
272  !$omp private(i,j) &
273  !$omp shared(KS,IS,IE,JS,JE) &
274  !$omp shared(flux_rad,buffer)
275  do j = js, je
276  do i = is, ie
277  flux_rad(ks-1,i,j,i_sw,i_up) = buffer(i,j)
278  end do
279  end do
280  end if
281 
282  call file_external_input_update( 'SFLX_SW_dn', time_now, buffer(:,:), error )
283  if ( error ) then
284  error_sum = .true.
285  else
286  !$omp parallel do default(none) OMP_SCHEDULE_ &
287  !$omp private(i,j) &
288  !$omp shared(KS,IS,IE,JS,JE) &
289  !$omp shared(flux_rad,buffer)
290  do j = js, je
291  do i = is, ie
292  flux_rad(ks-1,i,j,i_sw,i_dn) = buffer(i,j)
293  end do
294  end do
295  end if
296 
297  !$omp parallel do default(none) OMP_SCHEDULE_ &
298  !$omp private(i,j) &
299  !$omp shared(KS,IS,IE,JS,JE,ATMOS_PHY_RD_offline_diffuse_rate) &
300  !$omp shared(SFLX_rad_dn,flux_rad)
301  do j = js, je
302  do i = is, ie
303  sflx_rad_dn(i,j,i_r_direct ,i_r_ir) = 0.0_rp
304  sflx_rad_dn(i,j,i_r_diffuse,i_r_ir) = flux_rad(ks-1,i,j,i_lw,i_dn)
305  end do
306  end do
307 
308  ! 2D optional
309 
310  error_sflx = .false.
311 
312  if ( vars_2d_exist(1) ) then
313  call file_external_input_update( 'SFLX_NIR_dn_dir', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
314  error_sum = ( error .OR. error_sum )
315  else
316  error_sflx = .true.
317  endif
318 
319  if ( vars_2d_exist(2) ) then
320  call file_external_input_update( 'SFLX_NIR_dn_dif', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
321  error_sum = ( error .OR. error_sum )
322  else
323  error_sflx = .true.
324  endif
325 
326  if ( vars_2d_exist(3) ) then
327  call file_external_input_update( 'SFLX_VIS_dn_dir', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
328  error_sum = ( error .OR. error_sum )
329  else
330  error_sflx = .true.
331  endif
332 
333  if ( vars_2d_exist(4) ) then
334  call file_external_input_update( 'SFLX_VIS_dn_dif', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
335  error_sum = ( error .OR. error_sum )
336  else
337  error_sflx = .true.
338  endif
339 
340  if ( error_sflx ) then ! reconstruct from lowermost SW flux
341  !$omp parallel do default(none) OMP_SCHEDULE_ &
342  !$omp private(i,j) &
343  !$omp shared(KS,IS,IE,JS,JE,ATMOS_PHY_RD_offline_diffuse_rate,ATMOS_PHY_RD_offline_NIR_rate) &
344  !$omp shared(SFLX_rad_dn,flux_rad)
345  do j = js, je
346  do i = is, ie
347  sflx_rad_dn(i,j,i_r_direct ,i_r_nir) = ( 1.0_rp-atmos_phy_rd_offline_diffuse_rate ) &
348  * ( atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
349  sflx_rad_dn(i,j,i_r_diffuse,i_r_nir) = ( atmos_phy_rd_offline_diffuse_rate ) &
350  * ( atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
351  sflx_rad_dn(i,j,i_r_direct ,i_r_vis) = ( 1.0_rp-atmos_phy_rd_offline_diffuse_rate ) &
352  * ( 1.0_rp-atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
353  sflx_rad_dn(i,j,i_r_diffuse,i_r_vis) = ( atmos_phy_rd_offline_diffuse_rate ) &
354  * ( 1.0_rp-atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
355  enddo
356  enddo
357  endif
358 
359  if ( error_sum ) then
360  log_error("ATMOS_PHY_RD_offline_flux",*) 'Requested data is not found!'
361  call prc_abort
362  endif
363 
364  return
365  end subroutine atmos_phy_rd_offline_flux
366 
scale_cpl_sfc_index::n_rad_dir
integer, parameter, public n_rad_dir
Definition: scale_cpl_sfc_index.F90:36
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:342
scale_cpl_sfc_index::i_r_direct
integer, parameter, public i_r_direct
Definition: scale_cpl_sfc_index.F90:37
scale_atmos_phy_rd_offline::atmos_phy_rd_offline_flux
subroutine, public atmos_phy_rd_offline_flux(KA, KS, KE, IA, IS, IE, JA, JS, JE, time_now, flux_rad, SFLX_rad_dn)
Radiation main.
Definition: scale_atmos_phy_rd_offline.F90:192
scale_file_external_input::file_external_input_regist
subroutine, public file_external_input_regist(basename, basename_add_num, number_of_files, varname, axistype, enable_periodic_year, enable_periodic_month, enable_periodic_day, step_fixed, offset, defval, check_coordinates, aggregate, allow_missing, step_limit, exist)
Regist data.
Definition: scale_file_external_input.F90:324
scale_cpl_sfc_index::i_r_diffuse
integer, parameter, public i_r_diffuse
Definition: scale_cpl_sfc_index.F90:38
scale_atmos_phy_rd_offline::atmos_phy_rd_offline_setup
subroutine, public atmos_phy_rd_offline_setup
Setup.
Definition: scale_atmos_phy_rd_offline.F90:58
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_atmos_phy_rd_common::i_dn
integer, parameter, public i_dn
Definition: scale_atmos_phy_rd_common.F90:35
scale_atmos_phy_rd_common::i_lw
integer, parameter, public i_lw
Definition: scale_atmos_phy_rd_common.F90:37
scale_atmos_phy_rd_offline
module atmosphere / physics / radiation / offline
Definition: scale_atmos_phy_rd_offline.F90:13
scale_cpl_sfc_index::i_r_ir
integer, parameter, public i_r_ir
Definition: scale_cpl_sfc_index.F90:29
scale_atmos_phy_rd_common::i_up
integer, parameter, public i_up
Definition: scale_atmos_phy_rd_common.F90:34
scale_prc
module PROCESS
Definition: scale_prc.F90:11
scale_io
module STDIO
Definition: scale_io.F90:10
scale_cpl_sfc_index::i_r_nir
integer, parameter, public i_r_nir
Definition: scale_cpl_sfc_index.F90:30
scale_const
module CONSTANT
Definition: scale_const.F90:11
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_precision::dp
integer, parameter, public dp
Definition: scale_precision.F90:32
scale_atmos_phy_rd_common::i_sw
integer, parameter, public i_sw
Definition: scale_atmos_phy_rd_common.F90:38
scale_cpl_sfc_index
module coupler / surface-atmospehre
Definition: scale_cpl_sfc_index.F90:11
scale_cpl_sfc_index::i_r_vis
integer, parameter, public i_r_vis
Definition: scale_cpl_sfc_index.F90:31
scale_atmos_phy_rd_common
module atmosphere / physics / radiation / common
Definition: scale_atmos_phy_rd_common.F90:12
scale_file_external_input
module file / external_input
Definition: scale_file_external_input.F90:12
scale_cpl_sfc_index::n_rad_rgn
integer, parameter, public n_rad_rgn
Definition: scale_cpl_sfc_index.F90:28
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