Subversion Repositories lagranto.wrf

Rev

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

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