Subversion Repositories lagranto.wrf

Rev

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

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