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

Home » Public Forums » archive » Re: Simple question on Arrays
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: Simple question on Arrays [message #29140] Mon, 04 February 2002 02:37
Bhautik Jitendra Josh is currently offline  Bhautik Jitendra Josh
Messages: 3
Registered: November 2001
Junior Member
Hi,

Your code should be something like:

FUNCTION multfile

;get list of filenames
result = Dialog_Pickfile(/Multiple_Files)

;get number of slices
n_slices = n_elements(result)

;create an empty image of size 512x512xn_slices
img = BYTARR(512,512,n_slices)

;for each slice in the selection
for i = 0, n_slices-1 do begin

;get filename
filename = result[i]

;create empty slice
image = bytarr(512,512)

;open file and fill in slice
OpenR, lun, filename, /Get_lun
ReadU, lun, image
Free_lun, lun

;store slice in volume
img[*,*,i]=image
endfor

;return image
return, img

END

You would use this function like:

volume=multifile()

where volume is the final volume of slices you'd like to access.

If you'd like to read DICOM data, then you should replace the three file
I/O lines (OPENR, READU, FREE_LUN etc.) with the appropriate lines for
reading DICOM data.

Hope this helps.

Cheers,
Bhautik

ps. if you are feeling like a bit of a n00b* with IDL, I do suggest you
spend some quality time with the IDL online help, and, when you really
want to get into it, <plug> read David Fannings ' IDL Programming
Techniques, 2nd Edition,' (www.dfanning.com) </plug> :)

*go see: http://www.bosskey.net/quake/glossary.html

> hi Dr.Joshi,
>
> here is the code that i wrote to change 2D array into
> a 3D form. I can now see there are as many images as i
> pick. but i want to get them in a variable which will
> be in an array form, that i can index the array for
> the particular slice like a[*,*,10]
>
> i don't know how to save the image in an array form.
>
> Please tell me how to achieve that...
>
> Thanking you,
> Sincerely,
> Akhila.
>
> PRO multfile
>
> result = Dialog_Pickfile(/Multiple_Files)
> help, result
> a = size(result)
> b = a[3]
>
> for i = 0, b-1 do begin
> filename = result[i]
> image = bytarr(512,512)
> OpenR, lun, filename, /Get_lun
> ReadU, lun, image
> Free_lun, lun
> help, image
>
> endfor
>
> END




________________________________________________________
/ \
|bjoshi@geocities.com | phone: 0404032617 |
|ICQ #: 2464537 | http://cow.mooh.org |
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(__)~~~~~~~/
(__) |..|--\
/--|^^| moo | |--|
|--| | \OO/||^
^||\oo/ moo
Re: Simple question on Arrays [message #29141 is a reply to message #29140] Mon, 04 February 2002 00:44 Go to previous message
Vincent Schut is currently offline  Vincent Schut
Messages: 8
Registered: February 2002
Junior Member
Akhila wrote:
> HI,
> I have written a small code to get a 3D array from a 2D array. The
> error i encounter is :
>
> DL> multfile
> RESULT STRING = Array[3]
> I INT = 0
> % Out of range subscript encountered: A.
> % Execution halted at: MULTFILE 16
> D:\RSI\IDL55\Akhila\JanWeek3\multfile.pro
> % $MAIN$
>
>
>
> Can anybody please tell me, why the subscripts are out of range. i'm
> not able to understand that.
>

[snipped your program code...]

Akhila,

use N_ELEMENTS instead of SIZE.
Size returns not the number of elements in an array, but a couple of
other properties, like the number of dimensions (which is *not* the
number of elements; a (3,2) array has 6 elements, but 2 dimensions. Your
array has only 1 dimension, as it is a 1-dimensional array; and some
info about the data type of the argument of size. For more info, see
your idl-help or manual.
Using N_ELEMENTS should give you the right result: 3, as your array (as
you pick 3 files) has 3 elements.

Hope it helps.

Cheers,
Vincent Schut.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Simple question on Arrays
Next Topic: representive digits

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

Current Time: Wed Oct 08 15:57:29 PDT 2025

Total time taken to generate the page: 0.00574 seconds