Re: days of the week [message #29836] |
Thu, 21 March 2002 09:01  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"Mark Hadfield" <m.hadfield@niwa.co.nz> writes:
> "Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
> news:ong02v434v.fsf@cow.physics.wisc.edu...
>
>> P.S. I think the built-in JULDAY function is the one of the most
>> dangerous function I have ever seen. It measures *calendar dates*
>> from *noon* by gosh!
>
> I couldn't agree more.
>
>> It also doesn't handle fractional days...
>
> Not true in recent versions...
>
> IDL> print, julday(03,21,2002)
> 2452355
> IDL> print, julday(03,21,2002,10,23,30)
> 2452354.9
>
> But that weird argument order (month, day, year, ...) is what I
> *really* hate.
That is true, and the irony here is that JULDAY came from Numerical
Recipes, and other criticisms about code quality aside, those NR guys
are *astronomers* gosh darnit!
The following is totally unintuitive to me:
IDL> print, julday(3d,21d,2002d), format='(D30.3)'
2452355.000
;; Now, how about "one second" later
IDL> print, julday(3d,21d,2002d,00d,00d,01d), format='(D30.3)'
2452354.500
It's because in one case the calendar dates are measured from noon,
and in the other they are measured from midnight.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
|
Re: days of the week [message #29841 is a reply to message #29836] |
Thu, 21 March 2002 07:34   |
Doug Rowland
Messages: 12 Registered: March 2002
|
Junior Member |
|
|
> Not true in recent versions...
>
> IDL> print, julday(03,21,2002)
> 2452355
> IDL> print, julday(03,21,2002,10,23,30)
> 2452354.9
>
> But that weird argument order (month, day, year, ...) is what I
> *really* hate.
>
> --
> Mark Hadfield
> m.hadfield@niwa.co.nz Ka puwaha et tai nei
> http://katipo.niwa.co.nz/~hadfield Hoea tatou
> National Institute for Water and Atmospheric Research (NIWA)
Ah yes, from the country that brought you Tab soda and George W. Bush...
At least IDL doesn't force everything to be in imperial units.
--
Doug Rowland
rowland@fields.space.umn.edu
School of Physics and Astronomy
University of Minnesota
|
|
|
|
|
Re: days of the week [message #29859 is a reply to message #29857] |
Wed, 20 March 2002 14:26   |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
"Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
news:ong02v434v.fsf@cow.physics.wisc.edu...
> P.S. I think the built-in JULDAY function is the one of the most
> dangerous function I have ever seen. It measures *calendar dates*
> from *noon* by gosh!
I couldn't agree more.
> It also doesn't handle fractional days...
Not true in recent versions...
IDL> print, julday(03,21,2002)
2452355
IDL> print, julday(03,21,2002,10,23,30)
2452354.9
But that weird argument order (month, day, year, ...) is what I
*really* hate.
--
Mark Hadfield
m.hadfield@niwa.co.nz Ka puwaha et tai nei
http://katipo.niwa.co.nz/~hadfield Hoea tatou
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
|
|
|
|
Re: days of the week [message #29866 is a reply to message #29865] |
Wed, 20 March 2002 08:25   |
eddie haskell
Messages: 29 Registered: September 1998
|
Junior Member |
|
|
> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?
David's routine does work, and just for the record, you can also use IDL's
label_date routine by throwing in a couple dummy parameters.
IDL> print, label_date(0,0,julday(11,17,2002),date_format='%W')
Sun
Cheers,
eddie
|
|
|
Re: days of the week [message #29867 is a reply to message #29866] |
Wed, 20 March 2002 08:26   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
David Fanning <david@dfanning.com> writes:
> Bastienne Schneiter (b.schneiter@meteonews.ch) writes:
>
>> I need to show a date in a little application. Its format is
>> YYYYMMDDHH. But I also have to show to which day of the week this date
>> correspond (MON, TUE etc).
>> Does anybody know how to determine the day of the week for a given
>> date?
>
> Here is a bonus question. What is the significance
> of a meteorological event that happens on a Thursday?
I think you mean an "astronomical" or "celestial" event, and it
actually happens today at 19:16:08 UTC.
To answer Bastienne's original question, it's actually easier to
compute the day of the week than the calendar date. That's because
there are no "leap" weekdays, or irregularly sized weeks. Weeks are
always exactly seven days long.
We know that March 24, 2002, is a Sunday. Thus, we can compute the
day of the week using the MOD function:
dayweek = (julday(month,day,year) - julday(3,24,2002)) MOD 7
dayweek = (dayweek + 7) MOD 7
Where 0 means Sunday and 6 means Saturday. The second statement is to
handle cases when DAYWEEK is negative, which happens with the MOD
function unfortunately.
Craig
P.S. I think the built-in JULDAY function is the one of the most
dangerous function I have ever seen. It measures *calendar dates*
from *noon* by gosh! It also doesn't handle fractional days, which is
a pity, but thankfully there are tons of IDL Astro/JHU functions which
overcome this.
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: days of the week [message #29868 is a reply to message #29866] |
Wed, 20 March 2002 07:47   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Bastienne Schneiter (b.schneiter@meteonews.ch) writes:
> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?
Alright. Here is a little function that, given the
julian date, will tell you what day of the week it
is. For example, suppose you want to get married
on November 17, 2002 and the preacher asks you what
day of the week that is. You do this:
"Uh, hold-on...."
IDL> juliandate = Julday(11, 17, 2002)
IDL> Print, WhatDayIsIt(juliandate)
Sunday
"Uh, that's a Sunday, Man."
Cheers,
David
P.S. Sorry for the FOR loop. I was in a hurry. :-(
************************************************************ ************
FUNCTION WhatDayIsIt, juliandate
; Need a date? Duh...
IF N_Elements(juliandate) EQ 0 THEN $
juliandate = Systime(/Julian)
; Make a table. Use week of March 17th, 2002.
daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', $
'Thursday', 'Friday', 'Saturday']
datemod = IntArr(7)
FOR j=0,6 DO BEGIN
jdate = Julday(3, 17 + j, 2002)
datemod[j] = jdate MOD 7
ENDFOR
; Convert to day, month, year.
CalDat, juliandate, month, day, year
jdate = Julday(month, day, year)
; What day of the week is it? Return it.
index = Where(datemod EQ (jdate MOD 7))
RETURN, daysOfWeek[index]
END
************************************************************ ************
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
Re: days of the week [message #29884 is a reply to message #29849] |
Mon, 25 March 2002 09:07  |
Martin Downing
Messages: 136 Registered: September 1998
|
Senior Member |
|
|
OK, how about an amalgam of David's and Craigs methods:
FUNCTION WhatDayIsIt, jul_day = jdate, year=year, month=month, day=day,
NUMBER=NUMBER
;+
; Return the day of the week given either the JULDATE
; or
; the date as DAY , MONTH, YEAR
; NUMBER: return the number of days from sunday instead of the string day
name
;-
; convert input to julday
IF N_Elements(jdate) EQ 0 THEN begin
if N_Elements(day) EQ 1 THEN begin
jdate = Julday(month, day, year)
endif else begin
jdate = Systime(/Julian)
endelse
endif
; Julday of any old Sunday
jdate_sunday =2452358L ;= Julday(3,24,2002)
; What day of the week is it? (note the use of round)
dow = ( (round(jdate) - jdate_sunday ) mod 7 )
dow = (dow +7 ) mod 7
if keyword_set(NUMBER) EQ 0 then begin
; return a string day-name
daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', $
'Thursday', 'Friday', 'Saturday']
dow = daysOfWeek[dow]
endif
RETURN, dow
END
IDL> print, WhatDayIsIt(jul = systime(/jul))
Monday
IDL> profiler, /report
Module Type Count Only(s) Avg.(s) Time(s) Avg.(s)
WHATDAYISIT (U) 1 0.000065 0.000065 0.000065 0.000065
--
----------------------------------------
Martin Downing,
Clinical Research Physicist,
Grampian Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.
"trouble" <the_cacc@hotmail.com> wrote in message
news:5f9f0a23.0203210321.25c748ff@posting.google.com...
> David Fanning <david@dfanning.com> wrote in message
news:<MPG.17025cedc0db98d798983c@news.frii.com>...
>>
>> P.S. Sorry for the FOR loop. I was in a hurry. :-(
>>
>
> Tsk, according to my timings that FOR loop is costing us 0.0009 seconds.
> Maybe OK for some, but what if ya gots to know the day *now*? Maybe also
> consider using IntArr(7,/NOZERO)? ;)
|
|
|