|
|
Re: Imaginary is narrow minded [message #9846 is a reply to message #9842] |
Tue, 02 September 1997 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Now I'm really brainstorming. Here is another
program for Brian Jackel:
FUNCTION IF_IMAGINARY, variable
types = ['UNDEFINED', 'BYTE', 'INTEGER', 'LONG', 'FLOAT', $
'DOUBLE', 'COMPLEX', 'STRING', 'STRUCTURE', $
'DCOMPLEX', 'POINTER', 'OBJECT']
s = Size(variable)
thisType = types(s(s(0) + 1))
IF thisType EQ 'COMPLEX' THEN RETURN, Imaginary(variable) $
ELSE RETURN, 0.0
END
Then, you can do this:
imaginaryPart = IF_IMAGINARY(variable)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
|
|
|
Re: Imaginary is narrow minded [message #9848 is a reply to message #9846] |
Tue, 02 September 1997 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Brian Jackel writes:
> <Rant>
> I'm stuck with IDL 4.0, and was wondering if the snazzy new version
> still gives this stupid error
>
> % IMAGINARY: Operand must be of complex type:
>
> Alternatively, I'd love to know _why_ it can't just return a zero value.
> Sometimes the argument is going to be real, and it irritates me to add
> the extra call to make sure the argument is complex. IDL functions are
> usually pretty clever about dealing with variable input types, but not here.
> </Rant>
Oh, dear, it's one of those days, apparently. Here, Brian, something to
cheer you up.
FUNCTION Type, variable
types = ['UNDEFINED', 'BYTE', 'INTEGER', 'LONG', 'FLOAT', $
'DOUBLE', 'COMPLEX', 'STRING', 'STRUCTURE', $
'DCOMPLEX', 'POINTER', 'OBJECT']
s = Size(variable)
RETURN, types(s(s(0) + 1))
END
IF Type(thatThing) EQ 'COMPLEX' THEN thisThing=Imaginary(thatThing)$
ELSE thisThing = 0
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
|
|
|