;+ ; NAME: ; im ; PURPOSE: ; Return the imaginary part of a number ; EXPLANATION: ; CALLING SEQUENCE ; r = im(x) ; INPUTS: ; X - number or array of type complex, dcomplex ; (other types returned as 0) ; OUTPUT: ; result - imaginary part of x ; float for x is complex ; double for x is dcomplex ; original type for all others ; METHOD: ; IDL routines float and dfloat; ; REVISION HISTORY: ; 2012-01-08 Leslie Young, SwRI ;- function im,x On_error,2 res = size(x, /tname) ; use switch to "fall through" to the next statement ; making the byte, int etc simpler switch res of 'COMPLEX': return, float(complex(0,-1.)*x) 'DCOMPLEX': return, double(dcomplex(0,-1.)*x) 'BYTE': 'INT': 'LONG': 'FLOAT': 'DOUBLE': 'UNIT': 'ULONG': 'LONG64': 'ULONG64': return, 0b*x else : message,'Struct expression not allowed in this context.' endswitch end