readGDCN: Rain gauges

Description Usage Arguments Examples

Description

Functions to read rain gauge data from GCDN and aggregate statistics.

Usage

1
2
3
4
readGDCN(name, type = "PRCP")
raingauges(x0=1,tim=seq(as.Date('1960-01-01'),as.Date('2016-01-01'),by=1),
                       max.stations=NULL,
                       N.min=40*360,path="~/GDCN/")

Arguments

name

file name

type

variable

x0

threshold defining precipitation (mm/day)

tim

time period

max.stations

for testing with a smaller number of stations

N.min

mnimum number of valid data points in the rain gauge records for inclusion

path

path to the data files

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
##---- 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 (name, type = "PRCP") 
{
    cnames <- c(paste("day.", 1:31, sep = ""), paste("flags.day.", 
        1:31, sep = ""))
    reshufle <- rep(0, 62)
    ii <- 0
    for (i in seq(1, 62, by = 2)) {
        ii <- ii + 1
        reshufle[i:(i + 1)] <- seq(ii, 62, by = 31)
    }
    cnames <- cnames[reshufle]
    x <- read.fwf(name, widths = c(3, 8, 4, 2, 4, rep(c(5, 2), 
        31)), col.names = c("country", "stnr", "year", "month", 
        "type", cnames))
    ipick <- is.element(x$type, type)
    if (sum(ipick) > 0) {
        dat <- as.matrix(x[ipick, seq(6, 67, by = 2)]) * 0.1
        dat[dat < -99] <- NA
        attr(dat, "Data source") <- "GDCN"
        attr(dat, "year") <- x$year[ipick]
        attr(dat, "month") <- x$month[ipick]
        attr(dat, "URL") <- "http://www.ncdc.noaa.gov/oa/climate/research/gdcn/gdcn.html"
        attr(dat, "Station_number") <- x$stnr[1]
        attr(dat, "Country_code") <- x$country[1]
        attr(dat, "original data name") <- name
        attr(dat, "flags") <- x[ipick, seq(6, 66, by = 2)]
        attr(dat, "history") <- "read with readGDCN - R-script."
        attr(dat, "Observations") <- rownames(table(x$type))
    }
    else dat <- NA
    invisible(dat)
  }

brasmus/preciparea documentation built on May 7, 2019, 11:11 a.m.