Changeset 4794 for trunk/doc/pslib/psLibSDRS.tex
- Timestamp:
- Aug 16, 2005, 1:18:38 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/doc/pslib/psLibSDRS.tex (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/pslib/psLibSDRS.tex
r4719 r4794 1 %%% $Id: psLibSDRS.tex,v 1.32 4 2005-08-05 20:24:03price Exp $1 %%% $Id: psLibSDRS.tex,v 1.325 2005-08-16 23:18:38 price Exp $ 2 2 \documentclass[panstarrs,spec]{panstarrs} 3 3 … … 1666 1666 (supplied via \code{argc, argv}) into a metadata container of 1667 1667 \code{arguments}. The input \code{arguments} shall contain the list 1668 of possible arguments (lacking a leading dash) as the keywords 1669 providing the default values (of the appropriate type). As matching 1670 arguments are found on the command line, the values shall be read into 1671 the \code{arguments} metadata, with the appropriate type. Multiple 1672 values (i.e., when an argument takes two or more values) are specified 1673 using a \code{PS_DATA_METADATA_MULTI} list (i.e., by specifying a type 1674 with the \code{PS_META_DUPLICATE_OK} flag). A boolean argument shall 1675 be set to \code{true} by the presence of the argument itself (no value 1676 is specified). The arguments and their values shall be removed from 1677 the list of command line arguments as they are processed. The 1678 function shall return \code{false} without modifying the 1679 \code{arguments} if any argument (i.e., a string beginning with a 1680 dash; but not a string that does not start with a dash, which is 1681 likely a mandatory argument for the program) was encountered that is 1682 not present in the \code{arguments}. 1668 of possible arguments as the keywords providing the default values (of 1669 the appropriate type). As matching arguments are found on the command 1670 line, the values shall be read into the \code{arguments} metadata, 1671 with the appropriate type. Multiple values (i.e., when an argument 1672 takes two or more values) are specified using a 1673 \code{PS_DATA_METADATA_MULTI} list (i.e., by specifying a type with 1674 the \code{PS_META_DUPLICATE_OK} flag). A boolean argument shall be 1675 set to \code{true} by the presence of the argument itself (no value is 1676 specified). The arguments and their values shall be removed from the 1677 list of command line arguments as they are processed. The function 1678 shall return \code{false} without modifying the \code{arguments} if 1679 any argument (i.e., a string beginning with a dash; but not a string 1680 that does not start with a dash, which is likely a mandatory argument 1681 for the program; the purpose of this requirement is so that the 1682 default values are preserved) was encountered that is not present in 1683 the \code{arguments}. 1683 1684 1684 1685 \begin{prototype} … … 1690 1691 \code{psArgumentParse}) of the form: 1691 1692 \begin{verbatim} 1692 Optional arguments :1693 -names FREDThis is the comment from the first value1694 JIMThis is the comment from the second value1695 BOBThis is the comment from the third value1696 -answer 42This is a comment1697 -truth FALSEThis is another comment1693 Optional arguments, with default values: 1694 -names (FRED) This is the comment from the first value 1695 (JIM) This is the comment from the second value 1696 (BOB) This is the comment from the third value 1697 -answer (42) This is a comment 1698 -truth (FALSE) This is another comment 1698 1699 \end{verbatim} 1699 1700 Here the \code{arguments} contains three keywords, \code{names, magic, … … 1704 1705 the mandatory arguments. An example follows: 1705 1706 \begin{verbatim} 1706 void help(psMetadata *arguments, // Command-line arguments1707 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 1715 1707 int main(int argc, char *argv[]) 1716 1708 { 1717 1709 // Parse optional command-line arguments 1718 1710 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]); 1711 psMetadataAdd(arguments, PS_LIST_TAIL, "-string", PS_META_STR, "Test string", "SomeString"); 1712 psMetadataAdd(arguments, PS_LIST_TAIL, "-bool", PS_META_BOOL, "Test bool", false); 1713 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 1", 1); 1714 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 2", 2); 1715 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 3", 3); 1716 psMetadataAdd(arguments, PS_LIST_TAIL, "-float", PS_META_F32, "Test float", 1.234567); 1717 if (! psArgumentParse(arguments, &argc, argv) || argc != 3) { 1718 printf("\nName of the program here\n\n"); 1719 printf("Usage: %s INPUT OUTPUT\n\n", argv[0]); 1720 psArgumentHelp(arguments); 1721 psFree(arguments); 1728 1722 exit(EXIT_FAILURE); 1729 1723 } 1724 const char *inputName = argv[1]; // Name of input 1725 const char *outputName = argv[2]; // Name of output 1726 printf("Success: %s %s\n", inputName, outputName); 1727 1728 psString string = psMetadataLookupString(NULL, arguments, "-string"); 1729 float floating = psMetadataLookupF32(NULL, arguments, "-float"); 1730 bool boolean = psMetadataLookupBool(NULL, arguments, "-truth"); 1731 printf("String: %s\n", string); 1732 printf("Float: %f\n", floating); 1733 printf("Boolean: %d\n", boolean); 1734 1735 psMetadataItem *intItem = psMetadataLookup(arguments, "-int"); 1736 if (intItem->type == PS_META_MULTI) { 1737 psList *intMulti = intItem->data.V; 1738 psListIterator *intIter = psListIteratorAlloc(intMulti, PS_LIST_HEAD, false); 1739 psMetadataItem *intMultiItem = NULL; 1740 while (intMultiItem = psListGetAndIncrement(intIter)) { 1741 printf("Integer: %d\n", intMultiItem->data.S32); 1742 } 1743 psFree(intIter); 1744 } 1745 } 1746 \end{verbatim} 1747 1748 The above program should produce, on being given no arguments: 1749 \begin{verbatim} 1750 1751 Name of the program here 1752 1753 Usage: ./program INPUT OUTPUT 1754 1755 Optional arguments, with default values: 1756 -string (SomeString) Test string 1757 -bool (FALSE) Test bool 1758 -int (1) Test integer 1 1759 (2) Test integer 2 1760 (3) Test integer 3 1761 -float (1.234567e+00) Test float 1762 \end{verbatim} 1763 1764 and called with: \code{./program -string whatevers -float 9.876543 1765 -int 4 5 6 -bool input output}, then it should produce: 1766 1767 \begin{verbatim} 1768 Success: input output 1769 String: SomeString 1770 Float: 1.234567 1771 Boolean: 0 1772 Integer: 1 1773 Integer: 2 1774 Integer: 3 1730 1775 \end{verbatim} 1731 1776
Note:
See TracChangeset
for help on using the changeset viewer.
