Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.8.0.0 #6

Merged
merged 8 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions GLUE.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ OD<-paste(DSSATD, OutputD, sep="");
GD<-paste(DSSATD, GenotypeD, sep="");

eval(parse(text=paste("ModelRunIndicatorPath='",OD,"/ModelRunIndicator.txt'",sep = '')));
glueWarningLogFile <- file.path(OD, "GlueWarning.txt");
glueExcludedModelListFile <- file.path(WD, "GlueExcludedModels.csv");
##Path of the model run indicator file, which indicates which component of GLUE is finished so far.


Expand Down Expand Up @@ -115,6 +117,17 @@ LineSplit = unlist(strsplit(DSSATPro[LineNo]," "))
ModelSelect = LineSplit[length(LineSplit)]
write(c("Model Name =",ModelSelect), file = ModelRunIndicatorPath, ncolumns=2, append = T);

# Check is model is in the exclusion list
eval(parse(text=paste("excludedFile<-readLines('",glueExcludedModelListFile,"',n=-1)",sep = '')));
excludedFile.df <- read.table(textConnection(excludedFile[-c(1,2)]),header=F, sep=",")
colnames(excludedFile.df) <- unlist(strsplit(sub("@", "", excludedFile[2]), split = ","))
if (substr(ModelSelect,1,5) %in% excludedFile.df[,"MODEL"]) {
errorMsg <- paste0("Currently model ", ModelSelect, " is not supported by GLUE, please modify the DSSATPRO.v48 file to change to other model for crop ", CropName, ".")
write(errorMsg, file = glueWarningLogFile, ncolumns=1, append = T);
# stop(errorMsg)
q()
}

# Get the genotype file name
GenotypeFilePath<-GD;
CurrentGenotypeFile<-paste0(GD, "/",CropName,substr(ModelSelect,3,8),".CUL")
Expand Down Expand Up @@ -209,14 +222,13 @@ write(c("Parameter property:",CulFile ), file = ModelRunIndicatorPath, append =

# convert text to dataframe
CulFile.df = paste0(substr(CulFile,1,6), substr(CulFile,30,nchar(CulFile)[1]))
header = unlist(strsplit(CulFile.df[2]," "))
header = header[-which(nchar(header)<1)]
header = unlist(strsplit(CulFile.df[2],split="(\\s|\\|)+"))
header = header[which(nchar(header)>0)]
CulData = read.table(textConnection(CulFile.df[-c(1,2)]),header=F)
colnames(CulData) = header

Cali = unlist(strsplit(CulFile[1]," "))

Cali.reshape = paste(Cali[1],"placeholder",Cali[2],sep = " ")
Cali = unlist(strsplit(CulFile[1],"\\s+"))
Cali.reshape = paste(c(Cali[1],"placeholder", Cali[2:length(Cali)]), sep=" ", collapse = " ")
Cali.df = read.table(textConnection(Cali.reshape),header = F)
colnames(Cali.df) = header
CulData = rbind(CulData,Cali.df)
Expand Down
110 changes: 55 additions & 55 deletions GenotypeChange.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ OldLine<-GenotypeFile[LineNumber];#Get the line according to the line number.

R<-RunNumber;#Get what parameter set will be used to change the genotype file.

if (CropName != "SC")
{
# if (CropName != "SC")
# {
ParameterStep<-6;
ValuePosition1<-(38-ParameterStep);
ValuePosition2<-(42-ParameterStep);
Expand Down Expand Up @@ -52,59 +52,59 @@ if (CropName != "SC")
}

GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.
} else
{
ParameterStep<-15;

#chp modified
ValuePosition1<-(47-ParameterStep); #The initial starting point was 42, but it was changed to 46 since "EXPNO" was added by Cheryl recently.
ValuePosition2<-(61-ParameterStep); #The initial ending point was 47, but it is 51 now.

for (i in 1:TotalParameterNumber)
{
ValuePosition1<-ValuePosition1+ParameterStep;
ValuePosition2<-ValuePosition2+ParameterStep;

eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));

