Professional Documents
Culture Documents
22 SupplementaryDataS2
22 SupplementaryDataS2
# R script to batch run DayCent using different soil, weather and management files
# --------------------------------------------------------------------------------------------------
# 31st March,2017
# These R Scripts: Part One and Two are distributed with the aim to give R beginners ideas for what
# Variations of part one and two R scripts used together could involve:
# This script gives each result in a different file, all results could be collated into one file
#====================================================================
# In the outvars.txt file list all required outputs to be placed in the .lis file
# in this case .sch files (and their respective .bin and .lis files) are named
# (since DAIRYN3 was simply the name of the field being simulated)
#====================================================================
#====================================================================
modelpath<-"D://Daycent_directory_filename//"
daycent<-"./DailyDayCent.exe"
list100<-"./DailyDayCent_list100.exe"
#====================================================================
for (r in 1:10)
count<-paste("loop: ",r,sep="")
print(count)
setwd(modelpath)
print(modelpath)
print(cmdline)
system(cmdline, wait=TRUE)
# run model
print(cmdline)
system(cmdline, wait=TRUE)
# an alternate command to delete any previous ascii lis file of the same name
unlink(lis_file_ext)
# create ascii lis file from binary file using DayCent list100.exe
print(cmdline)
system(cmdline, wait=TRUE)
}
# R scripts for DayCent Part Two:
# R script to collate annual data from .lis file for 2011-2015, example ryegrass total biomass
# --------------------------------------------------------------------------------------------------
# This file is set to iterate 10 times to match the earlier R program Part One
# which ran Daycent 10 times using different soils (in site.100 files) and weather files
for (r in 1:10)
count<-paste("loop: ",r,sep="")
print(count)
setwd("d://Daycent_directory_filename//")
tableset<-paste("DairyN3_2016_",r,".lis",sep="")
lis.df<-read.table(tableset,header=TRUE)
head(lis.df)
dim(lis.df)
# .lis files have an unusual date format, this is converted into year and month
# create years
head(lis.df)
dim(lis.df)
names(lis.df)
# reorder columns
names(lis.df)
head(lis.df)
head(lis.df)
year<-2011:2015
#shorten to required years - delete rows (vary your row numbers for your output files)
agcacc<-agcacc[c(111,112,113,114,115),]
shrema<-shrema[c(111,112,113,114,115),]
stdedc<-stdedc[c(111,112,113,114,115),]
# create total annual crop biomass produced from total of accumulated aboveground crop carbon plus
# 28th March, 2017: checked the above calculations of output parameters by Excel and they were correct
tableset2.df<-data.frame(year,agcacc,shrema,stdedc,BiomassTOT)
names(tableset2.df)[2]<-"agcacc"
names(tableset2.df)[3]<-"shrema"
names(tableset2.df)[4]<-"stdedc"
names(tableset2.df)[5]<-"BiomassTOT_kg/ha"
write.table(tableset2.df,file=paste("lis5yr_",r,".df",sep=""))