Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Idl-pvware > Re: index array...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 12 Topic 5535 of 6251
Post > Topic >>

Re: index arrays of structures

by Raghu <raghuram.narasimhan@[EMAIL PROTECTED] > Mar 16, 2008 at 12:19 PM

On Mar 16, 5:49=C2=A0am, Vince Hradil <hrad...@[EMAIL PROTECTED]
> wrote:
> Raghu wrote:
> > On Mar 15, 7:31=EF=BF=BDpm, Vince Hradil <hrad...@[EMAIL PROTECTED]
> wrote:
> > > On Mar 15, 4:07 pm, Vince Hradil <hrad...@[EMAIL PROTECTED]
> wrote:
>
> > > > On Mar 15, 3:53 pm, Raghu <raghuram.narasim...@[EMAIL PROTECTED]
> wrote:
>
> > > > > Hi,
>
> > > > > With reference to my recent posting (IDL batch indexing), i
unders=
tood
> > > > > that i could structures. However, i haven't been able to figure
ou=
t
> > > > > one step.
>
> > > > > Here is my code as of now:
> > > > > ; I want to search for all the images(files) in the directory
tria=
ls,
> > > > > read them into the structure named data, and access each file
with=
in
> > > > > the structure.
>
> > > > > pro strcutres
> > > > > dir1=3D'D:\trials'
> > > > > cd,dir1
> > > > > files=3DFILE_SEARCH('*[^\.{hdr}]', /QUOTE,count=3Dnumfiles)
> > > > > i=3D0
> > > > > while i lt numfiles do begin
> > > > > named=3Dfiles(i)
> > > > > print,named
> > > > > data=3D{ID:'a',sizes:fltarr(2179,761)}
> > > > > data=3Dreplicate(data,numfiles)
> > > > > data.sizes=3Dfindgen(numfiles)
> > > > > openr,1,named
> > > > > readu,1,data[i].sizes
> > > > > close,1
> > > > > i=3Di+1
> > > > > endwhile
> > > > > end
>
> > > > > ERROR message- READU: Expression must be named variable in this
> > > > > context: <FLOAT =EF=BF=BD =EF=BF=BD Array[2179, 761]>.
>
> > > > > I am getting the error here because it seems like i am not able
to=

> > > > > read in the LUN 1 or named, into data[i].sizes.
>
> > > > > Where am i going wrong ?
>
> > > > > Raghu
>
> > > > Hoo boy - here you go.
>
> > > > 1-Yes, you need to use a named variable to readu
> > > > 2-You already defined "sizes" (weird name, by the way, how about
> > > > "values"), when you made the structure.
>
> > > > How about this:
>
> > > > pro strcutres
> > > > dir1=3D'D:\trials'
> > > > cd,dir1
> > > > files=3DFILE_SEARCH('*[^\.{hdr}]', /QUOTE,count=3Dnumfiles)
>
> > > > data=3D{ID:'a',values:fltarr(2179,761)}
> > > > data=3Dreplicate(data,numfiles)
> > > > tempval =3D fltarr(2179,761)
>
> > > > for i=3D0L, numfiles-1 do begin
> > > > named=3Dfiles(i)
> > > > print,named
>
> > > > openr,1,named
> > > > readu,1,tempval
> > > > free_lun,1
> > > > data[i].values =3D tempval
>
> > > > endfor
>
> > > > return
> > > > end
>
> > > BTW - why do you want to use a structure again? =EF=BF=BDThe above
cod=
e makes
> > > all the data.id's =3D 'a'.
>
> > > Why can't you just read the data into a matrix? =EF=BF=BDIf you want
t=
he
> > > structure to contain the filename then add data[i].id =3D named
inside=

> > > the loop.- Hide quoted text -
>
> > > - Show quoted text -
>
> > Hi,
>
> > Are you asking why i'm using structures in the first place ?
> > If yes, my initial idea (from python lessons) was to create something
> > like an empty array and then read in each file into this empty array
> > by concatenation. That way each element would have a unique ID which i
> > could use to access them.
> > But it seems like i can't create an empty 2-d array of a certain size
> > and number of files to be read ('numfiles' in my case).
> > When you say create a matrix, is this what you meant ?
>
> > I got the idea of using structures only from responses in my previous
> > emails on 'batch indexing'.
>
> > -R
>
> I guess I'm still confused. =C2=A0I was suggesting just doing:
> data =3D fltarr(nx,ny,numfiles)
>
> then for each files[i] the image is data[*,*,i]
>
> It's unique simply by the index.- Hide quoted text -
>
> - Show quoted text -

Hi Vince,

I combined the ideas and it seems to have worked.
The file_search method is storing the filenames in a string array. So,
if i read them all one by one into data[*,*,numfiles-1], it is
placing each files[i] into the corresponding location in data[*,*,i].
This way i am able to access each file, and then compute the mean, for
e.g.

Here's the code:

pro structures_simple

dir1=3D'D:\trials'
cd,dir1
files=3DFILE_SEARCH('*[^\.{hdr}]', /QUOTE,count=3Dnumfiles)
print,files
print,numfiles

data=3Dfltarr(2179,761,numfiles)

tempval =3D fltarr(2179,761)
for i=3D0L, numfiles-1 do begin
named=3Dfiles(i)

openr,1,named
readu,1,tempval
close,1
data[*,*,i]=3Dtempval
avg=3Dmean(data[*,*,i],/nan)
print,avg
help,data[*,*,i]
endfor

return

end

What do you think ?

-Raghu
 




 12 Posts in Topic:
index arrays of structures
Raghu <raghuram.narasi  2008-03-15 13:53:47 
Re: index arrays of structures
Vince Hradil <hradilv@  2008-03-15 14:07:08 
Re: index arrays of structures
Vince Hradil <hradilv@  2008-03-15 19:31:19 
Re: index arrays of structures
Raghu <raghuram.narasi  2008-03-15 21:04:57 
Re: index arrays of structures
Vince Hradil <hradilv@  2008-03-16 05:49:23 
Re: index arrays of structures
Raghu <raghuram.narasi  2008-03-16 12:19:00 
Re: index arrays of structures
Vince Hradil <hradilv@  2008-03-16 12:29:43 
Re: index arrays of structures
Reimar Bauer <R.Bauer@  2008-03-17 15:44:07 
Re: index arrays of structures
David Fanning <news@[E  2008-03-17 09:03:48 
Re: index arrays of structures
Raghu <raghuram.narasi  2008-03-17 09:29:55 
Re: index arrays of structures
"R.G. Stockwell"  2008-03-17 11:57:03 
Re: index arrays of structures
Raghu <raghuram.narasi  2008-03-17 13:31:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 13:00:50 CDT 2008.