Thread: [pure-lang-svn] SF.net SVN: pure-lang: [386] pure/trunk/examples/libor/date.pure
Status: Beta
Brought to you by:
agraef
From: <ye...@us...> - 2008-07-04 21:27:22
|
Revision: 386 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=386&view=rev Author: yes Date: 2008-07-04 14:27:31 -0700 (Fri, 04 Jul 2008) Log Message: ----------- improvements to date.pure Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-04 20:33:00 UTC (rev 385) +++ pure/trunk/examples/libor/date.pure 2008-07-04 21:27:31 UTC (rev 386) @@ -1,45 +1,79 @@ -/* Mayan Calendar - Copyright (c) 2008 by Libor Spacek +/* New Calendar and Clock + Copyright (c) 2008 by Libor Spacek Usage: pure -x date.pure [-h] Discrepancies with your local clock may occur when C library's time(); - returns Posix time based on UTC (Universel Temps Coordonné) or TAI - (Temps Atomique Internacional) rather than local daylight saving time */ + returns Posix time based on UTC (Universal Temps Coordinat) or TAI + (Temps Atomique International) rather than local daylight saving time */ -using system; -extern int time(); +using system; // this is needed just to get C printf +extern int time(); // makes available the C function time(); -puts "Mayan Calendar, Copyright (c) 2008 by Libor Spacek"; +puts "****************************************************************"; +puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; +puts "****************************************************************"; +def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch +def epochday = mayan2days posixepoch; // (mayan) day of the posix epoch +def endofcycle = (13:0:0:0:0); // The end of the cycle +def cycledays = mayan2days endofcycle; // total days in 13 Baktuns +def secsinday = 86400.0; // number of seconds in a day +def trueyear = 31556941.0;// (in seconds) divisible by 13 = current true year +def myyear = 31556943.0;// div by 2277, secsinday compatible, 365.2424 days +def gregyear = 31556952.0;// div by 40824, mean gregorian year, 365.2425 days -def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch -def epochday = mayan2days posixepoch; // Mayan day of the posix epoch -def endofdays = 15695; // posix days at the end of the cycle (13th baktun) -def secsinday = 86400; // number of seconds in a day -def cycledays = mayan2days (13:0:0:0:0); -def year = 365.242374; -def cycleyears = cycledays / year; - -// time now in posix seconds converted to whole days -posixsecsnow = time; // call posixsecsnow to refresh the current time -posixdays = posixsecsnow div secsinday; -secsnow = posixsecsnow mod secsinday; - -// time calculations on the usual days:hours:minutes:seconds format -dhms2secs (d::int:h::int:m::int:s) = 60.0*(60*(24*d+h)+m)+s; -// secs are usually double and can be int or bigint but d,h,m are always ints -secs2dhms secs = - d:(h mod 24):(m mod 60):(secs-60.0*m) +// current posix time supplied by C time(); +posixsecsnow = time; // int - each new call refreshes to the current second +secsnow = posixsecsnow mod (int secsinday); // int seconds since midnight + +// first some simple conversions +secs2days s::int | secs2days s::bigint = s div (int secsinday); +secs2days s::double = s / secsinday; // this returns double days +days2secs d::int = secsinday * d; +days2hours d::int = 24*d; +hours2days h::int = h div 24; + +// conversions from/to days:hours:minutes:seconds format +// seconds can be int or bigint or double. d,h,m are ints +dhms2secs (d::int:h::int:m::int:s::int) | +dhms2secs (d::int:h::int:m::int:s::bigint) | +dhms2secs (d::int:h::int:m::int:s::double) = 60.0*(60*(24*d+h)+m)+s; +secs2dhms secs::int | secs2dhms secs::bigint | secs2dhms secs::double = + d:(h mod 24):(m mod 60):(secs-60*m) when m::int = int (secs / 60); h::int = m div 60; d::int = h div 24 end; - -// an arbitrary binary operator applied to two (days,hours,minutes,seconds) +// an arbitrary binary operator applied to two (days:hours:minutes:seconds) opdhms op (d1::int:h1::int:m1::int:s1)(d2::int:h2::int:m2::int:s2) = secs2dhms (op (dhms2secs (d1:h1:m1:s1)) (dhms2secs (d2:h2:m2:s2))); + +// conversions from/to hours:minutes:seconds format for displaying time of day. +// hours may be more than 24 but use d:h:m:s for longer periods of time +hms2secs (h::int:m::int:s::int) | +hms2secs (h::int:m::int:s::bigint) | +hms2secs (h::int:m::int:s::double) = 60.0*(60*h+m)+s; +secs2hms secs::int | secs2hms secs::bigint | secs2hms secs::double = + h:(m mod 60):(secs-60*m) + when + m::int = int (secs / 60); + h::int = m div 60; + end; -// Now follows the Mayan Calendar +// New Time Format! hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s +// the normal seconds are now just a single digit 0-9 +// dicis:secs are easy to read: 6:0 means 60 seconds, 12:5 125 seconds etc. +// tres - multiply by three to get traditional babylonian minutes +// hours as usual (24 hour clock) +htds2secs (h::int:t::int:d::int:s::int) = 10.0*(18*(20*h+t)+d)+s; +secs2htds secs::int | secs2htds secs::bigint | secs2htds secs::double = + h:(t mod 20):(d mod 18):(secs-10*d) + when + d::int = int (secs / 10); + t::int = d div 18; + h::int = t div 20 + end; // not used yet but could be, as in: addmayan posixepoch (days2mayan posixdays) addmayan (baktun1::int:katun1::int:tun1::int:vinal1::int:kin1::int) @@ -59,11 +93,12 @@ mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; -// simple calculations to print -daytoday = epochday + posixdays; -mayantoday = days2mayan daytoday; -daysleft = endofdays - posixdays; -mayanleft = days2mayan daysleft; +// for now, let's just do some simple calculations to print +daytoday = epochday + (secs2days posixsecsnow); // mayan whole day count +mayantoday = days2mayan daytoday; // as above but in mayan long count format +daysleft = cycledays - epochday - (secs2days (double posixsecsnow)); // double +mayanleft = days2mayan ((int daysleft)); +timeleft = secs2htds ((int secsinday) - secsnow); percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; usage = puts "Usage: pure -x date.pure [anyarg]" $ @@ -71,16 +106,21 @@ case argc of 1 = - void (printf "Posix time now: %s\n" (str (secs2dhms posixsecsnow))) $ - void (printf "Mayan long count date: %s = day %d\n" - ((str mayantoday), (mayan2days mayantoday))) $ - void (printf "Mayan countdown today: %s = %d days till the cycle ends\n" - ((str mayanleft), daysleft)) $ - void (printf "The Mayan cycle of over %d years " (int cycleyears)) $ - void (printf "is now %11.8f%% complete!\n" percentcomplete); - 2 = void (puts "Mayan long count digits (and their range of values):") $ - void (puts "Baktun(0-12):Katun(0-19):Tun(0-19):Vinal(0-17):Kin(0-19)")$ - puts "Baktun=144000days:Katun=7200days:Tun=360days:Vinal=20days:Kin=1day"$ - usage; + void (printf "Mayan day %d + UTC Time %s = %s,%s\n" (daytoday, + (str (secs2hms secsnow)),(str mayantoday),(str (secs2htds secsnow))))$ + void (printf "Long countdown %f(days left) = %s,%s\n" + (daysleft, (str mayanleft), (str timeleft))) $ + void (printf "The Mayan cycle of over 5125 years is now %11.8f%% complete\n" + percentcomplete ) $ + void (puts"****************************************************************"); + 2 = + void(puts "Mayan long count digits (and their range of values):") $ + void(puts "Baktun(0-12) : Katun(0-19) : Tun(0-19) : Vinal(0-17) : Kin(0-19)")$ + puts "Baktun=144000days Katun=7200days Tun=360days Vinal=20days Kin=day"$ + void (puts "\nNew clock digits (and their range of values):") $ + void (puts "Hour(0-23) : Tre(0-19) : Dici(0-17) : Sec(0-9)")$ + puts "Hour=3600secs Tre=180secs Dici=10secs Sec=second\n"$ + puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" + usage; n = usage otherwise end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-04 22:40:36
|
Revision: 387 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=387&view=rev Author: yes Date: 2008-07-04 15:40:45 -0700 (Fri, 04 Jul 2008) Log Message: ----------- Added Moonphase to date.pure Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-04 21:27:31 UTC (rev 386) +++ pure/trunk/examples/libor/date.pure 2008-07-04 22:40:45 UTC (rev 387) @@ -18,17 +18,19 @@ def endofcycle = (13:0:0:0:0); // The end of the cycle def cycledays = mayan2days endofcycle; // total days in 13 Baktuns def secsinday = 86400.0; // number of seconds in a day -def trueyear = 31556941.0;// (in seconds) divisible by 13 = current true year -def myyear = 31556943.0;// div by 2277, secsinday compatible, 365.2424 days -def gregyear = 31556952.0;// div by 40824, mean gregorian year, 365.2425 days - +def trueyear = 31556941;// (in seconds) divisible by 13 = current true year +def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days +def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days +def lunarmonth = 2551443; // lunar (synodic) month to the nearest second +def newmoonsecs = dhms2secs(14063:2:19:0); // 3/July/08 in posix + // current posix time supplied by C time(); posixsecsnow = time; // int - each new call refreshes to the current second secsnow = posixsecsnow mod (int secsinday); // int seconds since midnight // first some simple conversions -secs2days s::int | secs2days s::bigint = s div (int secsinday); -secs2days s::double = s / secsinday; // this returns double days +secs2days s::int | secs2days s::bigint = (s div (int secsinday)); +secs2days s::double = ( s / secsinday ); // this returns double days days2secs d::int = secsinday * d; days2hours d::int = 24*d; hours2days h::int = h div 24; @@ -100,6 +102,8 @@ mayanleft = days2mayan ((int daysleft)); timeleft = secs2htds ((int secsinday) - secsnow); percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; + +moonphase = 100.0*((int (posixsecsnow-newmoonsecs)) mod lunarmonth)/lunarmonth; usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help"; @@ -112,6 +116,7 @@ (daysleft, (str mayanleft), (str timeleft))) $ void (printf "The Mayan cycle of over 5125 years is now %11.8f%% complete\n" percentcomplete ) $ + void (printf "Current Moonphase is %f%%\n" moonphase) $ void (puts"****************************************************************"); 2 = void(puts "Mayan long count digits (and their range of values):") $ @@ -120,7 +125,7 @@ void (puts "\nNew clock digits (and their range of values):") $ void (puts "Hour(0-23) : Tre(0-19) : Dici(0-17) : Sec(0-9)")$ puts "Hour=3600secs Tre=180secs Dici=10secs Sec=second\n"$ - puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" + puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" $ usage; n = usage otherwise end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-04 23:40:35
|
Revision: 388 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=388&view=rev Author: yes Date: 2008-07-04 16:40:43 -0700 (Fri, 04 Jul 2008) Log Message: ----------- minor fixes Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-04 22:40:45 UTC (rev 387) +++ pure/trunk/examples/libor/date.pure 2008-07-04 23:40:43 UTC (rev 388) @@ -22,15 +22,15 @@ def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days def lunarmonth = 2551443; // lunar (synodic) month to the nearest second -def newmoonsecs = dhms2secs(14063:2:19:0); // 3/July/08 in posix +def newmoonsecs = dhms2secs(14063:2:19:0); // 3rd July 08 new moon in posix -// current posix time supplied by C time(); +// current values in posix time supplied by C time(); posixsecsnow = time; // int - each new call refreshes to the current second secsnow = posixsecsnow mod (int secsinday); // int seconds since midnight +moonphase = 100.0*((posixsecsnow-newmoonsecs) mod lunarmonth)/lunarmonth; // first some simple conversions -secs2days s::int | secs2days s::bigint = (s div (int secsinday)); -secs2days s::double = ( s / secsinday ); // this returns double days +secs2days s::int | secs2days s::bigint | secs2days s::double = (s / secsinday); days2secs d::int = secsinday * d; days2hours d::int = 24*d; hours2days h::int = h div 24; @@ -39,7 +39,8 @@ // seconds can be int or bigint or double. d,h,m are ints dhms2secs (d::int:h::int:m::int:s::int) | dhms2secs (d::int:h::int:m::int:s::bigint) | -dhms2secs (d::int:h::int:m::int:s::double) = 60.0*(60*(24*d+h)+m)+s; +dhms2secs (d::int:h::int:m::int:s::double) = 60*(60*(24*d+h)+m)+s; + secs2dhms secs::int | secs2dhms secs::bigint | secs2dhms secs::double = d:(h mod 24):(m mod 60):(secs-60*m) when @@ -47,6 +48,7 @@ h::int = m div 60; d::int = h div 24 end; + // an arbitrary binary operator applied to two (days:hours:minutes:seconds) opdhms op (d1::int:h1::int:m1::int:s1)(d2::int:h2::int:m2::int:s2) = secs2dhms (op (dhms2secs (d1:h1:m1:s1)) (dhms2secs (d2:h2:m2:s2))); @@ -55,7 +57,8 @@ // hours may be more than 24 but use d:h:m:s for longer periods of time hms2secs (h::int:m::int:s::int) | hms2secs (h::int:m::int:s::bigint) | -hms2secs (h::int:m::int:s::double) = 60.0*(60*h+m)+s; +hms2secs (h::int:m::int:s::double) = 60*(60*h+m)+s; + secs2hms secs::int | secs2hms secs::bigint | secs2hms secs::double = h:(m mod 60):(secs-60*m) when @@ -68,7 +71,8 @@ // dicis:secs are easy to read: 6:0 means 60 seconds, 12:5 125 seconds etc. // tres - multiply by three to get traditional babylonian minutes // hours as usual (24 hour clock) -htds2secs (h::int:t::int:d::int:s::int) = 10.0*(18*(20*h+t)+d)+s; +htds2secs (h::int:t::int:d::int:s::int) = 10*(18*(20*h+t)+d)+s; + secs2htds secs::int | secs2htds secs::bigint | secs2htds secs::double = h:(t mod 20):(d mod 18):(secs-10*d) when @@ -97,26 +101,23 @@ // for now, let's just do some simple calculations to print daytoday = epochday + (secs2days posixsecsnow); // mayan whole day count -mayantoday = days2mayan daytoday; // as above but in mayan long count format +mayantoday = days2mayan (int daytoday); // as above but in the long count format daysleft = cycledays - epochday - (secs2days (double posixsecsnow)); // double mayanleft = days2mayan ((int daysleft)); timeleft = secs2htds ((int secsinday) - secsnow); percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; - -moonphase = 100.0*((int (posixsecsnow-newmoonsecs)) mod lunarmonth)/lunarmonth; usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help"; case argc of - 1 = - void (printf "Mayan day %d + UTC Time %s = %s,%s\n" (daytoday, + 1 = void (printf "\t\tThe moonphase now is: %7.4f%%\n" moonphase) $ + void (printf "Mayan day %d + UTC Time %s = %s,%s\n" ((int daytoday), (str (secs2hms secsnow)),(str mayantoday),(str (secs2htds secsnow))))$ - void (printf "Long countdown %f(days left) = %s,%s\n" + void (printf "Long countdown: %f days left = %s,%s\n" (daysleft, (str mayanleft), (str timeleft))) $ void (printf "The Mayan cycle of over 5125 years is now %11.8f%% complete\n" percentcomplete ) $ - void (printf "Current Moonphase is %f%%\n" moonphase) $ void (puts"****************************************************************"); 2 = void(puts "Mayan long count digits (and their range of values):") $ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-05 20:01:23
|
Revision: 391 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=391&view=rev Author: yes Date: 2008-07-05 13:01:33 -0700 (Sat, 05 Jul 2008) Log Message: ----------- stylistic improvements and simplification to integral seconds Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-05 09:38:36 UTC (rev 390) +++ pure/trunk/examples/libor/date.pure 2008-07-05 20:01:33 UTC (rev 391) @@ -14,26 +14,23 @@ puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; puts "****************************************************************"; def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch -def epochday = mayan2days posixepoch; // (mayan) day of the posix epoch def endofcycle = (13:0:0:0:0); // The end of the cycle -def cycledays = mayan2days endofcycle; // total days in 13 Baktuns -def secsinday = 86400.0; // number of seconds in a day +def secsinday = 86400; // number of seconds in a day def trueyear = 31556941;// (in seconds) divisible by 13 = current true year def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days def lunarmonth = 2551443; // lunar (synodic) month to the nearest second -def newmoonsecs = dhms2secs(14063:2:19:0); // 3rd July 08 new moon in posix +def newmoondhms = (14063:2:19:0); // 3rd July 08 new moon in posix dhms // current values in posix time supplied by C time(); posixsecsnow = time; // int - each new call refreshes to the current second -secsnow = posixsecsnow mod (int secsinday); // int seconds since midnight -moonphase = 100.0*((posixsecsnow-newmoonsecs) mod lunarmonth)/lunarmonth; +secsnow = posixsecsnow mod secsinday; // int seconds since midnight // first some simple conversions secs2days s::int | secs2days s::bigint | secs2days s::double = (s / secsinday); -days2secs d::int = secsinday * d; -days2hours d::int = 24*d; -hours2days h::int = h div 24; +days2secs d::int | days2secs d::bigint | deys2secs d::double = secsinday * d; +days2hours d::int| days2hours d::bigint| days2hours d::double= 24*d; +hours2days h::int = h / 24; // conversions from/to days:hours:minutes:seconds format // seconds can be int or bigint or double. d,h,m are ints @@ -98,35 +95,47 @@ mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; + +// moon calculations +moonphase psecs::int=((psecs-(dhms2secs newmoondhms))mod lunarmonth)/lunarmonth; +// full moon percentage at psecs posix seconds +fullmoon psecs::int = if mf > 0.5 then 200.0*(1.0-mf) else 200.0*mf + when mf = moonphase psecs end; // for now, let's just do some simple calculations to print +def epochday = mayan2days posixepoch; // (mayan) day of the posix epoch +def cycledays = mayan2days endofcycle; // total days in 13 Baktuns daytoday = epochday + (secs2days posixsecsnow); // mayan whole day count mayantoday = days2mayan (int daytoday); // as above but in the long count format -daysleft = cycledays - epochday - (secs2days (double posixsecsnow)); // double +daysleft = cycledays-epochday-(secs2days (double posixsecsnow)); // double mayanleft = days2mayan ((int daysleft)); -timeleft = secs2htds ((int secsinday) - secsnow); +timeleft = secs2htds (secsinday - secsnow); percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help"; case argc of - 1 = void (printf "\t\tThe moonphase now is: %7.4f%%\n" moonphase) $ - void (printf "Mayan day %d + UTC Time %s = %s,%s\n" ((int daytoday), - (str (secs2hms secsnow)),(str mayantoday),(str (secs2htds secsnow))))$ - void (printf "Long countdown: %f days left = %s,%s\n" - (daysleft, (str mayanleft), (str timeleft))) $ - void (printf "The Mayan cycle of over 5125 years is now %11.8f%% complete\n" - percentcomplete ) $ - void (puts"****************************************************************"); + 1 = + printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ + printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds (secsnow-1)))$ + printf "%7.4f %% \tFullness of the Moon\n" (fullmoon posixsecsnow) $ + printf "%d \tMayan day number\n" (int daytoday) $ + printf "%s \tMayan long count notation for this day\n" (str mayantoday) $ + printf "%s \tLong countdown of days to the end of this cycle\n" + (str mayanleft) $ + printf "%s \tTime (h:t:d:s) countdown of today\n" (str timeleft) $ + printf "%11.8f %%\tCompletion of the Mayan cycle of over 5125 years\n" + percentcomplete $ + puts "****************************************************************"; 2 = - void(puts "Mayan long count digits (and their range of values):") $ - void(puts "Baktun(0-12) : Katun(0-19) : Tun(0-19) : Vinal(0-17) : Kin(0-19)")$ - puts "Baktun=144000days Katun=7200days Tun=360days Vinal=20days Kin=day"$ - void (puts "\nNew clock digits (and their range of values):") $ - void (puts "Hour(0-23) : Tre(0-19) : Dici(0-17) : Sec(0-9)")$ - puts "Hour=3600secs Tre=180secs Dici=10secs Sec=second\n"$ - puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" $ - usage; - n = usage otherwise + puts "Mayan long count digits (and their range of values):" $ + puts "Baktun(0-12) : Katun(0-19) : Tun(0-19) : Vinal(0-17) : Kin(0-19)" $ + puts "Baktun=144000days Katun=7200days Tun=360days Vinal=20days Kin=day" $ + puts "\nNew clock digits (and their range of values):" $ + puts "Hour(0-23) : Tre(0-19) : Dici(0-17) : Sec(0-9)" $ + puts "Hour=3600secs Tre=180secs Dici=10secs Sec=second\n" $ + puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" $ + usage; + n = usage end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-05 21:49:37
|
Revision: 392 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=392&view=rev Author: yes Date: 2008-07-05 14:49:42 -0700 (Sat, 05 Jul 2008) Log Message: ----------- fixed a portability issue with external time declaration Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-05 20:01:33 UTC (rev 391) +++ pure/trunk/examples/libor/date.pure 2008-07-05 21:49:42 UTC (rev 392) @@ -8,7 +8,7 @@ (Temps Atomique International) rather than local daylight saving time */ using system; // this is needed just to get C printf -extern int time(); // makes available the C function time(); +extern int time(int*) = c_time; // makes available the C function time(); puts "****************************************************************"; puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; @@ -16,14 +16,14 @@ def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch def endofcycle = (13:0:0:0:0); // The end of the cycle def secsinday = 86400; // number of seconds in a day -def trueyear = 31556941;// (in seconds) divisible by 13 = current true year -def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days -def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days +def trueyear = 31556941;// (in seconds) divisible by 13 = current true year +def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days +def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days def lunarmonth = 2551443; // lunar (synodic) month to the nearest second -def newmoondhms = (14063:2:19:0); // 3rd July 08 new moon in posix dhms +def newmoondhms= (14063:2:19:0); // 3rd July 08 new moon in posix dhms // current values in posix time supplied by C time(); -posixsecsnow = time; // int - each new call refreshes to the current second +posixsecsnow = c_time (pointer 0); // each call refreshes to the current second secsnow = posixsecsnow mod secsinday; // int seconds since midnight // first some simple conversions @@ -113,7 +113,7 @@ percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; usage = puts "Usage: pure -x date.pure [anyarg]" $ - puts "\tanyarg for help"; + puts "\tanyarg for help\n"; case argc of 1 = @@ -129,13 +129,13 @@ percentcomplete $ puts "****************************************************************"; 2 = - puts "Mayan long count digits (and their range of values):" $ + puts "Mayan long count digits and their ranges of values:" $ puts "Baktun(0-12) : Katun(0-19) : Tun(0-19) : Vinal(0-17) : Kin(0-19)" $ puts "Baktun=144000days Katun=7200days Tun=360days Vinal=20days Kin=day" $ - puts "\nNew clock digits (and their range of values):" $ - puts "Hour(0-23) : Tre(0-19) : Dici(0-17) : Sec(0-9)" $ - puts "Hour=3600secs Tre=180secs Dici=10secs Sec=second\n" $ - puts "Complete time count: Baktun:Katun:Tun:Vinal:Kin,Hour:Tre:Dici:Sec\n" $ + puts "\nNew clock digits and their ranges of values:" $ + puts "hour(0-23) : tre(0-19) : dici(0-17) : second(0-9)" $ + puts "hour=3600s : tre=180s : dici=10s : s=second\n" $ + puts "Full time spec: Baktun:Katun:Tun:Vinal:Kin hour:tre:dici:second\n" $ usage; n = usage end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-06 00:58:41
|
Revision: 395 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=395&view=rev Author: yes Date: 2008-07-05 17:58:50 -0700 (Sat, 05 Jul 2008) Log Message: ----------- more simplifications and addition of Gregorian dates based on Dr Albert Graef's Q code Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-06 00:20:07 UTC (rev 394) +++ pure/trunk/examples/libor/date.pure 2008-07-06 00:58:50 UTC (rev 395) @@ -1,5 +1,8 @@ /* New Calendar and Clock Copyright (c) 2008 by Libor Spacek + + Acknowledgement: thanks to Dr Albert Graef for his "Q" code for the + Gregorian date calculation Usage: pure -x date.pure [-h] @@ -8,13 +11,16 @@ (Temps Atomique International) rather than local daylight saving time */ using system; // this is needed just to get C printf -extern int time(int*) = c_time; // makes available the C function time(); +extern long time(long*) = c_time; // makes available the C function time(); puts "****************************************************************"; puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; puts "****************************************************************"; -def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch -def endofcycle = (13:0:0:0:0); // The end of the cycle +// def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch +def mdayposix = 1856305; // Mayan day for the posix epoch Jan 1 1970 +def jdayposix = 2440588; // Julian day for the posix epoch +// def endofcycle = (13:0:0:0:0); // The end of the cycle +def cycledays = 1872000; // Total days in 13 Baktuns def secsinday = 86400; // number of seconds in a day def trueyear = 31556941;// (in seconds) divisible by 13 = current true year def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days @@ -25,25 +31,37 @@ // current values in posix time supplied by C time(); posixsecsnow = c_time (pointer 0); // each call refreshes to the current second secsnow = posixsecsnow mod secsinday; // int seconds since midnight + +// either mayan or julian day (and time) as a day number (::double) +mjday epoch::int secs::int |mjday epoch::int secs::bigint= epoch+secs/secsinday; // first some simple conversions +jday2mday day::int | jday2mday day::double = day - jdayposix + mdayposix; +mday2jday day::int | mday2jday day::double = day - mdayposix + jdayposix; + secs2days s::int | secs2days s::bigint | secs2days s::double = (s / secsinday); days2secs d::int | days2secs d::bigint | deys2secs d::double = secsinday * d; days2hours d::int| days2hours d::bigint| days2hours d::double= 24*d; hours2days h::int = h / 24; // conversions from/to days:hours:minutes:seconds format -// seconds can be int or bigint or double. d,h,m are ints +// seconds can be int or double. d,h,m are ints dhms2secs (d::int:h::int:m::int:s::int) | -dhms2secs (d::int:h::int:m::int:s::bigint) | dhms2secs (d::int:h::int:m::int:s::double) = 60*(60*(24*d+h)+m)+s; -secs2dhms secs::int | secs2dhms secs::bigint | secs2dhms secs::double = - d:(h mod 24):(m mod 60):(secs-60*m) +secs2dhms secs::int | secs2dhms secs::bigint = + d:(h mod 24):(m mod 60):(int (secs-60*m)) when m::int = int (secs / 60); h::int = m div 60; d::int = h div 24 + end; + +secs2dhms secs::double = d:(h mod 24):(m mod 60):(secs-60*m) + when + m::int = int (secs / 60); + h::int = m div 60; + d::int = h div 24 end; // an arbitrary binary operator applied to two (days:hours:minutes:seconds) @@ -53,14 +71,17 @@ // conversions from/to hours:minutes:seconds format for displaying time of day. // hours may be more than 24 but use d:h:m:s for longer periods of time hms2secs (h::int:m::int:s::int) | -hms2secs (h::int:m::int:s::bigint) | hms2secs (h::int:m::int:s::double) = 60*(60*h+m)+s; -secs2hms secs::int | secs2hms secs::bigint | secs2hms secs::double = - h:(m mod 60):(secs-60*m) +secs2hms secs::int | secs2hms secs::bigint = h:(m mod 60):(int (secs-60*m)) when m::int = int (secs / 60); h::int = m div 60; + end; +secs2hms secs::double = h:(m mod 60):(secs-60*m) + when + m::int = int (secs / 60); + h::int = m div 60; end; // New Time Format! hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s @@ -68,16 +89,24 @@ // dicis:secs are easy to read: 6:0 means 60 seconds, 12:5 125 seconds etc. // tres - multiply by three to get traditional babylonian minutes // hours as usual (24 hour clock) -htds2secs (h::int:t::int:d::int:s::int) = 10*(18*(20*h+t)+d)+s; +htds2secs (h::int:t::int:d::int:s::int)| +htds2secs (h::int:t::int:d::int:s::double) = 10*(18*(20*h+t)+d)+s; -secs2htds secs::int | secs2htds secs::bigint | secs2htds secs::double = - h:(t mod 20):(d mod 18):(secs-10*d) +secs2htds secs::int | secs2htds secs::bigint = + h:(t mod 20):(d mod 18):(int (secs-10*d)) when d::int = int (secs / 10); t::int = d div 18; h::int = t div 20 end; +secs2htds secs::double = h:(t mod 20):(d mod 18):(secs-10*d) + when + d::int = int (secs / 10); + t::int = d div 18; + h::int = t div 20 + end; + // not used yet but could be, as in: addmayan posixepoch (days2mayan posixdays) addmayan (baktun1::int:katun1::int:tun1::int:vinal1::int:kin1::int) (baktun2::int:katun2::int:tun2::int:vinal2::int:kin2::int) = @@ -96,29 +125,39 @@ mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; +/* Gregorian date for Julian day number. Please note that these dates are + historically correct only after the introduction of the Gregorian calendar + in 1582 (even much later in some countries). */ + +date N::int = (E-(153*M+2) div 5+1, M+3-12*(M div 10), 100*B+D-4800+M div 10) + when A = N+32044; B = (4*A+3) div 146097; + C = A-146097*B div 4; D = (4*C+3) div 1461; + E = C-1461*D div 4; M = (5*E+2) div 153 end; + + // moon calculations -moonphase psecs::int=((psecs-(dhms2secs newmoondhms))mod lunarmonth)/lunarmonth; +moonphase psecs::int | moonphase psecs::bigint = + ((psecs-(dhms2secs newmoondhms))mod lunarmonth)/lunarmonth; // full moon percentage at psecs posix seconds -fullmoon psecs::int = if mf > 0.5 then 200.0*(1.0-mf) else 200.0*mf - when mf = moonphase psecs end; - +fullmoon psecs::int | fullmoon psecs::bigint = + if mf > 0.5 then 200.0*(1.0-mf) else 200.0*mf when mf = moonphase psecs end; + // for now, let's just do some simple calculations to print -def epochday = mayan2days posixepoch; // (mayan) day of the posix epoch -def cycledays = mayan2days endofcycle; // total days in 13 Baktuns -daytoday = epochday + (secs2days posixsecsnow); // mayan whole day count +daytoday = mjday mdayposix posixsecsnow; // mayan day (double) mayantoday = days2mayan (int daytoday); // as above but in the long count format -daysleft = cycledays-epochday-(secs2days (double posixsecsnow)); // double +daysleft = cycledays - daytoday; mayanleft = days2mayan ((int daysleft)); timeleft = secs2htds (secsinday - secsnow); -percentcomplete = 100.0*(epochday+posixsecsnow/secsinday)/cycledays; +percentcomplete = 100.0*daytoday/cycledays; usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help\n"; case argc of - 1 = - printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ - printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds (secsnow-1)))$ + 1 = + printf "%s \tToday's Gregorian Date\n"(str(date(mday2jday(int daytoday))))$ + printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ + printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ printf "%7.4f %% \tFullness of the Moon\n" (fullmoon posixsecsnow) $ printf "%d \tMayan day number\n" (int daytoday) $ printf "%s \tMayan long count notation for this day\n" (str mayantoday) $ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-06 01:36:47
|
Revision: 396 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=396&view=rev Author: yes Date: 2008-07-05 18:36:57 -0700 (Sat, 05 Jul 2008) Log Message: ----------- updated, using the pure system time function Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-06 00:58:50 UTC (rev 395) +++ pure/trunk/examples/libor/date.pure 2008-07-06 01:36:57 UTC (rev 396) @@ -10,8 +10,8 @@ returns Posix time based on UTC (Universal Temps Coordinat) or TAI (Temps Atomique International) rather than local daylight saving time */ -using system; // this is needed just to get C printf -extern long time(long*) = c_time; // makes available the C function time(); +using system; +// extern long time(long*) = c_time; // Now replaced by time in system puts "****************************************************************"; puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; @@ -29,8 +29,7 @@ def newmoondhms= (14063:2:19:0); // 3rd July 08 new moon in posix dhms // current values in posix time supplied by C time(); -posixsecsnow = c_time (pointer 0); // each call refreshes to the current second -secsnow = posixsecsnow mod secsinday; // int seconds since midnight +secsnow = time mod secsinday; // int seconds since midnight // either mayan or julian day (and time) as a day number (::double) mjday epoch::int secs::int |mjday epoch::int secs::bigint= epoch+secs/secsinday; @@ -143,7 +142,7 @@ if mf > 0.5 then 200.0*(1.0-mf) else 200.0*mf when mf = moonphase psecs end; // for now, let's just do some simple calculations to print -daytoday = mjday mdayposix posixsecsnow; // mayan day (double) +daytoday = mjday mdayposix time; // mayan day (double) mayantoday = days2mayan (int daytoday); // as above but in the long count format daysleft = cycledays - daytoday; mayanleft = days2mayan ((int daysleft)); @@ -158,7 +157,7 @@ printf "%s \tToday's Gregorian Date\n"(str(date(mday2jday(int daytoday))))$ printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ - printf "%7.4f %% \tFullness of the Moon\n" (fullmoon posixsecsnow) $ + printf "%7.4f %% \tFullness of the Moon\n" (fullmoon time) $ printf "%d \tMayan day number\n" (int daytoday) $ printf "%s \tMayan long count notation for this day\n" (str mayantoday) $ printf "%s \tLong countdown of days to the end of this cycle\n" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-06 22:48:56
|
Revision: 404 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=404&view=rev Author: yes Date: 2008-07-06 15:49:06 -0700 (Sun, 06 Jul 2008) Log Message: ----------- added Venus conjunctions, Gregorian dates, and Julian days Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-06 22:48:40 UTC (rev 403) +++ pure/trunk/examples/libor/date.pure 2008-07-06 22:49:06 UTC (rev 404) @@ -2,7 +2,7 @@ Copyright (c) 2008 by Libor Spacek Acknowledgement: thanks to Dr Albert Graef for his "Q" code for the - Gregorian date calculation + Julian day and Gregorian dates Usage: pure -x date.pure [-h] @@ -10,36 +10,47 @@ returns Posix time based on UTC (Universal Temps Coordinat) or TAI (Temps Atomique International) rather than local daylight saving time */ -using system; -// extern long time(long*) = c_time; // Now replaced by time in system +using system; // import printf, time, ctime, gmtime, gettimeofday +// extern long time(long*) = c_time; //diy time, no longer needed +// diytime = c_time (pointer 0); puts "****************************************************************"; puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; puts "****************************************************************"; // def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch -def mdayposix = 1856305; // Mayan day for the posix epoch Jan 1 1970 -def jdayposix = 2440588; // Julian day for the posix epoch -// def endofcycle = (13:0:0:0:0); // The end of the cycle -def cycledays = 1872000; // Total days in 13 Baktuns -def secsinday = 86400; // number of seconds in a day +def mdayposix = 1856305;// Mayan day for the posix epoch Jan 1 1970 +def jdayposix = 2440588;// Julian day for the posix epoch +def cycledays = 1872000;// end of cycle: total days in 13 Baktuns + +def secsinday = 86400; // number of seconds in a day def trueyear = 31556941;// (in seconds) divisible by 13 = current true year def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days -def lunarmonth = 2551443; // lunar (synodic) month to the nearest second -def newmoondhms= (14063:2:19:0); // 3rd July 08 new moon in posix dhms +def lunarmonth = 2551443; // lunar (synodic) month to the nearest second +def newmoon = 1215051540;// 3rd July 2008, 2:19 am, new moon in posix seconds +def venussyn = 50450688;// seconds in a Venus synodic cycle +def venusinf = 1187409600;// 18th August 2007, 4am Venus inferior conjunction // current values in posix time supplied by C time(); secsnow = time mod secsinday; // int seconds since midnight + +// strip the inconvenient \n off strings given by ctime, gmtime +stripnl s::string = reverse (tail (reverse s)); -// either mayan or julian day (and time) as a day number (::double) +// either mayan or julian posix epoch (and posix time) as a mjday number mjday epoch::int secs::int |mjday epoch::int secs::bigint= epoch+secs/secsinday; -// first some simple conversions +// first some simple day conversions jday2mday day::int | jday2mday day::double = day - jdayposix + mdayposix; -mday2jday day::int | mday2jday day::double = day - mdayposix + jdayposix; - +mday2jday day::int | mday2jday day::double = day - mdayposix + jdayposix; +jday2pday day::int | jday2pday day::double = day - jdayposix; +mday2pday day::int | mday2pday day::double = day - mdayposix; +pday2jday day::int | pday2jday day::double = day + jdayposix; +pday2mday day::int | pday2mday day::double = day + mdayposix; + +// inner units conversions for convenience and readability secs2days s::int | secs2days s::bigint | secs2days s::double = (s / secsinday); -days2secs d::int | days2secs d::bigint | deys2secs d::double = secsinday * d; +days2secs d::int | days2secs d::bigint | days2secs d::double = secsinday * d; days2hours d::int| days2hours d::bigint| days2hours d::double= 24*d; hours2days h::int = h / 24; @@ -124,24 +135,38 @@ mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; -/* Gregorian date for Julian day number. Please note that these dates are - historically correct only after the introduction of the Gregorian calendar - in 1582 (even much later in some countries). */ +/* Julian day number for Gregorian dates (D,M,Y). These count the number of + days since 1 January 4713 BC in the Julian calendar. */ -date N::int = (E-(153*M+2) div 5+1, M+3-12*(M div 10), 100*B+D-4800+M div 10) - when A = N+32044; B = (4*A+3) div 146097; - C = A-146097*B div 4; D = (4*C+3) div 1461; - E = C-1461*D div 4; M = (5*E+2) div 153 end; +greg2jdays (D::int,M::int,Y::int) = + D+(153*M+2) div 5+365*Y+Y div 4-Y div 100+Y div 400-32045 + when A = (14-M) div 12; Y = Y+4800-A; M = M+12*A-3 end; + +greg2pdays date@(D::int,M::int,Y::int) = jday2pday (greg2jdays date); + +/* Gregorian date (D,M,Y) for Julian day number. Please note that these dates + are historically correct only after the introduction of the Gregorian + calendar in 1582 (even much later in some countries). */ + +jdays2greg N::int = + (E-(153*M+2) div 5+1, M+3-12*(M div 10), 100*B+D-4800+M div 10) + when A = N+32044; B = (4*A+3) div 146097; + C = A-146097*B div 4; D = (4*C+3) div 1461; + E = C-1461*D div 4; M = (5*E+2) div 153 + end; +pdays2greg N::int = jdays2greg (pday2jday N); -// moon calculations -moonphase psecs::int | moonphase psecs::bigint = - ((psecs-(dhms2secs newmoondhms))mod lunarmonth)/lunarmonth; -// full moon percentage at psecs posix seconds -fullmoon psecs::int | fullmoon psecs::bigint = - if mf > 0.5 then 200.0*(1.0-mf) else 200.0*mf when mf = moonphase psecs end; +// conjunction phase (of Moon and Venus for now) at psecs (posix seconds) time +// expressed as percentage: inferior conjunction = 0% (new moon), superior=100% +phase init::int length::int psecs::int | +phase init::int length::int psecs::bigint = + if (mf > 0.5) then 200.0*(1.0-mf) else 200.0*mf + when mf = ((psecs-init) mod length)/length end; // for now, let's just do some simple calculations to print +moonpercent = phase newmoon lunarmonth time; +vp = phase venusinf venussyn time; daytoday = mjday mdayposix time; // mayan day (double) mayantoday = days2mayan (int daytoday); // as above but in the long count format daysleft = cycledays - daytoday; @@ -152,18 +177,23 @@ usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help\n"; +// here are test prints of some facts case argc of 1 = - printf "%s \tToday's Gregorian Date\n"(str(date(mday2jday(int daytoday))))$ - printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ - printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ - printf "%7.4f %% \tFullness of the Moon\n" (fullmoon time) $ - printf "%d \tMayan day number\n" (int daytoday) $ - printf "%s \tMayan long count notation for this day\n" (str mayantoday) $ - printf "%s \tLong countdown of days to the end of this cycle\n" + puts ((stripnl (ctime time)) + " Local Timestamp") $ + puts ((stripnl (gmtime time)) + " UTC Timestamp") $ +// printf "%s \tToday's Gregorian Date\n"(str(date(mday2jday(int daytoday))))$ +// printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ +// printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ + printf "%7.4f %%\t\t Fullness of the Moon\n" moonpercent $ + printf "%7.4f %%\t\t Venus between inf. and sup. conjunction\n" vp $ + printf "%d \t\t Mayan day number\n" (int daytoday) $ + printf "%d \t\t Julian day number\n" (int (mjday jdayposix time)) $ + printf "%s\t\t Mayan long count date for today\n" (str mayantoday) $ + printf "%s\t\t Long countdown to the end of this cycle\n" (str mayanleft) $ - printf "%s \tTime (h:t:d:s) countdown of today\n" (str timeleft) $ - printf "%11.8f %%\tCompletion of the Mayan cycle of over 5125 years\n" +// printf "%s \tTime (h:t:d:s) countdown of today\n" (str timeleft) $ + printf "%11.8f %%\t\t Completion of this cycle of >5125 years\n" percentcomplete $ puts "****************************************************************"; 2 = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-07 14:22:00
|
Revision: 410 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=410&view=rev Author: yes Date: 2008-07-07 07:22:07 -0700 (Mon, 07 Jul 2008) Log Message: ----------- generalised computation of all kinds of cycles, added use of strftime, improved comments, moreless complete now Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-07 11:19:13 UTC (rev 409) +++ pure/trunk/examples/libor/date.pure 2008-07-07 14:22:07 UTC (rev 410) @@ -10,25 +10,25 @@ returns Posix time based on UTC (Universal Temps Coordinat) or TAI (Temps Atomique International) rather than local daylight saving time */ -using system; // import printf, time, ctime, gmtime, gettimeofday -// extern long time(long*) = c_time; //diy time, no longer needed +using system; // imports printf, time, ctime, gmtime, gettimeofday, strftime +// extern long time(long*) = c_time; // diy time, no longer needed // diytime = c_time (pointer 0); puts "****************************************************************"; puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; puts "****************************************************************"; -// def posixepoch = (12:17:16:7:5); // Mayan long count date of the posix epoch -def mdayposix = 1856305;// Mayan day for the posix epoch Jan 1 1970 -def jdayposix = 2440588;// Julian day for the posix epoch +// some constants in whole days +def mdayposix = 1856305;// Mayan day for the posix epoch 1 Jan 1970 +def jdayposix = 2440588;// Julian day (since 1 Jan 4713 BC) for the posix epoch def cycledays = 1872000;// end of cycle: total days in 13 Baktuns - +// some constants in whole seconds def secsinday = 86400; // number of seconds in a day -def trueyear = 31556941;// (in seconds) divisible by 13 = current true year +def trueyear = 31556941;// current true year (divisible by 13) def myyear = 31556943;// div by 2277, secsinday compatible, 365.2424 days def gregyear = 31556952;// div by 40824, mean gregorian year, 365.2425 days -def lunarmonth = 2551443; // lunar (synodic) month to the nearest second -def newmoon = 1215051540;// 3rd July 2008, 2:19 am, new moon in posix seconds -def venussyn = 50450688;// seconds in a Venus synodic cycle +def lunarmonth = 2551443; // duration of the lunar synodic month +def fullmoon = 1213810200;// 18th June 2008, 17:30, full moon in posix seconds +def venussyn = 50450688;// duration of the Venus synodic cycle def venusinf = 1187409600;// 18th August 2007, 4am Venus inferior conjunction // current values in posix time supplied by C time(); @@ -37,10 +37,12 @@ // strip the inconvenient \n off strings given by ctime, gmtime stripnl s::string = init s; -// either mayan or julian posix epoch (and posix time) as a mjday number -mjday epoch::int secs::int |mjday epoch::int secs::bigint= epoch+secs/secsinday; +// either mayan or julian posix epoch (plus posix seconds), gives a double mjday +// to get current pday, use simple: secs2days time +mjday epoch::int secs::int| mjday epoch::int secs::bigint= epoch+secs/secsinday; -// first some simple day conversions +// all conversions between Julian (j) Mayan (m) and Posix (p), done in days +// jday mday pday are numbers of days since their relevant origins (epochs) jday2mday day::int | jday2mday day::double = day - jdayposix + mdayposix; mday2jday day::int | mday2jday day::double = day - mdayposix + jdayposix; jday2pday day::int | jday2pday day::double = day - jdayposix; @@ -54,8 +56,8 @@ days2hours d::int| days2hours d::bigint| days2hours d::double= 24*d; hours2days h::int = h / 24; -// conversions from/to days:hours:minutes:seconds format -// seconds can be int or double. d,h,m are ints +/* conversions from/to days:hours:minutes:seconds format + seconds can be int or double. d,h,m are ints */ dhms2secs (d::int:h::int:m::int:s::int) | dhms2secs (d::int:h::int:m::int:s::double) = 60*(60*(24*d+h)+m)+s; @@ -74,15 +76,15 @@ d::int = h div 24 end; -// an arbitrary binary operator applied to two (days:hours:minutes:seconds) +// an arbitrary binary operator applied to two (days:hours:minutes:seconds) opdhms op (d1::int:h1::int:m1::int:s1)(d2::int:h2::int:m2::int:s2) = secs2dhms (op (dhms2secs (d1:h1:m1:s1)) (dhms2secs (d2:h2:m2:s2))); -// conversions from/to hours:minutes:seconds format for displaying time of day. -// hours may be more than 24 but use d:h:m:s for longer periods of time +/* conversions from/to hours:minutes:seconds format for displaying time of day + hours may be more than 24 but use d:h:m:s for longer periods of time */ hms2secs (h::int:m::int:s::int) | hms2secs (h::int:m::int:s::double) = 60*(60*h+m)+s; - + secs2hms secs::int | secs2hms secs::bigint = h:(m mod 60):(int (secs-60*m)) when m::int = int (secs / 60); @@ -94,11 +96,11 @@ h::int = m div 60; end; -// New Time Format! hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s -// the normal seconds are now just a single digit 0-9 -// dicis:secs are easy to read: 6:0 means 60 seconds, 12:5 125 seconds etc. -// tres - multiply by three to get traditional babylonian minutes -// hours as usual (24 hour clock) +/* New Time Format: hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s + the normal seconds are now just a single digit 0-9 + dicis:secs are easy to read: 6:0 means 60 seconds, 12:5 125 seconds etc. + tres - multiply by three to get traditional babylonian minutes + hours as usual (24 hour clock) */ htds2secs (h::int:t::int:d::int:s::int)| htds2secs (h::int:t::int:d::int:s::double) = 10*(18*(20*h+t)+d)+s; @@ -117,7 +119,17 @@ h::int = t div 20 end; -// not used yet but could be, as in: addmayan posixepoch (days2mayan posixdays) +// Mayan 'long count' calendar presentation format +days2mayan d::int = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(d mod 20) + when + vinal =d div 20; tun =vinal div 18; katun =tun div 20; baktun =katun div 20 + end; + +mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = + 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; + +/* Calculations in Mayan long count format, e.g. addmayan day1 day2 + probably not needed, is the same as: days2mayan day1+day2; */ addmayan (baktun1::int:katun1::int:tun1::int:vinal1::int:kin1::int) (baktun2::int:katun2::int:tun2::int:vinal2::int:kin2::int) = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(kin mod 20) @@ -127,26 +139,24 @@ baktun = baktun1+baktun2+(katun div 20) end; -days2mayan d::int = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(d mod 20) - when - vinal =d div 20; tun =vinal div 18; katun =tun div 20; baktun =katun div 20 - end; - -mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = - 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; - -/* Julian day number for Gregorian dates (D,M,Y). These count the number of - days since 1 January 4713 BC in the Julian calendar. */ - +/* Gregorian calendar presentation format: (D,M,Y) + unlike the Mayan long count, these dates are historically correct only after + the introduction of Gregorian calendar in 1582 (much later in non-catholic + countries). Ten days had been 'deleted' by pope Gregory. However, due to + ignoring 'pagan' advice, the corrected drift now builds up over the periods + of 4,100,200,400 years. This buildup is currently 2.15 days between 1900 and + 2100! On top of that, an uncorrected drift still remains, estimated as the + minimum of 8 days by the year 12000. + These reasons make the Gregorian calendar dates useless for astronomical + purposes. Julian days (acknowledgement to Julius Caesar) are still used + and conversions to either Julian days or Mayan days are necessary. */ greg2jdays (D::int,M::int,Y::int) = D+(153*M+2) div 5+365*Y+Y div 4-Y div 100+Y div 400-32045 when A = (14-M) div 12; Y = Y+4800-A; M = M+12*A-3 end; greg2pdays date@(D::int,M::int,Y::int) = jday2pday (greg2jdays date); - -/* Gregorian date (D,M,Y) for Julian day number. Please note that these dates - are historically correct only after the introduction of the Gregorian - calendar in 1582 (even much later in some countries). */ +greg2psecs g hms = + (days2secs (greg2pdays g)) + (hms2secs hms); // date time -> psecs jdays2greg N::int = (E-(153*M+2) div 5+1, M+3-12*(M div 10), 100*B+D-4800+M div 10) @@ -157,22 +167,28 @@ pdays2greg N::int = jdays2greg (pday2jday N); -// conjunction phase (of Moon and Venus for now) at psecs (posix seconds) time -// expressed as percentage: inferior conjunction = 0% (new moon), superior=100% -phase init::int length::int psecs::int | -phase init::int length::int psecs::bigint = - if (mf > 0.5) then 200.0*(1.0-mf) else 200.0*mf - when mf = ((psecs-init) mod length)/length end; +/* phase of a cycle of 'length' from 'init' at time 'now' (must be same units) + this is surprisingly accurate without computing the full orbital elements */ +x::double mod y::int = + (x - intx) + (intx mod y) when intx = (int x) end; // mod of a double +phase init::int length::int now::int | +phase init::int length::int now::bigint | +phase init::int length::int now::double = ((now-init) mod length)/length; + +// same as above but returns dhms till the completion +completion init::int length::int now::int | +completion init::int length::int now::bigint | +completion init::int length::int now::double = length - ((now-init) mod length); // for now, let's just do some simple calculations to print -moonpercent = phase newmoon lunarmonth time; -vp = phase venusinf venussyn time; -daytoday = mjday mdayposix time; // mayan day (double) -mayantoday = days2mayan (int daytoday); // as above but in the long count format -daysleft = cycledays - daytoday; -mayanleft = days2mayan ((int daysleft)); -timeleft = secs2htds (secsinday - secsnow); -percentcomplete = 100.0*daytoday/cycledays; +nextfmoon = secs2days (completion fullmoon lunarmonth time); // in seconds +nextvenus = secs2days (completion venusinf venussyn time); +jdaytoday = int (mjday jdayposix time); // whole julian day +daytoday = mjday mdayposix time; // double mayan day +longtoday = str (days2mayan (int daytoday)); +nextcycle = completion 0 cycledays daytoday; // now in days +mayanleft = str (days2mayan (int nextcycle)); +complete = 100.0*(phase 0 cycledays daytoday); usage = puts "Usage: pure -x date.pure [anyarg]" $ puts "\tanyarg for help\n"; @@ -180,21 +196,19 @@ // here are test prints of some facts case argc of 1 = - puts ((stripnl (ctime time)) + " Local Timestamp") $ - puts ((stripnl (gmtime time)) + " UTC Timestamp") $ -// printf "%s \tToday's Gregorian Date\n"(str(date(mday2jday(int daytoday))))$ -// printf "%s \tUTC Time in h:m:s\n" (str (secs2hms secsnow)) $ -// printf "%s \tUTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ - printf "%7.4f %%\t\t Fullness of the Moon\n" moonpercent $ - printf "%7.4f %%\t\t Venus between inf. and sup. conjunction\n" vp $ - printf "%d \t\t Mayan day number\n" (int daytoday) $ - printf "%d \t\t Julian day number\n" (int (mjday jdayposix time)) $ - printf "%s\t\t Mayan long count date for today\n" (str mayantoday) $ - printf "%s\t\t Long countdown to the end of this cycle\n" - (str mayanleft) $ -// printf "%s \tTime (h:t:d:s) countdown of today\n" (str timeleft) $ - printf "%11.8f %%\t\t Completion of this cycle of >5125 years\n" - percentcomplete $ + puts ((strftime "%x" time) + "\t Gregorian preferred date") $ + puts ((strftime "%X" time) + "\t local time") $ +// puts ((stripnl (gmtime time)) + " UTC Time") $ + printf "%s \t UTC Time\n" (str (secs2hms secsnow)) $ + printf "%s \t UTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ + printf "%d \t Julian day number\n" jdaytoday $ + printf "%d \t Mayan day number\n" (int daytoday) $ + printf "%s\t Mayan long count date\n" longtoday $ + printf "%5.3f \t days till the next full Moon\n" nextfmoon $ + printf "%6.3f \t days till the next inf. conjunction of Venus\n" nextvenus$ + printf "%8.3f \t days till the end of the Mayan cycle\n" nextcycle $ + printf "%s\t long countdown to the end of the cycle\n" mayanleft $ + printf "%11.8f %%\t completion of this cycle of >5125 years\n" complete $ puts "****************************************************************"; 2 = puts "Mayan long count digits and their ranges of values:" $ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-08 00:05:29
|
Revision: 415 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=415&view=rev Author: yes Date: 2008-07-07 17:05:37 -0700 (Mon, 07 Jul 2008) Log Message: ----------- date.pure finished: enabled interactive/library use, added conjunctions of Venus, added parsing of gmtime using strings slicing, simplified some polymorphic code. Now there are functions to convert nearly anything to do with time to nearly anything else Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-07 23:03:58 UTC (rev 414) +++ pure/trunk/examples/libor/date.pure 2008-07-08 00:05:37 UTC (rev 415) @@ -4,8 +4,6 @@ Acknowledgement: thanks to Dr Albert Graef for his "Q" code for the Julian day and Gregorian dates - Usage: pure -x date.pure [-h] - Discrepancies with your local clock may occur when C library's time(); returns Posix time based on UTC (Universal Temps Coordinat) or TAI (Temps Atomique International) rather than local daylight saving time */ @@ -14,9 +12,6 @@ // extern long time(long*) = c_time; // diy time, no longer needed // diytime = c_time (pointer 0); -puts "****************************************************************"; -puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; -puts "****************************************************************"; // some constants in whole days def mdayposix = 1856305;// Mayan day for the posix epoch 1 Jan 1970 def jdayposix = 2440588;// Julian day (since 1 Jan 4713 BC) for the posix epoch @@ -31,27 +26,30 @@ def venussyn = 50450688;// duration of the Venus synodic cycle def venusinf = 1187409600;// 18th August 2007, 4am Venus inferior conjunction -// current values in posix time supplied by C time(); +/* extended mod operator to work on doubles, so that int, bigint and double + times can be conveniently used */ +x::double mod y::int = + (x - intx) + (intx mod y) when intx = (int x) end; // mod of a double + +// can also use secsnow = gettimeofday mod secsinday; double for more accuracy secsnow = time mod secsinday; // int seconds since midnight -// strip the inconvenient \n off strings given by ctime, gmtime -stripnl s::string = init s; - // either mayan or julian posix epoch (plus posix seconds), gives a double mjday -// to get current pday, use simple: secs2days time -mjday epoch::int secs::int| mjday epoch::int secs::bigint= epoch+secs/secsinday; +// to get current pday, use simple: (secs2days time) or (secs2days gettimeofday) +mjday epoch::int secs::int| mjday epoch::int secs::bigint | +mjday epoch::int secs::double = epoch+secs/secsinday;// use time or gettimeofday // all conversions between Julian (j) Mayan (m) and Posix (p), done in days // jday mday pday are numbers of days since their relevant origins (epochs) -jday2mday day::int | jday2mday day::double = day - jdayposix + mdayposix; -mday2jday day::int | mday2jday day::double = day - mdayposix + jdayposix; -jday2pday day::int | jday2pday day::double = day - jdayposix; -mday2pday day::int | mday2pday day::double = day - mdayposix; -pday2jday day::int | pday2jday day::double = day + jdayposix; -pday2mday day::int | pday2mday day::double = day + mdayposix; +jday2mday d::int | jday2mday d::double = d - jdayposix + mdayposix; +mday2jday d::int | mday2jday d::double = d - mdayposix + jdayposix; +jday2pday d::int | jday2pday d::double = d - jdayposix; +mday2pday d::int | mday2pday d::double = d - mdayposix; +pday2jday d::int | pday2jday d::double = d + jdayposix; +pday2mday d::int | pday2mday d::double = d + mdayposix; // inner units conversions for convenience and readability -secs2days s::int | secs2days s::bigint | secs2days s::double = (s / secsinday); +secs2days s::int | secs2days s::bigint | secs2days s::double = s / secsinday; days2secs d::int | days2secs d::bigint | days2secs d::double = secsinday * d; days2hours d::int| days2hours d::bigint| days2hours d::double= 24*d; hours2days h::int = h / 24; @@ -59,23 +57,17 @@ /* conversions from/to days:hours:minutes:seconds format seconds can be int or double. d,h,m are ints */ dhms2secs (d::int:h::int:m::int:s::int) | +dhms2secs (d::int:h::int:m::int:s::bigint) | dhms2secs (d::int:h::int:m::int:s::double) = 60*(60*(24*d+h)+m)+s; -secs2dhms secs::int | secs2dhms secs::bigint = - d:(h mod 24):(m mod 60):(int (secs-60*m)) +secs2dhms secs::int | secs2dhms secs::bigint | secs2dhms secs::double = + d:(h mod 24):(m mod 60):(secs mod 60) when m::int = int (secs / 60); h::int = m div 60; d::int = h div 24 end; - -secs2dhms secs::double = d:(h mod 24):(m mod 60):(secs-60*m) - when - m::int = int (secs / 60); - h::int = m div 60; - d::int = h div 24 - end; - + // an arbitrary binary operator applied to two (days:hours:minutes:seconds) opdhms op (d1::int:h1::int:m1::int:s1)(d2::int:h2::int:m2::int:s2) = secs2dhms (op (dhms2secs (d1:h1:m1:s1)) (dhms2secs (d2:h2:m2:s2))); @@ -83,18 +75,15 @@ /* conversions from/to hours:minutes:seconds format for displaying time of day hours may be more than 24 but use d:h:m:s for longer periods of time */ hms2secs (h::int:m::int:s::int) | +hms2secs (h::int:m::int:s::bigint) | hms2secs (h::int:m::int:s::double) = 60*(60*h+m)+s; -secs2hms secs::int | secs2hms secs::bigint = h:(m mod 60):(int (secs-60*m)) +secs2hms secs::int | secs2hms secs::bigint | secs2hms secs::double = + h:(m mod 60):(secs mod 60) when m::int = int (secs / 60); h::int = m div 60; end; -secs2hms secs::double = h:(m mod 60):(secs-60*m) - when - m::int = int (secs / 60); - h::int = m div 60; - end; /* New Time Format: hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s the normal seconds are now just a single digit 0-9 @@ -102,34 +91,28 @@ tres - multiply by three to get traditional babylonian minutes hours as usual (24 hour clock) */ htds2secs (h::int:t::int:d::int:s::int)| +htds2secs (h::int:t::int:d::int:s::bigint)| htds2secs (h::int:t::int:d::int:s::double) = 10*(18*(20*h+t)+d)+s; -secs2htds secs::int | secs2htds secs::bigint = - h:(t mod 20):(d mod 18):(int (secs-10*d)) +secs2htds secs::int | secs2htds secs::bigint | secs2htds secs::double = + h:(t mod 20):(d mod 18):(secs mod 10) when d::int = int (secs / 10); t::int = d div 18; h::int = t div 20 end; -secs2htds secs::double = h:(t mod 20):(d mod 18):(secs-10*d) - when - d::int = int (secs / 10); - t::int = d div 18; - h::int = t div 20 - end; - // Mayan 'long count' calendar presentation format days2mayan d::int = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(d mod 20) when - vinal =d div 20; tun =vinal div 18; katun =tun div 20; baktun =katun div 20 + vinal=d div 20; tun=vinal div 18; katun=tun div 20; baktun=katun div 20 end; mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = 20*(18*(20*(20*baktun+katun)+tun)+vinal)+kin; /* Calculations in Mayan long count format, e.g. addmayan day1 day2 - probably not needed, is the same as: days2mayan day1+day2; */ + probably not needed, as it is the same as: days2mayan day1+day2; */ addmayan (baktun1::int:katun1::int:tun1::int:vinal1::int:kin1::int) (baktun2::int:katun2::int:tun2::int:vinal2::int:kin2::int) = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(kin mod 20) @@ -155,6 +138,7 @@ when A = (14-M) div 12; Y = Y+4800-A; M = M+12*A-3 end; greg2pdays date@(D::int,M::int,Y::int) = jday2pday (greg2jdays date); + greg2psecs g hms = (days2secs (greg2pdays g)) + (hms2secs hms); // date time -> psecs @@ -166,11 +150,17 @@ end; pdays2greg N::int = jdays2greg (pday2jday N); - -/* phase of a cycle of 'length' from 'init' at time 'now' (must be same units) + +//parse gmtime string and extract the components +nullary wday mon day utc year; +gmparse wday psecs::int| gmparse wday psecs::bigint= (gmtime psecs)!!(0..2); +gmparse mon psecs::int | gmparse mon psecs::bigint = (gmtime psecs)!!(4..6); +gmparse day psecs::int | gmparse day psecs::bigint = (gmtime psecs)!!(8..9); +gmparse utc psecs::int | gmparse utc psecs::bigint = (gmtime psecs)!!(11..18); +gmparse year psecs::int| gmparse year psecs::bigint =(gmtime psecs)!!(20..24); + +/* phase of any cycle of 'length' from 'init' at time 'now' (must be same units) this is surprisingly accurate without computing the full orbital elements */ -x::double mod y::int = - (x - intx) + (intx mod y) when intx = (int x) end; // mod of a double phase init::int length::int now::int | phase init::int length::int now::bigint | phase init::int length::int now::double = ((now-init) mod length)/length; @@ -180,44 +170,50 @@ completion init::int length::int now::bigint | completion init::int length::int now::double = length - ((now-init) mod length); -// for now, let's just do some simple calculations to print +/******************************************************************************/ +// now let's do some simple calculations nextfmoon = secs2days (completion fullmoon lunarmonth time); // in seconds nextvenus = secs2days (completion venusinf venussyn time); -jdaytoday = int (mjday jdayposix time); // whole julian day -daytoday = mjday mdayposix time; // double mayan day +jdaytoday = mjday jdayposix time; // double julian day - could use gettimeofday +daytoday = mjday mdayposix time; // double mayan day - could use gettimeofday longtoday = str (days2mayan (int daytoday)); nextcycle = completion 0 cycledays daytoday; // now in days mayanleft = str (days2mayan (int nextcycle)); complete = 100.0*(phase 0 cycledays daytoday); -usage = puts "Usage: pure -x date.pure [anyarg]" $ - puts "\tanyarg for help\n"; +// usage = puts "Usage: pure -x date.pure [anyarg]" $ +// puts "\tanyarg for help\n"; -// here are test prints of some facts -case argc of - 1 = - puts ((strftime "%x" time) + "\t Gregorian preferred date") $ +// usage with pure -x commented out to enable interactive and "using" modes +// case argc of +// 1 = + +puts "****************************************************************"; +puts "* New Calendar/Clock, Copyright (c) 2008 by Libor Spacek *"; +puts "****************************************************************"; + + puts ((strftime "%x" time) + "\t Gregorian date") $ puts ((strftime "%X" time) + "\t local time") $ -// puts ((stripnl (gmtime time)) + " UTC Time") $ - printf "%s \t UTC Time\n" (str (secs2hms secsnow)) $ - printf "%s \t UTC Time in h:t:d:s\n" (str (secs2htds secsnow))$ - printf "%d \t Julian day number\n" jdaytoday $ - printf "%d \t Mayan day number\n" (int daytoday) $ + puts ((gmparse utc time) + "\t UTC time") $ +// printf "%s \t UTC Time in h:t:d:s\n" (str (secs2htds (int secsnow)))$ + printf "%12.4f \t Julian day\n" jdaytoday $ + printf "%12.4f \t Mayan day\n" daytoday $ printf "%s\t Mayan long count date\n" longtoday $ - printf "%5.3f \t days till the next full Moon\n" nextfmoon $ - printf "%6.3f \t days till the next inf. conjunction of Venus\n" nextvenus$ - printf "%8.3f \t days till the end of the Mayan cycle\n" nextcycle $ + printf "%6.4f \t days till the next full Moon\n" nextfmoon $ + printf "%7.4f \t days till the next inf. conjunction of Venus\n" nextvenus$ + printf "%9.4f \t days till the end of the Mayan cycle\n" nextcycle $ printf "%s\t long countdown to the end of the cycle\n" mayanleft $ printf "%11.8f %%\t completion of this cycle of >5125 years\n" complete $ puts "****************************************************************"; - 2 = +// 2 = // another argument was presented -> print help and usage puts "Mayan long count digits and their ranges of values:" $ puts "Baktun(0-12) : Katun(0-19) : Tun(0-19) : Vinal(0-17) : Kin(0-19)" $ puts "Baktun=144000days Katun=7200days Tun=360days Vinal=20days Kin=day" $ - puts "\nNew clock digits and their ranges of values:" $ - puts "hour(0-23) : tre(0-19) : dici(0-17) : second(0-9)" $ - puts "hour=3600s : tre=180s : dici=10s : s=second\n" $ - puts "Full time spec: Baktun:Katun:Tun:Vinal:Kin hour:tre:dici:second\n" $ - usage; - n = usage -end; + puts "****************************************************************"; +// puts "\nNew clock digits and their ranges of values:" $ +// puts "hour(0-23) : tre(0-19) : dici(0-17) : second(0-9)" $ +// puts "hour=3600s : tre=180s : dici=10s : s=second\n" $ +// puts "Full time spec: Baktun:Katun:Tun:Vinal:Kin hour:tre:dici:second\n" ; +// usage; +// n = usage // any other number of arguments -> just print usage +//end; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-08 01:32:20
|
Revision: 416 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=416&view=rev Author: yes Date: 2008-07-07 18:32:29 -0700 (Mon, 07 Jul 2008) Log Message: ----------- a bit more tidying up Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-08 00:05:37 UTC (rev 415) +++ pure/trunk/examples/libor/date.pure 2008-07-08 01:32:29 UTC (rev 416) @@ -4,9 +4,8 @@ Acknowledgement: thanks to Dr Albert Graef for his "Q" code for the Julian day and Gregorian dates - Discrepancies with your local clock may occur when C library's time(); - returns Posix time based on UTC (Universal Temps Coordinat) or TAI - (Temps Atomique International) rather than local daylight saving time */ + time; returns Posix time based on UTC (Universal Temps Coordinat) or + TAI (Temps Atomique International) rather than local daylight saving time */ using system; // imports printf, time, ctime, gmtime, gettimeofday, strftime // extern long time(long*) = c_time; // diy time, no longer needed @@ -39,7 +38,7 @@ mjday epoch::int secs::int| mjday epoch::int secs::bigint | mjday epoch::int secs::double = epoch+secs/secsinday;// use time or gettimeofday -// all conversions between Julian (j) Mayan (m) and Posix (p), done in days +// all conversions between Julian (j) Mayan (m) and Posix (p), in days // jday mday pday are numbers of days since their relevant origins (epochs) jday2mday d::int | jday2mday d::double = d - jdayposix + mdayposix; mday2jday d::int | mday2jday d::double = d - mdayposix + jdayposix; @@ -55,18 +54,14 @@ hours2days h::int = h / 24; /* conversions from/to days:hours:minutes:seconds format - seconds can be int or double. d,h,m are ints */ + seconds can be int, bigint or double. d,h,m are ints */ dhms2secs (d::int:h::int:m::int:s::int) | dhms2secs (d::int:h::int:m::int:s::bigint) | dhms2secs (d::int:h::int:m::int:s::double) = 60*(60*(24*d+h)+m)+s; secs2dhms secs::int | secs2dhms secs::bigint | secs2dhms secs::double = d:(h mod 24):(m mod 60):(secs mod 60) - when - m::int = int (secs / 60); - h::int = m div 60; - d::int = h div 24 - end; + when m::int = int (secs / 60); h::int = m div 60; d::int = h div 24 end; // an arbitrary binary operator applied to two (days:hours:minutes:seconds) opdhms op (d1::int:h1::int:m1::int:s1)(d2::int:h2::int:m2::int:s2) = @@ -80,10 +75,7 @@ secs2hms secs::int | secs2hms secs::bigint | secs2hms secs::double = h:(m mod 60):(secs mod 60) - when - m::int = int (secs / 60); - h::int = m div 60; - end; + when m::int = int (secs / 60); h::int = m div 60 end; /* New Time Format: hours:3mins:10secs:secs = hours:tres:dicis:secs = h:t:d:s the normal seconds are now just a single digit 0-9 @@ -96,16 +88,12 @@ secs2htds secs::int | secs2htds secs::bigint | secs2htds secs::double = h:(t mod 20):(d mod 18):(secs mod 10) - when - d::int = int (secs / 10); - t::int = d div 18; - h::int = t div 20 - end; + when d::int = int (secs / 10); t::int = d div 18; h::int = t div 20 end; // Mayan 'long count' calendar presentation format days2mayan d::int = baktun:(katun mod 20):(tun mod 20):(vinal mod 18):(d mod 20) when - vinal=d div 20; tun=vinal div 18; katun=tun div 20; baktun=katun div 20 + vinal=d div 20; tun=vinal div 18; katun=tun div 20; baktun=katun div 20 end; mayan2days (baktun::int:katun::int:tun::int:vinal::int:kin::int) = @@ -139,8 +127,9 @@ greg2pdays date@(D::int,M::int,Y::int) = jday2pday (greg2jdays date); -greg2psecs g hms = - (days2secs (greg2pdays g)) + (hms2secs hms); // date time -> psecs +// gregorian date time -> psecs +greg2psecs g@(D::int,M::int,Y::int) hms = + (days2secs (greg2pdays g)) + (hms2secs hms); jdays2greg N::int = (E-(153*M+2) div 5+1, M+3-12*(M div 10), 100*B+D-4800+M div 10) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-08 20:38:42
|
Revision: 425 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=425&view=rev Author: yes Date: 2008-07-08 13:38:51 -0700 (Tue, 08 Jul 2008) Log Message: ----------- added 'timex' function discussed earlier on pure-lang-users list Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-08 17:37:56 UTC (rev 424) +++ pure/trunk/examples/libor/date.pure 2008-07-08 20:38:51 UTC (rev 425) @@ -24,13 +24,17 @@ def fullmoon = 1213810200;// 18th June 2008, 17:30, full moon in posix seconds def venussyn = 50450688;// duration of the Venus synodic cycle def venusinf = 1187409600;// 18th August 2007, 4am Venus inferior conjunction - + +/******************************************************************************/ +// first a couple of functions generally useful in Pure: +// timer function: (timex (id (foo arg))) returns cputime, value of (foo arg) +timex fn = (clock-t)/CLOCKS_PER_SEC $ res when t = clock; res = fn end; + /* extended mod operator to work on doubles, so that int, bigint and double times can be conveniently used */ x::double mod y::int = (x - intx) + (intx mod y) when intx = (int x) end; // mod of a double - -// can also use secsnow = gettimeofday mod secsinday; double for more accuracy +/******************************************************************************/ secsnow = time mod secsinday; // int seconds since midnight // either mayan or julian posix epoch (plus posix seconds), gives a double mjday This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ye...@us...> - 2008-07-09 20:20:39
|
Revision: 431 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=431&view=rev Author: yes Date: 2008-07-09 13:20:47 -0700 (Wed, 09 Jul 2008) Log Message: ----------- made timex work with any number of arguments and return rounded ms cputime and elapsed time Modified Paths: -------------- pure/trunk/examples/libor/date.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-09 19:58:31 UTC (rev 430) +++ pure/trunk/examples/libor/date.pure 2008-07-09 20:20:47 UTC (rev 431) @@ -26,9 +26,14 @@ def venusinf = 1187409600;// 18th August 2007, 4am Venus inferior conjunction /******************************************************************************/ -// first a couple of functions generally useful in Pure: -// Albert Graef's timer function: returns cputime, value of (f onearg) -timex f x = (clock-t0)/CLOCKS_PER_SEC, res when t0 = clock; res = f x end; +// first some functions generally useful in Pure: +round n::double = int (n+0.5); +mstime = 1000.0*gettimeofday; +mscpu = 1000.0*clock/CLOCKS_PER_SEC; + +// timex returns a list: [ evaluated string argument, cputime, realtime ] +timex s::string = [(eval s), round (mscpu-c0), round (mstime-d0)] + when d0::double = mstime; c0::double = mscpu end; /* extended mod operator to work on doubles, so that int, bigint and double times can be conveniently used */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |