XsimName = 'Xsim5.csv';
ySimName = 'ySim5.csv';
Xsim = as.matrix(read.csv(XsimName, header=TRUE));
load("net5.RData");
XsimName = 'Xsim5.csv';
ySimName = 'ySim5.csv';
netName  = 'net5.RData';
Xsim = as.matrix(read.csv(XsimName, header=TRUE));
load(netName);
source("ANnet-Simulate.R");
Xsim = matrix(colMeans(Xsim), nrow=1, ncol=ncol(Xsim));
tmp = colMeans(net@Input)
# Removing any old data
rm(list = ls());
XsimName     = 'Xsim.csv';
XwtrQltyName = 'XwtrQlty.csv';
ySimName     = 'ySim.csv';
netName      = 'net.RData';
# Loading Xsim data and averaging the input
Xsim     = as.matrix(read.csv(XsimName,     header=TRUE));
XwtrQlty = as.matrix(read.csv(XwtrQltyName, header=TRUE));
if (nrow(Xsim) == 30) {
# Lodaing the saved ANnet Object and the ANnet Simulation routine
load(netName);
source("ANnet-Simulate.R");
Xsim     = matrix(colMeans(Xsim),     nrow=1, ncol=ncol(Xsim));
XwtrQlty = matrix(colMeans(XwtrQlty), nrow=1, ncol=ncol(XwtrQlty));
end
end if
load(netName);
source("ANnet-Simulate.R");
Xsim     = matrix(colMeans(Xsim),     nrow=1, ncol=ncol(Xsim));
XwtrQlty = matrix(colMeans(XwtrQlty), nrow=1, ncol=ncol(XwtrQlty));
ySim1 = fSim(net, Xsim, BiasFactor = 0.0); #FLOW
ySim2 = fSim(net, Xsim, BiasFactor = 0.0); #ORGN
ySim3 = fSim(net, Xsim, BiasFactor = 0.0); #NH4
ySim4 = fSim(net, Xsim, BiasFactor = 0.0); #NO2
ySim5 = fSim(net, Xsim, BiasFactor = 0.0); #NO3
ySim6 = fSim(net, Xsim, BiasFactor = 0.0); #ORGP
ySim7 = fSim(net, Xsim, BiasFactor = 0.0); #SOLP
ySim8 = fSim(net, Xsim, BiasFactor = 0.0); #BOD
ySim9 = fSim(net, Xsim, BiasFactor = 0.0); #DO
ySim = cbind(ySim1,ySim2,ySim3,ySim4,ySim5,ySim6,ySim7,ySim8,ySim9);
write.csv(ySim, file=ySimName, row.names=FALSE);
# Updating Xsim.csv and XwtrQlty.csv to receive new input from SWAT
Xsim     = read.csv(XsimName,     header=TRUE);
XwtrQlty = read.csv(XwtrQltyName, header=TRUE);
Xsim     = Xsim[-(1:7),];
XwtrQlty = XwtrQlty[-(1:7),];
write.csv(Xsim,     file=XsimName,     row.names=FALSE)
write.csv(XwtrQlty, file=XwtrQltyName, row.names=FALSE)
load("netDESE.RData");
load("netORGN.RData");
netDESE = net
save(netDESE, file='netDESE.RData');
load("netDESE.RData");
load("netORGN.RData");
XwtrQltyName = 'XwtrQlty.csv';
XwtrQlty = as.matrix(read.csv(XwtrQltyName, header=TRUE));
load("netORGN.RData");
XwtrQlty = matrix(colMeans(XwtrQlty), nrow=1, ncol=ncol(XwtrQlty));
ySim2 = fSim(netORGN, XwtrQlty, BiasFactor = 0.0); #ORGN
source("ANnet-Simulate.R");
ySim2 = fSim(netORGN, XwtrQlty, BiasFactor = 0.0); #ORGN
XwtrQltyName = 'XwtrQlty.csv';
XwtrQlty = as.matrix(read.csv(XwtrQltyName, header=TRUE));
XwtrQlty = matrix(colMeans(XwtrQlty), nrow=1, ncol=ncol(XwtrQlty));
View(XwtrQlty)
# Removing any old data
rm(list = ls());
XsimName     = 'Xsim.csv';
XwtrQltyName = 'XwtrQlty.csv';
ySimName     = 'ySim.csv';
# Loading Xsim data and averaging the input
Xsim     = as.matrix(read.csv(XsimName,     header=TRUE));
XwtrQlty = as.matrix(read.csv(XwtrQltyName, header=TRUE));
# Lodaing the saved ANnet Object and the ANnet Simulation routine
load("netDESE.RData");
load("netTOTN.RData");
load("netTOTP.RData");
source("ANnet-Simulate.R");
Xsim     = matrix(colMeans(Xsim),     nrow=1, ncol=ncol(Xsim));
XwtrQlty = matrix(colMeans(XwtrQlty), nrow=1, ncol=ncol(XwtrQlty));
# Performing the simulations
ySim1 = fSim(netDESE, Xsim,     BiasFactor = 0.0); #FLOW
XwtrQlty = as.matrix(cbind(ySim1, XwtrQlty));
XTOTN = as.matrix(XwtrQlty[1, 1:6]);
yTOTN = fSim(netTOTN, XTOTN, BiasFactor = 0.0); #TOTN
XTOTN = XwtrQlty[1, 1:6];
XTOTN = matrix(XwtrQlty[1, 1:6], nrow=1, ncol=6);
yTOTN = fSim(netTOTN, XTOTN, BiasFactor = 0.0); #TOTN
load("netTOTN.RData");
