Raghu schrieb:
> Hi,
>
> With reference to my recent posting (IDL batch indexing), i understood
> that i could structures. However, i haven't been able to figure out
> one step.
>
> Here is my code as of now:
> ; I want to search for all the images(files) in the directory trials,
> read them into the structure named data, and access each file within
> the structure.
>
> pro strcutres
> dir1='D:\trials'
> cd,dir1
> files=FILE_SEARCH('*[^\.{hdr}]', /QUOTE,count=numfiles)
> i=0
> while i lt numfiles do begin
> named=files(i)
> print,named
> data={ID:'a',sizes:fltarr(2179,761)}
> data=replicate(data,numfiles)
> data.sizes=findgen(numfiles)
> openr,1,named
> readu,1,data[i].sizes
> close,1
> i=i+1
> endwhile
> end
>
> ERROR message- READU: Expression must be named variable in this
> context: <FLOAT 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
Have to say first that is not a solution for your current problem. But
sometimes you like to know about this too
You can directly read into pointers
this examples assumes files of equal filesize (it reads now only one
file, but you can use [i] for [0] )
a={data:replicate(ptr_new(bytarr(20996)),4)}
openr,lun,'example.bin',/get
readu,lun,*(a.data)[0]
free_lun,lun
print, (*(a.data)[0])[0:10] ; prints the first bytes
You can make the structure more complex if you have to read for example
records of byte, float and other types. Then you have to define a
structure with placeholders for these types. You can replicate this
structure to the number of records. And then the whole file could be
read at once.
cheers
Reimar


|