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

Home » Public Forums » archive » Re: printing an array from pointers
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: printing an array from pointers [message #48093] Tue, 28 March 2006 21:08 Go to next message
bressert@gmail.com is currently offline  bressert@gmail.com
Messages: 8
Registered: February 2006
Junior Member
Hi Peter,

Thanks for the tip on fltarr, worked like a gem. This is my first
project in IDL and I have a lot to cover still. When I initially made
the current program I was used to loops and realized towards the end
that using arrays is much more efficient. For the next script, I will
try that out.

Cheers,

Eli
Re: printing an array from pointers [message #48121 is a reply to message #48093] Tue, 28 March 2006 05:30 Go to previous messageGo to next message
peter.albert@gmx.de is currently offline  peter.albert@gmx.de
Messages: 108
Registered: July 2005
Senior Member
Hi Eli,

if your goal really is to just create the 10x8 array via the loop and
then print the complete array, I wouldn't use pointers. A simple

arr = fltarr(10,8)
for i = 0,9 do begin
...
arr[i,*] = (some 1 by 8 vector)
endfor

print, arr

will do the trick.

If you _really_ want to use the pointer array, you have to manually
concatenate the individual vectors like

print, transpose([[*ptr[0]], [*ptr[1]], ..., [*ptr[9]]])

which is far from being elegant and most likely will waste some memory.
Not really a problem with 10x8 entries, but there is probably more to
come?

While you think over it, why not completely re-thinking the problem and
trying to avoid the for-loop at all :-) ?

Cheers,

Peter
Re: printing an array from pointers [message #48124 is a reply to message #48121] Tue, 28 March 2006 00:22 Go to previous messageGo to next message
bing hu is currently offline  bing hu
Messages: 3
Registered: October 2005
Junior Member
openw,lun,'t3.txt',/get_lun
for i=0,9 do begin
etc...
arr=(some 1 by 8 vector)
printf,lun,arr(i)
endfor
free_lun,lun
end

----------------------------------------------
this code may help u.
Re: printing an array from pointers [message #48190 is a reply to message #48121] Tue, 28 March 2006 23:55 Go to previous message
bressert@gmail.com is currently offline  bressert@gmail.com
Messages: 8
Registered: February 2006
Junior Member
Hi Peter,

Another question, since I have ran into a new bump. Is there a way to
say

arr = fltarr(A,8)

where A is a number that fluctuates? So rather than stating that arr is
A rows long, it is a number determined by the total output of the for
loop? For example,

arr = fltarr(150,8)

will be sufficient in gathering all the 'for' outputs, but I will have
trailing zeros that have not been assigned an output value. Using UNIQ
or an 'if' to get rid of the zeros in the array does not work, since
some of the output from the 'for' loop is zero. This was the original
reason why I used the pointers, since there was no requirement of
predetermination of the number of rows. Any suggestions or ideas would
be greatly appreciated. Thanks again for the help.

Cheers,

Eli
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: What is the algorithms of sort function and where function?
Next Topic: Re: zoom screen id on envi_display_bands

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

Current Time: Wed Oct 08 13:36:38 PDT 2025

Total time taken to generate the page: 0.00737 seconds