Subversion Repositories lagranto.wrf

Rev

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

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