IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2005, 7:17:50 PM (21 years ago)
Author:
Paul Price
Message:

Adding psArgumentParse (may need another iteration for format) and psArgumentHelp.

File:
1 edited

Legend:

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

    r4711 r4712  
    1 %%% $Id: psLibSDRS.tex,v 1.322 2005-08-05 03:51:16 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.323 2005-08-05 05:17:50 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    16591659are processed.  The function shall return the resultant logging level.
    16601660
     1661\begin{prototype}
     1662bool psArgumentParse(psMetadata *arguments, int *argc, char **argv);
     1663\end{prototype}
     1664
     1665\code{psArgumentParse} shall parse the command line arguments
     1666(supplied via \code{argc, argv}) into a metadata container of
     1667\code{arguments}.  The input \code{arguments} shall contain the list
     1668of possible arguments (lacking a leading dash) as the keywords
     1669providing the default values (of the appropriate type).  As matching
     1670arguments are found on the command line, the values shall be read into
     1671the \code{arguments} metadata, with the appropriate type.  Multiple
     1672values (i.e., when an argument takes two or more values) are specified
     1673using a \code{PS_DATA_METADATA_MULTI} list (i.e., by specifying a type
     1674with the \code{PS_META_DUPLICATE_OK} flag).  A boolean argument shall
     1675be set to \code{true} by the presence of the argument itself (no value
     1676is specified).  The arguments and their values shall be removed from
     1677the list of command line arguments as they are processed.  The
     1678function shall return \code{false} without modifying the
     1679\code{arguments} if any argument (i.e., a string beginning with a
     1680dash; but not a string that does not start with a dash, which is
     1681likely a mandatory argument for the program) was encountered that is
     1682not present in the \code{arguments}.
     1683
     1684\begin{prototype}
     1685void psArgumentHelp(psMetadata *arguments);
     1686\end{prototype}
     1687
     1688\code{psArgumentHelp} shall print to \code{stdout} a guide to the
     1689command-line \code{arguments} (containing the same information as for
     1690\code{psArgumentParse}) of the form:
     1691\begin{verbatim}
     1692Optional arguments:
     1693    -names      FRED    This is the comment from the first value
     1694                JIM     This is the comment from the second value
     1695                BOB     This is the comment from the third value
     1696    -answer     42      This is a comment
     1697    -truth      FALSE   This is another comment
     1698\end{verbatim}
     1699Here the \code{arguments} contains three keywords, \code{names, magic,
     1700truth}.  \code{names} has three values, \code{FRED, JIM, BOB}, stored
     1701as a \code{PS_DATA_METADATA_MULTI}, each with the comment as shown.
     1702
     1703It will be the responsibility of the user to supply information for
     1704the mandatory arguments.  An example follows:
     1705\begin{verbatim}
     1706void help(psMetadata *arguments,        // Command-line arguments
     1707          const char *programName       // Name of the program = argv[0]
     1708    )
     1709{
     1710    printf("Pan-STARRS Phase 2 processing\n\n");
     1711    printf("Usage: %s INPUT.fits OUTPUT.fits\n\n", programName);
     1712    psArgumentHelp(arguments);
     1713}
     1714
     1715int main(int argc, char *argv[])
     1716{
     1717    // Parse optional command-line arguments
     1718    psMetadata *arguments = psMetadataAlloc(); // The arguments, with default values
     1719    psMetadataAddStr(arguments, PS_LIST_TAIL, "bias", "Name of the bias image", NULL);
     1720    psMetadataAddStr(arguments, PS_LIST_TAIL, "dark", "Name of the dark image", NULL);
     1721    psMetadataAddStr(arguments, PS_LIST_TAIL, "flat", "Name of the flat-field image", NULL);
     1722    psMetadataAddS32(arguments, PS_LIST_TAIL, "chip", "Chip number to process (if positive)", -1);
     1723    psMetadataAddS32(arguments, PS_LIST_TAIL | PS_META_DUPLICATE_OK, "timerange", "The lower time value", 0);
     1724    psMetadataAddS32(arguments, PS_LIST_TAIL, "timerange", "The upper time value", 10);
     1725    psMetadataAddBool(arguments, PS_LIST_TAIL, "ok", "Is this OK?", FALSE);
     1726    if (! psArgumentParse(arguments, &argc, argv) || argc != 2) {
     1727        help(arguments, argv[0]);
     1728        exit(EXIT_FAILURE);
     1729    }
     1730\end{verbatim}
     1731
     1732
    16611733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    16621734
Note: See TracChangeset for help on using the changeset viewer.