source: palm/trunk/SCRIPTS/palmplot @ 4443

Last change on this file since 4443 was 3202, checked in by Giersch, 6 years ago

Unix-Shell in palmplot script has been changed from ksh to bash

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