Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ncar!gatech!udel!rochester!uhura.cc.rochester.edu!bat.lle.rochester.edu!steve From: steve@bat.lle.rochester.edu (Steve Swales) Newsgroups: comp.lang.idl-pvwave Subject: Re: Curious array behaviour? Message-ID: <12793@ur-cc.UUCP> Date: 15 Mar 91 23:02:33 GMT References: <275@locke.water.ca.gov> Sender: news@uhura.cc.rochester.edu Reply-To: steve@bat.lle.rochester.edu (Steve Swales) Organization: UofR Laboratory for Laser Energetics Lines: 38 In article <275@locke.water.ca.gov>, rfinch@caldwr.water.ca.gov (Ralph Finch) writes: > > PV-Wave 3.02 on a Sun 4. > > Array operations are quite powerful in idl-wave and so different from > other languages that I think I still don't fully understand them. > Here is something that has me puzzled: > > a=[1,2,3,4,5] > print,a([-1]) > -> 1 > print,a(-1) > -> ERROR > > Why the difference? Looks like a 'feature' to me. One explanation for it might be that one commonly will use this syntax for 'mapping' an array through a lookup table, and in this case it makes sense to have range checking for values off the end of the LUT and 'clamp' them to the end values... i.e.: lut=[0.1,0.5,0.75,0.9,0.95] values=[0,1,2,3,4,5,-1,11,4,3,2,7] print,lut(values) -> .100000 .500000 .750000 .900000 .950000 .950000 -> .100000 .950000 .950000 .900000 .750000 .950000 Isn't it fun to think up justifications for inconsistent program behavior... and you get lots of practice working with WAVE/IDL :-). -steve -- -------------------------------------------------------+"Come, Watson, come!" Steve Swales (716) 275-0265,-3857,-5101| he cried. "The game is steve@lle.rochester.edu (128.151.32.111)| afoot. Not a word! | Into your clothes and University of Rochester 250 East River Road| come!" S.H. Laboratory for Laser Energetics Rochester, NY 14623| 'The Abbey Grange'