Main Page   Compound List   File List   Compound Members   File Members  

mfitsio.c File Reference

#include <string.h>
#include <stdio.h>
#include <fitsio.h>
#include <malloc.h>
#include <unistd.h>
#include "mex.h"
#include "matrix.h"
#include "mfitsio.h"

Go to the source code of this file.

Functions

void mfitsio_free_record (mfitsio_record *record)
 Deallocates a mfitsio_record structure. More...

void mfitsio_free_header (mfitsio_header *header)
 Deallocates a mfitsio_header structure. More...

void mfitsio_free_info (mfitsio_info *info)
 Deallocates a mfitsio_info structure. More...

mfitsio_recordmfitsio_parse_card (const char *cardtext)
 Parses a fits header "card". More...

mfitsio_headermfitsio_read_header (const char *filename)
 Reads a header from a fits file. More...

mxArray * mfitsio_adapt_frecord (const mfitsio_record *record)
 Adapts a mfitsio_record structure into a MATLAB variable. More...

mxArray * mfitsio_adapt_fheader (const mfitsio_header *header)
 Adapts a mfitsio_header structure into a MATLAB struct array. More...

mfitsio_infomfitsio_read_info (const char *filename)
 The dimensions and bitpix are acquired from the FITS file header. More...

mxArray * mfitsio_read_image (const char *filename, const mfitsio_info *info)
 Read a FITS image and store the result in a MATLAB array. More...

mxArray * mfitsio_read_image_impl (const char *filename, const mfitsio_info *info, long *fpixels, long *lpixels, long *lnaxes, long *inc)
 Read a FITS image and store the result in a MATLAB array. More...

mxArray * mfitsio_read_image_execute (const mfitsio_info *info, int *diff, fitsfile *fptr, int group, int naxis, long *lnaxes, long *fpixel, long *lpixel, long *inc, int *anynul, int *status)
 Return the resultant image. More...

void mfitsio_write_image (const char *filename, const mxArray *header, mxArray *img)
 Write a MATLAB array/image to a FITS file. More...

void mfitsio_write_image_impl (const char *filename, const mxArray *header, mxArray *img, long *fpixels, long *lpixels, long *lnaxes, long *inc, mfitsio_info *info)
 Write a MATLAB array/image to a FITS file. More...

void mfitsio_write_image_execute (fitsfile *file, mxArray *img, long group, long naxis, long *naxes, long *fpixel, long *lpixel, int *status)
 Close the FITS file. More...

void mfitsio_delete_keyword (const char *filename, const char *keyword)
 Delete a record from a header in a FITS file. More...

void mfitsio_write_header (const char *filename, const mxArray *header)
 Write header information stored in a MATLAB struct array to a FITS file. More...

void mfitsio_write_info (fitsfile *fptr, const mfitsio_info *info)
 Write bitpix and dimension information to a FITS header. More...

mfitsio_infomfitsio_calc_info (const mxArray *img)
 Calculate bitpix and dimension information from a MATLAB image. More...

int mfitsio_is_scalar (const mxArray *array)
 Determine whether the MATLAB array is singleton. More...

int mfitsio_forbidden (const char *s)
 This function determines whether modifying a certain header keyword is allowed. More...

int mfitsio_ignore_card (const char *s)
 This function determines whether modifying a certain header keyword is allowed. More...

mxArray * mfitsio_get_mfield (const mxArray *array, int index, const char *field_name)
 A wrapper function for mxGetField. More...

double mfitsio_get_mscalar (const mxArray *array)
 A wrapper function for mxGetScalar. More...

void mfitsio_check_coordinate (const mxArray *crd1, const mxArray *crd2, const int naxis, const int *naxes)
 Checks for validity of starting and ending pixel coordinates. More...

void mfitsio_check_size_info (const mxArray *size_unit)
 Checks for validity of size information. More...

long * mfitsio_convert_dbl2long (const double *dbl, const int size)
 Converts a double array to a long array. More...

long * mfitsio_convert_int2long (const int *in, const int size)
 Converts an int array to a long array. More...

long * mfitsio_create_ones_vector (const int size)
 Creates a one vector of a particular size. More...

int * mfitsio_get_region_size (const long *crd1, const long *crd2, const int naxis)
 Computes the size of a region defined by two coordinates. More...

mxArray * mfitsio_get_lpixels (const mxArray *spixels, const mxArray *img, int naxis)
 Computes the ending pixel value based on the starting pixel. More...

char * mfitsio_logical_m2f (const mxArray *img)


Function Documentation

mxArray* mfitsio_adapt_fheader const mfitsio_header   header
 

