comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: array chicanery
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: array chicanery [message #28050 is a reply to message #28048] Thu, 15 November 2001 16:35 Go to previous messageGo to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
From: "Rochelle Hatton" <nrh@imag.wsahs.nsw.gov.au>
> I've experienced some weird business with arrays, and I'm
> hoping somebody can explain.

Sure can!

> I have been using the IDL function PCOMP, calculating the principal
> components of some data. If I feed in a float array to the function,
> eg.
> result=PCOMP(data, coefficients=eigenvectors, $
> eigenvalues=eigenvalues, /covariance, /standardize)
>
> I get a result, but when I redisplay the data array, it has changed.
> Since PCOMP only returns a result, what is it doing to my original
> array, and why?

PCOMP doesn't "only return a result".

Looking at the source code for PCOMP and searching for "Array" (the name of
the first argument) one sees...

;Standardize the columns of the input array with a mean of 0.0
;and a variance of 1.0
if KEYWORD_SET(Standardize) ne 0 then $
Array = STANDARDVAR(Array, Dimension, Double = Double)

So "Array" is modified and if this corresponds to an argument passed by
reference then the original will be modified. In your case you have passed
it an array ("data") so it is fair game. For more info on this issue see
"Procedures and Functions/Parameter Passing Mechanisms" in "Building IDL
Applications". This is a common source of confusion, usually in the opposite
sense: people pass array segments and structure tags to routines and are
surprised when they *aren't* modified.

The easiest way of protecting your original array is to pass PCOMP a copy of
the data. This should work

result=PCOMP(reform(data),...)

BTW can anyone suggest a better general purpose function for this purpose?

I will refrain from commenting on whether PCOMP's behaviour represents good
programming practice... But I do think they could have warned you.

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research




--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: TV and T3D?
Next Topic: re-warping an image file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Dec 03 01:49:15 PST 2025

Total time taken to generate the page: 1.60647 seconds