The file HEIGHTS2.DAT contains spot heights at 500 metre intervals over the bulk of the UK. Heights are stored using one byte per interval to keep the file within a manageable size and reduce processing time.
The UK is first divided into 100km high strips based on the NGR northings, the length of each strip is an integer multiple of 100km sufficient to cross the country country completely. The first 100 km square (the NGR letter square) that contains any land becomes the starting point for each horizontal strip whose data length then depends on the width of Britain at that Northing. Therefore the 100km high strips start at arbitrary points in the data file, and at arbitrary 100km Eastings on the map. The starting points in the data file are, however, all multiples of 40000 (this being the total number of 0.5km grid points in a 100km square).
The starting points need to be known in adavnce, and in each program this information appears as a data statement which is subsequently read into an array and accessed by the 100km northing of any subsequently specified location.
Each 100 km strip is then broken down into 10 km squares which are then further broken down into 400 individual data points. The order of the 10 km squares, and their subdivision, is not straightforward. Going through the data file, the 10 km squares start at the bottom left of the 100 km strips and 10 sucessive squares are built up vertically from the bottom to form a strip 10 km wide by 100 km high. This is repeated until the easternmost limit for this strip is reached is reached.
Each 10km square consists of a raster scan of the 0.5km points starting at the TOP of the square, plotting 20 points across and then moving down one point to complete the 400 point square.
For any arbitrary NGR (Easting and Northing pair referred to as E and N and measured in km, floating point to allow 0.5) the following stages are required to find the location in the database where its associated height is stored :-
1) Generate the 100km northing
N100 = N DIV 100 and use this to look up the file offset, FILEBREAK
(in bytes), and 100km
Easting, Estart
(in km), of the start point of the strip. Note that in the data statements
of all the included
programs, the FILEBREAK
values are stored in kBytes and Estart in units of 100 km. These
have to be multiplied by
1000 and 100 respectively
to obtain the values as used below.
2) Find the 10 km square from
N10 = (N DIV 10) MOD 10 and E10 = (E DIV 10) MOD 10.
3) Find the spot data pointers from
Npoint = 19 - (N
DIV 0.5) MOD 20 nb. 19 - because the data is stored
downwards.
Epoint = (E DIV
0.5) MOD 20
The file pointer is then given by :
POINTER = FILEBREAK + (E - ESTART) * 40000 + (N10 + 10 * E10) * 400 + 20 * Npoint + Epoint
Access the byte at this position to obtain K (0 to 255)
Then Height = K ^ 1.32
This seemingly strange compressed format
was chosen in order to map heights from zero to 1500m into the range 0
to 255. Whilst maintaining the accuracy of the original database
based on multiples of 5 feet (American and Olde English units) at low elevations,
the resolution degrades to around 7m at the highest points. The RMS
deviation from the original database is 1.7m
To avoid excessive computational workload
with floating point maths, (not a problem if a maths coprocessor is available)
the colour maps are generated based on the compressed height, and this
is only expanded where needed to generate actual spot heights.