Subversion Repositories lagranto.ecmwf

Rev

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

Rev 5 Rev 39
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
# Take the time increment from flag list ('nil', if not defined)
313
# Take the time increment from flag list ('nil', if not defined)
313
set timeinc = ${flag_i}
314
set timeinc = ${flag_i}
314
 
315
 
315
# 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
316
# 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
317
if ( $direction == "f" ) then
318
if ( $direction == "f" ) then
318
  set file=${charp}${startdate_ymdh}
319
  set file=${charp}${startdate_ymdh}
319
else
320
else
320
  set file=${charp}${enddate_ymdh}
321
  set file=${charp}${enddate_ymdh}
321
endif
322
endif
322
if ( ! -f $file ) then
323
if ( ! -f $file ) then
323
  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/@//'`
324
endif
325
endif
325
 
326
 
326
# Determine timeinc (the time difference in hours between two data file)
327
# Determine timeinc (the time difference in hours between two data file)
327
# if not already defined with option -i
328
# if not already defined with option -i
328
if ( ${timeinc} == "nil" ) then
329
if ( ${timeinc} == "nil" ) then
329
  set date1=`echo $file | cut -c 2-12`
330
  set date1=`echo $file | cut -c 2-12`
330
  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}'`
331
  @ n ++
332
  @ n ++
