# tab.h File Reference

`#include "wcserr.h"`

Go to the source code of this file.

## Data Structures
struct | tabprm
| Tabular transformation parameters. More...
## Defines
#define | TABLEN (sizeof(struct tabprm)/sizeof(int))
| Size of the tabprm struct in int units.
#define | tabini_errmsg tab_errmsg
| Deprecated.
#define | tabcpy_errmsg tab_errmsg
| Deprecated.
#define | tabfree_errmsg tab_errmsg
| Deprecated.
#define | tabprt_errmsg tab_errmsg
| Deprecated.
#define | tabset_errmsg tab_errmsg
| Deprecated.
#define | tabx2s_errmsg tab_errmsg
| Deprecated.
#define | tabs2x_errmsg tab_errmsg
| Deprecated.
## Enumerations
enum | tab_errmsg_enum { TABERR_SUCCESS = 0, TABERR_NULL_POINTER = 1, TABERR_MEMORY = 2, TABERR_BAD_PARAMS = 3, TABERR_BAD_X = 4, TABERR_BAD_WORLD = 5 }
## Functions
int | tabini (int alloc, int M, const int K[], struct tabprm *tab)
| Default constructor for the tabprm struct.
int | tabmem (struct tabprm *tab)
| Acquire tabular memory.
int | tabcpy (int alloc, const struct tabprm *tabsrc, struct tabprm *tabdst)
| Copy routine for the tabprm struct.
int | tabfree (struct tabprm *tab)
| Destructor for the tabprm struct.
int | tabprt (const struct tabprm *tab)
| Print routine for the tabprm struct.
int | tabset (struct tabprm *tab)
| Setup routine for the tabprm struct.
int | tabx2s (struct tabprm *tab, int ncoord, int nelem, const double x[], double world[], int stat[])
| Pixel-to-world transformation.
int | tabs2x (struct tabprm *tab, int ncoord, int nelem, const double world[], double x[], int stat[])
| World-to-pixel transformation.
## Variables
const char * | tab_errmsg []
| Status return messages.

## Detailed Description

These routines implement the part of the FITS WCS standard that deals with tabular coordinates, i.e. coordinates that are defined via a lookup table. They define methods to be used for computing tabular world coordinates from intermediate world coordinates (a linear transformation of image pixel coordinates), and vice versa. They are based on the tabprm struct which contains all information needed for the computations. The struct contains some members that must be set by the user, and others that are maintained by these routines, somewhat like a C++ class but with no encapsulation.

tabini(), tabmem(), tabcpy(), and tabfree() are provided to manage the tabprm struct, and another, tabprt(), to print its contents.

A setup routine, tabset(), computes intermediate values in the tabprm struct from parameters in it that were supplied by the user. The struct always needs to be set up by tabset() but it need not be called explicitly - refer to the explanation of tabprm::flag.

tabx2s() and tabs2x() implement the WCS tabular coordinate transformations.

Accuracy:
No warranty is given for the accuracy of these routines (refer to the copyright notice); intending users must satisfy for themselves their adequacy for the intended purpose. However, closure effectively to within double precision rounding error was demonstrated by test routine ttab.c which accompanies this software.

## Define Documentation

#define TABLEN (sizeof(struct tabprm)/sizeof(int))

Size of the tabprm struct in int units, used by the Fortran wrappers.

#define tabini_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabcpy_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabfree_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabprt_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabset_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabx2s_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

#define tabs2x_errmsg tab_errmsg

Deprecated:
  Added for backwards compatibility, use tab_errmsg directly now instead.

## Enumeration Type Documentation

enum tab_errmsg_enum

Enumerator:

  TABERR_SUCCESS |
  TABERR_NULL_POINTER |
  TABERR_MEMORY |
  TABERR_BAD_PARAMS |
  TABERR_BAD_X |
  TABERR_BAD_WORLD |

## Function Documentation

int tabini | ( | int | alloc,
|  | int | M,
|  | const int | K[],
|  | struct tabprm * | tab |
| ) |  |  |

tabini() allocates memory for arrays in a tabprm struct and sets all members of the struct to default values.

PLEASE NOTE: every tabprm struct should be initialized by tabini(), possibly repeatedly. On the first invokation, and only the first invokation, the flag member of the tabprm struct must be set to -1 to initialize memory management, regardless of whether tabini() will actually be used to allocate memory.

Parameters:

  `[in]` | alloc | If true, allocate memory unconditionally for arrays in the tabprm struct. If false, it is assumed that pointers to these arrays have been set by the user except if they are null pointers in which case memory will be allocated for them regardless. (In other words, setting alloc true saves having to initalize these pointers to zero.)
  `[in]` | M | The number of tabular coordinate axes.
  `[in]` | K | Vector of length M whose elements record the lengths of the axes of the coordinate array and of each indexing vector. M and K[] are used to determine the length of the various tabprm arrays and therefore the amount of memory to allocate for them. Their values are copied into the tabprm struct. It is permissible to set K (i.e. the address of the array) to zero which has the same effect as setting each element of K[] to zero. In this case no memory will be allocated for the index vectors or coordinate array in the tabprm struct. These together with the K vector must be set separately before calling tabset().
  `[in,out]` | tab | Tabular transformation parameters. Note that, in order to initialize memory management tabprm::flag should be set to -1 when tab is initialized for the first time (memory leaks may result if it had already been initialized).

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 2: Memory allocation failed.
  - 3: Invalid tabular parameters.
  For returns > 1, a detailed error message is set in tabprm::err if enabled, see wcserr_enable().

