Subversion Repositories lagranto.um

Rev

Rev 3 | Rev 15 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 5
Line 254... Line 254...
254
      @ timediff_mm = 60 + $min
254
      @ timediff_mm = 60 + $min
255
    else
255
    else
256
      @ timediff_mm = 0 - $min
256
      @ timediff_mm = 0 - $min
257
    endif
257
    endif
258
  endif
258
  endif
-
 
259
else
-
 
260
  set timediff_mm = 0
259
endif
261
endif
260
 
262
 
261
# Write status information
263
# Write status information
262
echo "Time range      : ${startdate} -> ${enddate}"
264
echo "Time range      : ${startdate} -> ${enddate}"
263
if ( ${timediff_mm} != "" ) then
265
if ( ${timediff_mm} != "" ) then
Line 290... Line 292...
290
endif
292
endif
291
 
293
 
292
# Determine timeinc (the time difference in hours between two data file)
294
# Determine timeinc (the time difference in hours between two data file)
293
# if not already defined with option -i
295
# if not already defined with option -i
294
if ( ${timeinc} == "nil" ) then
296
if ( ${timeinc} == "nil" ) then
295
  set date1=`echo $file | cut -c 2-12`
297
  set date1=`echo $file | cut -c 2-`
296
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
298
  set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
297
  @ n ++
299
  @ n ++
298
  set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
300
  set date2=`\ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
299
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
301
  set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
300
endif
302
endif
301
if ( $timeinc == 0 ) then
303
if ( $timeinc == 0 ) then
302
    echo " ERROR: cannot set the time increment between input files ***"
304
    echo " ERROR: cannot set the time increment between input files ***"
303
    exit 1
305
    exit 1
304
endif
306
endif
305
 
307
 
-
 
308
# Decide whether the time increment is smaller than 1 h; if so set the hires
-
 
309
# flag and convert the timeincement into fractional hour
306
# Search the first file to use
310
set flag = `echo ${timeinc} | grep -n '\.'`
-
 
311
set hires = 0
-
 
312
if ( "${flag}" != "" ) then
-
 
313
  echo "Input files availability < 1 hour ($timeinc): switch to hires"
-
 
314
  echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
-
 
315
  set hires = 1
-
 
316
  set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
-
 
317
  set timeinc     = `echo "scale=2; ${timeinc} * 100 / 60" | bc`
-
 
318
  goto hires
-
 
319
endif
-
 
320
 
-
 
321
## 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 
-
 
323
# take it; if not, we step through all P files and find the good one  
307
set flag=0
324
set flag=0
308
set td=
325
set td=
-
 
326
 
-
 
327
set date = `echo $file | cut -c 2-12`
-
 
328
set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
-
 
329
set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
-
 
330
 
-
 
331
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
-
 
332
   set datfiles=$date
-
 
333
   if ( $td1 < $timeinc    ) set td=$td1
-
 
334
   if ( $td2 < $timeinc    ) set td=$td2
-
 
335
   if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
-
 
336
   goto label2      
-
 
337
endif
-
 
338
 
309
foreach i ( ${charp}????????_?? )
339
foreach i ( ${charp}????????_?? )
310
 
340
 
311
  set date = `echo $i | cut -c 2-12`
341
  set date = `echo $i | cut -c 2-12`
312
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
342
  set td1  = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
313
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
343
  set td2  = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh}   ${date}`
Line 320... Line 350...
320
      goto label2
350
      goto label2
321
  endif
351
  endif
322
 
352
 
323
end
353
end
324
 
354
 
325
# if no P/T-files are available for the specified time period, then $td is
-
 
326
# still undefined
-
 
327
if ( $td == "" ) then
355
if ( $td == "" ) then
328
  echo " ERROR: no data files available for the specified time period"
356
  echo " ERROR: no data files available for the specified time period"
329
  exit 1
357
  exit 1
330
endif
358
endif
331
 
359
 
-
 
360
# 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
-
 
362
# 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
-
 
364
# allowed between the model output files
-
 
365
hires:
-
 
366
 
-
 
367
set flag=0
-
 
368
set td=0
-
 
369
 
-
 
370
if ( $direction == "f" ) then
-
 
371
  set file=${charp}${startdate}
-
 
372
else 
-
 
373
  set file=${charp}${enddate}
-
 
374
endif
-
 
375
 
-
 
376
if ( -f $file ) then
-
 
377
  set date     = `echo ${file} | cut -c 2-14`
-
 
378
  set datfiles = $date
-
 
379
  set td       = 0
-
 
380
  goto label2
-
 
381
else
-
 
382
  echo
-
 
383
  echo " ERROR: no data files available for the specified time period"
-
 
384
  exit 1
-
 
385
endif
-
 
386
 
