# Long term daily mean of variables in htp-file
  #png(filename="xx.png", width=600, height=400, pointsize=12)

  x11()
  par(mfrow=c(2,1)) 
  par(mar = c(5, 4, 4, 4) + 0.3)
  plot(1,type="n",ylim=c(0,20),xlim=c(1,3000),col="blue",lwd=2,cex.axis=1.4,
       cex.lab=1.2,ylab="mm",xlab="Jahr",
       xaxt="n",yaxt="n",axes=F)
  #grid(lty="dotdash",col="darkgrey")
  abline(v=seq(1,3000,by=100),h=seq(0,30,by=10),lty="dotted",col="lightgrey")
  axis(1,at=seq(1,30000,by=100),cex.axis=1.2)
  axis(2,at=seq(0,20,by=5),cex.axis=1.2)
  
  par(new = TRUE)                             # Add new plot
  plot(1,type="n",ylim=c(0,10),xlim=c(1,3000),col="green",lwd=4,cex.axis=1.4,
       cex.lab=1.2,ylab="mm",xlab="Jahr",
       xaxt="n",yaxt="n",axes=F)
  axis(side = 4, at=seq(0,10,by=5),cex.axis=1.2)      # Add second axis
  mtext("LAI", side = 4, line = 3)           # Add second axis label
  
  legend("top",inset=0.05,col=c("blue","green","lightblue","orange"),lwd=c(2,2,2,2),
         legend=c("Rain","LAI","GWR","ETa"),
         cex=1.0,bg="white",ncol=4)
  title(main="Burkina Faso Nouna")

  setwd("output/Res")

  for (k in 1:10000)
  {

  system("ps -fC swim | grep swim > swim_progress")
  checkSwim <- read.table("swim_progress")
  if(length(checkSwim) == 0) {
    break()
  }  

  dataInOri<-read.table("htp.prn", skip=0,header=T)
  names(dataInOri)[1]  <- "jahr"
  names(dataInOri)[2]  <- "tag"
  names(dataInOri)[3]  <- "SUB"
  names(dataInOri)[4]  <- "HRU"
  names(dataInOri)[5]  <- "prec"
  names(dataInOri)[6]  <- "irr"
  names(dataInOri)[15] <- "LAI"
  names(dataInOri)[9]  <- "PERC"
  names(dataInOri)[13] <- "ETa"
  names(dataInOri)[21] <- "WS"   #Wasserstress
  names(dataInOri)[22] <- "g"
  names(dataInOri)[23] <- "SWE"  #Soilwater
  
  dataIn <- subset(dataInOri, dataInOri$SUB=="1" & dataInOri$HRU=="1") 
  mean.sim1 <- numeric()
  mean.sim2 <- numeric()
  mean.sim3 <- numeric()
  mean.sim4 <- numeric()
  mean.sim5 <- numeric()
  mean.sim6 <- numeric()
  mean.sim7 <- numeric()
  mean.sim8 <- numeric()
  
  # Mittelere Tage berechnen

  lines(dataIn$PERC,type="l",col="lightblue",lwd=2)
  lines(dataIn$ETa,type="l",col="orange",lwd=2)
  lines(dataIn$LAI,type="l",col="green",lwd=2)
  #box()

  
  Sys.sleep(5)
  
 
  } #for k loop

  for (i in 1:365)
  {
    mean.sim1[i]<-mean(dataIn$prec[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim2[i]<-mean(dataIn$LAI[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim3[i]<-mean(dataIn$PERC[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim4[i]<-mean(dataIn$ETa[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim5[i]<-mean(dataIn$WS[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim6[i]<-mean(dataIn$SWE[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim7[i]<-mean(dataIn$irr[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
    mean.sim8[i]<-mean(dataIn$g[dataIn$jahr>1959 & dataIn$jahr<2020 & dataIn$tag==i])
  }

  par(mar = c(5, 4, 4, 4) + 0.3)
  plot(mean.sim1,type="l",ylim=c(0,15),xlim=c(1,365),col="blue",lwd=2,cex.axis=1.4,
       cex.lab=1.2,ylab="mm",xlab="Jahr",
       xaxt="n",yaxt="n",axes=F)
  lines(mean.sim3,type="l",col="lightblue",lwd=2)
  lines(mean.sim4,type="l",col="orange",lwd=2)
  #lines(dataIn$LAI,type="l",col="green",lwd=2)
  #box()
  #grid(lty="dotdash",col="darkgrey")
  abline(v=seq(1,365,by=30),h=seq(0,15,by=5),lty="dotted",col="lightgrey")
  axis(1,at=seq(1,365,by=30),cex.axis=1.2)
  axis(2,at=seq(0,20,by=5),cex.axis=1.2)
  
  par(new = TRUE)                             # Add new plot
  plot(mean.sim2,type="l",ylim=c(0,10),xlim=c(1,365),col="green",lwd=4,cex.axis=1.4,
       cex.lab=1.2,ylab="mm",xlab="Jahr",
       xaxt="n",yaxt="n",axes=F)
  axis(side = 4, at=seq(0,10,by=5),cex.axis=1.2)      # Add second axis
  mtext("LAI", side = 4, line = 3)           # Add second axis label
  
  legend("top",inset=0.05,col=c("blue","green","lightblue","orange"),lwd=c(2,2,2,2),
         legend=c("Rain","LAI","GWR","ETa"),
         cex=1.0,bg="white",ncol=4)
  title("Kenya, Kisumu")
  
while(names(dev.cur()) !='null device') Sys.sleep(1)