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 :: topo_setup
28  public :: topo_fillhalo
29  public :: topo_write
30 
31  !-----------------------------------------------------------------------------
32  !
33  !++ Public parameters & variables
34  !
35  logical, public :: topo_exist = .false.
36 
37  real(RP), public, allocatable :: topo_zsfc(:,:)
38 
39  !-----------------------------------------------------------------------------
40  !
41  !++ Private procedure
42  !
43  private :: topo_read
44 
45  !-----------------------------------------------------------------------------
46  !
47  !++ Private parameters & variables
48  !
49  character(len=H_LONG), private :: topo_in_basename = ''
50  logical, private :: topo_in_aggregate
51  logical, private :: topo_in_check_coordinates = .false.
52  character(len=H_LONG), private :: topo_out_basename = ''
53  logical, private :: topo_out_aggregate
54  character(len=H_MID), private :: topo_out_title = 'SCALE-RM TOPOGRAPHY'
55  character(len=H_SHORT), private :: topo_out_dtype = 'DEFAULT'
56 
57  !-----------------------------------------------------------------------------
58 contains
59  !-----------------------------------------------------------------------------
61  subroutine topo_setup
62  use scale_file, only: &
64  use scale_prc, only: &
65  prc_abort
66  implicit none
67 
68  namelist / param_topo / &
69  topo_in_basename, &
70  topo_in_aggregate, &
71  topo_in_check_coordinates, &
72  topo_out_basename, &
73  topo_out_aggregate, &
74  topo_out_dtype
75 
76  integer :: ierr
77  !---------------------------------------------------------------------------
78 
79  log_newline
80  log_info("TOPO_setup",*) 'Setup'
81 
82  topo_in_aggregate = file_aggregate
83  topo_out_aggregate = file_aggregate
84 
85  !--- read namelist
86  rewind(io_fid_conf)
87  read(io_fid_conf,nml=param_topo,iostat=ierr)
88  if( ierr < 0 ) then !--- missing
89  log_info("TOPO_setup",*) 'Not found namelist. Default used.'
90  elseif( ierr > 0 ) then !--- fatal error
91  log_error("TOPO_setup",*) 'Not appropriate names in namelist PARAM_TOPO. Check!'
92  call prc_abort
93  endif
94  log_nml(param_topo)
95 
96  allocate( topo_zsfc(ia,ja) )
97  topo_zsfc(:,:) = 0.0_rp
98 
99  ! read from file
100  call topo_read
101 
102  return
103  end subroutine topo_setup
104 
105  !-----------------------------------------------------------------------------
107  subroutine topo_fillhalo( Zsfc, FILL_BND )
108  use scale_comm_cartesc, only: &
109  comm_vars8, &
110  comm_wait
111  implicit none
112 
113  real(RP), intent(inout), optional :: Zsfc(ia,ja)
114  logical, intent(in), optional :: FILL_BND
115 
116  logical :: FILL_BND_
117  !---------------------------------------------------------------------------
118 
119  fill_bnd_ = .false.
120  if ( present(fill_bnd) ) fill_bnd_ = fill_bnd
121 
122  if ( present(zsfc) ) then
123  call comm_vars8( zsfc(:,:), 1 )
124  call comm_wait ( zsfc(:,:), 1, fill_bnd_ )
125  else
126  call comm_vars8( topo_zsfc(:,:), 1 )
127  call comm_wait ( topo_zsfc(:,:), 1, fill_bnd_ )
128  end if
129 
130  return
131  end subroutine topo_fillhalo
132 
133  !-----------------------------------------------------------------------------
135  subroutine topo_read
136  use scale_file_cartesc, only: &
138  file_cartesc_read, &
140  file_cartesc_check_coordinates, &
142  use scale_prc, only: &
143  prc_abort
144  implicit none
145 
146  integer :: fid
147  !---------------------------------------------------------------------------
148 
149  log_newline
150  log_info("TOPO_read",*) 'Input topography file '
151 
152  if ( topo_in_basename /= '' ) then
153 
154  call file_cartesc_open( topo_in_basename, fid, aggregate=topo_in_aggregate )
155  call file_cartesc_read( fid, 'TOPO', 'XY', topo_zsfc(:,:) )
156 
157  call file_cartesc_flush( fid )
158 
159  if ( topo_in_check_coordinates ) then
160  call file_cartesc_check_coordinates( fid )
161  end if
162 
163  call file_cartesc_close( fid )
164 
165  call topo_fillhalo( fill_bnd=.false. )
166 
167  topo_exist = .true.
168 
169  else
170  log_info_cont(*) 'topography file is not specified.'
171 
172  topo_exist = .false.
173  endif
174 
175  return
176  end subroutine topo_read
177 
178  !-----------------------------------------------------------------------------
180  subroutine topo_write
181  use scale_file_cartesc, only: &
182  file_cartesc_write
183  implicit none
184  !---------------------------------------------------------------------------
185 
186  if ( topo_out_basename /= '' ) then
187 
188  log_newline
189  log_info("TOPO_write",*) 'Output topography file '
190 
191  call topo_fillhalo( fill_bnd=.false. )
192 
193  call file_cartesc_write( topo_zsfc(:,:), topo_out_basename, topo_out_title, & ! [IN]
194  'TOPO', 'Topography', 'm', 'XY', topo_out_dtype, & ! [IN]
195  standard_name="surface_altitude", & ! [IN]
196  haszcoord=.false., aggregate=topo_out_aggregate ) ! [IN]
197 
198  endif
199 
200  return
201  end subroutine topo_write
202 
203 end module scale_topography
subroutine, public topo_write
Write topography.
subroutine, public topo_fillhalo(Zsfc, FILL_BND)
HALO Communication.
integer, public ia
of whole cells: x, local, with HALO
logical, public file_aggregate
Definition: scale_file.F90:171
integer, public ja
of whole cells: y, local, with HALO
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:55
module COMMUNICATION
module file
Definition: scale_file.F90:15
subroutine, public topo_setup
Setup.
module atmosphere / grid / cartesC index
module PROCESS
Definition: scale_prc.F90:11
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:338
logical, public topo_exist
topography exists?
module profiler
Definition: scale_prof.F90:11
module PRECISION
module file / cartesianC
real(rp), dimension(:,:), allocatable, public topo_zsfc
absolute ground height [m]
module TOPOGRAPHY
module STDIO
Definition: scale_io.F90:10
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
subroutine, public file_cartesc_open(basename, fid, aggregate)
open a netCDF file for read
subroutine, public file_cartesc_close(fid)
Close a netCDF file.