1

I'm relative new to IDL and I need to achieve the following: Basically all I have to do is to read in different file and create different arrays while reading them.

So I was thinking something like:

files=dialog_pickfile(/multi, filter=filter, path=path, title=title)
n_files=n_elements(files)
for i=0, n_files-1 do begin
openr, lun, /get_lun, files[i]
readf, lun, data

But at this point how to create different array by keeping track of the e.g. name of the file.

For instance:

arrayfile1(i,j,k)=
arrayfile2(i,j,k)=

and so on.

Hope this is clear, Best.

Joe
  • 2,547
  • 1
  • 18
  • 27
  • What version of IDL are you using? IDL 8 and later support hashes (aka mapping aka associative arrays), so you can create a hash indexed on the filename. If you're using an earlier version, you can create an array of structures, with each struct having the filename + a pointer to the data. (you can't put the array data directly into the struct, as the size of the array is part of the struct's definition, and you can't make an array of structs unless they're all the same) – Joe Jan 09 '13 at 17:21

1 Answers1

3

How about something like this?

files = dialog_pickfile(/multiple_files, filter=filter, path=path, $
                        title=title)
n_files = n_elements(files)

; check if the user cancels the dialog
if (n_files eq 1 && files[0] eq '') then n_files = 0

full_data = fltarr(nfiles, ni, nj, nk)
data = fltarr(ni, nj, nk)

for i = 0, n_files - 1 do begin
  openr, lun, /get_lun, files[i]
  readf, lun, data
  full_data[i, 0, 0, 0] = data
  free_lun, lun
endfor

You could also use lists or hashes instead of a large array. Arrays are faster, but they must be continuous memory, so that could be a problem depending on the data size.

mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • @mgalloy.Thanks, but I'm getting an error at line: openr, lun, /get_lun, files[i]. Attempt to subscript FILES with I is out of range. Any ideas? –  Jun 23 '12 at 10:31
  • I would check files with a "HELP, files" to make sure it is what it is supposed to be. – mgalloy Jul 03 '12 at 22:33