Subversion Repositories lagranto.wrf

Rev

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

Rev 21 Rev 23
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=
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-12`
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-12`
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
-
 
277
# flag and convert the timeincement into fractional hour
-
 
278
set flag = `echo ${timeinc} | grep -n '\.'`
-
 
279
set hires = 0
-
 
280
if ( "${flag}" != "" ) then
-
 
281
  echo
-
 
282
  echo "Input files availability < 1 hour ($timeinc): switch to hires"
-
 
283
  echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
-
 
284
  set hires = 1
-
 
285
  set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
-
 
286
  set timeinc     = `echo "scale=2; ${timeinc} * 100 / 60" | bc`
-
 
287
  goto hires
-
 
288
endif
-
 
289
 
276
# 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
277
# 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 
278
# 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  
279
set flag=0
293
set flag=0
280
set td=
294
set td=
281
 
295
 
282
set date = `echo $file | cut -c 2-12`
296
set date = `echo $file | 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
foreach i ( ${charp}????????_?? )
308
foreach i ( ${charp}????????_?? )
295
 
309
 
296
  set date = `echo $i | cut -c 2-12`
310
  set date = `echo $i | cut -c 2-12`
297
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
311
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
298
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
312
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
299
 
313
 
300
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
314
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
301
     set datfiles=$date
315
     set datfiles=$date
302
     if ( $td1 < $timeinc    ) set td=$td1
316
     if ( $td1 < $timeinc    ) set td=$td1
303
     if ( $td2 < $timeinc    ) set td=$td2
317
     if ( $td2 < $timeinc    ) set td=$td2
304
     if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
318
     if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
305
     goto label2      
319
     goto label2      
306
  endif
320
  endif
307
 
321
 
308
end
322
end
309
 
323
 
310
# 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
311
# still undefined
325
# still undefined
312
if ( $td == "" ) then
326
if ( $td == "" ) then
313
  echo " ERROR: no data files available for the specified time period"
327
  echo " ERROR: no data files available for the specified time period"
314
  exit 1
328
  exit 1
315
endif
329
endif
316
 
330
 
-
 
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
-
 
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
-
 
335
# allowed between the model output files
-
 
336
hires:
-
 
337
 
-
 
338
set flag=0
-
 
339
set td=0
-
 
340
 
-
 
341
if ( $direction == "f" ) then
-
 
342
  set file=${charp}${startdate}
-
 
343
else 
-
 
344
  set file=${charp}${enddate}
-
 
345
endif
-
 
346
 
-
 
347
if ( -f $file ) then
-
 
348
  set date     = `echo ${file} | cut -c 2-14`
-
 
349
  set datfiles = $date
-
 
350
  set td       = 0
-
 
351
  goto label2
-
 
352
else
-
 
353
  echo
-
 
354
  echo " ERROR: no data files available for the specified time period"
-
 
355
  exit 1
-
 
356
endif
-
 
357
 
317
# Everything is fine so far: proceed
358
# Everything is fine so far: proceed
318
label2:
359
label2:
319
 
360
 
320
# Check whether first date is ok - before or at needed dates
361
# Check whether first date is ok - before or at needed dates
321
if ( $direction == "f" ) then
362
if ( $direction == "f" ) then
322
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
363
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
323
else
364
else
324
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
365
  set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
325
endif
366
endif
326
  if ( $tdiff0 < 0 ) then
367
  if ( $tdiff0 < 0 ) then
327
  echo " ERROR: data files missing for the specified time period"
368
  echo " ERROR: data files missing for the specified time period"
328
  exit 1
369
  exit 1
329
endif
370
endif
330
 
371
 
331
# Calculate the number of further files
372
# Calculate the number of further files; handle hires (timeinc<1 h) and
-
 
373
# standard mode (timeinc >= 1 h) separately
-
 
374
if ( ${hires} == 0 ) then
332
@ num = ( $timediff_hh + $td ) / $timeinc + 1
375
   @ num = ( $timediff_hh + $td ) / $timeinc + 1
333
@ dum1 = ( $num - 1 ) * $timeinc
376
   @ dum1 = ( $num - 1 ) * $timeinc
334
@ dum2 = $timediff_hh + $td
377
   @ dum2 = $timediff_hh + $td
335
if ( $dum1 != $dum2 ) @ num ++
378
   if ( $dum1 != $dum2 ) @ num ++
-
 
379
else
-
 
380
    set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
-
 
381
endif 
336
 
382
 
337
# Get a list of all needed files
383
# Get a list of all needed files
338
set numfiles=$num
384
set numfiles=$num
339
set sfiles=1
385
set sfiles=1
340
echo $datfiles
386
echo $datfiles 
341
while ( $num > 1 )
387
while ( $num > 1 )
-
 
388
  if ( $hires == 0 ) then
342
  set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
389
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
-
 
390
  else
-
 
391
     echo ${date} ${timeinc_min}
-
 
392
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
-
 
393
  endif
343
 
394
  
344
  echo $date
395
  echo ${date}
345
 
396
  
346
  if ( ! -f ${charp}${date} ) then
397
  if ( ! -f ${charp}${date} ) then
347
    echo " ERROR: file with primary data is missing for $date"
398
    echo " ERROR: file with primary data is missing for $date"
348
    exit 1
399
    exit 1
349
  else if ( ! -f ${chars}${date} ) then
400
  else if ( ! -f ${chars}${date} ) then
350
    set sfiles=0
401
    set sfiles=0
351
    set datfiles=`echo $datfiles $date`
402
    set datfiles=`echo $datfiles $date`
352
  else
403
  else
353
    set datfiles=`echo $datfiles $date`
404
    set datfiles=`echo $datfiles $date`
354
  endif
405
  endif
355
  @ num --
406
  @ num --
356
end
407
end
357
 
408
 
358
# Write some status information
409
# Write some status information
359
echo "Primary file prefix            : ${charp}"
410
echo "Primary file prefix            : ${charp}"
360
echo "Secondary file prefix          : ${chars}"
411
echo "Secondary file prefix          : ${chars}"
-
 
412
if ( ${hires} == 0 ) then
361
echo "Time increment for input files : ${timeinc}"
413
  echo "Time increment for input files : ${timeinc} h"
-
 
414
else
-
 
415
  echo "Time increment for input files : ${timeinc_min} min (0$timeinc h) "
-
 
416
endif
362
echo "# input files                  : ${numfiles}"
417
echo "# input files                  : ${numfiles}"
363
echo "${charp} files availability           : 1"  
418
echo "${charp} files availability           : 1"  
364
echo "${chars} files availability           : ${sfiles}"     
419
echo "${chars} files availability           : ${sfiles}"     
365
echo "First input file               : $datfiles[1] " 
420
echo "First input file               : $datfiles[1] " 
366
echo "Last input file                : $datfiles[$numfiles] " 
421
echo "Last input file                : $datfiles[$numfiles] " 
367
 
422
 
368
# ---------------------------------------------------------------------
423
# ---------------------------------------------------------------------
369
# Handle vertical wind - scaling factor
424
# Handle vertical wind - scaling factor
370
# ---------------------------------------------------------------------
425
# ---------------------------------------------------------------------
371
 
426
 
372
set wfactor=1.
427
set wfactor=1.
373
 
428
 
374
# ---------------------------------------------------------------------
429
# ---------------------------------------------------------------------
375
# Time step and output interval
430
# Time step and output interval
376
# ---------------------------------------------------------------------
431
# ---------------------------------------------------------------------
377
 
432
 
378
echo
433
echo
379
echo '---- TIME STEPS -----------------------------------------'
434
echo '---- TIME STEPS -----------------------------------------'
380
echo
435
echo
381
 
436
 
382
# Take the time step and output step from flag list ('nil', if not defined)
437
# Take the time step and output step from flag list ('nil', if not defined)
383
set timestep = ${flag_t}
438
set timestep = ${flag_t}
384
set deltout  = ${flag_o}
439
set deltout  = ${flag_o}
385
 
440
 
386
# Calculate the time step
441
# Calculate the time step
-
 
442
if ( $hires == 0 ) then
387
if ( $timestep == "nil" ) @ timestep = ( 60 * $timeinc ) / 12
443
  if ( $timestep == "nil" ) @ timestep = ( 60 * $timeinc ) / 12
-
 
444
else
-
 
445
  if ( $timestep == "nil" ) set timestep =  `echo "scale=2; $timeinc_min / 12" | bc`
-
 
446
endif
388
 
447
 
389
# Take the output interval from time increment
448
# Take the output interval from time increment
-
 
449
if ( $hires == 0 ) then
390
if ( $deltout == "nil" ) @ deltout = 60 * ${timeinc}
450
  if ( $deltout == "nil" ) @ deltout = 60 * ${timeinc}
-
 
451
else
-
 
452
  if ( $deltout == "nil" ) set deltout = ${timeinc_min}
-
 
453
endif
391
 
454
 
392
# Check whether the timestep is an integer ratio of deltout
455
# Check whether the timestep is an integer ratio of deltout
393
@ flag = $deltout / $timestep
456
#@ flag = $deltout / $timestep
394
@ flag = $deltout - ( $flag * $timestep )
457
#@ flag = $deltout - ( $flag * $timestep )
-
 
458
set flag = `echo "scale=2; $deltout / $timestep" | bc`
-
 
459
set flag = `echo "scale=2; $deltout - ( $flag * $timestep )" | bc`   
395
if ( $flag != 0 ) then
460
if ( $flag != 0 ) then
396
  echo " ERROR: output time interval should be multiple of timestep"
461
  echo " ERROR: output time interval should be multiple of timestep"
397
  echo 
462
  echo 
398
  echo "           $deltout min  : output time interval"
463
  echo "           $deltout min  : output time interval"
399
  echo "           $timestep min  : time step"
464
  echo "           $timestep min  : time step"
400
  exit 1
465
  exit 1
401
endif
466
endif
402
 
467
 
403
# Calculate the start and the end time relative to the first datfile
468
# Calculate the start and the end time relative to the first datfile
404
if ( $direction == f ) then
469
if ( $direction == f ) then
405
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
470
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
406
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
471
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
407
else
472
else
408
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
473
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
409
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
474
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
410
endif
475
endif
411
 
476
 
412
# Check whether tstart and tend are a multiple of the output time interval
477
# Check whether tstart and tend are a multiple of the output time interval
413
if ( $tstart != 0 ) then
478
if ( $tstart != 0 ) then
414
  if ( `echo $tstart | grep "\."` != "" ) then
479
  if ( `echo $tstart | grep "\."` != "" ) then
415
    set dum=`echo $tstart | sed -e 's/[-0-9]*\.//'`
480
    set dum=`echo $tstart | sed -e 's/[-0-9]*\.//'`
416
    @ flag = $dum / $deltout
481
    @ flag = $dum / $deltout
417
    @ flag = $dum - ( $flag * $deltout )
482
    @ flag = $dum - ( $flag * $deltout )
418
    if ( $flag != 0 ) then
483
    if ( $flag != 0 ) then
419
      echo " ERROR : the start time should be shifted relative to the first"
484
      echo " ERROR : the start time should be shifted relative to the first"
420
      echo "         datafile by a multiple of the output time interval"
485
      echo "         datafile by a multiple of the output time interval"
421
      echo "         hint:  set the latter with the option -o"
486
      echo "         hint:  set the latter with the option -o"
422
      exit 1
487
      exit 1
423
    endif
488
    endif
424
  endif
489
  endif
425
endif
490
endif
426
if ( `echo $tend | grep "\."` != "" ) then
491
if ( `echo $tend | grep "\."` != "" ) then
427
  set dum=`echo $tend | sed -e 's/[-0-9]*\.//'`
492
  set dum=`echo $tend | sed -e 's/[-0-9]*\.//'`
428
  @ flag = $dum / $deltout
493
  @ flag = $dum / $deltout
429
  @ flag = $dum - ( $flag * $deltout )
494
  @ flag = $dum - ( $flag * $deltout )
430
  if ( $flag != 0 ) then
495
  if ( $flag != 0 ) then
431
    echo " ERROR : the end time should be shifted relative to the first"
496
    echo " ERROR : the end time should be shifted relative to the first"
432
    echo "         datafile by a multiple of the output time interval"
497
    echo "         datafile by a multiple of the output time interval"
433
    echo "         hint:  set the latter with the option -o"
498
    echo "         hint:  set the latter with the option -o"
434
    exit 1
499
    exit 1
435
  endif
500
  endif
436
endif
501
endif
437
 
502
 
438
# Write status information
503
# Write status information
439
echo "Trajectory calculation time step [min] : ${timestep}"
504
echo "Trajectory calculation time step [min] : ${timestep}"
440
echo "Output time step [min]                 : ${deltout}"
505
echo "Output time step [min]                 : ${deltout}"
441
if ( $direction == f ) then
506
if ( $direction == f ) then
442
  echo "Start time relative to first file      : $datfiles[1] + ${tstart} "
507
  echo "Start time relative to first file      : $datfiles[1] + ${tstart} "
443
  echo "End time relative to first file        : $datfiles[$numfiles] - ${tend} "  
508
  echo "End time relative to first file        : $datfiles[$numfiles] - ${tend} "  
444
else
509
else
445
  echo "Start time relative to first file      : $datfiles[$numfiles] - ${tstart} "
510
  echo "Start time relative to first file      : $datfiles[$numfiles] - ${tstart} "
446
  echo "End time relative to last file         : $datfiles[1] + ${tend} "
511
  echo "End time relative to last file         : $datfiles[1] + ${tend} "
447
endif
512
endif
448
 
513
 
449
# ---------------------------------------------------------------------
514
# ---------------------------------------------------------------------
450
# Start file
515
# Start file
451
# ---------------------------------------------------------------------
516
# ---------------------------------------------------------------------
452
 
517
 
453
echo
518
echo
454
echo '---- START FILE -----------------------------------------'
519
echo '---- START FILE -----------------------------------------'
455
echo
520
echo
456
 
521
 
457
# Check if start file is available
522
# Check if start file is available
458
if ( ! -f ${startf} ) then
523
if ( ! -f ${startf} ) then
459
   echo " ERROR : start file ${startf} is missing"
524
   echo " ERROR : start file ${startf} is missing"
460
   exit 1
525
   exit 1
461
endif
526
endif
462
 
527
 
463
# Decide whether startfile has an explicit format specifier
528
# Decide whether startfile has an explicit format specifier
464
set format = "0"
529
set format = "0"
465
foreach app ( 1 2 3 4 5 6 7 8 9 )
530
foreach app ( 1 2 3 4 5 6 7 8 9 )
466
  set flag = `echo ${startf} | grep ".${app}"`
531
  set flag = `echo ${startf} | grep ".${app}"`
467
  if ( "${flag}" != "" ) set format = "${app}"
532
  if ( "${flag}" != "" ) set format = "${app}"
468
end
533
end
469
 
534
 
470
# If format is 0, it might nevertheless be a hidden format 1
535
# If format is 0, it might nevertheless be a hidden format 1
471
if ( "${format}" == "0" ) then
536
if ( "${format}" == "0" ) then
472
    set ncol = `awk "{print NF}" ${startf} | tail -1` 
537
    set ncol = `awk "{print NF}" ${startf} | tail -1` 
473
    if ( "${ncol}" != "3" ) then
538
    if ( "${ncol}" != "3" ) then
474
        set format = "1"
539
        set format = "1"
475
        echo " WARNING: ${startf} is a hidden trajectory file of format 1"
540
        echo " WARNING: ${startf} is a hidden trajectory file of format 1"
476
        echo "          it will be renamed: ${startf} -> ${startf}.1"
541
        echo "          it will be renamed: ${startf} -> ${startf}.1"
477
        echo
542
        echo
478
        ln -sf ${startf} ${startf}.1
543
        ln -sf ${startf} ${startf}.1
479
        set startf = "${startf}.1"
544
        set startf = "${startf}.1"
480
    endif
545
    endif
481
endif
546
endif
482
 
547
 
483
# Get the number of trajectories
548
# Get the number of trajectories
484
if ( "${format}" == "0" ) then
549
if ( "${format}" == "0" ) then
485
   set ntra = `wc -l ${startf} | awk '{print $1}' `
550
   set ntra = `wc -l ${startf} | awk '{print $1}' `
486
   set ncol = 3
551
   set ncol = 3
487
else
552
else
488
   set ntra = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntra`
