casacore
Loading...
Searching...
No Matches
Inputs.h
Go to the documentation of this file.
1//# Inputs.h: a module for simple command line user interface classes
2//# Copyright (C) 1994,1995,1996,1999,2000
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_INPUTS_H
27#define CASA_INPUTS_H
28
29#include <casacore/casa/aips.h>
30
31#include <casacore/casa/Inputs/Input.h>
32#include <casacore/casa/Inputs/Param.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <module>
37//
38// <summary>
39// A module for simple command line user interface classes
40// </summary>
41
42// <prerequisite>
43// <li> String
44// <li> The C language int main(int argc, const char* argv[]) convention.
45// </prerequisite>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" demos="">
48//</reviewed>
49
50// <etymology>
51// The Inputs module name reflects the Casacore convention of pluralizing
52// the name of the major class it contains.
53// The Input class name is a reflection of it's role as the early command
54// line user interface for Casacore applications. This class provides "inputs"
55// in the form "key=value" or "-key value."
56//</etymology>
57//
58// <synopsis>
59
60// During the old AIPS++ prototyping stage a basic command line user
61// interface was developed. This attempt at easing the trouble of passing
62// information to an executable program resulted in a set of C++ classes
63// called Param and Input. The programmer may simply include the Input
64// class into their code and have immediate Command Line User Interface
65// (CLUI) capabilities. The programmer's Casacore application is run from
66// the unix level prompt by invoking its name and listing linearly on the
67// same command line the "keyword=values" or "-keyword values" associated
68// with proper execution. The Input and Param classes will successfully
69// parse the command line into the executable program and check for
70// appropriateness.
71
72// The CLUI capabilities are further extended to a Graphical User
73// Interface through the use of the Khoros Cantata environment. The user
74// starts up Cantata from the unix prompt and, by utilizing a series of
75// pull down windows, invisibly creates an X-based window for visual
76// display of all parameters associated with the Casacore application's
77// need for external input.
78
79// The basic command line user interface is an ordered series of
80// "keyword=value" pairs, which we call parameters. The names parameter
81// and keyword may correctly be used to refer to each other.
82//
83// The class Param (see Param.h) implements one single such parameter.
84// Values may be Int, Block<Int>, double, Block<double>, Bool, or
85// Strings. In addition to a name and a value, a Param parameter has a
86// variety of other attributes, such as a one-line help string (useful
87// when being prompted for input or with hypertext identifiers, etc...),
88// a type, a range and optional units. All of these attributes are
89// character strings; parsing and error checking is done at a different
90// (hidden) level. The programmer, however, will never interact with a
91// parameter through it's Param class interface. Interaction is done
92// with the class Input, which is a container of Param's, with a variety
93// of user interface attributes (help-level, debug-level, etc...).
94//
95// Although the programmer must supply the user interface with a number
96// of predefined program parameters, the user interface itself will
97// create a small number of system parameters (help=, debug=). The
98// purpose of these is to tell the task how to communicate with the user
99// and it's environment, and give the user control over these items. For
100// example, the user may want to see (debug) messages above a certain
101// threshold level. The programmer simply adds debug levels to their
102// code and allows the user to specify how deeply they wish the debugging
103// to progress.
104//
105// For example, a interactive UNIX shell session may look like:
106//
107//<srcblock>
108// 1% MyProgram key1=val1 key3=val3
109// 2% MyProgram key1=val1 key2=val3 debug=5
110// 3% MyProgram help=prompt
111// 4% MyProgram help=pane > prog.pane
112//</srcblock>
113//
114// In command 1% the user has set several parameters for the program
115// MyProgram to applicable values. The 2% command line invokes the
116// executable and sets the level of displayed debugging to the programmer
117// specified 5th level. Command 3%: the user is prompted, and parameter
118// default values are restored. Command 4% gives an example of the
119// self-describing mode of programs, where a pane description file for
120// Khoros has been constructed. The latter is the first step toward
121// building a Khoros Graphic User Interface.
122//
123// The Input class is a means for building a linked list of parameters
124// and gaining access to them once created. Input takes care of
125// system/environment variables and assigns their values within the
126// programmer's code. The linked list of parameters is limited only by
127// the number of names the programmer can dream up. The programmer need
128// not think hard on the order of definition of parameters in Input. The
129// list of key=values given on the command line by the user need not be
130// in any specific order.
131//
132// The definition of parameters is by simply creating an Input and then
133// using the appropriate Input Create member function. Then the
134// programmer adds to the list of parameters as necessary.
135// </synopsis>
136//
137// <example>
138// <srcblock>
139// 01 #include <casacore/casa/Inputs/Input.h> // need this if you want it to work
140// 02 #include <aips/Plot.h>
141// 03 int main(int argc, const char* argv[])
142// 04 {
143// 05 Input inputs(1);
144// 06 // Define our input structure
145// 07 inputs.version("Id: xyPlot.C,v 1.1 1993/01/29 20:45:48 bglenden Exp");
146// 08 inputs.create("xyfile",
147// 09 "/tmp/xy.aipsio",
148// 10 "File which contains xy vectors",
149// 11 "InFile");
150// 12 inputs.create("overplot", "False", "Multiple plots?", "Bool");
151// 13 inputs.create("lines", "True", "Plot lines or points?", "Bool");
152// 14
153// 15 // and Fill them from the command line
154// 16 inputs.readArguments(argc, argv);
155// 17
156// 18 try {
157// 19 const Char *filename = inputs.getString("xyfile");
158// 20 AipsIO xyfile(filename, ByteIO::Old);
159// 21 Vector<float> x, y;
160// 22 Plot plot;
161// 23
162// 24 xyfile >> x >> y; // initial vectors
163// 25 plot(x,y,inputs.getBool("lines"));
164// 26
165// 27 for (;;) { // forever
166// 28 xyfile >> x >> y;
167// 29 if (inputs.getBool("overplot") == True) {
168// 30 plot(x,y,inputs.getBool("lines"));
169// 31 } else {
170// 32 plot.newPlot();
171// 33 plot(x,y,inputs.getBool("lines"));
172// 34 }
173// 35 }
174// 36 } catch (AipsIOError x) {
175// 37 ; // nothing - no more data
176// 38 } catch (AllocError x) {
177// 39 cerr << "AllocError : " << x.what() << endl;
178// 40 cerr << "Size is : " << x.size() << endl;
179// 41 } catch (std::exception x) {
180// 42 cerr << "aipserror: error " << x.what() << endl;
181// 43 return 1;
182// 44 }
183// 45
184// 46 cout << "Any key to exit:\n";
185// 47
186// 48 char ch;
187// 49 cin.get(ch);
188// 50
189// 51 return 0;
190// 52 }
191// </srcblock>
192// Let us discuss this program line for line.
193//
194// 03 - This is the method of passing the command line through to the
195// main body of code. This obviously makes it mandatory. The inclusion
196// of the argc, argv is very well discussed in Stroustrup, The
197// C++ Programming Language, page 87.
198//
199// 05 - The instantiation of Input in the variable inputs(1) is done with
200// an integer argument of (1) to indicate the constructor should build
201// inputs with a pair of system parameters and read in values for them.
202// An argument of (0) would build an Input that was empty and would
203// obligate the programmer to build a list of Params explicitly.
204//
205// 07 - The version of the code is stored within the Input. Note the
206// optional use of RCS keyword substitution. See the "co" man page for
207// details. This allows the code to be automatically updated.
208//
209// 08-11 - The create member function of Input builds, in this case, a
210// parameter called xyfile, immediately filled with the String containing
211// the directory that holds the data. The help String is useful for new
212// users or prompting. The fourth argument of InFile is the optional
213// type of the parameter's value. Any suitable String may be used.
214// Missing from this example are the optional fifth and sixth arguments,
215// the parameter's value's range and units, respectively.
216//
217// 12 - This is another instantiation of a Param inside of Input. This
218// parameter will be referenced by the keyword "overplot". It is
219// initialized to False and is of type Bool.
220//
221// 13 - This line is the third and final Param placed in inputs and is
222// recognized by the code when accessed with keyword "lines".
223//
224// 16 - The call of readArguments(argc, argv) should be done after the
225// list of Params has been completed. This line of code fills the values
226// from the command line. A keyword that doesn't match will throw an
227// error.
228//
229// 19 - At this point the local variable filename is initialized to the
230// String value held within the parameter accessed through the key
231// "xyfile". Recall that the value of xyfile was originally set to
232// "/tmp/xy.aipsio" but would be replaced with the proper value at
233// execution. The getString member function returns either the default
234// value specified during the xyfile parameter's instantiation or the
235// value placed into it from the command line use of xyfile=myfile.
236//
237// 25 - Here the boolean value of the Param called lines is inserted into
238// the call to the function plot.
239//
240// 29 - Again the Input interface has its parameter called overplot
241// return a boolean to be used as a test for an "if". The getBool(key)
242// Input member function may be reading the default value of the
243// appropriate parameter called key or using the value passed from the
244// command line.
245//
246// 30 & 33 - Another call to plot that uses the boolean value stored in
247// the parameter called lines.
248// </example>
249//
250//<motivation>
251// This module fit the early needs of a a simple user interface.
252// </motivation>
253
254// <todo asof="Thu 199504/06 21:26:43 GMT">
255// <li> possibly replace the Param class with Keywords
256// </todo>
257
258// </module>
259
260
261} //# NAMESPACE CASACORE - END
262
263#endif
264
265
266
267
268
269
this file contains all the compiler specific defines
Definition mainpage.dox:28