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

Home » Public Forums » archive » Re: How to check variable type?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to check variable type? [message #40504] Mon, 16 August 2004 16:49
MKatz843 is currently offline  MKatz843
Messages: 98
Registered: March 2002
Member
Here's a little dual-action function you can use.

;+
; -------------------------
; IDL function: var_type.pro
; for a given input variable, this function returns
; the type of that variable. The returned value is a number 0-15
; equal to the second-to-last field in the "size" function,
; OR if the keyword "string" is set, a type name is returned.
;
; Examples:
; print, var_type(1d) ;--- returns "5"
; print, var_type(1d, /string) ;--- returns "DOUBLE"
; -------------------------
;-

function var_type, a, string = string
return, keyword_set(string) ? size(a, /TNAME) : size(a, /TYPE)
end




biophys@gmail.com (biophysics) wrote in message news:<512b0d8b.0408131520.46e68fbd@posting.google.com>...
> Hi, guys
>
> I want to write a function that processes data very differently
> according to the type. But How do I check the type inline? I couldn't
> find any clue by a quick look through the function list. Can anybody
> give me some hints?
>
Re: How to check variable type? [message #40517 is a reply to message #40504] Fri, 13 August 2004 18:26 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <512b0d8b.0408131520.46e68fbd@posting.google.com>,
biophys@gmail.com (biophysics) wrote:

> Hi, guys
>
> I want to write a function that processes data very differently
> according to the type. But How do I check the type inline? I couldn't
> find any clue by a quick look through the function list. Can anybody
> give me some hints?
>
> thanks!

You mean it isn't obvious that you use SIZE to get the variable type?

CASE (SIZE(var, /TNAME) OF
'UNDEFINED' : ...
'BYTE' : ...
.
.
.
ELSE : ...
ENDCASE

To make it more obscure, you can use type codes instead of type names.
;-)

Regards, Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: animate loaded images
Next Topic: Re: animate loaded images

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

Current Time: Thu Oct 09 07:00:19 PDT 2025

Total time taken to generate the page: 1.04207 seconds