Subversion Repositories lagranto.um

Rev

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

Rev 13 Rev 15
1
#!/bin/csh
1
#!/bin/csh
2
 
2
 
-
 
3
# Set Lagranto 
-
 
4
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
-
 
5
 
3
# ---------------------------------------------------------------------
6
# ---------------------------------------------------------------------
4
# Usage, parameter settings
7
# Usage, parameter settings
5
# ---------------------------------------------------------------------
8
# ---------------------------------------------------------------------
6
 
9
 
7
# Write usage information
10
# Write usage information
8
if ( (${#argv} == 0) | (${#argv} < 2) ) then
11
if ( (${#argv} == 0) | (${#argv} < 2) ) then
9
  echo 
12
  echo 
10
  echo "--------------------------------------------------------------"
13
  echo "--------------------------------------------------------------"
11
  echo " Usage: trace.sh inpfile outfile [flags]        "
14
  echo " Usage: trace.sh inpfile outfile [flags]        "
12
  echo 
15
  echo 
13
  echo "        inpfile   : Input trajectory file                     "
16
  echo "        inpfile   : Input trajectory file                     "
14
  echo "        outfile   : Output trajectory file                    "
17
  echo "        outfile   : Output trajectory file                    "
15
  echo "        [ flags ] : Optional list of flags                    "
18
  echo "        [ flags ] : Optional list of flags                    "
16
  echo
19
  echo
17
  echo " Optional flags                                               "
20
  echo " Optional flags                                               "
18
  echo
21
  echo
19
  echo "        -i hours     : Time increment for input files in hours"
22
  echo "        -i hours     : Time increment for input files in hours"
20
  echo "        -v filename  : Name of tracing file                   "
23
  echo "        -v filename  : Name of tracing file                   "
21
  echo "        -f var scale : Trace field <var> with scaling <scale> "
24
  echo "        -f var scale : Trace field <var> with scaling <scale> "
22
  echo "        -changet     : change times on P,S files before calculation" 
25
  echo "        -changet     : change times on P,S files before calculation" 
23
  echo "        -noclean     : do not remove temporary files"
26
  echo "        -noclean     : do not remove temporary files"
24
  echo 
27
  echo 
25
  echo " Tracing variables must be available on file <tracevars>, if not"
28
  echo " Tracing variables must be available on file <tracevars>, if not"
26
  echo " provided with "-f" option. The format of the <tracevars> file is"
29
  echo " provided with "-f" option. The format of the <tracevars> file is"
27
  echo  
30
  echo  
28
  echo "           varname   scale    compflag[0|1]   prefix[P|S]     "
31
  echo "           varname   scale    compflag[0|1]   prefix[P|S]     "
29
  echo
32
  echo
30
  echo " The tracing variables have the following form                "
33
  echo " The tracing variables have the following form                "
31
  echo 
34
  echo 
32
  echo "             varname[:shift] with <shift> as + 100 km[lat]    "
35
  echo "             varname[:shift] with <shift> as + 100 km[lat]    "
33
  echo "                                             - 100 km[lon]    "
36
  echo "                                             - 100 km[lon]    "
34
  echo "                                             + 2 dlon         "
37
  echo "                                             + 2 dlon         "
35
  echo "                                             - 2 dlat         "
38
  echo "                                             - 2 dlat         "
36
  echo "                                             + 50 hPa         "
39
  echo "                                             + 50 hPa         "
37
  echo "                                             - 1 dp           "
40
  echo "                                             - 1 dp           "
38
  echo "                                             + 6 h            "
41
  echo "                                             + 6 h            "
39
  echo "                                             - 180 min        "
42
  echo "                                             - 180 min        "
40
  echo
43
  echo
41
  echo " The following fields can be computed 'online':               "
44
  echo " The following fields can be computed 'online':               "
42
  echo
45
  echo
43
  echo " TH, RHO, RH, THE, LHR, DUDX, DVDX, DTDX, DUDY, DVDY, DTDY,    " 
46
  echo " TH, RHO, RH, THE, LHR, DUDX, DVDX, DTDX, DUDY, DVDY, DTDY,    " 
44
  echo " DUDP, DVDP, DTDP, DTHDP, NSQ, RELVORT, ABSVORT, DIV, DTHDX,"
47
  echo " DUDP, DVDP, DTDP, DTHDP, NSQ, RELVORT, ABSVORT, DIV, DTHDX,"
45
  echo " DTHDY, PV, RI, TI"
48
  echo " DTHDY, PV, RI, TI"
46
  echo "--------------------------------------------------------------"
49
  echo "--------------------------------------------------------------"
47
  exit 0
50
  exit 0
48
endif
51
endif
49
 
52
 
50
# Write title
53
# Write title
51
echo 
54
echo 
52
echo '========================================================='
55
echo '========================================================='
53
echo '       *** START OF PREPROCESSOR TRACE ***              '
56
echo '       *** START OF PREPROCESSOR TRACE ***              '
54
echo
57
echo
55
 
58
 
56
# Get the arguments
59
# Get the arguments
57
set inpfile   = $1
60
set inpfile   = $1
58
set outfile   = $2
61
set outfile   = $2
59
 
62
 
60
# Set base directories (run+prog)
63
# Set base directories (run+prog)
61
set cdfdir=${PWD}
64
set cdfdir=${PWD}
62
set tradir=${PWD}
65
set tradir=${PWD}
63
 
66
 
64
# Set program paths and filenames 
67
# Set program paths and filenames 
65
set parfile = ${tradir}/trace.param 
68
set parfile = ${tradir}/trace.param 
66
set prog    = ${LAGRANTO}/trace/trace
69
set prog    = ${LAGRANTO}/trace/trace
67
 
70
 
68
# Set the prefix of the primary and secondary data files
71
# Set the prefix of the primary and secondary data files
69
set charp = 'P'
72
set charp = 'P'
70
set chars = 'S'
73
set chars = 'S'
71
 
74
 
72
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
75
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
73
echo    
76
echo    
74
echo "CDF directory         : ${cdfdir}"
77
echo "CDF directory         : ${cdfdir}"
75
echo "TRA directory         : ${tradir}"
78
echo "TRA directory         : ${tradir}"
76
echo "PROGRAM TRACE         : ${prog}"
79
echo "PROGRAM TRACE         : ${prog}"
77
echo "PARAMETER file        : ${parfile}"
80
echo "PARAMETER file        : ${parfile}"
78
echo
81
echo
79
 
82
 
80
# ---------------------------------------------------------------------
83
# ---------------------------------------------------------------------
81
# Set optional flags
84
# Set optional flags
82
# ---------------------------------------------------------------------
85
# ---------------------------------------------------------------------
83
 
86
 
84
echo '---- OPTIONAL FLAGS -------------------------------------'
87
echo '---- OPTIONAL FLAGS -------------------------------------'
85
echo
88
echo
86
 
89
 
87
# Set some default values ("nil" must be set according to input files)
90
# Set some default values ("nil" must be set according to input files)
88
set flag_i     = "nil"
91
set flag_i     = "nil"
89
set flag_v     = "tracevars"
92
set flag_v     = "tracevars"
90
set flag_f     = "nil"
93
set flag_f     = "nil"
91
set tvfile     = 'tracevars'
94
set tvfile     = 'tracevars'
92
set changet    = 'false'
95
set changet    = 'false'
93
set noclean    = 'false'
96
set noclean    = 'false'
94
set timecheck  = 'yes' 
97
set timecheck  = 'yes' 
95
 
98
 
96
# Set flag for consitency
99
# Set flag for consitency
97
set isok = 1
100
set isok = 1
98
 
101
 
99
while ( $#argv > 0 )
102
while ( $#argv > 0 )
100
 
103
 
101
  switch ( $argv[1] )
104
  switch ( $argv[1] )
102
 
105
 
103
   case -i
106
   case -i
104
     set flag_i=$argv[2]
107
     set flag_i=$argv[2]
105
     echo "Flag '-i'     -> ${flag_i} (user defined)"
108
     echo "Flag '-i'     -> ${flag_i} (user defined)"
106
     shift;
109
     shift;
107
   breaksw
110
   breaksw
108
 
111
 
109
   case -v
112
   case -v
110
     set flag_v="-v"
113
     set flag_v="-v"
111
     set tvfile=$argv[2]
114
     set tvfile=$argv[2]
112
     echo "Flag '-v'     -> ${tvfile} (user defined)"
115
     echo "Flag '-v'     -> ${tvfile} (user defined)"
113
     shift;
116
     shift;
114
     if ( $isok == 2 ) set isok = 0
117
     if ( $isok == 2 ) set isok = 0
115
     if ( $isok == 1 ) set isok = 2
118
     if ( $isok == 1 ) set isok = 2
116
   breaksw
119
   breaksw
117
 
120
 
118
   case -f
121
   case -f
119
     set flag_f="-f"
122
     set flag_f="-f"
120
     set tvfile="tracevars.tmp"
123
     set tvfile="tracevars.tmp"
121
     shift;
124
     shift;
122
     set tvar="$argv[1]"
125
     set tvar="$argv[1]"
123
     shift;
126
     shift;
124
     set tscale="$argv[1]"
127
     set tscale="$argv[1]"
125
     echo "Flag '-f'     -> ${tvar} ${tscale} (user defined)"
128
     echo "Flag '-f'     -> ${tvar} ${tscale} (user defined)"
126
     if ( $isok == 2 ) set isok = 0
129
     if ( $isok == 2 ) set isok = 0
127
     if ( $isok == 1 ) set isok = 2
130
     if ( $isok == 1 ) set isok = 2
128
   breaksw
131
   breaksw
129
 
132
 
130
   case -changet
133
   case -changet
131
     set changet = 'true'
134
     set changet = 'true'
132
     echo "changet       -> true (user defined)"
135
     echo "changet       -> true (user defined)"
133
   breaksw
136
   breaksw
134
 
137
 
135
   case -noclean
138
   case -noclean
136
     set noclean = 'true'
139
     set noclean = 'true'
137
     echo "noclean       -> true (user defined)"
140
     echo "noclean       -> true (user defined)"
138
   breaksw
141
   breaksw
139
 
142
 
140
   case -notimecheck
143
   case -notimecheck
141
     set timecheck = 'no'
144
     set timecheck = 'no'
142
     echo "timecheck               -> no (user defined)"
145
     echo "timecheck               -> no (user defined)"
143
   breaksw
146
   breaksw
144
 
147
 
145
  endsw
148
  endsw
146
 
149
 
147
  shift;
150
  shift;
148
 
151
 
149
end
152
end
150
 
153
 
151
# No change of times necessary if no check requested
154
# No change of times necessary if no check requested
152
if ( "${timecheck}" == "no" ) then
155
if ( "${timecheck}" == "no" ) then
153
   set  changet = 'false'
156
   set  changet = 'false'
154
endif
157
endif
155
 
158
 
156
# Check consitency of arguments
159
# Check consitency of arguments
157
if ( $isok == 0 ) then
160
if ( $isok == 0 ) then
158
    echo
161
    echo
159
    echo " ERROR: Use either option '-v' or '-f', but not both..."
162
    echo " ERROR: Use either option '-v' or '-f', but not both..."
160
    exit 1
163
    exit 1
161
endif
164
endif
162
 
165
 
163
# ---------------------------------------------------------------------
166
# ---------------------------------------------------------------------
164
# Handle the input trajectory file
167
# Handle the input trajectory file
165
# ---------------------------------------------------------------------
168
# ---------------------------------------------------------------------
166
 
169
 
167
echo
170
echo
168
echo '---- TIME RANGE -----------------------------------------'
171
echo '---- TIME RANGE -----------------------------------------'
169
echo
172
echo
170
 
173
 
171
# Check whether the input file can be found
174
# Check whether the input file can be found
172
if ( ! -f ${inpfile} ) then
175
if ( ! -f ${inpfile} ) then
173
    echo " ERROR : Input file ${inpfile} is missing"
176
    echo " ERROR : Input file ${inpfile} is missing"
174
    exit 1
177
    exit 1
175
endif
178
endif
176
 
179
 
177
# Get the start, end and reference date for the tracing
180
# Get the start, end and reference date for the tracing
178
set startdate = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} startdate` 
181
set startdate = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} startdate` 
179
set enddate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} enddate` 
182
set enddate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} enddate` 
180
set refdate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} refdate` 
183
set refdate   = `${LAGRANTO}/goodies/trainfo.sh ${inpfile} refdate` 
181
set ntra      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntra`
184
set ntra      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntra`
182
set ntim      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntim`
185
set ntim      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ntim`
183
set ncol      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ncol`
186
set ncol      =  `${LAGRANTO}/goodies/trainfo.sh ${inpfile} ncol`
184
 
187
 
185
# Check format of start and end date - must be the same
188
# Check format of start and end date - must be the same
186
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
189
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
187
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
190
set ne=`echo $enddate   | sed -e 's/_[0-9]*//' | wc -c`
188
if ( $ns != $ne ) then
191
if ( $ns != $ne ) then
189
  echo " ERROR: start and end date must be in the same format ***"
192
  echo " ERROR: start and end date must be in the same format ***"
190
  exit 1
193
  exit 1
191
endif
194
endif
192
if ( $ns != 9 ) then
195
if ( $ns != 9 ) then
193
  echo " ERROR: Date format must be yyyymmdd ***"
196
  echo " ERROR: Date format must be yyyymmdd ***"
194
  exit 1
197
  exit 1
195
endif
198
endif
196
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
199
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
197
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
200
set ne=`echo $enddate   | sed -e 's/[0-9]*_//' | wc -c`
198
if ( $ns != $ne ) then
201
if ( $ns != $ne ) then
199
  echo " ERROR: start and end date must be in the same format ***"
202
  echo " ERROR: start and end date must be in the same format ***"
200
  exit 1
203
  exit 1
201
endif
204
endif
202
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
205
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
203
  echo " ERROR: Time format must be hh(mm) ***"
206
  echo " ERROR: Time format must be hh(mm) ***"
204
  exit 1
207
  exit 1
205
endif
208
endif
206
 
209
 
207
# Split the start and end date into <yymmdd_hh and mm>
210
# Split the start and end date into <yymmdd_hh and mm>
208
set startdate_ymdh = `echo $startdate | cut -c 1-11`
211
set startdate_ymdh = `echo $startdate | cut -c 1-11`
209
set startdate_min  = `echo $startdate | cut -c 12-13`
212
set startdate_min  = `echo $startdate | cut -c 12-13`
210
if ( $startdate_min == "" ) set startdate_min = 00
213
if ( $startdate_min == "" ) set startdate_min = 00
211
 
214
 
212
set enddate_ymdh = `echo $enddate | cut -c 1-11`
215
set enddate_ymdh = `echo $enddate | cut -c 1-11`
213
set enddate_min  = `echo $enddate | cut -c 12-13`
216
set enddate_min  = `echo $enddate | cut -c 12-13`
214
if ( $enddate_min == "" ) set enddate_min = 00
217
if ( $enddate_min == "" ) set enddate_min = 00
215
 
218
 
216
# Get the time difference between <start_ymdh> and <end_ymdh> date
219
# Get the time difference between <start_ymdh> and <end_ymdh> date
217
# Decide whether trajectoriesare forward or backward
220
# Decide whether trajectoriesare forward or backward
218
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
221
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
219
 
222
 
220
if ( $timediff_hh == 0 ) then
223
if ( $timediff_hh == 0 ) then
221
  if ( $enddate_min > $startdate_min ) then
224
  if ( $enddate_min > $startdate_min ) then
222
    set direction = f
225
    set direction = f
223
    set idir      = 1
226
    set idir      = 1
224
  else
227
  else
225
    set direction = b
228
    set direction = b
226
    set idir      = -1
229
    set idir      = -1
227
  endif
230
  endif
228
else if ( $timediff_hh > 0 ) then
231
else if ( $timediff_hh > 0 ) then
229
  set direction = f
232
  set direction = f
230
  set idir      = 1
233
  set idir      = 1
231
else
234
else
232
  set direction = b
235
  set direction = b
233
  set idir      = -1
236
  set idir      = -1
234
  @ timediff_hh = $idir * $timediff_hh
237
  @ timediff_hh = $idir * $timediff_hh
235
endif
238
endif
236
 
239
 
237
# Get also minutes for time difference, if <start_min> or <end_min> != 0
240
# Get also minutes for time difference, if <start_min> or <end_min> != 0
238
set timediff_mm=
241
set timediff_mm=
239
 
242
 
240
if ( $startdate_min != 00 || $enddate_min != 00 ) then
243
if ( $startdate_min != 00 || $enddate_min != 00 ) then
241
  @ min = ( $enddate_min - $startdate_min )
244
  @ min = ( $enddate_min - $startdate_min )
242
  if ( $min == 0 ) then
245
  if ( $min == 0 ) then
243
    set timediff_mm=
246
    set timediff_mm=
244
  else if ( $min > 0 ) then
247
  else if ( $min > 0 ) then
245
    if ( $idir == 1 ) then
248
    if ( $idir == 1 ) then
246
      set timediff_mm=$min
249
      set timediff_mm=$min
247
    else
250
    else
248
      @ timediff_hh --
251
      @ timediff_hh --
249
      @ timediff_mm = 60 - $min
252
      @ timediff_mm = 60 - $min
250
    endif
253
    endif
251
  else
254
  else
252
    if ( $idir == 1 ) then
255
    if ( $idir == 1 ) then
253
      @ timediff_hh --
256
      @ timediff_hh --
254
      @ timediff_mm = 60 + $min
257
      @ timediff_mm = 60 + $min
255
    else
258
    else
256
      @ timediff_mm = 0 - $min
259
      @ timediff_mm = 0 - $min
257
    endif
260
    endif
258
  endif
261
  endif
259
else
262
else
260
  set timediff_mm = 0
263
  set timediff_mm = 0
261
endif
264
endif
262
 
265
 
263
# Write status information
266
# Write status information
264
echo "Time range      : ${startdate} -> ${enddate}"
267
echo "Time range      : ${startdate} -> ${enddate}"
265
if ( ${timediff_mm} != "" ) then
268
if ( ${timediff_mm} != "" ) then
266
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
269
   echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
267
else
270
else
268
   echo "Time difference : ${timediff_hh} h"
271
   echo "Time difference : ${timediff_hh} h"
269
endif
272
endif
270
echo "Direction       : ${direction} (${idir})"
273
echo "Direction       : ${direction} (${idir})"
271
 
274
 
272
# ---------------------------------------------------------------------
275
# ---------------------------------------------------------------------
273
# Check availability of input data 
276
# Check availability of input data 
274
# ---------------------------------------------------------------------
277
# ---------------------------------------------------------------------
275
 
278
 
276
echo
279
echo
277
echo '---- INPUT FILES ----------------------------------------'
280
echo '---- INPUT FILES ----------------------------------------'
278
echo
281
echo
279
 
282
 
280
# Take the time increment from flag list ('nil', if not defined)
283
# Take the time increment from flag list ('nil', if not defined)
281
set timeinc = ${flag_i}
284
set timeinc = ${flag_i}
282
 
285
 
283
# Find a first data file (if possible corresponding to start/end date
286
# Find a first data file (if possible corresponding to start/end date
284
# If starttime is not a data time, take the first file in the direectory
287
# If starttime is not a data time, take the first file in the direectory
285
if ( $direction == "f" ) then
288
if ( $direction == "f" ) then
286
  set file=${charp}${startdate_ymdh}
289
  set file=${charp}${startdate_ymdh}
287
else
290
else
288
  set file=${charp}${enddate_ymdh}
291
  set file=${charp}${enddate_ymdh}
289
endif
292
endif
290
if ( ! -f $file ) then
293
if ( ! -f $file ) then
291
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
294
  set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
292
endif
295
endif
293
 
296
 
294
# Determine timeinc (the time difference in hours between two data file)
297
# Determine timeinc (the time difference in hours between two data file)
295
# if not already defined with option -i
298
# if not already defined with option -i
296
if ( ${timeinc} == "nil" ) then
299
if ( ${timeinc} == "nil" ) then
297
  set date1=`echo $file | cut -c 2-`
300
  set date1=`echo $file | cut -c 2-`
298
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
301
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
299
  @ n ++
302
  @ n ++
300
  set date2=`\ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
303
  set date2=`\ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
301
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
304
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
302
endif
305
endif
303
if ( $timeinc == 0 ) then
306
if ( $timeinc == 0 ) then
304
    echo " ERROR: cannot set the time increment between input files ***"
307
    echo " ERROR: cannot set the time increment between input files ***"
305
    exit 1
308
    exit 1
306
endif
309
endif
307
 
310
 
308
# Decide whether the time increment is smaller than 1 h; if so set the hires
311
# Decide whether the time increment is smaller than 1 h; if so set the hires
309
# flag and convert the timeincement into fractional hour
312
# flag and convert the timeincement into fractional hour
310
set flag = `echo ${timeinc} | grep -n '\.'`
313
set flag = `echo ${timeinc} | grep -n '\.'`
311
set hires = 0
314
set hires = 0
312
if ( "${flag}" != "" ) then
315
if ( "${flag}" != "" ) then
313
  echo "Input files availability < 1 hour ($timeinc): switch to hires"
316
  echo "Input files availability < 1 hour ($timeinc): switch to hires"
314
  echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
317
  echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
315
  set hires = 1
318
  set hires = 1
316
  set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
319
  set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
317
  set timeinc     = `echo "scale=8; ${timeinc} * 100 / 60" | bc`
320
  set timeinc     = `echo "scale=8; ${timeinc} * 100 / 60" | bc`
318
  goto hires
321
  goto hires
319
endif
322
endif
320
 
323
 
321
## Search the first file to use: We step through all P files and see whether they are
324
## Search the first file to use: We step through all P files and see whether they are
322
# good P files. Let's first do the test for the first data file found. If it's ok, we 
325
# good P files. Let's first do the test for the first data file found. If it's ok, we 
323
# take it; if not, we step through all P files and find the good one  
326
# take it; if not, we step through all P files and find the good one  
324
set flag=0
327
set flag=0
325
set td=
328
set td=
326
 
329
 
327
set date = `echo $file | cut -c 2-12`
330
set date = `echo $file | cut -c 2-12`
328
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
331
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
329
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
332
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
330
 
333
 
331
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
334
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
332
   set datfiles=$date
335
   set datfiles=$date
333
   if ( $td1 < $timeinc    ) set td=$td1
336
   if ( $td1 < $timeinc    ) set td=$td1
334
   if ( $td2 < $timeinc    ) set td=$td2
337
   if ( $td2 < $timeinc    ) set td=$td2
335
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
338
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
336
   goto label2      
339
   goto label2      
337
endif
340
endif
338
 
341
 
339
foreach i ( ${charp}????????_?? )
342
foreach i ( ${charp}????????_?? )
340
 
343
 
341
  set date = `echo $i | cut -c 2-12`
344
  set date = `echo $i | cut -c 2-12`
342
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
345
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
343
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
346
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
344
 
347
 
345
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
348
  if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
346
      set datfiles=$date
349
      set datfiles=$date
347
      if ( $td1 < $timeinc    ) set td=$td1
350
      if ( $td1 < $timeinc    ) set td=$td1
348
      if ( $td2 < $timeinc    ) set td=$td2
351
      if ( $td2 < $timeinc    ) set td=$td2
349
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
352
      if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
350
      goto label2
353
      goto label2
351
  endif
354
  endif
352
 
355
 
353
end
356
end
354
 
357
 
355
if ( $td == "" ) then
358
if ( $td == "" ) then
356
  echo " ERROR: no data files available for the specified time period"
359
  echo " ERROR: no data files available for the specified time period"
357
  exit 1
360
  exit 1
358
endif
361
endif
359
 
362
 
360
# If the input files come with time increment < 1 hour, handle it in this
363
# If the input files come with time increment < 1 hour, handle it in this
361
# special section. The aim is not to 'interfere' with the well established
364
# special section. The aim is not to 'interfere' with the well established
362
# code handling the standard case with time increment >= 1 hour. In this mode
365
# code handling the standard case with time increment >= 1 hour. In this mode
363
# we require that the start and end date are available as P files: no start is
366
# we require that the start and end date are available as P files: no start is
364
# allowed between the model output files
367
# allowed between the model output files
365
hires:
368
hires:
366
 
369
 
367
set flag=0
370
set flag=0
368
set td=0
371
set td=0
369
 
372
 
370
if ( $direction == "f" ) then
373
if ( $direction == "f" ) then
371
  set file=${charp}${startdate}
374
  set file=${charp}${startdate}
372
else 
375
else 
373
  set file=${charp}${enddate}
376
  set file=${charp}${enddate}
374
endif
377
endif
375
 
378
 
376
if ( -f $file ) then
379
if ( -f $file ) then
377
  set date     = `echo ${file} | cut -c 2-14`
380
  set date     = `echo ${file} | cut -c 2-14`
378
  set datfiles = $date
381
  set datfiles = $date
379
  set td       = 0
382
  set td       = 0
380
  goto label2
383
  goto label2
381
else
384
else
382
  echo
385
  echo
383
  echo " ERROR: no data files available for the specified time period"
386
  echo " ERROR: no data files available for the specified time period"
384
  exit 1
387
  exit 1
385
endif
388
endif
386
 
389
 
387
# Everything is fine so far: proceed
390
# Everything is fine so far: proceed
388
label2:
391
label2:
389
 
392
 
390
# Calculate the number of further files; handle hires (timeinc<1 h) and
393
# Calculate the number of further files; handle hires (timeinc<1 h) and
391
# standard mode (timeinc >= 1 h) separately
394
# standard mode (timeinc >= 1 h) separately
392
if ( ${hires} == 0 ) then
395
if ( ${hires} == 0 ) then
393
 @ num = ( $timediff_hh + $td ) / $timeinc + 1
396
 @ num = ( $timediff_hh + $td ) / $timeinc + 1
394
 @ dum1 = ( $num - 1 ) * $timeinc
397
 @ dum1 = ( $num - 1 ) * $timeinc
395
 @ dum2 = $timediff_hh + $td
398
 @ dum2 = $timediff_hh + $td
396
 if ( $dum1 != $dum2 ) @ num ++
399
 if ( $dum1 != $dum2 ) @ num ++
397
else
400
else
398
 set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
401
 set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
399
endif 
402
endif 
400
 
403
 
401
# Get a list of all needed files
404
# Get a list of all needed files
402
set numfiles=$num
405
set numfiles=$num
403
set sfiles=1
406
set sfiles=1
404
echo $datfiles
407
echo $datfiles
405
while ( $num > 1 )
408
while ( $num > 1 )
406
  if ( $hires == 0 ) then
409
  if ( $hires == 0 ) then
407
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
410
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
408
  else
411
  else
409
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
412
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
410
  endif
413
  endif
411
  if ( ! -f ${charp}${date} ) then
414
  if ( ! -f ${charp}${date} ) then
412
    echo " ERROR: file with primary data is missing for $date"
415
    echo " ERROR: file with primary data is missing for $date"
413
    exit 1
416
    exit 1
414
  else if ( ! -f ${chars}${date} ) then
417
  else if ( ! -f ${chars}${date} ) then
415
    set sfiles=0
418
    set sfiles=0
416
    set datfiles=`echo $datfiles $date`
419
    set datfiles=`echo $datfiles $date`
417
  else
420
  else
418
    set datfiles=`echo $datfiles $date`
421
    set datfiles=`echo $datfiles $date`
419
  endif
422
  endif
420
  @ num --
423
  @ num --
421
end
424
end
422
 
425
 
423
# Calculate the start and the end time relative to the first datfile
426
# Calculate the start and the end time relative to the first datfile
424
if ( $direction == f ) then
427
if ( $direction == f ) then
425
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
428
  set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
426
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
429
  set tend   = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
427
else
430
else
428
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
431
  set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
429
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
432
  set tend   = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
430
endif
433
endif
431
 
434
 
432
 
435
 
433
# Write some status information
436
# Write some status information
434
echo "Primary file prefix               : ${charp}"
437
echo "Primary file prefix               : ${charp}"
435
echo "Secondary file prefix             : ${chars}"
438
echo "Secondary file prefix             : ${chars}"
436
if ( ${hires} == 0 ) then
439
if ( ${hires} == 0 ) then
437
  echo "Time increment for input files    : ${timeinc} h"
440
  echo "Time increment for input files    : ${timeinc} h"
438
else
441
else
439
  echo "Time increment for input files    : ${timeinc_min} min (0$timeinc h) "
442
  echo "Time increment for input files    : ${timeinc_min} min (0$timeinc h) "
440
endif
443
endif
441
echo "# input files                     : ${numfiles}"
444
echo "# input files                     : ${numfiles}"
442
echo "First input file                  : $datfiles[1] " 
445
echo "First input file                  : $datfiles[1] " 
443
echo "Last input file                   : $datfiles[$numfiles] " 
446
echo "Last input file                   : $datfiles[$numfiles] " 
444
echo "${charp} files availability              : 1"  
447
echo "${charp} files availability              : 1"  
445
echo "${chars} files availability              : ${sfiles}"     
448
echo "${chars} files availability              : ${sfiles}"     
446
if ( $direction == f ) then
449
if ( $direction == f ) then
447
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
450
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
448
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
451
echo "End time relative to last file    : $datfiles[$numfiles] - ${tend} "  
449
else
452
else
450
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
453
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
451
echo "End time relative to first file   : $datfiles[1] + ${tend} "
454
echo "End time relative to first file   : $datfiles[1] + ${tend} "
452
endif
455
endif
453
 
456
 
454
echo
457
echo
455
echo $datfiles
458
echo $datfiles
456
 
459
 
457
# ---------------------------------------------------------------------
460
# ---------------------------------------------------------------------
458
# Check availability of input data 
461
# Check availability of input data 
459
# ---------------------------------------------------------------------
462
# ---------------------------------------------------------------------
460
 
463
 
461
echo
464
echo
462
echo '---- TRACEVAR FILE --------------------------------------'
465
echo '---- TRACEVAR FILE --------------------------------------'
463
echo    
466
echo    
464
 
467
 
465
# If "-f" option is used, create a temporary tracevar file
468
# If "-f" option is used, create a temporary tracevar file
466
if ( "${flag_f}" == "-f" ) then
469
if ( "${flag_f}" == "-f" ) then
467
 
470
 
468
#   Preset values for <compfl> and <tprefix>
471
#   Preset values for <compfl> and <tprefix>
469
    set tcompfl=1
472
    set tcompfl=1
470
    set tprefix='P'
473
    set tprefix='P'
471
 
474
 
472
#   Split the variable name into its vectorial components, if necessary
475
#   Split the variable name into its vectorial components, if necessary
473
    set tvar0 = `echo ${tvar} | awk -F. '{print $1}' `
476
    set tvar0 = `echo ${tvar} | awk -F. '{print $1}' `
474
    set tvar1 = `echo ${tvar} | awk -F. '{print $2}' `
477
    set tvar1 = `echo ${tvar} | awk -F. '{print $2}' `
475
     
478
     
476
#   Check availability on P file - only for first vector component
479
#   Check availability on P file - only for first vector component
477
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
480
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
478
       if ( "${var}" == "${tvar0}" ) then
481
       if ( "${var}" == "${tvar0}" ) then
479
          set tcompfl=0
482
          set tcompfl=0
480
              set tprefix="P"
483
              set tprefix="P"
481
       endif
484
       endif
482
    end
485
    end
483
 
486
 
484
#   Check availability on S file 
487
#   Check availability on S file 
485
    if ( ${sfiles} == 1 ) then
488
    if ( ${sfiles} == 1 ) then
486
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
489
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
487
         if ( "${var}" == "${tvar0}" ) then
490
         if ( "${var}" == "${tvar0}" ) then
488
            set tcompfl=0
491
            set tcompfl=0
489
                set tprefix="S"
492
                set tprefix="S"
490
         endif
493
         endif
491
       end
494
       end
492
    endif
495
    endif
493
 
496
 
494
#   Write the temporary <tracevars> file
497
#   Write the temporary <tracevars> file
495
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
498
    echo "${tvar} ${tscale} ${tcompfl} ${tprefix}" >! ${tvfile}
496
    echo "Temporary tracervar file <${tvfile}> created"
499
    echo "Temporary tracervar file <${tvfile}> created"
497
    echo
500
    echo
498
 
501
 
499
endif
502
endif
500
 
503
 
501
# Check if tracevars-file exists
504
# Check if tracevars-file exists
502
if ( ! -f $tvfile ) then
505
if ( ! -f $tvfile ) then
503
  echo  " ERROR:  file $tvfile was not found ***"
506
  echo  " ERROR:  file $tvfile was not found ***"
504
  exit 1
507
  exit 1
505
endif
508
endif
506
 
509
 
507
# check if the variables contained in the tracevars-file are available in the
510
# check if the variables contained in the tracevars-file are available in the
508
# data file and check also if there are no empty lines in the tracevars-file
511
# data file and check also if there are no empty lines in the tracevars-file
509
 
512
 
510
set nlines = `cat $tvfile | wc -l`
513
set nlines = `cat $tvfile | wc -l`
511
set vars   = `cat $tvfile | awk '{print $1}'`
514
set vars   = `cat $tvfile | awk '{print $1}'`
512
set nvars  = `echo $vars | wc -w`
515
set nvars  = `echo $vars | wc -w`
513
if ( $nlines != $nvars ) then
516
if ( $nlines != $nvars ) then
514
  echo " ERROR: tracevars-files must not contain empty lines ***"
517
  echo " ERROR: tracevars-files must not contain empty lines ***"
515
  exit 1
518
  exit 1
516
endif
519
endif
517
set calf=`cat $tvfile | awk '{print $3}'`
520
set calf=`cat $tvfile | awk '{print $3}'`
518
set tfil=`cat $tvfile | awk '{print $4}'`
521
set tfil=`cat $tvfile | awk '{print $4}'`
519
 
522
 
520
# Write some status information
523
# Write some status information
521
cat ${tvfile}
524
cat ${tvfile}
522
echo
525
echo
523
echo "# Number of tracing variables : ${nlines}"
526
echo "# Number of tracing variables : ${nlines}"
524
echo "Fields are read from following files : ${tfil}"
527
echo "Fields are read from following files : ${tfil}"
525
 
528
 
526
# Loop over all variables - check availability
529
# Loop over all variables - check availability
527
foreach v ( $vars )
530
foreach v ( $vars )
528
  if ( $calf[1] == 0 ) then
531
  if ( $calf[1] == 0 ) then
529
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
532
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
530
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
533
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
531
    set iscomment=`echo $v0 | cut -c 1` 
534
    set iscomment=`echo $v0 | cut -c 1` 
532
    if ( "${iscomment}" != "#" ) then 
535
    if ( "${iscomment}" != "#" ) then 
533
         if ( $flag == 0 ) then
536
         if ( $flag == 0 ) then
534
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
537
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
535
           exit 1
538
           exit 1
536
         endif
539
         endif
537
    endif
540
    endif
538
  endif
541
  endif
539
  shift calf
542
  shift calf
540
  shift tfil
543
  shift tfil
541
end
544
end
542
set ntrace=${nlines} 
545
set ntrace=${nlines} 
543
 
546
 
544
# ---------------------------------------------------------------------
547
# ---------------------------------------------------------------------
545
# Prepare input file for trace and run it
548
# Prepare input file for trace and run it
546
# ---------------------------------------------------------------------
549
# ---------------------------------------------------------------------
547
 
550
 
548
# Set times relative to the reference date
551
# Set times relative to the reference date
549
if ( "${changet}" == "true" ) then
552
if ( "${changet}" == "true" ) then
550
  echo
553
  echo
551
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
554
  echo '---- CHANGE TIMES ON DATA FILES  ------------------------'
552
  echo   
555
  echo   
553
  foreach i ( $datfiles )
556
  foreach i ( $datfiles )
554
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
557
    ${LAGRANTO}/goodies/changet.sh ${refdate} ${charp}${i}
555
  end
558
  end
556
  if ( ${sfiles} == 1 ) then
559
  if ( ${sfiles} == 1 ) then
557
    foreach i ( $datfiles )
560
    foreach i ( $datfiles )
558
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
561
      ${LAGRANTO}/goodies/changet.sh ${refdate} ${chars}${i}
559
    end
562
    end
560
  endif
563
  endif
561
endif
564
endif
562
 
565
 
563
# ---------------------------------------------------------------------
566
# ---------------------------------------------------------------------
564
# Prepare input file for trace and run it
567
# Prepare input file for trace and run it
565
# ---------------------------------------------------------------------
568
# ---------------------------------------------------------------------
566
 
569
 
567
# Write parameter file
570
# Write parameter file
568
\rm -f ${parfile}
571
\rm -f ${parfile}
569
touch ${parfile}
572
touch ${parfile}
570
 
573
 
571
echo $inpfile                                              >> $parfile
574
echo $inpfile                                              >> $parfile
572
echo $outfile                                              >> $parfile    
575
echo $outfile                                              >> $parfile    
573
echo $startdate                                            >> $parfile
576
echo $startdate                                            >> $parfile
574
echo $enddate                                              >> $parfile
577
echo $enddate                                              >> $parfile
575
echo $idir                                                 >> $parfile
578
echo $idir                                                 >> $parfile
576
echo $numfiles                                             >> $parfile
579
echo $numfiles                                             >> $parfile
577
foreach i ( $datfiles )
580
foreach i ( $datfiles )
578
  echo $i                                                  >> $parfile
581
  echo $i                                                  >> $parfile
579
end
582
end
580
echo $timeinc                                              >> $parfile
583
echo $timeinc                                              >> $parfile
581
echo $tstart                                               >> $parfile
584
echo $tstart                                               >> $parfile
582
echo $tend                                                 >> $parfile
585
echo $tend                                                 >> $parfile
583
echo $ntra                                                 >> $parfile
586
echo $ntra                                                 >> $parfile
584
echo $ntim                                                 >> $parfile
587
echo $ntim                                                 >> $parfile
585
echo $ncol                                                 >> $parfile
588
echo $ncol                                                 >> $parfile
586
echo $ntrace                                               >> $parfile
589
echo $ntrace                                               >> $parfile
587
cat ${tvfile}                                              >> $parfile
590
cat ${tvfile}                                              >> $parfile
588
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
591
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1] | wc -l   >> $parfile
589
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
592
${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]           >> $parfile
590
if ( $sfiles == 1 ) then
593
if ( $sfiles == 1 ) then
591
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
594
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1] | wc -l >> $parfile
592
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
595
  ${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]         >> $parfile
593
else
596
else
594
  echo 0                                                   >> $parfile
597
  echo 0                                                   >> $parfile
595
endif
598
endif
596
echo \"${timecheck}\"                                      >> $parfile
599
echo \"${timecheck}\"                                      >> $parfile
597
 
600
 
598
# Finish the preprocessor
601
# Finish the preprocessor
599
echo 
602
echo 
600
echo '       *** END OF PREPROCESSOR TRACE ***              '
603
echo '       *** END OF PREPROCESSOR TRACE ***              '
601
echo '========================================================='
604
echo '========================================================='
602
echo
605
echo
603
 
606
 
604
# Run  trace
607
# Run  trace
605
${prog}
608
${prog}
606
 
609
 
607
if ( "${status}" != "0" ) then
610
if ( "${status}" != "0" ) then
608
  echo "ERROR:  Program <trace> failed"
611
  echo "ERROR:  Program <trace> failed"
609
  exit 1
612
  exit 1
610
endif
613
endif
611
 
614
 
612
# ---------------------------------------------------------------------
615
# ---------------------------------------------------------------------
613
# Final tasks (make clean)
616
# Final tasks (make clean)
614
# ---------------------------------------------------------------------
617
# ---------------------------------------------------------------------
615
 
618
 
616
finish:
619
finish:
617
 
620
 
618
if ( "${noclean}" == "false" ) then
621
if ( "${noclean}" == "false" ) then
619
  \rm -f ${parfile}
622
  \rm -f ${parfile}
620
endif
623
endif
621
 
624
 
622
exit 0 
625
exit 0 
623
 
626