Subversion Repositories lagranto.um

Rev

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

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