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

Home » Public Forums » archive » forcing variable definition in IDL?
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
forcing variable definition in IDL? [message #24876] Mon, 30 April 2001 23:19 Go to next message
Gernot Hassenpflug is currently offline  Gernot Hassenpflug
Messages: 18
Registered: April 2001
Junior Member
I have seen some threads on Google about the lack of 'implicit none'
Fortran type statement in IDL. However, those threads are, a) short,
b) date from 1995. I have not seen anything later than this.

So, my question: is it possible in IDL 5.4 to force definition of
variables, or at least to automate a variable-check in IDL.

Alternatively, maybe I need to write a function that automatically
checks the first use of a variable in a program. I have used the
routine_info and routine_names functions to obtain information
about variables in scope at the time.

Does anyone know of either how to get IDL to check variables'
definition,
or how to write a function to do that?

I have also toyed with the idea of using each variable as a single-
element array (eg. b(0) = 1), but that is most inelegant and lengthy.

Best regards,
Gernot Hassenpflug
PS email address in header includes SPAM TRAP. please note.
--
Gernot Hassenpflug, MSc. (Eng.)
+81 (0)75 213-1321 (H) Tel/Fax
+81 (0)774 38-3868 (W) Tel
gernot@kurasc.kyoto-u.ac.jp
Radio Atmospheric Science Centre, Kyoto University
京都
Re: forcing variable definition in IDL? [message #24965 is a reply to message #24876] Tue, 01 May 2001 13:40 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
William Daffer (whdaffer@mediaone.net) writes:

> Um... so you're agreeing with me when I say that David's remark is
> untrue?

I think Liam was trying to say that my remark was only
half true, in a smart-alacky sort of way. And that your
comment pointed that out. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: forcing variable definition in IDL? [message #24966 is a reply to message #24876] Tue, 01 May 2001 13:26 Go to previous message
William Daffer is currently offline  William Daffer
Messages: 34
Registered: February 1999
Member
"Liam E. Gumley" <Liam.Gumley@ssec.wisc.edu> writes:

> William Daffer wrote:
>>
>> davidf@dfanning.com (David Fanning) writes:
>> [...]
>>
>>> Don't bother. IDL scalars *are* single element arrays:
>>>
>>> IDL> a=5
>>> IDL> a[0] = 6 & Print, a
>>>
>>
>> Um... Not true.
>>
>> IDL> a=['foo|bar']
>> IDL> print,strsplit(a,'|',/extract)
>> % STRTOK: Expression must be a scalar in this context: STRING.
>> % Execution halted at: STRSPLIT 24
>> /usr/local/rsi/idl_5.3/lib/strsplit.pro
>> % $MAIN$
>> IDL> retall
>> IDL> print,strsplit(a[0],'|',/extract)
>> foo bar
>> IDL>
>>
>> There are some other RSI supplied code where one sees this behavior.
>>
>> By the way, this is idl 5.3. I haven't checked idl 5.4.
>
> An array with one element is an *array*, i.e., it has one dimension:
>
> IDL> a = [25]
> IDL> help, a
> A INT = Array[1]
> IDL> print, size(a, /n_dimensions)
> 1
>
> A single subscripted array element is a *scalar expression*, i.e., it
> has no dimensions:
>
> IDL> a = [1, 2, 3, 4, 5]
> IDL> help, a[0]
> <Expression> INT = 1
> IDL> print, size(a[0], /n_dimensions)
> 0
>
> A scalar may be treated as though it were a single subscripted array
> element. However, as shown above, a scalar expression has no dimensions:
>
> IDL> a = 100
> IDL> help, a
> A INT = 100
> IDL> help, a[0]
> <Expression> INT = 100
> IDL> print, size(a, /n_dimensions)
> 0
> IDL> print, size(a[0], /n_dimensions)
> 0
>
> The implementer of STRTOK (which is called by STRSPLIT) is therefore
> checking for an input argument which has no dimensions.
>
> Cheers,
> Liam.
> http://cimss.ssec.wisc.edu/~gumley/


Um... so you're agreeing with me when I say that David's remark is
untrue?

whd
--
Outside of a dog a book is man's best friend.
Inside of a dog it's too dark to read
Groucho Marx
Re: forcing variable definition in IDL? [message #24971 is a reply to message #24876] Tue, 01 May 2001 11:19 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
William Daffer wrote:
>
> davidf@dfanning.com (David Fanning) writes:
> [...]
>
>> Don't bother. IDL scalars *are* single element arrays:
>>
>> IDL> a=5
>> IDL> a[0] = 6 & Print, a
>>
>
> Um... Not true.
>
> IDL> a=['foo|bar']
> IDL> print,strsplit(a,'|',/extract)
> % STRTOK: Expression must be a scalar in this context: STRING.
> % Execution halted at: STRSPLIT 24
> /usr/local/rsi/idl_5.3/lib/strsplit.pro
> % $MAIN$
> IDL> retall
> IDL> print,strsplit(a[0],'|',/extract)
> foo bar
> IDL>
>
> There are some other RSI supplied code where one sees this behavior.
>
> By the way, this is idl 5.3. I haven't checked idl 5.4.

An array with one element is an *array*, i.e., it has one dimension:

IDL> a = [25]
IDL> help, a
A INT = Array[1]
IDL> print, size(a, /n_dimensions)
1

A single subscripted array element is a *scalar expression*, i.e., it
has no dimensions:

IDL> a = [1, 2, 3, 4, 5]
IDL> help, a[0]
<Expression> INT = 1
IDL> print, size(a[0], /n_dimensions)
0

A scalar may be treated as though it were a single subscripted array
element. However, as shown above, a scalar expression has no dimensions:

IDL> a = 100
IDL> help, a
A INT = 100
IDL> help, a[0]
<Expression> INT = 100
IDL> print, size(a, /n_dimensions)
0
IDL> print, size(a[0], /n_dimensions)
0

The implementer of STRTOK (which is called by STRSPLIT) is therefore
checking for an input argument which has no dimensions.

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley/
Re: forcing variable definition in IDL? [message #24973 is a reply to message #24876] Tue, 01 May 2001 10:18 Go to previous message
William Daffer is currently offline  William Daffer
Messages: 34
Registered: February 1999
Member
davidf@dfanning.com (David Fanning) writes:
[...]

> Don't bother. IDL scalars *are* single element arrays:
>
> IDL> a=5
> IDL> a[0] = 6 & Print, a
>

Um... Not true.

IDL> a=['foo|bar']
IDL> print,strsplit(a,'|',/extract)
% STRTOK: Expression must be a scalar in this context: STRING.
% Execution halted at: STRSPLIT 24
/usr/local/rsi/idl_5.3/lib/strsplit.pro
% $MAIN$
IDL> retall
IDL> print,strsplit(a[0],'|',/extract)
foo bar
IDL>

There are some other RSI supplied code where one sees this behavior.

By the way, this is idl 5.3. I haven't checked idl 5.4.

whd
--
Outside of a dog a book is man's best friend.
Inside of a dog it's too dark to read
Groucho Marx
Re: forcing variable definition in IDL? [message #24974 is a reply to message #24876] Tue, 01 May 2001 05:32 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Gernot Hassenpflug (gernot-nospam@kurasc.kyoto-u.ac.jp) writes:

> So, my question: is it possible in IDL 5.4 to force definition of
> variables, or at least to automate a variable-check in IDL.

It is certainly possible to "force" a variable to
have a certain definition. That's not the problem.
The problem is making it *stay* a certain definition.
That, in general, is not possible in IDL, since IDL
has dynamic typing capability.
>
> Alternatively, maybe I need to write a function that automatically
> checks the first use of a variable in a program. I have used the
> routine_info and routine_names functions to obtain information
> about variables in scope at the time.

You can check. But like recalcitrant children, they
will be doing something else the minute you turn
your back. :-)

> Does anyone know of either how to get IDL to check variables'
> definition,
> or how to write a function to do that?

IDL> theType = Size(variable, /Type)

Or, if you prefer the type "name":

IDL> theTypeName = Size(variable, /TName)

> I have also toyed with the idea of using each variable as a single-
> element array (eg. b(0) = 1), but that is most inelegant and lengthy.

Don't bother. IDL scalars *are* single element arrays:

IDL> a=5
IDL> a[0] = 6 & Print, a

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Dereferencing a Pointer Array
Next Topic: Array Concatenation Tutorial

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

Current Time: Wed Oct 08 11:27:32 PDT 2025

Total time taken to generate the page: 0.00654 seconds