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

Home » Public Forums » archive » Re: Can you do 'unions' with pv-wave?
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: Can you do 'unions' with pv-wave? [message #3176] Tue, 22 November 1994 07:22
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
jgavin@mksol.dseg.ti.com (Jeffrey S. Gavin) writes:

> Is there a way to have a single variable viewed as multiple types, similar
> to the way unions work in C. For example:

(rest deleted for brevity)

You can always do type conversions on the fly. For example, if you read in a
100 bytes from a file (e.g. into B), and want to treat bytes 20-29 as ten short
integers, you can say

PRINT, FIX(B,20,10)

Where 20 is the starting point in the B array, and 10 is the number of values
to extract.

The same is true for the functions BYTE, LONG, FLOAT, DOUBLE, and COMPLEX. If
you want to extract strings, then you simply say something like

PRINT, STRING(B(30:35))

Bill Thompson
Re: Can you do 'unions' with pv-wave? [message #3177 is a reply to message #3176] Mon, 21 November 1994 17:47 Go to previous message
sterner is currently offline  sterner
Messages: 106
Registered: February 1991
Senior Member
jgavin@mksol.dseg.ti.com (Jeffrey S. Gavin) writes:

> Is there a way to have a single variable viewed as multiple types, similar
> to the way unions work in C. For example:
. . .
> In other words, the characters '\0','A' were interpreted as a single integer.
> I'm trying to reference a single variable (i.e. 'm') as different types, without
> having to make a copy.

You can come close. Check out Type Conversion in the User's Guide.
A subsection called Extracting Fields describes how to do what you
want (or as close as possible in IDL).

Ray Sterner sterner@tesla.jhuapl.edu
The Johns Hopkins University North latitude 39.16 degrees.
Applied Physics Laboratory West longitude 76.90 degrees.
Laurel, MD 20723-6099
WWW Home page: ftp://fermi.jhuapl.edu/www/s1r/people/res/res.html
Re: Can you do 'unions' with pv-wave? [message #3179 is a reply to message #3177] Mon, 21 November 1994 17:08 Go to previous message
hahn is currently offline  hahn
Messages: 108
Registered: November 1993
Senior Member
In article <1994Nov19.012318.9400@mksol.dseg.ti.com> jgavin@mksol.dseg.ti.com (Jeffrey S. Gavin) writes:
> From: jgavin@mksol.dseg.ti.com (Jeffrey S. Gavin)
> Subject: Can you do 'unions' with pv-wave?
> Date: Sat, 19 Nov 1994 01:23:18 GMT

> Is there a way to have a single variable viewed as multiple types, similar
> to the way unions work in C. For example:

[example deleted]

> Our brute-force approach is to read the 50MB file in once as an array of bytes, then again as an array of int, float, then double. This takes time and space
> when actually, we simply want to view the same exact data in different ways.
> Again, the 'C' union structure is the best way I can describe the problem.

> Thanks for any help.

> Regards,

> Jeff


> --
> Jeff Gavin Jeff.Gavin@dseg.ti.com
> Texas Instruments MSG: JGAV / (214) 462-5496

The predefined approach to this problem is to read the data in pieces into a
string array or string and use reads to retrieve data from the string using a
fortran style format. Example (not tested) which assumes your data file on disk
is open:

temp_s = String ('*', format='(A200)') ; declare a 200 byte string
c2 = '**' ; declare a 2 byte character item
i2 = 0 ; declare a short integer variable

readu, iunit, temp_s ; read 200 bytes from disk

reads, temp_s, c2 ; read into a string variable

reads, temp_s, i2 ; read the same data into a short integer variable


... hope this helps
Norbert
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ** REQUEST ** for a list of well known bugs on SGI with prop' products
Next Topic: Re: Eigensystems in IDL

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

Current Time: Sat Oct 11 10:37:37 PDT 2025

Total time taken to generate the page: 0.56231 seconds