grid_tools  1.6.0
 All Data Structures Files Functions Variables
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, &
44  stretch_fac, res, nested, grid_type, regional
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 handle_err(status, string)
71 
72  implicit none
73 
74 #include <netcdf.inc>
75 
76  integer, intent(in) :: status
77  character(len=*), intent(in) :: string
78  character(len=256) :: errmsg
79 
80  if (status .ne. nf_noerr) then
81  errmsg = nf_strerror(status)
82  errmsg = trim(errmsg) // " " // trim(string)
83  print *, "FATAL ERROR:"
84  print *, trim(errmsg)
85  error stop 'Stopped'
86  endif
87 
88  end subroutine handle_err
89 
90  end module utils
subroutine read_namelist
Read the program namelist file.
Definition: utils.F90:36
subroutine handle_err(status, string)
Prints an error message to standard output, then halts program execution with a bad status...
Definition: utils.F90:70
Module that contains general utility routines.
Definition: utils.F90:8