comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: filling an empty array

Re: filling an empty array
type: item
description: JJMeyers2@gmail.com wrote: > Hello, > > I have an empty array that I am trying to fill out with results from a > conditional statement. Because I do not know the results of the > condition (and I do not want to use pointers) I make a really big > array and I fill it. When I compare the results though with the > expected ones they are not correct (except the first value). Any > ideas on what the problem might be? > > Here is the part of the code: > > index_data=intarr(32,1000) > > FOR i=0,31 DO BEGIN > index_data(i)= > where((dat_x(*,i) GE -0.1) AND (dat_x(*,i) LE 0.1) AND $ > (dat_y(*,i) GE -0.5) AND (dat_y(*,i) LE 0.5)) > ENDFOR > > The result of the 'where' statement is different for each of the i > cases and when I hard-coded several integers and compared with the > results of the loop they were different. > > Does anyone have any idea what the problem is? > > Thank you in advance, > JJM JJ, sorry if I sound critical but you mustn't build a single padded index array like this, especially when that index array is only partially valid and therefore unuseable without further extraction. You just mustn't. Don't do it. The EPG will get you. There's got to be a better way. Even doing the actual work row-by-row (i.e., create row's index array and then use it) would be better. Anyway, some discussion on the current setup. You are indexing a two-dimensional array (INDEX_DATA) with a one-dimensional index (I). You *can* do this in IDL, but when you do it works like this: IDL treats the array as one-dimensional (in this case an INTARR(32*1000)) and inserts stuff accordingly, starting at the given index (I). Memory layout becomes important. Clearly you are getting a *lot* of overwriting here, as I is only increasing by 1 in each iteration. You need to do 2D insertion, as in INDEX_DATA[i,0]=... You might have to use REFORM( ..., 1, ? ) on the right-hand-side to get it 2-dimensional (with a leading dimension of 1). It would be much better if INDEX_DATA was an INTARR(1000,32). …
creator: Peter Mason
date: 2006-05-04T05:34:03-00:00

Re: filling an empty array
type: item
description: ...who are the EPG?
creator: greg michael
date: 2006-05-04T07:03:51-00:00

Re: filling an empty array
type: item
description: But this is a perfect job for pointers - why avoid them? index_data=ptrarr(32) dat_x=randomu(0,1000,32)*4-2 dat_y=randomu(0,1000,32)*4-2 FOR i=0,31 DO BEGIN index_data(i)=ptr_new(where((dat_x(*,i) GE -0.1) AND (dat_x(*,i) LE 0.1) AND $ (dat_y(*,i) GE -0.5) AND (dat_y(*,i) LE 0.5))) ENDFOR IDL> print,*index_data[1] 0 29 36 50 62 102 123 241 244 269 284 304 316 390 428 441 443 446 543 544 546 553 564 577 634 685 695 709 717 738 745 752 773 799 852 965 regards, Greg
creator: greg michael
date: 2006-05-04T07:27:41-00:00

Re: filling an empty array
type: item
description: Thank you Peter and Greg! I am trying to avoid pointers because I have used them before and I ended up making a mess of my program! Builiding an array and then removing the extra 0 and -1 just sounds simpler:-). I guess there is no harm trying again. Thank you again, JJM
creator: JJMeyers2
date: 2006-05-04T15:15:16-00:00

Re: filling an empty array
type: item
description: greg michael wrote: > ...who are the EPG? Sorry, I had the acronym wrong. EPA or IEPA. http://www.dfanning.com/misc_tips/iepa.html
creator: Peter Mason
date: 2006-05-04T21:24:40-00:00