load("F:/HIRDS_work/Hv3/Hirdsv3.RData")
setwd <- "F:/HIRDS_work/Hv3"

#Hirdsv3 <- "F:/HIRDS_work/Hv3/Hirdsv3.r"

Rainfall_dataset <- 
  read.table("F:/HIRDS_work/1Anal/Extra1/55.csv", 
  header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
library(relimp, pos=4)

# length(x) returns the number of rows in a variable

recs <- length(Rainfall_dataset$idt)
print (recs)
## [1] 1
# specifying a row counter

i <- 1

while(i <= recs){

                myX <- as.numeric(Rainfall_dataset$POINT_X[i])
                print (myX)
                myY <- as.numeric(Rainfall_dataset$POINT_Y[i])
                print (myY)
                myID <- Rainfall_dataset$idt[i]

    
    
        # length(x) returns the number of rows in a variable


#Hirdsv3_main.r
#Script to run Hirdsv3 from terminal
#cst August 2007

#Recurrence intervals & specifications & storm durations (pre-loaded in to memory)
#ARI <- c(1.58, 2, 5, 10, 20, 30, 40, 50, 60, 80, 100)
#specs  <- c(738, 501, 2000, 5311, 2000, 3000, 6785)
#durations <- c("10m","20m","30m","60m","2h","6h","12h","24h","48h","72h")
ARI <- get("ARI", envir = globalenv())
specs <- get("specs", envir = globalenv())
durations <- get("durations", envir = globalenv())

#Geographic coordinate (metric) limits
#ylim <- c(5271,6785)*1000;
#xlim <- c(1907,3020)*1000

#land <- 0
#while (land == 0) {
#repeat {
    

#Read site information from terminal
    #print(" Geodetic Datum Cartesian Coordinate System: NZGD49. NZGD2000 not implemented")
    #print(" Enter latitude and longitude as decimal degrees ")


    ycoord <- as.numeric(myY)


    xcoord <- as.numeric(myX)


        site.easting <- round(xcoord/1000, 3)
        site.northing <- round(ycoord/1000, 3)
    
    

site.name <- (Rainfall_dataset$idt[i])
print(site.name)
sitev <- "GEV"
print(sitev)
#Climate Change module - MfE screening assessment
cctemp <- 0
                
#if (length(cctemp) > 1) cctemp <- cctemp[!cctemp==0]

#ifd <- "DDF"

#ifd <- ifelse (ifd == "IFD", TRUE, FALSE)
ifd<-FALSE  #depth durantion table
#ifd<-TRUE   #Intensity 

#Run the main script
print(as.character(c(site.name, site.easting, site.northing, sitev)))
Hv3.out <- Hirdsv3(site.easting, site.northing, site.name, sitev, cctemp, ifd, specs, ARI, durations)
Qp <- Hv3.out$Qp
dimnames(Qp) <- list(NULL, c("ARI","aep",durations))
print(Qp)

#Save output as a csv file
tmp <- site.name
tmp <- (Hv3.out$Qp)
dimnames(tmp) <- list(NULL, c("ARI", "aep", durations))


csvfile <- paste(site.name,sep=".","csv"); print(csvfile)
path<- paste("F:/HIRDS_work/1Anal/Extra1/Process1/",csvfile)
write.csv(tmp,file=path, row.names = FALSE)
  
  i <- i + 1

}
## [1] 2784937
## [1] 6063574
## [1] 1
## [1] "GEV"
## [1] "1"        "2784.937" "6063.574" "GEV"     
##          ARI   aep  10m  20m  30m  60m   2h    6h   12h   24h   48h   72h
##  [1,]   1.58 0.633  6.0  8.5 10.4 14.6 20.9  36.8  52.5  74.9  94.6 108.4
##  [2,]   2.00 0.500  6.7  9.5 11.6 16.3 23.2  40.4  57.4  81.4 102.8 117.8
##  [3,]   5.00 0.200  9.4 13.3 16.2 22.9 31.9  54.1  75.4 105.2 132.8 152.2
##  [4,]  10.00 0.100 11.8 16.6 20.3 28.6 39.4  65.6  90.4 124.6 157.3 180.3
##  [5,]  20.00 0.050 14.5 20.5 25.1 35.4 48.3  78.9 107.5 146.5 185.0 212.0
##  [6,]  30.00 0.033 16.4 23.2 28.4 40.1 54.2  87.7 118.8 160.9 203.1 232.8
##  [7,]  40.00 0.025 17.9 25.3 31.0 43.7 58.9  94.6 127.5 171.9 217.0 248.7
##  [8,]  50.00 0.020 19.2 27.1 33.1 46.7 62.8 100.2 134.6 180.8 228.3 261.7
##  [9,]  60.00 0.017 20.2 28.6 35.0 49.3 66.1 105.1 140.7 188.5 238.0 272.8
## [10,]  80.00 0.012 22.1 31.1 38.1 53.8 71.7 113.2 150.9 201.3 254.1 291.2
## [11,] 100.00 0.010 23.6 33.3 40.7 57.5 76.4 119.9 159.3 211.7 267.3 306.3
## [1] "1.csv"