source: palm/trunk/SCRIPTS/palmplot @ 1046

Last change on this file since 1046 was 1046, checked in by maronga, 12 years ago

put scripts and utilities under GPL

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