Viewing contents of file '../idllib/user_contrib/hamill/check_type_dim.pro'
FUNCTION CHECK_TYPE_DIM, VARIABLE, $
	DIMENSIONS=DIMENSIONS, $
	NUMERIC=NUMERIC, $
	UNDEFINED=UNDEFINED, $
	BYTE=BYTE, $
	INTEGER=INTEGER, $
	LONG=LONG, $
	FLOAT=FLOAT, $
	DOUBLE=DOUBLE, $
	COMPLEX=COMPLEX, $
	STRING=STRING, $
	STRUCTURE=STRUCTURE
;+
; NAME:
;	CHECK_TYPE_DIM
;
; PURPOSE:
;	This function returns a TRUE or FALSE value (1 or 0) depending
;	on the type of the variable, e.g. is it of type integer.
;
; CALLING SEQUENCE:
;	RESULT = CHECK_DATA_TYPE ( VARIABLE )
;	But the result only makes sense if one keyword or more are set.
;
; INPUTS:
;	VARIABLE: an IDL variable to be checked.
;	
; KEYWORD PARAMETERS:
;	There are two classes of keywords.  First, there is ...
;		DIMENSIONS	the number of dimensions; check that the
;				input variable is as specified; this parameter
;				can be a scalar (only one dimensionality is
;				expected) or a vector (if several dimensionali-
;				ties are allowed)
;	Next, there are keywords that specify the data types expected for
;	VARIABLE.  The choices are: UNDEFINED, BYTE, INTEGER, LONG, FLOAT,
;	DOUBLE, COMPLEX, STRING, and STRUCTURE; and there is also the choice
;	NUMERIC, which is the same as setting the BYTE, INTEGER, LONG, FLOAT,
;	and DOUBLE keywords.
;
; OUTPUTS:
;	The function returns 1 if the dimensions are correct and if the data
;	type matches any set keyword, otherwise it returns 0.
;
; EXAMPLE:
;	On entering a procedure, you can check that the input parameter P1 is
;	a 1, 2, or 3-dimensional floating or double array, as follows:
;
;	    if not check_data_type ( p1, dim=[1,2,3], /float, /double ) then $
;		message, "Invalid parameter P1"
;
; MODIFICATION HISTORY:
; 	Written by:	James Hamill
;			Siemens Medical Systems
;			2501 N. Barrington Rd.
;			Hoffman Estates, IL  60195-7372
;			(708)304-7760
;			hamill@sgi.siemens.com
;			October, 1993
;-



undefined_type	= 0
byte_type	= 1
int_type	= 2
long_type	= 3
float_type	= 4
double_type	= 5
complex_type	= 6
string_type	= 7
structure_type	= 8

sizv = size(variable)
ndims = sizv(0)
data_type = sizv(ndims+1)


;-------------------------------------------------------------------------------
;  Dimensions: does the input scalar or array have the required dimensions?
;-------------------------------------------------------------------------------


if n_elements(dimensions) eq 0 then dimensions_agreement=1 else begin

  agreement = where ( dimensions eq ndims, n_agreeing )
  dimensions_agreement = (n_agreeing ne 0)

endelse


;-------------------------------------------------------------------------------
;  Type: is any of the type keywords set?  If so, then does the actual type
;  agree with any of the set keywords?
;-------------------------------------------------------------------------------


ok_numeric	= keyword_set(numeric)
ok_undefined	= keyword_set(undefined)
ok_byte		= ok_numeric or keyword_set(byte)
ok_integer	= ok_numeric or keyword_set(integer)
ok_long		= ok_numeric or keyword_set(long)
ok_float	= ok_numeric or keyword_set(float)
ok_double	= ok_numeric or keyword_set(double)
ok_complex	= keyword_set(complex)
ok_string	= keyword_set(string)
ok_structure	= keyword_set(structure)

if (not ( ok_undefined or $
	ok_byte or $
	ok_integer or $
	ok_long or $
	ok_float or $
	ok_double or $
	ok_complex or $
	ok_string or $
	ok_structure ) ) then type_agreement=1 $ ; if no type keywords were set
	else case data_type of			; if some were set ...

  undefined_type:	type_agreement = ok_undefined
  byte_type:		type_agreement = ok_byte
  int_type:		type_agreement = ok_integer
  long_type:		type_agreement = ok_long
  float_type:		type_agreement = ok_float
  double_type:		type_agreement = ok_double
  complex_type:		type_agreement = ok_complex
  string_type:		type_agreement = ok_string
  structure_type:	type_agreement = ok_structure

endcase


;-------------------------------------------------------------------------------
;  Finally: do the dimensions and type both agree?
;-------------------------------------------------------------------------------


result = (dimensions_agreement and type_agreement)


return, result


end