Adapts a mfitsio_header structure into a MATLAB struct array.

Parameters:
header  The header to adapt.
Returns:
A MATLAB struct object corresponding to the parsed mfitsio_header.

Definition at line 445 of file mfitsio.c.

References mfitsio_record::key, mfitsio_header::length, mfitsio_adapt_frecord, MFITSIO_CALLOC, MFITSIO_ERR, MFITSIO_MALLOC, and mfitsio_header::records.

mxArray* mfitsio_adapt_frecord const mfitsio_record   record
 

Adapts a mfitsio_record structure into a MATLAB variable.

The syntax of the text of the value determines the type of the MATLAB variable.

Parameters:
record  The record to adapt.
Returns:
A MATLAB variable.

Definition at line 328 of file mfitsio.c.

References MFITSIO_MALLOC, and mfitsio_record::value.

Referenced by mfitsio_adapt_fheader.

mfitsio_info* mfitsio_calc_info const mxArray *    img
 

Calculate bitpix and dimension information from a MATLAB image.

Parameters:
img  The MATLAB array where the image is stored.
Returns:
A mfitsio_info struct containing the bitpix and dimension information.

Definition at line 1190 of file mfitsio.c.

References mfitsio_info::bitpix, mfitsio_info::check, MFITSIO_ERR, MFITSIO_MALLOC, MFITSIO_PRINTF, mfitsio_info::naxes, and mfitsio_info::naxis.

void mfitsio_check_coordinate const mxArray *    crd1,
const mxArray *    crd2,
const int    naxis,
const int *    naxes
 

Checks for validity of starting and ending pixel coordinates.

In particular, pixels must be within the range defined by the NAXES keywords and a region along a particular axis profile must not begin at the ending coordinate.

Parameters:
crd1  The starting coordinate.
crd2  The ending coordinate.
naxis  The number of axes.
naxes  The size of each axis.

Definition at line 1380 of file mfitsio.c.

References MFITSIO_ERR, and MFITSIO_PRINTF.

void mfitsio_check_size_info const mxArray *    size_unit
 

Checks for validity of size information.

The NAXIS and NAXES information must be non-negative.

Parameters:
size_unit  The size unit as a row vector.

Definition at line 1456 of file mfitsio.c.

References MFITSIO_ERR, and MFITSIO_PRINTF.

long* mfitsio_convert_dbl2long const double *    dbl,
const int    size
 

Converts a double array to a long array.

Parameters:
dbl  The array to convert.
size  The size of the array to convert.
Returns:
The converted array.

Definition at line 1493 of file mfitsio.c.

References MFITSIO_MALLOC.

long* mfitsio_convert_int2long const int *    in,
const int    size
 

Converts an int array to a long array.

Parameters:
in  The array to convert.
size  The size of the array to convert.
Returns:
The converted array.

Definition at line 1511 of file mfitsio.c.

References MFITSIO_MALLOC.

long* mfitsio_create_ones_vector const int    size
 

Creates a one vector of a particular size.

Parameters:
size  The size of the ones array to create.
Returns:
The converted array.

Definition at line 1528 of file mfitsio.c.

References MFITSIO_MALLOC.

void mfitsio_delete_keyword const char *    filename,
const char *    keyword
 

Delete a record from a header in a FITS file.

Parameters:
filename  The filename of the FITS file.
keyword  The keyword of the record to delete.

Definition at line 905 of file mfitsio.c.

References MFITSIO_ERR, mfitsio_forbidden, MFITSIO_PRINTF, and MFITSIO_READWRITE.

int mfitsio_forbidden const char *    s
 

This function determines whether modifying a certain header keyword is allowed.

The reason for checking is that we do not want users modifying NAXIS, BITPIX, and other important headers as they can be calculated from a MATLAB image. Thus, the situation where the dimension and bitpix keywords differ from the stored image is avoided.

Parameters:
array  The MATLAB variable to check for singleton dimensions.
Returns:
True is the array is a scalar.

Definition at line 1297 of file mfitsio.c.

void mfitsio_free_header mfitsio_header   header
 

Deallocates a mfitsio_header structure.

Parameters:
header  The record you wish to deallocate.

Definition at line 67 of file mfitsio.c.

References mfitsio_header::length, MFITSIO_FREE, mfitsio_free_record, and mfitsio_header::records.

void mfitsio_free_info mfitsio_info   info
 

Deallocates a mfitsio_info structure.

Parameters:
info  The info you wish to deallocate.

Definition at line 84 of file mfitsio.c.

