; $Id: vartype.pro,v 1.4 2006/01/25 23:12:57 azuah Exp $
;###############################################################################
;
; NAME:
;  vartype
;
; PURPOSE:
;  Deterimines the type name of an IDL variable. Should work with
;  intrinsic types (integer, float, etc) and user-defined types such
;  as structure and class names.
;
; CATEGORY:
;   DAVE Framework
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Oct, 2002
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used of if the code in this file is
;  included in another product.
;
;###############################################################################



;===============================================================================
;  vartype
;
; PURPOSE:
;  Deterimines the type name of an IDL variable.
;
; PARAMETERS:
;   variable [in] - The variable whose type is required
;
; RETURN VALUE:
;   - Either The IDL type which should be one of:
;     INT, BYTE, FLOAT, DOUBLE, STRING, LONG etc, struct name, class name
;   - Or an empty string if name is unknown or if an anonymous struct.
;
function vartype, variable

type = size(variable,/tname)
if (type eq "OBJREF") then begin
    if (obj_valid(variable) eq 1) then begin
        type = obj_class(variable)
    endif else begin
        type = 'OBJARR'
    endelse
endif
if (type eq "STRUCT") then type = tag_names(variable,/structure_name)

return, type

end
