comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: SPLIT numbers into sub-numbers
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: SPLIT numbers into sub-numbers [message #80577] Sun, 24 June 2012 01:36 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 22 juin, 21:52, k_ghr...@yahoo.com wrote:
> Dear all
> I would like to split the following number 20100115 into year, month
> and day
> any suggestions
> Thanks

The "IDL way" for extracting dates from such a coded integer array
might be:

IDL> dates = transpose([[x/10000],[(x mod 10000)/100],[x mod 100]])
in which dates will be an array of dimensions 3 x N_elements(x).

for instance:
IDL> x = [20100401, 20110501, 20120601]
IDL> print, transpose([[x/10000],[(x mod 10000)/100],[x mod 100]])
2010 4 1
2011 5 1
2012 6 1

A maybe more "readable", but slower way would be:

IDL> dates = intarr(3,N_elements(x)) ;you must define your output
first
IDL> reads, string(x, FORMAT='(i8)'), dates, FORMAT='(i4,i2,i2)'

or, if you like Julian days:

IDL> jd = dblarr(3,N_elements(x)) ;you must define your output
first
IDL> reads, string(x, FORMAT='(i8)'), jd,
FORMAT='(C(CYI4,CMOI2,CDI2))'
IDL> print,jd
2455288.0 2455683.0 2456080.0

alx.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: astronomy library
Next Topic: Re: Coyote graphics resizeable window

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:34:10 PDT 2025

Total time taken to generate the page: 0.00533 seconds