ncigt-fil
Functions
File I/O

Functions to read and write image and data files. More...

Functions

void copy_data_obj (DATA_OBJ *dest, DATA_OBJ *src)
 
void display_params (SCAN_INFO hdr)
 
void dump_out (char *name, int nc_out, int nf_out, int nz_out, int ny_out, int nx_out, short temp, COMPLEX *bin)
 
void free_data_obj (DATA_OBJ *data_obj)
 
void init_data_obj (DATA_OBJ *data)
 
int read_nd_data (char *filename, char **ptr, char *frmt, int *size, int *szI)
 
int read_nd_data2 (char *filename, DATA_OBJ *dat)
 
int write_nd_data (char *filename, void *bin, char *frmt, int size, int *sz)
 
int write_nd_data2 (char *filename, DATA_OBJ *dat)
 

Detailed Description

Functions to read and write image and data files.

The library provides a number of functions to pass data back and forth between C and Matlab.

One method is the .nd data format, which is a straight forward way to save real or complex multi-dimensional data. The .nd file format is:

Version 2 allows meta-data describing the data to also be stored.

Alternatively, one can use the dump_out function to write memory contents to disk. This format writes the raw binary data in one file, and then writes an associated text file describing the format of the data.

Function Documentation

void copy_data_obj ( DATA_OBJ *  dest,
DATA_OBJ *  src 
)

clone a copy of a data object

if dest is a clean object, then the memory will be allocated.

if not, (i.e. dest has pre-allocated data memory) the copy will proceed if (dest->init >= src->init).

void display_params ( SCAN_INFO  hdr)

Display some of the scan parameters contained in the SCAN_INFO header

void dump_out ( char *  name,
int  nc_out,
int  nf_out,
int  nz_out,
int  ny_out,
int  nx_out,
short  temp,
COMPLEX *  bin 
)

Write data to file, for debugging. The fuection output two files, one file is a binary format with the data. The second, with suffix '_dims' records the data structure (number of coils, frames, Nz, Ny, Nx, etc.). Data can be read in to Matlab using read_dump .

Parameters
nameoutput filename
nc_outnumber of coils
nf_outnumber of temporal frames
nz_outnumber of slices
ny_outsize along phase-encode dimension
nx_outsize along read-out dimension
temp(unused)
binthe data to write to disk
void free_data_obj ( DATA_OBJ *  data_obj)

release all allocated memory associated with the input data object.

  • sets the data_obj->type to NULL
  • frees the data_obj->data
  • clears the data_obj->init value (to '0')
  • frees the data_obj->metadata, if non-NULL
void init_data_obj ( DATA_OBJ *  data)

initialize the data points and array values for an empty data object

int read_nd_data ( char *  filename,
char **  ptr,
char *  frmt,
int *  size,
int *  szI 
)

import/read an N-D data array file (output by savend)

Usage:

COMPLEX *data;
char *tmpp;
int n, cnt, sz[4];
char dtype[5] = {0,0,0,0,0};
read_nd_data( "inputdata.nd", &tmpp, dtype, &n, sz );
if ( strcmp(dtype,"dblc")==0 ) {
data = (COMPLEX *) tmpp;
}
printf("read_nd_data read an %s %d-dimensional array of size ",dtype,n);
for ( cnt=0; cnt<n; cnt++ ) { printf(" %d",sz[cnt]);} printf(".\n");
Returns
Returns a 0 if read is successful, a non-zero value otherwise. Error messages are reported to STDERR.
Parameters
filenameOutput filename.
ptrpointer to the data buffer to read data to.
frmtpointer the file format char field.
sizepointer the returned number of dimensions in the data.
szIpointer to an array that holds the number of elements in dimension.
int read_nd_data2 ( char *  filename,
DATA_OBJ *  dat 
)

import/read an N-D data array file (output by savend)

Usage:

DATA_OBJ img;
init_data_obj( &img );
read_nd_data2( "inputdata.nd", &img );
printf("read_nd_data2 read an %s %d-dimensional array of size ",dtype,n);
for ( cnt=0; cnt<n; cnt++ ) { printf(" %d",sz[cnt]);} printf(".\n");
Returns
Returns a 0 if read is successful, a non-zero value otherwise. Error messages are reported to STDERR.

This version (version 2) can read meta-data stored at the end of the file.

Parameters
filenameOutput filename.
datpointer to the data object to populate.
int write_nd_data ( char *  filename,
void *  bin,
char *  frmt,
int  size,
int *  sz 
)

write an N-D data array to disk suitable for readnd

Usage:

int sz[4];
COMPLEX *ImageData;
sz[0] = (int)hdr.xres;
sz[1] = (int)hdr.yres;
sz[2] = (int)hdr.CinePhases;
sz[3] = (int)hdr.Ncoils;
write_nd_data( "I.dat", ImageData, "dblc", 4, sz );
Returns

Returns a 0 if read is successful, a non-zero value otherwise. Error messages are reported to STDERR.

Parameters
filenameinput data filename
bina pointer to the output data
frmta format descriptor of the data type: 'char', 'intr', 'intc', 'fltr', 'fltc', 'dblr', or 'dblc'.
sizethe number of dimensions spanned by the data
szthe number of elements in each dimension
int write_nd_data2 ( char *  filename,
DATA_OBJ *  dat 
)

export/write an N-D data array file (to be read by readnd) along with any associated meta-data

Usage:

DATA_OBJ img;
init_data_obj( &img );
// some processing, saving the data to img.data
write_nd_data2( "img_data.nd", &img );

This version (version 2) will append meta-data stored in the img.metadata field of the object

Parameters
filenameOutput filename.
datpointer to the data object to write.