332
# Everything is fine so far: proceed
387
# Everything is fine so far: proceed
333
label2:
388
label2:
334
 
389
 
335
# Calculate the number of further files
390
# Calculate the number of further files; handle hires (timeinc<1 h) and
-
 
391
# standard mode (timeinc >= 1 h) separately
-
 
392
if ( ${hires} == 0 ) then
336
@ num = ( $timediff_hh + $td ) / $timeinc + 1
393
 @ num = ( $timediff_hh + $td ) / $timeinc + 1
337
@ dum1 = ( $num - 1 ) * $timeinc
394
 @ dum1 = ( $num - 1 ) * $timeinc
338
@ dum2 = $timediff_hh + $td
395
 @ dum2 = $timediff_hh + $td
339
if ( $dum1 != $dum2 ) @ num ++
396
 if ( $dum1 != $dum2 ) @ num ++
-
 
397
else
-
 
398
 set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
-
 
399
endif 
340
 
400
 
341
# Get a list of all needed files
401
# Get a list of all needed files
342
set numfiles=$num
402
set numfiles=$num
343
set sfiles=1
403
set sfiles=1
-
 
404
echo $datfiles
344
while ( $num > 1 )
405
while ( $num > 1 )
-
 
406
  if ( $hires == 0 ) then
345
  set date=`${LAGRANTO}goodies/newtime $date $timeinc`
407
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
-
 
408
  else
-
 
409
     set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
-
 
410
  endif
346
  if ( ! -f ${charp}${date} ) then
411
  if ( ! -f ${charp}${date} ) then
347
    echo " ERROR: file with primary data is missing for $date"
412
    echo " ERROR: file with primary data is missing for $date"
348
    exit 1
413
    exit 1
349
  else if ( ! -f ${chars}${date} ) then
414
  else if ( ! -f ${chars}${date} ) then
350
    set sfiles=0
415
    set sfiles=0
Line 366... Line 431...
366
 
431
 
367
 
432
 
368
# Write some status information
433
# Write some status information
369
echo "Primary file prefix               : ${charp}"
434
echo "Primary file prefix               : ${charp}"
370
echo "Secondary file prefix             : ${chars}"
435
echo "Secondary file prefix             : ${chars}"
-
 
436
if ( ${hires} == 0 ) then
371
echo "Time increment for input files    : ${timeinc}"
437
  echo "Time increment for input files    : ${timeinc} h"
-
 
438
else
-
 
439
  echo "Time increment for input files    : ${timeinc_min} min (0$timeinc h) "
-
 
440
endif
372
echo "# input files                     : ${numfiles}"
441
echo "# input files                     : ${numfiles}"
373
echo "First input file                  : $datfiles[1] " 
442
echo "First input file                  : $datfiles[1] " 
374
echo "Last input file                   : $datfiles[$numfiles] " 
443
echo "Last input file                   : $datfiles[$numfiles] " 
375
echo "${charp} files availability              : 1"  
444
echo "${charp} files availability              : 1"  
376
echo "${chars} files availability              : ${sfiles}"     
445
echo "${chars} files availability              : ${sfiles}"     
Line 380... Line 449...
380
else
449
else
381
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
450
echo "Start time relative to last file  : $datfiles[$numfiles] - ${tstart} "
382
echo "End time relative to first file   : $datfiles[1] + ${tend} "
451
echo "End time relative to first file   : $datfiles[1] + ${tend} "
383
endif
452
endif
384
 
453
 
-
 
454
echo
-
 
455
echo $datfiles
-
 
456
 
385
# ---------------------------------------------------------------------
457
# ---------------------------------------------------------------------
386
# Check availability of input data 
458
# Check availability of input data 
387
# ---------------------------------------------------------------------
459
# ---------------------------------------------------------------------
388
 
460
 
389
echo
461
echo
Line 394... Line 466...
394
if ( "${flag_f}" == "-f" ) then
466
if ( "${flag_f}" == "-f" ) then
395
 
467
 
396
#   Preset values for <compfl> and <tprefix>
468
#   Preset values for <compfl> and <tprefix>
397
    set tcompfl=1
469
    set tcompfl=1
398
    set tprefix='P'
470
    set tprefix='P'
-
 
471
 
-
 
472
#   Split the variable name into its vectorial components, if necessary
-
 
473
    set tvar0 = `echo ${tvar} | awk -F. '{print $1}' `
-
 
474
    set tvar1 = `echo ${tvar} | awk -F. '{print $2}' `
399
    
475
     
400
#   Check availability on P file
476
#   Check availability on P file - only for first vector component
401
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
477
    foreach var ( `${LAGRANTO}/goodies/getvars ${charp}$datfiles[1]` )
402
       if ( "${var}" == "${tvar}" ) then
478
       if ( "${var}" == "${tvar0}" ) then
