5.13.3-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_common_read_data.f90
Go to the documentation of this file.
1!> \file mo_common_read_data.f90
2!> \brief \copybrief mo_common_read_data
3!> \details \copydetails mo_common_read_data
4
5!> \brief Common reading routines
6!> \details Routines to read the DEM and landcover files.
7!> \authors Robert Schweppe
8!> \date Jun 2018
9!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
10!! mHM is released under the LGPLv3+ license \license_note
11!> \ingroup f_common
13 USE mo_kind, ONLY : i4, dp
14 use mo_message, only: message, error_message
16
17 IMPLICIT NONE
18
19 PRIVATE
20
21 PUBLIC :: read_dem, read_lcover
22
23 ! ------------------------------------------------------------------
24
25CONTAINS
26
27 ! NAME
28 ! read_dem
29
30 ! PURPOSE
31 !> \brief TODO: add description
32
33 !> \details TODO: add description
34
35 ! HISTORY
36 !> \authors Robert Schweppe
37
38 !> \date Jun 2018
39
40 ! Modifications:
41
42 subroutine read_dem
43
44 use mo_append, only : append
46 use mo_common_file, only : file_dem, udem
47 use mo_common_types, only: grid
52 use mo_string_utils, only : num2str
53
54 implicit none
55
56 ! loop variables
57 integer(i4) :: domainid, idomain
58
59 ! file name of file to read
60 character(256) :: fname
61
62 real(dp), dimension(:, :), allocatable :: data_dp_2d
63
64 type(grid), pointer :: level0_idomain
65
66
67 ! ************************************************
68 ! READ SPATIAL DATA FOR EACH DOMAIN
69 ! ************************************************
70 ! allocate necessary variables at Level0
71 allocate(level0(domainmeta%nDomains))
72
73 do idomain = 1, domainmeta%nDomains
74 domainid = domainmeta%indices(idomain)
75
76 level0_idomain => level0(domainmeta%L0DataFrom(idomain))
77
78 ! check whether L0 data is shared
79 if (idomain .gt. 1) then
80 if (domainmeta%L0DataFrom(idomain) < idomain) then
81 !
82 call message(' Using dem of domain ', &
83 trim(adjustl(num2str(domainmeta%indices(domainmeta%L0DataFrom(idomain))))), ' for domain: ',&
84 trim(adjustl(num2str(idomain))), '...')
85
86 ! DO NOT read L0 data
87 cycle
88
89 end if
90 end if
91
92 call message(' Reading dem for domain: ', trim(adjustl(num2str(domainid))), ' ...')
93
94 ! Header (to check consistency)
95 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_dem))
96 call read_header_ascii(trim(fname), udem, &
97 level0_idomain%nrows, level0_idomain%ncols, level0_idomain%xllcorner, &
98 level0_idomain%yllcorner, level0_idomain%cellsize, level0_idomain%nodata_value)
99
100 ! check for L0 and L1 scale consistency
101 if(resolutionhydrology(idomain) .LT. level0_idomain%cellsize) then
102 call error_message('***ERROR: resolutionHydrology (L1) should be smaller than the input data resolution (L0)', raise=.false.)
103 call error_message(' check set-up (in mhm.nml) for domain: ', trim(adjustl(num2str(domainid))), ' ...')
104 end if
105
106 ! DEM + overall mask creation
107 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_dem))
108 call read_spatial_data_nc_or_ascii(trim(fname), udem, &
109 level0_idomain%nrows, level0_idomain%ncols, level0_idomain%xllcorner, &
110 level0_idomain%yllcorner, level0_idomain%cellsize, data_dp_2d, level0_idomain%mask)
111
112 ! put global nodata value into array (probably not all grid cells have values)
113 data_dp_2d = merge(data_dp_2d, nodata_dp, level0_idomain%mask)
114 ! put data in variable
115 call append(l0_elev, pack(data_dp_2d, level0_idomain%mask))
116 ! deallocate arrays
117 deallocate(data_dp_2d)
118
119 level0_idomain%nCells = count(level0_idomain%mask)
120
121 end do
122
123 call set_domain_indices(level0, indices=domainmeta%L0DataFrom)
124
125 end subroutine read_dem
126
127 ! NAME
128 ! read_lcover
129
130 ! PURPOSE
131 !> \brief TODO: add description
132
133 !> \details TODO: add description
134
135 ! HISTORY
136 !> \authors Robert Schweppe
137
138 !> \date Jun 2018
139
140 ! Modifications:
141
142 subroutine read_lcover
143
144 use mo_append, only : append, paste
146 use mo_common_file, only : ulcoverclass
147 use mo_common_types, only: grid
150 use mo_string_utils, only : num2str
151
152 implicit none
153
154 ! loop variables
155 integer(i4) :: domainid, idomain, ivar
156
157 ! file name of file to read
158 character(256) :: fname
159
160 integer(i4), dimension(:, :), allocatable :: data_i4_2d
161
162 integer(i4), dimension(:, :), allocatable :: datamatrix_i4
163
164 logical, dimension(:, :), allocatable :: mask_2d
165
166 type(grid), pointer :: level0_idomain
167
168
169 do idomain = 1, domainmeta%nDomains
170 domainid = domainmeta%indices(idomain)
171
172 level0_idomain => level0(domainmeta%L0DataFrom(idomain))
173
174 ! check whether L0 data is shared
175 ! ToDo: check change
176 if (domainmeta%L0DataFrom(idomain) < idomain) then
177 call message(' Using lcover of domain ', &
178 trim(adjustl(num2str(domainmeta%L0DataFrom(idomain)))), ' for domain: ',&
179 trim(adjustl(num2str(domainid))), '...')
180 ! DO NOT read L0 data
181 cycle
182
183 end if
184
185 call message(' Reading lcover for domain: ', trim(adjustl(num2str(domainid))), ' ...')
186
187 ! LCover read in is realized seperated because of unknown number of scenes
188 do ivar = 1, nlcoverscene
189 fname = trim(adjustl(dirlcover(idomain))) // trim(adjustl(lcfilename(ivar)))
191 level0_idomain%nrows, level0_idomain%ncols, level0_idomain%xllcorner, &
192 level0_idomain%yllcorner, level0_idomain%cellsize, data_i4_2d, mask_2d)
193 ! put global nodata value into array (probably not all grid cells have values)
194 data_i4_2d = merge(data_i4_2d, nodata_i4, mask_2d)
195 call paste(datamatrix_i4, pack(data_i4_2d, level0_idomain%mask), nodata_i4)
196 deallocate(data_i4_2d)
197 end do
198 call append(l0_lcover, datamatrix_i4)
199 deallocate(datamatrix_i4)
200
201 end do
202
203 end subroutine read_lcover
204
205end module mo_common_read_data
Reads spatial data files of ASCII format.
Reads spatial data files of nc or ASCII format.
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
integer(i4), parameter, public nodata_i4
Provides file names and units for mRM.
integer, parameter ulcoverclass
Unit for LCover input data file.
character(len= *), parameter file_dem
DEM input data file.
integer, parameter udem
Unit for DEM input data file.
gridding tools
subroutine, public set_domain_indices(grids, indices)
TODO: add description.
Common reading routines.
subroutine, public read_lcover
TODO: add description.
subroutine, public read_dem
TODO: add description.
Provides common types needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
real(dp), dimension(:), allocatable, public resolutionhydrology
character(256), dimension(:), allocatable, public lcfilename
type(domain_meta), public domainmeta
integer(i4), public nlcoverscene
character(256), dimension(:), allocatable, public dirlcover
real(dp), dimension(:), allocatable, public l0_elev
character(256), dimension(:), allocatable, public dirmorpho
integer(i4), dimension(:, :), allocatable, public l0_lcover
type(grid), dimension(:), allocatable, target, public level0
Reads spatial input data.
subroutine, public read_header_ascii(filename, fileunit, header_ncols, header_nrows, header_xllcorner, header_yllcorner, header_cellsize, header_nodata)
Reads header lines of ASCII files.