; $Id: vax_convert_float.pro,v 1.3 1998/03/04 18:14:32 ali Exp $ ; ;+ ; NAME: ; VAX_CONVERT_FLOAT ; ; PURPOSE: ; For VMS ONLY, allow direct access to the VMS Runtime Library ; routine CVT$CONVERT_FLOAT. This can be used to convert data ; types not supported by the IDL BYTEORDER procedure. ; ; This routine also serves as an example of using CALL_EXTERNAL to ; call VMS runtime library functions. ; ; To use this routine, it is very helpful to understand ; CVT$CONVERT_FLOAT. That routine is documented in the ; "OpenVMS RTL Library (LIB$) Manual". ; ; CATEGORY: ; Data Conversion, Examples ; ; CALLING SEQUENCE: ; Result = VAX_CONVERT_FLOAT(INPUT_VALUE, OUTPUT_VALUE) ; ; INPUTS: ; INPUT_VALUE: A single floating point value to be converted. The ; type of this value must agree with the that specified by the ; INPUT_TYPE_CODE keyword. ; ; OUTPUT_VALUE: Variable to receive the resulting converted value. ; The type of this variable must agree with that specified by the ; OUTPUT_TYPE_CODE keyword. ; ; KEYWORDS: ; INPUT_TYPE_CODE: This is an integer that indicates the type ; of data contained in INPUT_VALUE, and corresponds directly to ; the input_type_code argument of CVT$CONVERT_FLOAT. Use the ; following table to determine the allowed values: ; ; CVT$K_VAX_F = 0L ; VAX F Floating point data ; CVT$K_VAX_D = 1L ; VAX D Floating point data ; CVT$K_VAX_G = 2L ; VAX G Floating point data ; CVT$K_VAX_H = 3L ; VAX H Floating point data ; CVT$K_IEEE_S = 4L ; IEEE S Floating point data ; CVT$K_IEEE_T = 5L ; IEEE T Floating point data ; CVT$K_IBM_LONG = 6L ; IBM Long Floating point data ; CVT$K_IBM_SHORT = 7L ; IBM Short Floating point data ; CVT$K_CRAY = 8L ; Cray Floating point data ; CVT$K_IEEE_X = 9L ; IEEE X Floating point data ; ; If INPUT_TYPE_CODE is not specified, a default of 0 ; (CVT$K_VAX_F) is used. ; ; OUTPUT_TYPE_CODE: This is an integer that indicates the type ; of data contained in OUTPUT_VALUE, and corresponds directly to ; the output_type_code argument of CVT$CONVERT_FLOAT. Use the ; table from the description of OUTPUT_TYPE_CODE above to ; determine the allowed values. If OUTPUT_TYPE_CODE is not ; specified, a default of 0 (CVT$K_VAX_F) is used. ; ; OPTION: Conversion option specifier. This keyword corresponds ; directly to the options argument to CVT$CONVERT_FLOAT and ; is a mask in which each option bit set causes the corresponding ; option to be used during the conversion. Use the following table ; to construct this value: ; ; CVT$M_ROUND_TO_NEAREST = 1L ; CVT$M_TRUNCATE = 2L ; CVT$M_ROUND_TO_POS = 4L ; CVT$M_ROUND_TO_NEG = 8L ; CVT$M_VAX_ROUNDING = 16L ; CVT$M_BIG_ENDIAN = 32L ; CVT$M_ERR_UNDERFLOW = 64L ; ; If OPTION is not specified, a default of CVT$M_ROUND_TO_NEAREST ; is used. ; ; QUIET: Normally, this routine will print an error message if ; CVT$CONVERT_FLOAT reports a problem with the conversion. Setting ; QUIET suppresses this message. ; ; RESTRICTIONS: ; As a direct wrapper to a runtime library function, calling this ; routine with arguments specified incorrectly can cause memory ; corruption that can effect the IDL program. ; ; MODIFICATION HISTORY: ; Written by Michael J Whitington, Feb 1998 ; Modified to fit in the IDL examples directory, AB, Feb 1998 ;- ; FUNCTION VAX_CONVERT_FLOAT, input_value, INPUT_TYPE_CODE=input_type_code, $ output_value, OUTPUT_TYPE_CODE=output_type_code, $ OPTION=option, QUIET=quiet ; This could be written more concisely using the IDL 5.1 '?' operator ; but then this routine would not run with older versions of IDL ;in_code = (n_elements(input_type_code) eq 0) ? 0L : long(input_type_code) if (n_elements(input_type_code) eq 0) then in_code = 0L $ else in_code = long(input_type_code) ;out_code = (n_elements(output_type_code) eq 0) ? 0L : long(output_type_code) if (n_elements(output_type_code) eq 0) then out_code = 0L $ else out_code = long(output_type_code) ; opt = (N_ELEMENTS(option) EQ 0) ? 1L : LONG(option) if (N_ELEMENTS(option) EQ 0) then opt = 1L else opt = LONG(option) ; NOTE: Using _EXTRA to set the VAX_FLOAT keyword to zero ensures that ; CALL_EXTERNAL will not do VAX_FLOAT conversions no matter what the ; current default for that keyword has been set to. Use of the _EXTRA ; mechanism to specify it allows the statement to also work with versions ; of IDL prior to 5.1 (before CALL_EXTERNAL accepted VAX_FLOAT), as it will ; be quietly ignored as a side effect of keyword inheritance. result = CALL_EXTERNAL('LIBRTL', 'CVT$CONVERT_FLOAT', $ _extra={VAX_FLOAT:0}, input_value, in_code, $ output_value, out_code, opt, VALUE=[ 0, 1, 0, 1, 1]) IF NOT(KEYWORD_SET(quiet) ) AND NOT(result AND 1) THEN $ MESSAGE, 'bad conversion :' +string(result) , /CONTINUE, /INFORMATIONAL RETURN, result END ; Notes about the library routine CVT$CONVERT_FLOAT extracted from VMS C ; header files ; ; CVT$ROUTINES ; ; /* Source: 4-MAY-1995 18:58:45 $64$DUA3210:[STARLET_H.SRC]CVT$ROUTINES.SDI;1 */ ; /*** MODULE cvt$routines ***/ ; /* CVT$CONVERT_FLOAT */ ; /* The CVT$CONVERT_FLOAT converts floating point data types to other */ ; #define cvt$convert_float CVT$CONVERT_FLOAT ; unsigned int cvt$convert_float(__unknown_params); ; ; ; ; CVTDEF ; ; #define CVT$K_VAX_F 0 /* VAX F Floating point data */ ; #define CVT$K_VAX_D 1 /* VAX D Floating point data */ ; #define CVT$K_VAX_G 2 /* VAX G Floating point data */ ; #define CVT$K_VAX_H 3 /* VAX H Floating point data */ ; #define CVT$K_IEEE_S 4 /* IEEE S Floating point data */ ; #define CVT$K_IEEE_T 5 /* IEEE T Floating point data */ ; #define CVT$K_IBM_LONG 6 /* IBM Long Floating point data */ ; #define CVT$K_IBM_SHORT 7 /* IBM Short Floating point data */ ; #define CVT$K_CRAY 8 /* Cray Floating point data */ ; #define CVT$K_IEEE_X 9 /* IEEE X Floating point data */ ; #define CVT$M_ROUND_TO_NEAREST 0x1 ; #define CVT$M_TRUNCATE 0x2 ; #define CVT$M_ROUND_TO_POS 0x4 ; #define CVT$M_ROUND_TO_NEG 0x8 ; #define CVT$M_VAX_ROUNDING 0x10 ; #define CVT$M_BIG_ENDIAN 0x20 ; #define CVT$M_ERR_UNDERFLOW 0x40 ; #define CVT$M_SPARE2 0xFFFFFF80 ; struct cvt$r_conversion_options { ; unsigned cvt$v_round_to_nearest : 1; ; unsigned cvt$v_truncate : 1; ; unsigned cvt$v_round_to_pos : 1; ; unsigned cvt$v_round_to_neg : 1; ; unsigned cvt$v_vax_rounding : 1; ; unsigned cvt$v_big_endian : 1; ; unsigned cvt$v_err_underflow : 1; ; unsigned cvt$v_spare2 : 25; ; ; ; ; CVTMSG ; ; /* CVT$_ABCMNOXYZ */ ; #define CVT$_FACILITY 1530 ; #define CVT$_NORMAL 100302857 ; #define CVT$_INPCONERR 100302866 ; #define CVT$_INVINPTYP 100302874 ; #define CVT$_INVOPT 100302882 ; #define CVT$_INVOUTTYP 100302890 ; #define CVT$_INVVAL 100302898 ; #define CVT$_NEGINF 100302906 ; #define CVT$_OUTCONERR 100302914 ; #define CVT$_OVERFLOW 100302922 ; #define CVT$_POSINF 100302930 ; #define CVT$_UNDERFLOW 100302938 ; ;