References MFITSIO_FREE, and mfitsio_info::naxes.

void mfitsio_free_record mfitsio_record   record
 

Deallocates a mfitsio_record structure.

Parameters:
record  The record you wish to deallocate.

Definition at line 54 of file mfitsio.c.

References mfitsio_record::key, MFITSIO_FREE, and mfitsio_record::value.

mxArray* mfitsio_get_lpixels const mxArray *    spixels,
const mxArray *    img,
int    naxis
 

Computes the ending pixel value based on the starting pixel.

Parameters:
spixels  The starting pixel.
img  The image.
naxis  The number of axes.
Returns:
The size of the region as an array.

Definition at line 1568 of file mfitsio.c.

mxArray* mfitsio_get_mfield const mxArray *    array,
int    index,
const char *    field_name
 

A wrapper function for mxGetField.

Whenever a field cannot be retrieved, an error is reported and execution aborts.

Parameters:
array  The MATLAB struct array.
index  The index for the record.
field_name  The key for the record.
Returns:
The value of the field requested.

Definition at line 1334 of file mfitsio.c.

References MFITSIO_ERR, and MFITSIO_PRINTF.

double mfitsio_get_mscalar const mxArray *    array
 

A wrapper function for mxGetScalar.

Whenever a scalar cannot be retrieved, zero is returned.

Parameters:
array  The MATLAB struct array.
index  The index for the record.
field_name  The key for the record.
Returns:
The numeric value as a double.

Definition at line 1364 of file mfitsio.c.

References mfitsio_get_mscalar.

int* mfitsio_get_region_size const long *    crd1,
const long *    crd2,
const int    naxis
 

Computes the size of a region defined by two coordinates.

Parameters:
crd1  The starting coordinate.
crd2  The ending coordinate.
naxis  The number of axes.
Returns:
The size of the region as an array.

Definition at line 1547 of file mfitsio.c.

References MFITSIO_MALLOC.

int mfitsio_ignore_card const char *    s
 

This function determines whether modifying a certain header keyword is allowed.

The reason for checking is that we do not want users modifying NAXIS, BITPIX, and other important headers as they can be calculated from a MATLAB image. Thus, the situation where the dimension and bitpix keywords differ from the stored image is avoided.

Parameters:
array  The MATLAB variable to check for singleton dimensions.
Returns:
True is the array is a scalar.

Definition at line 1316 of file mfitsio.c.

Referenced by mfitsio_parse_card.

int mfitsio_is_scalar const mxArray *    array
 

Determine whether the MATLAB array is singleton.

Parameters:
array  The MATLAB variable to check for singleton dimensions.
Returns:
True is the array is a scalar.

Definition at line 1260 of file mfitsio.c.

char* mfitsio_logical_m2f const mxArray *    img
 

Definition at line 1593 of file mfitsio.c.

References MFITSIO_MALLOC.

mfitsio_record* mfitsio_parse_card const char *    cardtext
 

Parses a fits header "card".

Comments are ignored. A mfitsio_record structure is returned. When this structure is no longer needed, it should be deallocated.

Parameters:
cardtext  The text of the fits header card.
Returns:
A mfitsio_record structure containing the key and value which was parsed from the card. NULL is returned if the field is to be ignored or if the card is a comment line.

Definition at line 104 of file mfitsio.c.

References mfitsio_record::key, mfitsio_ignore_card, MFITSIO_MALLOC, and mfitsio_record::value.

mfitsio_header* mfitsio_read_header const char *    filename
 

Reads a header from a fits file.

Before the result of this function can be used by MATLAB, the header must be adapted to a MATLAB struct array using mfitsio_adapt_fheader function.

Parameters:
filename  The filename of the fits file to read.
Returns:
A mfitsio_header structure acquired by reading the header in the fits file.

Definition at line 223 of file mfitsio.c.

References mfitsio_header::length, MFITSIO_ERR, MFITSIO_FREE, MFITSIO_MALLOC, mfitsio_parse_card, MFITSIO_PRINTF, MFITSIO_READONLY, and mfitsio_header::records.

mxArray* mfitsio_read_image const char *    filename,
const mfitsio_info   info
 

Read a FITS image and store the result in a MATLAB array.

Parameters:
filename  The filename of the FITS image.
info  The dimensions and bitpix of the image.
Returns:
A mfitsio_info struct containing the information.

Definition at line 572 of file mfitsio.c.

References MFITSIO_FREE, MFITSIO_MALLOC, mfitsio_read_image_impl, mfitsio_info::naxes, and mfitsio_info::naxis.

