Subversion Repositories lagranto.ecmwf

Rev

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

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