IBM and IEEE Floats

The program bcnv uses an IBM C-language function contained in a published library, libascii.tar.Z, downloaded from <http://www-03.ibm.com/systems/z/os/zos/features/unix/libascii.html>. The file, xdrfloa.c, was extracted and used in BSU library libIBM. The downloaded library had to be translated from EBCDIC encoding using a Perl script.


{perllist}
#!/usr/bin/perl -w
 use Convert::EBCDIC;
#  $Id: Ebcdic2Ascii,v 1.1 2010-06-16 22:41:38 pm Exp $


 $translator = new Convert::EBCDIC;
#$ebcdic_string = $translator->toebcdic($a);
$filename=$ARGV[0];
open (fp1,$filename) ||
 die "error opening file \n";
$e=<fp1>;
close(fp1);

$ascii_string = $translator->toascii($e);


open (STDOUT,'| tr  \'\205\' \'\n\' | tr \'\335\' \'[\' |tr \'\250\' \']\'  ');

print $ascii_string;
perllist



The above Perl script requires a Convert-EBCDIC package found at:

<http://search.cpan.org/ cxl/Convert-EBCDIC-0.06/lib/Convert/EBCDIC.pm>.

Since there are a number of versions of EBCDIC, the translate pipe converts the left, “[”, and right, “]” characters to produce a correct ASCII translation.

The function, ConvertIEEEToFloat(src,dst), produces the IBM floating point needed for SEGY exchange format, and is used by my C program bcnv.c. The function, ConvertFloatToIEEE(src,dst), is used to produce IEEE from floating points read from a SEGY file. Because IBM main frames are big endian, and Linux PC's are little endian, some byte swapping became necessary.



Subsections