From: Steve S. <s.s...@im...> - 2008-08-03 14:53:17
|
Dear Plplot-devel, I attach a patch that immunizes plplot from the peculiarities of C's mktime function, that arise because mktime requires input in localtime. The various recipes to calculate offsets from local time to utc, such as those in example x29, are not foolproof or portable. I have not explored the equivalent timegm function that I've seen in one of the plplot-devel threads, but some of them still rely on mktime and then attempt to adjust the result. The patch works by converting a broken-down (year, month, day, ...) utc time to seconds from a robust epoch, and also converting time_t t=0 to the same epoch so that the difference can be calculated. My understanding is that t=0 is not part of the C-standard, and certainly some implementations use different values. The robust epoch is seconds since 0AD. Actually this isn't a real date, but this choice is used by NASA NSSDC CDF file standards and the resulting code, which is what I used in modified form, is robust and has been in use for many years on numerous platforms. The result is a mktimeutc routine that replaces mktime and is the matching partner/inverse for gmtime. I've put the prototypes for the helper routines in plplotP.h, and the routines in pldtik.c, which is the only place where mktime is used in plplot. Indeed, it is only found in pldtfac, which is now tidier in that tdiff doesn't need to be calculated. I have NOT modified x29 to use mktimeutc, but I think it might be helpful for users that need to handle time to have access to it. It's not really part of the plplot api, but it wouldn't hurt to employ it in x29, with a small comment so the user can find it, to help users code their own time-handling routines. This matter is important to us since we supply a sophisticated analysis suite, QSAS (http://www.sp.ph.ic.ac.uk/csc-web/QSAS/qsas_welcome.html) for space plasma physics; time plays an absolutely critical role in the data handling and analysis, so our product needs to be robust. Up until now, we have used pgplot for graphics, but we are in the process of converting to plplot to avoid the porting issues with fortran in a C/C++ environment - especially in an attempt to port to Windows/mingw -, and to take advantage of ongoing plplot development. I'm sure you'll be hearing more from us, and I hope we will be able to contribute to the development in addition to cries for help. For those who want to look at or try my changes, I attach my pldtik.c routine. If you uncomment the prototypes near the top of that file and drop it into the src directory, it should build without any changes to header files and such. Comments welcome. Thanks for the good work. Steve -- +-------------------------------------------------------------------+ Professor Steven J Schwartz Phone: +44-(0)20-7594-7660 Space and Atmospheric Physics Fax: +44-(0)20-7594-7772 The Blackett Laboratory E-mail: s.s...@im... Imperial College London Office: Huxley 6M70 London SW7 2BW, U.K. Web: http://www.sp.ph.ic.ac.uk/~sjs +-------------------------------------------------------------------+ |