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

Home » Public Forums » archive » System Variables: defining and using
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
System Variables: defining and using [message #11594] Tue, 28 April 1998 00:00 Go to next message
Ray Muzic is currently offline  Ray Muzic
Messages: 5
Registered: June 1997
Junior Member
I wrote a function is_little_endian to determine if a system uses little
endian data representation. (see below) It doesn't compile in IDL4 or
IDL5. An error is generated on the return statement with the message
that system variable !little_endian does not exist. Apparently IDL
requires the system variable to be defined at compile time.

The idea was to, on the first call to this function, determine the
endian of the system and store info in a system variable. On subsequent
calls the function should note that the
system variable exists and use the stored result.

Is there a way to do this using system variables? I'd prefer to not use
common blocks.

I relalize the endian determination is a cheap calculation so there is
question as to whether or not saving the result in a system variable is
really worthwhile. Nevertheless, I'm interested in the solution in
regards to saving results in system variables in other applications.

function is_little_endian
; is_little_endian() returns
; 1b (true) if system uses little endian data representation
; 0b (false) otherwise.
;
; Side effects: Creates and sets the value of a sustem variable
!little_endian
; if it does not already exist.
;
;
defsysv,'!little_endian', exists=i
if i ne 1 then defsysv,'!little_endian', (byte(1, 0, 1))(0)
; grab first byte of a 2 byte integer representation of 1 (1st arg. to
byte)

return,!little_endian


Ray Muzic
muzic@uhrad.com
Re: System Variables: defining and using [message #11720 is a reply to message #11594] Sun, 03 May 1998 00:00 Go to previous message
mallors is currently offline  mallors
Messages: 76
Registered: November 1997
Member
In article <6ihdnf$rc8$1@ratatosk.uio.no>,
steinhh@ulrik.uio.no (Stein Vidar Hagfors Haugan) writes:
>
>> Apparently IDL
>> requires the system variable to be defined at compile time.
>
> Yes, that's right. Which means they should preferably be defined
> in the IDL_STARTUP file. There is one way of getting around this,
> though. In your case, write
>
> dummy = execute("endian = !little_endian")
> return,endian
>
> instead of simply return,!little_endian. This will allow your
> routine to compile, and define the system variable before it's
> used.
>

From the file 51new.txt that was distributed with 5.1b3:

"Note also that system variables can now be defined
after code that references them is compiled (or even
in the same routine) and IDL will correctly resolve the
reference as long as the variable exists at the time the
referencing code executes."

I tried the is_little_endian() function, and it works fine
with 5.1b3. I think 5.1 is due to be released any day now.


Regards,

-bob mallozzi


--
Robert S. Mallozzi
http://cspar.uah.edu/~mallozzir/
Re: System Variables: defining and using [message #11723 is a reply to message #11594] Sun, 03 May 1998 00:00 Go to previous message
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
> Apparently IDL
> requires the system variable to be defined at compile time.

Yes, that's right. Which means they should preferably be defined
in the IDL_STARTUP file. There is one way of getting around this,
though. In your case, write

dummy = execute("endian = !little_endian")
return,endian

instead of simply return,!little_endian. This will allow your
routine to compile, and define the system variable before it's
used.

Regards,

Stein Vidar
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 32bit signed integer problems
Next Topic: Reinventing the IDL wheel: 2D Object Graphics plots

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

Current Time: Wed Oct 08 15:53:09 PDT 2025

Total time taken to generate the page: 0.00405 seconds