Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
SPLIT numbers into sub-numbers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
k_ghr...@yahoo.com  
View profile  
 More options Jun 22 2012, 3:52 pm
Newsgroups: comp.lang.idl-pvwave
From: k_ghr...@yahoo.com
Date: Fri, 22 Jun 2012 12:52:48 -0700 (PDT)
Local: Fri, Jun 22 2012 3:52 pm
Subject: SPLIT numbers into sub-numbers
Dear all
I would like to split the following number 20100115 into year, month
and day
any suggestions
Thanks

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Galloy  
View profile  
 More options Jun 22 2012, 5:02 pm
Newsgroups: comp.lang.idl-pvwave
From: Michael Galloy <mgal...@gmail.com>
Date: Fri, 22 Jun 2012 15:02:02 -0600
Local: Fri, Jun 22 2012 5:02 pm
Subject: Re: SPLIT numbers into sub-numbers
On 6/22/12 1:52 PM, k_ghr...@yahoo.com wrote:

> Dear all
> I would like to split the following number 20100115 into year, month
> and day
> any suggestions
> Thanks

Something like this:

IDL> ts = '20100115'
IDL> year = long(strmid(ts, 0, 4))
IDL> month = long(strmid(ts, 4, 2))
IDL> day = long(strmid(ts, 6, 2))
IDL> help, year, month, day
YEAR            LONG      =         2010
MONTH           LONG      =            1
DAY             LONG      =           15

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth P. Bowman  
View profile  
 More options Jun 22 2012, 9:45 pm
Newsgroups: comp.lang.idl-pvwave
From: "Kenneth P. Bowman" <k-bow...@null.edu>
Date: Fri, 22 Jun 2012 20:45:01 -0500
Local: Fri, Jun 22 2012 9:45 pm
Subject: Re: SPLIT numbers into sub-numbers
In article <js2mga$jh...@dont-email.me>, Michael Galloy <mgal...@gmail.com>
wrote:

Or

year  = 0
month = 0
day   = 0
READS, ts, year, month, day, FORMAT = "(I4,2I2)"

Cheers, Ken


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
k_ghr...@yahoo.com  
View profile  
 More options Jun 23 2012, 2:59 pm
Newsgroups: comp.lang.idl-pvwave
From: k_ghr...@yahoo.com
Date: Sat, 23 Jun 2012 11:59:30 -0700 (PDT)
Local: Sat, Jun 23 2012 2:59 pm
Subject: Re: SPLIT numbers into sub-numbers
On Jun 23, 3:45 am, "Kenneth P. Bowman" <k-bow...@null.edu> wrote:

Thanks for your help
first you convert a long number to a string by put it between '  '

but if i have a long array like this
20100101    20100101    20100101    20100101    20100102
20100102    20100102    20100102    20100103    20100103
20100103    20100103    20100104

and I cann't put each sub group between ' '
how I can split this directly?
Best wishes
Khaled


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
k_ghr...@yahoo.com  
View profile  
 More options Jun 23 2012, 2:59 pm
Newsgroups: comp.lang.idl-pvwave
From: k_ghr...@yahoo.com
Date: Sat, 23 Jun 2012 11:59:55 -0700 (PDT)
Local: Sat, Jun 23 2012 2:59 pm
Subject: Re: SPLIT numbers into sub-numbers
On Jun 22, 11:02 pm, Michael Galloy <mgal...@gmail.com> wrote:

Thanks for your help
first you convert a long number to a string by put it between '  '

but if i have a long array like this
20100101    20100101    20100101    20100101    20100102
20100102    20100102    20100102    20100103    20100103
20100103    20100103    20100104

and I cann't put each sub group between ' '
how I can split this directly?
Best wishes
Khaled


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carsten Lechte  
View profile  
 More options Jun 23 2012, 5:13 pm
Newsgroups: comp.lang.idl-pvwave
From: Carsten Lechte <c...@toppoint.de>
Date: Sat, 23 Jun 2012 23:13:56 +0200
Local: Sat, Jun 23 2012 5:13 pm
Subject: Re: SPLIT numbers into sub-numbers
On 23/06/12 03:45, Kenneth P. Bowman wrote:

> year  = 0
> month = 0
> day   = 0
> READS, ts, year, month, day, FORMAT = "(I4,2I2)"

Nice, I had not thought of that.

My first idea was:

num = 20100115L ; very important: force LONG integer type!
y = num/10000
m = (num-y*10000)/100
d = num - y*10000 - m*100
print, num, y, m, d

==>    20100115        2010           1          15

chl


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
k_ghr...@yahoo.com  
View profile  
 More options Jun 23 2012, 6:08 pm
Newsgroups: comp.lang.idl-pvwave
From: k_ghr...@yahoo.com
Date: Sat, 23 Jun 2012 15:08:02 -0700 (PDT)
Local: Sat, Jun 23 2012 6:08 pm
Subject: Re: SPLIT numbers into sub-numbers
On Jun 23, 11:13 pm, Carsten Lechte <c...@toppoint.de> wrote:

for the following array
20100101    20100101    20100101    20100101    20100102
20100102    20100102    20100102    20100103    20100103
20100103    20100103    20100104

 I wrote

y=lonarr( n_elements(num))
m =lonarr( n_elements(num))
d =lonarr( n_elements(num))
for i = 0, n_elements(num)-1 do begin
num(i)=num(i)+0L

y(i) = num(i)/10000
m(i) = (num(i)-y(i)*10000)/100
d(i) = num(i) - y(i)*10000 - m(i)*100
print, num(i), y(i), m(i), d(i)
endfor

and now ran correctly with the following output
    20100101        2010           1           1
    20100101        2010           1           1
    20100101        2010           1           1
    20100101        2010           1           1
    20100102        2010           1           2
    20100102        2010           1           2
    20100102        2010           1           2
    20100102        2010           1           2
    20100103        2010           1           3
    20100103        2010           1           3
    20100103        2010           1           3
    20100103        2010           1           3
    20100104        2010           1           4
thank you for your helping


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
alx  
View profile  
 More options Jun 24 2012, 4:36 am
Newsgroups: comp.lang.idl-pvwave
From: alx <lecacheux.al...@wanadoo.fr>
Date: Sun, 24 Jun 2012 01:36:14 -0700 (PDT)
Local: Sun, Jun 24 2012 4:36 am
Subject: Re: SPLIT numbers into sub-numbers
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »