-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_namelist.F90
57 lines (39 loc) · 1.31 KB
/
module_namelist.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
!-------------------------------------------------------------
MODULE namelist_module
implicit none
integer, parameter :: nml_unit = 7
character(len=1024) :: program_name, input_flnm, output_flnm
integer :: nalt
real :: dz
logical :: debug_on
contains
subroutine read_namelist(file_path)
implicit none
!Reads Namelist from given file.
character(len=*), intent(in) :: file_path
integer :: rc
!Namelist definition.
namelist /control_param/ program_name, input_flnm, &
output_flnm, nalt, dz, debug_on
program_name = 'Vertical Interpolation'
input_flnm = '../data/gfs_4_20210101_0000_000.nc'
output_flnm = 'verticalheight.nc'
nalt = 101
dz = 500.0
debug_on = .false.
!Check whether file exists.
inquire(file=file_path, iostat=rc)
if(rc /= 0) then
write(unit=0, fmt='(3a)') 'Error: input file <', &
trim(file_path), '> does not exist.'
return
end if
!Open and read Namelist file.
open(action='read', file=file_path, iostat=rc, unit=nml_unit)
read(nml=control_param, iostat=rc, unit=nml_unit)
if(rc /= 0) then
write(unit=0, fmt='(a)') 'Error: invalid Namelist format.'
end if
close(nml_unit)
end subroutine read_namelist
END MODULE namelist_module