Subversion Repositories lagranto.ecmwf

Rev

Rev 3 | Rev 39 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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