corrigating the leapyear
This commit is contained in:
parent
2a694681b5
commit
caf59371b0
@ -56,6 +56,12 @@ sumDaysOfPeriod <- function(year, periodlen, corrigated=TRUE){
|
||||
}
|
||||
}
|
||||
|
||||
musoLeapYears <- function(settings){
|
||||
days <- 365*settings$numyears
|
||||
years <- settings$startyear:(settings$startyear+settings$numyears-1)
|
||||
Leapyears <-unlist(lapply(years,isLeapyear))
|
||||
return(Leapyears)
|
||||
}
|
||||
|
||||
musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE, format="en"){
|
||||
##purpose: generate date label for muso
|
||||
|
||||
@ -51,3 +51,29 @@ supportedMuso <- function(x="outputs"){
|
||||
return(cat("Supported formats are ",supportedFormats,"If your fileformat is something else, we automaticle coerced it to csv.\n"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
insertRow <- function(existingDF, newrow, r){
|
||||
nr <- nrow(existingDF)
|
||||
existingDF <- rbind(existingDF,rep(NA,ncol(existingDF)))
|
||||
existingDF[seq(r+1,nr+1),] <- existingDF[seq(r,nr),]
|
||||
existingDF[r,] <- newrow
|
||||
existingDF
|
||||
}
|
||||
|
||||
corrigMuso <- function(settings, data){
|
||||
numdays <- nrow(data)
|
||||
data <- data
|
||||
numyears <- settings$numyears
|
||||
leapyears <- musoLeapYears(settings)
|
||||
sylvesters <- data[seq(from=365, to=numdays, by=365),]
|
||||
ind <- 0
|
||||
for(i in 1:numyears){
|
||||
|
||||
if(leapyears[i]){
|
||||
data <- insertRow(data,sylvesters[i],i*360+ind)
|
||||
ind <- ind+1
|
||||
}
|
||||
}
|
||||
return(data)
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
Linuxp <-(Sys.info()[1]=="Linux")
|
||||
|
||||
rungetMuso <- function(settings, timee="d", debugging=FALSE, logfilename=NULL, keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE){
|
||||
rungetMuso <- function(settings, timee="d", debugging=FALSE, logfilename=NULL, keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE, leapYear=FALSE){
|
||||
|
||||
#############################################################
|
||||
############################spinup run############################
|
||||
@ -194,6 +194,13 @@ rungetMuso <- function(settings, timee="d", debugging=FALSE, logfilename=NULL, k
|
||||
colnames(Reva) <- unlist(settings$outputvars[[2]])
|
||||
}
|
||||
|
||||
if(leapYear){
|
||||
Reva <- corrigMuso(settings,Reva)
|
||||
rownames(Reva) <- musoDate(settings)
|
||||
} else {
|
||||
rownames(Reva) <- musoDate(settings, corrigated=FALSE)
|
||||
}
|
||||
|
||||
if(export!=FALSE){
|
||||
setwd(whereAmI)
|
||||
|
||||
@ -204,7 +211,7 @@ rungetMuso <- function(settings, timee="d", debugging=FALSE, logfilename=NULL, k
|
||||
|
||||
|
||||
## )
|
||||
|
||||
write.csv(Reva,export)
|
||||
|
||||
} else{
|
||||
setwd(whereAmI)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user