mxArray* mfitsio_read_image_execute const mfitsio_info   info,
int *    diff,
fitsfile *    fptr,
int    group,
int    naxis,
long *    lnaxes,
long *    fpixel,
long *    lpixel,
long *    inc,
int *    anynul,
int *    status
 

Return the resultant image.

Definition at line 646 of file mfitsio.c.

References mfitsio_info::bitpix, MFITSIO_ERR, MFITSIO_PRINTF, and mfitsio_info::naxis.

mxArray* mfitsio_read_image_impl const char *    filename,
const mfitsio_info   info,
long *    fpixels,
long *    lpixels,
long *    lnaxes,
long *    inc
 

Read a FITS image and store the result in a MATLAB array.

Parameters:
filename  The filename of the FITS image.
info  The dimensions and bitpix of the image.
Returns:
A mfitsio_info struct containing the information.

Definition at line 607 of file mfitsio.c.

References MFITSIO_ERR, MFITSIO_FREE, mfitsio_get_region_size, MFITSIO_PRINTF, mfitsio_read_image_execute, MFITSIO_READONLY, and mfitsio_info::naxis.

mfitsio_info* mfitsio_read_info const char *    filename
 

The dimensions and bitpix are acquired from the FITS file header.

Parameters:
filename  The filename of the FITS file.
Returns:
A mfitsio_info struct containing the information.

Definition at line 503 of file mfitsio.c.

References mfitsio_info::bitpix, MFITSIO_ERR, MFITSIO_FREE, MFITSIO_MALLOC, MFITSIO_PRINTF, MFITSIO_READONLY, mfitsio_info::naxes, and mfitsio_info::naxis.

void mfitsio_write_header const char *    filename,
const mxArray *    header
 

Write header information stored in a MATLAB struct array to a FITS file.

Parameters:
filename  The filename of the FITS file.
header  The MATLAB struct array containing the information.

Definition at line 951 of file mfitsio.c.

References MFITSIO_CALLOC, MFITSIO_ERR, mfitsio_forbidden, mfitsio_get_mscalar, mfitsio_is_scalar, MFITSIO_PRINTF, MFITSIO_READWRITE, and MFITSIO_WARN.

void mfitsio_write_image const char *    filename,
const mxArray *    header,
mxArray *    img
 

Write a MATLAB array/image to a FITS file.

Parameters:
filename  The filename of the FITS file.
info  The MATLAB struct array representing the keywords to store.
img  The MATLAB array/image to store in the FITS file.

Definition at line 704 of file mfitsio.c.

References mfitsio_calc_info, MFITSIO_FREE, mfitsio_free_info, MFITSIO_MALLOC, mfitsio_write_image_impl, mfitsio_info::naxes, and mfitsio_info::naxis.

void mfitsio_write_image_execute fitsfile *    file,
mxArray *    img,
long    group,
long    naxis,
long *    naxes,
long *    fpixel,
long *    lpixel,
int *    status
 

Close the FITS file.

Definition at line 825 of file mfitsio.c.

References MFITSIO_ERR, and MFITSIO_PRINTF.

void mfitsio_write_image_impl const char *    filename,
const mxArray *    header,
mxArray *    img,
long *    fpixels,
long *    lpixels,
long *    lnaxes,
long *    inc,
mfitsio_info   info
 

Write a MATLAB array/image to a FITS file.

Parameters:
filename  The filename of the FITS file.
info  The MATLAB struct array representing the keywords to store.
img  The MATLAB array/image to store in the FITS file.
fpixels  The starting pixel coordinates.
lpixels  The ending pixel coordinates.
lnaxes  The

Definition at line 751 of file mfitsio.c.

References mfitsio_info::bitpix, mfitsio_info::check, MFITSIO_ERR, MFITSIO_PRINTF, MFITSIO_READWRITE, mfitsio_write_header, mfitsio_write_image_execute, and mfitsio_info::naxis.

void mfitsio_write_info fitsfile *    fptr,
const mfitsio_info   info
 

Write bitpix and dimension information to a FITS header.

Parameters:
filename  The filename of the FITS file.
info  The mfitsio_info struct containing the dimension and bitpix information.

Definition at line 1145 of file mfitsio.c.

References mfitsio_info::bitpix, MFITSIO_ERR, MFITSIO_PRINTF, mfitsio_info::naxes, and mfitsio_info::naxis.



Operated by University of California for the National Nuclear Security Administration of the US Department of Energy. Copyright © 2002-2003 UC | Disclaimer/Privacy
This website has been approved for unlimited release with associated LA-UR number LA-UR-03-0949.