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

Home » Public Forums » archive » Re: Could you explain why this happen?
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: Could you explain why this happen? [message #70686] Thu, 29 April 2010 03:57
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
David Fanning wrote:
> An IDL start-up file is simply a text file containing
> IDL commands of the sort you would type at the IDL
> command line. You point to it via an environment
> variable named IDL_STARTUP.

Note however, that COMPILE_OPT only affects the local scope, i.e. you have
to put it into every procedure and function definition, not just into the
startup file, or you will be wondering if the sky is falling. Example:

IDL Version 6.4 (linux x86 m32). (c) 2007, ITT Visual Information Solutions
IDL> print, 32000*6
-4608
IDL> compile_opt defint32
IDL> print, 32000*6
192000
IDL> .comp
- pro test
- print, 32000*6
- end
% Compiled module: TEST.
IDL> test
-4608
IDL> print, 32000*6
192000
IDL>


chl
Re: Could you explain why this happen? [message #70704 is a reply to message #70686] Wed, 28 April 2010 12:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bryan writes:

> Thank you for your kind response. Then, could you let me know how to
> set the IDL start-up file like you?

An IDL start-up file is simply a text file containing
IDL commands of the sort you would type at the IDL
command line. You point to it via an environment
variable named IDL_STARTUP.

Here is how you might define it in a UNIX environment:

http://www.dfanning.com/misc_tips/idlsetup.html

In a Windows environment, you define it via a Windows
Preference dialog.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Could you explain why this happen? [message #70705 is a reply to message #70704] Wed, 28 April 2010 10:54 Go to previous message
bryan.s.hong is currently offline  bryan.s.hong
Messages: 12
Registered: November 2008
Junior Member
On 4월28일, 오후12시06분, David Fanning <n...@dfanning.com> wrote:
> Bryan writes:
>> This may be a stupid question, but I really want to know why.
>> Please, see below and explain. Thanks.
>
>> IDL> print, 132*30
>> 3960
>> IDL> print, 132*30*10
>> -25936
>> IDL> print, 132*300
>> -25936
>> IDL> data1 = 132
>> IDL> data2 = 300
>> IDL> data3 = data1*data2
>> IDL> print, data3
>> -25936
>
> Here is a clue. These are the same IDL commands in my IDL
> session:
>
> IDL> print, 132*30
> 3960
> IDL> print, 132*30*10
> 39600
> IDL> print, 132*300
> 39600
> IDL> data1 = 132
> IDL> data2 = 300
> IDL> data3 = data1*data2
> IDL> print, data3
> 39600
>
> Probably the only difference between your IDL session and mine
> is that I have this command in my IDL startup file:
>
> compile_opt defint32
>
> Why would that matter?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thank you for your kind response. Then, could you let me know how to
set the IDL start-up file like you?

Thanks.

Bryan
Re: Could you explain why this happen? [message #70706 is a reply to message #70705] Wed, 28 April 2010 10:06 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bryan writes:

> This may be a stupid question, but I really want to know why.
> Please, see below and explain. Thanks.
>
> IDL> print, 132*30
> 3960
> IDL> print, 132*30*10
> -25936
> IDL> print, 132*300
> -25936
> IDL> data1 = 132
> IDL> data2 = 300
> IDL> data3 = data1*data2
> IDL> print, data3
> -25936

Here is a clue. These are the same IDL commands in my IDL
session:

IDL> print, 132*30
3960
IDL> print, 132*30*10
39600
IDL> print, 132*300
39600
IDL> data1 = 132
IDL> data2 = 300
IDL> data3 = data1*data2
IDL> print, data3
39600

Probably the only difference between your IDL session and mine
is that I have this command in my IDL startup file:

compile_opt defint32

Why would that matter?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Could you explain why this happen? [message #70707 is a reply to message #70706] Wed, 28 April 2010 10:04 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 4/28/10 10:46 AM, Bryan wrote:
> This may be a stupid question, but I really want to know why.
> Please, see below and explain. Thanks.
>
> IDL> print, 132*30
> 3960
> IDL> print, 132*30*10
> -25936
> IDL> print, 132*300
> -25936
> IDL> data1 = 132
> IDL> data2 = 300
> IDL> data3 = data1*data2
> IDL> print, data3
> -25936

The default integer in IDL is a 16-bit signed integer (i.e., INT), range
-32768 to 32767. Your calculation involved two of these 16-bit integers,
so IDL calculated a result which was a 16-bit integer, wrapping around
to negative values in the process:

IDL> help, 132
<Expression> INT = 132
IDL> help, 300
<Expression> INT = 300
IDL> help, 132 * 300
<Expression> INT = -25936

The way to fix this to get the "correct" result is to make one or both
of the operands in the operation be of type long, making the result of
type long (range -2^31 to 2^31 - 1):

IDL> help, 132L * 300L
<Expression> LONG = 39600

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
Re: Could you explain why this happen? [message #70708 is a reply to message #70707] Wed, 28 April 2010 10:01 Go to previous message
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
On 28/04/2010 12:46 PM, Bryan wrote:
> This may be a stupid question, but I really want to know why.
> Please, see below and explain. Thanks.
>
> IDL> print, 132*30
> 3960
> IDL> print, 132*30*10
> -25936
> IDL> print, 132*300
> -25936
> IDL> data1 = 132
> IDL> data2 = 300
> IDL> data3 = data1*data2
> IDL> print, data3
> -25936

Hi,

you are working with integers, the maximum value being 32 767. When you
go over this limit, IDL goes back to the minimum value (-32 768). So 32
767 + 1 = -32 768
Use long integers instead, and you will have the value you are expecting!

Jean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: How to read field attributes in HDF-EOS
Next Topic: ms2gt MODIS reprojection toolkit

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

Current Time: Wed Oct 08 13:52:48 PDT 2025

Total time taken to generate the page: 0.00413 seconds