Prev Up Next Index
Go backward to 9.4.4 Reading the Binary File
Go up to 9.4 Creating a Binary Archive
Go forward to 9.4.6 Converting to Binary Long

9.4.5 Conversion to a More Portable Binary

In this example, you will use newform to reformat the latitude and longitude values in the ASCII data file latlon.dat into binary longs in the binary file latlon2.bin. The input and output data formats are described in latlon2.fmt.

This is what's in latlon2.fmt:

/ This is the format description file for data files latlon.dat
/ and latlon2.bin. Each record in both files contains two fields, 
/ latitude and longitude.

ASCII_data "ASCII format"
latitude 1 10 double 6
longitude 12 22 double 6

binary_data "binary format"
latitude 1 4 long 6
longitude 5 8 long 6

The ASCII and binary variables both have the same names. The ASCII variable latitude occupies positions 1-10 and longitude occupies positions 12-22. The ASCII variables are defined to be of type double. The binary variables occupy four bytes each (positions 1-4 and 5-8) and are of type long. The precision for all is 6.


Tom Sgouros and James Gallagher, 2006-02-12

Prev Up Next