Subversion Repositories lagranto.um

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
#!/bin/csh
2
 
15 michaesp 3
# Set Lagranto 
4
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
5
 
3 michaesp 6
# Set some parameters
7
set crifile=${PWD}/select.parsed
8
 
9
# Set base directories (run+prog)
10
set cdfdir=${PWD}
11
set tradir=${PWD}
12
 
13
# Write usage information
14
if ( ${#argv} ==  0 ) then
15
  echo " -------------------------------------------------------------------------------------" 
16
  echo "Usage: select <input> <output> <criterion> [optional flags]"
17
  echo 
18
  echo "Criterion structure: Command:Variable(VMode):Parameters:Times(TMode)"
19
  echo
20
  echo "     Command:    GT, LT, EQ, IN, OUT"
21
  echo "     Variable:   Name as in LSL header"
22
  echo "     VMode:      VALUE, MEAN, MAX, MIN, SUM"
23
  echo "     Parameters: Comma separated list"
24
  echo "     Times:      FIRST, LAST, Explicit values (separated with , or -)"
25
  echo "     TMode:      ALL, ANY, NONE"
26
  echo
27
  echo "Criterion examples:"
28
  echo
29
  echo "     GT:PV:2.:ALL            : PV at all times greater than 2"
30
  echo "     LT:PV:2.:FIRST          : PV at first time less than 2"
31
  echo "     IN:LAT:10,15:18,24      : Latitude within 10 and 15 N at time 18 and 24"
32
  echo "     EQ:LAT:10:18,24(ANY)    : Latitude equal to 10 N at time 18 or 24"
33
  echo "     EQ:LAT:10:18,24(NONE)   : Latitude equal to 10 N neither at time 18 or 24"
34
  echo "     OUT:LON:10,15:0-24(ALL) : Longitude outside 10 to 15 E for all times from 0 to 24"
35
  echo "     LT:PV(SUM):5:ALL        : Sum over all PV values less than 5 pvu"
36
  echo 
37
  echo "Logical operators examples:"
38
  echo
39
  echo "     GT:LAT:30:ALL & LT:LON:15:ALL : Logical AND"
40
  echo "     GT:LAT:30:ALL | LT:LON:15:ALL : Logical OR"
41
  echo 
42
  echo "Optional flags:"
43
  echo
44
  echo "     -noclean      : Keep temporary files  for debugging)"
45
  echo "     -boolean      : Output as boolean (0/1) list"
46
  echo "     -index        : Output as index (1...ntra) list"
47
  echo "     -startf       : Write onlay starting positions of selected trajectories"
48
  echo "     -regionf file : Name of the region file"
49
  echo "     -trigger      : Flag whether a trigger column should be added to the trajectory"
50
  echo "-------------------------------------------------------------------------------------"  
51
exit 1
52
endif
53
 
54
# Write list of special selection criteria
55
if ( "$1" == "-special" ) then
56
    grep '%)' ${LAGRANTO}/select/special.f
57
    exit 0
58
endif
59
 
60
# Write title
61
echo 
62
echo '========================================================='
63
echo '       *** START OF PREPROCESSOR SELECT ***              '
64
echo
65
 
66
# Save input arguments
67
set inpfile=$1
68
set outfile=$2
69
set crit="$3"
70
shift
71
shift
72
shift
73
 
74
# Handle optional arguments
75
echo
76
echo '---- OPTIONAL FLAGS -------------------------------------'
77
echo  
78
 
79
set noclean = 'false'
80
set format  = 'trajectory'
81
set regionf = 'regionf'
82
set trigger = 'nil'
83
 
84
while ( $#argv > 0 )
85
 
86
  switch ( $argv[1] )
87
 
88
   case -noclean
89
     set noclean = 'true'
90
     echo "noclean       -> true (user defined)"
91
   breaksw
92
 
93
   case -trigger
94
     set trigger = '-trigger'
95
     echo "trigger      ->  true (user defined)"
96
   breaksw
97
 
98
   case -boolean
99
     set format = 'boolean'
100
     echo "format       ->  boolean (user defined)"
101
   breaksw
102
 
103
   case -index
104
     set format = 'index'
105
     echo "format       ->  index (user defined)"
106
   breaksw
107
 
108
   case -count
109
     set format = 'count'
110
     echo "format       ->  count (user defined)"
111
   breaksw
112
 
113
   case -startf
114
     set format = 'startf'
115
     echo "format       ->  startf (user defined)"
116
   breaksw
117
 
118
   case -regionf
119
     set regionf = $argv[2]
120
     echo "regionf                -> ${regionf} (user defined)"
121
     shift;
122
   breaksw
123
 
124
  endsw
125
 
126
  shift;
127
 
128
end
129
 
130
# Decide whether <select> is a file or an explicit criterion
131
set flag_select = 'criterion'
132
set test = `echo ${crit} | grep ':' | wc -c`
133
if ( "${test}" == "0" ) then 
134
  set flag_select     = 'file'
135
  set flag_selectfile = $crit
136
  if ( -f ${flag_selectfile} ) then 
137
     set crit             = `cat ${flag_selectfile}`
138
  else
139
     echo " ERROR: criterion file ${flag_selectfile} is missing... Stop"
140
     exit 1
141
  endif
142
endif
143
 
144
# Get the start, end and reference date for the tracing
145
set ntra      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntra`
146
set ntim      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntim`
147
set ncol      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ncol`
148
set times     =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} times`
149
set vars      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} vars`
150
 
151
# Split the criterion into subunits (with Perl)
152
${LAGRANTO}/select/select.perl "${crit}" >! ${crifile} 
153
if ( "${status}" != "0" ) then
154
     echo "ERROR:  Parser <select> failed"
155
     exit 1
156
endif
157
 
158
# Write some status information
159
echo
160
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
161
echo    
162
echo "CDF directory         : ${cdfdir}"
163
echo "TRA directory         : ${tradir}"
164
echo "PROGRAM SELECT        : ${LAGRANTO}/select/select"
165
echo "PARSER                : ${LAGRANTO}/select/select.perl"
166
echo "CRITERION FILE        : ${crifile}"
167
echo
168
echo '---- INPUT PARAMETERS -----------------------------------'
169
echo    
170
echo "Input file            : ${inpfile}"
171
echo "Output file           : ${outfile}"
172
echo "Output format         : ${format}"
173
if ( "${flag_select}" == "criterion" ) then
174
    echo "Criterion             : ${crit}"
175
else
176
    echo "Criterion             : ${crit} (from file ${flag_selectfile})"
177
endif
178
echo
179
echo '---- INPUT FILE -----------------------------------------'
180
echo    
181
echo "# TRA                 : ${ntra}"
182
echo "# TIMES               : ${ntim}"
183
echo "# COLUMNS             : ${ncol}"
184
echo "Times                 : ${times}"
185
echo "Variables             : ${vars}"
186
echo
187
echo '---- PARSED CRITERION ------------------------------------'
188
echo 
189
cat ${crifile}
190
 
191
# Finish the preprocessor
192
echo 
193
echo '       *** END OF PREPROCESSOR SELECT ***              '
194
echo '========================================================='
195
echo
196
 
197
# Run the selection programme
198
echo \"${inpfile}\" >! select.param
199
echo \"${outfile}\" >> select.param
200
echo \"${format}\"  >> select.param
201
echo \"${crifile}\" >> select.param
202
echo ${ntra}        >> select.param
203
echo ${ntim}        >> select.param
204
echo ${ncol}        >> select.param
205
echo \"${regionf}\" >> select.param
206
echo \"${trigger}\" >> select.param
207
 
208
${LAGRANTO}/select/select
209
 
210
if ( "${status}" != "0" ) then
211
  echo "ERROR:  Program <select> failed"
212
  exit 1
213
endif
214
 
215
# Make clean
216
if ( "${noclean}" == "false" ) then
217
  \rm -f select.param
218
  \rm -f ${crifile}
219
endif
220
 
221
exit 0