IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 23, 2005, 3:31:03 PM (21 years ago)
Author:
Paul Price
Message:

Reworked psLookupTable functions so that the number of columns and
their types are defined by a scanf-like format string. Added
psVectorsReadFromFile and psLookupTableImport to generalise the
reading of tabular data from a file.

File:
1 edited

Legend:

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

    r3248 r3315  
    1 %%% $Id: psLibSDRS.tex,v 1.182 2005-02-17 02:34:56 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.183 2005-02-24 01:31:03 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    17871787polar motion vector as a function of date.
    17881788
     1789One of the key functionalities of a lookup table is to read data from
     1790an ordinary text file into an array of vectors.  This functionality is
     1791generally useful, and so we specify a separate function that may be
     1792called independently:
     1793\begin{verbatim}
     1794psArray *psVectorsReadFromFile(const char *filename, const char *format);
     1795\end{verbatim}
     1796\code{psVectorsReadFromFile} shall return an array of
     1797\code{psVector}s, read from the specified \code{filename}.  The file
     1798shall be plain text, consisting of an identical number of columns on
     1799each line, with the values separated by whitespace.  Lines commencing
     1800with a comment character (the pound sign, \code{#}) and blank lines
     1801shall be ignored.  The \code{format} is a \code{scanf}-like format
     1802which specifies the number of columns in the file, as well as their
     1803types.  The following formats shall be defined: \code{\%d} for psS32,
     1804\code{\%ld} for psS64, \code{\%f} for psF32, and \code{\%lf} for
     1805psF64.  A star (\code{*}) in the format shall indicate that the column
     1806is to be skipped.
     1807
     1808
    17891809\begin{verbatim}
    17901810typedef struct {
     1811    const char *filename;               ///< File from which data is to be read
     1812    const char *format;                 ///< scanf-like format string for file
     1813    unsigned int indexCol;              ///< Column of the index vector (starting at zero)
    17911814    psVector *index;                    ///< Index values
    17921815    psArray *values;                    ///< Corresponding values: an array of vectors
    1793     const char *filename;               ///< File from which table was read
    17941816    const psF64 validFrom, validTo;     ///< Range of validity
    17951817} psLookupTable;
    17961818\end{verbatim}
    17971819
    1798 \code{index} shall contain the index values, which shall be sorted in
    1799 increasing order.  The \code{values} shall consist of an array of
    1800 vectors, each of the same length as the \code{index} vector.  The
    1801 vectors (including the \code{index} and all vectors in the
    1802 \code{values} array) may be any numerical type except complex types.
    1803 The \code{filename} shall specify the file from which the table is to
    1804 be read.  The \code{validFrom} and \code{validTo} shall specify the
    1805 range of valid values for the index; in most cases, these will simply
    1806 be the first and last indices.
     1820\code{filename} shall specify the file from which the lookup table
     1821data is to be read.  \code{format} shall contain a \code{scanf}-like
     1822format string specifying how the columns are to be interpreted (see
     1823\code{psVectorsReadFromFile}).  \code{indexCol} shall specify the
     1824index of the column (with the first column having an index of zero)
     1825that will form the index values.  \code{index} shall contain the index
     1826values, which shall be sorted in increasing order.  The \code{values}
     1827shall consist of an array of vectors, each of the same length as the
     1828\code{index} vector.  The vectors (including the \code{index} and all
     1829vectors in the \code{values} array) may be any numerical type except
     1830complex types.  The \code{validFrom} and \code{validTo} shall specify
     1831the range of valid values for the index; in most cases, these will
     1832simply be the first and last indices.
    18071833
    18081834The constructor shall be:
    18091835\begin{verbatim}
    1810 psLookupTable *psLookupTableAlloc(const char *filename, int numValues);
    1811 \end{verbatim}
    1812 Here the \code{filename} indicates the file from which the table
    1813 shall be read when \code{psLookupTableRead} is
    1814 called. \code{numValues} indicates the number of vectors in the
    1815 \code{values} array.
    1816 
    1817 The destructor shall also free the components.
     1836psLookupTable *psLookupTableAlloc(const char *filename, ///< File from which to read
     1837                                  const char *format ///< scanf-like format string
     1838                                  int indexCol ///< Column of the index vector (starting at zero)
     1839                                  );
     1840\end{verbatim}
     1841This function shall allocate a \code{psLookupTable}, and set the
     1842appropriate values, but it shall not read the lookup table.  This is
     1843so that the lookup table can be specified at the initialisation of a
     1844program, but not read unless required.
     1845
     1846The destructor shall free all the components.
     1847
     1848\begin{verbatim}
     1849psLookupTable *psLookupTableImport(psLookupTable *table, ///< Lookup table into which to import
     1850                                   const psArray *vectors, ///< Array of vectors
     1851                                   int indexCol ///< Index of the index vector in the array of vectors
     1852                                   );
     1853\end{verbatim}
     1854\code{psLookupTableImport} shall import an array of vectors into a
     1855\code{table}.  If \code{table} is \code{NULL}, a new
     1856\code{psLookupTable} shall be allocated and returned.  The array of
     1857\code{vectors}, which was likely generated by
     1858\code{psVectorsReadFromFile}, are imported by setting the
     1859\code{table->index} to the vector specified by the \code{indexCol},
     1860and pointing the \code{table->values} array data to the remaining
     1861vectors in \code{vectors}.  Reference counters for the vectors shall
     1862be incremented as appropriate.  The \code{validFrom} and
     1863\code{validTo} members of the \code{table} shall be set to the first
     1864and last values in the index vector.  If the \code{index} vector is
     1865not sorted in the file, the lookup table shall be sorted prior to the
     1866function returning.
    18181867
    18191868\begin{verbatim}
    18201869int psLookupTableRead(psLookupTable *table);
    18211870\end{verbatim}
    1822 \code{psLookupTableRead} shall read the \code{table} from the
    1823 appropriate file and import the data into the \code{table}, and set
    1824 the \code{validFrom} and \code{validTo} on the basis of the first and
    1825 last values in the \code{table}.  Sufficient memory shall be allocated
    1826 to hold all the data in the specified file.  The file shall be plain
    1827 text, with index and values on separate lines, separated by
    1828 whitespace.  Lines commencing with a comment character (the pound
    1829 sign, \code{#}) and blank lines shall be ignored.
    1830 \code{table->values->n} in addition to the index shall be read on each
    1831 line.  If the \code{index} vector is not sorted in the file, the
    1832 lookup table shall be sorted prior to the function returning, but no
    1833 sort shall be performed if the indices were sorted in the file.  If
    1834 the input \code{table} has already been read from a file, the file
    1835 shall be re-read, and the contents replaced.  The function shall
    1836 return the number of lines read (not including ignored lines).
     1871\code{psLookupTableRead} combines \code{psVectorsReadFromFile} and
     1872\code{psLookupTableImport} to read the appropriate file and import the
     1873data into the extant \code{table}.  If the input \code{table} has
     1874already been read from a file, the file shall be re-read, and the
     1875contents replaced.  The function shall return the number of lines read
     1876(not including ignored lines).
    18371877
    18381878Interpolation on a lookup table is performed by the following
    18391879functions:
    18401880\begin{verbatim}
    1841 psF64 psLookupTableInterpolate(psLookupTable *table, psF64 index, int column);
    1842 psVector *psLookupTableInterpolateAll(psLookupTable *table, psF64 index);
     1881psF64 psLookupTableInterpolate(const psLookupTable *table, psF64 index, int column);
     1882psVector *psLookupTableInterpolateAll(const psLookupTable *table, psF64 index);
    18431883\end{verbatim}
    18441884Both functions shall interpolate the \code{table} at the provided
     
    18511891and \code{psLookupTableInterpolateAll} shall return \code{NULL} ---
    18521892that is, no attempt is made at extrapolation.
    1853 
    1854 
    1855 
    1856 
    18571893
    18581894%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset for help on using the changeset viewer.