New modul for change met data, and outputmapper
This commit is contained in:
parent
b5cc7a88b5
commit
49afb724a3
@ -15,7 +15,7 @@ getdailyout<-function(settings){
|
||||
binaryname<-paste(settings$inputloc,settings$outputnames,".dayout",sep="")
|
||||
d<-file(binaryname,"rb")
|
||||
dayoutput<-matrix(readBin(d,"double",size=8,n=(settings$numdata[1])),(settings$numyears*365),byrow=TRUE)
|
||||
close(d)
|
||||
close(d)
|
||||
return(dayoutput)
|
||||
}
|
||||
|
||||
|
||||
49
RBBGCMuso/R/musoMethChanger.R
Normal file
49
RBBGCMuso/R/musoMethChanger.R
Normal file
@ -0,0 +1,49 @@
|
||||
library(RBBGCMuso)
|
||||
library(BayesianTools)
|
||||
library(sensitivity)
|
||||
|
||||
metMusoGet <- function(metFile,skip=4,namerow=3,saveBackup=TRUE, revert=FALSE){
|
||||
|
||||
|
||||
|
||||
metData<-read.table(file = metFile,skip=skip)
|
||||
namesMet <- unlist(read.table(file=metFile,skip = namerow-1,nrows = 1))
|
||||
colnames(metData)<-namesMet
|
||||
|
||||
if(revert){
|
||||
file.copy(grep(basename(metFile),grep("mbck$",list.files(dirname(metFile)),value=TRUE),value = TRUE), metFile,overwrite = TRUE)
|
||||
return(cat("Meteorological data is succesfully reverted to backup data"))
|
||||
}
|
||||
|
||||
if(saveBackup){
|
||||
file.copy(metFile,paste(metFile,"mbck",sep = "-"))
|
||||
}
|
||||
return(metData)
|
||||
}
|
||||
|
||||
metMusoSet <- function(metFile,skip=4,namerow=3,saveBackup=TRUE, revert=FALSE,index, changedData){
|
||||
|
||||
|
||||
|
||||
metData<-read.table(file = metFile,skip=skip)
|
||||
namesMet <- unlist(read.table(file=metFile,skip = namerow-1,nrows = 1))
|
||||
colnames(metData)<-namesMet
|
||||
|
||||
if(revert){
|
||||
file.copy(grep("mbck$",list.files(),value=TRUE), metFile)
|
||||
}
|
||||
|
||||
if(saveBackup){
|
||||
file.copy(metFile,paste(metFile,"mbck",sep = "-"))
|
||||
}
|
||||
|
||||
if(is.vector(changedData)&(length(metData[,index])==length(changedData))){
|
||||
metData[,index]<-changedData
|
||||
|
||||
changedMet<- c(readLines(metFile,-1)[1:skip],apply(metData,1, function (x) paste(x,collapse = " ")))
|
||||
return(writeLines(changedMet,metFile))
|
||||
|
||||
}else {
|
||||
return(cat("\n\tThe changedData is not a vector or not in a same length"))
|
||||
}
|
||||
}
|
||||
@ -36,3 +36,11 @@ musoMapping <- function(code, mapData=NULL){
|
||||
return(unlist(mapData[which(mapData[,1]==650),2]))
|
||||
}
|
||||
}
|
||||
|
||||
musoMappingFind <- function(variable=NULL){
|
||||
if(is.null(variable)){
|
||||
return(mMapping)
|
||||
} else {
|
||||
mMapping[grep(variable,mMapping[,2]),]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user