if(Parameter>=0 & Parameter<10)
{
ParameterFormat<-sprintf('%1.3f', Parameter);
} else if (Parameter>=10 & Parameter<100)
{
ParameterFormat<-sprintf('%2.2f', Parameter);

# chp added extra format statement for values between 100 and 1000
} else if (Parameter>=100 & Parameter<1000)
{
ParameterFormat<-sprintf('%3.1f', Parameter);
} else

# chp - how to get format xxxx. (with nothing past the ".") ?
{
ParameterFormat<-sprintf('%4.0f', Parameter);
}

##chp
#print(ParameterFormat);
#print (" ");

substr(OldLine, ValuePosition1, ValuePosition2)<-' ';# Delete initial values.
substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;

}

GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.

eval(parse(text=paste('ECOFilePath="',GD,'/SCCAN048.ECO"',sep = '')));
ReadLine<-readLines(ECOFilePath, n=-1)
ECOFile<-as.character(ReadLine);
#Get the ECO file from the Genotype directory.

eval(parse(text=paste("NewECOFilePath='",OD,"/SCCAN048.ECO'",sep = '')));
write(ECOFile, file=NewECOFilePath);
#Save the ECO file in the GLWork directory.
}
# } else
# {
# ParameterStep<-15;
#
# #chp modified
# ValuePosition1<-(47-ParameterStep); #The initial starting point was 42, but it was changed to 46 since "EXPNO" was added by Cheryl recently.
# ValuePosition2<-(61-ParameterStep); #The initial ending point was 47, but it is 51 now.
#
# for (i in 1:TotalParameterNumber)
# {
# ValuePosition1<-ValuePosition1+ParameterStep;
# ValuePosition2<-ValuePosition2+ParameterStep;
#
# eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));
#
# if(Parameter>=0 & Parameter<10)
# {
# ParameterFormat<-sprintf('%1.3f', Parameter);
# } else if (Parameter>=10 & Parameter<100)
# {
# ParameterFormat<-sprintf('%2.2f', Parameter);
#
# # chp added extra format statement for values between 100 and 1000
# } else if (Parameter>=100 & Parameter<1000)
# {
# ParameterFormat<-sprintf('%3.1f', Parameter);
# } else
#
# # chp - how to get format xxxx. (with nothing past the ".") ?
# {
# ParameterFormat<-sprintf('%4.0f', Parameter);
# }
#
# ##chp
# #print(ParameterFormat);
# #print (" ");
#
# substr(OldLine, ValuePosition1, ValuePosition2)<-' ';# Delete initial values.
# substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;
#
# }
#
# GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.
#
# eval(parse(text=paste('ECOFilePath="',GD,'/SCCAN048.ECO"',sep = '')));
# ReadLine<-readLines(ECOFilePath, n=-1)
# ECOFile<-as.character(ReadLine);
# #Get the ECO file from the Genotype directory.
#
# eval(parse(text=paste("NewECOFilePath='",OD,"/SCCAN048.ECO'",sep = '')));
# write(ECOFile, file=NewECOFilePath);
# #Save the ECO file in the GLWork directory.
# }

eval(parse(text=paste("NewGenotypeFilePath='",OD,"/",GenotypeFileName,".CUL'",sep = '')));
write(GenotypeFile, file=NewGenotypeFilePath);
Expand Down
11 changes: 11 additions & 0 deletions GlueExcludedModels.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*Simulation/Crop Models,,
@MODEL,CROP,Description
PRFRM,PO,FORAGE-Perennial peanut
SCCAN,SC,CANEGRO-Sugarcane
SCCSP,SC,CASUPRO-Sugarcane
SCSAM,SC,SAMUCA-Sugarcane
PRFRM,BM,FORAGE-Bermudagrass
PRFRM,BR,FORAGE-Brachiaria
PRFRM,BH,FORAGE-Bahiagrass
PRFRM,AL,FORAGE-Alfalfa
SUOIL,SU,OILCROP-Sunflower