# R script:  codehpc.R
# Example of using command line arguments in an R script
# Author:  NCSU HPC
# Usage:
#  Rscript codehpc.R [#years] [#models]

# Reads in the arguments
args = commandArgs(trailingOnly=TRUE)

# Throw error if missing or too many arguments
argslen <- length(args)
if (argslen > 2) stop('Error: too many arguments')
if (argslen < 2) stop('Error: Takes two arguments, the array locations defining the year and the model for a run')

cat("There were ",argslen," arguments.\n")
cat("Arguments were ",args,"\n")

#define which year by the first command line argument
which_year=as.integer(args[1])
years<- c("1990", "1991")
year<- years[which_year]
cat("The year is ",year,".\n",sep="")

#define which model by the second command line argument
which_model=as.integer(args[2])
models<- c("Mobile_Bay" ,"Pamlico_Sound")
model<- models[which_model]
cat("The model is ",model,".\n",sep="")

# Make an awesome R code here that does some analysis on yearly estuary data (for example)
#
#  blahblahblah_awesome_blah
#
#