source: palm/trunk/SCRIPTS/palmplot @ 2839

Last change on this file since 2839 was 2837, checked in by gronemeier, 6 years ago

palmplot: config file of ncl scripts can be chosen in shell command

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