source: palm/trunk/SCRIPTS/palmplot @ 548

Last change on this file since 548 was 530, checked in by heinze, 15 years ago

Bugfix concerning the treatment of special character * in NCL variables containing lists

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.9 KB
RevLine 
[513]1#!/bin/ksh
2# palmplot - script for running the NCL scripts
3# $Id: palmplot 530 2010-04-01 07:36:48Z raasch $
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
[513]16
17
18 # SHORT INTRODUCTION FOR USING THIS SCRIPT
19 if [[ "$1" = "?"  || "$1" = "--help" || "$1" = "-h" ]]
20  then
21    (printf "\n   palmplot is designed to run the NCL scripts of PALM \n"
22     printf "\n   palmplot can be called as follows:"
[529]23     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]24     printf "\n   script_identifier has to be one of the following:"
25     printf "\n    xy, xz, yz, pr, ts, sp"
26     printf "\n   in dependence of the data that wants to be plotted\n"
27     printf "\n   the further arguments control the plot"
28     printf "\n   they can also be set in the configuration file .ncl.config"
29     printf "\n   a documentation is available at $PALM_BIN/\NCL\/UserGuide_for_NCLscripts.pdf\n\n")
30     exit
31 fi
32
33
34 # DEFINITION OF VARIABLES
35 a=""
36 arg=""
[529]37 b=""
[513]38 key=""
39 script=""
40 value=""
41 CMDLINE=""
42 STRINGPARAMS=""
43 STRINGPARAMS_CO=""
44 STRINGPARAMS_CS=""
45 STRINGPARAMS_PR="" 
46 STRINGPARAMS_SP=""
47 STRINGPARAMS_TS=""
[529]48 STRINGPARAMS_VA=""
[513]49
50
51 # LIST OF THE PARAMETERS OF THE NCL SCRIPTS WHICH NCL EXPECTED TO BE STRINGS
52 # CO: PARAMETERS WHICH ARE COMMON FOR ALL NCL SCRIPTS
53 # CS: cross_sections.ncl PR: profiles.ncl SP: spectra.ncl TS: timeseries.ncl
[529]54 # VA: PARAMETERS WHICH CONTAIN LISTS OF VARIABLE NAMES
[513]55 STRINGPARAMS_CO="file_1 format_out file_out var "
56 STRINGPARAMS_CS="sort mode fill_mode unit_x unit_y unit_z vec1 vec2 plotvec"
57 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"
58 STRINGPARAMS_SP="sort unit_x unit_y"
59 STRINGPARAMS_TS="unit_t"
[529]60 STRINGPARAMS_VA="var c_var vec1 vec2 plotvec"
[513]61
62
63 # CHOICE OF THE PARTICULAR NCL SCRIPT
64 if [[ "$1" == "xy" ]]
65  then
66    script="cross_sections.ncl"
67    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS
68    CMDLINE="xyc=1 "
69  elif [[ "$1" == "xz" ]]
70    then
71    script="cross_sections.ncl"
72    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS
73    CMDLINE="xzc=1 "
74  elif [[ "$1" == "yz" ]]
75    then
76    script="cross_sections.ncl"
77    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_CS
78    CMDLINE="yzc=1 "
79  elif [[ "$1" == "pr" ]]
80    then
81    script="profiles.ncl"
82    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_PR
83  elif [[ "$1" == "ts" ]]
84    then
85    script="timeseries.ncl"
86    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_TS
87  elif [[ "$1" == "sp" ]]
88    then
89    script="spectra.ncl"
90    STRINGPARAMS=$STRINGPARAMS_CO$STRINGPARAMS_SP
91   else
92     (printf "\n  first argument has to be one of the following:"
93      printf "\n   xy, xz, yz, pr, ts or sp \n" 
94      printf "\n  type \"palmplot ?\" for information about the usage of this script\n")
95     exit
96 fi
97
98 # SHIFTING THE FIRST COMMAND LINE ARGUMENT
99 shift 
100
101 # PROCESSING THE COMMAND LINE ARGUMENTS
102 while [ $# -gt 0 ] 
103 do
104    arg=$1
105    key=${arg%%=*}
106    value=${arg#*=}
[529]107
[513]108    # ALLOWING RELATIVE AND ABSOLUTE FILE PATHS
109    if [[ "$key" ==  @(file_*) && "$value" != @(~/*|/*) ]]
110    then
111       value=$PWD/$value
112    fi
113     
[526]114    # PROCESSING STRINGS
[513]115    for a in $STRINGPARAMS
116    do
117      if [ "$key" = "$a" ]
118      then
[529]119
120         # PROCESSING STRINGS CONTAINING LISTS OF VARIABLES
121         for b in $STRINGPARAMS_VA
122         do
123           if [ "$key" = "$b" ]
124           then
125              if [[ "$value" != "all" ]]
126              then
127                 # SUBSTITUTING BLANKS WITH COMMAS IN
128                 # PARAMETERS CONTAINING LISTS OF VARIABLES
[530]129                 value=`echo $value | sed 's/ /,/g'`   
130                 
131                 # ALLOWING THE USAGE OF COMMA SEPARATED LIST AS WELL         
[529]132                 if [[ "$value" == ${value#,} ]]
133                 then
134                    value=,$value
135                 fi
136                 if [[ "$value" == ${value%,} ]]
137                 then
138                    value=$value,
[530]139                 fi             
140                 value=${value/%\*,,/\*,}                 
141
[529]142                 break
143              fi
144           fi
145         done
146
[526]147         # SUBSTITUTING DOUBLE QUOTES - REQUIRED BY NCL
148         value=`echo $value | sed 's/\"/\"+dq+\"/g'`
149         # SETTING ENTIRE STRING IN DOUBLE QUOTES - REQUIRED BY NCL
[513]150         value=\"$value\"
151      fi
152    done
153
154    CMDLINE+="$key=$value "
155    shift
156 done
157
158 # EXECUTING THE PARTICULAR NCL SCRIPT
159 cd $PALM_BIN/NCL
[526]160 ncl 'dq=str_get_dq()' $script $CMDLINE 
[513]161
162
163
164
165
166
Note: See TracBrowser for help on using the repository browser.