5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_mrm_read_data.f90
Go to the documentation of this file.
1!> \file mo_mrm_read_data.f90
2!> \brief \copybrief mo_mrm_read_data
3!> \details \copydetails mo_mrm_read_data
4
5!> \brief mRM reading routines
6!> \details This module contains all routines to read mRM data from file.
7!> \authors Stephan Thober
8!> \date Aug 2015
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_mrm
13 use mo_kind, only : i4, dp
14 use mo_message, only: message, error_message
15
16 implicit none
17
18 public :: mrm_read_l0_data
19 public :: mrm_read_discharge
20 public :: mrm_read_total_runoff
22 private
23contains
24 ! ------------------------------------------------------------------
25
26 ! NAME
27 ! mrm_read_L0_data
28
29 ! PURPOSE
30 !> \brief read L0 data from file
31
32 !> \details With the exception of L0_mask, L0_elev, and L0_LCover, all
33 !> L0 variables are read from file. The former three are only read if they
34 !> are not provided as variables.
35
36 ! INTENT(IN)
37 !> \param[in] "logical :: do_reinit"
38 !> \param[in] "logical :: do_readlatlon"
39 !> \param[in] "logical :: do_readlcover"
40
41 ! HISTORY
42 !> \authors Juliane Mai, Matthias Zink, and Stephan Thober
43
44 !> \date Aug 2015
45
46 ! Modifications:
47 ! Stephan Thober Sep 2015 - added L0_mask, L0_elev, and L0_LCover
48 ! Robert Schweppe Jun 2018 - refactoring and reformatting
49 ! Stephan Thober Jun 2018 - including varying celerity functionality
50
51 subroutine mrm_read_l0_data(do_reinit, do_readlatlon, do_readlcover)
52
53 use mo_append, only : append
56 use mo_common_types, only: grid
58 use mo_mpr_file, only: file_slope, uslope
59 use mo_mrm_file, only : file_facc, file_fdir, &
62 use mo_read_latlon, only : read_latlon
64 use mo_string_utils, only : num2str
65
66 implicit none
67
68 logical, intent(in) :: do_reinit
69
70 logical, intent(in) :: do_readlatlon
71
72 logical, intent(in) :: do_readlcover
73
74 integer(i4) ::domainid, idomain
75
76 integer(i4) :: ivar
77
78 integer(i4) :: igauge
79
80 character(256) :: fname
81
82 integer(i4) :: nunit
83
84 integer(i4), dimension(:, :), allocatable :: data_i4_2d
85
86 integer(i4), dimension(:, :), allocatable :: datamatrix_i4
87
88 logical, dimension(:, :), allocatable :: mask_2d
89
90 logical, dimension(:, :), allocatable :: mask_global
91
92 type(grid), pointer :: level0_idomain => null()
93
94
95 ! ************************************************
96 ! READ SPATIAL DATA FOR EACH DOMAIN
97 ! ************************************************
98 if (do_reinit) then
99 call read_dem()
100 end if
101
102 if (do_readlcover .and. processmatrix(8, 1) .eq. 1) then
103 call read_lcover()
104 else if (do_readlcover .and. ((processmatrix(8, 1) .eq. 2) .or. (processmatrix(8, 1) .eq. 3))) then
105 allocate(datamatrix_i4(count(mask_global), 1))
106 datamatrix_i4 = nodata_i4
107 call append(l0_lcover, datamatrix_i4)
108 ! free memory
109 deallocate(datamatrix_i4)
110 end if
111
112 do idomain = 1, domainmeta%nDomains
113 domainid = domainmeta%indices(idomain)
114
115 level0_idomain => level0(domainmeta%L0DataFrom(idomain))
116
117 ! ToDo: check if change is correct
118 ! check whether L0 data is shared
119 if (domainmeta%L0DataFrom(idomain) < idomain) then
120 !
121 call message(' Using data of domain ', &
122 trim(adjustl(num2str(domainmeta%indices(domainmeta%L0DataFrom(idomain))))), ' for domain: ',&
123 trim(adjustl(num2str(domainid))), '...')
124 cycle
125 !
126 end if
127 !
128 call message(' Reading data for domain: ', trim(adjustl(num2str(domainid))), ' ...')
129
130 if (do_readlatlon) then
131 ! read lat lon coordinates of each domain
132 call read_latlon(idomain, "lon_l0", "lat_l0", "level0", level0_idomain)
133 end if
134
135 ! read fAcc, fDir, gaugeLoc
136 do ivar = 1, 4
137 select case (ivar)
138 case(1) ! flow accumulation
139 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_facc))
140 nunit = ufacc
141 case(2) ! flow direction
142 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_fdir))
143 nunit = ufdir
144 case(3) ! location of gauging stations
145 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_gaugeloc))
146 nunit = ugaugeloc
147 case(4)
148 fname = trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_slope))
149 nunit = uslope
150 end select
151
152 if (ivar .le. 2) then
153 !
154 ! reading and transposing
155 call read_spatial_data_ascii(trim(fname), nunit, &
156 level0_idomain%nrows, level0_idomain%ncols, level0_idomain%xllcorner, &
157 level0_idomain%yllcorner, level0_idomain%cellsize, data_i4_2d, mask_2d)
158
159 ! put global nodata value into array (probably not all grid cells have values)
160 data_i4_2d = merge(data_i4_2d, nodata_i4, mask_2d)
161 end if
162
163 if (ivar .eq. 3) then
164 if (domain_mrm(idomain)%nGauges .ge. 1_i4) then
165 !
166 ! reading and transposing
167 call read_spatial_data_ascii(trim(fname), nunit, &
168 level0_idomain%nrows, level0_idomain%ncols, level0_idomain%xllcorner, &
169 level0_idomain%yllcorner, level0_idomain%cellsize, data_i4_2d, mask_2d)
170
171 ! put global nodata value into array (probably not all grid cells have values)
172 data_i4_2d = merge(data_i4_2d, nodata_i4, mask_2d)
173
174 else
175 ! set to nodata, but not ommit because data association between arrays and domains might break
176 data_i4_2d = merge(nodata_i4, nodata_i4, level0_idomain%mask)
177 end if
178 end if
179
180 ! put data into global L0 variable
181 select case (ivar)
182 case(1) ! flow accumulation
183 call append(l0_facc, pack(data_i4_2d, level0_idomain%mask))
184 case(2) ! flow direction
185 ! rotate flow direction and any other variable with directions
186 ! NOTE: ONLY when ASCII files are read
187 call rotate_fdir_variable(data_i4_2d)
188 ! append
189 call append(l0_fdir, pack(data_i4_2d, level0_idomain%mask))
190 case(3) ! location of evaluation and inflow gauging stations
191 ! evaluation gauges
192 ! Input data check
193 do igauge = 1, domain_mrm(idomain)%nGauges
194 ! If gaugeId is found in gauging location file?
195 if (.not. any(data_i4_2d .EQ. domain_mrm(idomain)%gaugeIdList(igauge))) then
196 call error_message('***ERROR: Gauge ID "', trim(adjustl(num2str(domain_mrm(idomain)%gaugeIdList(igauge)))), &
197 '" not found in ', raise=.false.)
198 call error_message(' Gauge location input file: ', &
199 trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_gaugeloc)))
200 end if
201 end do
202
203 call append(l0_gaugeloc, pack(data_i4_2d, level0_idomain%mask))
204
205 ! inflow gauges
206 ! if no inflow gauge for this subdomain exists still matirx with dim of subdomain has to be paded
207 if (domain_mrm(idomain)%nInflowGauges .GT. 0_i4) then
208 ! Input data check
209 do igauge = 1, domain_mrm(idomain)%nInflowGauges
210 ! If InflowGaugeId is found in gauging location file?
211 if (.not. any(data_i4_2d .EQ. domain_mrm(idomain)%InflowGaugeIdList(igauge))) then
212 call error_message('***ERROR: Inflow Gauge ID "', &
213 trim(adjustl(num2str(domain_mrm(idomain)%InflowGaugeIdList(igauge)))), &
214 '" not found in ', raise=.false.)
215 call error_message(' Gauge location input file: ', &
216 trim(adjustl(dirmorpho(idomain))) // trim(adjustl(file_gaugeloc)))
217 end if
218 end do
219 end if
220
221 call append(l0_inflowgaugeloc, pack(data_i4_2d, level0_idomain%mask))
222
223 end select
224 !
225 ! deallocate arrays
226 if (allocated(data_i4_2d)) deallocate(data_i4_2d)
227 if (allocated(mask_2d)) deallocate(mask_2d)
228 !
229 end do
230 end do
231
232 end subroutine mrm_read_l0_data
233 ! ---------------------------------------------------------------------------
234
235 ! NAME
236 ! mrm_read_discharge
237
238 ! PURPOSE
239 !> \brief Read discharge timeseries from file
240
241 !> \details Read Observed discharge at the outlet of a catchment
242 !> and at the inflow of a catchment. Allocate global runoff
243 !> variable that contains the simulated runoff after the simulation.
244
245 ! HISTORY
246 !> \authors Matthias Zink & Stephan Thober
247
248 !> \date Aug 2015
249
250 ! Modifications:
251 ! Robert Schweppe Jun 2018 - refactoring and reformatting
252
254
255 use mo_append, only : paste
259 use mo_mrm_file, only : udischarge
264 use mo_string_utils, only : num2str
265
266 implicit none
267
268 integer(i4) :: igauge
269
270 integer(i4) :: idomain
271
272 integer(i4) :: maxtimesteps
273
274 ! file name of file to read
275 character(256) :: fname
276
277 integer(i4), dimension(3) :: start_tmp, end_tmp
278
279 real(dp), dimension(:), allocatable :: data_dp_1d
280
281 logical, dimension(:), allocatable :: mask_1d
282
283
284 !----------------------------------------------------------
285 ! INITIALIZE RUNOFF
286 !----------------------------------------------------------
287 maxtimesteps = maxval(simper(1 : domainmeta%nDomains)%julEnd - simper(1 : domainmeta%nDomains)%julStart + 1) * ntstepday
288 allocate(mrm_runoff(maxtimesteps, ngaugeslocal))
290
291 ! READ GAUGE DATA
292 do igauge = 1, ngaugeslocal
293 ! get domain id
294 idomain = gauge%domainId(igauge)
295 ! get start and end dates
296 start_tmp = (/evalper(idomain)%yStart, evalper(idomain)%mStart, evalper(idomain)%dStart/)
297 end_tmp = (/evalper(idomain)%yEnd, evalper(idomain)%mEnd, evalper(idomain)%dEnd /)
298 ! evaluation gauge
299 fname = trim(adjustl(gauge%fname(igauge)))
300 call read_timeseries(trim(fname), udischarge, &
301 start_tmp, end_tmp, optimize, opti_function, &
302 data_dp_1d, mask = mask_1d, nmeasperday = nmeasperday)
303 data_dp_1d = merge(data_dp_1d, nodata_dp, mask_1d)
304 call paste(gauge%Q, data_dp_1d, nodata_dp)
305 deallocate (data_dp_1d)
306 ! TODO-RIV-TEMP: read temperature at gauge
307 end do
308 !
309 ! inflow gauge
310 !
311 ! in mhm call InflowGauge%Q has to be initialized -- dummy allocation with period of domain 1 and initialization
312 if (ninflowgaugestotal .EQ. 0) then
313 allocate(data_dp_1d(maxval(simper(:)%julEnd - simper(:)%julStart + 1)))
314 data_dp_1d = nodata_dp
315 call paste(inflowgauge%Q, data_dp_1d, nodata_dp)
316 else
317 do igauge = 1, ninflowgaugestotal
318 ! get domain id
319 idomain = inflowgauge%domainId(igauge)
320 ! get start and end dates
321 start_tmp = (/simper(idomain)%yStart, simper(idomain)%mStart, simper(idomain)%dStart/)
322 end_tmp = (/simper(idomain)%yEnd, simper(idomain)%mEnd, simper(idomain)%dEnd /)
323 ! inflow gauge
324 fname = trim(adjustl(inflowgauge%fname(igauge)))
325 call read_timeseries(trim(fname), udischarge, &
326 start_tmp, end_tmp, optimize, opti_function, &
327 data_dp_1d, mask = mask_1d, nmeasperday = nmeasperday)
328 if (.NOT. (all(mask_1d))) then
329 call error_message('***ERROR: Nodata values in inflow gauge time series. File: ', trim(fname), raise=.false.)
330 call error_message(' During simulation period from ', num2str(simper(idomain)%yStart) &
331 , ' to ', num2str(simper(idomain)%yEnd))
332 end if
333 data_dp_1d = merge(data_dp_1d, nodata_dp, mask_1d)
334 call paste(inflowgauge%Q, data_dp_1d, nodata_dp)
335 deallocate (data_dp_1d)
336 end do
337 end if
338
339 end subroutine mrm_read_discharge
340
341 ! ---------------------------------------------------------------------------
342
343 ! NAME
344 ! mrm_read_total_runoff
345
346 ! PURPOSE
347 !> \brief read simulated runoff that is to be routed
348
349 !> \details read spatio-temporal field of total runoff that has been
350 !> simulated by a hydrologic model or land surface model. This
351 !> total runoff will then be aggregated to the level 11 resolution
352 !> and then routed through the stream network.
353
354 ! INTENT(IN)
355 !> \param[in] "integer(i4) :: iDomain" domain id
356
357 ! HISTORY
358 !> \authors Stephan Thober
359
360 !> \date Sep 2015
361
362 ! Modifications:
363 ! Stephan Thober Feb 2016 - refactored deallocate statements
364 ! Stephan Thober Sep 2016 - added ALMA convention
365 ! Robert Schweppe Jun 2018 - refactoring and reformatting
366
367 subroutine mrm_read_total_runoff(iDomain)
368
369 use mo_append, only : append
370 use mo_constants, only : hoursecs
376 use mo_read_nc, only : read_nc
377
378 implicit none
379
380 ! domain id
381 integer(i4), intent(in) :: idomain
382
383 integer(i4) :: tt
384
385 integer(i4) :: ntimesteps
386
387 ! tell nc file to read daily or hourly values
388 integer(i4) :: nctimestep
389
390 ! read data from file
391 real(dp), dimension(:, :, :), allocatable :: l1_data
392
393 real(dp), dimension(:, :), allocatable :: l1_data_packed
394
395
396 if (timestep .eq. 1) nctimestep = -4 ! hourly input
397 if (timestep .eq. 24) nctimestep = -1 ! daily input
398 call read_nc(trim(dirtotalrunoff(idomain)), level1(idomain)%nrows, level1(idomain)%ncols, &
399 varnametotalrunoff, level1(idomain)%mask, l1_data, target_period = simper(idomain), &
400 nctimestep = nctimestep, filename = filenametotalrunoff)
401 ! pack variables
402 ntimesteps = size(l1_data, 3)
403 allocate(l1_data_packed(level1(idomain)%nCells, ntimesteps))
404 do tt = 1, ntimesteps
405 l1_data_packed(:, tt) = pack(l1_data(:, :, tt), mask = level1(idomain)%mask)
406 end do
407 ! free space immediately
408 deallocate(l1_data)
409
410 ! convert if ALMA conventions have been given
411 if (alma_convention) then
412 ! convert from kg m-2 s-1 to mm TS-1
413 ! 1 kg m-2 -> 1 mm depth
414 ! multiply with time to obtain per timestep
415 l1_data_packed = l1_data_packed * timestep * hoursecs
416 end if
417
418 ! append
419 call append(l1_total_runoff_in, l1_data_packed(:, :), nodata_dp)
420
421 !free space
422 deallocate(l1_data_packed)
423
424 end subroutine mrm_read_total_runoff
425
426 subroutine mrm_read_bankfull_runoff(iDomain)
427 ! ---------------------------------------------------------------------------
428
429 ! NAME
430 ! mrm_read_bankfull_runoff
431
432 !> \brief reads the bankfull runoff for approximating the channel widths
433
434 !> \details reads the bankfull runoff, which can be calculated with
435 !> the script in mhm/post_proc/bankfull_discharge.py
436
437 ! INTENT(IN)
438 !> \param[in] "integer(i4) :: iDomain" domain id
439
440 ! INTENT(INOUT)
441 ! None
442
443 ! INTENT(OUT)
444 ! None
445
446 ! INTENT(IN), OPTIONAL
447 ! None
448
449 ! INTENT(INOUT), OPTIONAL
450 ! None
451
452 ! INTENT(OUT), OPTIONAL
453 ! None
454
455 ! RETURN
456 ! None
457
458 ! RESTRICTIONS
459 !> \note The file read in must contain a double precision float variable with the name
460 !> "Q_bkfl".
461
462 ! EXAMPLE
463 ! None
464
465 ! LITERATURE
466 ! None
467
468 ! HISTORY
469 ! \author Lennart Schueler
470 ! \date May 2018
471
473 use mo_read_nc, only: read_const_nc
474 use mo_mrm_global_variables, only: &
475 dirbankfullrunoff, & ! directory of bankfull_runoff file for each domain
476 l11_bankfull_runoff_in ! bankfull runoff at L1
477
478 implicit none
479
480 ! input variables
481 integer(i4), intent(in) :: idomain
482
483 ! local variables
484 real(dp), dimension(:,:), allocatable :: l11_data ! read data from file
485 real(dp), dimension(:), allocatable :: l11_data_packed
486
487 call read_const_nc(trim(dirbankfullrunoff(idomain)), &
488 level11(idomain)%nrows, &
489 level11(idomain)%ncols, &
490 "Q_bkfl", l11_data)
491
492 allocate(l11_data_packed(level11(idomain)%nCells))
493 l11_data_packed(:) = pack(l11_data(:,:), mask=level11(idomain)%mask)
494
495 ! append
496 if (allocated(l11_bankfull_runoff_in)) then
498 else
499 allocate(l11_bankfull_runoff_in(size(l11_data_packed)))
500 l11_bankfull_runoff_in = l11_data_packed
501 end if
502
503 deallocate(l11_data)
504 deallocate(l11_data_packed)
505
506 end subroutine mrm_read_bankfull_runoff
507
508 ! NAME
509 ! rotate_fdir_variable
510
511 ! PURPOSE
512 !> \brief TODO: add description
513
514 !> \details TODO: add description
515
516 ! INTENT(INOUT)
517 !> \param[inout] "integer(i4), dimension(:, :) :: x"
518
519 ! HISTORY
520 !> \authors L. Samaniego & R. Kumar
521
522 !> \date Jun 2018
523
524 ! Modifications:
525 ! Robert Schweppe Jun 2018 - refactoring and reformatting
526
528
530
531 implicit none
532
533 integer(i4), dimension(:, :), intent(INOUT) :: x
534
535
536 ! 0 -1 0 |
537 integer(i4) :: i, j
538
539
540 !-------------------------------------------------------------------
541 ! NOTE:
542 !
543 ! Since the DEM was transposed from (lat,lon) to (lon,lat), i.e.
544 ! new DEM = transpose(DEM_old), then
545 !
546 ! the flow direction X (which was read) for every i, j cell needs
547 ! to be rotated as follows
548 !
549 ! X(i,j) = [R] * {uVector}
550 !
551 ! with
552 ! {uVector} denoting the fDir_old (read) in vector form, and
553 ! e.g. dir 8 => {-1, -1, 0 }
554 ! [R] denting a full rotation matrix to transform the flow
555 ! direction into the new coordinate system (lon,lat).
556 !
557 ! [R] = [rx][rz]
558 !
559 ! with
560 ! | 1 0 0 |
561 ! [rx] =| 0 cos T sin T | = elemental rotation along x axis
562 ! | 0 -sin T cos T |
563 !
564 ! | cos F sin F 0 |
565 ! [rz] =| -sin F cos F 0 | = elemental rotation along z axis
566 ! | 0 0 1 |
567 !
568 ! and T = pi, F = - pi/2
569 ! thus
570 ! | 0 -1 0 |
571 ! [R] =| -1 0 0 |
572 ! | 0 0 -1 |
573 ! making all 8 directions the following transformation were
574 ! obtained.
575 !-------------------------------------------------------------------
576 do i = 1, size(x, 1)
577 do j = 1, size(x, 2)
578 if (x(i, j) .eq. nodata_i4) cycle
579 select case (x(i, j))
580 case(1)
581 x(i, j) = 4
582 case(2)
583 x(i, j) = 2
584 case(4)
585 x(i, j) = 1
586 case(8)
587 x(i, j) = 128
588 case(16)
589 x(i, j) = 64
590 case(32)
591 x(i, j) = 32
592 case(64)
593 x(i, j) = 16
594 case(128)
595 x(i, j) = 8
596 end select
597 end do
598 end do
599
600 end subroutine rotate_fdir_variable
601
602end module mo_mrm_read_data
Reads spatial data files of ASCII format.
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
integer(i4), parameter, public nodata_i4
Provides structures needed by mHM, mRM and/or mpr.
type(period), dimension(:), allocatable, public simper
type(period), dimension(:), allocatable, public evalper
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.
type(domain_meta), public domainmeta
character(256), dimension(:), allocatable, public dirmorpho
integer(i4), dimension(:, :), allocatable, public l0_lcover
integer(i4), dimension(nprocesses, 3), public processmatrix
type(grid), dimension(:), allocatable, target, public level1
type(grid), dimension(:), allocatable, target, public level0
Provides file names and units for mRM.
character(len=*), parameter file_slope
slope input data file
integer, parameter uslope
Unit for slope input data file.
Provides file names and units for mRM.
integer, parameter ufacc
Unit for flow accumulation input data file.
integer, parameter udischarge
unit for discharge time series
character(len=*), parameter file_gaugeloc
gauge location input data file
character(len=*), parameter file_facc
integer, parameter ufdir
Unit for flow direction input data file.
integer, parameter ugaugeloc
Unit for gauge location input data file.
character(len=*), parameter file_fdir
flow direction input data file
Global variables for mRM only.
type(gaugingstation), public inflowgauge
type(riv_temp_type), public riv_temp_pcs
This is a container for the river temperature routing process (pcs)
integer(i4), dimension(:), allocatable, public l0_fdir
character(256), dimension(:), allocatable, public dirbankfullrunoff
real(dp), dimension(:, :), allocatable, public mrm_runoff
type(gaugingstation), public gauge
type(domaininfo_mrm), dimension(:), allocatable, target, public domain_mrm
type(grid), dimension(:), allocatable, target, public level11
character(256), public varnametotalrunoff
integer(i4), dimension(:), allocatable, public l0_facc
integer(i4), dimension(:), allocatable, public l0_inflowgaugeloc
character(256), dimension(:), allocatable, public dirtotalrunoff
real(dp), dimension(:, :), allocatable, public l1_total_runoff_in
real(dp), dimension(:), allocatable, public l11_bankfull_runoff_in
integer(i4), public ninflowgaugestotal
integer(i4), dimension(:), allocatable, public l0_gaugeloc
character(256), public filenametotalrunoff
mRM reading routines
subroutine, public mrm_read_bankfull_runoff(idomain)
subroutine, public mrm_read_discharge
Read discharge timeseries from file.
subroutine, public mrm_read_l0_data(do_reinit, do_readlatlon, do_readlcover)
read L0 data from file
subroutine rotate_fdir_variable(x)
TODO: add description.
subroutine, public mrm_read_total_runoff(idomain)
read simulated runoff that is to be routed
reading latitude and longitude coordinates for each domain
subroutine, public read_latlon(ii, lon_var_name, lat_var_name, level_name, level)
reads latitude and longitude coordinates
Reads forcing input data.
subroutine, public read_const_nc(folder, nrows, ncols, varname, data, filename)
Reads time independent forcing input in NetCDF file format.
subroutine, public read_nc(folder, nrows, ncols, varname, mask, data, target_period, lower, upper, nctimestep, filename, nocheck, maskout, is_meteo, bound_error, ntstepforcingday)
Reads forcing input in NetCDF file format.
Reads spatial input data.
Routines to read files containing timeseries data.
subroutine, public read_timeseries(filename, fileunit, periodstart, periodend, optimize, opti_function, data, mask, nmeasperday)
Reads time series in ASCII format.