#!/bin/sh # This comment extends to the next line for tcl \ exec dbtcl -f $0 $* # # Script to fix TARA timing problem, days 237-285 # # Script by T.J. Owens, finalized July 1997 # # set tcl_precision 17 # # **** GENERAL EQUATIONS FOR FIXING MUFFED TIMING CORRECTIONS **** # # Let A = current time in database (time that needs fixing) # B = Original uncorrected time (prior to improper correction that produced A) # C = Correct time (time with proper corrections applied) # D1 = Improper drift rate (applied to B to produce A) # D2 = Proper drift rate (want to applied to B to produce C) # O = Static Offset, zero in these examples # R = Reference time (when corrections Begin) # End = End of problem segment (when corrections Stop) # # Then A = [O + (B - R)*D1] + B # B = [A - O + R*D1]/[1 + D1] # So # C = [O + (B-R)*D2] + B # # **** END GENERAL EQUATIONS ************************************** # # OK, the problem at TARA is that a drift of improper sign was applied # between 1994:237:21:31:40 and 1994:285:10:02:01:007 # # Here are the parameters: # set R 777850300. set End 781956121.007 set O 0.001 set D1 -0.0000008037394 set D2 0.0000008037394 # set site TARA # # set infile [lindex $argv 0] set type [lindex [split $infile .] 1] # if { ($type == "arrival") || ($type == "wfdisc") } { puts "Correcting $site timing problem in $infile" } else { puts "This code cannot fix $type tables, only wfdisc and arrival tables" return } # set db [dbopen_table $infile r+] # for {set i 0 } {$i <[dbquery $db dbRECORD_COUNT]} {incr i} { # set A [dbgetv $db 0 $i time] set sta [dbgetv $db 0 $i site] # # if {$sta == $site} { if {($A > $R) && ($A < $End)} { set t1 [expr 1. + $D1] set t2 [expr $R*$D1] set t3 [expr $A + $O] set B [expr ($t3 + $t2)/$t1] set C [expr $B + ($O + ($B - $R)*$D2)] # puts "$t1 $t2 $t3 $B $C" if {$type == "wfdisc"} { set diff [expr $A - $C] set newendtime [expr [dbgetv $db 0 $i endtime] - $diff] dbputv $db 0 $i time $C endtime $newendtime } else { dbputv $db 0 $i time $C } } } } dbclose $db