Prev Up Next Index
Go backward to 9.4.5 Conversion to a More Portable Binary
Go up to 9.4 Creating a Binary Archive
Go forward to 9.4.7 Reading the Binary File

9.4.6 Converting to Binary Long

In the previous example, both the ASCII and binary variables were defined to be doubles. Binary longs, which are 4-byte integers, may be more portable across different platforms than binary doubles or floats.

To convert the ASCII data in latlon.dat to binary longs:

  1. Change to the directory that contains the FreeForm ND example files.
  2. Enter the following command:
    newform latlon.dat -f latlon2.fmt -o latlon2.bin 
    

It creates the binary archive file latlon2.bin with the 20 latitude and longitude values in latlon.dat stored as binary longs.

This example duplicates one in chapter 2. If you completed that example, an error message will indicate that latlon2.bin exists. You can rename, move, or delete the existing file.

The size of the archive file latlon2.bin is about 1/3 the size of latlon.dat. Also, the data do not have to be converted to machine representation by applications. The main tradeoff in achieving savings in space and access time is that although binary longs are more portable than binary doubles or floats, any binary representation is less portable than ASCII.

CAUTION: There may be a loss of precision when input data of

type double is converted to long.


Tom Sgouros and James Gallagher, 2006-02-12

Prev Up Next