grid_tools 1.14.0
Loading...
Searching...
No Matches
utils.F90
Go to the documentation of this file.
1
4
8 module utils
9
10 implicit none
11
12 public
13
14 character(len=512) :: topo_file = "orog"
15 character(len=128) :: topo_field = "orog_filt"
17 character(len=128) :: mask_field = "slmsk"
18 character(len=512) :: grid_file = "atmos_mosaic.nc"
19
20 logical :: zero_ocean = .true.
22 logical :: nested = .false.
23 logical :: regional = .false.
24
25 integer :: grid_type = 0
26
27 real :: stretch_fac = 1.0
28 real :: res = 48.
29
30 contains
31
36 subroutine read_namelist
37
38 implicit none
39
40 integer :: stdunit = 6, unit=7, io_status
41 logical :: opened
42
43 namelist /filter_topo_nml/ topo_file, topo_field, mask_field, grid_file, zero_ocean, &
45
46 do
47 inquire( unit=unit, opened=opened )
48 if( .NOT.opened )exit
49 unit = unit + 1
50 if( unit.EQ.100 )call handle_err(-1, 'Unable to locate unit number.' )
51 end do
52
53 open( unit=unit, file='input.nml', iostat=io_status )
54 read( unit,filter_topo_nml, iostat=io_status )
55 close(unit)
56
57 if (io_status > 0) call handle_err(-1, 'Error reading input.nml')
58
59 write (stdunit, nml=filter_topo_nml)
60
61 end subroutine read_namelist
62
70 subroutine fill_regional_halo(data, halo)
71 integer, intent(in) :: halo
72 real, dimension(1-halo:,1-halo:,:), intent(inout) :: data
73 integer :: h, i_st, i_ed, j_st, j_ed
74
75 i_st=lbound(data,1)+halo
76 i_ed=ubound(data,1)-halo
77 j_st=lbound(data,2)+halo
78 j_ed=ubound(data,2)-halo
79
80 do h = 1, halo
81 data(i_st:i_ed, j_st-1 , :) = 2* data(i_st:i_ed, j_st , :) - data(i_st:i_ed, j_st+1 , :)! north
82 data(i_st:i_ed, j_ed+1 , :) = 2* data(i_st:i_ed, j_ed , :) - data(i_st:i_ed, j_ed-1 , :)! south
83 data(i_st-1 , j_st:j_ed, :) = 2* data(i_st , j_st:j_ed, :) - data(i_st+1 , j_st:j_ed, :)! east
84 data(i_ed+1 , j_st:j_ed, :) = 2* data(i_ed , j_st:j_ed, :) - data(i_ed-1 , j_st:j_ed, :)! west
85
86 data(i_st-1, j_st-1, :) = (data(i_st-1, j_st, :) + data(i_st, j_st-1, :))*0.5 !NW Corner
87 data(i_ed+1, j_st-1, :) = (data(i_ed+1, j_st, :) + data(i_ed, j_st-1, :))*0.5 !NE Corner
88 data(i_st-1, j_ed+1, :) = (data(i_st-1, j_ed, :) + data(i_st, j_ed+1, :))*0.5 !SW Corner
89 data(i_ed+1, j_ed+1, :) = (data(i_ed+1, j_ed, :) + data(i_ed, j_ed+1, :))*0.5 !SE Corner
90
91 i_st=i_st-1
92 i_ed=i_ed+1
93 j_st=j_st-1
94 j_ed=j_ed+1
95 enddo
96
97 end subroutine fill_regional_halo
98
106 subroutine handle_err(status, string)
107
108 implicit none
109
110#include <netcdf.inc>
111
112 integer, intent(in) :: status
113 character(len=*), intent(in) :: string
114 character(len=256) :: errmsg
115
116 if (status .ne. nf_noerr) then
117 errmsg = nf_strerror(status)
118 errmsg = trim(errmsg) // " " // trim(string)
119 print *, "FATAL ERROR:"
120 print *, trim(errmsg)
121 error stop 'Stopped'
122 endif
123
124 end subroutine handle_err
125
126 end module utils
Module that contains general utility routines.
Definition utils.F90:8
logical regional
If true, process a stand-alone regional grid.
Definition utils.F90:23
subroutine fill_regional_halo(data, halo)
This routine extrapolate geolat_c and geolon_c halo points for the regional standalone grid.
Definition utils.F90:71
character(len=128) topo_field
NetCDF record name of the filtered topography (or orography).
Definition utils.F90:15
character(len=512) grid_file
Path/name of the grid mosaic file.
Definition utils.F90:18
character(len=512) topo_file
Path/name of the topography (or orography) file.
Definition utils.F90:14
integer grid_type
Grid type.
Definition utils.F90:25
subroutine handle_err(status, string)
Prints an error message to standard output, then halts program execution with a bad status.
Definition utils.F90:107
real stretch_fac
Grid stretching factor.
Definition utils.F90:27
logical zero_ocean
If true, no diffusive flux into water/ocean area (preserve islands).
Definition utils.F90:20
subroutine read_namelist
Read the program namelist file.
Definition utils.F90:37
real res
The 'CRES' resolution.
Definition utils.F90:28
logical nested
If true, process a global grid with a nest.
Definition utils.F90:22
character(len=128) mask_field
NetCDF record name of the land/sea mask.
Definition utils.F90:17