Subversion Repositories lagranto.um

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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