251 lines
10 KiB
Plaintext
251 lines
10 KiB
Plaintext
<TRASH FROM MUSO.R>
|
|
|
|
## runMuso <- function(settings, parameters=c(" ECOPHYS")){
|
|
## #changing section
|
|
## # for(i in changeinput){
|
|
## # changemulline(settings, parameters[[i]])
|
|
## # }
|
|
## changemulline(settings,parameters)
|
|
|
|
## #spinup run
|
|
## # changemulline(type=1,setup(), parameters[[2]])
|
|
## setwd(settings$inputloc)
|
|
## system(paste(settings$executable,settings$ininput[1],sep=" "))
|
|
## #normal run
|
|
## setwd(settings$inputloc)
|
|
## system(paste(settings$executable,settings$ininput[2],sep=" "))
|
|
## }
|
|
|
|
## rungetMusowc <- function(settings,parameters=c(" ECOPHYS"),timee="y",logfile=FALSE,logfilename=NULL){
|
|
## #spinup run
|
|
## # changemulline(type=1,setup(), parameters[[2]])
|
|
## changemulline(settings,parameters)
|
|
## setwd(settings$inputloc)
|
|
## system(paste(settings$executable,settings$ininput[1],sep=" "))
|
|
## #normal run
|
|
## setwd(settings$inputloc)
|
|
## system(paste(settings$executable,settings$ininput[2],sep=" "))
|
|
|
|
## switch(timee,
|
|
## "d"=(Reva<-getdailyout(settings)),
|
|
## "m"=(Reva<-getmonthlyout(settings)),
|
|
## "y"=(Reva<-getyearlyout(settings))
|
|
## )
|
|
## return(Reva)
|
|
## }
|
|
|
|
<TRASH FROM OTHER_USEFULL_FUNCTIONS.R>
|
|
|
|
##For this functions there is a built in dirname function in R, which do the same.
|
|
## splitstr <- function(string, sep){
|
|
## return(unlist(strsplit(string,sep)))
|
|
## }
|
|
|
|
## containerdir<-function(string){
|
|
## return(paste(splitstr(string,"/")[1:(length(splitstr(string,"/"))-1)],collapse = "/"))
|
|
##}
|
|
|
|
<TRASH FROM CHANGECONTENT.R>
|
|
|
|
## changspecline <- function(filename, line_number,content){
|
|
## #This function calls the UNIX(-like) sed program to change specific line to other, using the row numbers.
|
|
## for_command_line <- paste("sed -i '",line_number,"s/.*/",content,"/'"," ",filename, sep="")
|
|
## system(for_command_line)
|
|
## }
|
|
|
|
## changespecline<- function(filename,line_number,content){
|
|
## TOT=readLines(filename,-1)
|
|
## TOT[line_number]<-content
|
|
## writeLines(TOT,filename)
|
|
## }
|
|
|
|
## changemulline <- function(settings,contents){
|
|
## #This is the function which is capable change multiple specific lines to other using their row numbers.
|
|
## #The function uses the previous changspecline function to operate.
|
|
## varnum <- length(settings$calibrationpar)
|
|
## if(length(contents)!=varnum)
|
|
## {
|
|
## cat("Error: number of the values is not the same as the number of the changed parameters")
|
|
## }
|
|
|
|
## for(i in 1:varnum){
|
|
## changspecline(settings$epcinput,settings$calibrationpar[i], contents[i] )
|
|
## }
|
|
## }
|
|
|
|
## changmulline2 <- function(settings,contents){
|
|
## #This is the function which is capable change multiple specific lines to other using their row numbers.
|
|
## #The function uses the previous changspecline function to operate.
|
|
## varnum <- length(settings$calibrationpar)
|
|
## if(length(contents)!=varnum)
|
|
## {
|
|
## cat("Error: number of the values is not the same as the number of the changed parameters")
|
|
## }
|
|
|
|
## for(i in 1:varnum){
|
|
## changespecline(settings$epcinput,settings$calibrationpar[i], contents[i] )
|
|
## }
|
|
## }
|
|
|
|
|
|
|
|
## changeSpecLine<-function(lineNumber,content,file){
|
|
## TOT=readLines(file,-1)
|
|
## TOT[lineNumber]<-content
|
|
## writeLines(TOT,file)
|
|
## }
|
|
|
|
|
|
###Old solution for path joins, now I use file.path() function
|
|
## if(is.null(inputLoc)){
|
|
## inputLoc<- "./"
|
|
## } else {
|
|
## file.path(inputLoc,"")
|
|
## }
|
|
## inp <- unlist(strsplit(inputLoc,"")) #This is the charactervector of the given imput location
|
|
|
|
## if(inp[length(inp)]!="/"){
|
|
## inp<-c(inp,"/")
|
|
## inputLoc <- paste(inp,collapse = "")
|
|
## rm(inp)
|
|
## }# If inp not ends in / paste one at the end, then make a string, that will be the new inputLoc
|
|
|
|
## ##Example: "a/b/c ==> a/b/c/"
|
|
|
|
|
|
|
|
|
|
|
|
if(is.null(epcInput)){
|
|
epcflag=TRUE
|
|
epcInput[1] <- paste0(inputLoc,inputParser(string=" EPC file name",fileName=iniFiles[[1]],counter=1,value=TRUE))
|
|
epcInput[2] <- paste0(inputLoc,inputParser(string=" EPC file name",fileName=iniFiles[[2]],counter=1,value=TRUE))
|
|
} else {
|
|
iniFiles[[1]][grep(" EPC file name",iniFiles[[1]])]<-paste(epcInput[1],"\t EPC file name",sep="")
|
|
|
|
if(length(epcInput)==2){
|
|
iniFiles[[2]][grep(" EPC file name",iniFiles[[2]])]<-paste(epcInput[2],"\t EPC file name",sep="")
|
|
}
|
|
}
|
|
|
|
if(is.null(metInput)){
|
|
metflag=TRUE
|
|
metInput[1] <- unlist(strsplit(grep(" met file name",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
metInput[2] <- unlist(strsplit(grep(" met file name",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep(" met file name",iniFiles[[1]])]<-paste(metInput[1],"\t met file name",sep="")
|
|
|
|
if(length(metInput)==2){
|
|
iniFiles[[2]][grep(" met file name",iniFiles[[2]])]<-paste(metInput[2],"\t met file name",sep="")
|
|
}}
|
|
|
|
if(is.null(CO2Input)){
|
|
CO2flag=TRUE
|
|
CO2Input[1] <- unlist(strsplit(grep(" CO2 file",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
CO2Input[2] <- unlist(strsplit(grep(" CO2 file",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep(" CO2 file",iniFiles[[1]])]<-paste(CO2Input[1],"\t CO2 file",sep="")
|
|
|
|
if(length(CO2Input)==2){
|
|
iniFiles[[2]][grep(" CO2 file",iniFiles[[2]])]<-paste(CO2Input[2],"\t CO2 file",sep="")
|
|
}}
|
|
|
|
if(is.null(nitInput)){
|
|
nitflag=TRUE
|
|
nitInput[1] <- unlist(strsplit(grep("N-dep file",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
nitInput[2] <- unlist(strsplit(grep("N-dep file",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("N-dep file",iniFiles[[1]])]<-paste(nitInput[1],"N-dep file",sep="N-dep file")
|
|
|
|
if(length(epcInput)==2){
|
|
iniFiles[[2]][grep("N-dep file",iniFiles[[2]])]<-paste(nitInput[2],"N-dep file",sep="")
|
|
}}
|
|
|
|
if(is.null(thinInput)){
|
|
thinflag=TRUE
|
|
thinInput[1] <- unlist(strsplit(grep("do THINNING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
thinInput[2] <- unlist(strsplit(grep("do THINNING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do THINNING",iniFiles[[1]])]<-paste(thinInput[1],"do THINNING",sep="")
|
|
|
|
if(length(thinInput)==2){
|
|
iniFiles[[2]][grep("do THINNING",iniFiles[[2]])]<-paste(thinInput[2],"do THINNING",sep="")
|
|
}}
|
|
|
|
if(is.null(plantInput)){
|
|
plantflag=TRUE
|
|
plantInput[1] <- unlist(strsplit(grep("do PLANTING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
plantInput[2] <- unlist(strsplit(grep("do PLANTING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do PLANTING",iniFiles[[1]])]<-paste(plantInput[1],"do PLANTING",sep="")
|
|
|
|
if(length(plantInput)==2){
|
|
iniFiles[[2]][grep("do PLANTING",iniFiles[[2]])]<-paste(plantInput[2],"do PLANTING",sep="")
|
|
}}
|
|
|
|
if(is.null(mowInput)){
|
|
mowflag=TRUE
|
|
mowInput[1] <- unlist(strsplit(grep("do MOWING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
mowInput[2] <- unlist(strsplit(grep("do MOWING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do MOWING",iniFiles[[1]])]<-paste(mowInput[1],"do MOWING",sep="")
|
|
|
|
if(length(mowInput)==2){
|
|
iniFiles[[2]][grep("do MOWING",iniFiles[[2]])]<-paste(mowInput[2],"do MOWING",sep="")
|
|
}}
|
|
|
|
if(is.null(grazInput)){
|
|
grazflag=TRUE
|
|
grazInput[1] <- unlist(strsplit(grep("do GRAZING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
grazInput[2] <- unlist(strsplit(grep("do GRAZING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do GRAZING",iniFiles[[1]])]<-paste(grazInput[1],"do GRAZING",sep="")
|
|
|
|
if(length(grazInput)==2){
|
|
iniFiles[[2]][grep("do GRAZING",iniFiles[[2]])]<-paste(grazInput[2],"do GRAZING",sep="")
|
|
}}
|
|
|
|
if(is.null(harvInput)){
|
|
harvflag=TRUE
|
|
harvInput[1] <- unlist(strsplit(grep("do HARVESTING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
harvInput[2] <- unlist(strsplit(grep("do HARVESTING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do HARVESTING",iniFiles[[1]])]<-paste(harvInput[1],"do HARVESTING",sep="")
|
|
|
|
if(length(harvInput)==2){
|
|
iniFiles[[2]][grep("do HARVESTING",iniFiles[[2]])]<-paste(harvInput[2],"do HARVESTING",sep="")
|
|
}}
|
|
|
|
if(is.null(plougInput)){
|
|
plougflag=TRUE
|
|
plougInput[1] <- unlist(strsplit(grep("do PLOUGHING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
plougInput[2] <- unlist(strsplit(grep("do PLOUGHING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do PLOUGHING",iniFiles[[1]])]<-paste(plougInput[1],"do PLOUGHING",sep="")
|
|
|
|
if(length(plougInput)==2){
|
|
iniFiles[[2]][grep("do PLOUGHING",iniFiles[[2]])]<-paste(plougInput[2],"do PLOUGHING",sep="")
|
|
}}
|
|
|
|
if(is.null(fertInput)){
|
|
fertflag=TRUE
|
|
fertInput[1] <- unlist(strsplit(grep("do FERTILIZING",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
fertInput[2] <- unlist(strsplit(grep("do FERTILIZING",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do FERTILIZING",iniFiles[[1]])]<-paste(fertInput[1],"do FERTILIZING",sep="")
|
|
|
|
if(length(fertInput)==2){
|
|
iniFiles[[2]][grep("do FERTILIZING",iniFiles[[2]])]<-paste(fertInput[2],"do FERTILIZING",sep="")
|
|
}}
|
|
|
|
if(is.null(irrInput)){
|
|
irrflag=TRUE
|
|
irrInput[1] <- unlist(strsplit(grep("do IRRIGATION",iniFiles[[1]],value=TRUE),"[\ \t]"))[1]
|
|
irrInput[2] <- unlist(strsplit(grep("do IRRIGATION",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]
|
|
} else {
|
|
iniFiles[[1]][grep("do IRRIGATION",iniFiles[[1]])]<-paste(irrInput[1],"do IRRIGATION",sep="")
|
|
|
|
if(length(irrInput)==2){
|
|
iniFiles[[2]][grep("do IRRIGATION",iniFiles[[2]])]<-paste(irrInput[2],"do IRRIGATION",sep="")
|
|
}}
|