Subversion Repositories lagranto.wrf

Rev

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

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