fun_read_data:

Usage Arguments Examples

View source: R/sndet_read_data_metadata.R View source: R/fhs_read_data_metadata.R View source: R/esqc_Read_data_metadata.R

Usage

1
fun_read_data(PATH, FILE)

Arguments

PATH
FILE

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (PATH, FILE) 
{
    data = read.csv(paste(PATH, FILE, sep = ""), stringsAsFactors = F)
    units = data[c(1, 2), ]
    data = data[-c(1, 2), ]
    if (colnames(data)[ncol(data)] == "Precip_T_Int15_Metadata") {
        METADATA = T
        warning(paste("OK! This file contains 'Precip_T_Int15_Metadata'.", 
            "  You can read it with 'fun_read_metadata' function.", 
            sep = "\n"))
    }
    else {
        METADATA = F
    }
    if (METADATA == T) {
        for (j in 2:(ncol(data) - 1)) {
            data[, j] = as.numeric(data[, j])
        }
        year <- substring(data[, 1], 1, 4)
        month <- substring(data[, 1], 6, 7)
        day <- substring(data[, 1], 9, 10)
        hour <- substring(data[, 1], 12, 13)
        min <- substr(data[, 1], 15, 16)
        date_chr <- paste(year, "-", month, "-", day, " ", hour, 
            ":", min, ":00", sep = "")
        time <- as.POSIXct(strptime(x = date_chr, format = "%Y-%m-%d %H:%M:%S"), 
            tz = "Etc/GMT-1")
        zoo_data = zoo(data[, -c(1, ncol(data))], order.by = time)
    }
    else {
        for (j in 2:ncol(data)) {
            data[, j] = as.numeric(data[, j])
        }
        year <- substring(data[, 1], 1, 4)
        month <- substring(data[, 1], 6, 7)
        day <- substring(data[, 1], 9, 10)
        hour <- substring(data[, 1], 12, 13)
        min <- substr(data[, 1], 15, 16)
        date_chr <- paste(year, "-", month, "-", day, " ", hour, 
            ":", min, ":00", sep = "")
        time <- as.POSIXct(strptime(x = date_chr, format = "%Y-%m-%d %H:%M:%S"), 
            tz = "Etc/GMT-1")
        zoo_data = zoo(data[, -1], order.by = time)
    }
    return(zoo_data)
  }

EURAC-Ecohydro/SnowSeasonAnalysis documentation built on Dec. 6, 2020, 2:05 a.m.