int tabmem | ( | struct tabprm * | tab | ) |

tabmem() takes control of memory allocated by the user for arrays in the tabprm struct.

Parameters:

  `[in,out]` | tab | Tabular transformation parameters.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 2: Memory allocation failed.
  For returns > 1, a detailed error message is set in tabprm::err if enabled, see wcserr_enable().

int tabcpy | ( | int | alloc,
|  | const struct tabprm * | tabsrc,
|  | struct tabprm * | tabdst |
| ) |  |  |

tabcpy() does a deep copy of one tabprm struct to another, using tabini() to allocate memory for its arrays if required. Only the "information to be provided" part of the struct is copied; a call to tabset() is required to set up the remainder.

Parameters:

  `[in]` | alloc | If true, allocate memory unconditionally for arrays in the tabprm struct. If false, it is assumed that pointers to these arrays have been set by the user except if they are null pointers in which case memory will be allocated for them regardless. (In other words, setting alloc true saves having to initalize these pointers to zero.)
  `[in]` | tabsrc | Struct to copy from.
  `[in,out]` | tabdst | Struct to copy to. tabprm::flag should be set to -1 if tabdst was not previously initialized (memory leaks may result if it was previously initialized).

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 2: Memory allocation failed.
  For returns > 1, a detailed error message is set in tabprm::err (associated with tabdst) if enabled, see wcserr_enable().

int tabfree | ( | struct tabprm * | tab | ) |

tabfree() frees memory allocated for the tabprm arrays by tabini(). tabini() records the memory it allocates and tabfree() will only attempt to free this.

PLEASE NOTE: tabfree() must not be invoked on a tabprm struct that was not initialized by tabini().

Parameters:

  `[out]` | tab | Coordinate transformation parameters.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.

int tabprt | ( | const struct tabprm * | tab | ) |

tabprt() prints the contents of a tabprm struct using wcsprintf(). Mainly intended for diagnostic purposes.

Parameters:

  `[in]` | tab | Tabular transformation parameters.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.

int tabset | ( | struct tabprm * | tab | ) |

tabset() allocates memory for work arrays in the tabprm struct and sets up the struct according to information supplied within it.

Note that this routine need not be called directly; it will be invoked by tabx2s() and tabs2x() if tabprm::flag is anything other than a predefined magic value.

Parameters:

  `[in,out]` | tab | Tabular transformation parameters.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 3: Invalid tabular parameters.
  For returns > 1, a detailed error message is set in tabprm::err if enabled, see wcserr_enable().

int tabx2s | ( | struct tabprm * | tab,
|  | int | ncoord,
|  | int | nelem,
|  | const double | x[],
|  | double | world[],
|  | int | stat[] |
| ) |  |  |

tabx2s() transforms intermediate world coordinates to world coordinates using coordinate lookup.

Parameters:

  `[in,out]` | tab | Tabular transformation parameters.
  `[in]` | ncoord,nelem | The number of coordinates, each of vector length nelem.
  `[in]` | x | Array of intermediate world coordinates, SI units.
  `[out]` | world | Array of world coordinates, in SI units.
  `[out]` | stat | Status return value status for each coordinate: 0: Success. 1: Invalid intermediate world coordinate.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 3: Invalid tabular parameters.
  - 4: One or more of the x coordinates were invalid, as indicated by the stat vector.
  For returns > 1, a detailed error message is set in tabprm::err if enabled, see wcserr_enable().

int tabs2x | ( | struct tabprm * | tab,
|  | int | ncoord,
|  | int | nelem,
|  | const double | world[],
|  | double | x[],
|  | int | stat[] |
| ) |  |  |

tabs2x() transforms world coordinates to intermediate world coordinates.

Parameters:

  `[in,out]` | tab | Tabular transformation parameters.
  `[in]` | ncoord,nelem | The number of coordinates, each of vector length nelem.
  `[in]` | world | Array of world coordinates, in SI units.
  `[out]` | x | Array of intermediate world coordinates, SI units.
  `[out]` | stat | Status return value status for each vector element: 0: Success. 1: Invalid world coordinate.

Returns:
  Status return value:
  - 0: Success.
  - 1: Null tabprm pointer passed.
  - 3: Invalid tabular parameters.
  - 5: One or more of the world coordinates were invalid, as indicated by the stat vector.
  For returns > 1, a detailed error message is set in tabprm::err if enabled, see wcserr_enable().

## Variable Documentation

const char * tab_errmsg[]

Error messages to match the status value returned from each function.