Procedures Details <Prev Next>

Binary LineList Format

When a line list is produced with PrintLevel = Binary the resulting binary format is designed to be quick to read by external programs. (See the information about the Command Line Version for a common way to do this) It has the same content as the other linelist formats, and consists of a sequence of lines/records:

The line/record is a simple sequence of fields, with each field headed by a byte identifying the type:

Header Byte
Field Contents
< 200
String field; header byte gives length. A one character string with a single character 10 (new line character) implies end of line/record.
200+sizeof(int)
(Normally 204)
Integer. Note that quantum numbers are represented as integers with twice the true value.
200+sizeof(double)
(Normally 224)
Floating point value

The integer and floating point values are in the format naive to the platform, so the binary files are not necessarily transportable between machines. However all current versions (except the obsolete PowerPC version) produce compatible files.

A simple C program that dumps the binary file as text is shown below:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _Windows
#include <io.h>
#else
#include <unistd.h>
#define O_BINARY 0
#endif
#include <fcntl.h>
#include <stdlib.h>

int main(int argc, char*argv[])
{
int fd = open(argv[1],O_RDONLY | O_BINARY); /* Open file */
struct stat sbuf;
unsigned char *buffer, *p;
fstat(fd,&sbuf); /* Find it's size */
buffer = malloc(sbuf.st_size);
read(fd, buffer, sbuf.st_size); /* Read it into memory */
p = buffer;
while ( p < buffer + sbuf.st_size ) { /* Loop over entries */
if ( (*p > 0) && (*p < 200) ) { /* Is it a string? */
if ( (*p == 1) && (p[1] == 10) )
printf("\n"); /* End of line marker */
else {
fwrite(p+1, 1, *p, stdout); /* Normal string */
printf(" ");
}
p += *p + 1; /* Skip string */
} else if ( *p < 216 ) {
printf("%d ",*(int *)(p+1)); /* Integer */
p += 1 + sizeof(int);
} else if ( *p < 232 ) {
printf("%g ",*(double *)(p+1)); /* Floating point value */
p += 1 + sizeof(double);
} else {
printf("\nUnknown Field:%d\n",*p);
return 1;
}
}
return 0;
}