Re: Array of associated variables? [message #42273 is a reply to message #42269] |
Fri, 21 January 2005 00:58   |
sso
Messages: 13 Registered: February 2002
|
Junior Member |
|
|
Thanks! This works, but my code still doesn't. The difference which
makes my program crash is the definition of the a=assoc(...) which in
my code is a structure. It's like this:
openu, inun, filename, /swap_if_little_endian, /get_lun
a = assoc(inun, strucval, headpos)
where strucval is a structure (consisting of various types of
float/long data) and headpos is the offset. There's another difference
also, and that's the open statement above, but I guess that shouldnt
cause the program to crash.
So it seems as the use of pointer arrays for associated variables
doesnt work when the associated variable is a structure? Hmm. I must
admit I get somewhat confused with this. Perhaps it's what one would
call a bug? At least it doesnt only halt. The whole idl session
crashes, returns to the Unix environment and give me the Unix message
"Segmentation fault" which normally indicates a rather serious error.
Guess I will have to leave the array of associated vars. then and try
to circumvent this in some way(?)
Sverre
David Fanning wrote:
> sso@nilu.no writes:
>
>> However, I dont get this really to work. It's probably a basic
error I
>> am doing, but a code like this will crash.
>>
>> all = ptrarr(n, /allocate_heap)
>>
>> FOR i = 0, n-1 DO BEGIN
>> ;..define a, the associated variable (that works)
>> p = ptr_new(a)
>> all(i) = p
>> ENDFOR
>>
>> ;..extract values back:
>> a = all(0)
>> pval = *a
>>
>> ----------
>> I'm not that into pointers so it may be a simple error
>
> Don't know. Looks right to me. Here is my example:
>
> n=3
> filename = 'junk'
> all = ptrarr(n)
>
> FOR I = 0, n-1 DO BEGIN
> Openw, lun, filename + String(I, format='(i1)') +'.pro', /Get_Lun
> a = Assoc(lun, Bytarr(200))
> p = ptr_new(a)
> all[I] = p
> ENDFOR
>
> ;..extract values back:
> a = all[0]
> pval = *a
> help, pval
> END
>
> And here is what I get:
>
> IDL> .COMPILE "C:\RSI\David\assoc_ptr.pro"
> % Compiled module: $MAIN$.
> IDL> .go
> PVAL BYTE = File<C:\RSI\David\junk0.pro> Array[200]
>
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|