##############################################################
# In your script, before performing the analysis, the range  #
# of values of its parameter(s) is specified somewhere       #
# before the main analysis:                                  #
##############################################################

start_date <- 1:12
lead_time <- 1:5

...

###############################################################
# Insert these new lines to link your script with the job     #
# file. They have to be inserted BEFORE the main loop where   #
# you repeat the same analysis many times varying the         #
# parameter(s) defined above (in this example, start_date and #
# lead_time):                                                 #
###############################################################

script.arg <- as.integer(commandArgs(TRUE))

if(length(script.arg) > 0) {
    start_date <- script.arg[1]
    lead_time <- script.arg[2]
}

###############################################################
# In case you script is written in Python, you have to        #
# introduce these lines instead:                              #
###############################################################

import sys
script.arg = int(sys.argv)

if len(script.arg) > 0 :
    start_date = script.arg[1]
    lead_time <- script.arg[2]


###############################################################
# If your script is in fortran, C or another language, you    #
# need to adapt the syntax of the previous lines to the       #
# language used.                                              #
###############################################################

###############################################################
# Here you perform the main analysis (the one which the       #
# major part of computing times) many times, cycling over one #
# parameter (or a few parameters) inside this loop until the  #
# analysis is finished. When you link this script to the job  #
# file, you'll be able to split this analysis in multiple     #
# ones, one for each different value of the looping           #
# parameter(s), and to assign each value to a different job,  #
# running all jobs (or as many as possible) on our cluster.   #
###############################################################

for(sd in start_date){
    for(lt in lead_time){

    # your analysis here
    # ......


    ###########################################################
    # When you save the outputs of the analysis, save them in #
    # one file for each different value of the looping        #
    # parameter(s), because if not, each job will overwrite   #
    # the results of the previous jobs!                       #
    ###########################################################

    save(output_1, output_2, ..., output_N, file=paste0(work.dir, "/my_analysis_start_date_", sd, "_lead_time_", lt, ".RData"))
        
    }    
}
    

   