403
          set tcompfl=0
479
          set tcompfl=0
404
	  set tprefix="P"
480
              set tprefix="P"
405
       endif
481
       endif
406
    end
482
    end
407
 
483
 
408
#   Check availability on S file 
484
#   Check availability on S file 
409
    if ( ${sfiles} == 1 ) then
485
    if ( ${sfiles} == 1 ) then
410
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
486
       foreach var ( `${LAGRANTO}/goodies/getvars ${chars}$datfiles[1]` )
411
         if ( "${var}" == "${tvar}" ) then
487
         if ( "${var}" == "${tvar0}" ) then
412
            set tcompfl=0
488
            set tcompfl=0
413
	    set tprefix="S"
489
                set tprefix="S"
414
         endif
490
         endif
415
       end
491
       end
416
    endif
492
    endif
417
 
493
 
418
#   Write the temporary <tracevars> file
494
#   Write the temporary <tracevars> file
Line 420... Line 496...
420
    echo "Temporary tracervar file <${tvfile}> created"
496
    echo "Temporary tracervar file <${tvfile}> created"
421
    echo
497
    echo
422
 
498
 
423
endif
499
endif
424
 
500
 
425
 
-
 
426
# Check if tracevars-file exists
501
# Check if tracevars-file exists
427
if ( ! -f $tvfile ) then
502
if ( ! -f $tvfile ) then
428
  echo  " ERROR:  file $tvfile was not found ***"
503
  echo  " ERROR:  file $tvfile was not found ***"
429
  exit 1
504
  exit 1
430
endif
505
endif
Line 439... Line 514...
439
  echo " ERROR: tracevars-files must not contain empty lines ***"
514
  echo " ERROR: tracevars-files must not contain empty lines ***"
440
  exit 1
515
  exit 1
441
endif
516
endif
442
set calf=`cat $tvfile | awk '{print $3}'`
517
set calf=`cat $tvfile | awk '{print $3}'`
443
set tfil=`cat $tvfile | awk '{print $4}'`
518
set tfil=`cat $tvfile | awk '{print $4}'`
-
 
519
 
-
 
520
# Write some status information
-
 
521
cat ${tvfile}
-
 
522
echo
-
 
523
echo "# Number of tracing variables : ${nlines}"
-
 
524
echo "Fields are read from following files : ${tfil}"
-
 
525
 
-
 
526
# Loop over all variables - check availability
444
foreach v ( $vars )
527
foreach v ( $vars )
445
  if ( $calf[1] == 0 ) then
528
  if ( $calf[1] == 0 ) then
446
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
529
    set v0 = `echo $v | awk 'BEGIN {FS = ":"}; {print $1}'`
447
    set flag=`${LAGRANTO}goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
530
    set flag=`${LAGRANTO}/goodies/getvars $tfil[1]$datfiles[1] | grep " $v0 " | wc -l`
448
    set iscomment=`echo $v0 | cut -c 1` 
531
    set iscomment=`echo $v0 | cut -c 1` 
449
    if ( "${iscomment}" != "#" ) then 
532
    if ( "${iscomment}" != "#" ) then 
450
	 if ( $flag == 0 ) then
533
         if ( $flag == 0 ) then
451
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
534
           echo " ERROR: variable $v listed in $tvfile is not on the $tfil[1]-files ***"
452
           exit 1
535
           exit 1
453
	 endif
536
         endif
454
    endif
537
    endif
455
  endif
538
  endif
456
  shift calf
539
  shift calf
457
  shift tfil
540
  shift tfil
458
end
541
end
459
set ntrace=${nlines} 
542
set ntrace=${nlines} 
460
 
543
 
461
# Write some status information
-
 
462
cat ${tvfile}
-
 
463
echo
-
 
464
echo "# Number of tracing variables : ${ntrace}"
-
 
465
 
-
 
466
# ---------------------------------------------------------------------
544
# ---------------------------------------------------------------------
467
# Prepare input file for trace and run it
545
# Prepare input file for trace and run it
468
# ---------------------------------------------------------------------
546
# ---------------------------------------------------------------------
469
 
547
 
470
# Set times relative to the reference date
548
# Set times relative to the reference date
Line 481... Line 559...
481
    end
559
    end
482
  endif
560
  endif
483
endif
561
endif
484
 
562
 
485
# ---------------------------------------------------------------------
563
# ---------------------------------------------------------------------
486
# Prepare input file for caltra and run it
564
# Prepare input file for trace and run it
487
# ---------------------------------------------------------------------
565
# ---------------------------------------------------------------------
488
 
566
 
489
# Write parameter file
567
# Write parameter file
490
\rm -f ${parfile}
568
\rm -f ${parfile}
491
touch ${parfile}
569
touch ${parfile}