Index: palm/trunk/SCRIPTS/mrun
===================================================================
--- palm/trunk/SCRIPTS/mrun	(revision 759)
+++ palm/trunk/SCRIPTS/mrun	(revision 807)
@@ -234,4 +234,7 @@
      # 15/09/11 - Siggi  - new option -w tp set the maximum number of parallel
      #                     io streams, option -T is obligatory from now on
+     # 25/01/12 - BjornM - a namelist file check prior to the model run has
+     #                     been implemented (check_namelist_files). 
+     #                     New option -z can be used to skip the check
 
  
@@ -248,4 +251,5 @@
  archive_save=true
  archive_system=none
+ check_namelist_files=true
  compiler_name=""
  cond1=""
@@ -311,4 +315,5 @@
  package_list=""
  punkte="..........................................................."
+ p3d_suffix=""
  queue=none
  read_from_config=""
@@ -449,4 +454,5 @@
     # BEI TERMINAL-BREAK:
  trap 'rm -rf  $working_directory/tmp_mrun
+       rm -rf  $working_directory/tmp_check_namelist_files
        [[ $tmpcreate = true ]]  &&  (cd; rm -rf $TEMPDIR)
        if [[ -f ~/job_queue/JOBINFO.$QSUB_REQID ]]
@@ -479,5 +485,5 @@
     # SHELLSCRIPT-OPTIONEN EINLESEN UND KOMMANDO NEU ZUSAMMENSETZEN, FALLS ES
     # FUER FOLGEJOBS BENOETIGT WIRD
- while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:O:p:P:q:r:R:s:St:T:u:U:vw:xX:yY: option
+ while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:O:p:P:q:r:R:s:St:T:u:U:vw:xX:yY:z option
  do
    case  $option  in
@@ -521,4 +527,5 @@
        (y)   ocean_file_appendix=true; mc="$mc -y";;
        (Y)   run_coupled_model=true; coupled_dist=$OPTARG; mc="$mc -Y'$OPTARG'";;
+       (z)   check_namelist_files=false; mc="$mc -z";;
        (\?)  printf "\n  +++ unknown option $OPTARG \n"
              printf "\n  --> type \"$0 ?\" for available options \n"
@@ -2394,10 +2401,280 @@
     fi
  fi
