Subversion Repositories lagranto.um

Rev

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

Rev 3 Rev 5
1
#!/bin/csh
1
#!/bin/csh
2
 
2
 
3
# ---------------------------------------------------------------------
3
# ---------------------------------------------------------------------
4
# Usage, parameter settings
4
# Usage, parameter settings
5
# ---------------------------------------------------------------------
5
# ---------------------------------------------------------------------
6
 
6
 
7
# Write usage information
7
# Write usage information
8
if ( (${#argv} == 0) | (${#argv} < 4) ) then
8
if ( (${#argv} == 0) | (${#argv} < 4) ) then
9
  echo 
9
  echo 
10
  echo "--------------------------------------------------------------"
10
  echo "--------------------------------------------------------------"
11
  echo "Usage: caltra startdate enddate startf outfile [flags]        "
11
  echo "Usage: caltra startdate enddate startf outfile [flags]        "
12
  echo 
12
  echo 
13
  echo "        startdate : Start date in format yyyymmdd_hh(mm)      "
13
  echo "        startdate : Start date in format yyyymmdd_hh(mm)      "
14
  echo "        endate    : End date in format yyyymmdd_hh(mm)        "
14
  echo "        endate    : End date in format yyyymmdd_hh(mm)        "
15
  echo "        startf    : Starting coordinates                      "
15
  echo "        startf    : Starting coordinates                      "
16
  echo "        outfile   : Output file                               "
16
  echo "        outfile   : Output file                               "
17
  echo "        [ flags ] : Optional list of flags                    "
17
  echo "        [ flags ] : Optional list of flags                    "
18
  echo
18
  echo
19
  echo " Optional flags                                               "
19
  echo " Optional flags                                               "
20
  echo "        -j          : Jumping flag for crossing lower boundary "
20
  echo "        -j          : Jumping flag for crossing lower boundary "
21
  echo "        -i hours    : Time increment for input files in hours  "
21
  echo "        -i hours    : Time increment for input files in hours  "
22
  echo "        -t min      : Time steps for calculation               "
22
  echo "        -t min      : Time steps for calculation               "
23
  echo "        -o min      : Output interval in minutes               "
23
  echo "        -o min      : Output interval in minutes               "
24
  echo "        -p          : Periodicity flag                         "
24
  echo "        -p          : Periodicity flag                         "
25
  echo "        -changet    : flag whether to change times on P,S files before calculation" 
25
  echo "        -changet    : flag whether to change times on P,S files before calculation" 
26
  echo "        -noclean    : flag whether to remove temporary files"
26
  echo "        -noclean    : flag whether to remove temporary files"
27
  echo "--------------------------------------------------------------"
27
  echo "--------------------------------------------------------------"
28
  exit 0
28
  exit 0
29
endif
29
endif
30
 
30
 
31
# Write title
31
# Write title
32
echo 
32
echo 
33
echo '========================================================='
33
echo '========================================================='
34
echo '       *** START OF PREPROCESSOR CALTRA ***              '
34
echo '       *** START OF PREPROCESSOR CALTRA ***              '
35
echo
35
echo
36
 
36
 
37
# Get the arguments
37
# Get the arguments
38
set startdate = $1
38
set startdate = $1
39
set enddate   = $2
39
set enddate   = $2
40
set startf    = $3
40
set startf    = $3
41
set outfile   = $4
41
set outfile   = $4
42
if ( ${#argv} > 4 ) then
42
if ( ${#argv} > 4 ) then
43
   set flags = $5
43
   set flags = $5
44
else
44
else
45
   set flags=
45
   set flags=
46
endif 
46
endif 
47
 
47
 
48
# Set base directories (run+prog)
48
# Set base directories (run+prog)
49
set cdfdir=${PWD}
49
set cdfdir=${PWD}
50
set tradir=${PWD}
50
set tradir=${PWD}
51
 
51
 
52
# Set program paths and filenames 
52
# Set program paths and filenames 
53
set parfile = ${tradir}/caltra.param 
53
set parfile = ${tradir}/caltra.param 
54
 
54
 
55
# Set the prefix of the primary and secondary data files
55
# Set the prefix of the primary and secondary data files
56
set charp = 'P'
56
set charp = 'P'
57
set chars = 'S'
57
set chars = 'S'
58
 
58
 
59
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
59
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
60
echo    
60
echo    
61
echo "CDF directory         : ${cdfdir}"
61
echo "CDF directory         : ${cdfdir}"
62
echo "TRA directory         : ${tradir}"
62
echo "TRA directory         : ${tradir}"
63
echo "PROGRAM CALTRA        : ${LAGRANTO}/caltra/caltra"
63
echo "PROGRAM CALTRA        : ${LAGRANTO}/caltra/caltra"
64
echo "PARAMETER file        : ${parfile}"
64
echo "PARAMETER file        : ${parfile}"
65
echo
65
echo
66
 
66
 
67
# ---------------------------------------------------------------------
67
# ---------------------------------------------------------------------
68
# Set optional flags
68
# Set optional flags
69
# ---------------------------------------------------------------------
69
# ---------------------------------------------------------------------
70
 
70
 
71
echo '---- OPTIONAL FLAGS -------------------------------------'
71
echo '---- OPTIONAL FLAGS -------------------------------------'
72
echo
72
echo
73
 
73
 
74
# Set some default values ("nil" must be set according to input files)
74
# Set some default values ("nil" must be set according to input files)
75
set flag_j     = "nil"
75
set flag_j     = "nil"
76
set flag_i     = "nil"
76
set flag_i     = "nil"
77
set flag_t     = "nil"
77
set flag_t     = "nil"
78
set flag_o     = "nil"
78
set flag_o     = "nil"
79
set flag_p     = "nil"
79
set flag_p     = "nil"
80
set changet    = 'false'
80
set changet    = 'false'
81
set noclean    = 'false'
81
set noclean    = 'false'
82
set timecheck  = 'yes' 
82
set timecheck  = 'yes' 
83
 
83
 
84
 
84
 
85
while ( $#argv > 0 )
85
while ( $#argv > 0 )
86
 
86
 
87
  switch ( $argv[1] )
87
  switch ( $argv[1] )
88
 
88
 
89
   case -j
89
   case -j
90
     set flag_j=1
90
     set flag_j=1
91
     echo "Flag '-j'     -> ${flag_j} (user defined)"
91
     echo "Flag '-j'     -> ${flag_j} (user defined)"
92
   breaksw
92
   breaksw
93
 
93
 
94
   case -i
94
   case -i
95
     set flag_i=$argv[2]
95
     set flag_i=$argv[2]
96
     echo "Flag '-i'     -> ${flag_i} (user defined)"
96
     echo "Flag '-i'     -> ${flag_i} (user defined)"
97
     shift;
97
     shift;
98
   breaksw
98
   breaksw
99
 
99
 
100
   case -t
100
   case -t
101
     set flag_t=$argv[2]
101
     set flag_t=$argv[2]
102
     echo "Flag '-t'     -> ${flag_t} (user defined)"
102
     echo "Flag '-t'     -> ${flag_t} (user defined)"
103
     shift;
103
     shift;
104
   breaksw
104
   breaksw
105
 
105
 
106
   case -o
106
   case -o
107
     set flag_o=$argv[2]
107
     set flag_o=$argv[2]
108
     echo "Flag '-o'     -> ${flag_o} (user defined)"
108
     echo "Flag '-o'     -> ${flag_o} (user defined)"
109
     shift;
109
     shift;
110
   breaksw
110
   breaksw
111
 
111
 
112
   case -p
112
   case -p
113
     set flag_p=1
113
     set flag_p=1
114
     echo "Flag '-p'     -> ${flag_p} (user defined)"
114
     echo "Flag '-p'     -> ${flag_p} (user defined)"
115
   breaksw
115
   breaksw
116
 
116
 
117
   case -changet
117
   case -changet
118
     set changet = 'true'
118
     set changet = 'true'
119
     echo "changet       -> true (user defined)"
119
     echo "changet       -> true (user defined)"
120
   breaksw
120
   breaksw
121
 
121
 
122
   case -noclean
122
   case -noclean
123
     set noclean = 'true'
123
     set noclean = 'true'
124
     echo "noclean       -> true (user defined)"
124
     echo "noclean       -> true (user defined)"
125
   breaksw
125
   breaksw
126
 
126
 
127
   case -notimecheck
127
   case -notimecheck
128
     set timecheck = 'no'
128
     set timecheck = 'no'
129
     echo "timecheck               -> no (user defined)"
129
     echo "timecheck               -> no (user defined)"
130
   breaksw
130
   breaksw
131
 
131
 
132
 
132
 
133
  endsw
133
  endsw
134
 
134
 
135
  shift;
135
  shift;
136
 
136
 
137
end
137
end
138
 
138
 
139
# No change of times necessary if no check requested
139
# No change of times necessary if no check requested
140
if ( "${timecheck}" == "no" ) then
140
if ( "${timecheck}" == "no" ) then
141
   set  changet = 'false'
141
   set  changet = 'false'
142
endif
142
endif
143
 
143
 
144
# Set some defaults
144
# Set some defaults
145
if ( "${flag_j}"     == "nil" ) then
145
if ( "${flag_j}"     == "nil" ) then
146
    set flag_j     = 0
146
    set flag_j     = 0
147
    echo "Flag '-j'     -> 0 (default)"
147
    echo "Flag '-j'     -> 0 (default)"
148
endif
148
endif
149
if ( "${flag_p}"     == "nil" ) then
149
if ( "${flag_p}"     == "nil" ) then
150
    set flag_p     = 0
150
    set flag_p     = 0
151
    echo "Flag '-p'     -> 0 (default)"
151
    echo "Flag '-p'     -> 0 (default)"
152
endif
152
endif
153
 
153
 
154
# ---------------------------------------------------------------------
154
# ---------------------------------------------------------------------
155
# Handle the time specifier - startdate, enddate
155
# Handle the time specifier - startdate, enddate
156
# ---------------------------------------------------------------------
156
# ---------------------------------------------------------------------
157
 
157
 
158
echo
158
echo
159
echo '---- TIME RANGE -----------------------------------------'
159
echo '---- TIME RANGE -----------------------------------------'
160
echo
160
echo
161
 
161
 
162
# Check format of start and end date - must be the same
162
# Check format of start and end date - must be the same
163
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
163
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
164
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
164
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
165
if ( $ns != $ne ) then
165
if ( $ns != $ne ) then
166
  echo " ERROR: start and end date must be in the same format ***"
166
  echo " ERROR: start and end date must be in the same format ***"
167
  exit 1
167
  exit 1
168
endif
168
endif
169
if ( $ns != 9 ) then
169
if ( $ns != 9 ) then
170
  echo " ERROR: Date format must be yyyymmdd ***"
170
  echo " ERROR: Date format must be yyyymmdd ***"
171
  exit 1
171
  exit 1
172
endif
172
endif
173
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
173
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
174
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
174
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
175
if ( $ns != $ne ) then
175
if ( $ns != $ne ) then
176
  echo " ERROR: start and end date must be in the same format ***"
176
  echo " ERROR: start and end date must be in the same format ***"
177
  exit 1
177
  exit 1
178
endif
178
endif
179
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
179
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
180
  echo " ERROR: Time format must be hh(mm) ***"
180
  echo " ERROR: Time format must be hh(mm) ***"
181
  exit 1
181
  exit 1
182
endif
182
endif
183
 
183
 
184
# Split the start and end date into <yymmdd_hh and mm>
184
# Split the start and end date into <yymmdd_hh and mm>
185
set startdate_ymdh = `echo $startdate | cut -c 1-11`
185
set startdate_ymdh = `echo $startdate | cut -c 1-11`
186
set startdate_min  = `echo $startdate | cut -c 12-13`
186
set startdate_min  = `echo $startdate | cut -c 12-13`
187
if ( $startdate_min == "" ) set startdate_min = 00
187
if ( $startdate_min == "" ) set startdate_min = 00
188
 
188
 
189
set enddate_ymdh = `echo $enddate | cut -c 1-11`
189
set enddate_ymdh = `echo $enddate | cut -c 1-11`
190
set enddate_min  = `echo $enddate | cut -c 12-13`
190
set enddate_min  = `echo $enddate | cut -c 12-13`
191
if ( $enddate_min == "" ) set enddate_min = 00
191
if ( $enddate_min == "" ) set enddate_min = 00
192
 
192
 
193
# Get the time difference between <start_ymdh> and <end_ymdh> date
193
# Get the time difference between <start_ymdh> and <end_ymdh> date
194
# Decide whether trajectoriesare forward or backward
194
# Decide whether trajectoriesare forward or backward
195
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
195
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
196
 
196
 
197
if ( $timediff_hh == 0 ) then
197
if ( $timediff_hh == 0 ) then
198
  if ( $enddate_min > $startdate_min ) then
198
  if ( $enddate_min > $startdate_min ) then
199
    set direction = f
199
    set direction = f
200
    set idir      = 1
200
    set idir      = 1
201
  else
201
  else
202
    set direction = b
202
    set direction = b
203
    set idir      = -1
203
    set idir      = -1
204
  endif
204
  endif
205
else if ( $timediff_hh > 0 ) then
205
else if ( $timediff_hh > 0 ) then
206
  set direction = f
206
  set direction = f
207
  set idir      = 1
207
  set idir      = 1
208
else
208
else
209
  set direction = b
209
  set direction = b
210
  set idir      = -1
210
  set idir      = -1
211
  @ timediff_hh = $idir * $timediff_hh
211
  @ timediff_hh = $idir * $timediff_hh
212
endif
212
endif
213
 
213
 
214
# Get also minutes for time difference, if <start_min> or <end_min> != 0
214
# Get also minutes for time difference, if <start_min> or <end_min> != 0
215
set timediff_mm=
215
set timediff_mm=00
216
 
216
 
217
if ( $startdate_min != 00 || $enddate_min != 00 ) then
217
if ( $startdate_min != 00 || $enddate_min != 00 ) then
218
  @ min = ( $enddate_min - $startdate_min )
218
  @ min = ( $enddate_min - $startdate_min )
219
  if ( $min == 0 ) then
219
  if ( $min == 0 ) then
220
    set timediff_mm=
220
    set timediff_mm=
221
  else if ( $min > 0 ) then
221
  else if ( $min > 0 ) then
222
    if ( $idir == 1 ) then
222
    if ( $idir == 1 ) then
223
      set timediff_mm=$min
223
      set timediff_mm=$min
224
    else
224
    else
225
      @ timediff_hh --
225
      @ timediff_hh --
226
      @ timediff_mm = 60 - $min
226
      @ timediff_mm = 60 - $min
227
    endif
227
    endif
228
  else
228
  else
229
    if ( $idir == 1 ) then
229
    if ( $idir == 1 ) then
230
      @ timediff_hh --
230
      @ timediff_hh --
231
      @ timediff_mm = 60 + $min
231
      @ timediff_mm = 60 + $min
232
    else
232
    else
233
      @ timediff_mm = 0 - $min
233
      @ timediff_mm = 0 - $min
234
    endif
234
    endif
235
  endif
235
  endif
236
endif
236
endif
237
 
237
 
238
# Set the reference date equal to the satrtdate
238
# Set the reference date equal to the satrtdate
239
set refdate=${startdate}
239
set refdate=${startdate}
240
 
240
 
241
# Write status information
241
# Write status information
242
echo "Time range      : ${startdate} -> ${enddate}"
242
echo "Time range      : ${startdate} -> ${enddate}"
243
if ( ${timediff_mm} !=  "" ) then
243
if ( ${timediff_mm} !=  "" ) then
244
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
244
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
245
else
245
else
246
   echo "Time difference : ${timediff_hh} h"
246
   echo "Time difference : ${timediff_hh} h"
247
endif
247
endif
248
echo "Direction       : ${direction} (${idir})"
248
echo "Direction       : ${direction} (${idir})"
249
echo "Reference date  : ${refdate}"
249
echo "Reference date  : ${refdate}"
250
 
250
 
251
# ---------------------------------------------------------------------
251
# ---------------------------------------------------------------------
252
# Check availability of input data 
252
# Check availability of input data 
253
# ---------------------------------------------------------------------
253
# ---------------------------------------------------------------------
254
 
254
 
255
echo
255
echo
256
echo '---- INPUT FILES ----------------------------------------'
256
echo '---- INPUT FILES ----------------------------------------'
257
echo
257
echo
258
 
258
 
259
# Take the time increment from flag list ('nil', if not defined)
259
# Take the time increment from flag list ('nil', if not defined)
260
set timeinc = ${flag_i}
260
set timeinc = ${flag_i}
261
 
261
 
262
# Find a first data file (if possible corresponding to start/end date
262
# Find a first data file (if possible corresponding to start/end date
263
# If starttime is not a data time, take the first file in the direectory
263
# If starttime is not a data time, take the first file in the directory
264
if ( $direction == "f" ) then
264
if ( $direction == "f" ) then
265
  set file=${charp}${startdate_ymdh}
265
  set file=${charp}${startdate_ymdh}
266
else
266
else 
267
  set file=${charp}${enddate_ymdh}
267
  set file=${charp}${enddate_ymdh}
268
endif
268
endif
269
if ( ! -f $file ) then
269
if ( ! -f $file ) then
270
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
270
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
271
endif
271
endif
272
 
272
 
273
# Determine timeinc (the time difference in hours between two data file)
273
# Determine timeinc (the time difference in hours between two data file)
274
# if not already defined with option -i
274
# if not already defined with option -i
275
if ( ${timeinc} == "nil" ) then
275
if ( ${timeinc} == "nil" ) then
276
  set date1=`echo $file | cut -c 2-12`
276
  set date1=`echo $file | cut -c 2-`
277
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
277
  set n=`\ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
278
  @ n ++
278
  @ n ++
279
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
279
  set date2=`\ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
280
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
280
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
281
endif
281
endif
282
if ( $timeinc == 0 ) then
282
if ( $timeinc == 0 ) then
283
    echo " ERROR: cannot set the time increment between input files ***"
283
    echo " ERROR: cannot set the time increment between input files ***"
284
    exit 1
284
    exit 1
285
endif
285
endif
286
 
286
 
-
 
287
# Decide whether the time increment is smaller than 1 h; if so set the hires
-
 
288
# flag and convert the timeincement into fractional hour
287
# Search the first file to use
289
set flag = `echo ${timeinc} | grep -n '\.'`
-
 
290
set hires = 0
-
 
291
 
-
 
292
if ( "${flag}" != "" ) then
-
 
293
  echo "Input files availability < 1 hour ($timeinc): switch to hires"
-
 
294
  echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
-
 
295
  set hires = 1
-
 
296
  set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
-
 
297
  set timeinc     = `echo "scale=2; ${timeinc} * 100 / 60" | bc`
-
 
298
  goto hires
-
 
299
endif
-
 
300
 
-
 
301
# Search the first file to use: We step through all P files and see whether they are
-
 
302
# good P files. Let's first do the test for the first data file found. If it's ok, we 
-
 
303
# take it; if not, we step through all P files and find the good one
288
set flag=0
304
set flag=0
289
set td=
305
set td=
-
 
306
 
-
 
307
set date = `echo ${file} | cut -c 2-12`
-
 
308
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
-
 
309
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
-
 
310
 
-
 
311
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
-
 
312
   set datfiles=$date
-
 
313
   if ( $td1 < $timeinc    ) set td=$td1
-
 
314
   if ( $td2 < $timeinc    ) set td=$td2
-
 
315
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
-
 
316
   goto label2      
-
 
317
endif
-
 
318
 
290
foreach i ( ${charp}????????_?? )
319
foreach i ( ${charp}????????_?? )
291
 
320
 
292
  set date = `echo $i | cut -c 2-12`
321
  set date = `echo $i | cut -c 2-12`
293
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
322
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
294
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
323
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
295
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
324
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
296
      set datfiles=$date
325
      set datfiles=$date
297
      if ( $td1 < $timeinc    ) set td=$td1
326
      if ( $td1 < $timeinc    ) set td=$td1
298
      if ( $td2 < $timeinc    ) set td=$td2
327
      if ( $td2 < $timeinc    ) set td=$td2
299
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
328
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
300
      goto label2
329
      goto label2
301
  endif
330
  endif
302
 
331
 
303
end
332
end
304
 
333
 
305
# if no P/T-files are available for the specified time period, then $td is
-
 
306
# still undefined
-
 
307
if ( $td == "" ) then
334
if ( $td == "" ) then
-
 
335
  echo
308
  echo " ERROR: no data files available for the specified time period"
336
  echo " ERROR: no data files available for the specified time period"
309
  exit 1
337
  exit 1
310
endif
338
endif
311
 
339
 
-
 
340
# If the input files come with time increment < 1 hour, handle it in this
-
 
341
# special section. The aim is not to 'interfere' with the well established
-
 
342
# code handling the standard case with time increment >= 1 hour. In this mode
-
 
343
# we require that the start and end date are available as P files: no start is
312
# Everything is fine so far: proceed
344
# allowed between the model output files
313
label2:
345
hires:
-
 
346
 
-
 
347
set flag=0
-
 
348
set td=0
-
 
349
 
-
 
350
if ( $direction == "f" ) then
-
 
351
  set file=${charp}${startdate}
-
 
352
else 
-
 
353
  set file=${charp}${enddate}
-
 
354
endif
314
 
355
 
315
# Calculate the number of further files
356
if ( -f $file ) then
316
@ num = ( $timediff_hh + $td ) / $timeinc + 1
357
  set date     = `echo ${file} | cut -c 2-14`
317
@ dum1 = ( $num - 1 ) * $timeinc
358
  set datfiles = $date
318
@ dum2 = $timediff_hh + $td
359
  set td       = 0
319
if ( $dum1 != $dum2 ) @ num ++
360
  goto label2
-
 
361
else
-
 
362
  echo
-
 
363
  echo " ERROR: no data files available for the specified time period"
-
 
364
  exit 1
-
 
365
endif
320
 
366
 
-
 
367
# Everything is fine so far (first data file found): proceed
-
 
368
label2:
-
 
369
 
-
 
370
# Calculate the number of further files; handle hires (timeinc<1 h) and
-
 
371
# standard mode (timeinc >= 1 h) separately
-
 
372
if ( ${hires} == 0 ) then
-
 
373
 @ num = ( $timediff_hh + $td ) / $timeinc + 1
-
 
374
 @ dum1 = ( $num - 1 ) * $timeinc
-
 
375
 @ dum2 = $timediff_hh + $td
-
 
376
 if ( $dum1 != $dum2 ) @ num ++
-
 
377
else
-
 
378
 set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
-
 
379
endif 
-
 
380
 
321
# Get a list of all needed files
381
# Get a list of all needed files
322
set numfiles=$num
382
set numfiles=$num
323
set sfiles=1
383
set sfiles=1
-
 
384
echo $datfiles
324
while ( $num > 1 )
385
while ( $num > 1 )
-
 
386
  if ( $hires == 0 ) then
325
  set date=`${LAGRANTO}goodies/newtime $date $timeinc`
387
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
-
 
388
  else
-
 
389
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
-
 
390
  endif
326
 
391
  
327
  echo $date
392
  echo ${date}
328
 
393
  
329
  if ( ! -f ${charp}${date} ) then
394
  if ( ! -f ${charp}${date} ) then
330
    echo " ERROR: file with primary data is missing for $date"
395
    echo " ERROR: file with primary data is missing for $date"
331
    exit 1
396
    exit 1
332
  else if ( ! -f ${chars}${date} ) then
397
  else if ( ! -f ${chars}${date} ) then
333
    set sfiles=0
398
    set sfiles=0
334
    set datfiles=`echo $datfiles $date`
399
    set datfiles=`echo $datfiles $date`
335
  else
400
  else
336
    set datfiles=`echo $datfiles $date`
401
    set datfiles=`echo $datfiles $date`
337
  endif
402
  endif
338
  @ num --
403
  @ num --
339
end
404
end
340
 
405
 
341
# Write some status information
406
# Write some status information
342
echo "Primary file prefix            : ${charp}"
407
echo "Primary file prefix            : ${charp}"
343
echo "Secondary file prefix          : ${chars}"
408
echo "Secondary file prefix          : ${chars}"
-
 
409
if ( ${hires} == 0 ) then
344
echo "Time increment for input files : ${timeinc}"
410
  echo "Time increment for input files : ${timeinc} h"
-
 
411
else
-
 
412
  echo "Time increment for input files : ${timeinc_min} min (0$timeinc h) "
-
 
413
endif
345
echo "# input files                  : ${numfiles}"
414
echo "# input files                  : ${numfiles}"
346
echo "${charp} files availability           : 1"  
415
echo "${charp} files availability           : 1"  
347
echo "${chars} files availability           : ${sfiles}"     
416
echo "${chars} files availability           : ${sfiles}"     
348
echo "First input file               : $datfiles[1] " 
417
echo "First input file               : $datfiles[1] " 
349
echo "Last input file                : $datfiles[$numfiles] " 
418
echo "Last input file                : $datfiles[$numfiles] " 
350
 
419
 
-
 
420
echo
-
 
421
echo $datfiles
-
 
422
 
351
# ---------------------------------------------------------------------
423
# ---------------------------------------------------------------------
352
# Handle vertical wind - scaling factor
424
# Handle vertical wind - scaling factor
353
# ---------------------------------------------------------------------
425
# ---------------------------------------------------------------------
354
 
426
 
355
echo
427
echo
356
echo '---- VERTICAL WIND SCALING ------------------------------'
428
echo '---- VERTICAL WIND SCALING ------------------------------'
357
echo
429
echo
358
 
430
 
359
# Check whether OMEGA is avialbale on first file
431
# Check whether OMEGA is avialbale on first file
360
set first=$datfiles[1]
432
set first=$datfiles[1]
361
set file="${charp}${first}"
433
set file="${charp}${first}"
362
set omflag=`${LAGRANTO}/goodies/getvars $file | grep " OMEGA " | wc -l`
434
set omflag=`${LAGRANTO}/goodies/getvars $file | grep " OMEGA " | wc -l`
363
if ( $omflag != 1 ) then
435
if ( $omflag != 1 ) then
364
   echo " ERROR: variable OMEGA is not on file $file"
436
   echo " ERROR: variable OMEGA is not on file $file"
365
   exit 1
437
   exit 1
366
endif
438
endif
367
 
439
 
368
# Get the maximum and minimum wind on 850 hPa and decide the <wfactor>
440
# Get the maximum and minimum wind on 850 hPa and decide the <wfactor>
369
set wmin  = `${LAGRANTO}/goodies/getmima $file OMEGA P850 | awk '{print $1}'`
441
set wmin  = `${LAGRANTO}/goodies/getmima $file OMEGA P850 | awk '{print $1}'`
370
set wmax  = `${LAGRANTO}/goodies/getmima $file OMEGA P850 | awk '{print $2}'`
442
set wmax  = `${LAGRANTO}/goodies/getmima $file OMEGA P850 | awk '{print $2}'`
371
set wmin  = `echo $wmin | sed -e 's/\.//'`
443
set wmin  = `echo $wmin | sed -e 's/\.//'`
372
set wmax  = `echo $wmax | sed -e 's/\.//'`
444
set wmax  = `echo $wmax | sed -e 's/\.//'`
373
set wdiff = `echo $wmax - $wmin | bc`
445
set wdiff = `echo $wmax - $wmin | bc`
374
 
446
 
375
if ( $wdiff > 400 ) then
447
if ( $wdiff > 400 ) then
376
    set wfactor=1.
448
    set wfactor=1.
377
else
449
else
378
    set wfactor=100.
450
    set wfactor=100.
379
endif
451
endif
380
 
452
 
381
# Write status information
453
# Write status information
382
echo "Vertical scaling factor (wfactor)  : ${wfactor}"
454
echo "Vertical scaling factor (wfactor)  : ${wfactor}"
383
 
455
 
384
# ---------------------------------------------------------------------
456
# ---------------------------------------------------------------------
385
# Time step and output interval
457
# Time step and output interval
386
# ---------------------------------------------------------------------
458
# ---------------------------------------------------------------------
387
 
459
 
388
echo
460
echo
389
echo '---- TIME STEPS -----------------------------------------'
461
echo '---- TIME STEPS -----------------------------------------'
390
echo
462
echo
391
 
463
 
392
# Take the time step and output step from flag list ('nil', if not defined)
464
# Take the time step and output step from flag list ('nil', if not defined)
393
set timestep = ${flag_t}
465
set timestep = ${flag_t}
394
set deltout  = ${flag_o}
466
set deltout  = ${flag_o}
395
 
467
 
396
# Calculate the time step
468
# Calculate the time step
-
 
469
if ( $hires == 0 ) then
397
if ( $timestep == "nil" ) @ timestep = ( 60 * $timeinc ) / 12
470
  if ( $timestep == "nil" ) @ timestep = ( 60 * $timeinc ) / 12
-
 
471
else
-
 
472
  if ( $timestep == "nil" ) set timestep =  `echo "scale=2; $timeinc_min / 12" | bc`
-
 
473
endif
398
 
474
 
399
# Take the output interval from time increment
475
# Take the output interval from time increment
-
 
476
if ( $hires == 0 ) then
400
if ( $deltout == "nil" ) @ deltout = 60 * ${timeinc}
477
  if ( $deltout == "nil" ) @ deltout = 60 * ${timeinc}
-
 
478
else
-
 
479
  if ( $deltout == "nil" ) set deltout = ${timeinc_min}
-
 
480
endif
401
 
481
 
402
# Check whether the timestep is an integer ratio of deltout
482
# Check whether the timestep is an integer ratio of deltout
403
@ flag = $deltout / $timestep
483
#@ flag = $deltout / $timestep
404
@ flag = $deltout - ( $flag * $timestep )
484
#@ flag = $deltout - ( $flag * $timestep )
-
 
485
set flag = `echo "scale=2; $deltout / $timestep" | bc`
-
 
486
set flag = `echo "scale=2; $deltout - ( $flag * $timestep )" | bc`   
405
if ( $flag != 0 ) then
487
if ( $flag != 0 ) then
406
  echo " ERROR: output time interval should be multiple of timestep"
488
  echo " ERROR: output time interval should be multiple of timestep"
407
  echo 
489
  echo 
408
  echo "           $deltout min  : output time interval"
490
  echo "           $deltout min  : output time interval"
409
  echo "           $timestep min  : time step"
491
  echo "           $timestep min  : time step"
410
  exit 1
492
  exit 1
411
endif
493
endif
412
 
494
 
413
# Calculate the start and the end time relative to the first datfile
495
# Calculate the start and the end time relative to the first datfile
414
if ( $direction == f ) then
496
if ( $direction == f ) then
415
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
497
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
416
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
498
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
417
else
499
else
418
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
500
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
419
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
501
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
420
endif
502
endif
421
 
503
 
422
# Check whether tstart and tend are a multiple of the output time interval
504
# Check whether tstart and tend are a multiple of the output time interval
423
if ( $tstart != 0 ) then
505
if ( $tstart != 0 ) then
424
  if ( `echo $tstart | grep "\."` != "" ) then
506
  if ( `echo $tstart | grep "\."` != "" ) then
425
    set dum=`echo $tstart | sed -e 's/[-0-9]*\.//'`
507
    set dum=`echo $tstart | sed -e 's/[-0-9]*\.//'`
426
    @ flag = $dum / $deltout
508
    @ flag = $dum / $deltout
427
    @ flag = $dum - ( $flag * $deltout )
509
    @ flag = $dum - ( $flag * $deltout )
428
    if ( $flag != 0 ) then
510
    if ( $flag != 0 ) then
429
      echo " ERROR : the start time should be shifted relative to the first"
511
      echo " ERROR : the start time should be shifted relative to the first"
430
      echo "         datafile by a multiple of the output time interval"
512
      echo "         datafile by a multiple of the output time interval"
431
      echo "         hint:  set the latter with the option -o"
513
      echo "         hint:  set the latter with the option -o"
432
      exit 1
514
      exit 1
433
    endif
515
    endif
434
  endif
516
  endif
435
endif
517
endif
436
if ( `echo $tend | grep "\."` != "" ) then
518
if ( `echo $tend | grep "\."` != "" ) then
437
  set dum=`echo $tend | sed -e 's/[-0-9]*\.//'`
519
  set dum=`echo $tend | sed -e 's/[-0-9]*\.//'`
438
  @ flag = $dum / $deltout
520
  @ flag = $dum / $deltout
439
  @ flag = $dum - ( $flag * $deltout )
521
  @ flag = $dum - ( $flag * $deltout )
440
  if ( $flag != 0 ) then
522
  if ( $flag != 0 ) then
441
    echo " ERROR : the end time should be shifted relative to the first"
523
    echo " ERROR : the end time should be shifted relative to the first"
442
    echo "         datafile by a multiple of the output time interval"
524
    echo "         datafile by a multiple of the output time interval"
443
    echo "         hint:  set the latter with the option -o"
525
    echo "         hint:  set the latter with the option -o"
444
    exit 1
526
    exit 1
445
  endif
527
  endif
446
endif
528
endif
447
 
529
 
448
# Write status information
530
# Write status information
449
echo "Trajectory calculation time step [min] : ${timestep}"
531
echo "Trajectory calculation time step [min] : ${timestep}"
450
echo "Output time step [min]                 : ${deltout}"
532
echo "Output time step [min]                 : ${deltout}"
451
if ( $direction == f ) then
533
if ( $direction == f ) then
452
  echo "Start time relative to first file      : $datfiles[1] + ${tstart} "
534
  echo "Start time relative to first file      : $datfiles[1] + ${tstart} "
453
  echo "End time relative to first file        : $datfiles[$numfiles] - ${tend} "  
535
  echo "End time relative to first file        : $datfiles[$numfiles] - ${tend} "  
454
else
536
else
455
  echo "Start time relative to first file      : $datfiles[$numfiles] - ${tstart} "
537
  echo "Start time relative to first file      : $datfiles[$numfiles] - ${tstart} "
456
  echo "End time relative to last file         : $datfiles[1] + ${tend} "
538
  echo "End time relative to last file         : $datfiles[1] + ${tend} "
457
endif
539
endif
458
 
540
 
459
# ---------------------------------------------------------------------
541
# ---------------------------------------------------------------------
460
# Start file
542
# Start file
461
# ---------------------------------------------------------------------
543
# ---------------------------------------------------------------------
462
 
544
 
463
echo
545
echo
464
echo '---- START FILE -----------------------------------------'
546
echo '---- START FILE -----------------------------------------'
465
echo
547
echo
466
 
548
 
467
# Check if start file is available
549
# Check if start file is available
468
if ( ! -f ${startf} ) then
550
if ( ! -f ${startf} ) then
469
   echo " ERROR : start file ${startf} is missing"
551
   echo " ERROR : start file ${startf} is missing"
470
   exit 1
552
   exit 1
471
endif
553
endif
472
 
554
 
473
# Decide whether startfile has an explicit format specifier
555
# Decide whether startfile has an explicit format specifier
474
set format = "0"
556
set format = "0"
475
foreach app ( 1 2 3 4 5 6 7 8 9 )
557
foreach app ( 1 2 3 4 5 6 7 8 9 )
476
  set flag = `echo ${startf} | grep ".${app}"`
558
  set flag = `echo ${startf} | grep ".${app}"`
477
  if ( "${flag}" != "" ) set format = "${app}"
559
  if ( "${flag}" != "" ) set format = "${app}"
478
end
560
end
479
 
561
 
480
# If format is 0, it might nevertheless be a hidden format 1
562
# If format is 0, it might nevertheless be a hidden format 1
481
if ( "${format}" == "0" ) then
563
if ( "${format}" == "0" ) then
482
    set ncol = `awk "{print NF}" ${startf} | tail -1` 
564
    set ncol = `awk "{print NF}" ${startf} | tail -1` 
483
    if ( "${ncol}" != "3" ) then
565
    if ( "${ncol}" != "3" ) then
484
        set format = "1"
566
        set format = "1"
485
        echo " WARNING: ${startf} is a hidden trajectory file of format 1"
567
        echo " WARNING: ${startf} is a hidden trajectory file of format 1"
486
        echo "          it will be renamed: ${startf} -> ${startf}.1"
568
        echo "          it will be renamed: ${startf} -> ${startf}.1"
487
        echo
569
        echo
488
        ln -sf ${startf} ${startf}.1
570
        ln -sf ${startf} ${startf}.1
489
        set startf = "${startf}.1"
571
        set startf = "${startf}.1"
490
    endif
572
    endif
491
endif
573
endif
492
 
574
 
493
# Get the number of trajectories
575
# Get the number of trajectories
494
if ( "${format}" == "0" ) then
576
if ( "${format}" == "0" ) then
495
   set ntra = `wc -l ${startf} | awk '{print $1}' `
577
   set ntra = `wc -l ${startf} | awk '{print $1}' `
496
   set ncol = 3
578
   set ncol = 3
497
else
579
else
498
   set ntra = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntra`
580
   set ntra = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntra`
499
   set ncol = `${LAGRANTO}/goodies/trainfo.sh ${startf} ncol`
581
   set ncol = `${LAGRANTO}/goodies/trainfo.sh ${startf} ncol`
500
   set ntim = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntim`
582
   set ntim = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntim`
501
   
583
   
502
   if ( "${ntim}" != "1" ) then
584
   if ( "${ntim}" != "1" ) then
503
      echo " ERROR: starting trajectory file must only have one time... Stop"
585
      echo " ERROR: starting trajectory file must only have one time... Stop"
504
      exit 1
586
      exit 1
505
   endif
587
   endif
506
 
588
 
507
endif
589
endif
508
 
590
 
509
# Write status information
591
# Write status information
510
echo "Start file                  : ${startf} "
592
echo "Start file                  : ${startf} "
511
if ( "${format}" == "0" ) then 
593
if ( "${format}" == "0" ) then 
512
   echo "Format                      : (lon,lat,p) list"
594
   echo "Format                      : (lon,lat,p) list"
513
else
595
else
514
   echo "Format                      : trajectory file (${format})"
596
   echo "Format                      : trajectory file (${format})"
515
endif
597
endif
516
echo "# coordinates (lon,lat,lev) : ${ntra} "  
598
echo "# coordinates (lon,lat,lev) : ${ntra} "  
517
echo "# columns                   : ${ncol} "  
599
echo "# columns                   : ${ncol} "  
518
 
600
 
519
# ---------------------------------------------------------------------
601
# ---------------------------------------------------------------------
520
# Prepare input file for caltra and run it
602
# Prepare input file for caltra and run it
521
# ---------------------------------------------------------------------
603
# ---------------------------------------------------------------------
522
 
604
 
523
# Set times relative to the reference date
605
# Set times relative to the reference date
524
if ( "${changet}" == "true" ) then
606
if ( "${changet}" == "true" ) then
525
 echo
607
 echo
526
 echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
608
 echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
527
 echo   
609
 echo   
528
 foreach i ( $datfiles )
610
 foreach i ( $datfiles )
529
   ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
611
   ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
530
 end
612
 end
531
 if ( ${sfiles} == 1 ) then
613
 if ( ${sfiles} == 1 ) then
532
   foreach i ( $datfiles )
614
   foreach i ( $datfiles )
533
     ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
615
     ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
534
   end
616
   end
535
 endif
617
 endif
536
endif
618
endif
537
 
619
 
538
# Split the reference date
620
# Split the reference date
539
set yyyy=`echo ${refdate}   | cut -c 1-4` 
621
set yyyy=`echo ${refdate}   | cut -c 1-4` 
540
set   mm=`echo ${refdate}   | cut -c 5-6` 
622
set   mm=`echo ${refdate}   | cut -c 5-6` 
541
set   dd=`echo ${refdate}   | cut -c 7-8` 
623
set   dd=`echo ${refdate}   | cut -c 7-8` 
542
set   hh=`echo ${refdate}   | cut -c 10-11` 
624
set   hh=`echo ${refdate}   | cut -c 10-11` 
543
set  min=`echo ${refdate}00 | cut -c 12-13` 
625
set  min=`echo ${refdate}00 | cut -c 12-13` 
544
 
626
 
545
# Get the total tiem range
627
# Get the total tiem range
546
if ( ${timediff_mm} != '' ) then
628
if ( ${timediff_mm} != '' ) then
547
   @ timerange = 60 * ${timediff_hh} + ${timediff_mm}
629
   @ timerange = 60 * ${timediff_hh} + ${timediff_mm}
548
else
630
else
549
   @ timerange = 60 * ${timediff_hh}
631
   @ timerange = 60 * ${timediff_hh}
550
endif
632
endif
551
 
633
 
552
# Write parameter file
634
# Write parameter file
553
\rm -f ${parfile}
635
\rm -f ${parfile}
554
touch ${parfile}
636
touch ${parfile}
555
 
637
 
556
\echo $idir                   >> $parfile
638
\echo $idir                   >> $parfile
557
echo $numfiles                >> $parfile
639
echo $numfiles                >> $parfile
558
foreach i ( $datfiles )
640
foreach i ( $datfiles )
559
  echo $i                     >> $parfile
641
  echo $i                     >> $parfile
560
end
642
end
561
echo $timeinc                 >> $parfile
643
echo $timeinc                 >> $parfile
562
echo $flag_p                  >> $parfile
644
echo $flag_p                  >> $parfile
563
echo \"${startf}\"            >> $parfile
645
echo \"${startf}\"            >> $parfile
564
echo ${ntra}                  >> $parfile
646
echo ${ntra}                  >> $parfile
565
echo ${ncol}                  >> $parfile
647
echo ${ncol}                  >> $parfile
566
echo \"${outfile}\"           >> $parfile
648
echo \"${outfile}\"           >> $parfile
567
echo $timestep                >> $parfile
649
echo $timestep                >> $parfile
568
echo $tstart                  >> $parfile
650
echo $tstart                  >> $parfile
569
echo $tend                    >> $parfile
651
echo $tend                    >> $parfile
570
echo $deltout                 >> $parfile
652
echo $deltout                 >> $parfile
571
echo $flag_j                  >> $parfile
653
echo $flag_j                  >> $parfile
572
echo $wfactor                 >> $parfile
654
echo $wfactor                 >> $parfile
573
echo $yyyy                    >> $parfile
655
echo $yyyy                    >> $parfile
574
echo $mm                      >> $parfile
656
echo $mm                      >> $parfile
575
echo $dd                      >> $parfile
657
echo $dd                      >> $parfile
576
echo $hh                      >> $parfile
658
echo $hh                      >> $parfile
577
echo $min                     >> $parfile
659
echo $min                     >> $parfile
578
echo $timerange               >> $parfile
660
echo $timerange               >> $parfile
579
echo \"${timecheck}\"         >> $parfile
661
echo \"${timecheck}\"         >> $parfile
580
 
662
 
581
# Finish the preprocessor
663
# Finish the preprocessor
582
echo 
664
echo 
583
echo '       *** END OF PREPROCESSOR CALTRA ***              '
665
echo '       *** END OF PREPROCESSOR CALTRA ***              '
584
echo '========================================================='
666
echo '========================================================='
585
echo
667
echo
586
 
668
 
587
# Run caltra
669
# Run caltra
588
${LAGRANTO}/caltra/caltra
670
${LAGRANTO}/caltra/caltra
589
 
671
 
590
if ( "${status}" != "0" ) then
672
if ( "${status}" != "0" ) then
591
  echo "ERROR:  Program <caltra> failed"
673
  echo "ERROR:  Program <caltra> failed"
592
  exit 1
674
  exit 1
593
endif
675
endif
594
 
676
 
595
# ----------------------------------------------------------
677
# ----------------------------------------------------------
596
# Final tasks (make clean)
678
# Final tasks (make clean)
597
# ----------------------------------------------------------
679
# ----------------------------------------------------------
598
 
680
 
599
finish:
681
finish:
600
 
682
 
601
if ( "${noclean}" == "false" ) then
683
if ( "${noclean}" == "false" ) then
602
  \rm -f ${parfile}
684
  \rm -f ${parfile}
603
 endif
685
 endif
604
 
686
 
605
exit 0 
687
exit 0 
606
 
688