Subversion Repositories lagranto.wrf

Rev

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

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