mailman3.common-lisp.net
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
List overview
Download
cl-libtai-cvs
January 2006
----- 2024 -----
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
cl-libtai-cvs@common-lisp.net
1 participants
1 discussions
Start a n
N
ew thread
[cl-libtai-cvs] r1 -
by lvecsey@common-lisp.net
30 Jan '06
30 Jan '06
Author: lvecsey Date: Mon Jan 30 09:05:38 2006 New Revision: 1 Added: cl-libtai.asd cl-libtai.lisp leapsecs.dat (contents, props changed) test-libtai.lisp Log: Added: cl-libtai.asd ============================================================================== --- (empty file) +++ cl-libtai.asd Mon Jan 30 09:05:38 2006 @@ -0,0 +1,6 @@ +(defsystem "cl-libtai" + :description "TAI - Temps Atomique International; time conversion library" + :version "0.51" + :author "Lester Vecsey" + :licence "LGPL" + :components ((:file "cl-libtai"))) Added: cl-libtai.lisp ============================================================================== --- (empty file) +++ cl-libtai.lisp Mon Jan 30 09:05:38 2006 @@ -0,0 +1,177 @@ +(in-package "COMMON-LISP-USER") + +(defpackage #:cl-libtai + (:use #:common-lisp) + (:export :leapsecs-add :*leapsecs* :*leapsecs-strings* + :tai-unpack + :taia-unpack + :tai-now + :caldate-scan + :caldate-mjd + :caldate-frommjd + :caltime-tai + :caltime-utc + :leapsecs-gen + :leapsecs-add + :leapsecs-sub + :make-caldate + :make-caltime + :make-tai64-internal + :make-tai64na-internal)) + +(in-package "CL-LIBTAI") + +(defvar times365 (list 0 365 730 1095)) +(defvar times36524 (list 0 36524 73048 109572)) +(defvar montab (list 0 31 61 92 122 153 184 214 245 275 306 337)) + +(defun make-tai64-internal(s) + (pairlis '(x) (list s))) + +(defun make-tai64na-internal(s a n) + (pairlis '(sec atto nano) (list s a n))) + +(defun make-caldate(y m d) + (list :year y :month m :day d)) + +(defun make-caltime(cd h m s o) + (pairlis '(date hour minute second offset) (list cd h m s o))) + +;
http://maia.usno.navy.mil/leapsec.html
+;
http://maia.usno.navy.mil/ser7/leapsec.dat
+ +(defvar *leapsecs-strings* (list +"+1972-06-30" +"+1972-12-31" +"+1973-12-31" +"+1974-12-31" +"+1975-12-31" +"+1976-12-31" +"+1977-12-31" +"+1978-12-31" +"+1979-12-31" +"+1981-06-30" +"+1982-06-30" +"+1983-06-30" +"+1985-06-30" +"+1987-12-31" +"+1989-12-31" +"+1990-12-31" +"+1992-06-30" +"+1993-06-30" +"+1994-06-30" +"+1995-12-31" +"+1997-06-30" +"+1998-12-31" +"+2005-12-31")) + +(defun leapsecs-add(t2 hit leapsecs) + (let ((u (cdr (assoc 'x t2)))) + (loop for a in leapsecs for m = (cdr (assoc 'x a)) + do (if (< u m) (loop-finish) + (if (or (= hit 0) (> u m)) (setf u (1+ u)))) + finally (return (make-tai64-internal u))))) + +(defun leapsecs-sub(t2 leapsecs) + (let ((u (cdr (assoc 'x t2)))) + (loop for a in leapsecs for s = 0 then (1+ s) + do (if (< u (cdr (assoc 'x a))) (return (values (make-tai64-internal (- u s)) 0))) + (if (= u (cdr (assoc 'x a))) (return (values (make-tai64-internal (- u (1+ s))) 1))) + finally (return (values (make-tai64-internal (- u s)) 0))))) + +(defun tai-now() + (make-tai64-internal (+ (- 4611686018427387914 2208988800) (get-universal-time)))) + +(defun tai-pack(tai64i) + (format nil "~x" (cdr (assoc 'x tai64i)))) + +(defun tai-unpack(s) + (make-tai64-internal (parse-integer s :radix 16))) + +(defun taia-pack(tai64nai) + (format nil "~x~x~x" (cdr (assoc 'sec tai64nai)) + (cdr (assoc 'atto tai64nai)) + (cdr (assoc 'nano tai64nai)))) + +(defun taia-unpack(s) + (let ((tai-s (subseq s 0 8)) (atto-s (subseq s 8 12)) (nano-s (subseq s 12 16 ))) + (make-tai64na-internal (parse-integer tai-s :radix 16) + (parse-integer atto-s :radix 16) + (parse-integer nano-s :radix 16)))) + +(defun display-numeric(tai-s atto-s nano-s) + (format t "~a ~a ~a" (parse-integer tai-s :radix 16) + (parse-integer atto-s :radix 16) + (parse-integer nano-s :radix 16))) + +(defun caldate-mjd (cd) + (defun final-yd(y d) + (+ d + (nth (logand #x3 y) times365) + (* 1461 (rem (floor (/ y 4)) 25)) + (nth (logand #x3 (floor (/ y 100))) times36524))) + (defun mjd-ycheck1(year m day) + (let ((y (rem year 400)) (d (+ (* (floor (/ year 400)) 146097) (+ day (+ (nth m montab)))))) + (if (< y 0) (final-yd (+ y 400) (- d 146097)) (final-yd y d)))) + (defun mcheck2(year month d) + (let ((y (+ year (floor (/ month 12)))) (m (rem month 12))) + (if (< m 0) (mjd-ycheck1 (- y 1) (+ m 12) d) (mjd-ycheck1 y m d)))) + (defun mcheck1(y m d) + (if (>= m 2) (mcheck2 y (- m 2) d) (mcheck2 (- y 1) (+ m 10) d))) + (destructuring-bind (&key year month day) cd + (mcheck1 (rem year 400) (- month 1) (+ (* 146097 (floor (/ year 400))) (- day 678882))))) + +(defun caldate-frommjd(day) + (let ((pwday 0)) + (defun daydec(n acc) + (if (>= n 146097) (daydec (- n 146097) (1+ acc)) (values n acc))) + (defun check5(yday y m d) + (values (make-caldate y (+ m 1) (+ d 1)) pwday yday)) + (defun check4(yday year day) + (let ((da (* 10 day))) + (let ((m (floor (/ (+ 5 da) 306))) (d (floor (/ (rem (+ da 5) 306) 10)))) + (if (>= m 10) (check5 (- yday 306) (+ year 1) (- m 10) d) (check5 (+ yday 59) year (+ m 2) d))))) + (defun check3(year day) + (let ((yday (if (< day 306) 1 0))) + (if (eq day 1460) (check4 yday (+ year 3) 365) (check4 yday (+ year (floor (/ day 365))) (rem day 365))))) + (defun check2(year day) + (let ((y (* 4 (+ (floor (/ day 1461)) (* year 25)))) (d (rem day 1461))) + (check3 y d))) + (defun fmjd-ycheck1(year day) + (let ((y (* year 4))) + (if (eq day 146096) (check2 (+ y 3) 36524) (check2 (+ y (floor (/ day 36524))) (rem day 36524))))) + (let ((year (floor (/ day 146097))) (d (+ 678881 (rem day 146097)))) + (multiple-value-bind (newday yeardiff) + (daydec d 0) + (progn (setf pwday (mod (+ 3 newday) 7)) + (fmjd-ycheck1 (+ year yeardiff) newday)))))) + +(defun caldate-normalize(cd) + (caldate-frommjd (caldate-mjd cd))) + +(defun caldate-scan(s) + (let* ((sign (if (eq (char s 0) #\-) -1 1)) (r (string-trim "-+" s)) (p1 (position #\- r)) (p2 (position #\- r :start (1+ p1)))) + (make-caldate (* (parse-integer r :end p1) sign) (parse-integer r :start (1+ p1) :end p2) (parse-integer r :start (1+ p2))))) + +(defun leapsecs-gen(ls) + (loop for a in ls for leaps = 0 then (1+ leaps) + collect (make-tai64-internal (+ leaps (+ 4611686014920671114 (* 86400 (1+ (caldate-mjd (caldate-scan a))))))))) + +(defparameter *leapsecs* (leapsecs-gen *leapsecs-strings*)) + +(defun caltime-tai(ct) + (defun m60p(mul syp) + (+ (cdr (assoc syp ct)) (* 60 mul))) + (defun inner() (m60p (cdr (assoc 'hour ct)) 'minute)) + (defun xval(d) + (+ 4611686014920671114 (* 86400 d) (m60p (- (inner) (cdr (assoc 'offset ct))) 'second))) + (let ((day (caldate-mjd (cdr (assoc 'date ct))))) + (leapsecs-add (make-tai64-internal (xval day)) (if (= 60 (cdr (assoc 'second ct))) 1 0) *leapsecs*))) + +(defun caltime-utc(tai64i) + (multiple-value-bind (tn leap) + (leapsecs-sub tai64i *leapsecs*) + (let ((u (+ 58486 (cdr (assoc 'x tn))))) + (let ((s (rem u 86400))) + (make-caltime (caldate-frommjd (logand #xFFFFFFFF (- (floor (/ u 86400)) 53375995543064))) (floor (/ s 3600)) (rem (floor (/ s 60)) 60) (+ leap (rem s 60)) 0))))) + Added: leapsecs.dat ============================================================================== Binary file. No diff available. Added: test-libtai.lisp ============================================================================== --- (empty file) +++ test-libtai.lisp Mon Jan 30 09:05:38 2006 @@ -0,0 +1,55 @@ +(in-package "COMMON-LISP-USER") + +(defpackage #:cl-test-libtai + (:use #:common-lisp #:cl-libtai)) + +(in-package "CL-TEST-LIBTAI") + +(defvar test-libtai-iit (lisp-implementation-type)) + +(defun report-result (result form) + (format t "~:[FAIL~;pass~] ... ~a~%" result form)) + +(defmacro check (form) + `(report-result ,form ',form)) + +(defmacro check (&body forms) + `(progn + ,@(loop for f in forms collect `(report-result ,f ',f)))) + +(defun test-report() + (format t "lisp-implementation-type: ~a~%" test-libtai-iit)) + +(defun test-leapsecs-add() + (check + (= 4611686019090075928 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075913) 0 *leapsecs*)))) + (= 4611686019090075928 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075913) 1 *leapsecs*)))) + (= 4611686019090075930 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075914) 0 *leapsecs*)))) + (= 4611686019090075929 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075914) 1 *leapsecs*)))) + (= 4611686019090075931 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075915) 0 *leapsecs*)))) + (= 4611686019090075931 (cdr (assoc 'cl-libtai::x (leapsecs-add (make-tai64-internal 4611686019090075915) 1 *leapsecs*)))))) + +(defun test-bench() + (let ((full #x4000000043a72b922e8da9282313e8a8) (full-s "4000000043a72b922e8da9282313e8a8") + (short #x4000000043a72b92) + (short-s "4000000043a72b92")) + (check + (format t "t.x = ~a~%" (cdr (assoc 'x (make-tai64-internal (floor (/ full (expt 2 64))))))) + (tai-unpack short-s) + (taia-unpack full-s) + (caltime-utc (make-tai64-internal short)) + (caltime-utc (tai-now)) + (destructuring-bind (&key year month day) (caldate-scan "+2005-12-26") + (= year 2005) (= month 12) (= day 26)) + (leapsecs-gen (list "+1998-12-31" "+2005-12-31")) + (= 53730 (caldate-mjd (make-caldate 2005 12 26))) + ; MJD 51604 is year 5, day 0. + (destructuring-bind (&key year month day) (caldate-frommjd 51604) + (= year 2000) (= month 3) (= day 1))))) + +(defun test-caltime-tai() + (caltime-tai (make-caltime (make-caldate 2005 12 28) 3 36 10 0))) + +(defun test-libtai() + (progn (test-report) (test-leapsecs-add) (test-bench) (test-caltime-tai))) +
1
0
0
0
Results per page:
10
25
50
100
200