making assistant functions for calibMuso
This commit is contained in:
parent
61124636b7
commit
0cf2c1af66
62
RBBGCMuso/R/assistantFunctions.R
Normal file
62
RBBGCMuso/R/assistantFunctions.R
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#' getLogs
|
||||||
|
#'
|
||||||
|
#'This function gives us the muso logfiles with their paths
|
||||||
|
#'
|
||||||
|
#'@param outputLoc This is the location of the output files.
|
||||||
|
#'@param outputNames These are the prefixis of the logfiles
|
||||||
|
#'@return Logfiles with paths
|
||||||
|
#'@keywords internal
|
||||||
|
|
||||||
|
|
||||||
|
getLogs <- function(outputLoc, outputNames, type = "spinup"){
|
||||||
|
switch(type,
|
||||||
|
"spinup" = return(grep(paste0(outputNames[1], ".log"), list.files(outputLoc), value = TRUE)),
|
||||||
|
"normal" = return(grep(paste0(outputNames[2], ".log"), list.files(outputLoc), value = TRUE)),
|
||||||
|
"both" = return(grep(paste0(outputNames[2], ".log"), list.files(outputLoc), value = TRUE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#' readErrors
|
||||||
|
#'
|
||||||
|
#'This function reads the spinup and the normal logfiles and gives back the last line which indicates weather there are any errors.
|
||||||
|
#'
|
||||||
|
#'@param outputLoc This is the location of the output files.
|
||||||
|
#'@param logfiles These are the names of the logfiles
|
||||||
|
#'@return vector with 0 and 1 values, 1, if succed, 0 if not. The first is the spinup run, the second is the normal.
|
||||||
|
#'@keywords internal
|
||||||
|
|
||||||
|
|
||||||
|
readErrors <- function(outputLoc, logfiles){
|
||||||
|
return(as.numeric(as.vector(lapply(paste(outputLoc,logfiles,sep = "/"),function(x) tail(readLines(x,-1),1)))) )
|
||||||
|
}
|
||||||
|
|
||||||
|
#' getOutFiles
|
||||||
|
#'
|
||||||
|
#'This function gives us the muso output files with their paths
|
||||||
|
#'
|
||||||
|
#'@param outputLoc This is the location of the output files.
|
||||||
|
#'@param outputNames These are the prefixis of the logfiles
|
||||||
|
#'@return Output files with their paths
|
||||||
|
#'@keywords internal
|
||||||
|
|
||||||
|
|
||||||
|
getOutFiles <- function(outputLoc, outputNames){
|
||||||
|
|
||||||
|
return(grep("out$", grep(paste(paste0(outputNames, "*"), collapse = "|"), list.files(outputLoc), value=TRUE), value = TRUE))
|
||||||
|
}
|
||||||
|
|
||||||
|
#' getOutFiles
|
||||||
|
#'
|
||||||
|
#'This function gives us the muso output files with their paths
|
||||||
|
#'
|
||||||
|
#'@param outputLoc This is the location of the output files.
|
||||||
|
#'@param outputNames These are the prefixis of the logfiles
|
||||||
|
#'@return Output files with their paths
|
||||||
|
#'@keywords internal
|
||||||
|
|
||||||
|
stampAndCopyDir <- function(outputLoc,names,stampDir, stampnum=NULL){
|
||||||
|
if(!is.null(stampnum)){file.copy(file.path(outputLoc,names)
|
||||||
|
,file.path(stampDir,paste0((stampnum+1),"-",possibleNames)))
|
||||||
|
} else{file.copy(file.path(outputLoc,names)
|
||||||
|
,file.path(stampDir,paste0((stamp(stampDir)+1),"-",possibleNames)))}
|
||||||
|
}
|
||||||
@ -70,14 +70,6 @@ calibMuso <- function(settings,parameters=NULL, timee="d", debugging=FALSE, logf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
|
||||||
###########################Defining Functions########################
|
|
||||||
########################################################################
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#############################################################
|
||||||
############################spinup run############################
|
############################spinup run############################
|
||||||
##########################################################
|
##########################################################
|
||||||
@ -125,8 +117,8 @@ calibMuso <- function(settings,parameters=NULL, timee="d", debugging=FALSE, logf
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logspinup <- getLogs(outputLoc,outputNames,type="spinup")
|
||||||
logspinup <- grep(paste0(outputNames[1],".log"), list.files(outputLoc),value = TRUE)
|
## logspinup <- grep(paste0(outputNames[1],".log"), list.files(outputLoc),value = TRUE)
|
||||||
## logspinup <- list.files(outputLoc)[grep("log$",list.files(outputLoc))]#load the logfiles
|
## logspinup <- list.files(outputLoc)[grep("log$",list.files(outputLoc))]#load the logfiles
|
||||||
|
|
||||||
if(length(logspinup)==0){
|
if(length(logspinup)==0){
|
||||||
@ -186,16 +178,14 @@ calibMuso <- function(settings,parameters=NULL, timee="d", debugging=FALSE, logf
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(keepBinary){
|
if(keepBinary){
|
||||||
possibleNames <- grep("out$",grep(paste(paste0(outputNames,"*"), collapse = "|") ,list.files(outputLoc),value=TRUE),value = TRUE)
|
possibleNames <- getOutFiles(outputLoc = outputLoc,outputNames = outputNames)
|
||||||
|
|
||||||
print(stamp(binaryPlace))
|
|
||||||
file.copy(file.path(outputLoc,possibleNames)
|
file.copy(file.path(outputLoc,possibleNames)
|
||||||
,file.path(binaryPlace,paste0((stamp(binaryPlace)+1),"-",possibleNames)))
|
,file.path(binaryPlace,paste0((stamp(binaryPlace)+1),"-",possibleNames)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logfiles <- grep(paste(paste0(outputNames,".log"), collapse = "|"), list.files(outputLoc),value = TRUE)
|
logfiles <- getLogs(outputLoc,outputNames,type="both")
|
||||||
## list.files(outputLoc)[grep("log$",list.files(outputLoc))]#creating a vector for logfilenames
|
## list.files(outputLoc)[grep("log$",list.files(outputLoc))]#creating a vector for logfilenames
|
||||||
|
|
||||||
###############################################
|
###############################################
|
||||||
@ -204,7 +194,7 @@ calibMuso <- function(settings,parameters=NULL, timee="d", debugging=FALSE, logf
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
perror<-as.numeric(as.vector(lapply(paste(outputLoc,logfiles,sep="/"),function(x) tail(readLines(x,-1),1)))) #vector of spinup and normalrun error
|
perror <- readErrors(outputLoc=outputLoc,logfiles=logfiles) #vector of spinup and normalrun error
|
||||||
|
|
||||||
|
|
||||||
##if errorsign is 1 there is error, if it is 0 everything ok
|
##if errorsign is 1 there is error, if it is 0 everything ok
|
||||||
@ -226,7 +216,7 @@ calibMuso <- function(settings,parameters=NULL, timee="d", debugging=FALSE, logf
|
|||||||
if(keepEpc){#if keepepc option turned on
|
if(keepEpc){#if keepepc option turned on
|
||||||
|
|
||||||
if(length(unique(dirname(epc)))>1){
|
if(length(unique(dirname(epc)))>1){
|
||||||
print("Why are you playing with my nervs? Seriously? You hold your epc-s in different folders?")
|
stop("Why are you playing with my nervs? Seriously? You hold your epc-s in different folders?")
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
## epcfiles <- list.files(epcdir)[grep("epc$",list.files(
|
## epcfiles <- list.files(epcdir)[grep("epc$",list.files(
|
||||||
|
|||||||
@ -214,7 +214,7 @@ setupMuso <- function(executable=NULL,
|
|||||||
|
|
||||||
inputFiles<-c(iniInput,epcInput,metInput)
|
inputFiles<-c(iniInput,epcInput,metInput)
|
||||||
numData<-rep(NA,3)
|
numData<-rep(NA,3)
|
||||||
numYears <- as.numeric(unlist(strsplit(grep("simulation years",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])gfrurgc dhxv
|
numYears <- as.numeric(unlist(strsplit(grep("simulation years",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])
|
||||||
## numYears<-unlist(read.table(iniInput[2],skip = 14,nrows = 1)[1])
|
## numYears<-unlist(read.table(iniInput[2],skip = 14,nrows = 1)[1])
|
||||||
numValues <- as.numeric(unlist(strsplit(grep("number of daily output variables",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])
|
numValues <- as.numeric(unlist(strsplit(grep("number of daily output variables",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])
|
||||||
## numValues will be replaced to numVar
|
## numValues will be replaced to numVar
|
||||||
|
|||||||
20
RBBGCMuso/man/getLogs.Rd
Normal file
20
RBBGCMuso/man/getLogs.Rd
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/assistantFunctions.R
|
||||||
|
\name{getLogs}
|
||||||
|
\alias{getLogs}
|
||||||
|
\title{getLogs}
|
||||||
|
\usage{
|
||||||
|
getLogs(outputLoc, outputNames, type = "spinup")
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{outputLoc}{This is the location of the output files.}
|
||||||
|
|
||||||
|
\item{outputNames}{These are the prefixis of the logfiles}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
Logfiles with paths
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function gives us the muso logfiles with their paths
|
||||||
|
}
|
||||||
|
\keyword{internal}
|
||||||
20
RBBGCMuso/man/getOutFiles.Rd
Normal file
20
RBBGCMuso/man/getOutFiles.Rd
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/assistantFunctions.R
|
||||||
|
\name{getOutFiles}
|
||||||
|
\alias{getOutFiles}
|
||||||
|
\title{getOutFiles}
|
||||||
|
\usage{
|
||||||
|
getOutFiles(outputLoc, outputNames)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{outputLoc}{This is the location of the output files.}
|
||||||
|
|
||||||
|
\item{outputNames}{These are the prefixis of the logfiles}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
Output files with their paths
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function gives us the muso output files with their paths
|
||||||
|
}
|
||||||
|
\keyword{internal}
|
||||||
20
RBBGCMuso/man/readErrors.Rd
Normal file
20
RBBGCMuso/man/readErrors.Rd
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/assistantFunctions.R
|
||||||
|
\name{readErrors}
|
||||||
|
\alias{readErrors}
|
||||||
|
\title{readErrors}
|
||||||
|
\usage{
|
||||||
|
readErrors(outputLoc, logfiles)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{outputLoc}{This is the location of the output files.}
|
||||||
|
|
||||||
|
\item{logfiles}{These are the names of the logfiles}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
vector with 0 and 1 values, 1, if succed, 0 if not. The first is the spinup run, the second is the normal.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function reads the spinup and the normal logfiles and gives back the last line which indicates weather there are any errors.
|
||||||
|
}
|
||||||
|
\keyword{internal}
|
||||||
Loading…
Reference in New Issue
Block a user