[513] | 1 | #!/bin/ksh |
---|
[1046] | 2 | #--------------------------------------------------------------------------------# |
---|
| 3 | # This file is part of PALM. |
---|
| 4 | # |
---|
| 5 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | # either version 3 of the License, or (at your option) any later version. |
---|
| 8 | # |
---|
| 9 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | # |
---|
| 13 | # You should have received a copy of the GNU General Public License along with |
---|
| 14 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | # |
---|
[1310] | 16 | # Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1046] | 17 | #--------------------------------------------------------------------------------# |
---|
| 18 | # |
---|
| 19 | # Current revisions: |
---|
| 20 | # ----------------- |
---|
| 21 | # |
---|
| 22 | # Former revisions: |
---|
| 23 | # ----------------- |
---|
[513] | 24 | # $Id: palmplot 1310 2014-03-14 08:01:56Z raasch $ |
---|
[1047] | 25 | # |
---|
| 26 | # 1046 2012-11-09 14:38:45Z maronga |
---|
| 27 | # code put under GPL (PALM 3.9) |
---|
| 28 | # |
---|
[1046] | 29 | # palmplot - script for running the NCL scripts |
---|
[513] | 30 | # Using the available NCL scripts via the shell script palmplot |
---|
| 31 | |
---|
| 32 | # Last changes |
---|
| 33 | # 16/03/10 - Rieke - initial revision |
---|
[526] | 34 | # 30/03/10 - Rieke - substituting double quotes (") with a character |
---|
| 35 | # variable (dq) containing double quotes |
---|
[529] | 36 | # 31/03/10 - Rieke - list of variable names can be specified using |
---|
| 37 | # blank separated lists instead of comma |
---|
| 38 | # separated lists |
---|
[530] | 39 | # 01/04/10 - Rieke - bugfix - treatment of special character * |
---|
| 40 | # in NCL variables containing lists corrected |
---|
[566] | 41 | # 23/08/10 - Rieke - bugfix - "" had to be added in if-queries |
---|
| 42 | # 30/09/10 - Rieke - Link to new online documentation of PALM NCL scripts |
---|
[776] | 43 | # 31/10/11 - Rieke - Adjustement so that palmplot also works on |
---|
| 44 | # DKRZ (ibmh) |
---|
[513] | 45 | |
---|
| 46 | |
---|
| 47 | # SHORT INTRODUCTION FOR USING THIS SCRIPT |
---|
| 48 | if [[ "$1" = "?" || "$1" = "--help" || "$1" = "-h" ]] |
---|
| 49 | then |
---|
| 50 | (printf "\n palmplot is designed to run the NCL scripts of PALM \n" |
---|
| 51 | printf "\n palmplot can be called as follows:" |
---|
[529] | 52 | 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] | 53 | printf "\n script_identifier has to be one of the following:" |
---|
| 54 | printf "\n xy, xz, yz, pr, ts, sp" |
---|
[566] | 55 | printf "\n in dependence on the data that wants to be plotted\n" |
---|
[513] | 56 | printf "\n the further arguments control the plot" |
---|
| 57 | printf "\n they can also be set in the configuration file .ncl.config" |
---|
[566] | 58 | printf "\n a documentation is available at" |
---|
| 59 | printf "\n http://palm.muk.uni-hannover.de/wiki/doc/app/ncl \n\n") |
---|
[513] | 60 | exit |
---|
| 61 | fi |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | # DEFINITION OF VARIABLES |
---|
| 65 | a="" |
---|
| 66 | arg="" |
---|
[529] | 67 | b="" |
---|
[513] | 68 | key="" |
---|
| 69 | script="" |
---|
| 70 | value="" |
---|
| 71 | CMDLINE="" |
---|
| 72 | STRINGPARAMS="" |
---|
| 73 | STRINGPARAMS_CO="" |
---|
| 74 | STRINGPARAMS_CS="" |
---|
| 75 | STRINGPARAMS_PR="" |
---|
| 76 | STRINGPARAMS_SP="" |
---|
| 77 | STRINGPARAMS_TS="" |
---|
[529] | 78 | STRINGPARAMS_VA="" |
---|
[513] | 79 | |
---|
| 80 | |
---|
| 81 | # LIST OF THE PARAMETERS OF THE NCL SCRIPTS WHICH NCL EXPECTED TO BE STRINGS |
---|
| 82 | # CO: PARAMETERS WHICH ARE COMMON FOR ALL NCL SCRIPTS |
---|
| 83 | # CS: cross_sections.ncl PR: profiles.ncl SP: spectra.ncl TS: timeseries.ncl |
---|
[529] | 84 | # VA: PARAMETERS WHICH CONTAIN LISTS OF VARIABLE NAMES |
---|
[513] | 85 | STRINGPARAMS_CO="file_1 format_out file_out var " |
---|
| 86 | STRINGPARAMS_CS="sort mode fill_mode unit_x unit_y unit_z vec1 vec2 plotvec" |
---|
| 87 | 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" |
---|
| 88 | STRINGPARAMS_SP="sort unit_x unit_y" |
---|
| 89 | STRINGPARAMS_TS="unit_t" |
---|
[529] | 90 | STRINGPARAMS_VA="var c_var vec1 vec2 plotvec" |
---|
[513] | 91 | |
---|
| 92 | |
---|
| 93 | # CHOICE OF THE PARTICULAR NCL SCRIPT |
---|
| 94 | if [[ "$1" == "xy" ]] |
---|
| 95 | then |
---|
| 96 | script="cross_sections.ncl" |
---|
| 97 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 98 | CMDLINE="xyc=1 " |
---|
| 99 | elif [[ "$1" == "xz" ]] |
---|
| 100 | then |
---|
| 101 | script="cross_sections.ncl" |
---|
| 102 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 103 | CMDLINE="xzc=1 " |
---|
| 104 | elif [[ "$1" == "yz" ]] |
---|
| 105 | then |
---|
| 106 | script="cross_sections.ncl" |
---|
| 107 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 108 | CMDLINE="yzc=1 " |
---|
| 109 | elif [[ "$1" == "pr" ]] |
---|
| 110 | then |
---|
| 111 | script="profiles.ncl" |
---|
| 112 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_PR |
---|
| 113 | elif [[ "$1" == "ts" ]] |
---|
| 114 | then |
---|
| 115 | script="timeseries.ncl" |
---|
| 116 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_TS |
---|
| 117 | elif [[ "$1" == "sp" ]] |
---|
| 118 | then |
---|
| 119 | script="spectra.ncl" |
---|
| 120 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_SP |
---|
| 121 | else |
---|
| 122 | (printf "\n first argument has to be one of the following:" |
---|
| 123 | printf "\n xy, xz, yz, pr, ts or sp \n" |
---|
| 124 | printf "\n type \"palmplot ?\" for information about the usage of this script\n") |
---|
| 125 | exit |
---|
| 126 | fi |
---|
| 127 | |
---|
| 128 | # SHIFTING THE FIRST COMMAND LINE ARGUMENT |
---|
| 129 | shift |
---|
| 130 | |
---|
| 131 | # PROCESSING THE COMMAND LINE ARGUMENTS |
---|
| 132 | while [ $# -gt 0 ] |
---|
| 133 | do |
---|
| 134 | arg=$1 |
---|
| 135 | key=${arg%%=*} |
---|
| 136 | value=${arg#*=} |
---|
[529] | 137 | |
---|
[513] | 138 | # ALLOWING RELATIVE AND ABSOLUTE FILE PATHS |
---|
| 139 | if [[ "$key" == @(file_*) && "$value" != @(~/*|/*) ]] |
---|
| 140 | then |
---|
| 141 | value=$PWD/$value |
---|
| 142 | fi |
---|
| 143 | |
---|
[526] | 144 | # PROCESSING STRINGS |
---|
[513] | 145 | for a in $STRINGPARAMS |
---|
| 146 | do |
---|
| 147 | if [ "$key" = "$a" ] |
---|
| 148 | then |
---|
[529] | 149 | |
---|
| 150 | # PROCESSING STRINGS CONTAINING LISTS OF VARIABLES |
---|
| 151 | for b in $STRINGPARAMS_VA |
---|
| 152 | do |
---|
| 153 | if [ "$key" = "$b" ] |
---|
| 154 | then |
---|
| 155 | if [[ "$value" != "all" ]] |
---|
| 156 | then |
---|
| 157 | # SUBSTITUTING BLANKS WITH COMMAS IN |
---|
| 158 | # PARAMETERS CONTAINING LISTS OF VARIABLES |
---|
[530] | 159 | value=`echo $value | sed 's/ /,/g'` |
---|
[549] | 160 | # ALLOWING THE USAGE OF COMMA SEPARATED LIST AS WELL |
---|
| 161 | |
---|
| 162 | if [[ "$value" == "${value#,}" ]] |
---|
[529] | 163 | then |
---|
| 164 | value=,$value |
---|
| 165 | fi |
---|
[549] | 166 | if [[ "$value" == "${value%,}" ]] |
---|
[529] | 167 | then |
---|
| 168 | value=$value, |
---|
[549] | 169 | fi |
---|
[530] | 170 | value=${value/%\*,,/\*,} |
---|
[529] | 171 | break |
---|
| 172 | fi |
---|
| 173 | fi |
---|
| 174 | done |
---|
| 175 | |
---|
[526] | 176 | # SUBSTITUTING DOUBLE QUOTES - REQUIRED BY NCL |
---|
| 177 | value=`echo $value | sed 's/\"/\"+dq+\"/g'` |
---|
| 178 | # SETTING ENTIRE STRING IN DOUBLE QUOTES - REQUIRED BY NCL |
---|
[513] | 179 | value=\"$value\" |
---|
| 180 | fi |
---|
| 181 | done |
---|
| 182 | |
---|
[776] | 183 | CMDLINE=$CMDLINE"$key=$value " |
---|
[513] | 184 | shift |
---|
| 185 | done |
---|
| 186 | |
---|
| 187 | # EXECUTING THE PARTICULAR NCL SCRIPT |
---|
| 188 | cd $PALM_BIN/NCL |
---|
[526] | 189 | ncl 'dq=str_get_dq()' $script $CMDLINE |
---|
[513] | 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|