[513] | 1 | #!/bin/ksh |
---|
| 2 | # palmplot - script for running the NCL scripts |
---|
| 3 | # $Id: palmplot 566 2010-09-30 13:37:58Z suehring $ |
---|
| 4 | |
---|
| 5 | # Using the available NCL scripts via the shell script palmplot |
---|
| 6 | |
---|
| 7 | # Last changes |
---|
| 8 | # 16/03/10 - Rieke - initial revision |
---|
[526] | 9 | # 30/03/10 - Rieke - substituting double quotes (") with a character |
---|
| 10 | # variable (dq) containing double quotes |
---|
[529] | 11 | # 31/03/10 - Rieke - list of variable names can be specified using |
---|
| 12 | # blank separated lists instead of comma |
---|
| 13 | # separated lists |
---|
[530] | 14 | # 01/04/10 - Rieke - bugfix - treatment of special character * |
---|
| 15 | # in NCL variables containing lists corrected |
---|
[566] | 16 | # 23/08/10 - Rieke - bugfix - "" had to be added in if-queries |
---|
| 17 | # 30/09/10 - Rieke - Link to new online documentation of PALM NCL scripts |
---|
[513] | 18 | |
---|
| 19 | |
---|
| 20 | # SHORT INTRODUCTION FOR USING THIS SCRIPT |
---|
| 21 | if [[ "$1" = "?" || "$1" = "--help" || "$1" = "-h" ]] |
---|
| 22 | then |
---|
| 23 | (printf "\n palmplot is designed to run the NCL scripts of PALM \n" |
---|
| 24 | printf "\n palmplot can be called as follows:" |
---|
[529] | 25 | printf "\n palmplot script_identifier file_1=OUTPUT/test.nc file_out=test format_out=pdf var='pt w\"pt\" w*pt* u' no_rows=2 ...\n" |
---|
[513] | 26 | printf "\n script_identifier has to be one of the following:" |
---|
| 27 | printf "\n xy, xz, yz, pr, ts, sp" |
---|
[566] | 28 | printf "\n in dependence on the data that wants to be plotted\n" |
---|
[513] | 29 | printf "\n the further arguments control the plot" |
---|
| 30 | printf "\n they can also be set in the configuration file .ncl.config" |
---|
[566] | 31 | printf "\n a documentation is available at" |
---|
| 32 | printf "\n http://palm.muk.uni-hannover.de/wiki/doc/app/ncl \n\n") |
---|
[513] | 33 | exit |
---|
| 34 | fi |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | # DEFINITION OF VARIABLES |
---|
| 38 | a="" |
---|
| 39 | arg="" |
---|
[529] | 40 | b="" |
---|
[513] | 41 | key="" |
---|
| 42 | script="" |
---|
| 43 | value="" |
---|
| 44 | CMDLINE="" |
---|
| 45 | STRINGPARAMS="" |
---|
| 46 | STRINGPARAMS_CO="" |
---|
| 47 | STRINGPARAMS_CS="" |
---|
| 48 | STRINGPARAMS_PR="" |
---|
| 49 | STRINGPARAMS_SP="" |
---|
| 50 | STRINGPARAMS_TS="" |
---|
[529] | 51 | STRINGPARAMS_VA="" |
---|
[513] | 52 | |
---|
| 53 | |
---|
| 54 | # LIST OF THE PARAMETERS OF THE NCL SCRIPTS WHICH NCL EXPECTED TO BE STRINGS |
---|
| 55 | # CO: PARAMETERS WHICH ARE COMMON FOR ALL NCL SCRIPTS |
---|
| 56 | # CS: cross_sections.ncl PR: profiles.ncl SP: spectra.ncl TS: timeseries.ncl |
---|
[529] | 57 | # VA: PARAMETERS WHICH CONTAIN LISTS OF VARIABLE NAMES |
---|
[513] | 58 | STRINGPARAMS_CO="file_1 format_out file_out var " |
---|
| 59 | STRINGPARAMS_CS="sort mode fill_mode unit_x unit_y unit_z vec1 vec2 plotvec" |
---|
| 60 | STRINGPARAMS_PR="file_2 file_3 file_4 file_5 file_6 name_legend_1 name_legend_2 name_legend_3 name_legend_4 name_legend_5 name_legend_6 c_var" |
---|
| 61 | STRINGPARAMS_SP="sort unit_x unit_y" |
---|
| 62 | STRINGPARAMS_TS="unit_t" |
---|
[529] | 63 | STRINGPARAMS_VA="var c_var vec1 vec2 plotvec" |
---|
[513] | 64 | |
---|
| 65 | |
---|
| 66 | # CHOICE OF THE PARTICULAR NCL SCRIPT |
---|
| 67 | if [[ "$1" == "xy" ]] |
---|
| 68 | then |
---|
| 69 | script="cross_sections.ncl" |
---|
| 70 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 71 | CMDLINE="xyc=1 " |
---|
| 72 | elif [[ "$1" == "xz" ]] |
---|
| 73 | then |
---|
| 74 | script="cross_sections.ncl" |
---|
| 75 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 76 | CMDLINE="xzc=1 " |
---|
| 77 | elif [[ "$1" == "yz" ]] |
---|
| 78 | then |
---|
| 79 | script="cross_sections.ncl" |
---|
| 80 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 81 | CMDLINE="yzc=1 " |
---|
| 82 | elif [[ "$1" == "pr" ]] |
---|
| 83 | then |
---|
| 84 | script="profiles.ncl" |
---|
| 85 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_PR |
---|
| 86 | elif [[ "$1" == "ts" ]] |
---|
| 87 | then |
---|
| 88 | script="timeseries.ncl" |
---|
| 89 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_TS |
---|
| 90 | elif [[ "$1" == "sp" ]] |
---|
| 91 | then |
---|
| 92 | script="spectra.ncl" |
---|
| 93 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_SP |
---|
| 94 | else |
---|
| 95 | (printf "\n first argument has to be one of the following:" |
---|
| 96 | printf "\n xy, xz, yz, pr, ts or sp \n" |
---|
| 97 | printf "\n type \"palmplot ?\" for information about the usage of this script\n") |
---|
| 98 | exit |
---|
| 99 | fi |
---|
| 100 | |
---|
| 101 | # SHIFTING THE FIRST COMMAND LINE ARGUMENT |
---|
| 102 | shift |
---|
| 103 | |
---|
| 104 | # PROCESSING THE COMMAND LINE ARGUMENTS |
---|
| 105 | while [ $# -gt 0 ] |
---|
| 106 | do |
---|
| 107 | arg=$1 |
---|
| 108 | key=${arg%%=*} |
---|
| 109 | value=${arg#*=} |
---|
[529] | 110 | |
---|
[513] | 111 | # ALLOWING RELATIVE AND ABSOLUTE FILE PATHS |
---|
| 112 | if [[ "$key" == @(file_*) && "$value" != @(~/*|/*) ]] |
---|
| 113 | then |
---|
| 114 | value=$PWD/$value |
---|
| 115 | fi |
---|
| 116 | |
---|
[526] | 117 | # PROCESSING STRINGS |
---|
[513] | 118 | for a in $STRINGPARAMS |
---|
| 119 | do |
---|
| 120 | if [ "$key" = "$a" ] |
---|
| 121 | then |
---|
[529] | 122 | |
---|
| 123 | # PROCESSING STRINGS CONTAINING LISTS OF VARIABLES |
---|
| 124 | for b in $STRINGPARAMS_VA |
---|
| 125 | do |
---|
| 126 | if [ "$key" = "$b" ] |
---|
| 127 | then |
---|
| 128 | if [[ "$value" != "all" ]] |
---|
| 129 | then |
---|
| 130 | # SUBSTITUTING BLANKS WITH COMMAS IN |
---|
| 131 | # PARAMETERS CONTAINING LISTS OF VARIABLES |
---|
[530] | 132 | value=`echo $value | sed 's/ /,/g'` |
---|
[549] | 133 | # ALLOWING THE USAGE OF COMMA SEPARATED LIST AS WELL |
---|
| 134 | |
---|
| 135 | if [[ "$value" == "${value#,}" ]] |
---|
[529] | 136 | then |
---|
| 137 | value=,$value |
---|
| 138 | fi |
---|
[549] | 139 | if [[ "$value" == "${value%,}" ]] |
---|
[529] | 140 | then |
---|
| 141 | value=$value, |
---|
[549] | 142 | fi |
---|
[530] | 143 | value=${value/%\*,,/\*,} |
---|
[529] | 144 | break |
---|
| 145 | fi |
---|
| 146 | fi |
---|
| 147 | done |
---|
| 148 | |
---|
[526] | 149 | # SUBSTITUTING DOUBLE QUOTES - REQUIRED BY NCL |
---|
| 150 | value=`echo $value | sed 's/\"/\"+dq+\"/g'` |
---|
| 151 | # SETTING ENTIRE STRING IN DOUBLE QUOTES - REQUIRED BY NCL |
---|
[513] | 152 | value=\"$value\" |
---|
| 153 | fi |
---|
| 154 | done |
---|
| 155 | |
---|
| 156 | CMDLINE+="$key=$value " |
---|
| 157 | shift |
---|
| 158 | done |
---|
| 159 | |
---|
| 160 | # EXECUTING THE PARTICULAR NCL SCRIPT |
---|
| 161 | cd $PALM_BIN/NCL |
---|
[526] | 162 | ncl 'dq=str_get_dq()' $script $CMDLINE |
---|
[513] | 163 | |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | |
---|