bash script example for submitting jobs to the queue

In the hope that some of you might benefit from this, here's an example of a bash script which you can use to submit jobs  to the queue.
I think it's a good example of passing parameters to a bash script,  function calling and filename manipulation.  The general idea is to do all the directory creation and job submitting in bash and to how have the actual jobs written as Rscripts which use the optparse library to parse command line arguments.