SCALE-RM
scale_topography.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
9 !-------------------------------------------------------------------------------
10 #include "scalelib.h"
12  !-----------------------------------------------------------------------------
13  !
14  !++ used modules
15  !
16  use scale_precision
17  use scale_io
18  use scale_prof
20  !-----------------------------------------------------------------------------
21  implicit none
22  private
23  !-----------------------------------------------------------------------------
24  !
25  !++ Public procedure
26  !
27  public :: topography_setup
28  public :: topography_fillhalo
29  public :: topography_write
31 
32  !-----------------------------------------------------------------------------
33  !
34  !++ Public parameters & variables
35  !
36  logical, public :: topography_exist = .false.
37 
38  real(rp), public, allocatable :: topography_zsfc (:,:)
39  real(rp), public, allocatable :: topography_tansl_x(:,:)
40  real(rp), public, allocatable :: topography_tansl_y(:,:)
41 
42  !-----------------------------------------------------------------------------
43  !
44  !++ Private procedure
45  !
46  private :: topography_read
47 
48  !-----------------------------------------------------------------------------
49  !
50  !++ Private parameters & variables
51  !
52  character(len=H_LONG), private :: topography_in_basename = ''
53  character(len=H_LONG), private :: topography_in_varname = 'topo'
54  logical, private :: topography_in_aggregate
55  logical, private :: topography_in_check_coordinates = .false.
56  character(len=H_LONG), private :: topography_out_basename = ''
57  logical, private :: topography_out_aggregate
58  character(len=H_MID), private :: topography_out_title = 'SCALE-RM TOPOGRAPHY'
59  character(len=H_SHORT), private :: topography_out_dtype = 'DEFAULT'
60 
61  !-----------------------------------------------------------------------------
62 contains
63  !-----------------------------------------------------------------------------
65  subroutine topography_setup
66  use scale_file, only: &
68  use scale_prc, only: &
69  prc_abort
70  implicit none
71 
72  namelist / param_topography / &
73  topography_in_basename, &
74  topography_in_varname, &
75  topography_in_aggregate, &
76  topography_in_check_coordinates, &
77  topography_out_basename, &
78  topography_out_aggregate, &
79  topography_out_dtype
80 
81  integer :: ierr
82  !---------------------------------------------------------------------------
83 
84  log_newline
85  log_info("TOPOGRAPHY_setup",*) 'Setup'
86 
87  topography_in_aggregate = file_aggregate
88  topography_out_aggregate = file_aggregate
89 
90  !--- read namelist
91  rewind(io_fid_conf)
92  read(io_fid_conf,nml=param_topography,iostat=ierr)
93  if( ierr < 0 ) then !--- missing
94  log_info("TOPOGRAPHY_setup",*) 'Not found namelist. Default used.'
95  elseif( ierr > 0 ) then !--- fatal error
96  log_error("TOPOGRAPHY_setup",*) 'Not appropriate names in namelist PARAM_TOPOGRAPHY. Check!'
97  call prc_abort
98  endif
99  log_nml(param_topography)
100 
101  allocate( topography_zsfc(ia,ja) )
102  allocate( topography_tansl_x(ia,ja) )
103  allocate( topography_tansl_y(ia,ja) )
104  topography_zsfc(:,:) = 0.0_rp
105  topography_tansl_x(:,:) = 0.0_rp
106  topography_tansl_y(:,:) = 0.0_rp
107 
108  ! read from file
109  call topography_read
110 
111  return
112  end subroutine topography_setup
113 
114  !-----------------------------------------------------------------------------
116  subroutine topography_fillhalo( Zsfc, FILL_BND )
117  use scale_comm_cartesc, only: &
118  comm_vars8, &
119  comm_wait
120  implicit none
121 
122  real(rp), intent(inout), optional :: zsfc(ia,ja)
123  logical, intent(in), optional :: fill_bnd
124 
125  logical :: fill_bnd_
126  !---------------------------------------------------------------------------
127 
128  fill_bnd_ = .false.
129  if ( present(fill_bnd) ) fill_bnd_ = fill_bnd
130 
131  if ( present(zsfc) ) then
132  call comm_vars8( zsfc(:,:), 1 )
133  call comm_wait ( zsfc(:,:), 1, fill_bnd_ )
134  else
135  call comm_vars8( topography_zsfc(:,:), 1 )
136  call comm_wait ( topography_zsfc(:,:), 1, fill_bnd_ )
137  end if
138 
139  return
140  end subroutine topography_fillhalo
141 
142  !-----------------------------------------------------------------------------
144  subroutine topography_read
145  use scale_file_cartesc, only: &
147  file_cartesc_read, &
149  file_cartesc_check_coordinates, &
151  use scale_prc, only: &
152  prc_abort
153  implicit none
154 
155  integer :: fid
156  !---------------------------------------------------------------------------
157 
158  log_newline
159  log_info("TOPOGRAPHY_read",*) 'Input topography file '
160 
161  if ( topography_in_basename /= '' ) then
162 
163  call file_cartesc_open( topography_in_basename, fid, aggregate=topography_in_aggregate )
164  call file_cartesc_read( fid, topography_in_varname, 'XY', topography_zsfc(:,:) )
165 
166  call file_cartesc_flush( fid )
167 
168  if ( topography_in_check_coordinates ) then
169  call file_cartesc_check_coordinates( fid )
170  end if
171 
172  call file_cartesc_close( fid )
173 
174  call topography_fillhalo( fill_bnd=.false. )
175 
176  topography_exist = .true.
177 
178  else
179  log_info_cont(*) 'topography file is not specified.'
180 
181  topography_exist = .false.
182  endif
183 
184  return
185  end subroutine topography_read
186 
187  !-----------------------------------------------------------------------------
189  subroutine topography_write
190  use scale_file_cartesc, only: &
194  file_cartesc_write_var, &
196  implicit none
197 
198  integer :: fid, vid
199  !---------------------------------------------------------------------------
200 
201  if ( topography_out_basename /= '' .and. topography_out_basename /= topography_in_basename ) then
202 
203  log_newline
204  log_info("TOPOGRAPHY_write",*) 'Output topography file '
205 
206  call topography_fillhalo( fill_bnd=.false. )
207 
208  call file_cartesc_create( topography_out_basename, topography_out_title, topography_out_dtype, & ! [IN]
209  fid, & ! [OUT]
210  haszcoord=.false., aggregate=topography_out_aggregate ) ! [IN]
211 
212  call file_cartesc_def_var( fid, 'topo', 'Topography', 'm', 'XY', topography_out_dtype, & ! [IN]
213  vid, & ! [OUT]
214  standard_name="surface_altitude" ) ! [IN]
215 
216  call file_cartesc_enddef( fid )
217 
218  call file_cartesc_write_var( fid, vid, topography_zsfc(:,:), 'topo', 'XY' ) ! [IN]
219 
220 
221  call file_cartesc_close( fid )
222 
223  endif
224 
225  return
226  end subroutine topography_write
227 
228  subroutine topography_calc_tan_slope( &
229  IA, IS, IE, JA, JS, JE, &
230  RCDX, RCDY, MAPF )
231  use scale_prc_cartesc, only: &
232  prc_twod
233  implicit none
234  integer, intent(in) :: ia, is, ie
235  integer, intent(in) :: ja, js, je
236  real(rp), intent(in) :: rcdx(ia), rcdy(ja)
237  real(rp), intent(in) :: mapf(ia,ja,2)
238 
239  integer :: i, j
240 
241  if ( prc_twod ) then
242  !$omp parallel do
243  do j = js, je
244  do i = is, ie
245  topography_tansl_x(i,j) = 0.0_rp
246  end do
247  end do
248  else
249  !$omp parallel do
250  do j = js, je
251  do i = is, ie
252  topography_tansl_x(i,j) = ( ( topography_zsfc(i+1,j) + topography_zsfc(i ,j) ) * 0.5_rp &
253  - ( topography_zsfc(i ,j) + topography_zsfc(i-1,j) ) * 0.5_rp ) &
254  * rcdx(i) * mapf(i,j,1)
255  end do
256  end do
257  end if
258  !$omp parallel do
259  do j = js, je
260  do i = is, ie
261  topography_tansl_y(i,j) = ( ( topography_zsfc(i,j+1) + topography_zsfc(i,j ) ) * 0.5_rp &
262  - ( topography_zsfc(i,j ) + topography_zsfc(i,j-1) ) * 0.5_rp ) &
263  * rcdy(j) * mapf(i,j,2)
264  end do
265  end do
266 
267  call topography_fillhalo( topography_tansl_x(:,:), .true. )
268  call topography_fillhalo( topography_tansl_y(:,:), .true. )
269 
270  return
271  end subroutine topography_calc_tan_slope
272 
273 end module scale_topography
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:342
scale_topography::topography_calc_tan_slope
subroutine, public topography_calc_tan_slope(IA, IS, IE, JA, JS, JE, RCDX, RCDY, MAPF)
Definition: scale_topography.F90:231
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
scale_topography::topography_tansl_y
real(rp), dimension(:,:), allocatable, public topography_tansl_y
tan(slope_y)
Definition: scale_topography.F90:40
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_topography::topography_write
subroutine, public topography_write
Write topography.
Definition: scale_topography.F90:190
scale_topography
module TOPOGRAPHY
Definition: scale_topography.F90:11
scale_file
module file
Definition: scale_file.F90:15
scale_prc
module PROCESS
Definition: scale_prc.F90:11
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
scale_atmos_grid_cartesc_index
module atmosphere / grid / cartesC index
Definition: scale_atmos_grid_cartesC_index.F90:12
scale_atmos_grid_cartesc_index::ia
integer, public ia
Definition: scale_atmos_grid_cartesC_index.F90:48
scale_topography::topography_setup
subroutine, public topography_setup
Setup.
Definition: scale_topography.F90:66
scale_topography::topography_tansl_x
real(rp), dimension(:,:), allocatable, public topography_tansl_x
tan(slope_x)
Definition: scale_topography.F90:39
scale_file_cartesc::file_cartesc_close
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
Definition: scale_file_cartesC.F90:1023
scale_prc_cartesc
module process / cartesC
Definition: scale_prc_cartesC.F90:11
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_topography::topography_exist
logical, public topography_exist
topography exists?
Definition: scale_topography.F90:36
scale_atmos_grid_cartesc_index::is
integer, public is
start point of inner domain: x, local
Definition: scale_atmos_grid_cartesC_index.F90:53
scale_atmos_grid_cartesc_index::ja
integer, public ja
Definition: scale_atmos_grid_cartesC_index.F90:49
scale_topography::topography_zsfc
real(rp), dimension(:,:), allocatable, public topography_zsfc
absolute ground height [m]
Definition: scale_topography.F90:38
scale_file::file_aggregate
logical, public file_aggregate
Definition: scale_file.F90:182
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
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_comm_cartesc
module COMMUNICATION
Definition: scale_comm_cartesC.F90:11
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_topography::topography_fillhalo
subroutine, public topography_fillhalo(Zsfc, FILL_BND)
HALO Communication.
Definition: scale_topography.F90:117
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_prc_cartesc::prc_twod
logical, public prc_twod
2D experiment
Definition: scale_prc_cartesC.F90:55
scale_file_cartesc
module file / cartesianC
Definition: scale_file_cartesC.F90:11