IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2004, 5:39:01 PM (22 years ago)
Author:
Paul Price
Message:

Updated APIs. APIs in this file should be correct as of the current
version of the .h files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r288 r296  
     1%%% $Id: psLibSDRS.tex,v 1.9 2004-03-24 03:39:01 price Exp $
    12\documentclass[panstarrs]{panstarrs}
    23%\documentclass[panstarrs]{panstarrs}
     
    3334\pagenumbering{arabic}
    3435
    35 %Here's a reference to another document:
    36 %\href{file:utils#psDlist}{utils.pdf}; the \code{#psDlist} points to
    37 %\CODE|\hlabel{psDlist}| in the file \file{utils.tex} (this is like
    38 %a regular \code{\label}, but defines the hyperlink too).
    39 
    4036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    8379described here.
    8480
    85 All of the memory management APIs should be provided in a header file
    86 \file{psMemory.h} which is included by \file{psUtils.h}.
    87 
    8881\subsubsection{Rationale}
    8982
     
    146139in the following struct definition:
    147140\begin{verbatim}
    148   typedef struct {
    149       const unsigned long id;           // a unique ID for this allocation
    150       const char *file;                 // set from __FILE__ in e.g. p_psAlloc
    151       const int lineno;                 // set from __LINE__ in e.g. p_psAlloc
    152       int refcntr;                      // how many times pointer is referenced
    153       const void *magic;                // initialised to P_PS_MEMMAGIC
    154   } psMemBlock;
     141typedef struct {
     142    const void *magic0;                 //!< initialised to p_psMEMMAGIC
     143    const unsigned long id;             //!< a unique ID for this allocation
     144    const char *file;                   //!< set from __FILE__ in e.g. p_psAlloc
     145    const int lineno;                   //!< set from __LINE__ in e.g. p_psAlloc
     146    int refCounter;                     //!< how many times pointer is referenced
     147    const void *magic;                  //!< initialised to p_psMEMMAGIC
     148} psMemBlock;
    155149\end{verbatim}
    156150
     
    161155\paragraph{APIs for using Memory Allocation Functions}
    162156
    163 \begin{table}
    164 \begin{verbatim}
    165 void *psAlloc(size_t size);
    166 void *psRealloc(void *ptr, size_t size);
    167 void psFree(void *ptr);
    168 
    169 void *p_psAlloc(size_t size, const char *file, int lineno);
    170 void *p_psRealloc(void *ptr, size_t size, const char *file, int lineno);
    171 void p_psFree(void *ptr, const char *file, int lineno);
    172 
     157The types and function prototypes for the part of the memory API
     158concerned with allocating and freeing memory are shown below.
     159
     160\begin{verbatim}
     161/// Memory allocation. Underlying private function called by macro psAlloc.
     162void *p_psAlloc(size_t size,            //!< Size required
     163                const char *file,       //!< File of call
     164                int lineno              //!< Line number of call
     165                );
     166
     167/// Memory re-allocation.  Underlying private function called by macro psRealloc.
     168void *p_psRealloc(void *ptr,            //!< Pointer to re-allocate
     169                  size_t size,          //!< Size required
     170                  const char *file,     //!< File of call
     171                  int lineno            //!< Line number of call
     172                  );
     173
     174/// Free memory.  Underlying private function called by macro psFree.
     175void p_psFree(void *ptr,                //!< Pointer to free
     176              const char *file,         //!< File of call
     177              int lineno                //!< Line number of call
     178              );
     179
     180/// Memory allocation. psAlloc sends file and line number to p_psAlloc.
    173181#define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
     182
     183/// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
    174184#define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)
     185
     186/// Free memory.  psFree sends file and line number to p_psFree.
    175187#define psFree(size) p_psFree(size, __FILE__, __LINE__)
    176188\end{verbatim}
    177 \begin{caption}{The APIs required to use the \PS{} memory allocation routines}
    178   \hlabel{tabUsageAPI}
    179   The APIs required to use the \PS{} memory allocation routines, and as
    180   provided by \file{psMemory.h}.
    181 \end{caption}
    182 \end{table}
    183 
    184 The types and function prototypes for the part of the memory API
    185 concerned with allocating and freeing memory are given in table
    186 \ref{tabUsageAPI}.
    187189
    188190N.b.
     
    204206 
    205207\item
    206   The file \file{psMemory.h} shall take steps to ensure that
    207   code calling the functions \code{malloc}, \code{calloc}, \code{realloc},
    208   or \code{free} shall not compile (\eg{} \code{#define malloc(S) for})
    209   unless the symbol \code{PS_ALLOC_MALLOC} is defined.
     208  The header file (\file{psMemory.h}) shall take steps to ensure that
     209  code calling the functions \code{malloc}, \code{calloc},
     210  \code{realloc}, or \code{free} shall not compile (\eg{}
     211  \code{#define malloc(S) for}) unless the symbol
     212  \code{PS_ALLOC_MALLOC} is defined.
    210213
    211214\item
     
    245248\hlabel{secMemAdvanced}
    246249
     250The types and function prototypes for this part of the memory API
     251are shown below.
     252
    247253\begin{table}
    248254\begin{verbatim}
     255/// prototype of a basic callback used by memory functions
    249256typedef int (*psMemCallback)(const psMemBlock *ptr);
    250 typedef void (*psMemProblemCallback)(const psMemBlock *ptr,
    251                                      const char *file, int lineno);
     257
     258/// prototype of a callback used in error conditions
     259typedef void (*psMemProblemCallback)(const psMemBlock *ptr, const char *file, int lineno);
     260
     261/// prototype of a callback used when memory runs out
    252262typedef void *(*psMemExhaustedCallback)(size_t size);
    253263
    254 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func);
    255 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func);
    256 
    257 psMemCallback psMemAllocateSetCB(psMemCallback func);
    258 psMemCallback psMemFreeSetCB(psMemCallback func);
    259 
    260 int psMemGetId(void);                   // get next memory ID
    261 
    262 long psMemSetAllocateID(long id);       // set p_psMemAllocateID to id
    263 long psMemSetFreeID(long id);           // set p_psMemFreeID to id
    264 
    265 int psMemCheckLeaks(
    266     int id0,                            // don't list blocks with id < id0
    267     psMemBlock ***arr,                  // pointer to array of pointers to
    268                                         //leaked blocks, or NULL
    269     FILE *fd);                          // print list of leaks to fd (or NULL)
    270 int psMemCheckCorruption(int abort_on_error);
    271 \end{verbatim}
    272 \begin{caption}{The APIs required to use the \PS{} memory allocation routines}
    273   \hlabel{tabCallbackAPI}
    274   The APIs required to use the callback and tracing facilities
    275   in \PS{} memory allocation routines, as defined in \file{psMemory.h}.
    276 \end{caption}
    277 \end{table}
    278 
    279 The types and function prototypes for this part of the memory API
    280 are given in table \ref{tabCallbackAPI}.
     264/// Set callback for problems
     265psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func //!< Function to run
     266                                       );
     267
     268/// Set callback for out-of-memory
     269psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func //!< Function to run
     270                                           );
     271
     272/// Set call back for when a particular memory block is allocated
     273psMemCallback psMemAllocateSetCB(psMemCallback func //!< Function to run
     274                                 );
     275
     276/// Set call back for when a particular memory block is freed
     277psMemCallback psMemFreeSetCB(psMemCallback func
     278                             );
     279
     280/// get next memory ID
     281int psMemGetId(void);
     282
     283/// set p_psMemAllocateID to id
     284long psMemSetAllocateID(long id         //!< ID to set
     285                        );
     286
     287/// set p_psMemFreeID to id
     288long psMemSetFreeID(long id             //!< ID to set
     289                    );
     290
     291/// Check for memory leaks
     292int psMemCheckLeaks(int id0,            //!< don't list blocks with id < id0
     293                    psMemBlock ***arr,  //!< pointer to array of pointers to leaked blocks, or NULL
     294                    FILE *fd            //!< print list of leaks to fd (or NULL)
     295                    );
     296/// Check for memory corruption
     297int psMemCheckCorruption(int abort_on_error //!< Abort on detecting corruption?
     298                         );
     299\end{verbatim}
    281300
    282301\paragraph{Callback Routines}
     
    381400The API for this field is:
    382401\begin{verbatim}
    383 int psMemGetRefCounter(void *vptr);        // return refcounter
    384 void *psMemIncrRefCounter(void *vptr);     // increment refcounter and return vptr
    385 void *psMemDecrRefCounter(void *vptr);     // decrement refcounter and return vptr
     402/// Return reference counter
     403int psMemGetRefCounter(void *vptr       //!< Pointer to get refCounter for
     404                       );
     405
     406/// Increment reference counter and return the pointer
     407void *psMemIncrRefCounter(void *vptr    //!< Pointer to increment refCounter, and return
     408                          );
     409
     410/// Decrement reference counter and return the pointer
     411void *psMemDecrRefCounter(void *vptr    //!< Pointer to decrement refCounter, and return
     412                          );
    386413\end{verbatim}
    387414
     
    391418\subsubsubsection{Rationale}
    392419
    393 \begin{table}
     420The \code{psMemBlock.refcounter} is clearly useful for detecting
     421attempts to free memory that is already free.  A more complex
     422application is for allowing pointers to complex data-objects (e.g.\
     423images) to appear in more than one data structure simultaneously:
     424
    394425\begin{verbatim}
    395426typedef struct {
     
    417448}
    418449\end{verbatim}
    419 \caption{An example of reference counting}
    420 \label{tabReferenceCounting}
    421 \end{table}
    422 
    423 The \code{psMemBlock.refcounter} is clearly useful for detecting
    424 attempts to free memory that is already free.  A more complex
    425 application is for allowing pointers to complex data-objects (e.g.
    426 images) to appear in more than one data structure simultaneously
    427 (see table \ref{tabReferenceCounting}).
     450
    428451
    429452Because of the use of the \code{refcounter} field, we can safely put items of
     
    456479\hlabel{psTrace}
    457480
    458 \begin{table}
    459   \begin{verbatim}
     481\begin{verbatim}
    460482#if defined(PS_NTRACE)
    461483#  define psTrace(facil, level, ...) /* do nothing */
     
    465487#endif
    466488
    467 void p_psTrace(const char *facil, int level, ...);
    468 
    469 int psSetTraceLevel(const char *facil,  // facilty of interest
    470                     int level);         // desired trace level
    471 int psGetTraceLevel(const char *name);  // facilty of interest
    472 
    473 void psTraceReset(void);                // turn off all tracing, and free trace's allocated memory
    474 
    475 void psPrintTraceLevels(void);          // print trace levels
    476   \end{verbatim}
    477   \begin{caption}{The public API for the trace facility
    478       from \file{psTrace.h}.}
    479     \hlabel{tabTraceAPI}
    480   \end{caption}
    481 \end{table}
    482 
    483 The public API for the trace facility (table \ref{tabTraceAPI})
    484 should be provided in a header file \file{psTrace.h} which
    485 is included by \file{psUtils.h}.
     489/// Send a trace message
     490void p_psTrace(const char *facil,       ///< facilty of interest
     491               int level,               ///< desired trace level
     492               ...                      ///< trace message arguments
     493    );
     494
     495/// Set trace level
     496int psSetTraceLevel(const char *facil,  ///< facilty of interest
     497                    int level           ///< desired trace level
     498    );
     499
     500/// Get the trace level
     501int psGetTraceLevel(const char *name    ///< facilty of interest
     502    );
     503
     504/// turn off all tracing, and free trace's allocated memory
     505void psTraceReset(void);
     506
     507/// print trace levels
     508void psPrintTraceLevels(void);
     509\end{verbatim}
    486510
    487511\begin{itemize}
     
    489513    Logging is provided by the function \code{psTrace},
    490514    which is actually a macro.  When the macro \code{PS_NTRACE}
    491     is defined, all occurrences of  \code{psTrace} shall
     515    is defined, all occurrences of \code{psTrace} shall
    492516    be replaced by whitespace.
    493517
     
    536560    \item
    537561      There is no requirement that \code{psTrace} be usable from
    538       within the functions that implement \file{psTrace.h}
    539       or \file{psMemory.h} systems.
     562      within the functions that implement the tracing or memory
     563      management systems.
    540564
    541565    \item
     
    617641\hlabel{psLogMsg}
    618642
    619 \begin{table}
    620   \begin{verbatim}
    621 enum { PS_LOG_ABORT = 0, PS_LOG_ERROR, PS_LOG_WARN, PS_LOG_INFO };
    622 
    623 enum { PS_LOG_TO_STDERR, PS_LOG_TO_STDOUT };
    624 
    625 void psLogMsg(const char *name, int level, const char *fmt, ...);
    626 void p_psVLogMsg(const char *name, int level, const char *fmt, va_list ap);
    627 
    628 int psSetLogDestination(int dest);
    629 void psSetLogFormat(const char *fmt);
    630 
    631 int psSetLogLevel(int level);
    632   \end{verbatim}
    633   \begin{caption}{API for message logging}
    634     \hlabel{tabLogMsgAPI}
    635     The API for message logging.
    636   \end{caption}
    637 \end{table}
    638 
    639 The public API for the logging facility (table \ref{tabLogMsgAPI})
    640 should be provided in a header file \file{psLogMsg.h} which
    641 is included by \file{psUtils.h}.
     643\begin{verbatim}
     644enum { PS_LOG_ABORT = 0, PS_LOG_ERROR, PS_LOG_WARN, PS_LOG_INFO }; //!< Status codes for log messages
     645
     646enum { PS_LOG_TO_STDERR, PS_LOG_TO_STDOUT }; //!< Destinations for log messages
     647
     648/// Logs a message
     649void psLogMsg(const char *name, int level, const char *fmt, ...);
     650
     651/// Logs a message from varargs
     652void p_psVLogMsg(const char *name, int level, const char *fmt, va_list ap);
     653
     654/// Sets the log destination
     655int psSetLogDestination(int dest);     
     656
     657/// Sets the log level
     658int psSetLogLevel(int level);           
     659
     660/// sets the log format
     661void psSetLogFormat(const char *fmt);   
     662\end{verbatim}
    642663
    643664The function \code{psSetLogLevel} may be used to set the current
     
    702723\hlabel{psDlist}
    703724
    704 Pan-STARRS supports doubly linked lists through a type \code{psDlist}.
    705 The type is defined in the header file \file{psDlist.h}, and consists
    706 of the following definitions:
    707 
    708 \begin{verbatim}
     725\PS{} supports doubly linked lists through a type \code{psDlist}.  The
     726type consists of the following definitions:
     727
     728\begin{verbatim}
     729/** Doubly-linked list element */
    709730typedef struct psDlistElem {
    710     struct psDlistElem *prev;           // previous link in list
    711     struct psDlistElem *next;           // next link in list
    712     void *data;                         // real data item
     731   struct psDlistElem *prev;            //!< previous link in list
     732   struct psDlistElem *next;            //!< next link in list
     733   void *data;                          //!< real data item
    713734} psDlistElem;
    714735
     736/** Doubly-linked list */
    715737typedef struct {
    716     int n;                              // number of elements on list
    717     psDlistElem *head;                  // first element on list (may be NULL)
    718     psDlistElem *tail;                  // last element on list (may be NULL)
    719     psDlistElem *iter;                  // iteration cursor; private
     738   int n;                               //!< number of elements on list
     739   psDlistElem *head;                   //!< first element on list (may be NULL)
     740   psDlistElem *tail;                   //!< last element on list (may be NULL)
     741   psDlistElem *iter;                   //!< iteration cursor
    720742} psDlist;
    721743
    722 enum {                                  // Special values of index into list
    723     psDlistHead = 0,                    // at head
    724     psDlistTail = -1,                   // at tail
    725     psDlistUnknown = -2,                // unknown position
    726     psDlistPrev = -3,                   // previous element
    727     psDlistNext = -4                    // next element
     744/** Special values of index into list */
     745enum {
     746   PS_DLIST_HEAD = 0,                   //!< at head
     747   PS_DLIST_TAIL = -1,                  //!< at tail
     748   PS_DLIST_UNKNOWN = -2,               //!< unknown position
     749   PS_DLIST_PREV = -3,                  //!< previous element
     750   PS_DLIST_NEXT = -4                   //!< next element
    728751};
    729752\end{verbatim}
     
    732755
    733756\begin{verbatim}
    734 psDlist *psDlistAlloc(void *data);        // initial data item; may be NULL
    735 
    736 void psDlistFree(psDlist *list,          // list to destroy
    737                 void (*elemFree)(void *)); // destructor for list data, or NULL
    738 
    739 /*
    740  * List maintainence functions
    741  */
    742 psDlist *psDlistAdd(psDlist *list,      // list to add to (may be NULL)
    743                     void *data,         // data item to add
    744                     int where);         // index, psDlistHead, or psDlistTail
    745 psDlist *psDlistAppend(psDlist *list,   // list to append to (may be NULL)
    746                        void *data);     // data item to add
    747 void *psDlistRemove(psDlist *list,      // list to remove element from
    748                     void *data,         // data item to remove
    749                     int which);         // index of item, or psDlistUnknown,
    750                                         // or psDlistNext, or psDlistPrev
    751 void *psDlistGet(const psDlist *list,   // list to retrieve element from
    752                  int which);            // index of item, or psDlistNext,
    753                                         // or psDlistPrev
    754 /*
    755  * Conversions to/from arrays
    756  */
    757 psVoidPtrArray *psDlistToArray(psDlist *dlist);
    758 psDlist *psArrayToDlist(psVoidPtrArray *arr);
    759 \end{verbatim}
    760 
    761 All data items placed onto lists (e.g. with \code{psDlistAdd})
    762 shall have their reference counters (section \ref{secMemRefcounter}) incremented.
    763 When elements
    764 are removed from a list with \code{psDlistRemove}, they shall
    765 have their reference counters decremented. The action of retrieving
    766 data from a list (with \code{psDlistGet}) shall not affect
    767 their reference counter.
     757/** Constructor */
     758psDlist *psDlistAlloc(void *data        //!< initial data item; may be NULL
     759                      );
     760
     761/** Destructor */
     762void psDlistFree(psDlist *list,         //!< list to destroy
     763                void (*elemFree)(void *) //!< destructor for data on list
     764                 );
     765
     766/**** List maintainence functions ****/
     767
     768/** Add to list */
     769psDlist *psDlistAdd(psDlist *list,      //!< list to add to (may be NULL)
     770                    void *data,         //!< data item to add
     771                    int where           //!< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
     772                    );
     773
     774/** Append to a list */
     775psDlist *psDlistAppend(psDlist *list,   //!< list to append to (may be NULL)
     776                       void *data       //!< data item to add
     777                       );
     778
     779/** Remove from a list */
     780void *psDlistRemove(psDlist *list,      //!< list to remove element from
     781                    void *data,         //!< data item to remove
     782                    int which           //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or
     783                                        //!< PS_DLIST_PREV
     784                    );
     785/** Retrieve from a list */
     786void *psDlistGet(const psDlist *list,   //!< list to retrieve element from
     787                 int which              //!< index of item, or PS_DLIST_NEXT, or PS_DLIST_PREV
     788                 );
     789
     790/** Convert doubly-linked list to an array */
     791psVoidPtrArray *psDlistToArray(psDlist *dlist //!< List to convert
     792                               );
     793
     794/** Convert array to a doubly-linked list */
     795psDlist *psArrayToDlist(psVoidPtrArray *arr //!< Array to convert
     796                        );
     797\end{verbatim}
     798
     799All data items placed onto lists (e.g. with \code{psDlistAdd}) shall
     800have their reference counters (section \ref{secMemRefcounter})
     801incremented.  When elements are removed from a list with
     802\code{psDlistRemove}, they shall have their reference counters
     803decremented. The action of retrieving data from a list (with
     804\code{psDlistGet}) shall not affect their reference counter.
    768805
    769806If \code{psDlistFree}'s argument \code{elemFree} is NULL, the
     
    773810Iteration over all elements of the list is provided by the functions:
    774811\begin{verbatim}
    775 void psDlistSetIterator(psDlist *list, int where, int which);
    776 void *psDlistGetNext(psDlist *list, int which);
    777 void *psDlistGetPrev(psDlist *list, int which);
     812/** Set the iterator */
     813void psDlistSetIterator(psDlist *list,  //!< list to retrieve element from
     814                        int where,      //!< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
     815                        int which       //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or
     816                                        //!< PS_DLIST_PREV
     817                        );
     818
     819/** Get next element */
     820void *psDlistGetNext(psDlist *list,     //!< list to retrieve element from
     821                     int which          //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or
     822                                        //!< PS_DLIST_PREV
     823                     );
     824
     825/** Get previous element */
     826void *psDlistGetPrev(psDlist *list,     //!< list to retrieve element from
     827                     int which          //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or
     828                                        //!< PS_DLIST_PREV
     829                     );
    778830\end{verbatim}
    779831in which the \code{where} argument must be \code{PS_DLIST_HEAD} or \code{PS_DLIST_TAIL},
     
    815867is the number of elements allocated ($s \ge n$).
    816868
    817 This type and functions may be declared and defined using two macros
    818 from \file{psArray.h}, \code{PS_DECLARE_ARRAY_TYPE(psType)} and
     869This type and functions may be declared and defined using two macros,
     870\code{PS_DECLARE_ARRAY_TYPE(psType)} and
    819871\code{PS_CREATE_ARRAY_TYPE(psType)}.  The former defines the
    820872\code{typedef} and declares the prototypes (and is thus suitable for
     
    903955\code{array}s.
    904956\begin{verbatim}
    905 #include "psUtils.h"
     957#include "psLib.h"
    906958
    907959typedef struct {
     
    9601012\hlabel{psHash}
    9611013
    962 \begin{table}
    963   \begin{verbatim}
    964 typedef struct HashTable psHash;
    965 
    966 psHash *psHashAlloc(int nbucket);       // initial number of buckets
    967 void psHashFree(psHash *table,          // hash table to be freed
    968                void (*itemFree)(void *item)); // how to free hashed data;
    969                                         // or NULL
    970 
    971 void *psHashInsert(psHash *table,       // table to insert in
    972                    const char *key,     // key to use
    973                    void *data,          // data to insert
    974                    void (*itemFree)(void *item)); // how to free hashed data;
    975                                         // or NULL
    976 void *psHashLookup(psHash *table,       // table to lookup key in
    977                    const char *key);    // key to lookup
    978 
    979 void *psHashRemove(psHash *table,       // table to lookup key in
    980                    const char *key);    // key to lookup
    981   \end{verbatim}
    982   \begin{caption}{The public API for hash tables from \file{psHash.h}}
    983     \hlabel{tabPsHash}
    984   \end{caption}
    985 \end{table}
    986 
    987 The public API for the hash table (table \ref{tabPsHash})
    988 should be provided in a header file \file{psHash.h} which
    989 is included by \file{psUtils.h}.
     1014The public APIs for the hash table (table \ref{tabPsHash}) are shown below.
    9901015\footnote{
    9911016  We choose not to use the posix function \code{hcreate},
    9921017  \code{hdestroy}, and \code{hsearch} as they only support
    9931018  a single hash table at any one time.}
     1019
     1020\begin{verbatim}
     1021typedef struct HashTable psHash;        ///< Opaque type for a hash table
     1022
     1023/// Allocate hash buckets in table.
     1024psHash *psHashAlloc(int nbucket         ///< initial number of buckets
     1025    );
     1026
     1027/// Free hash buckets from table.
     1028void psHashFree(psHash *table,          ///< hash table to be freed
     1029                void (*itemFree)(void *item) ///< how to free hashed data; or NULL
     1030    );
     1031
     1032/// Insert entry into table.
     1033void *psHashInsert(psHash *table,       ///< table to insert in
     1034                   const char *key,     ///< key to use
     1035                   void *data,          ///< data to insert
     1036                   void (*itemFree)(void *item) ///< how to free hashed data; or NULL
     1037    );
     1038
     1039/// Lookup key in table.
     1040void *psHashLookup(psHash *table,       ///< table to lookup key in
     1041                   const char *key      ///< key to lookup
     1042    );
     1043
     1044/// Remove key from table.
     1045void *psHashRemove(psHash *table,       ///< table to lookup key in
     1046                   const char *key      ///< key to lookup
     1047    );
     1048\end{verbatim}
     1049
    9941050
    9951051A hash table is an abstract type \code{psHash}.  The argument
     
    10161072\subsection{Miscellaneous Utilities}
    10171073
    1018 \begin{table}
    1019   \begin{verbatim}
    1020 #define PS_CONCAT(A, B) A ## B          // Expands to AB
    1021 #define PS_CONCAT2(A, B) PS_CONCAT(A, B) // Also expands to AB
    1022 #define PS_CONCAT3(A, B, C) A ## B ## C // Expands to ABC
    1023 
     1074\begin{verbatim}
    10241075#define PS_STRING(S) #S                 // converts argument S to string
    10251076   
    1026 void psAbort(const char *name, const char *fmt, ...);
    1027 void psError(const char *name, const char *fmt, ...);
    1028 char *psStringCopy(const char *str);
    1029   \end{verbatim}
    1030   \begin{caption}{The utilities provided by \file{psMisc.h}}
    1031       \hlabel{psMisc}
    1032   \end{caption}
    1033 \end{table}
     1077/// Prints an error message and aborts
     1078void psAbort(const char *name,          ///< Category of code that caused the abort
     1079             const char *fmt,           ///< Format
     1080             ...                        ///< Extra arguments to use format
     1081             );
     1082
     1083/// Prints an error message and doesn't abort
     1084void psError(const char *name,          ///< Category of code that caused the abort
     1085             const char *fmt,           ///< Format
     1086             ...                        ///< Extra arguments to use format
     1087    );
     1088
     1089/// Allocates and returns a copy of a string
     1090char *psStringCopy(const char *str      ///< string to copy
     1091    );
     1092
     1093/// Allocates nChar and returns a copy of the string or segment
     1094char *psStringNCopy(const char *str,    ///< string to copy
     1095                    int nChar           //!< Number of characters (including \0 )
     1096    );
     1097\end{verbatim}
    10341098
    10351099\code{psAbort} shall call \code{psMsgLog} with a level of \code{PS_LOG_ABORT},
     
    11411205            char *operator,             ///< operator
    11421206            void *in2                   ///< second input
    1143 );
     1207    );
    11441208\end{verbatim}
    11451209
     
    11511215           void *in,                    ///< input
    11521216           char *operator,              ///< operator
    1153 );
     1217    );
    11541218\end{verbatim}
    11551219
     
    11821246
    11831247\begin{verbatim}
     1248/** private structure used to pass constant values into the math operators. */
    11841249typedef struct {
    1185     psType type;
    1186     union {
    1187         int i;
    1188         float f;
    1189         double d;
    1190         complex float c;
    1191     }
     1250    psType type;                        ///< data type information
     1251    union {                           
     1252        int i;                          ///< integer value entry
     1253        float f;                        ///< float value entry
     1254        double d;                       ///< double value entry
     1255        complex float c;                ///< complex value entry
     1256    } val;
    11921257} p_psScalar;
    11931258\end{verbatim}
     
    16441709/// basic image data structure.
    16451710typedef struct psImage {
    1646     psType type;                        ///< image data type and dimension
    1647     int nx, ny;                         ///< size of image
    1648     int x0, y0;                         ///< data region relative to parent
     1711    psType type;                        ///< image data type and dimension
     1712    int nx, ny;                         ///< size of image
     1713    int x0, y0;                         ///< data region relative to parent
    16491714    union {
    1650         psF32 **rows;                   ///< == rows_f32
    1651         psS8  **rows_s8;                ///< pointers to psS8 data
    1652         psS16 **rows_s16;               ///< pointers to psS16 data
    1653         psS32 **rows_s32;               ///< pointers to psS32 data
    1654         psU8  **rows_u8;                ///< pointers to psU8 data
    1655         psU16 **rows_u16;               ///< pointers to psU16 data
    1656         psU32 **rows_u32;               ///< pointers to psU32 data
    1657         psF32 **rows_f32;               ///< pointers to psF32 data
    1658         psF64 **rows_f64;               ///< pointers to psF64 data
     1715        psF32 **rows;                   ///< == rows_f32
     1716        psS8  **rows_s8;                ///< pointers to psS8 data
     1717        psS16 **rows_s16;               ///< pointers to psS16 data
     1718        psS32 **rows_s32;               ///< pointers to psS32 data
     1719        psU8  **rows_u8;                ///< pointers to psU8 data
     1720        psU16 **rows_u16;               ///< pointers to psU16 data
     1721        psU32 **rows_u32;               ///< pointers to psU32 data
     1722        psF32 **rows_f32;               ///< pointers to psF32 data
     1723        psF64 **rows_f64;               ///< pointers to psF64 data
     1724        psComplex **rows_complex;       //!< pointers to psComplex data
    16591725    } rows;
    1660     struct psImage *parent;             ///< parent, if a subimage
    1661     struct psImage *children;           ///< children of this region
    1662     int Nchildren;                      ///< number of subimages
     1726    psImage *parent;                    ///< parent, if a subimage
     1727    int Nchildren;                      ///< number of subimages
     1728    psImage *children;                  ///< children of this region; array of Nchildren pointers
    16631729} psImage;
    16641730\end{verbatim}
     
    16951761outside of the parent image.
    16961762\begin{verbatim}
     1763/// Create a subimage of the specified area.
    16971764psImage *
    1698 psImageSubset (psImage *image,          ///< parent image
    1699                int nx,                  ///< subimage width (<= image.nx - x0) 
    1700                int ny,                  ///< subimage width (<= image.ny - y0) 
    1701                int x0,                  ///< subimage x-offset (0 <= x0 < nx)   
    1702                int y0)                  ///< subimage y-offset (0 <= y0 < ny)   
     1765psImageSubset(psImage *out,             //!< Subimage to return, or NULL
     1766              const psImage *image,     ///< parent image
     1767              int nx,                   ///< subimage width (<= image.nx - x0) 
     1768              int ny,                   ///< subimage width (<= image.ny - y0) 
     1769              int x0,                   ///< subimage x-offset (0 <= x0 < nx)   
     1770              int y0                    ///< subimage y-offset (0 <= y0 < ny)   
     1771    );
    17031772\end{verbatim}
    17041773
     
    17301799\begin{verbatim}
    17311800psImage *
    1732 psImageCopy (psImage *output,           ///< target structure for output image data
    1733              psImage *input)            ///< copy this image
     1801psImageCopy(psImage *output,            ///< target structure for output image data
     1802            const psImage *input        ///< copy this image
     1803    );
    17341804\end{verbatim}
    17351805
     
    17441814\begin{verbatim}
    17451815psFloatArray *
    1746 psImageSlice (psImage *input,           ///< extract slice from this image
    1747               int x,                    ///< starting x coord of region to slice
    1748               int y,                    ///< starting y coord of region to slice
    1749               int nx,                   ///< width of region in x
    1750               int ny,                   ///< width of region in y
    1751               int direction,            ///< direction of vector along slice
    1752               psStats *stats)           ///< defines statistics used to find output values
     1816psImageSlice(psFloatArray *out,         //!< Vector to output, or NULL
     1817             const psImage *input,      ///< extract slice from this image
     1818             int x,                     ///< starting x coord of region to slice
     1819             int y,                     ///< starting y coord of region to slice
     1820             int nx,                    ///< width of region in x
     1821             int ny,                    ///< width of region in y
     1822             int direction,             ///< direction of vector along slice
     1823             const psStats *stats       ///< defines statistics used to find output values
     1824    );
    17531825\end{verbatim}
    17541826
     
    17641836\begin{verbatim}
    17651837psFloatArray *
    1766 psImageCut (psImage *input,             ///< extract cut from this image
    1767             float xs,                   ///< starting x coord of cut
    1768             float ys,                   ///< starting y coord of cut
    1769             float xe,                   ///< ending x coord of cut
    1770             float ye,                   ///< ending y coord of cut
    1771             float dw,                   ///< width of cut
    1772             psStats *stats)             ///< defines statistics used to find output values
     1838psImageCut(psFloatArray *out,           //!< Vector to output, or NULL
     1839           const psImage *input,        ///< extract cut from this image
     1840           float xs,                    ///< starting x coord of cut
     1841           float ys,                    ///< starting y coord of cut
     1842           float xe,                    ///< ending x coord of cut
     1843           float ye,                    ///< ending y coord of cut
     1844           float dw,                    ///< width of cut
     1845           const psStats *stats         ///< defines statistics used to find output values
     1846    );
    17731847 \end{verbatim}
    17741848
     
    17831857\begin{verbatim}
    17841858psFloatArray *
    1785 psImageRadialCut (psImage *input,       ///< extract profile from this image
    1786                   float x,              ///< center x coord of annulii
    1787                   float y,              ///< center y coord of annulii
    1788                   float radius,         ///< outer radius of annulii
    1789                   float dr,             ///< radial step size of annulii
    1790                   psStats *stats)       ///< defines statistics used to find output values
    1791 \end{verbatim}
    1792 
    1793 %/// Extract a 2-d contour from an image at the given threshold.
    1794 %\begin{verbatim}
    1795 %psFloatArray *
    1796 %psImageContour (psImage *input,        ///< create contour for this image
    1797 %               float threshold,        ///< contour image at this threshold
    1798 %               int binning)            ///< bin image by this value for contour calculation
    1799 %\end{verbatim}
     1859psImageRadialCut(psFloatArray *out,     //!< Vector to output, or NULL
     1860                 const psImage *input,  ///< extract profile from this image
     1861                 float x,               ///< center x coord of annulii
     1862                 float y,               ///< center y coord of annulii
     1863                 float radius,          ///< outer radius of annulii
     1864                 float dr,              ///< radial step size of annulii
     1865                 const psStats *stats   ///< defines statistics used to find output values
     1866    );
     1867\end{verbatim}
    18001868
    18011869Rebin image to new scale.  A new image is constructed in which the
     
    18081876\begin{verbatim}
    18091877psImage *
    1810 psImageRebin (psImage *input,           ///< rebin this image
    1811               float scale,              ///< rebinning scale: doutput = scale*dinput
    1812               psStats *stats)           ///< defines statistics used to find output values
     1878psImageRebin(psImage *out,              //!< Image to output, or NULL
     1879             const psImage *input,      ///< rebin this image
     1880             float scale,               ///< rebinning scale: doutput = scale*dinput
     1881             const psStats *stats       ///< defines statistics used to find output values
     1882    );
    18131883\end{verbatim}
    18141884
     
    18211891\begin{verbatim}
    18221892psImage *
    1823 psImageRotate (psImage *input,          ///< rotate this image
    1824                float angle)             ///< rotate by this amount (degrees)
     1893psImageRotate(psImage *out,             //!< Image to output, or NULL
     1894              const psImage *input,     ///< rotate this image
     1895              float angle               ///< rotate by this amount anti-clockwise (degrees)
     1896    );
    18251897\end{verbatim}
    18261898
     
    18331905\begin{verbatim}
    18341906psImage *
    1835 psImageShift (psImage *input,           ///< shift this image
    1836               float dx,                 ///< shift by this amount in x
    1837               float dy,                 ///< shift by this amount in y
    1838               float exposed)            ///< set exposed pixels to this value
     1907psImageShift(psImage *out,              //!< Image to output, or NULL
     1908             const psImage *input,      ///< shift this image
     1909             float dx,                  ///< shift by this amount in x
     1910             float dy,                  ///< shift by this amount in y
     1911             float exposed              ///< set exposed pixels to this value
     1912    );
    18391913\end{verbatim}
    18401914
     
    18441918\begin{verbatim}
    18451919psImage *
    1846 psImageRoll (psImage *input,            ///< roll this image
    1847              int dx,                    ///< roll this amount in x
    1848              int dy)                    ///< roll this amount in y
     1920psImageRoll(psImage *out,               //!< Image to output, or NULL
     1921            const psImage *input,       ///< roll this image
     1922            int dx,                     ///< roll this amount in x
     1923            int dy                      ///< roll this amount in y
     1924    );
    18491925\end{verbatim}
    18501926
     
    18531929\begin{verbatim}
    18541930psStats *
    1855 psImageGetStats (psImage *input,        ///< image (or subimage) to calculate stats
    1856                  psStats *stats)        ///< defines statistics to be calculated
     1931psImageGetStats(const psImage *input,   ///< image (or subimage) to calculate stats
     1932                psStats *stats          ///< defines statistics to be calculated & target
     1933    );
    18571934\end{verbatim}
    18581935
     
    18611938\begin{verbatim}
    18621939psHistogram *
    1863 psImageHistogram (psHistogram *hist,    ///< input histogram description & target
    1864                   psImage *input)       ///< determine histogram of this image
     1940psImageHistogram(psHistogram *hist,     ///< input histogram description & target
     1941                 const psImage *input   ///< determine histogram of this image
     1942    );
    18651943\end{verbatim}
    18661944
     
    18701948\begin{verbatim}
    18711949psPolynomial2D *
    1872 psImageFitPolynomial (psImage *input,   ///< image to fit
    1873                       psPolynomial2D *coeffs) ///< coefficient structure carries in desired terms
     1950psImageFitPolynomial(const psImage *input, ///< image to fit
     1951                     psPolynomial2D *coeffs ///< coefficient structure carries in desired terms & target
     1952    );
    18741953\end{verbatim}
    18751954
     
    18801959\begin{verbatim}
    18811960int
    1882 psImageEvalPolynomial (psImage *input,  ///< image to fit
    1883                        psPolynomial2D *coeffs) ///< coefficient structure carries in desired terms
     1961psImageEvalPolynomial(const psImage *input, ///< image to fit
     1962                      const psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
     1963    );
    18841964\end{verbatim}
    18851965
     
    19001980\begin{verbatim}
    19011981psImage *
    1902 psImageReadSection (psImage *output,    ///< place data in this structure for output
    1903                     int x,              ///< starting x coord of region
    1904                     int y,              ///< starting y coord of region
    1905                     int nx,             ///< x size of region (-1 for full range)
    1906                     int ny,             ///< y size of region (-1 for full range)
    1907                     int z,              ///< plane of interest
    1908                     char *extname,      ///< MEF extension name ("PHU" for primary header)
    1909                     int extnum,         ///< MEF extension sequence number (-1 for PHU)
    1910                     char *filename)     ///< file to read data from
     1982psImageReadSection(psImage *output,     ///< place data in this structure for output
     1983                   int x,               ///< starting x coord of region
     1984                   int y,               ///< starting y coord of region
     1985                   int nx,              ///< x size of region (-1 for full range)
     1986                   int ny,              ///< y size of region (-1 for full range)
     1987                   int z,               ///< plane of interest
     1988                   const char *extname, ///< MEF extension name ("PHU" for primary header)
     1989                   int extnum,          ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     1990                   const char *filename ///< file to read data from
     1991    );
    19111992\end{verbatim}
    19121993 
     
    19161997\begin{verbatim}
    19171998psImage *
    1918 psImageFReadSection (psImage *output,   ///< place data in this structure for output
    1919                      int x,             ///< starting x coord of region           
    1920                      int y,             ///< starting y coord of region           
    1921                      int dx,            ///< x size of region (-1 for full range)         
    1922                      int dy,            ///< y size of region (-1 for full range)         
    1923                      int z,             ///< plane of interest                     
    1924                      char *extname,     ///< MEF extension name ("PHU" for primary header)                         
    1925                      FILE *f)           ///< file descriptor to read data from             
     1999psImageFReadSection(psImage *output,    ///< place data in this structure for output
     2000                    int x,              ///< starting x coord of region           
     2001                    int y,              ///< starting y coord of region           
     2002                    int dx,             ///< x size of region (-1 for full range)         
     2003                    int dy,             ///< y size of region (-1 for full range)         
     2004                    int z,              ///< plane of interest                     
     2005                    const char *extname, ///< MEF extension name ("PHU" for primary header)
     2006                    int extnum,         ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     2007                    FILE *f     ///< file descriptor to read data from             
     2008    );
    19262009\end{verbatim}
    19272010
     
    19362019\begin{verbatim}
    19372020psImage *
    1938 psImageWriteSection (psImage *input,    ///< image to write out
    1939                      int x,             ///< starting x coord of region           
    1940                      int y,             ///< starting y coord of region           
    1941                      int z,             ///< plane of interest                     
    1942                      char *extname,     ///< MEF extension name ("PHU" for primary header)
    1943                      char *filename)    ///< file to write data to                 
     2021psImageWriteSection(psImage *input,    ///< image to write out
     2022                    int x,              ///< starting x coord of region           
     2023                    int y,              ///< starting y coord of region           
     2024                    int z,              ///< plane of interest                     
     2025                    const char *extname, ///< MEF extension name ("PHU" for primary header)
     2026                    int extnum,         ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     2027                    const char *filename ///< file to write data to               
     2028    );
    19442029\end{verbatim}
    19452030
     
    19472032\begin{verbatim}
    19482033psImage *
    1949 psImageFWriteSection(psImage *input,    ///< image to write out
    1950                      int x,             ///< starting x coord of region           
    1951                      int y,             ///< starting y coord of region           
    1952                      int z,             ///< plane of interest                     
    1953                      char *extname,     ///< MEF extension name                   
    1954                      FILE *f)           ///< file descriptor to write data to             
     2034psImageFWriteSection(psImage *input,    ///< image to write out
     2035                     int x,             ///< starting x coord of region           
     2036                     int y,             ///< starting y coord of region           
     2037                     int z,             ///< plane of interest                     
     2038                     const char *extname, ///< MEF extension name                         
     2039                     int extnum,        ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     2040                     FILE *f            ///< file descriptor to write data to             
     2041    );
    19552042\end{verbatim}
    19562043
     
    19612048return an error. 
    19622049\begin{verbatim}
    1963 struct psMetadata *
    1964 psImageReadHeader(struct psMetadata *output,    ///< read data to this structure
    1965                   char *extname,        ///< MEF extension name ("PHU" for primary header)
    1966                   int extnum,           ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    1967                   char *filename)       ///< file to read from
     2050psMetadata *
     2051psImageReadHeader(psMetadata *output,   ///< read data to this structure
     2052                  const char *extname,  ///< MEF extension name ("PHU" for primary header)
     2053                  int extnum,           ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     2054                  const char *filename  ///< file to read from
     2055    );
    19682056\end{verbatim}
    19692057
     
    19712059structure. 
    19722060\begin{verbatim}
    1973 struct psMetadata *
    1974 psImageFReadHeader (struct psMetadata *output, ///< read data to this structure
    1975                    char *extname,       ///< MEF extension name ("PHU" for primary header)
    1976                    int extnum,          ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    1977                    FILE *f)             ///< file descriptor to read from
     2061psMetadata *
     2062psImageFReadHeader(psMetadata *output, ///< read data to this structure
     2063                   const char *extname, ///< MEF extension name ("PHU" for primary header)
     2064                   int extnum,          ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
     2065                   FILE *f              ///< file descriptor to read from
     2066    );
    19782067\end{verbatim}
    19792068
     
    19822071\begin{verbatim}
    19832072psImage *
    1984 psImageFFT (psImage *input,             ///< image to FFT
    1985             int direction)              ///< FFT direction
     2073psImageFFT(psImage *output,             //!< Output image
     2074           const psImage *input,        ///< image to FFT
     2075           int direction                ///< FFT direction
     2076    );
    19862077\end{verbatim}
    19872078
     
    19912082\begin{verbatim}
    19922083int
    1993 psImageClip (psImage *input,            ///< clip this image
    1994              float min,                 ///< clip pixels with values < min
    1995              float vmin,                ///< set min-clipped pixels to vmin
    1996              float max,                 ///< clip pixels with values > max
    1997              float vmax)                ///< set max-clipped pixels to vmax
     2084psImageClip(psImage *input,             ///< clip this image
     2085            float min,                  ///< clip pixels with values < min
     2086            float vmin,                 ///< set min-clipped pixels to vmin
     2087            float max,                  ///< clip pixels with values > max
     2088            float vmax                  ///< set max-clipped pixels to vmax
     2089    );
    19982090\end{verbatim}
    19992091
     
    20032095\begin{verbatim}
    20042096int
    2005 psImageClipNaN (psImage *input,         ///< clip this image
    2006                 float value)            ///< set nan pixels to this value
     2097psImageClipNaN(psImage *input,          ///< clip this image & target
     2098               float value              ///< set nan pixels to this value
     2099    );
    20072100\end{verbatim}
    20082101
     
    20162109\begin{verbatim}
    20172110int
    2018 psImageOverlaySection (psImage *image,          ///< input image
    2019                 psImage *overlay,       ///< image to overlay
    2020                 int x0,                 ///< x offset of overlay subimage
    2021                 int y0,                 ///< y offset of overlay subimage
    2022                 char *operator)         ///< overlay operation
    2023 \end{verbatim}
     2111psImageOverlaySection(psImage *image,   ///< input image & target
     2112                      const psImage *overlay, ///< image to overlay
     2113                      int x0,           ///< x offset of overlay subimage
     2114                      int y0,           ///< y offset of overlay subimage
     2115                      const char *operator ///< overlay operation
     2116    );
     2117\end{verbatim}
     2118
     2119%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    20242120
    20252121\subsection{Astrometry}
     
    21722268typedef struct {
    21732269    int nCells;                         ///< Number of Cells assigned
    2174     struct psCell *cells;               ///< Cells in the Chip
    2175 
    2176     psMetaDataSet *md;                  ///< Chip-level metadata
     2270    psCell *cells;                      ///< Cells in the Chip
     2271
     2272    psMetaDataSet *md;                  ///< Chip-level metadata
    21772273    psCoordXform *chipToFPA;            ///< Transformations from chip coordinates to FPA coordinates
    2178 
    2179     struct psFPA *parentFPA;            ///< FPA which contains this chip
     2274    psCoordXform *FPAtoChip;            //!< Transformations from FPA coordinates to chip
     2275
     2276    struct psFPA *parentFPA;            ///< FPA which contains this chip
    21802277} psChip;
    21812278\end{verbatim}
     
    22072304    int nChips;                         ///< Number of Cells assigned
    22082305    int nAlloc;                         ///< Number of Cells available
    2209     struct psChip *chips;               ///< Chips in the Focal Plane Array
    2210 
    2211     psMetaDataSet *md;                  ///< FPA-level metadata
    2212     psDistortion *TPtoFP;               ///< Transformation term from
    2213     psDistortion *FPtoTP;               ///< Transformation term from
    2214     psFixedPattern *pattern;            //!< Fixed pattern residual offsets
     2306    psChip *chips;                      ///< Chips in the Focal Plane Array
     2307
     2308    psMetaDataSet *md;                  ///< FPA-level metadata
     2309    psDistortion *TPtoFP;               ///< Transformation term from
     2310    psDistortion *FPtoTP;               ///< Transformation term from
     2311    psFixedPattern *pattern;            //!< Fixed pattern residual offsets
    22152312    psExposure *exp;                    ///< information about this exposure
    22162313    psPhotSystem colorPlus, colorMinus; ///< Colour reference
     
    22302327
    22312328\begin{verbatim}
    2232 /** Information needed (by SLALIB) to convert Apparent to Observed Position */
     2329/** Information needed (by SLALib) to convert Apparent to Observed Position */
    22332330typedef struct {
    22342331    double latitude;                    ///< geodetic latitude (radians)
     
    23412438/** returns Chip in FPA which contains the given FPA coordinate */
    23422439psChip *
    2343 psChipInFPA (psFPA *fpa,                ///< FPA description
    2344              psCoord *coord             ///< coordinate in FPA
    2345              );
     2440psChipInFPA (psChip *out,               //!< Chip to return, or NULL
     2441             const psFPA *fpa,          ///< FPA description
     2442             const psCoord *coord       ///< coordinate in FPA
     2443             );
    23462444\end{verbatim}
    23472445
     
    23492447/** returns Cell in Chip which contains the given chip coordinate */
    23502448psCell *
    2351 psCellInChip (psChip *chip,             ///< chip description
    2352               psCoord *coord            ///< coordinate in chip
    2353               );
     2449psCellInChip(psCell *out,               //!< Cell to return, or NULL
     2450             const psChip *chip,        ///< chip description
     2451             const psCoord *coord       ///< coordinate in chip
     2452             );
    23542453\end{verbatim}
    23552454
     
    23612460/** Return the cell in FPA which contains the given FPA coordinates */
    23622461psCell *
    2363 psCellInFPA(psCell *out,                //!< Cell to return, or NULL
    2364             psFPA *fpa,                 //!< FPA description
    2365             psCoord *coord              //!< Coordinate in FPA
    2366             );
     2462psCellInFPA(psCell *out,                //!< Cell to return, or NULL
     2463            const psFPA *fpa,           //!< FPA description
     2464            const psCoord *coord        //!< Coordinate in FPA
     2465            );
    23672466\end{verbatim}
    23682467
     
    23982497
    23992498\begin{verbatim}
    2400 /** returns Chip in FPA which contains the given FPA coordinate */
    2401 psChip *
    2402 psChipInFPA (psChip *out,               //!< Chip to return, or NULL
    2403              psFPA *fpa,                ///< FPA description
    2404              psCoord *coord             ///< coordinate in FPA
    2405              );
    2406 \end{verbatim}
    2407 
    2408 \begin{verbatim}
    2409 /** returns Cell in Chip which contains the given chip coordinate */
    2410 psCell *
    2411 psCellInChip(psCell *out,               //!< Cell to return, or NULL
    2412              psChip *chip,              ///< chip description
    2413              psCoord *coord             ///< coordinate in chip
    2414              );
    2415 \end{verbatim}
    2416 
    2417 \begin{verbatim}
    2418 /** Return the cell in FPA which contains the given FPA coordinates */
    2419 psCell *
    2420 psCellInFPA(psCell *out,                //!< Cell to return, or NULL
    2421             psFPA *fpa,                 //!< FPA description
    2422             psCoord *coord              //!< Coordinate in FPA
    2423             );
    2424 \end{verbatim}
    2425 
    2426 \begin{verbatim}
    24272499/** Convert (RA,Dec) to cell and cell coordinates */
    24282500psCoord *
     
    24362508/** Convert cell and cell coordinate to (RA,Dec) */
    24372509psCoord *
    2438 psCoordCellToSky(psCoord *out,          //!< Coordinates to return, or NULL
    2439                  const psCell *cell,    //!< Cell to get coordinates for
    2440                  psCoord *coord         //!< cell coordinates to transform
    2441                 );
     2510psCoordCellToSky(psCoord *out,          //!< Coordinates to return, or NULL
     2511                 const psCell *cell,    //!< Cell to get coordinates for
     2512                 const psCoord *coord   //!< cell coordinates to transform
     2513                );
    24422514\end{verbatim}
    24432515
     
    24452517/** Quick and dirty cell to (RA,Dec) --- employs cellToSky transformation */
    24462518psCoord *
    2447 psCoordCellToSkyQuick(psCoord *out,     //!< Coordinates to return, or NULL
    2448                       const psCell *cell, //!< Cell description
    2449                       psCoord *coord    //!< cell coordinates to transform
    2450                       );
     2519psCoordCellToSkyQuick(psCoord *out,     //!< Coordinates to return, or NULL
     2520                      const psCell *cell, //!< Cell description
     2521                      const psCoord *coord //!< cell coordinates to transform
     2522                      );
    24512523\end{verbatim}
    24522524
     
    24542526/** Convert (RA,Dec) to tangent plane coords */
    24552527psCoord *
    2456 psCoordSkyToTP(psCoord *out,            //!< Coordinates to return, or NULL
    2457                psexposure *exp,         //!< Exposure description
    2458                psCoord *coord           //!< input Sky coordinate
    2459                );
     2528psCoordSkyToTP(psCoord *out,            //!< Coordinates to return, or NULL
     2529               const psExposure *exp,   //!< Exposure description
     2530               const psCoord *coord     //!< input Sky coordinate
     2531               );
    24602532\end{verbatim}
    24612533
     
    24632535/** Convert tangent plane coords to focal plane coordinates */
    24642536psCoord *
    2465 psCoordTPtoFPA(psCoord *out,            //!< Coordinates to return, or NULL
    2466                const psFPA *fpa,        //!< FPA description
    2467                psCoord *coord           //!< input TP coordinate
    2468                );
     2537psCoordTPtoFPA(psCoord *out,            //!< Coordinates to return, or NULL
     2538               const psFPA *fpa,        //!< FPA description
     2539               const psCoord *coord     //!< input TP coordinate
     2540               );
    24692541\end{verbatim}
    24702542
     
    24722544/** converts the specified FPA coord to the coord on the given Chip */
    24732545psCoord *
    2474 psCoordFPAtoChip (psCoord *out,         //!< Coordinates to return, or NULL
    2475                   psFPA *fpa,           ///< FPA description
    2476                   psChip *chip,         ///< Chip of interest
    2477                   psCoord *coord        ///< input FPA coordinate
    2478                   );
     2546psCoordFPAtoChip (psCoord *out,         //!< Coordinates to return, or NULL
     2547                  const psChip *chip,   ///< Chip of interest
     2548                  const psCoord *coord  ///< input FPA coordinate
     2549                  );
    24792550\end{verbatim}
    24802551
     
    24822553/** converts the specified Chip coord to the coord on the given Cell */
    24832554psCoord *
    2484 psCoordChiptoCell (psCoord *out,        //!< Coordinates to return, or NULL
    2485                    psChip *chip,        ///< Chip description
    2486                    psCell *cell,        ///< Cell of interest
    2487                    psCoord *coord       ///< input Chip coordinate
    2488                    );
     2555psCoordChiptoCell (psCoord *out,        //!< Coordinates to return, or NULL
     2556                   const psCell *cell,  ///< Cell of interest
     2557                   const psCoord *coord ///< input Chip coordinate
     2558                   );
    24892559\end{verbatim}
    24902560
     
    24922562/** converts the specified Cell coord to the coord on the parent Chip */
    24932563psCoord *
    2494 psCoordCelltoChip (psCoord *out,        //!< Coordinates to return, or NULL
    2495                    psCell *cell,        ///< Cell description
    2496                    psCoord *coord       ///< input Cell coordinate
    2497                    );
     2564psCoordCelltoChip (psCoord *out,        //!< Coordinates to return, or NULL
     2565                   const psCell *cell,  ///< Cell description
     2566                   const psCoord *coord ///< input Cell coordinate
     2567                   );
    24982568\end{verbatim}
    24992569
     
    25012571/** converts the specified Chip coord to the coord on the parent FPA */
    25022572psCoord *
    2503 psCoordChiptoFPA (psCoord *out,         //!< Coordinates to return, or NULL
    2504                   psChip *chip,         ///< Chip description
    2505                   psCoord *coord        ///< input Chip coordinate
    2506                   );
     2573psCoordChiptoFPA (psCoord *out,         //!< Coordinates to return, or NULL
     2574                  const psChip *chip,   ///< Chip description
     2575                  const psCoord *coord  ///< input Chip coordinate
     2576                  );
    25072577\end{verbatim}
    25082578
     
    25102580/** Convert focal plane coords to tangent plane coordinates */
    25112581psCoord *
    2512 psCoordFPAToTP(psCoord *out,            //!< Coordinates to return, or NULL
    2513                psFPA *fpa,              //!< FPA description
    2514                psCoord *coord           //!< input FPA coordinate
    2515                );
     2582psCoordFPAToTP(psCoord *out,            //!< Coordinates to return, or NULL
     2583               const psFPA *fpa,        //!< FPA description
     2584               const psCoord *coord     //!< input FPA coordinate
     2585               );
    25162586\end{verbatim}
    25172587
     
    25192589/** Convert tangent plane coords to (RA,Dec) */
    25202590psCoord *
    2521 psCoordTPtoSky(psCoord *out,            //!< Coordinates to return, or NULL
    2522                psExposure *exp,         //!< Exposure description
    2523                psCoord *coord           //!< input TP coordinate
    2524                );
     2591psCoordTPtoSky(psCoord *out,            //!< Coordinates to return, or NULL
     2592               const psExposure *exp,   //!< Exposure description
     2593               const psCoord *coord     //!< input TP coordinate
     2594               );
    25252595\end{verbatim}
    25262596
     
    25282598/** Convert Cell coords to FPA coordinates */
    25292599psCoord *
    2530 psCoordCellToFPA(psCoord *out,          //!< Coordinates to return, or NULL
    2531                  psCell *cell,          //!< Cell description
    2532                  psCoord *coord         //!< Input cell coordinates
    2533                 );
     2600psCoordCellToFPA(psCoord *out,          //!< Coordinates to return, or NULL
     2601                 const psCell *cell,    //!< Cell description
     2602                 const psCoord *coord   //!< Input cell coordinates
     2603                );
    25342604\end{verbatim}
    25352605
     
    25942664fields:
    25952665\begin{verbatim}
    2596 /*
    2597  * A struct to define a single item of metadata
    2598  */
     2666/** A struct to define a single item of metadata */
    25992667typedef struct {
    2600     const int id;                       // unique ID for this item
    2601    
    2602     char *name;                         // Name of item
    2603     psMetaDataType type;                // type of this item
     2668    const int id;                       //!< unique ID for this item
     2669    char *restrict name;                //!< Name of item
     2670    psMetaDataType type;                //!< type of this item
     2671    psMetaDataFlags flags;              //!< flags associated with this item
    26042672    const union {
    2605         float f;                        // floating value
    2606         int i;                          // integer value
    2607         void *v;                        // other type
    2608     } val;                              // value of metadata
    2609     char *comment;                      // optional comment ("", not NULL)
     2673        float f;                        //!< floating value
     2674        int i;                          //!< integer value
     2675        void *v;                        //!< other type
     2676    } val;                              //!< value of metadata
     2677    char *comment;                      //!< optional comment ("", not NULL)
     2678    psDlist *restrict items;            //!< list of psMetaDataItems with the same name
    26102679} psMetaDataItem;
    26112680\end{verbatim}
     
    26232692\code{psMetaDataType} (see also table \ref{tabMetaDataTypes}); the initial defined values are:
    26242693\begin{verbatim}
    2625 /*
    2626  * Possible types of metadata. 
    2627  */
    2628 typedef enum {                          // type of val is:
    2629     psMetaFloat,                        // float (.f)
    2630     psMetaInt,                          // int (.i)
    2631     psMetaStr,                          // string (.v)
    2632     psMetaImg,                          // image (.v)
    2633     psMetaJPEG,                         // JPEG (.v)
    2634     psMetaPNG,                          // PNG (.v)
    2635     psMetaAstrom,                       // astrometric coefficients (.v)
    2636     psMetaUnknown,                      // other (.v)
    2637     psMetaNType                         // Number of types; must be last
     2694/** Possible types of metadata. */
     2695typedef enum {                          //!< type of val is:
     2696    PS_META_ITEM_SET = 0,               //!< NULL; metadata is in psMetaDataType.items
     2697    PS_META_FLOAT,                      //!< float (.f)
     2698    PS_META_INT,                        //!< int (.i)
     2699    PS_META_STR,                        //!< string (.v)
     2700    PS_META_IMG,                        //!< image (.v)
     2701    PS_META_JPEG,                       //!< JPEG (.v)
     2702    PS_META_PNG,                        //!< PNG (.v)
     2703    PS_META_ASTROM,                     //!< astrometric coefficients (.v)
     2704    PS_META_UNKNOWN,                    //!< other (.v)
     2705    PS_META_NTYPE                       //!< Number of types; must be last
    26382706} psMetaDataType;
    26392707\end{verbatim}
     
    26432711\textbf{Value} & \textbf{Type} & \textbf{member of union} & \textbf{Comments}\\
    26442712\hline
    2645 psMetaFloat & float & f & value, not pointer, is stored \\
    2646 psMetaInt & int & i &  value, not pointer, is stored \\
    2647 psMetaStr & string & v &  value, not pointer to original, is stored \\
    2648 psMetaImg & psImage & v &  \\
    2649 psMetaJPEG & JPEG & v &  \\
    2650 psMetaPNG & PNG & v &  \\
    2651 psMetaAstrom & psAstrom & v &  \\
    2652 psMetaUnknown & other & v &  \\
    2653 psMetaNType & (none) & & The number of types defined
     2713PS_META_FLOAT & float & f & value, not pointer, is stored \\
     2714PS_META_INT & int & i &  value, not pointer, is stored \\
     2715PS_META_STR & string & v &  value, not pointer to original, is stored \\
     2716PS_META_IMG & psImage & v &  \\
     2717PS_META_JPEG & JPEG & v &  \\
     2718PS_META_PNG & PNG & v &  \\
     2719PS_META_ASTROM & psAstrom & v &  \\
     2720PS_META_UNKNOWN & other & v &  \\
     2721PS_META_NTYPE & (none) & & The number of types defined
    26542722\end{tabular}
    26552723\begin{caption}{Supported Metadata Types}
     
    26622730
    26632731\begin{verbatim}
     2732/** A set of metadata */
    26642733typedef struct {
    2665     psDlist *list;                      // list of psMetaDataItem
    2666     psHash *table;                      // hash table of the same metadata
     2734    psDlist *restrict list;             //!< list of psMetaDataItem
     2735    psHash *restrict table;             //!< hash table of the same metadata
    26672736} psMetaDataSet;
    26682737\end{verbatim}
     
    27452814
    27462815\begin{verbatim}
    2747 psMetaDataItem *psMetaDataItemAlloc(
    2748     psMetaDataType type,                // type of this piece of metadata
    2749     const void *val,                    // value of new item
    2750                                         // N.b. a pointer even if the item
    2751                                         // is of type e.g. int
    2752     const char *comment,                // comment associated with item
    2753     const char *name,                   // name of new item of metadata (may be an sprintf format)
    2754     ...);                               // possible arguments for name format
    2755 
    2756 void psMetaDataItemFree(psMetaDataItem *ms); // piece of metadata to destroy
    2757 
    2758 psMetaDataSet *psMetaDataSetAlloc(void);          // make a new set of metadata
    2759 void psMetaDataSetDel(psMetaDataSet *ms); // destroy a set of metadata
    2760 
    2761 /*****************************************************************************/
    2762 /*
    2763  * Utilities
    2764  */
    2765 psMetaDataItem *psMetaDataAppend(psMetaDataSet *restrict ms, psMetaDataItem *restrict item);
    2766 psMetaDataItem *psMetaDataRemove(psMetaDataSet *restrict ms, const char *restrict key);
    2767 
    2768 void psMetaDataSetIterator(psMetaDataSet *ms);
    2769 psMetaDataItem *psMetaDataGetNext(psMetaDataSet *ms);
    2770 psMetaDataItem *psMetaDataLookup(const psMetaDataSet *ms, const char *key);
    2771 
    2772 void psMetaDataItemPrint(FILE *fd,              // file descriptor to write to
    2773                          const psMetaDataItem *ms); // item of metadata to print
     2816/** Constructor */
     2817psMetaDataItem *psMetaDataItemAlloc(int typeFlags, //!< type of this piece of metadata + flags
     2818                                    const void *val, //!< value of new item N.b. a pointer even if the item
     2819                                                     //!< is of type e.g. int
     2820                                    const char *comment, //!< comment associated with item
     2821                                    const char *name, //!< name of new item of metadata (may be in sprintf
     2822                                                      //!< format)
     2823                                    ... //!< possible arguments for name format
     2824    );
     2825
     2826/** Destructor */
     2827void psMetaDataItemFree(psMetaDataItem *ms //!< piece of metadata to destroy
     2828    );
     2829/** Constructor */
     2830psMetaDataSet *psMetaDataSetAlloc(void);   //!< make a new set of metadata
     2831
     2832/** Destructor */
     2833void psMetaDataSetFree(psMetaDataSet *ms //!< destroy a set of metadata
     2834    );
     2835
     2836/**** Utilities **********************************************************************/
     2837
     2838/// Add entry to the end of the metadata set
     2839psMetaDataItem *psMetaDataAppend(psMetaDataSet *restrict ms, //!< Metadata set to add to
     2840                                 psMetaDataItem *restrict item //!< Metatdata to add
     2841    );
     2842
     2843/// delete entry from the metadata set
     2844psMetaDataItem *psMetaDataRemove(psMetaDataSet *restrict ms, //!< Metadata set to delete from
     2845                                 const char *restrict key //!< Key to delete
     2846    );
     2847
     2848/// reset the iterator to the start of the list
     2849void psMetaDataSetIterator(psMetaDataSet *ms //!< Metadata set to set iterator for
     2850    );
     2851
     2852/// get the next entry in the sequence
     2853psMetaDataItem *psMetaDataGetNext(psMetaDataSet *restrict ms, //!< Metadata set to get from
     2854                                  const char *restrict match //!< Match this
     2855    );
     2856
     2857/// find the metadata with the specified key
     2858psMetaDataItem *psMetaDataLookup(const psMetaDataSet *restrict ms, //!< Metadata set to look up
     2859                                 const char *restrict key //!< Key to find
     2860    );
     2861
     2862/// print metadata item to the specified stream
     2863void psMetaDataItemPrint(FILE *fd,              //!< file descriptor to write to
     2864                         const psMetaDataItem *restrict ms, //!< item of metadata to print
     2865                         const char *prefix        //!< print this at the beginning of each line
     2866    );
    27742867\end{verbatim}
    27752868
     
    28342927\begin{verbatim}
    28352928/** apply the coordinate transformation to the given coordinate */
    2836 psCoord *psCoordXformApply (psCoordXform *frame, ///< coordinate transformation
    2837                             psCoord *coords) ///< input coordiate
    2838 ;
     2929psCoord *psCoordXformApply (psCoord *out, //!< Output coordinates, or NULL
     2930                            const psCoordXform *frame, ///< coordinate transformation
     2931                            const psCoord *coords ///< input coordiate
     2932    );
    28392933\end{verbatim}
    28402934
    28412935\begin{verbatim}
    28422936/** apply the optical distortion to the given coordinate, magnitude, color */
    2843 psCoord *psDistortionApply (psDistortion *pattern, ///< optical distortion pattern
    2844 psCoord *coords,                        ///< input coordinate
    2845 float mag,                              ///< magnitude of object
    2846 float color)                            ///< color of object
    2847 ;
     2937psCoord *psDistortionApply (psCoord *out, //!< Output coordinates, or NULL
     2938                            const psdistortion *pattern, ///< optical distortion pattern
     2939                            const psCoord *coords, ///< input coordinate
     2940                            float mag,  ///< magnitude of object
     2941                            float color ///< color of object
     2942    );
    28482943\end{verbatim}
    28492944
     
    28582953psCoord *
    28592954psGetOffset(const psCoord *restrict position1, //!< Position 1
    2860             const psCoord *restrict position2, //!< Position 2
    2861             const char *type            //!< Type of offset: Linear, Spherical/Arcsec, Spherical/Degreees etc
     2955            const psCoord *restrict position2, //!< Position 2
     2956            const char *type            //!< Type of offset: Linear, Spherical/Arcsec, Spherical/Degreees etc
    28622957    );
    28632958\end{verbatim}
     
    28672962psCoord *
    28682963psApplyOffset(const psCoord *restrict position, //!< Position
    2869               const psCoord *restrict offset, //!< Offset
    2870               const char *type          //!< Type of offset: Linear, Spherical/Arcsec, Spherical/Degreees etc
     2964              const psCoord *restrict offset, //!< Offset
     2965              const char *type          //!< Type of offset: Linear, Spherical/Arcsec, Spherical/Degreees etc
    28712966    );
    28722967\end{verbatim}
     
    28812976/** Get Sun Position */
    28822977psCoord *
    2883 psGetSunPos(float mjd)                  //!< MJD to get position for
    2884 ;
     2978psGetSunPos(float mjd                   //!< MJD to get position for
     2979    );
    28852980\end{verbatim}
    28862981
     
    28882983/** Get Moon position */
    28892984psCoord *
    2890 psGetMoonPos(float mjd,                 //!< MJD to get position for
    2891              double latitude,           //!< Latitude for apparent position
    2892              double longitude)          //!< Longitude for apparent position
    2893 ;
     2985psGetMoonPos(float mjd,                 //!< MJD to get position for
     2986             double latitude,           //!< Latitude for apparent position
     2987             double longitude           //!< Longitude for apparent position
     2988    );
    28942989\end{verbatim}
    28952990
     
    28972992/** Get Moon phase */
    28982993float
    2899 psGetMoonPhase(float mjd)               //!< MJD to get phase for
    2900 ;
     2994psGetMoonPhase(float mjd                //!< MJD to get phase for
     2995    );
    29012996\end{verbatim}
    29022997
     
    29042999/** Get Planet positions */
    29053000psCoord *
    2906 psGetSolarSystemPos(char *solarSystemObject, //!< Named S.S. object
    2907                     float mjd)          //!< MJD to get position for
    2908 ;
     3001psGetSolarSystemPos(const char *solarSystemObject, //!< Named S.S. object
     3002                    float mjd           //!< MJD to get position for
     3003    );
    29093004\end{verbatim}
    29103005
     
    29173012/** Convert ICRS to Ecliptic */
    29183013psCoord *
    2919 psCoordinatesItoE(const psCoord *restrict coordinates) //!< ICRS coordinates to convert
    2920 ;
     3014psCoordinatesItoE(const psCoord *restrict coordinates //!< ICRS coordinates to convert
     3015    );
    29213016\end{verbatim}
    29223017
     
    29243019/** Convert Ecliptic to ICRS */
    29253020psCoord *
    2926 psCoordinatesEtoI(const psCoord *restrict coordinates) //!< Ecliptic coordinates to convert
    2927 ;
     3021psCoordinatesEtoI(const psCoord *restrict coordinates //!< Ecliptic coordinates to convert
     3022    );
    29283023\end{verbatim}
    29293024
     
    29313026/** Convert ICRS to Galactic */
    29323027psCoord *
    2933 psCoordinatesItoG(const psCoord *restrict coordinates) //!< ICRS coordinates to convert
    2934 ;
     3028psCoordinatesItoG(const psCoord *restrict coordinates //!< ICRS coordinates to convert
     3029    );
    29353030\end{verbatim}
    29363031
     
    29383033/** Convert Galactic to ICRS */
    29393034psCoord *
    2940 psCoordinatesGtoI(const psCoord *restrict coordinates) //!< Galactic coordinates to convert
    2941 ;
     3035psCoordinatesGtoI(const psCoord *restrict coordinates //!< Galactic coordinates to convert
     3036    );
    29423037\end{verbatim}
    29433038
Note: See TracChangeset for help on using the changeset viewer.