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

Home » Public Forums » archive » Re: loop limit ???
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: loop limit ??? [message #53579] Wed, 18 April 2007 15:28
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <1176929681.182929.291930@q75g2000hsh.googlegroups.com>, kostis <kostiskaz@gmail.com> writes:
> i wouldnt expect that IDL has a limit for loops !!
> trying a loop of 50.000 steps i got the message:
>
> % Compiled module: TRAJECTORY.
> % Loop limit expression too large for loop variable type.
> <LONG ( 49999)>.
> % Execution halted at: TRAJECTORY 16 /home/kostis/PROJECT
> LARMOR/dipole/trajectory.pro
> % $MAIN$
>
> Why is this?
> This means i cant have bigger loops... or is there a trick??
>
You can have much larger loops, just be careful about the indexing.
In the expression

for i = a, b do ....

the type of the loop variable is determined by the type of a
(regardless of what b is). So, if you write

for i = 0, 50000

or even

for i = 0, 50000l

the loop variable will be a standard (aka "short") integer and these
are limited to 2^15 - 1, i.e. 32767. But if you'll write

for i = 0l, 50000

the loop variable is of type LONG and the limit is at 2^31 - 1, more
then 2 billion. If that's not enough you can use LONG64, at which
point it'll probably be the longevity of the computer that'll
determine the limit

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: loop limit ??? [message #53580 is a reply to message #53579] Wed, 18 April 2007 15:06 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Apr 18, 3:45 pm, Gianguido Cianci <gianguido.cia...@gmail.com>
wrote:
> Or you could get into the habit of typing
>
> Compile_Opt IDL2
>
> at the beginning of our programs and never worry about it again.
> ('downside' is you are forced to use [] for arrays and () only for
> functions)
>
> Gianguido

I don't consider it a downside, but if you only want the default
integer to be 32 bit then use

compile_opt defint32

instead of idl2 (which is just a convenience for both defint32 and
strictarr).

Mike
--
www.michaelgalloy.com
Re: loop limit ??? [message #53582 is a reply to message #53580] Wed, 18 April 2007 14:45 Go to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
On Apr 18, 4:54 pm, kostis <kostis...@gmail.com> wrote:
> i wouldnt expect that IDL has a limit for loops !!
> trying a loop of 50.000 steps i got the message:
>
> % Compiled module: TRAJECTORY.
> % Loop limit expression too large for loop variable type.
> <LONG ( 49999)>.
> % Execution halted at: TRAJECTORY 16 /home/kostis/PROJECT
> LARMOR/dipole/trajectory.pro
> % $MAIN$
>
> Why is this?
> This means i cant have bigger loops... or is there a trick??
>
> Thanx...

Or you could get into the habit of typing

Compile_Opt IDL2

at the beginning of our programs and never worry about it again.
('downside' is you are forced to use [] for arrays and () only for
functions)

Gianguido
Re: loop limit ??? [message #53583 is a reply to message #53582] Wed, 18 April 2007 14:02 Go to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Wed, 18 Apr 2007, kostis wrote:

> i wouldnt expect that IDL has a limit for loops !!
> trying a loop of 50.000 steps i got the message:
>
> % Compiled module: TRAJECTORY.
> % Loop limit expression too large for loop variable type.
> <LONG ( 49999)>.
> % Execution halted at: TRAJECTORY 16 /home/kostis/PROJECT
> LARMOR/dipole/trajectory.pro
> % $MAIN$
>
> Why is this?
> This means i cant have bigger loops... or is there a trick??
>

IDL> for i=0,49999 do begin & endfor
% Loop limit expression too large for loop variable type.
<LONG ( 49999)>.
% Execution halted at: $MAIN$


0 is of type INT (default integer), whose max. value is 32767.
Use 0l (LONG) instead.

regards,
lajos
Re: loop limit ??? [message #53584 is a reply to message #53583] Wed, 18 April 2007 14:12 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Apr 18, 2:54 pm, kostis <kostis...@gmail.com> wrote:
> i wouldnt expect that IDL has a limit for loops !!
> trying a loop of 50.000 steps i got the message:
>
> % Compiled module: TRAJECTORY.
> % Loop limit expression too large for loop variable type.
> <LONG ( 49999)>.
> % Execution halted at: TRAJECTORY 16 /home/kostis/PROJECT
> LARMOR/dipole/trajectory.pro
> % $MAIN$
>
> Why is this?
> This means i cant have bigger loops... or is there a trick??

There's a "trick". A FOR loop variable gets it type from the "start"
value of the loop and it doesn't change in the course of the loop.

So, (note the 0L -- it's the "trick"):

for i = 0L, 50000L do begin
; stuff here
endfor

should do it for you.

Mike
--
www.michaelgalloy.com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Help with the F-test. mpftest.pro in particular.
Next Topic: Re: Annoying ROIs

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

Current Time: Fri Oct 10 10:56:29 PDT 2025

Total time taken to generate the page: 0.96056 seconds