GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
port_init.c File Reference

Vector library - portability (lower level functions) More...

#include <stdio.h>
#include <sys/types.h>
#include <grass/vector.h>
#include <grass/glocale.h>
Include dependency graph for port_init.c:

Go to the source code of this file.

Macros

#define TEST_PATTERN   1.3333
 
#define LONG_LONG_TEST   0x0102030405060708LL
 
#define LONG_TEST   0x01020304
 
#define INT_TEST   0x01020304
 
#define SHORT_TEST   0x0102
 

Functions

void port_init (void)
 Initialize Port_info structures. More...
 

Variables

off_t u_o
 
int nat_dbl = sizeof(double)
 
int nat_flt = sizeof(float)
 
int nat_off_t = sizeof(off_t)
 
int nat_lng = sizeof(long)
 
int nat_int = sizeof(int)
 
int nat_shrt = sizeof(short)
 
int dbl_order
 
int flt_order
 
int off_t_order
 
int lng_order
 
int int_order
 
int shrt_order
 
unsigned char dbl_cnvrt [sizeof(double)]
 
unsigned char flt_cnvrt [sizeof(float)]
 
unsigned char off_t_cnvrt [sizeof(off_t)]
 
unsigned char lng_cnvrt [sizeof(long)]
 
unsigned char int_cnvrt [sizeof(int)]
 
unsigned char shrt_cnvrt [sizeof(short)]
 

Detailed Description

Vector library - portability (lower level functions)

Lower level functions for reading/writing/manipulating vectors.

This code is a quick hack to allow the writing of portable binary data files. The approach is to take known values and compare them against the current machine's internal representation. A cross reference table is then built, and then all file reads and writes must go through these routines to correct the numbers if need be.

As long as the byte switching is symmetrical, the conversion routines will work both directions.

The integer test patterns are quite simple, and their choice was arbitrary, but the float and double valued were more critical.

I did not have a specification for IEEE to go by, so it is possible that I have missed something. My criteria were:

First, true IEEE numbers had to be chosen to avoid getting an FPE. Second, every byte in the test pattern had to be unique. And finally, the number had to not be sensitive to rounding by the specific hardware implementation.

By experimentation it was found that the number 1.3333 met all these criteria for both floats and doubles

See the discourse at the end of this file for more information

The 3.0 dig, and dig_plus files are inherently non-portable. This can be seen in moving files between a SUN 386i and other SUN machines. The recommended way to transport files was always to convert to ASCII (b.a.vect) and copy the ASCII files: dig_ascii and dig_att to the destination machine.

The problem lies in the way that different architectures internally represent data. If a number is internally store as 0x01020304 on a 680x0 family machine, the same number will be stored as 0x04030201 on an 80386 class machine.

The CERL port of GRASS to the Compaq 386 already has code to deal with this incompatibility. This code converts all files that are written out to conform to the 680x0 standard. These binary files can then be shared between machines without conversion. This code is designed to work with the majority of computers in use today that fit the following requirements: byte == 8 bits int == 4 bytes long == 4 bytes double == IEEE standard 64 bit float == IEEE standard 32 bit

bytes can be swapped around in any reasonable way, but bits within each byte must be maintained in normal high to low ordering: 76543210 is this a problem?

If this ability is desired on a SUN 386i, for example, you simply define the compiler flag CERL_PORTABLE in the src/CMD/makehead file and recompile all of the mapdev programs. needs update, makehead/mapdev no longer exist

Binary DLG files are NOT supported by this code, and will continue to be non-portable between different architectures. applies to the files coor/topo/cidx, needs testing

(C) 2001-2009 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL, probably Dave Gerdes
Update to GRASS 5.7 Radim Blazek

Definition in file port_init.c.

Macro Definition Documentation

◆ INT_TEST

#define INT_TEST   0x01020304

Definition at line 89 of file port_init.c.

◆ LONG_LONG_TEST

#define LONG_LONG_TEST   0x0102030405060708LL

Definition at line 86 of file port_init.c.

Referenced by port_init().

◆ LONG_TEST

#define LONG_TEST   0x01020304

Definition at line 88 of file port_init.c.

Referenced by port_init().

◆ SHORT_TEST

#define SHORT_TEST   0x0102

Definition at line 90 of file port_init.c.

◆ TEST_PATTERN

#define TEST_PATTERN   1.3333

Definition at line 84 of file port_init.c.

Function Documentation

◆ port_init()

void port_init ( void  )

Variable Documentation

◆ dbl_cnvrt

unsigned char dbl_cnvrt[sizeof(double)]

Definition at line 124 of file port_init.c.

Referenced by dig_init_portable().

◆ dbl_order

int dbl_order

Definition at line 117 of file port_init.c.

Referenced by dig__byte_order_out(), dig_init_portable(), and port_init().

◆ flt_cnvrt

unsigned char flt_cnvrt[sizeof(float)]

Definition at line 125 of file port_init.c.

Referenced by dig_init_portable().

◆ flt_order

int flt_order

Definition at line 118 of file port_init.c.

Referenced by dig_init_portable().

◆ int_cnvrt

unsigned char int_cnvrt[sizeof(int)]

Definition at line 128 of file port_init.c.

Referenced by dig_init_portable().

◆ int_order

int int_order

Definition at line 121 of file port_init.c.

Referenced by dig_init_portable().

◆ lng_cnvrt

unsigned char lng_cnvrt[sizeof(long)]

Definition at line 127 of file port_init.c.

Referenced by dig_init_portable().

◆ lng_order

int lng_order

Definition at line 120 of file port_init.c.

Referenced by dig_init_portable().

◆ nat_dbl

int nat_dbl = sizeof(double)

Definition at line 110 of file port_init.c.

Referenced by port_init().

◆ nat_flt

int nat_flt = sizeof(float)

Definition at line 111 of file port_init.c.

Referenced by port_init().

◆ nat_int

int nat_int = sizeof(int)

Definition at line 114 of file port_init.c.

Referenced by dig__fread_port_I(), dig__fwrite_port_I(), and port_init().

◆ nat_lng

int nat_lng = sizeof(long)

Definition at line 113 of file port_init.c.

Referenced by dig__fread_port_L(), dig__fwrite_port_L(), and port_init().

◆ nat_off_t

int nat_off_t = sizeof(off_t)

Definition at line 112 of file port_init.c.

Referenced by dig__fread_port_O(), dig__fwrite_port_O(), dig_init_portable(), and port_init().

◆ nat_shrt

int nat_shrt = sizeof(short)

Definition at line 115 of file port_init.c.

Referenced by dig__fread_port_S(), dig__fwrite_port_S(), and port_init().

◆ off_t_cnvrt

unsigned char off_t_cnvrt[sizeof(off_t)]

Definition at line 126 of file port_init.c.

Referenced by dig_init_portable().

◆ off_t_order

int off_t_order

Definition at line 119 of file port_init.c.

Referenced by dig_init_portable().

◆ shrt_cnvrt

unsigned char shrt_cnvrt[sizeof(short)]

Definition at line 129 of file port_init.c.

Referenced by dig_init_portable().

◆ shrt_order

int shrt_order

Definition at line 122 of file port_init.c.

Referenced by dig_init_portable().

◆ u_o

off_t u_o

Definition at line 94 of file port_init.c.

Referenced by port_init().