- 
-
-
-
-     # FALLS AUF DIESER MASCHINE GERECHNET WERDEN SOLL, WERDEN JETZT ENTSPRE-
-     # CHENDE AKTIONEN DURCHGEFUEHRT
+
+#### PERFORM PARAMETER FILE CHECK (COUPLED RUNS ARE NOT SUPPORTED YET)
+ if [[ $check_namelist_files == true && $fromhost == $localhost && $run_coupled_model == false ]]
+ then
+    if [[ $ocean_file_appendix == true ]]
+    then
+       d3par_string="d3o#"
+       d3fpar_string="d3of"
+    else
+       d3par_string="d3#"
+       d3fpar_string="d3f"
+    fi
+
+    tmp_check=${working_directory}/tmp_check
+
+#   GET PARAMETER FILE SUFFIX (USUALLY "_P3D")
+    line=""
+    found=false
+    grep  "$d3par_string" $config_file | grep "PARIN"  >  $tmp_check
+    while read line1
+    do
+       line="$line1"
+       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
+       then
+             # EVENTUELLE DOPPELPUNKTE AUS OPTIONSSTRING ENTFERNEN
+          p3d_suffix=`echo $line | tr -s " " | cut -d" " -s -f5`
+          found=true
+       fi
+    done < $tmp_check
+
+    if [[ $found = false ]]
+    then
+       printf "\n  +++ no PARIN list entry found for $d3par_string in the configuration file."
+
+       locat=check_namelist; exit
+    fi
+
+#   GET RESTART PARAMETER FILE SUFFIX (USUALLY "_P3DF"). THIS FILE MIGHT IS
+#   NOT NECESSARILY REQUIRED
+    line=""
+    found=false
+    grep  "d3f" $config_file | grep "PARIN"  >  $tmp_check
+    while read line1
+    do
+       line="$line1"
+       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
+       then
+          p3df_suffix=`echo $line | tr -s " " | cut -d" " -s -f5`
+          found=true
+       fi
+    done < $tmp_check
+
+    if [[ $found = false ]]
+    then
+       printf "\n  +++ no PARIN list entry found for d3f in the configuration file."
+    fi
+
+    rm -rf ${working_directory}/tmp_check
+
+#   DEFINE VARIABLES FOR FREQUENTLY USED DIRECTORIES
+    check_depository="${working_directory}/trunk/UTIL"
+    check_sources="${working_directory}/tmp_check_namelist_files"
+
+#   CHECK IF THE A P3DF FILE MUST BE CHECKED
+    for  item  in  $input_list
+    do
+       if [[ "$item" == "restart" || "$item" == d3f || "$item" == d3of ]]
+       then
+          check_restart=1
+       else
+          check_restart=0
+       fi
+    done
+
+#   ERROR IF NO PARAMETER FILE WAS FOUND, OTHERWISE PROCEED
+    if [[ ! -f $working_directory/JOBS/$fname/INPUT/${fname}${p3d_suffix} ]]
+    then
+       printf "\n\n  +++ ERROR: parameter file (${fname}${p3d_suffix}) not found." 
+       locat=check_namelist; exit
+    fi
+   
+#   CHECK IF THE RESTART PARAMETER FILE EXISTS (IF NECESSARY)
+    if  [[ $check_restart == 1 ]]
+    then
+       if [[ ! -f $working_directory/JOBS/$fname/INPUT/${fname}${p3df_suffix} ]]
+       then
+          printf "\n\n  +++ WARNING: restart parameter file (${fname}${p3df_suffix}) is missing."  
+          check_restart=0
+          answer=dummy
+          printf "\n\n"
+
+          while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
+          do
+             printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
+             read  answer
+          done
+          if [[ $answer = a  ||  $answer = A ]]
+          then
+             printf "\n  +++ Aborting...."
+             locat=normal; exit
+          fi
+       else
+          check_restart=1
+       fi
+    fi
+
+#   CREATE TEMPORARY SOURCES_FOR_CHECK PATH
+    mkdir $check_sources
+    cd $check_sources
+
+#   CHECK FOR USER CODE, OTHERWISE USE THE PRECOMPILED CHECK_NAMELIST_FILES.X
+    if [[ -d $working_directory/USER_CODE/$fname ]]
+    then
+       printf "\n\n  *** copying files from $check_depository" 
+       cp $check_depository/check_namelist_files.tar ./
+
+       printf "\n\n  *** untar of makefile and source files in $check_sources"
+       tar -xf check_namelist_files.tar  >  /dev/null  2>&1
+
+       printf "\n\n  *** adding user code." 
+       cp $working_directory/USER_CODE/$fname/* ./
+       touch check_namelist_files.f90
+
+#      GET COMPILER OPTIONS AND PERFORM MAKE
+       printf "\n\n  *** compiling code if necessary...\n"
+       copts_check="-cpp -D_parallel -D__check"
+       make -f Makefile_check F90=$compiler_name_ser  COPT="$copts_check"
+
+#      GET MAKE OUTPUT
+       if [[ $? != 0 ]]
+       then
+          rm -rf  $check_sources
+          locat=check_namelist; exit
+       fi
+    else
+       cp $PALM_BIN/check_namelist_files.x ./
+    fi
+
+    cp $working_directory/JOBS/$fname/INPUT/${fname}${p3d_suffix} ./PARIN
+    if [[ $check_restart == 1 ]] 
+    then
+       cp $working_directory/JOBS/$fname/INPUT/${fname}${p3df_suffix} ./PARINF   
+    fi
+
+#   CREATE ENVPAR FILE, WHICH IS NEEDED BY CHECK_NAMELIST_FILES.X
+    cat  >  ENVPAR  <<  %%END%%
+ &envpar  run_identifier = '$fname', host = '$localhost',
+	    write_binary = '$write_binary', tasks_per_node = $tasks_per_node,
+	    maximum_parallel_io_streams = $maximum_parallel_io_streams,
+	    maximum_cpu_time_allowed = ${cpumax}.,
+	    revision = '$global_revision',
+	    local_dvrserver_running = $local_dvrserver_running /
+
+%%END%%
+
+#   SAFETY CHECK: ONLY PROCEED IF THE PARAMETER CHECK PROGRAM WAS PROPERLY COMPILED
+    if [[ ! -f check_namelist_files.x ]] then
+       printf "\n  +++ WARNING: check_namelist_files.x not found."
+       answer=dummy
+       printf "\n\n"
+       while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
+       do
+          printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
+          read  answer
+       done
+       if [[ $answer = a  ||  $answer = A ]]
+       then
+          printf "\n  +++ Aborting..."
+          rm -rf  $check_sources
+          locat=normal; exit
+       else
+          printf "\n  *** Skipping parameter file check."
+       fi       
+    else
+#      STARTING THE PARAMETER FILE CHECK
+       printf "\n\n  *** starting parameter file check..."
+
+#      CHECKING THE P3D FILE
+       printf "\n\n      (1) checking $fname$p3d_suffix"  
+       echo "$numprocs 0" > VARIN
+       errors=`./check_namelist_files.x < VARIN 2>&1`
+
+       check_error=false
+       if [[ "$errors" == "" ]]
+       then
+          printf " --> o.k."
+       else
+          printf " --> failed."
+          check_error=true
+          printf "\n\n  $errors"
+       fi
+
+#      CHECKING THE PD3F FILE IF NECESSARY
+       if [[ $check_restart == 1 && $check_error == false ]]
+       then
+          printf "\n\n      (2) checking $fname$p3df_suffix"  
+
+#         FIRST CHECK IF INITIALIZING_ACTIONS="READ_RESTART_DATA" IS SET IN &INIPAR LIST
+          found=false
+          cat PARINF|while read line
+          do
+             line=$(echo $line|sed 's/ //g')
+             if [[ $line == *"&inipar"* ]]
+             then
+                start_search=true
+             fi 
+
+             if [[ $start_search == true ]]
+             then
+                if [[ $line == *"initializing_actions='read_restart_data'"* ]]
+                then
+                   found=true
+                   break
+                fi
+             fi
+
+             if [[ $line == *"/"* ]]
+             then
+                start_search=false
+             fi 
+
+          done
+
+          if [[ $found = false ]]
+          then
+             printf "\n\n  +++ ERROR: initializing_actions = 'read_restart_data' not found"
+             printf "\n      in &inipar list in $fname$p3df_suffix."
+             rm -rf  $check_sources
+             locat=check_namelist; exit
+          fi
+
+          echo "$numprocs 1" > VARIN
+          errors=`./check_namelist_files.x < VARIN 2>&1`
+
+          if [[ "$errors" == "" ]]
+          then
+             printf " --> o.k."
+          else
+             printf " --> failed."
+             check_error=true
+             printf "\n\n  $errors"
+          fi
+       fi
+    
+#      REPORT ERRORS AND CONTINUE/EXIT
+       if [[ $check_error == true ]]
+       then
+          printf "\n  +++ errors found in the parameter file!\n"
+          answer=dummy
+          printf "\n\n"
+
+          while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
+          do
+          printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
+          read  answer
+          done
+
+          if [[ $answer = a  ||  $answer = A ]]
+          then
+             printf "\n  +++ Aborting..."
+             rm -rf  $check_sources
+             locat=normal; exit
+          fi
+        else
+          printf "\n\n  *** parameter file(s) seem(s) to be o.k.\n"
+        fi
+        rm -rf $check_sources
+    fi
+ else
+    printf "\n\n  +++ skipping parameter file check\n" 
+ fi
+
+ cd $working_directory
+
+    # FALLS AUF DIESER MASCHINE GERECHNET WERDEN SOLL, WERDEN JETZT ENTSPRE-
+    # CHENDE AKTIONEN DURCHGEFUEHRT
  if [[ $do_batch = false ]]
  then
@@ -2588,4 +2865,5 @@
           [[ "$module_calls" != "" ]]  &&  eval $module_calls
           make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
+
        fi
 
