Index: /issm/trunk/cron/nightlyrun.sh
===================================================================
--- /issm/trunk/cron/nightlyrun.sh	(revision 4818)
+++ /issm/trunk/cron/nightlyrun.sh	(revision 4819)
@@ -4,5 +4,5 @@
 
 #some functions
-function timer()
+function timer() #{{{1
 {
 	if [[ $# -eq 0 ]]; then
@@ -20,11 +20,11 @@
 		printf '%d:%02d:%02d' $dh $dm $ds
 	fi
-}
-function todaydate()
+} #}}}
+function todaydate() #{{{1
 {
 	suffix=`date | awk '{printf("%s-%s-%s  %s",$2,$3,$6,$4);}'`			 
 	echo $suffix;			 
-} 
-function host_name()
+} #}}}
+function host_name() #{{{1
 {
 	#return host name depending on the OS
@@ -36,18 +36,26 @@
 	fi
 	echo $HOST_NAME;
-} 
-
-#get configs
+} #}}}
+
+#Get configuration
+#Source config file{{{1
 if [ $# -ne 1 ];
 then
 	#no config file specified: exit
-	echo "no config file specified. Exiting..."
+	echo "no config file specified. Exiting..." >&2 # Error message to stderr.
 	exit 1
 fi
+if [ ! -f "$1" ]
+then
+	echo "File $1 not found!" >&2   # Error message to stderr.
+	exit 1
+fi 
 source $1;
+#}}}
+#Export ISSM_* variables{{{1
 export ISSM_DIR
 export ISSM_ARCH
-
-#launch nightly run (get start time)
+#}}}
+#Initialize variables {{{1
 TODAY=$(todaydate);
 HOST_NAME=$(host_name $OS);
@@ -56,6 +64,8 @@
 USER=$(whoami);
 INIT_PATH=$(pwd);
-
-#Checkout and install ISSM if required
+#}}}
+
+#Lauch installation
+#Checkout and install ISSM if requested (SKIPINSTALLATION){{{1
 if [ "$SKIPINSTALLATION" != "yes" ]
 then
@@ -81,5 +91,5 @@
 END
 
-	#Install external packages
+	#Compile external packages if requested    (SKIPPACKAGESCOMPILATION){{{2
 	if [ "$SKIPPACKAGESCOMPILATION"  = "yes" ]
 	then
@@ -117,4 +127,5 @@
 		cd ..
 	fi
+	#}}}
 else
 
@@ -124,6 +135,6 @@
 
 fi
-
-#Generate Makefiles and compile ISSM if requested
+#}}}
+#Compile ISSM if requested              (SKIPCOMPILATION) {{{1
 if [ "$SKIPCOMPILATION" != "yes" ]
 then
@@ -147,5 +158,8 @@
 	fi
 fi
-
+#}}}
+
+#Prepare run
+#Windows hack for startup.m {{{1
 #windows environments: ISSM_DIR_WIN variable not correctly picked up when using 
 #the cron job. just get startup to take the ISSM_DIR variable as the pwd:
@@ -155,5 +169,6 @@
 	mv startup.m.bak startup.m
 fi
-
+#}}}
+#Create NightlyRun directory and nightly.log {{{1
 #put installation elapsed time in nightly.log
 INSTALL_TIME=$(timer)
@@ -170,8 +185,12 @@
 elapsed_install: $(echo $ELAPSED_INSTALL)
 END
-
-#Launch matlab and the nightly run script
+#}}}
+
+#Run tests
+#Call run.sh script{{{1
 cd $ISSM_DIR/cron/
 ./run.sh $1
+#}}}
+#Complete nightly.log {{{1
 ELAPSED_RUN=$(timer $INSTALL_TIME)
 ELAPSED_TOTAL=$(timer $START_TIME)
@@ -180,11 +199,13 @@
 elapsed_total: $(echo $ELAPSED_TOTAL)
 END
-
-#Build html report
+#}}}
+
+#Send Report
+#Build html report {{{1
 cd $ISSM_DIR/cron/
 ./report.sh
 echo "html report located in $ISSM_DIR/test/Verification/NightlyRun/report.html"
-
-#send mail if requested
+#}}}
+#send mail if requested                  (SKIPMAIL) {{{1
 if [ "$SKIPMAIL" != "yes" ]
 then
@@ -218,2 +239,3 @@
 	done
 fi
+#}}}
