I have almost finished assembling the needed components of leap second logic for libqsastime.
1) tai-utc-gen.c (implemented a few days ago) generates a header with the needed leap-second information parsed from the tai-utc.dat file. 2) The programming of bhunt_search has been completed. The point here is to avoid scanning through the whole leap second table every time you are dealing with a broken-down or continuous time. So this algorithm follows the general idea in Numerical Recipes of first having a hunt phase where the increment (or decrement) in index is doubled until the value is bracketed, and then bisection is used to find the index such that x[index] <= value < x[index+1], (1) where "<=" and "<" stand for a generalized comparison (e.g., of broken-down time values or anything I can stuff into a struct). Programming a completely general routine for this task definitely tested and expanded my C skills, but I think the results are worth it, see below. 3) The testing of bhunt_search has now been completed with the implementation (revision 9594) of the bhunt_search_test executable. You specify ntable, offset, and multiplier for this routine via stdin. This executable creates a table of ntable double values (of 0. through (double) ntable-1) and searches that table at a set of ntest = (ntable-1)*multiplier +1 (2) points which are offset from the table range by offset. (Thus, large positive or negative offset values allow you to test repeated searches for data beyond the ends of the table.) An offset of zero and a multiplier of 1 mean you search the table for the exact table values rather than something in between the table values. For each of the ntest values, bhunt_search returns an index which the test routine then tests to make sure it satisfies condition 1 above. Here are some typical results which show extensive (!) testing of condition (1) above done in an extremely efficient way. (You can play with this test application yourself in the build tree.) softw...@raven> time echo '1000000 0 10'| lib/qsastime/bhunt_search_test ntable, offset, multiplier, ntest = 1000000, 0, 10, 9999991 Average number of gedouble calls per bhunt_search call = 19.951426 for ifhunt, ifrandom = 0,0 Average number of gedouble calls per bhunt_search call = 19.951496 for ifhunt, ifrandom = 0,1 Average number of gedouble calls per bhunt_search call = 2.200001 for ifhunt, ifrandom = 1,0 Average number of gedouble calls per bhunt_search call = 35.978823 for ifhunt, ifrandom = 1,1 Successful completion of bhunt_search test real 0m27.154s user 0m27.142s sys 0m0.012s softw...@raven> time echo '1000000 1000000 10'| lib/qsastime/bhunt_search_test ntable, offset, multiplier, ntest = 1000000, 1000000, 10, 9999991 Average number of gedouble calls per bhunt_search call = 20.000000 for ifhunt, ifrandom = 0,0 Average number of gedouble calls per bhunt_search call = 20.000000 for ifhunt, ifrandom = 0,1 Average number of gedouble calls per bhunt_search call = 1.000002 for ifhunt, ifrandom = 1,0 Average number of gedouble calls per bhunt_search call = 1.000002 for ifhunt, ifrandom = 1,1 Successful completion of bhunt_search test real 0m7.231s user 0m7.212s sys 0m0.004s As expected a table with 1 million entries (i.e, near 2^20 entries) takes only 20 calls to gedouble (my simple callback test code which compares two floating point numbers) to search on average per bhunt_search call if you turn off the hunt phase part of the routine. That number drops down almost to 2 if the hunt phase is turned on and the successive numbers tend to be correlated (as happens quite often with time variables, for example). The number drops close to unity if you are beyond the end of the table (which also happens often for time variables). The hunt phase actually slows down the search by roughly a factor of two for completely uncorrelated (i.e., random) variables, but that is a rare case for time variables so I will always leave the hunt phase turned on when using bhunt_search to determine (quickly!) e.g., the offset between TAI and UTC for a set of arbitrary epochs. I pleased with these results because (a) they stretched my C skills, (b) bhunt_search has proved to be quite efficient, and (c) bhunt_search worked right out of the box (usually my C programmes don't do that!). Obviously, the above tests are gross overkill, but I get a kick out of such extreme testing, and I hope you enjoy seeing such good extreme test results as well. ********** My next planned task is to use components 1) and 2) above to provide a libqsastime option (controlled via the ccontrol formal argument of plconfigtime or configqsas) to transform between UTC (which has leap seconds) and TAI. This is fairly straightforward, but non-trivial because the epochs when leap seconds are inserted are specified in UTC. Thus, some careful thought has to be used to figure out the equivalent TAI epochs when transforming from TAI to UTC. Another complication is the input epochs can be both broken-down time and continuous time. I plan to handle all of this by generalizing tai-utc-gen.c above to create 4 tables to be searched with all combinations of TAI and UTC with continuous and broken-down time. bhunt_search is already generalized to handle any type of table entry so it should be straightforward to search these 4 different tables as needed with appropriate "ge" callback functions. Note, the callback functions with broken-down time as the independent variable are going to be a little complicated since the first step will be to normalize the test variable (assuming the table variable is already normalized), and then compare years, months, days, etc., until greater than or equal is proved true or false. Once I have the TAI-UTC transformation licked, then a lot of other time systems which are a linear transform of TAI become accessible, e.g., TT, TCG, and GPS time. Those should all be available with the present API for both libqsastime (configqsas, btimeqsas, ctimeqsas, and strfqsas) and libplplot (plconfigtime, plbtime, plctime, and pltimefmt), and I am happy with this prospect. Alan __________________________ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linux-powered Science __________________________ ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Plplot-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/plplot-devel
