ArgCvt - Convert from one scaler SDS type to Another.

Function

Convert from one scaler SDS type to Another.

Description

This routine meets requirements for a general type conversion between Sds scaler types. There are three classes of scalars

1.
Signed Integers
2.
Unsigned Integers
3.
Real (floating point) values

Within each class, Sds can represent various types. For example- Sds supports SDS_BYTE, SDS_SHORT SDS_INT and SDS_I64 versions of the Signed integer class. The difference is the number of bytes required for each one.

This routine does a three part conversion-

1.
Convert the source type to the largest type of the same class (char, short -> long int) (unsigned char, unsigned short -> unsigned long int) (float -> double )

2.
Convert the value above to the largest type of the destination class.

3.
Convert the value in 2 to the actual destination type.

Range errors are possible during the conversions.

The source/destination for a conversion can be the address of a value of the appropiate type or it may be an Sds item.

When specifing the address of the value, you must specify the type. (SDS_CHAR, SDS_INT, SDS_UINT etc. (Not SDS_STRUCT)). Additional type codes - ARG_STRING/ARG_STRING2 - can be speicifed indicating the source or destination is a null terminated string while should/will contain a representation of the number. (If both source and destination are strings, then a simple string copy is done.) A ARG_STRING2 type differs in only when the source is a FLOAT or DOUBLE value. When ARG_STRING is used, the maximum number of decimal digits is retrieved whilst when ARG_STRING2 is used, 6 is used for FLOAT and 10 for double. (Note that a type of SDS_CHAR represents a single character, not a string of characters)

To specify an Sds item as the source/destination, supply the address of the Sds id of the item in the appropiate address argument. Suppy ARG_SDS as the corresponding type code. The Sds id must describe a Scaler item, expect if it is a one dimensional character array. In this case, it is considered a character string. Source strings must be null terminated.

Invalid conversions result in status being set to ARG__CNVERR and an error being reported using ErsRep.

The ranges of integer types are determined by the range acceptable to SDS. The ranges of real types are determined by the archecture on which the machine is running.

Types of SDS_INT and SDS_UINT indicate the relevant item is a long int (which may be 32 or 64 bits, depending upon the machine and compiler being used). Note that if the machine does not support 64 bits integers then 64bit values with the high 32bits set to non-zero values cannot be handled - an error is returned.

Language

C

Call

(Void) = ArgCvt (SrcAddr, SrcType, DstType, DstAddr, DstLen, status)

Parameters

(">" input, "!" modified, "W" workspace, "<" output)

>SrcAddrvoid *Address of the source data or of an Sds item id.
>SrcTypeSdsCodeTypeType of the source data.
>DstTypeSdsCodeTypeType of the destination data.
>DstAddrvoid *Address of the destination or of an Sds item id.
>DstLenintLength of the destination in bytes. If DstType is ARG_SDS, then this is ignored.
!statusStatusType *Modified status.

Include files

Arg.h

External functions used

ErsRepErs Report an error.
ErsSPrintfErs Format a string into a buffer.
strtolCRTL Convert a decimal string to a long.
strtoulCRTL Convert a decimal string to an unsigned long.
strtodCRTL Convert a decimal string to a double.
strncpyCRTL Copy one string to another
strlenCRTL Get the length of a string.

External values used

none

Prior requirements

none

Support

Tony Farrell, AAO

Click here for the DRAMA home page and here for the AAO home page.

 For more information, contact tony.farrell@mq.edu.au