diff options
Diffstat (limited to '')
| -rw-r--r-- | ckcptime.awk | 60 |
1 files changed, 16 insertions, 44 deletions
diff --git a/ckcptime.awk b/ckcptime.awk index e6c88d1..7bfef6e 100644 --- a/ckcptime.awk +++ b/ckcptime.awk @@ -8,12 +8,7 @@ function log10(n) { function merge_meas(est_val, est_unc, meas_val, meas_unc) { - # add (meas - est) delta to the measurement uncertainty - # note: this works when tracking a constant value, - # the first derivative of a constant 'should' be zero - # unc_meas = sqrt(unc_meas^2.0 + (val_meas - val_est)^2.0) - - # Kalman filtering compares variances + # Kalman filtering compares variances, # convert uncertainties to square units est_unc = (0.5*est_unc)^2.0 meas_unc = (0.5*meas_unc)^2.0 @@ -35,14 +30,17 @@ function sigfig(val, unc) { ordmag_val = log10(val) ordmag_unc = log10(unc) - #sigfig_unc = sprintf("%.f", 6) - sigfig_unc = sprintf("%.f", sqrt((ordmag_val - ordmag_unc)^2.0) + 1.0) - sigfig_val = sprintf("%.f", (ordmag_val - ordmag_unc + sigfig_unc)) + ordmag_high = sqrt((ordmag_val)^2.0 + (ordmag_unc)^2.0) + ordmag_low = ((ordmag_val)^-1.0 + (ordmag_unc)^-1.0)^-1.0 + ordmag_range = ordmag_high - ordmag_low + + sigfig_unc = sprintf("%.f", sqrt((ordmag_range)^2.0 + 3.0^2.0)) + sigfig_val = sprintf("%.f", sqrt((ordmag_range)^2.0 + (sigfig_unc)^2.0 + 3.0^2.0)) ofmt_val = "%." sigfig_val "g" ofmt_unc = "%." sigfig_unc "g" - return sprintf(ofmt_val OFS ofmt_unc ORS, val, unc) + return sprintf(ofmt_val OFS ofmt_unc, val, unc) } @@ -66,20 +64,12 @@ function ck_cptime() { } -function ck_uptime(t0_est, t0_unc) { - - t_sys_meas[1] = systime() - t_sys_meas[2] = 1.0 +function ck_uptime() { + # check uptime cmd "uptime" | getline t_up_cmd close("uptime") - split(merge_meas(t_sys_meas[1], t_sys_meas[2], systime(), 1.0), t_sys_meas) - - # estimate (predict) uptime - t_up_est[1] = t_sys_meas[1] - t0_est - t_up_est[2] = t_sys_meas[2] + t0_unc - # evaluate measured uptime t_up_meas[1] = 0.0 t_up_meas[2] = systime() @@ -119,38 +109,20 @@ function ck_uptime(t0_est, t0_unc) { } - # merge predicted and measured uptimes - split(merge_meas(t_up_est[1], t_up_est[2], t_up_meas[1], t_up_meas[2]), t_up_est) - - # evaluate measured boot time, t0 - t_boot_meas[1] = t_sys_meas[1] - t_up_meas[1] - t_boot_meas[2] = t_sys_meas[2] + t_up_meas[2] - - # merge previous and updated boot time, t0 - split(merge_meas(t0_est, t0_unc, t_boot_meas[1], t_boot_meas[2]), t_boot_est) - - return sigfig(t_boot_est[1], t_boot_est[2]) + return sigfig(t_up_meas[1], t_up_meas[2]) } BEGIN { - OFMT="%.21g" + OFMT="%f" + pi = 4.0*atan2(1.0, 1.0) + c0 = 299792458 # m/sec + #print("_systime_", systime()) #print("_boottime_", ck_boottime()) - printf("%s" ORS, ck_cptime()) - - # check ARGV for previous estimate - # if (ARGC > 0) { - # ARGV[1] ? t0_est[1] = ARGV[1] : t0_est[1] = 0.0 - # ARGV[2] ? t0_est[2] = ARGV[2] : t0_est[2] = systime() - # } - #print("t0_est = ", t0_est[1]) - #print("t_boot_unc = ", t0_est[2]) - - # check uptime, update estimate - #print(ck_uptime(t0_est[1], t0_est[2])) + print( ck_cptime() ) } |
