[513] | 1 | #!/bin/ksh |
---|
[1046] | 2 | #--------------------------------------------------------------------------------# |
---|
[2696] | 3 | # This file is part of the PALM model system. |
---|
[1046] | 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 | # |
---|
[2718] | 16 | # Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[1046] | 17 | #--------------------------------------------------------------------------------# |
---|
| 18 | # |
---|
| 19 | # Current revisions: |
---|
| 20 | # ----------------- |
---|
[2716] | 21 | # |
---|
[2845] | 22 | # |
---|
[1046] | 23 | # Former revisions: |
---|
| 24 | # ----------------- |
---|
[513] | 25 | # $Id: palmplot 2845 2018-03-01 08:32:34Z suehring $ |
---|
[2845] | 26 | # assign configuration file within palmplot call |
---|
| 27 | # |
---|
| 28 | # 2837 2018-02-26 14:04:53Z gronemeier |
---|
[2716] | 29 | # Corrected "Former revisions" section |
---|
[1047] | 30 | # |
---|
[2716] | 31 | # 2696 2017-12-14 17:12:51Z kanani |
---|
| 32 | # Change in file header (GPL part) |
---|
| 33 | # |
---|
| 34 | # 1310 2014-03-14 08:01:56Z raasch |
---|
| 35 | # update GPL copyright |
---|
| 36 | # |
---|
[1047] | 37 | # 1046 2012-11-09 14:38:45Z maronga |
---|
| 38 | # code put under GPL (PALM 3.9) |
---|
| 39 | # |
---|
[1046] | 40 | # palmplot - script for running the NCL scripts |
---|
[513] | 41 | # Using the available NCL scripts via the shell script palmplot |
---|
| 42 | |
---|
| 43 | # Last changes |
---|
| 44 | # 16/03/10 - Rieke - initial revision |
---|
[526] | 45 | # 30/03/10 - Rieke - substituting double quotes (") with a character |
---|
| 46 | # variable (dq) containing double quotes |
---|
[529] | 47 | # 31/03/10 - Rieke - list of variable names can be specified using |
---|
| 48 | # blank separated lists instead of comma |
---|
| 49 | # separated lists |
---|
[530] | 50 | # 01/04/10 - Rieke - bugfix - treatment of special character * |
---|
| 51 | # in NCL variables containing lists corrected |
---|
[566] | 52 | # 23/08/10 - Rieke - bugfix - "" had to be added in if-queries |
---|
| 53 | # 30/09/10 - Rieke - Link to new online documentation of PALM NCL scripts |
---|
[776] | 54 | # 31/10/11 - Rieke - Adjustement so that palmplot also works on |
---|
| 55 | # DKRZ (ibmh) |
---|
[513] | 56 | |
---|
| 57 | |
---|
| 58 | # SHORT INTRODUCTION FOR USING THIS SCRIPT |
---|
| 59 | if [[ "$1" = "?" || "$1" = "--help" || "$1" = "-h" ]] |
---|
| 60 | then |
---|
| 61 | (printf "\n palmplot is designed to run the NCL scripts of PALM \n" |
---|
| 62 | printf "\n palmplot can be called as follows:" |
---|
[529] | 63 | 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] | 64 | printf "\n script_identifier has to be one of the following:" |
---|
| 65 | printf "\n xy, xz, yz, pr, ts, sp" |
---|
[566] | 66 | printf "\n in dependence on the data that wants to be plotted\n" |
---|
[513] | 67 | printf "\n the further arguments control the plot" |
---|
| 68 | printf "\n they can also be set in the configuration file .ncl.config" |
---|
[566] | 69 | printf "\n a documentation is available at" |
---|
| 70 | printf "\n http://palm.muk.uni-hannover.de/wiki/doc/app/ncl \n\n") |
---|
[513] | 71 | exit |
---|
| 72 | fi |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | # DEFINITION OF VARIABLES |
---|
| 76 | a="" |
---|
| 77 | arg="" |
---|
[529] | 78 | b="" |
---|
[513] | 79 | key="" |
---|
| 80 | script="" |
---|
| 81 | value="" |
---|
| 82 | CMDLINE="" |
---|
| 83 | STRINGPARAMS="" |
---|
| 84 | STRINGPARAMS_CO="" |
---|
| 85 | STRINGPARAMS_CS="" |
---|
| 86 | STRINGPARAMS_PR="" |
---|
| 87 | STRINGPARAMS_SP="" |
---|
| 88 | STRINGPARAMS_TS="" |
---|
[529] | 89 | STRINGPARAMS_VA="" |
---|
[513] | 90 | |
---|
| 91 | |
---|
| 92 | # LIST OF THE PARAMETERS OF THE NCL SCRIPTS WHICH NCL EXPECTED TO BE STRINGS |
---|
| 93 | # CO: PARAMETERS WHICH ARE COMMON FOR ALL NCL SCRIPTS |
---|
| 94 | # CS: cross_sections.ncl PR: profiles.ncl SP: spectra.ncl TS: timeseries.ncl |
---|
[529] | 95 | # VA: PARAMETERS WHICH CONTAIN LISTS OF VARIABLE NAMES |
---|
[2837] | 96 | STRINGPARAMS_CO="file_1 format_out file_out var file_config " |
---|
[513] | 97 | STRINGPARAMS_CS="sort mode fill_mode unit_x unit_y unit_z vec1 vec2 plotvec" |
---|
| 98 | 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" |
---|
| 99 | STRINGPARAMS_SP="sort unit_x unit_y" |
---|
| 100 | STRINGPARAMS_TS="unit_t" |
---|
[529] | 101 | STRINGPARAMS_VA="var c_var vec1 vec2 plotvec" |
---|
[513] | 102 | |
---|
| 103 | |
---|
| 104 | # CHOICE OF THE PARTICULAR NCL SCRIPT |
---|
| 105 | if [[ "$1" == "xy" ]] |
---|
| 106 | then |
---|
| 107 | script="cross_sections.ncl" |
---|
| 108 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 109 | CMDLINE="xyc=1 " |
---|
| 110 | elif [[ "$1" == "xz" ]] |
---|
| 111 | then |
---|
| 112 | script="cross_sections.ncl" |
---|
| 113 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 114 | CMDLINE="xzc=1 " |
---|
| 115 | elif [[ "$1" == "yz" ]] |
---|
| 116 | then |
---|
| 117 | script="cross_sections.ncl" |
---|
| 118 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS |
---|
| 119 | CMDLINE="yzc=1 " |
---|
| 120 | elif [[ "$1" == "pr" ]] |
---|
| 121 | then |
---|
| 122 | script="profiles.ncl" |
---|
| 123 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_PR |
---|
| 124 | elif [[ "$1" == "ts" ]] |
---|
| 125 | then |
---|
| 126 | script="timeseries.ncl" |
---|
| 127 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_TS |
---|
| 128 | elif [[ "$1" == "sp" ]] |
---|
| 129 | then |
---|
| 130 | script="spectra.ncl" |
---|
| 131 | STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_SP |
---|
| 132 | else |
---|
| 133 | (printf "\n first argument has to be one of the following:" |
---|
| 134 | printf "\n xy, xz, yz, pr, ts or sp \n" |
---|
| 135 | printf "\n type \"palmplot ?\" for information about the usage of this script\n") |
---|
| 136 | exit |
---|
| 137 | fi |
---|
| 138 | |
---|
| 139 | # SHIFTING THE FIRST COMMAND LINE ARGUMENT |
---|
| 140 | shift |
---|
| 141 | |
---|
| 142 | # PROCESSING THE COMMAND LINE ARGUMENTS |
---|
| 143 | while [ $# -gt 0 ] |
---|
| 144 | do |
---|
| 145 | arg=$1 |
---|
| 146 | key=${arg%%=*} |
---|
| 147 | value=${arg#*=} |
---|
[529] | 148 | |
---|
[513] | 149 | # ALLOWING RELATIVE AND ABSOLUTE FILE PATHS |
---|
| 150 | if [[ "$key" == @(file_*) && "$value" != @(~/*|/*) ]] |
---|
| 151 | then |
---|
| 152 | value=$PWD/$value |
---|
| 153 | fi |
---|
[2837] | 154 | |
---|
| 155 | # USE CONFIG FILE SPECIFIED BY USER |
---|
| 156 | if [ "$key" = "file_config" ] |
---|
| 157 | then |
---|
| 158 | if [ -f $value ] |
---|
| 159 | then |
---|
| 160 | use_user_config=true |
---|
| 161 | else |
---|
| 162 | printf "\n configuration file \"$value\" not found." |
---|
| 163 | printf "\n trying to use one of the standard configuraion files...\n" |
---|
| 164 | fi |
---|
| 165 | fi |
---|
| 166 | |
---|
[526] | 167 | # PROCESSING STRINGS |
---|
[513] | 168 | for a in $STRINGPARAMS |
---|
| 169 | do |
---|
| 170 | if [ "$key" = "$a" ] |
---|
| 171 | then |
---|
[529] | 172 | |
---|
| 173 | # PROCESSING STRINGS CONTAINING LISTS OF VARIABLES |
---|
| 174 | for b in $STRINGPARAMS_VA |
---|
| 175 | do |
---|
| 176 | if [ "$key" = "$b" ] |
---|
| 177 | then |
---|
| 178 | if [[ "$value" != "all" ]] |
---|
| 179 | then |
---|
| 180 | # SUBSTITUTING BLANKS WITH COMMAS IN |
---|
| 181 | # PARAMETERS CONTAINING LISTS OF VARIABLES |
---|
[530] | 182 | value=`echo $value | sed 's/ /,/g'` |
---|
[549] | 183 | # ALLOWING THE USAGE OF COMMA SEPARATED LIST AS WELL |
---|
| 184 | |
---|
| 185 | if [[ "$value" == "${value#,}" ]] |
---|
[529] | 186 | then |
---|
| 187 | value=,$value |
---|
| 188 | fi |
---|
[549] | 189 | if [[ "$value" == "${value%,}" ]] |
---|
[529] | 190 | then |
---|
| 191 | value=$value, |
---|
[549] | 192 | fi |
---|
[530] | 193 | value=${value/%\*,,/\*,} |
---|
[529] | 194 | break |
---|
| 195 | fi |
---|
| 196 | fi |
---|
| 197 | done |
---|
| 198 | |
---|
[526] | 199 | # SUBSTITUTING DOUBLE QUOTES - REQUIRED BY NCL |
---|
| 200 | value=`echo $value | sed 's/\"/\"+dq+\"/g'` |
---|
| 201 | # SETTING ENTIRE STRING IN DOUBLE QUOTES - REQUIRED BY NCL |
---|
[513] | 202 | value=\"$value\" |
---|
| 203 | fi |
---|
| 204 | done |
---|
| 205 | |
---|
[776] | 206 | CMDLINE=$CMDLINE"$key=$value " |
---|
[513] | 207 | shift |
---|
| 208 | done |
---|
| 209 | |
---|
[2837] | 210 | # SET CONFIGURATION FILE TO ONE OF THE DEFAULT FILES IF NOT SPECIFIED BY USER |
---|
| 211 | if [ "$use_user_config" != true ] |
---|
| 212 | then |
---|
| 213 | key="file_config" |
---|
| 214 | |
---|
| 215 | if [ -f $PALM_BIN/../../.ncl.config ] |
---|
| 216 | then |
---|
| 217 | value="\"$PALM_BIN/../../.ncl.config\"" |
---|
| 218 | else |
---|
| 219 | value="\"$PALM_BIN/NCL/.ncl.config.default\"" |
---|
| 220 | fi |
---|
| 221 | |
---|
| 222 | CMDLINE=$CMDLINE"$key=$value " |
---|
| 223 | fi |
---|
| 224 | |
---|
[513] | 225 | # EXECUTING THE PARTICULAR NCL SCRIPT |
---|
| 226 | cd $PALM_BIN/NCL |
---|
[526] | 227 | ncl 'dq=str_get_dq()' $script $CMDLINE |
---|