Namespaces | Macros | Typedefs | Enumerations | Functions
xdrfile.h File Reference

Interface to read/write portabile binary files using XDR. More...

Namespaces

 PLMD
 
 PLMD::xdrfile
 

Macros

#define _XDRFILE_H_
 
#define DIM   3
 

Typedefs

typedef float PLMD::xdrfile::matrix[DIM][DIM]
 
typedef int PLMD::xdrfile::mybool
 
typedef float PLMD::xdrfile::rvec[DIM]
 
typedef struct XDRFILE PLMD::xdrfile::XDRFILE
 Abstract datatype for an portable binary file handle. More...
 

Enumerations

enum  {
  PLMD::xdrfile::exdrOK, PLMD::xdrfile::exdrHEADER, PLMD::xdrfile::exdrSTRING, PLMD::xdrfile::exdrDOUBLE,
  PLMD::xdrfile::exdrINT, PLMD::xdrfile::exdrFLOAT, PLMD::xdrfile::exdrUINT, PLMD::xdrfile::exdr3DX,
  PLMD::xdrfile::exdrCLOSE, PLMD::xdrfile::exdrMAGIC, PLMD::xdrfile::exdrNOMEM, PLMD::xdrfile::exdrENDOFFILE,
  PLMD::xdrfile::exdrFILENOTFOUND, PLMD::xdrfile::exdrNR
}
 

Functions

int PLMD::xdrfile::xdrfile_close (XDRFILE *xfp)
 Close a previously opened portable binary file, just like fclose() More...
 
int PLMD::xdrfile::xdrfile_compress_coord_double (double *ptr, int ncoord, double precision, XDRFILE *xfp)
 Compress coordiates in a double array to XDR file. More...
 
int PLMD::xdrfile::xdrfile_compress_coord_float (float *ptr, int ncoord, float precision, XDRFILE *xfp)
 Compress coordiates in a float array to XDR file. More...
 
int PLMD::xdrfile::xdrfile_decompress_coord_double (double *ptr, int *ncoord, double *precision, XDRFILE *xfp)
 Decompress coordiates from XDR file to array of doubles. More...
 
int PLMD::xdrfile::xdrfile_decompress_coord_float (float *ptr, int *ncoord, float *precision, XDRFILE *xfp)
 Decompress coordiates from XDR file to array of floats. More...
 
XDRFILE * PLMD::xdrfile::xdrfile_open (const char *path, const char *mode)
 Open a portable binary file, just like fopen() More...
 
int PLMD::xdrfile::xdrfile_read_char (char *ptr, int ndata, XDRFILE *xfp)
 Read one or more char type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_double (double *ptr, int ndata, XDRFILE *xfp)
 Read one or more double type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_float (float *ptr, int ndata, XDRFILE *xfp)
 Read one or more float type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_int (int *ptr, int ndata, XDRFILE *xfp)
 Read one or more integer type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_opaque (char *ptr, int nbytes, XDRFILE *xfp)
 Read raw bytes from file (unknown datatype) More...
 
int PLMD::xdrfile::xdrfile_read_short (short *ptr, int ndata, XDRFILE *xfp)
 Read one or more short type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_string (char *ptr, int maxlen, XDRFILE *xfp)
 Read a string (array of characters) More...
 
int PLMD::xdrfile::xdrfile_read_uchar (unsigned char *ptr, int ndata, XDRFILE *xfp)
 Read one or more unsigned char type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_uint (unsigned int *ptr, int ndata, XDRFILE *xfp)
 Read one or more unsigned integers type variable(s) More...
 
int PLMD::xdrfile::xdrfile_read_ushort (unsigned short *ptr, int ndata, XDRFILE *xfp)
 Read one or more unsigned short type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_char (char *ptr, int ndata, XDRFILE *xfp)
 Write one or more characters type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_double (double *ptr, int ndata, XDRFILE *xfp)
 Write one or more double type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_float (float *ptr, int ndata, XDRFILE *xfp)
 Write one or more float type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_int (int *ptr, int ndata, XDRFILE *xfp)
 Write one or more integer type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_opaque (char *ptr, int nbytes, XDRFILE *xfp)
 Write raw bytes to file (unknown datatype) More...
 
int PLMD::xdrfile::xdrfile_write_short (short *ptr, int ndata, XDRFILE *xfp)
 Write one or more short type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_string (char *ptr, XDRFILE *xfp)
 Write a string (array of characters) More...
 
int PLMD::xdrfile::xdrfile_write_uchar (unsigned char *ptr, int ndata, XDRFILE *xfp)
 Write one or more unsigned characters type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_uint (unsigned int *ptr, int ndata, XDRFILE *xfp)
 Write one or more unsigned integer type variable(s) More...
 
int PLMD::xdrfile::xdrfile_write_ushort (unsigned short *ptr, int ndata, XDRFILE *xfp)
 Write one or more unsigned short type variable(s) More...
 

Detailed Description

Interface to read/write portabile binary files using XDR.

This file provides an interface to read & write portably binary files, using XDR - the external data representation standard defined in RFC 1014.

There are several advantages to the XDR approach:

  1. It is portable. And not just portable between big/small integer endian, but truly portable if you have system XDR routines. For example:
    • It doesn't matter if the character representation is ASCII or EBCDIC.
    • Some systems are small endian but use big endian order of the two dword in a double precision floating-point variable. The system XDR libraries will read/write this correctly.
    • Some systems (VAX...) don't use IEEE floating point. Their system XDR libraries will convert to/from this automatically.
  2. XDR libraries are required for NFS and lots of other network functions. This means there isn't a single Unix-like system that doesn't have them.
  3. There is NO extra metadata whatsoever, and we write plain XDR files. If you write a float, it will take exactly 4 bytes in the file. (All basic datatypes are 4 bytes, double fp 8 bytes).
  4. You can read/write the files by calling the system XDR routines directly too - you don't have to use the routines defined in this file.
  5. It is no problem if your system doesn't have XDR libraries (MS Windows). We have written our own versions of the necessary routines that work if your system uses ASCII for strings and IEEE floating-point. All types of byte and dword endian for integer and floating-point are supported.
  6. You can use these routines for any type of data, but since we designed them for Gromacs we also provide a special routine to write coordinates with (adjustable) lossy compression. The default precision will give you three decimals guaranteed accuracy, and reduces the filesize to 1/10th of normal binary data.

We do not support getting or setting positions in XDR files, since it can break in horrible ways for large (64-bit) files, resulting in silent data corruption. Note that it works great to open/read/write 64-bit files if your system supports it; it is just the random access we cannot trust!

We also provide wrapper routines so this module can be used from FORTRAN - see the file xdrfile_fortran.txt in the Gromacs distribution for documentation on the FORTRAN interface!

Macro Definition Documentation

◆ _XDRFILE_H_

#define _XDRFILE_H_

◆ DIM

#define DIM   3