332
  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`
333
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
334
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
334
endif
335
endif
335
if ( $timeinc == 0 ) then
336
if ( $timeinc == 0 ) then
336
    echo " ERROR: cannot set the time increment between input files ***"
337
    echo " ERROR: cannot set the time increment between input files ***"
337
    exit 1
338
    exit 1
338
endif
339
endif
339
 
340
 
340
# 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
341
# 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 
342
# 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  
343
set flag=0
344
set flag=0
344
set td=
345
set td=
345
 
346
 
346
set date = `echo $file | cut -c 2-12`
347
set date = `echo $file | cut -c 2-12`
347
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
348
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
348
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
349
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
349
 
350
 
350
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
351
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
351
   set datfiles=$date
352
   set datfiles=$date
352
   if ( $td1 < $timeinc    ) set td=$td1
353
   if ( $td1 < $timeinc    ) set td=$td1
353
   if ( $td2 < $timeinc    ) set td=$td2
354
   if ( $td2 < $timeinc    ) set td=$td2
354
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
355
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
355
   goto label2      
356
   goto label2      
356
endif
357
endif
357
 
358
 
358
foreach i ( ${charp}????????_?? )
359
foreach i ( ${charp}????????_?? )
359
 
360
 
360
  set date = `echo $i | cut -c 2-12`
361
  set date = `echo $i | cut -c 2-12`
361
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
362
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
362
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
363
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
363
 
364
 
364
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
365
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
365
      set datfiles=$date
366
      set datfiles=$date
366
      if ( $td1 < $timeinc    ) set td=$td1
367
      if ( $td1 < $timeinc    ) set td=$td1
367
      if ( $td2 < $timeinc    ) set td=$td2
368
      if ( $td2 < $timeinc    ) set td=$td2
368
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
369
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
369
      goto label2
370
      goto label2
370
  endif
371
  endif
371
 
372
 
372
end
373
end
373
 
374
 
374
# 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
375
# still undefined
376
# still undefined
376
if ( $td == "" ) then
377
if ( $td == "" ) then
377
  echo " ERROR: no data files available for the specified time period"
378
  echo " ERROR: no data files available for the specified time period"
378
  exit 1
379
  exit 1
379
endif
380
endif
380
 
381
 
381
# Everything is fine so far: proceed
382
# Everything is fine so far: proceed
382
label2:
383
label2:
383
 
384
 
384
# Check whether first date is ok - before or at needed dates
385
# Check whether first date is ok - before or at needed dates
385
if ( $direction == "f" ) then
386
if ( $direction == "f" ) then
386
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
387
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
387
else
388
else
388
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
389
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
389
endif
390
endif
390
  if ( $tdiff0 < 0 ) then
391
  if ( $tdiff0 < 0 ) then
391
  echo " ERROR: data files missing for the specified time period"
392
  echo " ERROR: data files missing for the specified time period"
392
  exit 1
393
  exit 1
393
endif
394
endif
394
 
395
 
395
# Calculate the number of further files
396
# Calculate the number of further files
396
@ num = ( $timediff_hh + $td ) / $timeinc + 1
397
@ num = ( $timediff_hh + $td ) / $timeinc + 1
397
@ dum1 = ( $num - 1 ) * $timeinc
398
@ dum1 = ( $num - 1 ) * $timeinc
398
@ dum2 = $timediff_hh + $td
399
@ dum2 = $timediff_hh + $td
399
if ( $dum1 != $dum2 ) @ num ++
400
if ( $dum1 != $dum2 ) @ num ++
400
 
401
 
401
# Get a list of all needed files
402
# Get a list of all needed files
402
set numfiles=$num
403
set numfiles=$num
403
set sfiles=1
404
set sfiles=1
404
while ( $num > 1 )
405
while ( $num > 1 )
405
 
406
 
406
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
407
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
407
  if ( ! -f ${charp}${date} ) then
408
  if ( ! -f ${charp}${date} ) then
408
    echo " ERROR: file with primary data is missing for $date"
409
    echo " ERROR: file with primary data is missing for $date"
409
    exit 1
410
    exit 1
410
  else if ( ! -f ${chars}${date} ) then
411
  else if ( ! -f ${chars}${date} ) then
411
    set sfiles=0
412
    set sfiles=0
412
    set datfiles=`echo $datfiles $date`
413
    set datfiles=`echo $datfiles $date`
413
  else
414
  else
414
    set datfiles=`echo $datfiles $date`
415
    set datfiles=`echo $datfiles $date`
415
  endif
416
  endif
416
  @ num --
417
  @ num --
417
end
418
end
418
 
419
 
419
# 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
420
if ( $direction == f ) then
421
if ( $direction == f ) then
421
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
422
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
422
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
423
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
423
else
424
else
424
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
425
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
425
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
426
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
426
endif
427
endif
427
 
428
 
428
 
429
 
429
# Write some status information
430
# Write some status information
430
echo "Primary file prefix               : ${charp}"
431
echo "Primary file prefix               : ${charp}"
431
echo "Secondary file prefix             : ${chars}"
432
echo "Secondary file prefix             : ${chars}"
432
echo "Time increment for input files    : ${timeinc}"
433
echo "Time increment for input files    : ${timeinc}"
433
echo "# input files                     : ${numfiles}"
434
echo "# input files                     : ${numfiles}"
434
echo "First input file                  : $datfiles[1] " 
435
echo "First input file                  : $datfiles[1] " 
435
echo "Last input file                   : $datfiles[$numfiles] " 
436
echo "Last input file                   : $datfiles[$numfiles] " 
436
echo "${charp} files availability              : 1"  
437
echo "${charp} files availability              : 1"  
437
echo "${chars} files availability              : ${sfiles}"     
438
echo "${chars} files availability              : ${sfiles}"     
438
if ( $direction == f ) then
439
if ( $direction == f ) then
439
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
440
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
440
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
441
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
441
else
442
else
442
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
443
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
443
echo "End time relative to first file   : $datfiles[1] + ${tend} "
444
echo "End time relative to first file   : $datfiles[1] + ${tend} "
444
endif
445
endif
445
 
446
 
446
# ---------------------------------------------------------------------
447
# ---------------------------------------------------------------------
447
# Check availability of input data 
448
# Check availability of input data 
448
# ---------------------------------------------------------------------
449
# ---------------------------------------------------------------------
449
 
450
 
450
echo
451
echo
451
echo '---- TRACEVAR FILE --------------------------------------'
452
echo '---- TRACEVAR FILE --------------------------------------'
452
echo    
453
echo    
453
 
454
 
454
# If "-f" option is used, create a temporary tracevar file
455
# If "-f" option is used, create a temporary tracevar file
455
if ( "${flag_f}" == "-f" ) then
456
if ( "${flag_f}" == "-f" ) then
456
 
457
 
457
#   Preset values for <compfl> and <tprefix>
458
#   Preset values for <compfl> and <tprefix>
458
    set tcompfl=1
459
    set tcompfl=1
459
    set tprefix='P'
460
    set tprefix='P'
460
    
461
    
461
#   Check availability on P file
462
#   Check availability on P file
462
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
463
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
463
       if ( "${var}" == "${tvar}" ) then
464
       if ( "${var}" == "${tvar}" ) then
464
          set tcompfl=0
465
          set tcompfl=0
465
	  set tprefix="P"
466
	  set tprefix="P"
466
       endif
467
       endif
467
    end
468
    end
468
 
469
 
469
#   Check availability on S file 
470
#   Check availability on S file 
470
    if ( ${sfiles} == 1 ) then
471
    if ( ${sfiles} == 1 ) then
471
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
472
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
472
         if ( "${var}" == "${tvar}" ) then
473
         if ( "${var}" == "${tvar}" ) then
473
            set tcompfl=0
474
            set tcompfl=0
474
	    set tprefix="S"
475
	    set tprefix="S"
475
         endif
476
         endif
476
       end
477
       end
477
    endif
478
    endif
478
 
479
 
479
#   Write the temporary <tracevars> file
480
#   Write the temporary <tracevars> file
480
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
481
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
481
    echo "Temporary tracervar file <${tvfile}> created"
482
    echo "Temporary tracervar file <${tvfile}> created"
482
    echo
483
    echo
483
 
484
 
484
endif
485
endif
485
 
486
 
486
 
487
 
487
# Check if tracevars-file exists
488
# Check if tracevars-file exists
488
if ( ! -f $tvfile ) then
489
if ( ! -f $tvfile ) then
489
  echo  " ERROR:  file $tvfile was not found ***"
490
  echo  " ERROR:  file $tvfile was not found ***"
490
  exit 1
491
  exit 1
491
endif
492
endif
492
 
493
 
493
# 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
494
# 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
495
 
496
 
496
set nlines = `cat $tvfile | wc -l`
497
set nlines = `cat $tvfile | wc -l`
497
set vars   = `cat $tvfile | awk '{print $1}'`
498
set vars   = `cat $tvfile | awk '{print $1}'`
498
set nvars  = `echo $vars | wc -w`
499
set nvars  = `echo $vars | wc -w`
499
if ( $nlines != $nvars ) then
500
if ( $nlines != $nvars ) then
500
  echo " ERROR: tracevars-files must not contain empty lines ***"
501
  echo " ERROR: tracevars-files must not contain empty lines ***"
501
  exit 1
502
  exit 1
502
endif
503
endif
503
set calf=`cat $tvfile | awk '{print $3}'`
504
set calf=`cat $tvfile | awk '{print $3}'`
504
set tfil=`cat $tvfile | awk '{print $4}'`
505
set tfil=`cat $tvfile | awk '{print $4}'`
505
 
506
 
506
# Write some status information
507
# Write some status information
507
cat ${tvfile}
508
cat ${tvfile}
508
echo
509
echo
509
echo "# Number of tracing variables        : ${nlines}"
510
echo "# Number of tracing variables        : ${nlines}"
510
echo "Fields are read from following files : ${tfil}"
511
echo "Fields are read from following files : ${tfil}"
511
 
512
 
512
# Loop over all variables - check availability
513
# Loop over all variables - check availability
513
foreach v ( $vars )
514
foreach v ( $vars )
514
  if ( $calf[1] == 0 ) then
515
  if ( $calf[1] == 0 ) then
515
    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]
-
 
519
 
516
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
520
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
517
    set iscomment=`echo $v0 | cut -c 1` 
521
    set iscomment=`echo $v0 | cut -c 1` 
-
 
522
    
-
 
523
    if ( "$v0" == "PMIN" ) set flag = 1
-
 
524
    if ( "$v0" == "PMAX" ) set flag = 1
-
 
525
    
518
    if ( "${iscomment}" != "#" ) then 
526
    if ( "${iscomment}" != "#" ) then 
519
	 if ( $flag == 0 ) then
527
	 if ( $flag == 0 ) then
520
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
528
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
521
           exit 1
529
           exit 1
522
	 endif
530
	 endif
523
    endif
531
    endif
524
  endif
532
  endif
525
  shift calf
533
  shift calf
526
  shift tfil
534
  shift tfil
527
end
535
end
528
set ntrace=${nlines} 
536
set ntrace=${nlines} 
529
 
537
 
530
# ---------------------------------------------------------------------
538
# ---------------------------------------------------------------------
531
# Prepare input file for trace and run it
539
# Prepare input file for trace and run it
532
# ---------------------------------------------------------------------
540
# ---------------------------------------------------------------------
533
 
541
 
534
# Set times relative to the reference date
542
# Set times relative to the reference date
535
if ( "${changet}" == "true" ) then
543
if ( "${changet}" == "true" ) then
536
  echo
544
  echo
537
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
545
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
538
  echo   
546
  echo   
539
  foreach i ( $datfiles )
547
  foreach i ( $datfiles )
540
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
548
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
541
  end
549
  end
542
  if ( ${sfiles} == 1 ) then
550
  if ( ${sfiles} == 1 ) then
543
    foreach i ( $datfiles )
551
    foreach i ( $datfiles )
544
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
552
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
545
    end
553
    end
546
  endif
554
  endif
547
endif
555
endif
548
 
556
 
549
# ---------------------------------------------------------------------
557
# ---------------------------------------------------------------------
550
# Prepare input file for caltra and run it
558
# Prepare input file for caltra and run it
551
# ---------------------------------------------------------------------
559
# ---------------------------------------------------------------------
552
 
560
 
553
# Write parameter file
561
# Write parameter file
554
\rm -f ${parfile}
562
\rm -f ${parfile}
555
touch ${parfile}
563
touch ${parfile}
556
 
564
 
557
echo $inpfile                                              >> $parfile
565
echo $inpfile                                              >> $parfile
558
echo $outfile                                              >> $parfile    
566
echo $outfile                                              >> $parfile    
559
echo $startdate                                            >> $parfile
567
echo $startdate                                            >> $parfile
560
echo $enddate                                              >> $parfile
568
echo $enddate                                              >> $parfile
561
echo $idir                                                 >> $parfile
569
echo $idir                                                 >> $parfile
562
echo $numfiles                                             >> $parfile
570
echo $numfiles                                             >> $parfile
563
foreach i ( $datfiles )
571
foreach i ( $datfiles )
564
  echo $i                                                  >> $parfile
572
  echo $i                                                  >> $parfile
565
end
573
end
566
echo $timeinc                                              >> $parfile
574
echo $timeinc                                              >> $parfile
567
echo $tstart                                               >> $parfile
575
echo $tstart                                               >> $parfile
568
echo $tend                                                 >> $parfile
576
echo $tend                                                 >> $parfile
569
echo $ntra                                                 >> $parfile
577
echo $ntra                                                 >> $parfile
570
echo $ntim                                                 >> $parfile
578
echo $ntim                                                 >> $parfile
571
echo $ncol                                                 >> $parfile
579
echo $ncol                                                 >> $parfile
572
echo $ntrace                                               >> $parfile
580
echo $ntrace                                               >> $parfile
573
cat ${tvfile}                                              >> $parfile
581
cat ${tvfile}                                              >> $parfile
574
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
582
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
575
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
583
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
576
if ( $sfiles == 1 ) then
584
if ( $sfiles == 1 ) then
577
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
585
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
578
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
586
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
579
else
587
else
580
  echo 0                                                   >> $parfile
588
  echo 0                                                   >> $parfile
581
endif
589
endif
582
echo \"${timecheck}\"                                      >> $parfile
590
echo \"${timecheck}\"                                      >> $parfile
583
echo \"${intmode}\"                                        >> $parfile
591
echo \"${intmode}\"                                        >> $parfile
584
echo ${radius}                                             >> $parfile # Bojan circle mode
592
echo ${radius}                                             >> $parfile # Bojan circle mode
585
echo ${tropo_pv}                                           >> $parfile # Bojan clustering mode
593
echo ${tropo_pv}                                           >> $parfile # Bojan clustering mode
586
echo ${tropo_th}                                           >> $parfile # Bojan clustering mode
594
echo ${tropo_th}                                           >> $parfile # Bojan clustering mode
587
 
595
 
588
# Finish the preprocessor
596
# Finish the preprocessor
589
echo 
597
echo 
590
echo '       *** END OF PREPROCESSOR TRACE ***              '
598
echo '       *** END OF PREPROCESSOR TRACE ***              '
591
echo '========================================================='
599
echo '========================================================='
592
echo
600
echo
593
 
601
 
594
# Run  trace
602
# Run  trace
595
${prog}
603
${prog}
596
 
604
 
597
if ( "${status}" != "0" ) then
605
if ( "${status}" != "0" ) then
598
  echo "ERROR:  Program <trace> failed"
606
  echo "ERROR:  Program <trace> failed"
599
  exit 1
607
  exit 1
600
endif
608
endif
601
 
609
 
602
# ---------------------------------------------------------------------
610
# ---------------------------------------------------------------------
603
# Final tasks (make clean)
611
# Final tasks (make clean)
604
# ---------------------------------------------------------------------
612
# ---------------------------------------------------------------------
605
 
613
 
606
finish:
614
finish:
607
 
615
 
608
if ( "${noclean}" == "false" ) then
616
if ( "${noclean}" == "false" ) then
609
  \rm -f ${parfile}
617
  \rm -f ${parfile}
610
endif
618
endif
611
 
619
 
612
exit 0 
620
exit 0 
613
 
621