int read_header( char *filename, header *hdr)
The functions searches for a valid header file in the following manner:
filename is an ANALYZE header.
filename is a VAPET file.
filename is a XPRIME file.
filename.hdr is an ANALYZE header.
filename minus extention + .hdr
is an ANALYZE header.
filename.Z is a compressed ANALYZE header.
filename.Z is a compressed VAPET file.
filename.Z is a compressed XPRIME file.
filename.gz is a gzipped ANALYZE header.
filename.gz is a gzipped VAPET file.
filename.gz is a gzipped XPRIME file.
filename.hdr.gz is a gzipped ANALYZE header.
filename.hdr.Z is a compressed ANALYZE header.
filename minus extention + .hdr.gz
is a gzipped ANALYZE header.
filename minus extention + .hdr.Z
is a compressed ANALYZE header.
I.e. the command
read_header("myfile.dat", hdr);
looks for an ANALYZE header in
Header file Allowed (& expected) data file ------------------------------------------------------------- myfile.myhdr myfile.img myfile.dat.hdr myfile.dat.img[.gz|.Z] myfile.hdr myfile.img[.gz|.Z] myfile.hdr.gz myfile.img[.gz|.Z] myfile.hdr.Z myfile.img[.gz|.Z] myfile.myhdr.gz myfile.dat.img[.gz|.Z] myfile.dat.hdr.gz myfile.dat.img[.gz|.Z] myfile.dat.Z myfile.dat.img[.gz|.Z] myfile.dat.hdr.Z myfile.dat.img[.gz|.Z]and for a VAPET, then XPRIME file in
VAPET File ------------------ myfile.dat myfile.dat.Z myfile.dat.gzThe expected data file name is stored in
hdr->filename2.
The CPU is checked for little/big endian architecture, and the fields are accordingly reversed, unless static auto_convert is set to 0 (not default)
The struct *hdr should be allocated using new_header() before calling read_header().
The function is capable of reading both XPRIME, VAPET and ANALZYZE files and automatically detects which file format the file is.
All entries in the header struct are initialized.
typedef struct {
int rank; // Dimension of data 1 <= rank <= MAXRANK
int size[MAX_RANK]; // Image dimension
float cmpix[MAX_RANK]; // Voxel dimension
enum data_type type; // n.o. data bytes pr. voxel 1,2,4 or 8
description *descr; // A chain of image description strings.
int filetype; // A code for file type (defines: ANALYZE
// XPRIME or VAPET)
char filename1[MAX_STR],
filename2[MAX_STR]; // Filenames (readonly) for
// header & data files
} header;
header *hdr;
hdr = new_header();
read_header("myvolume.vol", hdr);
// Now the header has been read!
free_header(hdr);
1.01 20 feb 97 Removed bug when reading analyze .bin/.hdr pair referenced by the .bin file 1.02 march 5 Corrected filename2 return value for analyze, when reading xx.hdr/xx.img specified by "xx." only. 1.03 23/10/97 Reads XPRIME files