22 USE mo_kind,
ONLY : i4, dp
23 USE mo_os,
ONLY : check_path_isfile
24 use mo_message,
only: error_message
95 header_yllcorner, header_cellsize, data, mask)
99 character(len = *),
intent(in) :: filename
102 integer(i4),
intent(in) :: fileunit
105 integer(i4),
intent(in) :: header_nRows
108 integer(i4),
intent(in) :: header_nCols
111 real(dp),
intent(in) :: header_xllcorner
114 real(dp),
intent(in) :: header_yllcorner
117 real(dp),
intent(in) :: header_cellsize
120 real(dp),
dimension(:, :),
allocatable,
intent(out) :: data
123 logical,
dimension(:, :),
allocatable,
intent(out) :: mask
126 integer(i4) :: file_nRows
129 integer(i4) :: file_nCols
132 real(dp) :: file_xllcorner
135 real(dp) :: file_yllcorner
138 real(dp) :: file_cellsize
141 real(dp) :: file_nodata
146 real(dp),
dimension(:, :),
allocatable :: tmp_data
149 logical,
dimension(:, :),
allocatable :: tmp_mask
154 file_ncols, file_nrows, &
155 file_xllcorner, file_yllcorner, file_cellsize, file_nodata)
156 if ((file_ncols .ne. header_ncols)) &
157 call error_message(
'read_spatial_data_ascii: header not matching with reference header: ncols')
158 if ((file_nrows .ne. header_nrows)) &
159 call error_message(
'read_spatial_data_ascii: header not matching with reference header: nrows')
160 if ((abs(file_xllcorner - header_xllcorner) .gt. tiny(1.0_dp))) &
161 call error_message(
'read_spatial_data_ascii: header not matching with reference header: xllcorner')
162 if ((abs(file_yllcorner - header_yllcorner) .gt. tiny(1.0_dp))) &
163 call error_message(
'read_spatial_data_ascii: header not matching with reference header: yllcorner')
164 if ((abs(file_cellsize - header_cellsize) .gt. tiny(1.0_dp))) &
165 call error_message(
'read_spatial_data_ascii: header not matching with reference header: cellsize')
168 allocate(tmp_data(file_nrows, file_ncols))
169 tmp_data = file_nodata
170 allocate(tmp_mask(file_nrows, file_ncols))
175 call check_path_isfile(path = filename, raise=.true.)
179 open (unit = fileunit, file = filename, action =
'read', status =
'old', recl = 48 * file_ncols)
186 read(fileunit, *) (tmp_data(i, j), j = 1, file_ncols)
191 where (abs(tmp_data - file_nodata) .lt. tiny(1.0_dp))
196 allocate(
data(file_ncols, file_nrows))
197 data = transpose(tmp_data)
200 allocate(mask(file_ncols, file_nrows))
201 mask = transpose(tmp_mask)
235 header_yllcorner, header_cellsize, data, mask)
239 character(len = *),
intent(in) :: filename
242 integer(i4),
intent(in) :: fileunit
245 integer(i4),
intent(in) :: header_nRows
248 integer(i4),
intent(in) :: header_nCols
251 real(dp),
intent(in) :: header_xllcorner
254 real(dp),
intent(in) :: header_yllcorner
257 real(dp),
intent(in) :: header_cellsize
260 integer(i4),
dimension(:, :),
allocatable,
intent(out) :: data
263 logical,
dimension(:, :),
allocatable,
intent(out) :: mask
266 integer(i4) :: file_nRows
269 integer(i4) :: file_nCols
272 real(dp) :: file_xllcorner
275 real(dp) :: file_yllcorner
278 real(dp) :: file_cellsize
281 real(dp) :: file_nodata
286 integer(i4),
dimension(:, :),
allocatable :: tmp_data
289 logical,
dimension(:, :),
allocatable :: tmp_mask
294 file_ncols, file_nrows, &
295 file_xllcorner, file_yllcorner, file_cellsize, file_nodata)
296 if ((file_ncols .ne. header_ncols)) &
297 call error_message(
'read_spatial_data_ascii: header not matching with reference header: ncols')
298 if ((file_nrows .ne. header_nrows)) &
299 call error_message(
'read_spatial_data_ascii: header not matching with reference header: nrows')
300 if ((abs(file_xllcorner - header_xllcorner) .gt. tiny(1.0_dp))) &
301 call error_message(
'read_spatial_data_ascii: header not matching with reference header: xllcorner')
302 if ((abs(file_yllcorner - header_yllcorner) .gt. tiny(1.0_dp))) &
303 call error_message(
'read_spatial_data_ascii: header not matching with reference header: yllcorner')
304 if ((abs(file_cellsize - header_cellsize) .gt. tiny(1.0_dp))) &
305 call error_message(
'read_spatial_data_ascii: header not matching with reference header: cellsize')
308 allocate(tmp_data(file_nrows, file_ncols))
309 tmp_data = int(file_nodata, i4)
310 allocate(tmp_mask(file_nrows, file_ncols))
314 call check_path_isfile(path = filename, raise=.true.)
318 open (unit = fileunit, file = filename, action =
'read', status =
'old', recl = 48 * file_ncols)
325 read(fileunit, *) (tmp_data(i, j), j = 1, file_ncols)
330 where (tmp_data .EQ. int(file_nodata, i4))
335 allocate(
data(file_ncols, file_nrows))
336 data = transpose(tmp_data)
339 allocate(mask(file_ncols, file_nrows))
340 mask = transpose(tmp_mask)
375 subroutine read_header_ascii(filename, fileunit, header_ncols, header_nrows, header_xllcorner, header_yllcorner, &
376 header_cellsize, header_nodata)
381 character(len = *),
intent(in) :: filename
384 integer(i4),
intent(in) :: fileunit
387 integer(i4),
intent(out) :: header_nrows
390 integer(i4),
intent(out) :: header_ncols
393 real(dp),
intent(out) :: header_xllcorner
396 real(dp),
intent(out) :: header_yllcorner
399 real(dp),
intent(out) :: header_cellsize
402 real(dp),
intent(out) :: header_nodata
404 character(5) :: dummy
408 call check_path_isfile(path = filename, raise=.true.)
410 open (unit = fileunit, file = filename, status =
'old')
411 read (fileunit, *) dummy, header_ncols
412 read (fileunit, *) dummy, header_nrows
413 read (fileunit, *) dummy, header_xllcorner
414 read (fileunit, *) dummy, header_yllcorner
415 read (fileunit, *) dummy, header_cellsize
416 read (fileunit, *, iostat=io) dummy, header_nodata
Reads spatial data files of ASCII format.
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
Reads spatial input data.
subroutine read_spatial_data_ascii_i4(filename, fileunit, header_ncols, header_nrows, header_xllcorner, header_yllcorner, header_cellsize, data, mask)
TODO: add description.
subroutine read_spatial_data_ascii_dp(filename, fileunit, header_ncols, header_nrows, header_xllcorner, header_yllcorner, header_cellsize, data, mask)
TODO: add description.
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.