'\" t .\" @(#)convert_external.3m 1.8 93/09/01 SMI; .TH convert_external 3M "1 Sep 1993" .SH NAME convert_external \- convert external binary data formats .SH SYNOPSIS .LP .B cc .RI "[ " "flag" " \|.\|.\|. ] " "file" " \|.\|.\|." .B \-lsunmath -lm .RI "[ " "library" " \|.\|.\|. ]" .LP .B #include .LP .ft B .nf enum convert_external_arch_t = { convert_external_sparc, convert_external_pc, convert_external_vax, convert_external_vaxg, convert_external_s370, convert_external_cray }; enum convert_external_type_t = { convert_external_signed, convert_external_unsigned, convert_external_float }; enum convert_external_rounding_t = { convert_external_common = \-1, convert_external_biased = \-2, convert_external_away = \-3 }; typedef struct { enum convert_external_arch_t arch ; /* format architecture */ enum convert_external_type_t type ; /* format type */ int size ; /* format size in 8-bit bytes */ } convert_external_t ; .fi .ft R .LP .BI "fp_exception_field_type convert_external(const char *" "src_p" , .BI "convert_external_t " "src_format" , .BI "char *" "dst_p" , .BI "convert_external_t " "dst_format" , .BI "int " "rounding" , .BI "int " "n" ); .LP .BI "fp_exception_field_type convert_external_(const char *" "src_p" , .BI "const convert_external_t *" "src_format_p" , .BI "char *" "dst_p" , .BI "const convert_external_t *" "dst_format_p" , .BI "const int *" "rounding_p" , .BI "const int *" "n_p" ); .LP .SH DESCRIPTION .IX "convert_external" "convert external binary data formats" .LP .B convert_external(\|) is used in C programs to convert between binary data on non-SPARC systems and SPARC binary data. The data may be signed integers, unsigned integers, or floating-point data. .B convert_external_(\|) is used in FORTRAN programs (CALL CONVERT_EXTERNAL(...)) for the same purpose, with all parameters call-by-reference. .br .ne 6 .LP The .B convert_external_t type describes the supported formats; for each architecture, signed and unsigned integers of sizes 1, 2, 4, 8, or 16 bytes, and floating-point types of sizes 4, 8, 10, 12, or 16 bytes in size are supported. If an improper size is specified for the source or destination, no conversion occurs and (1< char datasrc[800]; double datadest[100]; fp_exception_field_type excep; int rounding; int i; convert_external_t src, dest; /* read the Cray data into the array datasrc somehow, then ... */ src.arch = convert_external_cray; src.type = convert_external_float; src.size = 8; dest.arch = convert_external_sparc; dest.type = convert_external_float; dest.size = 8; rounding = convert_external_biased; excep = convert_external((char *) datasrc, src, (char *) datadest, dest, rounding, 100); /* * usually you aren't interested in inexact exceptions * and you'd do this */ excep &= ~(1 << fp_inexact); /* * other exceptions are possible in this example - after the fact, * you can find out where they happened this way */ if (excep != 0) for (i = 0 ; i < 100 ; i++) { excep = convert_external((char *)&datasrc[8 * i], src, (char *)&datadest[i], dest, rounding, 1); if (excep != 0) { /* do something specific about datadest[i] */ } } .fi .ft .RE .SS "Converting SPARC internal data to external form in FORTRAN" .LP Suppose data created in a SPARC program is to be read into an IBM PC. To convert, .RS .ft B .nf #include REAL*4 datasrc(100) REAL*4 datadest(100) INTEGER excep, convert_external, round INTEGER src(4), dest(4) c create datasrc array somehow, then ... src(1) = convert_external_sparc src(2) = convert_external_float src(3) = 4 dest(1) = convert_external_pc dest(2) = convert_external_float dest(3) = 4 round = convert_external_common excep = convert_external(datasrc, src, datadest, dest, round, 100) c The only exception that can arise is fp_invalid, c by converting a signaling NaN. c Now write the data out in a file that an IBM PC can read .fi .ft .RE .SH "SEE ALSO" .BR dd (1M), for reading tapes from foreign systems; .BR xdr (3N), for formatting arbitrary data structures in a machine-independent fashion. .SH NOTES .LP Conversions are performed one at a time by converting a source datum into an internal format large enough to hold any input exactly, then by converting the internal data to the destination form. Thus any pair of source and destination formats is permitted, but efficiency is not as high as would be the case for programs written to convert from one specific format to another.