Subversion Repositories lagranto.ecmwf

Rev

Rev 39 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 46
1
#!/bin/csh
1
#!/bin/csh
2
 
2
 
3
# ---------------------------------------------------------------------
3
# ---------------------------------------------------------------------
4
# Usage, parameter settings
4
# Usage, parameter settings
5
# ---------------------------------------------------------------------
5
# ---------------------------------------------------------------------
6
 
6
 
7
# Write usage information
7
# Write usage information
8
if ( (${#argv} == 0) | (${#argv} < 2) ) then
8
if ( (${#argv} == 0) | (${#argv} < 2) ) then
9
  echo 
9
  echo 
10
  ${LAGRANTO}/bin/lagrantohelp trace short
10
  ${LAGRANTO}/bin/lagrantohelp trace short
11
  echo  
11
  echo  
12
  exit 0
12
  exit 0
13
endif
13
endif
14
 
14
 
15
# Write title
15
# Write title
16
echo 
16
echo 
17
echo '========================================================='
17
echo '========================================================='
18
echo '       *** START OF PREPROCESSOR TRACE ***              '
18
echo '       *** START OF PREPROCESSOR TRACE ***              '
19
echo
19
echo
20
 
20
 
21
# Get the arguments
21
# Get the arguments
22
set inpfile   = $1
22
set inpfile   = $1
23
set outfile   = $2
23
set outfile   = $2
24
 
24
 
25
# Set base directories (run+prog)
25
# Set base directories (run+prog)
26
set cdfdir=${PWD}
26
set cdfdir=${PWD}
27
set tradir=${PWD}
27
set tradir=${PWD}
28
 
28
 
29
# Set program paths and filenames 
29
# Set program paths and filenames 
30
set parfile = ${tradir}/trace.param 
30
set parfile = ${tradir}/trace.param 
31
set prog    = ${LAGRANTO}/trace/trace
31
set prog    = ${LAGRANTO}/trace/trace
32
 
32
 
33
# Set the prefix of the primary and secondary data files
33
# Set the prefix of the primary and secondary data files
34
set charp = 'P'
34
set charp = 'P'
35
set chars = 'S'
35
set chars = 'S'
36
 
36
 
37
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
37
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
38
echo    
38
echo    
39
echo "CDF directory         : ${cdfdir}"
39
echo "CDF directory         : ${cdfdir}"
40
echo "TRA directory         : ${tradir}"
40
echo "TRA directory         : ${tradir}"
41
echo "PROGRAM TRACE         : ${prog}"
41
echo "PROGRAM TRACE         : ${prog}"
42
echo "PARAMETER file        : ${parfile}"
42
echo "PARAMETER file        : ${parfile}"
43
echo
43
echo
44
 
44
 
45
# ---------------------------------------------------------------------
45
# ---------------------------------------------------------------------
46
# Set optional flags
46
# Set optional flags
47
# ---------------------------------------------------------------------
47
# ---------------------------------------------------------------------
48
 
48
 
49
echo '---- OPTIONAL FLAGS -------------------------------------'
49
echo '---- OPTIONAL FLAGS -------------------------------------'
50
echo
50
echo
51
 
51
 
52
# Set some default values ("nil" must be set according to input files)
52
# Set some default values ("nil" must be set according to input files)
53
set flag_i     = "nil"
53
set flag_i     = "nil"
54
set flag_v     = "tracevars"
54
set flag_v     = "tracevars"
55
set flag_f     = "nil"
55
set flag_f     = "nil"
56
set tvfile     = 'tracevars'
56
set tvfile     = 'tracevars'
57
set changet    = 'false'
57
set changet    = 'false'
58
set noclean    = 'false'
58
set noclean    = 'false'
59
set timecheck  = 'no' 
59
set timecheck  = 'no' 
60
set intmode    = 'normal'
60
set intmode    = 'normal'
61
set radius     = '0'        
61
set radius     = '0'        
62
set tropo_pv   = '2' 
62
set tropo_pv   = '2' 
63
set tropo_th   = '380'
63
set tropo_th   = '380'
64
 
64
 
65
# Set flag for consistency
65
# Set flag for consistency
66
set isok = 1
66
set isok = 1
67
 
67
 
68
while ( $#argv > 0 )
68
while ( $#argv > 0 )
69
 
69
 
70
  switch ( $argv[1] )
70
  switch ( $argv[1] )
71
 
71
 
72
   case -i
72
   case -i
73
     set flag_i=$argv[2]
73
     set flag_i=$argv[2]
74
     echo "Flag '-i'     -> ${flag_i} (user defined)"
74
     echo "Flag '-i'     -> ${flag_i} (user defined)"
75
     shift;
75
     shift;
76
   breaksw
76
   breaksw
77
 
77
 
78
   case -v
78
   case -v
79
     set flag_v="-v"
79
     set flag_v="-v"
80
     set tvfile=$argv[2]
80
     set tvfile=$argv[2]
81
     echo "Flag '-v'     -> ${tvfile} (user defined)"
81
     echo "Flag '-v'     -> ${tvfile} (user defined)"
82
     shift;
82
     shift;
83
     if ( $isok == 2 ) set isok = 0
83
     if ( $isok == 2 ) set isok = 0
84
     if ( $isok == 1 ) set isok = 2
84
     if ( $isok == 1 ) set isok = 2
85
   breaksw
85
   breaksw
86
 
86
 
87
   case -f
87
   case -f
88
     set flag_f="-f"
88
     set flag_f="-f"
89
     set tvfile="tracevars.tmp"
89
     set tvfile="tracevars.tmp"
90
     shift;
90
     shift;
91
     set tvar="$argv[1]"
91
     set tvar="$argv[1]"
92
     shift;
92
     shift;
93
     set tscale="$argv[1]"
93
     set tscale="$argv[1]"
94
     echo "Flag '-f'     -> ${tvar} ${tscale} (user defined)"
94
     echo "Flag '-f'     -> ${tvar} ${tscale} (user defined)"
95
     if ( $isok == 2 ) set isok = 0
95
     if ( $isok == 2 ) set isok = 0
96
     if ( $isok == 1 ) set isok = 2
96
     if ( $isok == 1 ) set isok = 2
97
   breaksw
97
   breaksw
98
 
98
 
99
   case -changet
99
   case -changet
100
     set changet = 'true'
100
     set changet = 'true'
101
     echo "changet       -> true (user defined)"
101
     echo "changet       -> true (user defined)"
102
   breaksw
102
   breaksw
103
 
103
 
104
   case -noclean
104
   case -noclean
105
     set noclean = 'true'
105
     set noclean = 'true'
106
     echo "noclean       -> true (user defined)"
106
     echo "noclean       -> true (user defined)"
107
   breaksw
107
   breaksw
108
 
108
 
109
   case -timecheck
109
   case -timecheck
110
     set timecheck = 'yes'
110
     set timecheck = 'yes'
111
     echo "timecheck               -> yes (user defined)"
111
     echo "timecheck               -> yes (user defined)"
112
   breaksw
112
   breaksw
113
 
113
 
114
   case -nearest
114
   case -nearest
115
     set intmode = 'nearest'
115
     set intmode = 'nearest'
116
     echo "intmode                 -> nearest (user defined)"
116
     echo "intmode                 -> nearest (user defined)"
117
   breaksw
117
   breaksw
118
 
118
 
119
   case -clustering
119
   case -clustering
120
     set intmode = 'clustering'
120
     set intmode = 'clustering'
121
     echo "intmode                 -> clustering (user defined)"
121
     echo "intmode                 -> clustering (user defined)"
122
     shift;
122
     shift;
123
     if ( "$1" == "" ) then
123
     if ( "$1" == "" ) then
124
        echo "ERROR (clustering): specify tropopause PV [pvu] and TH [K]! Example: -clustering 2 380"
124
        echo "ERROR (clustering): specify tropopause PV [pvu] and TH [K]! Example: -clustering 2 380"
125
        exit
125
        exit
126
     else
126
     else
127
        set tropo_pv = $1
127
        set tropo_pv = $1
128
     endif
128
     endif
129
     shift;
129
     shift;
130
     if ( "$1" == "" ) then
130
     if ( "$1" == "" ) then
131
        echo "ERROR (clustering): specify tropopause PV [pvu] and TH [K]! Example: -clustering 2 380"
131
        echo "ERROR (clustering): specify tropopause PV [pvu] and TH [K]! Example: -clustering 2 380"
132
        exit
132
        exit
133
     else
133
     else
134
        set tropo_th = $1
134
        set tropo_th = $1
135
        echo 'intmode                 -> clustering tropo_pv = ' ${tropo_pv} 'pvu and tropo_th = ' ${tropo_th} 'K'
135
        echo 'intmode                 -> clustering tropo_pv = ' ${tropo_pv} 'pvu and tropo_th = ' ${tropo_th} 'K'
136
     endif
136
     endif
137
   breaksw
137
   breaksw
138
 
138
 
139
   case -circle_avg
139
   case -circle_avg
140
     set intmode = 'circle_avg'
140
     set intmode = 'circle_avg'
141
     echo "intmode                 -> circle_avg (user defined)"
141
     echo "intmode                 -> circle_avg (user defined)"
142
     shift;
142
     shift;
143
     if ( "$1" == "" ) then
143
     if ( "$1" == "" ) then
144
        echo "ERROR (circle_avg): specify radius in circle mode (km)! Example: -circle_avg 500"
144
        echo "ERROR (circle_avg): specify radius in circle mode (km)! Example: -circle_avg 500"
145
        exit
145
        exit
146
     else
146
     else
147
        set radius = $1
147
        set radius = $1
148
        echo 'intmode                 -> circle_avg radius =' ${radius} 'km'
148
        echo 'intmode                 -> circle_avg radius =' ${radius} 'km'
149
     endif
149
     endif
150
   breaksw
150
   breaksw
151
 
151
 
152
   case -circle_min
152
   case -circle_min
153
     set intmode = 'circle_min'
153
     set intmode = 'circle_min'
154
     echo "intmode                 -> circle_min (user defined)"
154
     echo "intmode                 -> circle_min (user defined)"
155
     shift;
155
     shift;
156
     if ( "$1" == "" ) then
156
     if ( "$1" == "" ) then
157
        echo "ERROR (circle_min): specify radius in circle mode (km)! Example: -circle_min 400"
157
        echo "ERROR (circle_min): specify radius in circle mode (km)! Example: -circle_min 400"
158
        exit
158
        exit
159
     else
159
     else
160
        set radius = $1
160
        set radius = $1
161
        echo 'intmode                 -> circle_min radius =' ${radius} 'km'
161
        echo 'intmode                 -> circle_min radius =' ${radius} 'km'
162
     endif
162
     endif
163
   breaksw
163
   breaksw
164
 
164
 
165
   case -circle_max
165
   case -circle_max
166
     set intmode = 'circle_max'
166
     set intmode = 'circle_max'
167
     echo "intmode                 -> circle_max (user defined)"
167
     echo "intmode                 -> circle_max (user defined)"
168
     shift;
168
     shift;
169
     if ( "$1" == "" ) then
169
     if ( "$1" == "" ) then
170
        echo "ERROR (circle_max): specify radius in circle mode (km)! Example: -circle_max 600"
170
        echo "ERROR (circle_max): specify radius in circle mode (km)! Example: -circle_max 600"
171
        exit
171
        exit
172
     else
172
     else
173
        set radius = $1
173
        set radius = $1
174
        echo 'intmode                 -> circle_max radius =' ${radius} 'km'
174
        echo 'intmode                 -> circle_max radius =' ${radius} 'km'
175
     endif
175
     endif
176
 
176
 
177
   breaksw
177
   breaksw
178
   
178
   
179
  endsw
179
  endsw
180
 
180
 
181
  shift;
181
  shift;
182
 
182
 
183
end
183
end
184
 
184
 
185
# No change of times necessary if no check requested
185
# No change of times necessary if no check requested
186
if ( "${timecheck}" == "no" ) then
186
if ( "${timecheck}" == "no" ) then
187
   set  changet = 'false'
187
   set  changet = 'false'
188
endif
188
endif
189
 
189
 
190
# Check consitency of arguments
190
# Check consitency of arguments
191
if ( $isok == 0 ) then
191
if ( $isok == 0 ) then
192
    echo
192
    echo
193
    echo " ERROR: Use either option '-v' or '-f', but not both..."
193
    echo " ERROR: Use either option '-v' or '-f', but not both..."
194
    exit 1
194
    exit 1
195
endif
195
endif
196
 
196
 
197
# ---------------------------------------------------------------------
197
# ---------------------------------------------------------------------
198
# Handle the input trajectory file
198
# Handle the input trajectory file
199
# ---------------------------------------------------------------------
199
# ---------------------------------------------------------------------
200
 
200
 
201
echo
201
echo
202
echo '---- TIME RANGE -----------------------------------------'
202
echo '---- TIME RANGE -----------------------------------------'
203
echo
203
echo
204
 
204
 
205
# Check whether the input file can be found
205
# Check whether the input file can be found
206
if ( ! -f ${inpfile} ) then
206
if ( ! -f ${inpfile} ) then
207
    echo " ERROR : Input file ${inpfile} is missing"
207
    echo " ERROR : Input file ${inpfile} is missing"
208
    exit 1
208
    exit 1
209
endif
209
endif
210
 
210
 
211
# Get the start, end and reference date for the tracing
211
# Get the start, end and reference date for the tracing
212
set startdate = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} startdate` 
212
set startdate = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} startdate` 
213
set enddate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} enddate` 
213
set enddate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} enddate` 
214
set refdate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} refdate` 
214
set refdate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} refdate` 
215
set ntra      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntra`
215
set ntra      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntra`
216
set ntim      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntim`
216
set ntim      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntim`
217
set ncol      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ncol`
217
set ncol      = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ncol`
218
 
218
 
219
# Check format of start and end date - must be the same
219
# Check format of start and end date - must be the same
220
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
220
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
221
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
221
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
222
if ( $ns != $ne ) then
222
if ( $ns != $ne ) then
223
  echo " ERROR: start and end date must be in the same format ***"
223
  echo " ERROR: start and end date must be in the same format ***"
224
  exit 1
224
  exit 1
225
endif
225
endif
226
if ( $ns != 9 ) then
226
if ( $ns != 9 ) then
227
  echo " ERROR: Date format must be yyyymmdd ***"
227
  echo " ERROR: Date format must be yyyymmdd ***"
228
  exit 1
228
  exit 1
229
endif
229
endif
230
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
230
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
231
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
231
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
232
if ( $ns != $ne ) then
232
if ( $ns != $ne ) then
233
  echo " ERROR: start and end date must be in the same format ***"
233
  echo " ERROR: start and end date must be in the same format ***"
234
  exit 1
234
  exit 1
235
endif
235
endif
236
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
236
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
237
  echo " ERROR: Time format must be hh(mm) ***"
237
  echo " ERROR: Time format must be hh(mm) ***"
238
  exit 1
238
  exit 1
239
endif
239
endif
240
 
240
 
241
# Split the start and end date into <yymmdd_hh and mm>
241
# Split the start and end date into <yymmdd_hh and mm>
242
set startdate_ymdh = `echo $startdate | cut -c 1-11`
242
set startdate_ymdh = `echo $startdate | cut -c 1-11`
243
set startdate_min  = `echo $startdate | cut -c 12-13`
243
set startdate_min  = `echo $startdate | cut -c 12-13`
244
if ( $startdate_min == "" ) set startdate_min = 00
244
if ( $startdate_min == "" ) set startdate_min = 00
245
 
245
 
246
set enddate_ymdh = `echo $enddate | cut -c 1-11`
246
set enddate_ymdh = `echo $enddate | cut -c 1-11`
247
set enddate_min  = `echo $enddate | cut -c 12-13`
247
set enddate_min  = `echo $enddate | cut -c 12-13`
248
if ( $enddate_min == "" ) set enddate_min = 00
248
if ( $enddate_min == "" ) set enddate_min = 00
249
 
249
 
250
# Get the time difference between <start_ymdh> and <end_ymdh> date
250
# Get the time difference between <start_ymdh> and <end_ymdh> date
251
# Decide whether trajectoriesare forward or backward
251
# Decide whether trajectoriesare forward or backward
252
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
252
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
253
 
253
 
254
if ( $timediff_hh == 0 ) then
254
if ( $timediff_hh == 0 ) then
255
  if ( $enddate_min > $startdate_min ) then
255
  if ( $enddate_min > $startdate_min ) then
256
    set direction = f
256
    set direction = f
257
    set idir      = 1
257
    set idir      = 1
258
  else
258
  else
259
    set direction = b
259
    set direction = b
260
    set idir      = -1
260
    set idir      = -1
261
  endif
261
  endif
262
else if ( $timediff_hh > 0 ) then
262
else if ( $timediff_hh > 0 ) then
263
  set direction = f
263
  set direction = f
264
  set idir      = 1
264
  set idir      = 1
265
else
265
else
266
  set direction = b
266
  set direction = b
267
  set idir      = -1
267
  set idir      = -1
268
  @ timediff_hh = $idir * $timediff_hh
268
  @ timediff_hh = $idir * $timediff_hh
269
endif
269
endif
270
 
270
 
271
# Get also minutes for time difference, if <start_min> or <end_min> != 0
271
# Get also minutes for time difference, if <start_min> or <end_min> != 0
272
set timediff_mm=
272
set timediff_mm=
273
 
273
 
274
if ( $startdate_min != 00 || $enddate_min != 00 ) then
274
if ( $startdate_min != 00 || $enddate_min != 00 ) then
275
  @ min = ( $enddate_min - $startdate_min )
275
  @ min = ( $enddate_min - $startdate_min )
276
  if ( $min == 0 ) then
276
  if ( $min == 0 ) then
277
    set timediff_mm=
277
    set timediff_mm=
278
  else if ( $min > 0 ) then
278
  else if ( $min > 0 ) then
279
    if ( $idir == 1 ) then
279
    if ( $idir == 1 ) then
280
      set timediff_mm=$min
280
      set timediff_mm=$min
281
    else
281
    else
282
      @ timediff_hh --
282
      @ timediff_hh --
283
      @ timediff_mm = 60 - $min
283
      @ timediff_mm = 60 - $min
284
    endif
284
    endif
285
  else
285
  else
286
    if ( $idir == 1 ) then
286
    if ( $idir == 1 ) then
287
      @ timediff_hh --
287
      @ timediff_hh --
288
      @ timediff_mm = 60 + $min
288
      @ timediff_mm = 60 + $min
289
    else
289
    else
290
      @ timediff_mm = 0 - $min
290
      @ timediff_mm = 0 - $min
291
    endif
291
    endif
292
  endif
292
  endif
293
endif
293
endif
294
 
294
 
295
# Write status information
295
# Write status information
296
echo "Time range      : ${startdate} -> ${enddate}"
296
echo "Time range      : ${startdate} -> ${enddate}"
297
if ( ${timediff_mm} != "" ) then
297
if ( ${timediff_mm} != "" ) then
298
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
298
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
299
else
299
else
300
   echo "Time difference : ${timediff_hh} h"
300
   echo "Time difference : ${timediff_hh} h"
301
endif
301
endif
302
echo "Direction       : ${direction} (${idir})"
302
echo "Direction       : ${direction} (${idir})"
303
 
303
 
304
# ---------------------------------------------------------------------
304
# ---------------------------------------------------------------------
305
# Check availability of input data 
305
# Check availability of input data 
306
# ---------------------------------------------------------------------
306
# ---------------------------------------------------------------------
307
 
307
 
308
echo
308
echo
309
echo '---- INPUT FILES ----------------------------------------'
309
echo '---- INPUT FILES ----------------------------------------'
310
echo
310
echo
311
 
311
 
312
 
312
 
313
# Take the time increment from flag list ('nil', if not defined)
313
# Take the time increment from flag list ('nil', if not defined)
314
set timeinc = ${flag_i}
314
set timeinc = ${flag_i}
315
 
315
 
316
# Find a first data file (if possible corresponding to start/end date
316
# Find a first data file (if possible corresponding to start/end date
317
# If starttime is not a data time, take the first file in the direectory
317
# If starttime is not a data time, take the first file in the direectory
318
if ( $direction == "f" ) then
318
if ( $direction == "f" ) then
319
  set file=${charp}${startdate_ymdh}
319
  set file=${charp}${startdate_ymdh}
320
else
320
else
321
  set file=${charp}${enddate_ymdh}
321
  set file=${charp}${enddate_ymdh}
322
endif
322
endif
323
if ( ! -f $file ) then
323
if ( ! -f $file ) then
324
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
324
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
325
endif
325
endif
326
 
326
 
327
# Determine timeinc (the time difference in hours between two data file)
327
# Determine timeinc (the time difference in hours between two data file)
328
# if not already defined with option -i
328
# if not already defined with option -i
329
if ( ${timeinc} == "nil" ) then
329
if ( ${timeinc} == "nil" ) then
330
  set date1=`echo $file | cut -c 2-12`
330
  set date1=`echo $file | cut -c 2-12`
331
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
331
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
332
  @ n ++
332
  @ n ++
333
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
333
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
334
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
334
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
335
endif
335
endif
336
if ( $timeinc == 0 ) then
336
if ( $timeinc == 0 ) then
337
    echo " ERROR: cannot set the time increment between input files ***"
337
    echo " ERROR: cannot set the time increment between input files ***"
338
    exit 1
338
    exit 1
339
endif
339
endif
340
 
340
 
341
# Search the first file to use: We step through all P files and see whether they are
341
# Search the first file to use: We step through all P files and see whether they are
342
# good P files. Let's first do the test for the first data file found. If it's ok, we 
342
# good P files. Let's first do the test for the first data file found. If it's ok, we 
343
# take it; if not, we step through all P files and find the good one  
343
# take it; if not, we step through all P files and find the good one  
344
set flag=0
344
set flag=0
345
set td=
345
set td=
346
 
346
 
347
set date = `echo $file | cut -c 2-12`
347
set date = `echo $file | cut -c 2-12`
348
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
348
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
349
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
349
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
350
 
350
 
351
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
351
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
352
   set datfiles=$date
352
   set datfiles=$date
353
   if ( $td1 < $timeinc    ) set td=$td1
353
   if ( $td1 < $timeinc    ) set td=$td1
354
   if ( $td2 < $timeinc    ) set td=$td2
354
   if ( $td2 < $timeinc    ) set td=$td2
355
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
355
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
356
   goto label2      
356
   goto label2      
357
endif
357
endif
358
 
358
 
359
foreach i ( ${charp}????????_?? )
359
foreach i ( ${charp}????????_?? )
360
 
360
 
361
  set date = `echo $i | cut -c 2-12`
361
  set date = `echo $i | cut -c 2-12`
362
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
362
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
363
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
363
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
364
 
364
 
365
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
365
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
366
      set datfiles=$date
366
      set datfiles=$date
367
      if ( $td1 < $timeinc    ) set td=$td1
367
      if ( $td1 < $timeinc    ) set td=$td1
368
      if ( $td2 < $timeinc    ) set td=$td2
368
      if ( $td2 < $timeinc    ) set td=$td2
369
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
369
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
370
      goto label2
370
      goto label2
371
  endif
371
  endif
372
 
372
 
373
end
373
end
374
 
374
 
375
# if no P/T-files are available for the specified time period, then $td is
375
# if no P/T-files are available for the specified time period, then $td is
376
# still undefined
376
# still undefined
377
if ( $td == "" ) then
377
if ( $td == "" ) then
378
  echo " ERROR: no data files available for the specified time period"
378
  echo " ERROR: no data files available for the specified time period"
379
  exit 1
379
  exit 1
380
endif
380
endif
381
 
381
 
382
# Everything is fine so far: proceed
382
# Everything is fine so far: proceed
383
label2:
383
label2:
384
 
384
 
385
# Check whether first date is ok - before or at needed dates
385
# Check whether first date is ok - before or at needed dates
386
if ( $direction == "f" ) then
386
if ( $direction == "f" ) then
387
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
387
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
388
else
388
else
389
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
389
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
390
endif
390
endif
391
  if ( $tdiff0 < 0 ) then
391
  if ( $tdiff0 < 0 ) then
392
  echo " ERROR: data files missing for the specified time period"
392
  echo " ERROR: data files missing for the specified time period"
393
  exit 1
393
  exit 1
394
endif
394
endif
395
 
395
 
396
# Calculate the number of further files
396
# Calculate the number of further files
397
@ num = ( $timediff_hh + $td ) / $timeinc + 1
397
@ num = ( $timediff_hh + $td ) / $timeinc + 1
398
@ dum1 = ( $num - 1 ) * $timeinc
398
@ dum1 = ( $num - 1 ) * $timeinc
399
@ dum2 = $timediff_hh + $td
399
@ dum2 = $timediff_hh + $td
400
if ( $dum1 != $dum2 ) @ num ++
400
if ( $dum1 != $dum2 ) @ num ++
401
 
401
 
402
# Get a list of all needed files
402
# Get a list of all needed files
403
set numfiles=$num
403
set numfiles=$num
404
set sfiles=1
404
set sfiles=1
405
while ( $num > 1 )
405
while ( $num > 1 )
406
 
406
 
407
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
407
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
408
  if ( ! -f ${charp}${date} ) then
408
  if ( ! -f ${charp}${date} ) then
409
    echo " ERROR: file with primary data is missing for $date"
409
    echo " ERROR: file with primary data is missing for $date"
410
    exit 1
410
    exit 1
411
  else if ( ! -f ${chars}${date} ) then
411
  else if ( ! -f ${chars}${date} ) then
412
    set sfiles=0
412
    set sfiles=0
413
    set datfiles=`echo $datfiles $date`
413
    set datfiles=`echo $datfiles $date`
414
  else
414
  else
415
    set datfiles=`echo $datfiles $date`
415
    set datfiles=`echo $datfiles $date`
416
  endif
416
  endif
417
  @ num --
417
  @ num --
418
end
418
end
419
 
419
 
420
# Calculate the start and the end time relative to the first datfile
420
# Calculate the start and the end time relative to the first datfile
421
if ( $direction == f ) then
421
if ( $direction == f ) then
422
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
422
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
423
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
423
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
424
else
424
else
425
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
425
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
426
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
426
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
427
endif
427
endif
428
 
428
 
429
 
429
 
430
# Write some status information
430
# Write some status information
431
echo "Primary file prefix               : ${charp}"
431
echo "Primary file prefix               : ${charp}"
432
echo "Secondary file prefix             : ${chars}"
432
echo "Secondary file prefix             : ${chars}"
433
echo "Time increment for input files    : ${timeinc}"
433
echo "Time increment for input files    : ${timeinc}"
434
echo "# input files                     : ${numfiles}"
434
echo "# input files                     : ${numfiles}"
435
echo "First input file                  : $datfiles[1] " 
435
echo "First input file                  : $datfiles[1] " 
436
echo "Last input file                   : $datfiles[$numfiles] " 
436
echo "Last input file                   : $datfiles[$numfiles] " 
437
echo "${charp} files availability              : 1"  
437
echo "${charp} files availability              : 1"  
438
echo "${chars} files availability              : ${sfiles}"     
438
echo "${chars} files availability              : ${sfiles}"     
439
if ( $direction == f ) then
439
if ( $direction == f ) then
440
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
440
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
441
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
441
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
442
else
442
else
443
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
443
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
444
echo "End time relative to first file   : $datfiles[1] + ${tend} "
444
echo "End time relative to first file   : $datfiles[1] + ${tend} "
445
endif
445
endif
446
 
446
 
447
# ---------------------------------------------------------------------
447
# ---------------------------------------------------------------------
448
# Check availability of input data 
448
# Check availability of input data 
449
# ---------------------------------------------------------------------
449
# ---------------------------------------------------------------------
450
 
450
 
451
echo
451
echo
452
echo '---- TRACEVAR FILE --------------------------------------'
452
echo '---- TRACEVAR FILE --------------------------------------'
453
echo    
453
echo    
454
 
454
 
455
# If "-f" option is used, create a temporary tracevar file
455
# If "-f" option is used, create a temporary tracevar file
456
if ( "${flag_f}" == "-f" ) then
456
if ( "${flag_f}" == "-f" ) then
457
 
457
 
458
#   Preset values for <compfl> and <tprefix>
458
#   Preset values for <compfl> and <tprefix>
459
    set tcompfl=1
459
    set tcompfl=1
460
    set tprefix='P'
460
    set tprefix='P'
461
    
461
    
462
#   Check availability on P file
462
#   Check availability on P file
463
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
463
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
464
       if ( "${var}" == "${tvar}" ) then
464
       if ( "${var}" == "${tvar}" ) then
465
          set tcompfl=0
465
          set tcompfl=0
466
	  set tprefix="P"
466
	  set tprefix="P"
467
       endif
467
       endif
468
    end
468
    end
469
 
469
 
470
#   Check availability on S file 
470
#   Check availability on S file 
471
    if ( ${sfiles} == 1 ) then
471
    if ( ${sfiles} == 1 ) then
472
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
472
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
473
         if ( "${var}" == "${tvar}" ) then
473
         if ( "${var}" == "${tvar}" ) then
474
            set tcompfl=0
474
            set tcompfl=0
475
	    set tprefix="S"
475
	    set tprefix="S"
476
         endif
476
         endif
477
       end
477
       end
478
    endif
478
    endif
479
 
479
 
480
#   Write the temporary <tracevars> file
480
#   Write the temporary <tracevars> file
481
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
481
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
482
    echo "Temporary tracervar file <${tvfile}> created"
482
    echo "Temporary tracervar file <${tvfile}> created"
483
    echo
483
    echo
484
 
484
 
485
endif
485
endif
486
 
486
 
487
 
487
 
488
# Check if tracevars-file exists
488
# Check if tracevars-file exists
489
if ( ! -f $tvfile ) then
489
if ( ! -f $tvfile ) then
490
  echo  " ERROR:  file $tvfile was not found ***"
490
  echo  " ERROR:  file $tvfile was not found ***"
491
  exit 1
491
  exit 1
492
endif
492
endif
493
 
493
 
494
# check if the variables contained in the tracevars-file are available in the
494
# check if the variables contained in the tracevars-file are available in the
495
# data file and check also if there are no empty lines in the tracevars-file
495
# data file and check also if there are no empty lines in the tracevars-file
496
 
496
 
497
set nlines = `cat $tvfile | wc -l`
497
set nlines = `cat $tvfile | wc -l`
498
set vars   = `cat $tvfile | awk '{print $1}'`
498
set vars   = `cat $tvfile | awk '{print $1}'`
499
set nvars  = `echo $vars | wc -w`
499
set nvars  = `echo $vars | wc -w`
500
if ( $nlines != $nvars ) then
500
if ( $nlines != $nvars ) then
501
  echo " ERROR: tracevars-files must not contain empty lines ***"
501
  echo " ERROR: tracevars-files must not contain empty lines ***"
502
  exit 1
502
  exit 1
503
endif
503
endif
504
set calf=`cat $tvfile | awk '{print $3}'`
504
set calf=`cat $tvfile | awk '{print $3}'`
505
set tfil=`cat $tvfile | awk '{print $4}'`
505
set tfil=`cat $tvfile | awk '{print $4}'`
506
 
506
 
507
# Write some status information
507
# Write some status information
508
cat ${tvfile}
508
cat ${tvfile}
509
echo
509
echo
510
echo "# Number of tracing variables        : ${nlines}"
510
echo "# Number of tracing variables        : ${nlines}"
511
echo "Fields are read from following files : ${tfil}"
511
echo "Fields are read from following files : ${tfil}"
512
 
512
 
513
# Loop over all variables - check availability
513
# Loop over all variables - check availability
514
foreach v ( $vars )
514
foreach v ( $vars )
515
  if ( $calf[1] == 0 ) then
515
  if ( $calf[1] == 0 ) then
516
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
516
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
517
 
-
 
518
    ${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1]
517
    ${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1]
519
 
518
 
520
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
519
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
521
    set iscomment=`echo $v0 | cut -c 1` 
520
    set iscomment=`echo $v0 | cut -c 1` 
522
    
521
    
523
    if ( "$v0" == "PMIN" ) set flag = 1
522
    if ( "$v0" == "PMIN" ) set flag = 1
524
    if ( "$v0" == "PMAX" ) set flag = 1
523
    if ( "$v0" == "PMAX" ) set flag = 1
525
    
524
    
526
    if ( "${iscomment}" != "#" ) then 
525
    if ( "${iscomment}" != "#" ) then 
527
	 if ( $flag == 0 ) then
526
	 if ( $flag == 0 ) then
528
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
527
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
529
           exit 1
528
           exit 1
530
	 endif
529
	 endif
531
    endif
530
    endif
532
  endif
531
  endif
533
  shift calf
532
  shift calf
534
  shift tfil
533
  shift tfil
535
end
534
end
536
set ntrace=${nlines} 
535
set ntrace=${nlines} 
537
 
536
 
538
# ---------------------------------------------------------------------
537
# ---------------------------------------------------------------------
539
# Prepare input file for trace and run it
538
# Prepare input file for trace and run it
540
# ---------------------------------------------------------------------
539
# ---------------------------------------------------------------------
541
 
540
 
542
# Set times relative to the reference date
541
# Set times relative to the reference date
543
if ( "${changet}" == "true" ) then
542
if ( "${changet}" == "true" ) then
544
  echo
543
  echo
545
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
544
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
546
  echo   
545
  echo   
547
  foreach i ( $datfiles )
546
  foreach i ( $datfiles )
548
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
547
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
549
  end
548
  end
550
  if ( ${sfiles} == 1 ) then
549
  if ( ${sfiles} == 1 ) then
551
    foreach i ( $datfiles )
550
    foreach i ( $datfiles )
552
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
551
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
553
    end
552
    end
554
  endif
553
  endif
555
endif
554
endif
556
 
555
 
557
# ---------------------------------------------------------------------
556
# ---------------------------------------------------------------------
558
# Prepare input file for caltra and run it
557
# Prepare input file for caltra and run it
559
# ---------------------------------------------------------------------
558
# ---------------------------------------------------------------------
560
 
559
 
561
# Write parameter file
560
# Write parameter file
562
\rm -f ${parfile}
561
\rm -f ${parfile}
563
touch ${parfile}
562
touch ${parfile}
564
 
563
 
565
echo $inpfile                                              >> $parfile
564
echo $inpfile                                              >> $parfile
566
echo $outfile                                              >> $parfile    
565
echo $outfile                                              >> $parfile    
567
echo $startdate                                            >> $parfile
566
echo $startdate                                            >> $parfile
568
echo $enddate                                              >> $parfile
567
echo $enddate                                              >> $parfile
569
echo $idir                                                 >> $parfile
568
echo $idir                                                 >> $parfile
570
echo $numfiles                                             >> $parfile
569
echo $numfiles                                             >> $parfile
571
foreach i ( $datfiles )
570
foreach i ( $datfiles )
572
  echo $i                                                  >> $parfile
571
  echo $i                                                  >> $parfile
573
end
572
end
574
echo $timeinc                                              >> $parfile
573
echo $timeinc                                              >> $parfile
575
echo $tstart                                               >> $parfile
574
echo $tstart                                               >> $parfile
576
echo $tend                                                 >> $parfile
575
echo $tend                                                 >> $parfile
577
echo $ntra                                                 >> $parfile
576
echo $ntra                                                 >> $parfile
578
echo $ntim                                                 >> $parfile
577
echo $ntim                                                 >> $parfile
579
echo $ncol                                                 >> $parfile
578
echo $ncol                                                 >> $parfile
580
echo $ntrace                                               >> $parfile
579
echo $ntrace                                               >> $parfile
581
cat ${tvfile}                                              >> $parfile
580
cat ${tvfile}                                              >> $parfile
582
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
581
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
583
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
582
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
584
if ( $sfiles == 1 ) then
583
if ( $sfiles == 1 ) then
585
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
584
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
586
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
585
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
587
else
586
else
588
  echo 0                                                   >> $parfile
587
  echo 0                                                   >> $parfile
589
endif
588
endif
590
echo \"${timecheck}\"                                      >> $parfile
589
echo \"${timecheck}\"                                      >> $parfile
591
echo \"${intmode}\"                                        >> $parfile
590
echo \"${intmode}\"                                        >> $parfile
592
echo ${radius}                                             >> $parfile # Bojan circle mode
591
echo ${radius}                                             >> $parfile # Bojan circle mode
593
echo ${tropo_pv}                                           >> $parfile # Bojan clustering mode
592
echo ${tropo_pv}                                           >> $parfile # Bojan clustering mode
594
echo ${tropo_th}                                           >> $parfile # Bojan clustering mode
593
echo ${tropo_th}                                           >> $parfile # Bojan clustering mode
595
 
594
 
596
# Finish the preprocessor
595
# Finish the preprocessor
597
echo 
596
echo 
598
echo '       *** END OF PREPROCESSOR TRACE ***              '
597
echo '       *** END OF PREPROCESSOR TRACE ***              '
599
echo '========================================================='
598
echo '========================================================='
600
echo
599
echo
601
 
600
 
602
# Run  trace
601
# Run  trace
603
${prog}
602
${prog}
604
 
603
 
605
if ( "${status}" != "0" ) then
604
if ( "${status}" != "0" ) then
606
  echo "ERROR:  Program <trace> failed"
605
  echo "ERROR:  Program <trace> failed"
607
  exit 1
606
  exit 1
608
endif
607
endif
609
 
608
 
610
# ---------------------------------------------------------------------
609
# ---------------------------------------------------------------------
611
# Final tasks (make clean)
610
# Final tasks (make clean)
612
# ---------------------------------------------------------------------
611
# ---------------------------------------------------------------------
613
 
612
 
614
finish:
613
finish:
615
 
614
 
616
if ( "${noclean}" == "false" ) then
615
if ( "${noclean}" == "false" ) then
617
  \rm -f ${parfile}
616
  \rm -f ${parfile}
618
endif
617
endif
619
 
618
 
620
exit 0 
619
exit 0 
621
 
620