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: &
61  file_external_input_regist
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_defval ! = UNDEF
83  logical :: atmos_phy_rd_offline_check_coordinates = .true.
84  integer :: atmos_phy_rd_offline_step_limit = 0
85 
86  namelist / param_atmos_phy_rd_offline / &
87  atmos_phy_rd_offline_basename, &
88  atmos_phy_rd_offline_basename_add_num, &
89  atmos_phy_rd_offline_number_of_files, &
90  atmos_phy_rd_offline_axistype, &
91  atmos_phy_rd_offline_enable_periodic_year, &
92  atmos_phy_rd_offline_enable_periodic_month, &
93  atmos_phy_rd_offline_enable_periodic_day, &
94  atmos_phy_rd_offline_step_fixed, &
95  atmos_phy_rd_offline_defval, &
96  atmos_phy_rd_offline_check_coordinates, &
97  atmos_phy_rd_offline_step_limit, &
98  atmos_phy_rd_offline_diffuse_rate, &
99  atmos_phy_rd_offline_nir_rate
100 
101  integer :: n, ierr
102  !---------------------------------------------------------------------------
103 
104  log_newline
105  log_info("ATMOS_PHY_RD_offline_setup",*) 'Setup'
106  log_info("ATMOS_PHY_RD_offline_setup",*) 'Offline radiation process'
107 
108  atmos_phy_rd_offline_defval = undef
109 
110  !--- read namelist
111  rewind(io_fid_conf)
112  read(io_fid_conf,nml=param_atmos_phy_rd_offline,iostat=ierr)
113  if( ierr < 0 ) then !--- missing
114  log_info("ATMOS_PHY_RD_offline_setup",*) 'Not found namelist. Default used.'
115  elseif( ierr > 0 ) then !--- fatal error
116  log_error("ATMOS_PHY_RD_offline_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_PHY_RD_OFFLINE. Check!'
117  call prc_abort
118  endif
119  log_nml(param_atmos_phy_rd_offline)
120 
121  if ( atmos_phy_rd_offline_basename == '' ) then
122  log_error("ATMOS_PHY_RD_offline_setup",*) 'ATMOS_PHY_RD_offline_basename is necessary'
123  call prc_abort
124  end if
125 
126  do n = 1, num_vars_3d
127  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
128  atmos_phy_rd_offline_basename_add_num, & ! [IN]
129  atmos_phy_rd_offline_number_of_files, & ! [IN]
130  vars_3d(n), & ! [IN]
131  atmos_phy_rd_offline_axistype, & ! [IN]
132  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
133  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
134  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
135  atmos_phy_rd_offline_step_fixed, & ! [IN]
136  atmos_phy_rd_offline_defval, & ! [IN]
137  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
138  step_limit = atmos_phy_rd_offline_step_limit ) ! [IN]
139  end do
140 
141  do n = 1, num_vars_2d
142  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
143  atmos_phy_rd_offline_basename_add_num, & ! [IN]
144  atmos_phy_rd_offline_number_of_files, & ! [IN]
145  vars_2d(n), & ! [IN]
146  'XY', & ! [IN]
147  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
148  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
149  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
150  atmos_phy_rd_offline_step_fixed, & ! [IN]
151  atmos_phy_rd_offline_defval, & ! [IN]
152  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
153  step_limit = atmos_phy_rd_offline_step_limit ) ! [IN]
154  end do
155 
156  do n = 1, num_vars_2d_op
157  call file_external_input_regist( atmos_phy_rd_offline_basename, & ! [IN]
158  atmos_phy_rd_offline_basename_add_num, & ! [IN]
159  atmos_phy_rd_offline_number_of_files, & ! [IN]
160  vars_2d_op(n), & ! [IN]
161  'XY', & ! [IN]
162  atmos_phy_rd_offline_enable_periodic_year, & ! [IN]
163  atmos_phy_rd_offline_enable_periodic_month, & ! [IN]
164  atmos_phy_rd_offline_enable_periodic_day, & ! [IN]
165  atmos_phy_rd_offline_step_fixed, & ! [IN]
166  atmos_phy_rd_offline_defval, & ! [IN]
167  check_coordinates = atmos_phy_rd_offline_check_coordinates, & ! [IN]
168  step_limit = atmos_phy_rd_offline_step_limit, & ! [IN]
169  exist = vars_2d_exist(n) ) ! [OUT]
170  if ( vars_2d_exist(n) ) then
171  log_info("ATMOS_PHY_RD_offline_setup",*) '', trim(vars_2d_op(n)), ' found.'
172  else
173  log_info("ATMOS_PHY_RD_offline_setup",*) '', trim(vars_2d_op(n)), ' not found.'
174  end if
175  end do
176 
177  return
178  end subroutine atmos_phy_rd_offline_setup
179 
180  !-----------------------------------------------------------------------------
182  subroutine atmos_phy_rd_offline_flux( &
183  KA, KS, KE, IA, IS, IE, JA, JS, JE, &
184  time_now, &
185  flux_rad, &
186  SFLX_rad_dn )
187  use scale_prc, only: &
188  prc_abort
189  use scale_file_external_input, only: &
190  file_external_input_update
191  use scale_atmos_phy_rd_common, only: &
192  i_sw, &
193  i_lw, &
194  i_dn, &
195  i_up
196  implicit none
197 
198  integer, intent(in) :: ka, ks, ke
199  integer, intent(in) :: ia, is, ie
200  integer, intent(in) :: ja, js, je
201  real(dp), intent(in) :: time_now
202  real(rp), intent(out) :: flux_rad (ka,ia,ja,2,2)
203  real(rp), intent(out) :: sflx_rad_dn(ia,ja,n_rad_dir,n_rad_rgn)
204 
205  real(rp) :: buffer(ia,ja)
206  logical :: error, error_sum, error_sflx
207 
208  integer :: i, j
209  !---------------------------------------------------------------------------
210 
211  log_progress(*) 'atmosphere / physics / radiation / offline'
212 
213  ! [note] external data input is now support only SCALE-RM
214 
215  error_sum = .false.
216 
217  ! 3D
218  call file_external_input_update( 'RFLX_LW_up', time_now, flux_rad(:,:,:,i_lw,i_up), error )
219  error_sum = ( error .OR. error_sum )
220 
221  call file_external_input_update( 'RFLX_LW_dn', time_now, flux_rad(:,:,:,i_lw,i_dn), error )
222  error_sum = ( error .OR. error_sum )
223 
224  call file_external_input_update( 'RFLX_SW_up', time_now, flux_rad(:,:,:,i_sw,i_up), error )
225  error_sum = ( error .OR. error_sum )
226 
227  call file_external_input_update( 'RFLX_SW_dn', time_now, flux_rad(:,:,:,i_sw,i_dn), error )
228  error_sum = ( error .OR. error_sum )
229 
230 
231  ! 2D
232  call file_external_input_update( 'SFLX_LW_up', time_now, buffer(:,:), error )
233  if ( error ) then
234  error_sum = .true.
235  else
236  !$omp parallel do default(none) OMP_SCHEDULE_ &
237  !$omp private(i,j) &
238  !$omp shared(KS,IS,IE,JS,JE) &
239  !$omp shared(flux_rad,buffer)
240  !$acc kernels
241  do j = js, je
242  do i = is, ie
243  flux_rad(ks-1,i,j,i_lw,i_up) = buffer(i,j)
244  end do
245  end do
246  !$acc end kernels
247  end if
248 
249  call file_external_input_update( 'SFLX_LW_dn', time_now, buffer(:,:), error )
250  if ( error ) then
251  error_sum = .true.
252  else
253  !$omp parallel do default(none) OMP_SCHEDULE_ &
254  !$omp private(i,j) &
255  !$omp shared(KS,IS,IE,JS,JE) &
256  !$omp shared(flux_rad,buffer)
257  !$acc kernels
258  do j = js, je
259  do i = is, ie
260  flux_rad(ks-1,i,j,i_lw,i_dn) = buffer(i,j)
261  end do
262  end do
263  !$acc end kernels
264  end if
265 
266  call file_external_input_update( 'SFLX_SW_up', time_now, buffer(:,:), error )
267  if ( error ) then
268  error_sum = .true.
269  else
270  !$omp parallel do default(none) OMP_SCHEDULE_ &
271  !$omp private(i,j) &
272  !$omp shared(KS,IS,IE,JS,JE) &
273  !$omp shared(flux_rad,buffer)
274  !$acc kernels
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  !$acc end kernels
281  end if
282 
283  call file_external_input_update( 'SFLX_SW_dn', time_now, buffer(:,:), error )
284  if ( error ) then
285  error_sum = .true.
286  else
287  !$omp parallel do default(none) OMP_SCHEDULE_ &
288  !$omp private(i,j) &
289  !$omp shared(KS,IS,IE,JS,JE) &
290  !$omp shared(flux_rad,buffer)
291  !$acc kernels
292  do j = js, je
293  do i = is, ie
294  flux_rad(ks-1,i,j,i_sw,i_dn) = buffer(i,j)
295  end do
296  end do
297  !$acc end kernels
298  end if
299 
300  !$omp parallel do default(none) OMP_SCHEDULE_ &
301  !$omp private(i,j) &
302  !$omp shared(KS,IS,IE,JS,JE,ATMOS_PHY_RD_offline_diffuse_rate) &
303  !$omp shared(SFLX_rad_dn,flux_rad)
304  !$acc kernels
305  do j = js, je
306  do i = is, ie
307  sflx_rad_dn(i,j,i_r_direct ,i_r_ir) = 0.0_rp
308  sflx_rad_dn(i,j,i_r_diffuse,i_r_ir) = flux_rad(ks-1,i,j,i_lw,i_dn)
309  end do
310  end do
311  !$acc end kernels
312 
313  ! 2D optional
314 
315  error_sflx = .false.
316 
317  if ( vars_2d_exist(1) ) then
318  call file_external_input_update( 'SFLX_NIR_dn_dir', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
319  error_sum = ( error .OR. error_sum )
320  else
321  error_sflx = .true.
322  endif
323 
324  if ( vars_2d_exist(2) ) then
325  call file_external_input_update( 'SFLX_NIR_dn_dif', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
326  error_sum = ( error .OR. error_sum )
327  else
328  error_sflx = .true.
329  endif
330 
331  if ( vars_2d_exist(3) ) then
332  call file_external_input_update( 'SFLX_VIS_dn_dir', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
333  error_sum = ( error .OR. error_sum )
334  else
335  error_sflx = .true.
336  endif
337 
338  if ( vars_2d_exist(4) ) then
339  call file_external_input_update( 'SFLX_VIS_dn_dif', time_now, sflx_rad_dn(:,:,i_r_direct,i_r_vis), error )
340  error_sum = ( error .OR. error_sum )
341  else
342  error_sflx = .true.
343  endif
344 
345  if ( error_sflx ) then ! reconstruct from lowermost SW flux
346  !$omp parallel do default(none) OMP_SCHEDULE_ &
347  !$omp private(i,j) &
348  !$omp shared(KS,IS,IE,JS,JE,ATMOS_PHY_RD_offline_diffuse_rate,ATMOS_PHY_RD_offline_NIR_rate) &
349  !$omp shared(SFLX_rad_dn,flux_rad)
350  !$acc kernels
351  do j = js, je
352  do i = is, ie
353  sflx_rad_dn(i,j,i_r_direct ,i_r_nir) = ( 1.0_rp-atmos_phy_rd_offline_diffuse_rate ) &
354  * ( atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
355  sflx_rad_dn(i,j,i_r_diffuse,i_r_nir) = ( atmos_phy_rd_offline_diffuse_rate ) &
356  * ( atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
357  sflx_rad_dn(i,j,i_r_direct ,i_r_vis) = ( 1.0_rp-atmos_phy_rd_offline_diffuse_rate ) &
358  * ( 1.0_rp-atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
359  sflx_rad_dn(i,j,i_r_diffuse,i_r_vis) = ( atmos_phy_rd_offline_diffuse_rate ) &
360  * ( 1.0_rp-atmos_phy_rd_offline_nir_rate ) * flux_rad(ks-1,i,j,i_sw,i_dn)
361  enddo
362  enddo
363  !$acc end kernels
364  endif
365 
366  if ( error_sum ) then
367  log_error("ATMOS_PHY_RD_offline_flux",*) 'Requested data is not found!'
368  call prc_abort
369  endif
370 
371  return
372  end subroutine atmos_phy_rd_offline_flux
373 
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:350
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:187
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:43
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:57