Incorrect JULDAY Results with Unsiged Integers

Name: Don Woodraska
E-mail Address: don.woodraska@lasp.colorado.edu
IDL version: IDL 5.4
Platform and OS: Unix?

Description of Behavior:

JULDAY appears to produce incorrect results when called in its six-variable version
with unsigned long and 64-bit integers.

Example Code:

IDL> print,!version
{ sparc sunos unix 5.4 Sep 25 2000      32      64}
IDL> $uname -a
SunOS sun4 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-30
IDL> mo=long(2) & day=long(16) & year=long(2001) & h=long(0) & m=long(0) &
s=long(0)
IDL> x=julday(mo,day,year,h,m,s)
IDL> help,x
X               DOUBLE    =        2451956.5

As expected, it works fine with all 6 long arguments, however, with
ulong...

IDL> mo=ulong(2) & day=ulong(16) & year=ulong(2001) & h=ulong(0) &
m=ulong(0) & s=ulong(0)
IDL> x=julday(mo,day,year,h,m,s)
IDL> help,x
X               DOUBLE    =    1.8140893e+08

This is not correct, however, if we leave off the h,m,s args...

IDL> mo=ulong(2) & day=ulong(16) & year=ulong(2001)
IDL> x=julday(mo,day,year)
IDL> help,x
X               LONG      =      2451957

It works! (This is the new Julian day starting at noon on Feb 16,2001.)

To demonstrate the ulong64 problem, here's more sample output.

IDL> mo=ulong64(2) & day=ulong64(16) & year=ulong64(2001) & h=ulong64(0) &
m=ulong64(0) & s=ulong64(0)
IDL> x=julday(mo,day,year,h,m,s)
IDL> help,x
X               DOUBLE    =    7.6861434e+17
IDL> x=julday(mo,day,year)
IDL> help,x
X               LONG      =      2451957

Know Workarounds or Fixes: 

Cast unsiged variables to signed variables.

RSI Technical Support Response:

The problem is with using an unsigned long integer. Inside JULDAY.PRO,
it subtracts 12 off of the hours before dividing by 24. This will cause
wrap-around for unsigned longs and unsigned long64s.

So you should be able to fix (no pun!) your problem by:

   in_jday = julday( umm, udd, uyear, FIX(uhr), umin, usec )

This bug has been logged with RSI, and will be fixed in the next IDL
version.

[Return to Table of Contents]

Last Updated 25 September 2002