Commit a45e3a80 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

added function: getInitTargetInfo

parent ed82c678
......@@ -77,6 +77,49 @@ getInitInfo<-function(targetYear, targetMonth, leadMonth) {
return(list(initYear = initYear, initMonth = initMonth,availableInSystem4 = availableInSystem4))
}
getInitTargetInfo<-function(initYear = NULL, initMonth = NULL, leadMonth = NULL, targetYear = NULL, targetMonth = NULL) {
minInitYearInData <- 1981
maxInitYearInData <- 2010
## If target Year and Month were given
if (!is.null(targetYear) && !is.null(targetMonth)) {
targetDate <- as.Date(sprintf("%04d-%02d-01", targetYear, targetMonth))
substractMonthsString <- sprintf("-%d months",leadMonth)
initDate <- seq(targetDate, length = 2, by = substractMonthsString)[2]
initYear <- as.numeric(format(initDate, "%Y"))
initMonth <- as.numeric(format(initDate, "%m"))
} else if (!is.null(initYear) && !is.null(initMonth)) {
## If target Year and Month were given
initDate <- as.Date(sprintf("%04d-%02d-01", initYear, initMonth))
addMonthsString <- sprintf("%d months",leadMonth)
targetDate <- seq(initDate, length = 2, by = addMonthsString)[2]
targetYear <- as.numeric(format(targetDate, "%Y"))
targetMonth <- as.numeric(format(targetDate, "%m"))
} else if (!is.null(initYear) && !is.null(targetMonth)) {
initMonth <- targetMonth - leadMonth
if (initMonth < 1) initMonth<-initMonth+12
initDate <- as.Date(sprintf("%04d-%02d-01", initYear, initMonth))
addMonthsString <- sprintf("%d months",leadMonth)
targetDate <- seq(initDate, length = 2, by = addMonthsString)[2]
targetYear <- as.numeric(format(targetDate, "%Y"))
targetMonth <- as.numeric(format(targetDate, "%m"))
} else if (!is.null(targetYear) && !is.null(initMonth)) {
targetMonth <- initMonth + leadMonth
if (targetMonth > 12) targetMonth<-targetMonth-12
targetDate <- as.Date(sprintf("%04d-%02d-01", targetYear, targetMonth))
substractMonthsString <- sprintf("-%d months",leadMonth)
initDate <- seq(targetDate, length = 2, by = substractMonthsString)[2]
initYear <- as.numeric(format(initDate, "%Y"))
initMonth <- as.numeric(format(initDate, "%m"))
} else {
stop("error: Please give a leadMonth and a year/month combination!")
}
availableInSystem4 <- FALSE
if (initYear >= minInitYearInData && initYear <= maxInitYearInData) availableInSystem4 <- TRUE
return(list(initYear = initYear, targetYear = targetYear, initMonth = initMonth, targetMonth = targetMonth, leadMonth =leadMonth, availableInSystem4 = availableInSystem4))
}
## get the available target years (in system-4) for the certain targetMonth and leadMonth
getAvailableTargetYears <- function(targetYears, targetMonth, leadMonth) {
arrayAvailableInSystem4<-NULL
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment