comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Checking datatypes (datatype.pro)

Checking datatypes (datatype.pro)
type: item
description: Someone posted about the danger of IDL variables and parameters being of unexpected datatypes. There is a little function, 'datatype' (probably based on HELP) which is handy for verifying that the type is what you expect it is at critical times, such as upon entering a routine. For example: IDL> j=1L IDL> if datatype(j) NE 'LON' then message,'Invalid datatype for j.' IDL> IDL> j=1.0 IDL> if datatype(j) NE 'LON' then message,'Invalid datatype for j.' % $MAIN$: Invalid datatype for j. I find it very helpful. Thank you, Ray Sterner, and here it is: ;----------------------------------------------------------- -- ;+ ; NAME: ; DATATYPE ; PURPOSE: ; Datatype of variable as a string (3 char or spelled out). ; CATEGORY: ; CALLING SEQUENCE: ; typ = datatype(var, [flag]) ; INPUTS: ; var = variable to examine. in ; flag = output format flag (def=0). in ; KEYWORD PARAMETERS: ; Keywords: ; /DESCRIPTOR returns a descriptor for the given variable. ; If the variable is a scalar the value is returned as ; a string. If it is an array a description is return ; just like the HELP command gives. Ex: ; datatype(fltarr(2,3,5),/desc) gives ; FLTARR(2,3,5) (flag always defaults to 3 for /DESC). ; OUTPUTS: ; typ = datatype string or number. out ; flag=0 flag=1 flag=2 flag=3 ; UND Undefined 0 UND ; BYT Byte 1 BYT ; INT Integer 2 INT ; LON Long 3 LON ; FLO Float 4 FLT ; DOU Double 5 DBL ; COM Complex 6 COMPLEX ; STR String 7 STR ; STC Structure 8 STC ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; Written by R. Sterner, 24 Oct, 1985. ; RES 29 June, 1988 --- added spelled out TYPE. ; R. Sterner, 13 Dec 1990 --- Added strings and structures. ; R. Sterner, 19 Jun, 1991 --- Added format 3. ; R. Sterner, 18 Mar, 1993 --- Added /DESCRIPTOR. ; Johns Hopkins University Applied Physics Laboratory. ; ; Copyright (C) 1985, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each…
creator: Russ Welti
date: 1995-07-13T07:00:00-00:00