<p><b>dwj07@fsu.edu</b> 2011-12-02 11:47:02 -0700 (Fri, 02 Dec 2011)</p><p><br>
        -- BRANCH COMMIT --<br>
<br>
        Cleaning up and abstrating a lot of the code from the "driver" script.<br>
<br>
        It now uses functions and should handle any cases that are added as a directory. <br>
        Though the cases need to work in a similar way as the current two do.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/ocean_projects/ocean_test_cases_staging/ocean/oceanTestCases.sh
===================================================================
--- branches/ocean_projects/ocean_test_cases_staging/ocean/oceanTestCases.sh        2011-12-02 16:55:54 UTC (rev 1230)
+++ branches/ocean_projects/ocean_test_cases_staging/ocean/oceanTestCases.sh        2011-12-02 18:47:02 UTC (rev 1231)
@@ -18,308 +18,228 @@
CUR_DIR=`pwd`
-ACTIONS="setup submit postprocess clean"
-CASES="lock_exchange baroclinic_channel"
-
ACTION=$1
CASE=$2
VALID="no"
ACTION_VALID="no"
CASE_VALID="no"
-if [ $# -ge 2 ]; then
-        if [ $1 == "setup" -o $1 == "submit" -o $1 == "postprocess" -o "clean" ]; then
-                ACTION_VALID="yes"
-        fi
+## Function Definitions ###{{{
-        if [ $2 == "lock_exchange" -o $2 == "baroclinic_channel" ]; then
-                CASE_VALID="yes"
-        fi
+setup_mpas () { #{{{
+        rm -f .run_info
+        rm -f run_paths
+        touch .run_info
-        if [ $2 == "mpas" -a $1 == "setup" ]; then
-                VALID="yes"
-        elif [ $2 == "mpas" -a $1 == "clean" ]; then
-                VALID="yes"
-        elif [ $ACTION_VALID == "yes" ]; then
-                if [ $CASE_VALID == "yes" ]; then
-                        VALID="yes"
-                fi
-        fi
-fi
+        echo "Checking out ${REPOSITORY_ADDRESS}"
+        svn co $REPOSITORY_ADDRESS mpas > /dev/null
+        cd mpas
-if [ $VALID == "no" ]; then
-        echo "Invalid usage."
-        echo "./oceanTestCases.sh [action] [case]"
-        echo ""
-        echo "[action] = setup submit postprocess clean"
-        echo ""
-        echo "[case] = lock_exchange baroclinic_channel"
-        echo "[case] = mpas (only for action = setup or clean)"
-        exit
-fi
+        echo "Compiling mpas"
+        make $COMPILE_SET CORE=ocean > /dev/null &> /dev/null
+        REV=`svn info | grep "Revision"`
+        cd ..
-if [ ! -e mpas ]; then
-        if [ $CASE != "mpas" ]; then
-                echo 'must run "./oceanTestCase.sh setup mpas" before other cases'
-                exit
-        fi
-fi
+        MAKE_OPTS=`grep "$COMPILE_SET:" mpas/Makefile -A 11 | tail -n 11 | grep "[a-Z]"`
-if [ $ACTION == "setup" ]; then
-        if [ $CASE == "mpas" ]; then
-                rm -f run_info
-                rm -f run_paths
-                touch run_info
+        echo "Compile flags:" >> .run_info
+        grep "$COMPILE_SET:" mpas/Makefile -A 11 | grep "[a-Z]" >> .run_info
+        echo "" >> .run_info
+        echo "Checkout path:" >> .run_info
+        echo "$REPOSITORY_ADDRESS" >> .run_info
+        echo "$REV" >> .run_info
+        echo "$MACHINE_NAME" >> .run_info
-                svn co $REPOSITORY_ADDRESS
-                cd mpas
-                make $COMPILE_SET CORE=ocean
-                REV=`svn info | grep "Revision"`
-                cd ..
+        echo "${COMPILE_SET}:" > .Makefile.front
+        echo -e "\t$MAKE_OPTS" >> .Makefile.front
+} #}}}
-                MAKE_OPTS=`grep "$COMPILE_SET:" mpas/Makefile -A 11 | tail -n 11 | grep "[a-Z]"`
+setup () { #{{{
+        if [ -e ${CASE}/basin_src ]; then
+                cp .Makefile.front ${CASE}/basin_src/Makefile.front
+        fi
-                echo "Compile flags:" >> run_info
-                grep "$COMPILE_SET:" mpas/Makefile -A 11 | grep "[a-Z]" >> run_info
-                echo "" >> run_info
-                echo "Checkout path:" >> run_info
-                echo "$REPOSITORY_ADDRESS" >> run_info
-                echo "$REV" >> run_info
-                echo "$MACHINE_NAME" >> run_info
-
-                echo "${COMPILE_SET}:" > Makefile.front
-                echo -e "\t$MAKE_OPTS" >> Makefile.front
-        elif [ $CASE == "lock_exchange" ]; then
-                cp Makefile.front lock_exchange/basin_src/.
-                cp Makefile.front lock_exchange/periodic_hex/.
-                cd lock_exchange
-                ./makeMeshes.sh ${CUR_DIR}/mpas/src/ocean_model.exe ${CUR_DIR}/run_info "$PROC_LIST"
-                cd ${CUR_DIR}
-
-                cat lock_exchange/run_paths >> run_paths
-
-        elif [ $CASE == "baroclinic_channel" ]; then
-                cp Makefile.front baroclinic_channel/basin_src/.
-                cp Makefile.front baroclinic_channel/periodic_hex/.
-                cd baroclinic_channel
-                ./makeMeshes.sh ${CUR_DIR}/mpas/src/ocean_model.exe ${CUR_DIR}/run_info "$PROC_LIST"
-                cd ${CUR_DIR}
-
-                cat baroclinic_channel/run_paths >> run_paths
+        if [ -e ${CASE}/periodic_hex ]; then
+                cp .Makefile.front ${CASE}/periodic_hex/Makefile.front
        fi
-elif [ $ACTION == "submit" ]; then
-        if [ $CASE == "lock_exchange" ]; then
-                RUNS=`cat lock_exchange/run_paths`
-                rm -f job_ids_lock_exchange cancel_jobs_lock_exchange.sh
-                rm -f start_times_lock_exchange.sh
-                mkdir -p lock_exchange/submits
-                for RUN in $RUNS
-                do
-                        NAME=`echo ${RUN%/*procs}`
-                        NAME=`echo ${NAME##*/}`
-                        PROCS=`echo ${RUN##*/}`
-                        PROCS=`echo ${PROCS%%procs}`
+        cp .run_info run_info
+        cd ${CASE}
+        ./makeMeshes.sh ${CUR_DIR}/mpas/src/ocean_model.exe ${CUR_DIR}/run_info "$PROC_LIST"
+        cd ${CUR_DIR}
-                        if [ $PROCS -lt $MACHINE_PPN ]; then
-                                NODES=1
-                                PPN=${PROCS}
-                        else
-                                NODES=`echo "$PROCS / $MACHINE_PPN" | bc`
-                                PPN=${MACHINE_PPN}
-                        fi
+        rm run_info
+} #}}}
-                        cat ${CUR_DIR}/${MACHINE_NAME}_submit_template.sh | sed "s/run_name/lock_exchange_${NAME}/g" | sed "s/num_nodes/${NODES}/g" | sed "s/procs_per_node/${PPN}/g" | sed "s|working_dir|$RUN|g" | sed "s/num_procs/$PROCS/g" > lock_exchange/submits/$NAME.sh
+submit () { #{{{
+        RUNS=`cat $CASE/run_paths`
+        rm -f job_ids_$CASE cancel_jobs_$CASE.sh
+        rm -f start_times_$CASE.sh
+        mkdir -p $CASE/submits
-                        ${SUBMISSION_CMD} ${CUR_DIR}/lock_exchange/submits/$NAME.sh >> job_ids_tmp
-                        echo "showstart " >> start_times_front
-                        echo -n " | head -n 3 | tail -n 1 | awk '{print " >> start_times_back
-                        echo -n '$6' >> start_times_back
-                        echo "}'" >> start_times_back
-                        echo "canceljob " >> cancel_jobs_front
-                done
+        for RUN in $RUNS
+        do
+                NAME=`echo ${RUN%/*procs}`
+                NAME=`echo ${NAME##*/}`
+                PROCS=`echo ${RUN##*/}`
+                PROCS=`echo ${PROCS%%procs}`
-                grep "[0-9]" job_ids_tmp > job_ids
+                if [ $PROCS -lt $MACHINE_PPN ]; then
+                        NODES=1
+                        PPN=${PROCS}
+                else
+                        NODES=`echo "$PROCS / $MACHINE_PPN" | bc`
+                        PPN=${MACHINE_PPN}
+                fi
-                paste start_times_front job_ids start_times_back > start_times_lock_exchange.sh
-                paste cancel_jobs_front job_ids > cancel_jobs_lock_exchange.sh
+                cat ${CUR_DIR}/${MACHINE_NAME}_submit_template.sh | sed "s/run_name/${CASE}_${NAME}/g" \
+                        | sed "s/num_nodes/${NODES}/g" | sed "s/procs_per_node/${PPN}/g" | sed "s|working_dir|$RUN|g" \
+                        | sed "s/num_procs/$PROCS/g" > $CASE/submits/$NAME.sh
-                rm -f job_ids_tmp start_times_front start_times_back cancel_jobs_front
+                JOB_ID=`${SUBMISSION_CMD} ${CUR_DIR}/${CASE}/submits/$NAME.sh`
+                JOB_ID=`echo $JOB_ID | grep [0-9]`
+                echo $JOB_ID >> job_ids_${CASE}
-                chmod +x cancel_jobs_lock_exchange.sh
-                chmod +x start_times_lock_exchange.sh
-        elif [ $CASE == "baroclinic_channel" ]; then
-                RUNS=`cat baroclinic_channel/run_paths`
-                rm -f job_ids_baroclinic_channel cancel_jobs_baroclinic_channel.sh
-                rm -f start_times_baroclinic_channel.sh
-                mkdir -p baroclinic_channel/submits
+                echo 'echo "' "$JOB_ID" '" `showstart ' "$JOB_ID | head -n 3 | tail -n 1 | awk '{print" '$6' " }'" '`' >> start_times_${CASE}.sh
+                echo "canceljob $JOB_ID > /dev/null" >> cancel_jobs_${CASE}.sh
+        done
-                for RUN in $RUNS
-                do
-                        NAME=`echo ${RUN%/*procs}`
-                        NAME=`echo ${NAME##*/}`
-                        PROCS=`echo ${RUN##*/}`
-                        PROCS=`echo ${PROCS%%procs}`
+        echo 'echo "All jobs canceled"' >> cancel_jobs_${CASE}.sh
-                        if [ $PROCS -lt $MACHINE_PPN ]; then
-                                NODES=1
-                                PPN=${PROCS}
-                        else
-                                NODES=`echo "$PROCS / $MACHINE_PPN" | bc`
-                                PPN=${MACHINE_PPN}
-                        fi
+        chmod +x cancel_jobs_${CASE}.sh
+        chmod +x start_times_${CASE}.sh
+} #}}}
-                        cat ${CUR_DIR}/${MACHINE_NAME}_submit_template.sh | sed "s/run_name/baroclinic_channel_${NAME}/g" | sed "s/num_nodes/${NODES}/g" | sed "s/procs_per_node/${PPN}/g" | sed "s|working_dir|$RUN|g" | sed "s/num_procs/$PROCS/g" > baroclinic_channel/submits/$NAME.sh
+postprocess () { #{{{
+        rm -f timing_results_${CASE}.txt timing_results2_${CASE}.txt
+        rm -f timing_results3_${CASE}.txt
-                        ${SUBMISSION_CMD} ${CUR_DIR}/baroclinic_channel/submits/$NAME.sh >> job_ids_tmp
-                        echo "showstart " >> start_times_front
-                        echo -n " | head -n 3 | tail -n 1 | awk '{print " >> start_times_back
-                        echo -n '$6' >> start_times_back
-                        echo "}'" >> start_times_back
-                        echo "canceljob " >> cancel_jobs_front
-                done
+        echo "procs = [ " > timing_results3_front
+        echo "WCtime = [ ..." > timing_results3_back
-                grep "[0-9]" job_ids_tmp > job_ids
+        RUNS=`cat ${CASE}/run_paths`
-                paste start_times_front job_ids start_times_back > start_times_baroclinic_channel.sh
-                paste cancel_jobs_front job_ids > cancel_jobs_baroclinic_channel.sh
+        for RUN in $RUNS
+        do
+                NAME=`echo ${RUN%/*procs}`
+                NAME=`echo ${NAME##*/}`
+                SPACING=`echo ${NAME%m*}`
+                PROCS=`echo ${RUN##*/}`
+                PROCS=`echo ${PROCS%%procs}`
-                rm -f job_ids_tmp start_times_front start_times_back cancel_jobs_front
+                KE=`cat ${RUN}/stats_max.txt | tail -n 1 | awk '{print $7}'`
+                TIME=`grep "total time" ${RUN}/log.0000.out | awk '{print $4}'`
+                DURATION=`grep "config_run_duration" ${RUN}/namelist.input`
-                chmod +x cancel_jobs_baroclinic_channel.sh
-                chmod +x start_times_baroclinic_channel.sh
-        fi
+                KM=`expr match "$SPACING" 'k'`
-elif [ $ACTION == "postprocess" ]; then
-        if [ $CASE == "lock_exchange" ]; then
-                rm -f timing_results_lock_exchange.txt timing_results2_lock_exchange.txt
-                rm -f timing_results3_lock_exchange.txt
+                if [ $KM == 0 ]; then
+                        KM=`echo "scale=4; ${SPACING} / 1000" | bc`
+                else
+                        KM=`echo ${SPACING%k}`
+                fi
-                echo "procs = [ " > timing_results3_front
-                echo "WCtime = [ ..." > timing_results3_back
+                echo "${NAME}_${PROCS}procs" >> first
+                echo "${DURATION}" >> second
+                echo "Final KE: ${KE}" >> third
+                echo "Total time: ${TIME}" >> fourth
-                RUNS=`cat lock_exchange/run_paths`
+                echo "${KM}" ${PROCS} ${TIME} >> timing_results2_${CASE}.txt
+                echo `cat time_tmp` " ${TIME}" > time_tmp
-                for RUN in $RUNS
-                do
-                        NAME=`echo ${RUN%/*procs}`
-                        NAME=`echo ${NAME##*/}`
-                        SPACING=`echo ${NAME%m*}`
-                        PROCS=`echo ${RUN##*/}`
-                        PROCS=`echo ${PROCS%%procs}`
+                echo "${PROC} " >> timing_results3_front
+                echo " ${TIME} ; ... % ${NAME}" >> timing_results3_back
+        done
-                        KE=`cat ${RUN}/stats_max.txt | tail -n 1 | awk '{print $7}'`
-                        TIME=`grep "total time" ${RUN}/log.0000.out | awk '{print $4}'`
-                        DURATION=`grep "config_run_duration" ${RUN}/namelist.input`
+        echo " ]'/86400.;" >> timing_results3_back
-                        KM=`expr match "$SPACING" 'k'`
-                        echo "SPACING = $SPACING"
-                        echo "KM = $KM"
+        paste first second third fourth > timing_results_${CASE}.txt
-                        if [ $KM == 0 ]; then
-                                KM=`echo "scale=4; ${SPACING} / 1000" | bc`
-                        else
-                                KM=`echo ${SPACING%k}`
-                        fi
-                        echo "KM = $KM"
+        cat timing_results3_front > timing_results3_${CASE}.txt
+        cat timing_results3_back >> timing_results3_${CASE}.txt
-                        echo "${NAME}_${PROCS}procs" >> first
-                        echo "${DURATION}" >> second
-                        echo "Final KE: ${KE}" >> third
-                        echo "Total time: ${TIME}" >> fourth
+        rm -f first second third fourth timing_results3_front timing_results3_back
+        rm -f time_tmp
+} #}}}
-                        echo "${KM}" ${PROCS} ${TIME} >> timing_results2_lock_exchange.txt
-                        echo `cat time_tmp` " ${TIME}" > time_tmp
+clean_mpas () { #{{{
+        rm -rf mpas
+        rm -f .run_info .Makefile.front
+} #}}}
-                        echo "${PROC} " >> timing_results3_front
-                        echo " ${TIME} ; ... % ${NAME}" >> timing_results3_back
-                done
+clean () { #{{{
+        cd ${CASE}
+        rm -rf *m_*levs submits
+        rm -f run_paths
+        cd ${CUR_DIR}
-                echo " ]'/86400.;" >> timing_results3_back
+        rm -f *${CASE}.sh
+        rm -f timing_results*_${CASE}.txt
+        rm -f job_ids_${CASE}
+} #}}}
-                paste first second third fourth > timing_results_lock_exchange.txt
+#}}}
-                cat timing_results3_front > timing_results3_lock_exchange.txt
-                cat timing_results3_back >> timing_results3_lock_exchange.txt
+if [ ! -e mpas/src/ocean_model.exe ]; then
+        echo "MPAS is not setup properly yet. Setting up MPAS first."
+        setup_mpas
+fi
-                rm first second third fourth timing_results3_front timing_results3_back
-                rm time_tmp
-        elif [ $CASE == "baroclinic_channel" ]; then
-                rm -f timing_results_baroclinic_channel.txt timing_results2_baroclinic_channel.txt
-                rm -f timing_results3_baroclinic_channel.txt
+PMETIS_CHECK=`which pmetis | grep "no pmetis in"`
-                echo "procs = [ " > timing_results3_front
-                echo "WCtime = [ ..." > timing_results3_back
+if [ -n "${PMETIS}" ]; then
+        echo "pmetis must be in your path."
+        exit
+fi
-                RUNS=`cat baroclinic_channel/run_paths`
+if [ $# -ge 2 ]; then
+        if [ $1 == "setup" -o $1 == "submit" -o $1 == "postprocess" -o "clean" ]; then
+                ACTION_VALID="yes"
+        fi
-                for RUN in $RUNS
-                do
-                        NAME=`echo ${RUN%/*procs}`
-                        NAME=`echo ${NAME##*/}`
-                        SPACING=`echo ${NAME%m*}`
-                        PROCS=`echo ${RUN##*/}`
-                        PROCS=`echo ${PROCS%%procs}`
+        if [ -e $2 ]; then
+                CASE_VALID="yes"
+        fi
-                        KE=`cat ${RUN}/stats_max.txt | tail -n 1 | awk '{print $7}'`
-                        TIME=`grep "total time" ${RUN}/log.0000.out | awk '{print $4}'`
-                        DURATION=`grep "config_run_duration" ${RUN}/namelist.input`
+        if [ $ACTION_VALID == "yes" ]; then
+                if [ $CASE_VALID == "yes" ]; then
+                        VALID="yes"
+                fi
+        fi
-                        KM=`expr match "$SPACING" 'k'`
-                        echo "SPACING = $SPACING"
-                        echo "KM = $KM"
+        if [ $CASE == "mpas" -a $ACTION != "clean" ]; then
+                echo "A case of mpas can only have action of clean"
+                echo ""
+                VALID="no"
+        fi
+fi
-                        if [ $KM == 0 ]; then
-                                KM=`echo "scale=4; ${SPACING} / 1000" | bc`
-                        else
-                                KM=`echo ${SPACING%k}`
-                        fi
-                        echo "KM = $KM"
+if [ $VALID == "no" ]; then
+        echo "Invalid usage."
+        echo "./oceanTestCases.sh [action] [case]"
+        echo ""
+        echo "[action] = setup submit postprocess clean"
+        echo ""
+        echo "[case] = lock_exchange baroclinic_channel"
+        echo "[case] = mpas (only for action = clean)"
+        exit
+fi
-                        echo "${NAME}_${PROCS}procs" >> first
-                        echo "${DURATION}" >> second
-                        echo "Final KE: ${KE}" >> third
-                        echo "Total time: ${TIME}" >> fourth
+if [ $ACTION == "setup" ]; then
+        setup
+elif [ $ACTION == "submit" ]; then
+        submit
-                        echo "${KM}" ${PROCS} ${TIME} >> timing_results2_baroclinic_channel.txt
-                        echo `cat time_tmp` " ${TIME}" > time_tmp
-
-                        echo "${PROC} " >> timing_results3_front
-                        echo " ${TIME} ; ... % ${NAME}" >> timing_results3_back
-                done
-
-                echo " ]'/86400.;" >> timing_results3_back
-
-                paste first second third fourth > timing_results_baroclinic_channel.txt
-
-                cat timing_results3_front > timing_results3_baroclinic_channel.txt
-                cat timing_results3_back >> timing_results3_baroclinic_channel.txt
-
-                rm first second third fourth timing_results3_front timing_results3_back
-                rm time_tmp
-        fi
+elif [ $ACTION == "postprocess" ]; then
+        postprocess
elif [ $ACTION == "clean" ]; then
        rm -f run_paths job_ids
        if [ $CASE == "mpas" ]; then
-                rm -rf mpas
-                rm -f run_info Makefile.front
-        elif [ $CASE == "lock_exchange" ]; then
-                cd lock_exchange
-                rm -rf *m_*levs submits
-                rm -f run_paths
-                cd ${CUR_DIR}
-
-                rm -f *lock_exchange.sh
-                rm -f timing_results*_lock_exchange.txt
-        elif [ $CASE == "baroclinic_channel" ]; then
-                cd baroclinic_channel
-                rm -rf *m_*levs submits
-                rm -f run_paths
-                cd ${CUR_DIR}
-
-                rm -f *baroclinic_channel.sh
-                rm -f timing_results*_baroclinic_channel.txt
+                clean_mpas
+        else
+                clean
        fi
fi
+
</font>
</pre>