SCALE-RM
scale_topography.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
9 !-------------------------------------------------------------------------------
11  !-----------------------------------------------------------------------------
12  !
13  !++ used modules
14  !
15  use scale_precision
16  use scale_stdio
17  use scale_prof
19  !-----------------------------------------------------------------------------
20  implicit none
21  private
22  !-----------------------------------------------------------------------------
23  !
24  !++ Public procedure
25  !
26  public :: topo_setup
27  public :: topo_fillhalo
28  public :: topo_write
29 
30  !-----------------------------------------------------------------------------
31  !
32  !++ Public parameters & variables
33  !
34  logical, public :: topo_exist = .false.
35 
36  real(RP), public, allocatable :: topo_zsfc(:,:)
37 
38  !-----------------------------------------------------------------------------
39  !
40  !++ Private procedure
41  !
42  private :: topo_read
43 
44  !-----------------------------------------------------------------------------
45  !
46  !++ Private parameters & variables
47  !
48  character(len=H_LONG), private :: topo_in_basename = ''
49  character(len=H_LONG), private :: topo_out_basename = ''
50  character(len=H_MID), private :: topo_out_title = 'SCALE-RM TOPOGRAPHY'
51  character(len=H_MID), private :: topo_out_dtype = 'DEFAULT'
52 
53  !-----------------------------------------------------------------------------
54 contains
55  !-----------------------------------------------------------------------------
57  subroutine topo_setup
58  use scale_process, only: &
60  implicit none
61 
62  namelist / param_topo / &
63  topo_in_basename, &
64  topo_out_basename, &
65  topo_out_dtype
66 
67  integer :: ierr
68  !---------------------------------------------------------------------------
69 
70  if( io_l ) write(io_fid_log,*)
71  if( io_l ) write(io_fid_log,*) '++++++ Module[TOPOGRAPHY] / Categ[ATMOS-RM GRID] / Origin[SCALElib]'
72 
73  !--- read namelist
74  rewind(io_fid_conf)
75  read(io_fid_conf,nml=param_topo,iostat=ierr)
76  if( ierr < 0 ) then !--- missing
77  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
78  elseif( ierr > 0 ) then !--- fatal error
79  write(*,*) 'xxx Not appropriate names in namelist PARAM_TOPO. Check!'
80  call prc_mpistop
81  endif
82  if( io_lnml ) write(io_fid_log,nml=param_topo)
83 
84  allocate( topo_zsfc(ia,ja) )
85  topo_zsfc(:,:) = 0.0_rp
86 
87  ! read from file
88  call topo_read
89 
90  return
91  end subroutine topo_setup
92 
93  !-----------------------------------------------------------------------------
95  subroutine topo_fillhalo( Zsfc )
96  use scale_comm, only: &
97  comm_vars8, &
98  comm_wait
99  implicit none
100  real(RP), intent(inout), optional :: Zsfc(ia,ja)
101  !---------------------------------------------------------------------------
102 
103  if ( present(zsfc) ) then
104  call comm_vars8( zsfc(:,:), 1 )
105  call comm_wait ( zsfc(:,:), 1 )
106  else
107  call comm_vars8( topo_zsfc(:,:), 1 )
108  call comm_wait ( topo_zsfc(:,:), 1 )
109  end if
110 
111  return
112  end subroutine topo_fillhalo
113 
114  !-----------------------------------------------------------------------------
116  subroutine topo_read
117  use gtool_file, only: &
118  fileread
119  use scale_fileio, only: &
120  fileio_read
121  use scale_process, only: &
122  prc_mpistop, &
123  prc_myrank
124  use scale_grid, only: &
125  grid_cx, &
126  grid_cy
127 
128  implicit none
129 
130  real(RP) :: tmp_CX(ia), tmp_CY(ja)
131  real(RP) :: epsilon
132  integer :: i, j
133  !---------------------------------------------------------------------------
134 
135  epsilon = 0.1_rp**(rp-1)
136 
137  if( io_l ) write(io_fid_log,*)
138  if( io_l ) write(io_fid_log,*) '*** Input topography file ***'
139 
140  if ( topo_in_basename /= '' ) then
141 
142  call fileio_read( topo_zsfc(:,:), & ! [OUT]
143  topo_in_basename, 'TOPO', 'XY', step=1 ) ! [IN]
144 
145  call topo_fillhalo
146 
147  topo_exist = .true.
148 
149  call fileread( tmp_cx(:), topo_in_basename, 'CX', 1, prc_myrank )
150  call fileread( tmp_cy(:), topo_in_basename, 'CY', 1, prc_myrank )
151 
152  do i = 1, ia
153  if( abs(tmp_cx(i) - grid_cx(i)) > epsilon ) then
154  write( io_fid_log,'(A)') '*** X position in TOPO_IN_BASENAME is different from GRID_IN_BASENAME ***'
155  write( io_fid_log,* ) "I", i, tmp_cx(i), grid_cx(i)
156  call prc_mpistop
157  endif
158  enddo
159  do j = 1, ja
160  if( abs(tmp_cy(j) - grid_cy(j)) > epsilon ) then
161  write( io_fid_log,'(A)') '*** Y position in TOPO_IN_BASENAME is different from GRID_IN_BASENAME ***'
162  write( io_fid_log,* ) "J", j, tmp_cy(j), grid_cy(j)
163  call prc_mpistop
164  endif
165  enddo
166 
167  else
168  if( io_l ) write(io_fid_log,*) '*** topography file is not specified.'
169 
170  topo_exist = .false.
171  endif
172 
173  return
174  end subroutine topo_read
175 
176  !-----------------------------------------------------------------------------
178  subroutine topo_write
179  use scale_fileio, only: &
180  fileio_write
181  implicit none
182  !---------------------------------------------------------------------------
183 
184  if ( topo_out_basename /= '' ) then
185 
186  if( io_l ) write(io_fid_log,*)
187  if( io_l ) write(io_fid_log,*) '*** Output topography file ***'
188 
189  call fileio_write( topo_zsfc(:,:), topo_out_basename, topo_out_title, & ! [IN]
190  'TOPO', 'Topography', 'm', 'XY', topo_out_dtype, & ! [IN]
191  nozcoord=.true. )
192 
193  endif
194 
195  return
196  end subroutine topo_write
197 
198 end module scale_topography
subroutine, public topo_write
Write topography.
module GTOOL_FILE
Definition: gtool_file.f90:17
subroutine, public topo_fillhalo(Zsfc)
HALO Communication.
subroutine, public prc_mpistop
Abort MPI.
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
module STDIO
Definition: scale_stdio.F90:12
module FILE I/O (netcdf)
module grid index
integer, public ia
of x whole cells (local, with HALO)
subroutine, public topo_setup
Setup.
module COMMUNICATION
Definition: scale_comm.F90:23
module PROCESS
integer, public prc_myrank
process num in local communicator
real(rp), dimension(:), allocatable, public grid_cx
center coordinate [m]: x, local
module GRID (cartesian)
logical, public topo_exist
topography exists?
module profiler
Definition: scale_prof.F90:10
logical, public io_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
module PRECISION
real(rp), dimension(:,:), allocatable, public topo_zsfc
absolute ground height [m]
module TOPOGRAPHY
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
integer, parameter, public rp
real(rp), dimension(:), allocatable, public grid_cy
center coordinate [m]: y, local
integer, public ja
of y whole cells (local, with HALO)