comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Reading into arrays with order > 2

Re: Reading into arrays with order > 2
type: item
description: Steven Riley wrote: > Assuming names3Mom is a 1D array of strings (of valid filenames) is there > any reason why the following code will not read many files into a 3d array? > > FOR I=0,1 DO BEGIN > close,1 & openr,1,names3Mom(I) > readf,1,all3MomData(I,*,*) > END > > I get no error messages, but when I look at my array it contains no data...? > I'm quite sure the files being read contain data. Is this some inherent > problem with readf and arrays with order > 2? "Subscripted variable references are passed by value. Parameters passed by value can only be inputs to program units." (Source: IDL Online Help - Parameter Passing Mechanism) The following code will work. sz = SIZE(all3MomData) buffer = ???ARR(sz(2), sz(3)) ; ??? is data type (INT, FLT etc.) FOR I=0,1 DO BEGIN close,1 & openr,1,names3Mom(I) readf,1,buffer all3MomData(I,*,*) = buffer END -------------------------------- May the Force be with you. Osamu Sasaki as Dasaki E-mail : dasaki@pc.highway.ne.jp
creator: Osamu Sasaki
date: 1999-11-08T08:00:00-00:00

Re: Reading into arrays with order > 2
type: item
description: > Assuming names3Mom is a 1D array of strings (of valid filenames) is there > any reason why the following code will not read many files into a 3d array? > > FOR I=0,1 DO BEGIN > close,1 & openr,1,names3Mom(I) > readf,1,all3MomData(I,*,*) > END > > I get no error messages, but when I look at my array it contains no data...? > I'm quite sure the files being read contain data. Is this some inherent > problem with readf and arrays with order > 2? > > Steven This is an very common mistake and is one which has cost me literally hours of time cursing at my code only to realise that I've been duped again. The problem lies in the readf line. Unfortunately you can not read into subscripted arrays. This is to do with the way IDL handles passing around subscripted arrays. Essentially when you subscript an array, IDL creates a copy of that small subsection. So, it is a temporary smaller array which gets passed into the readf function, not the actual all3MomData array. This is called passing by value, because it is only the value of all3MomData that is passed in, not the actual memory location, so readf cannot change all3MomData at all. So readf goes along as normal but instead of doing what you want, which is to read the data into the right slice of all3MomData, it reads the data into this smaller temporary variable. This is no use to you as this temp variable is destroyed after readf is exited and nothing goes back into all3MomData. This is why you're left with all 0's. That's not a very good explanation - if you want a nice concise one then you'll have to wait for David Fanning to post his reply. That's all very well but you're now thinking what exactly do I have to change. Well it's quite simple. Instead of reading directly into all3MomData, you're going to go via a smaller variable which is the same size as the slice, i.e temp = all3MomData(0,*,*) FOR i=0, 1 DO BEGIN OpenR, lun, /GET_LUN, names3Mom[i] readf, lun, temp all3MomData[i,*,*] = temp Free_Lun, lun ENDFOR I've take…
creator: Phil Aldis
date: 1999-11-08T08:00:00-00:00

Re: Reading into arrays with order > 2
type: item
description: Hi Steven, You are trying to read into a subscripted variable which is passed to readf by value and not by reference so when readf finishes all3MomData is unchanged. this should work (assumimg that all3MomData matches the file format, size+data type) temp=reform(all3MomData[0,*,*]) for i=0, n_elements(names3Mom)-1 do begin openr, lun, names3Mom[i], /get_lun readf, lun, temp all3MomData[i,*,*]=temp free_lun, lun endfor good luck, Ivan Steven Riley wrote: > > Assuming names3Mom is a 1D array of strings (of valid filenames) is there > any reason why the following code will not read many files into a 3d array? > > FOR I=0,1 DO BEGIN > close,1 & openr,1,names3Mom(I) > readf,1,all3MomData(I,*,*) > END > > I get no error messages, but when I look at my array it contains no data...? > I'm quite sure the files being read contain data. Is this some inherent > problem with readf and arrays with order > 2? > > Steven > > -- > > Linacre College > Oxford > OX1 3JA > > 01865 - (2)81229 (W) > 01865 - 209295 (H) > > www.linacre.ox.ac.uk/student_pages/steven_riley -- Ivan Zimine Dpt. of Radiology (MRI), Geneva University Hospitals email: ivan.zimine@physics.unige.ch tel. : (+41 22) 372 70 70
creator: Ivan Zimine
date: 1999-11-08T08:00:00-00:00