next up previous
Next: open_read() Up: Brain Volume I/O Handling Previous: read_volume()

read_header()  

Read a volume's header



Synopsis


int
read_header( char *filename, header *hdr)


Description
This function first determines the file format and secondly reads in the file header information to the header struct. Both ANALYZE, XPRIME and VAPET formats are supported. The filename fields of the header struct are initialized, although for ANALYZE files, the data file name (filename2) is only a best guess as only the header file is actually read.

The functions searches for a valid header file in the following manner:

1.
Check if filename is an ANALYZE header.
2.
Check if filename is a VAPET file.
3.
Check if filename is a XPRIME file.
Stop now with an error if the file was found but did not contain a valid file format.
4.
Check if filename.hdr is an ANALYZE header.
5.
Check if filename minus extention + .hdr is an ANALYZE header.
6.
Check if filename.Z is a compressed ANALYZE header.
7.
Check if filename.Z is a compressed VAPET file.
8.
Check if filename.Z is a compressed XPRIME file.
9.
Check if filename.gz is a gzipped ANALYZE header.
10.
Check if filename.gz is a gzipped VAPET file.
11.
Check if filename.gz is a gzipped XPRIME file.
12.
Check if filename.hdr.gz is a gzipped ANALYZE header.
13.
Check if filename.hdr.Z is a compressed ANALYZE header.
14.
Check if filename minus extention + .hdr.gz is a gzipped ANALYZE header.
15.
Check if filename minus extention + .hdr.Z is a compressed ANALYZE header.
Report error if no valid file is found.

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.gz
The 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;

Usage

  header *hdr;
  hdr = new_header();
  read_header("myvolume.vol", hdr);

  // Now the header has been read!

  free_header(hdr);

Revision


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


Program listing





next up previous
Next: open_read() Up: Brain Volume I/O Handling Previous: read_volume()
Ulrik Kjems
6/3/1998