553
   set ntra = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntra`
489
   set ncol = `${LAGRANTO}/goodies/trainfo.sh ${startf} ncol`
554
   set ncol = `${LAGRANTO}/goodies/trainfo.sh ${startf} ncol`
490
   set ntim = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntim`
555
   set ntim = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntim`
491
   
556
   
492
   if ( "${ntim}" != "1" ) then
557
   if ( "${ntim}" != "1" ) then
493
      echo " ERROR: starting trajectory file must only have one time... Stop"
558
      echo " ERROR: starting trajectory file must only have one time... Stop"
494
      exit 1
559
      exit 1
495
   endif
560
   endif
496
 
561
 
497
endif
562
endif
498
 
563
 
499
# Write status information
564
# Write status information
500
echo "Start file                  : ${startf} "
565
echo "Start file                  : ${startf} "
501
if ( "${format}" == "0" ) then 
566
if ( "${format}" == "0" ) then 
502
   echo "Format                      : (x,y,z) list"
567
   echo "Format                      : (x,y,z) list"
503
else
568
else
504
   echo "Format                      : trajectory file (${format})"
569
   echo "Format                      : trajectory file (${format})"
505
endif
570
endif
506
echo "# coordinates (lon,lat,lev) : ${ntra} "  
571
echo "# coordinates (lon,lat,lev) : ${ntra} "  
507
echo "# columns                   : ${ncol} "  
572
echo "# columns                   : ${ncol} "  
508
 
573
 
509
# ---------------------------------------------------------------------
574
# ---------------------------------------------------------------------
510
# Prepare input file for caltra and run it
575
# Prepare input file for caltra and run it
511
# ---------------------------------------------------------------------
576
# ---------------------------------------------------------------------
512
 
577
 
513
# Split the reference date
578
# Split the reference date
514
set yyyy=`echo ${refdate}   | cut -c 1-4` 
579
set yyyy=`echo ${refdate}   | cut -c 1-4` 
515
set   mm=`echo ${refdate}   | cut -c 5-6` 
580
set   mm=`echo ${refdate}   | cut -c 5-6` 
516
set   dd=`echo ${refdate}   | cut -c 7-8` 
581
set   dd=`echo ${refdate}   | cut -c 7-8` 
517
set   hh=`echo ${refdate}   | cut -c 10-11` 
582
set   hh=`echo ${refdate}   | cut -c 10-11` 
518
set  min=`echo ${refdate}00 | cut -c 12-13` 
583
set  min=`echo ${refdate}00 | cut -c 12-13` 
519
 
584
 
520
# Get the total tiem range
585
# Get the total tiem range
521
if ( ${timediff_mm} != '' ) then
586
if ( ${timediff_mm} != '' ) then
522
   @ timerange = 60 * ${timediff_hh} + ${timediff_mm}
587
   @ timerange = 60 * ${timediff_hh} + ${timediff_mm}
523
else
588
else
524
   @ timerange = 60 * ${timediff_hh}
589
   @ timerange = 60 * ${timediff_hh}
525
endif
590
endif
526
 
591
 
527
# Write parameter file
592
# Write parameter file
528
\rm -f ${parfile}
593
\rm -f ${parfile}
529
touch ${parfile}
594
touch ${parfile}
530
 
595
 
531
\echo $idir                   >> $parfile
596
\echo $idir                   >> $parfile
532
echo $numfiles                >> $parfile
597
echo $numfiles                >> $parfile
533
foreach i ( $datfiles )
598
foreach i ( $datfiles )
534
  echo $i                     >> $parfile
599
  echo $i                     >> $parfile
535
end
600
end
536
echo $timeinc                 >> $parfile
601
echo $timeinc                 >> $parfile
537
echo $flag_p                  >> $parfile
602
echo $flag_p                  >> $parfile
538
echo \"${startf}\"            >> $parfile
603
echo \"${startf}\"            >> $parfile
539
echo ${ntra}                  >> $parfile
604
echo ${ntra}                  >> $parfile
540
echo ${ncol}                  >> $parfile
605
echo ${ncol}                  >> $parfile
541
echo \"${outfile}\"           >> $parfile
606
echo \"${outfile}\"           >> $parfile
542
echo $timestep                >> $parfile
607
echo $timestep                >> $parfile
543
echo $tstart                  >> $parfile
608
echo $tstart                  >> $parfile
544
echo $tend                    >> $parfile
609
echo $tend                    >> $parfile
545
echo $deltout                 >> $parfile
610
echo $deltout                 >> $parfile
546
echo $flag_j                  >> $parfile
611
echo $flag_j                  >> $parfile
547
echo $wfactor                 >> $parfile
612
echo $wfactor                 >> $parfile
548
echo $yyyy                    >> $parfile
613
echo $yyyy                    >> $parfile
549
echo $mm                      >> $parfile
614
echo $mm                      >> $parfile
550
echo $dd                      >> $parfile
615
echo $dd                      >> $parfile
551
echo $hh                      >> $parfile
616
echo $hh                      >> $parfile
552
echo $min                     >> $parfile
617
echo $min                     >> $parfile
553
echo $timerange               >> $parfile
618
echo $timerange               >> $parfile
554
echo \"${timecheck}\"         >> $parfile
619
echo \"${timecheck}\"         >> $parfile
555
echo ${flag_agl}              >> $parfile
620
echo ${flag_agl}              >> $parfile
556
echo ${flag_isen}             >> $parfile
621
echo ${flag_isen}             >> $parfile
557
 
622
 
558
# Finish the preprocessor
623
# Finish the preprocessor
559
echo 
624
echo 
560
echo '       *** END OF PREPROCESSOR CALTRA ***              '
625
echo '       *** END OF PREPROCESSOR CALTRA ***              '
561
echo '========================================================='
626
echo '========================================================='
562
echo
627
echo
563
 
628
 
564
# Run caltra
629
# Run caltra
565
${LAGRANTO}/caltra/caltra
630
${LAGRANTO}/caltra/caltra
566
 
631
 
567
if ( "${status}" != "0" ) then
632
if ( "${status}" != "0" ) then
568
  echo "ERROR:  Program <caltra> failed"
633
  echo "ERROR:  Program <caltra> failed"
569
  exit 1
634
  exit 1
570
endif
635
endif
571
 
636
 
572
# ----------------------------------------------------------
637
# ----------------------------------------------------------
573
# Final tasks (make clean)
638
# Final tasks (make clean)
574
# ----------------------------------------------------------
639
# ----------------------------------------------------------
575
 
640
 
576
finish:
641
finish:
577
 
642
 
578
if ( "${noclean}" == "false" ) then
643
if ( "${noclean}" == "false" ) then
579
  \rm -f ${parfile}
644
  \rm -f ${parfile}
580
 endif
645
 endif
581
 
646
 
582
exit 0 
647
exit 0 
583
 
648