Subversion Repositories lagranto.wrf

Rev

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

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