source: trunk/src/duchamp.hh @ 909

Last change on this file since 909 was 909, checked in by MatthewWhiting, 12 years ago

Ticket #95: yAdding macros to help with warning, error and exception handling. Idea is to move all the duchampWarning & duchampError calls to use these.

File size: 11.2 KB
Line 
1// -----------------------------------------------------------------------
2// duchamp.hh: Definitions for use with Duchamp
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef DUCHAMP_HH
29#define DUCHAMP_HH
30
31#include <iostream>
32#include <stdexcept>
33#include <string>
34
35// need to undef these in case other packages have them defined.
36#undef PACKAGE_BUGREPORT
37#undef PACKAGE_NAME
38#undef PACKAGE_STRING
39#undef PACKAGE_TARNAME
40#undef PACKAGE_VERSION
41#undef HAVE_PGPLOT
42#include <duchamp/config.h>
43
44#ifdef HAVE_PGPLOT
45#include <duchamp/Utils/mycpgplot.hh>
46#endif
47
48/// The primary namespace for all functionality directly related to Duchamp
49namespace duchamp
50{
51
52  /// @brief How to convey whether a function has worked
53  enum OUTCOME {SUCCESS=0, FAILURE};
54
55  /// Usage message for command line help.
56  const std::string ERR_USAGE_MSG =
57    "Usage: Duchamp [OPTION] [FILE]\n\
58Duchamp is an object finder for spectral-line FITS cubes.\n\
59\n\
60  -p FILE      Read in parameters from FILE, including FITS image location.\n\
61  -f FILE      Use default parameters with imageFile=FILE\n\
62  -x           Do not use X-windows PGPLOT output\n\
63               (equivalent to setting flagXOutput=false -- overrides the parameter file)\n\n\
64  -v           Return version number and exit\n\
65  -h           Display this help information and exit\n";
66
67  /// Usage message for command line help for Selavy.
68  const std::string SELAVY_ERR_USAGE_MSG =
69    "Usage: Selavy [OPTION] [FILE]\n\
70Selavy re-analyses and re-plots objects found by Duchamp.\n\
71\n\
72  -p FILE      Read in parameters from FILE, including FITS image location.\n\
73  -f FILE      Use default parameters with imageFile=FILE\n\
74  -x           Do not use X-windows PGPLOT output\n\
75               (equivalent to setting flagXOutput=false -- overrides the parameter file)\n\n\
76  -v           Return version number and exit\n\
77  -h           Display this help information and exit\n";
78
79  /// Shorter Usage message for command line help.
80  const std::string ERR_USAGE_MSG_SHORT="Usage: Duchamp -p [parameter file]\n";
81
82  /// The program name. (Duchamp)
83  const std::string PROGNAME = PACKAGE_NAME;
84
85  /// The program version
86  const std::string VERSION = PACKAGE_VERSION;
87
88  // Specialised functions to report warnings and errors -- in duchamp.cc
89  /// Print a warning message to the stderr
90  void duchampWarning(std::string subroutine, std::string warning);
91  /// Print an error message to the stderr and sound the bell
92  void duchampError(std::string subroutine, std::string error);
93
94  /// Define the duchamp exception class.
95  class DuchampError: public std::runtime_error
96  {
97  public:
98    /// Constructor taking a message
99    explicit DuchampError(const std::string& message);
100    /// empty destructor
101    virtual ~DuchampError() throw();
102  };
103
104  // Macro to handle warnings, specifying the origin of the warning and taking a streamed input
105#define DUCHAMPWARN(origin,stream) \
106  {                                \
107    std::ostringstream oss;        \
108    oss << stream;                 \
109    std::cerr << "WARNING <" << origin << ">: " << oss.str()<<"\n"; \
110  }     
111 
112  // Macro to handle errors, with origin and streamed input. No exception is thrown (use DUCHAMPTHROW instead)
113#define DUCHAMPERROR(origin,stream) \
114{                                   \
115  std::ostringstream oss;           \
116  oss << stream;                    \
117  std::cerr << "ERROR <" << origin << ">: " << oss.str() << "\n"; \
118}
119
120#define DUCHAMPTHROW(origin,stream) \
121{                                   \
122  DUCHAMPERROR(origin,"\a"<<stream);\
123  std::ostringstream error;         \
124  error << stream;                  \
125  throw DuchampError(error.str());  \
126}
127
128  /// The spectral type that we want the wcsprm structs to be in.
129    const char duchampVelocityType[9] = "VOPT-F2W";
130  //const char duchampVelocityType[9] = "VELO-F2V";
131  /// The spectral type that we want the wcsprm structs to be in when no velocity info is present.
132  const char duchampFrequencyType[9] = "FREQ    ";
133
134  /// Descriptions of the various spectral axis types
135  enum TYPEDESC {FREQUENCY=0,VELOCITY,WAVELENGTH};
136  /// Human-readable descriptions of the various spectral axis types
137  const std::string duchampSpectralDescription[3]=
138    {"Frequency", "Velocity", "Wavelength"};
139
140  // The following are the FITS Header Keywords corresponding to the
141  // parameters related to the atrous reconstruction.
142
143  /// FITS header keyword for min atrous scale
144  const std::string keyword_scaleMin     = "DU_MINSC";
145  /// FITS header keyword for S/N used in atrous reconstruction
146  const std::string keyword_snrRecon     = "DU_ATCUT";
147  /// FITS header keyword for number of dimensions used in atrous reconstruction
148  const std::string keyword_reconDim     = "DU_ATDIM";
149  /// FITS header keyword for the code number of the filter used in atrous reconstruction
150  const std::string keyword_filterCode   = "DU_FILTR";
151  /// FITS header keyword: does this file hold the reconstructed array or the residual?
152  const std::string keyword_ReconResid   = "DU_RECON";
153  /// FITS header keyword: type of smoothing done.
154  const std::string keyword_smoothtype   = "DU_SMTYP";
155  /// FITS header keyword for the gaussian kernel major axis FWHM
156  const std::string keyword_kernmaj      = "DU_KMAJ";
157  /// FITS header keyword for the gaussian kernel minor axis FWHM
158  const std::string keyword_kernmin      = "DU_KMIN";
159  /// FITS header keyword for the gaussian kernel position angle
160  const std::string keyword_kernpa       = "DU_KPA";
161  /// FITS header keyword for the Hanning filter width
162  const std::string keyword_hanningwidth = "DU_WHANN";
163  /// FITS header keyword for the image subsection used
164  const std::string keyword_subsection   = "DU_IMSUB";
165
166  // And these are the comments corresponding to the relevant keywords
167  /// FITS header comment for DU_MINSC keyword
168  const std::string comment_scaleMin     = "Duchamp parameter scaleMin";
169  /// FITS header comment for DU_ATCUT keyword
170  const std::string comment_snrRecon     = "Duchamp parameter snrRecon";
171  /// FITS header comment for DU_ATDIM keyword
172  const std::string comment_reconDim     = "Duchamp parameter reconDim";
173  /// FITS header comment for DU_FILTR keyword
174  const std::string comment_filterCode   = "Duchamp parameter filterCode";
175  /// FITS header comment for DU_RECON keyword
176  const std::string comment_ReconResid   = "Is this the reconstruction or residual?";
177  /// FITS header comment for DU_SMTYP keyword
178  const std::string comment_smoothtype   = "Type of smoothing done";
179  /// FITS header comment for DU_KMAJ  keyword
180  const std::string comment_kernmaj      = "Duchamp parameter kernMaj";
181  /// FITS header comment for DU_KMIN  keyword
182  const std::string comment_kernmin      = "Duchamp parameter kernMin";
183  /// FITS header comment for DU_KPA   keyword
184  const std::string comment_kernpa       = "Duchamp parameter kernPA";
185  /// FITS header comment for DU_WHANN keyword
186  const std::string comment_hanningwidth = "Duchamp parameter hanningWidth";
187  /// FITS header comment for DU_IMSUB keyword
188  const std::string comment_subsection   = "Subsection of the original image";
189
190  // Descriptive Headers: for the reconstruction case
191  const std::string header_reconHistory1 =
192    "Reconstructed with a trous wavelet technique";
193  const std::string header_reconHistory2 =
194    "Reconstruction by " + PROGNAME + " v." + VERSION;
195  const std::string header_reconHistory_input =
196    "Original (input) image used by " + PROGNAME + " follows";
197  const std::string header_reconSubsection_comment  =
198    "A subsection of the original was reconstructed by " + PROGNAME;
199  const std::string header_atrous_comment  =
200    "The following are the Duchamp parameters used in reconstruction";
201
202  // Descriptive Headers: for the Smoothing case
203  const std::string header_smoothHistory =
204    "Smoothed by " + PROGNAME + " v." + VERSION;
205  const std::string header_smoothHistory_input =
206    "Original (input) image used by " + PROGNAME + " follows";
207  const std::string header_smoothSubsection_comment  =
208    "A subsection of the original was smoothed by " + PROGNAME;
209  const std::string header_smoothSpatial = "Spatial, gaussian kernel";
210  const std::string header_smoothSpectral= "Spectral, hanning filter";
211
212  // Descriptive Headers: for the output Mask image
213  const std::string header_maskHistory =
214    "Results of searching by " + PROGNAME + " v." + VERSION;
215  const std::string header_maskHistory_input =
216    "Input image used by " + PROGNAME + " follows";
217  const std::string header_maskSubsection_comment =
218    "A subsection of the original was searched by " + PROGNAME;
219
220  // Descriptive Headers: for the output Moment-0 image
221  const std::string header_moment0History =
222    "Moment-0 map from searching by " + PROGNAME + " v." + VERSION;
223  const std::string header_moment0History_input =
224    "Input image used by " + PROGNAME + " follows";
225  const std::string header_moment0Subsection_comment =
226    "A subsection of the original was searched by " + PROGNAME;
227
228}
229
230#ifdef HAVE_PGPLOT
231namespace duchamp
232{
233
234  // Colours used in graphical output
235  /// The colour for the Blank edges
236  const int DUCHAMP_BLANK_EDGE_COLOUR = mycpgplot::MAGENTA;
237  /// The colour for the edge of the cube
238  const int DUCHAMP_CUBE_EDGE_COLOUR = mycpgplot::YELLOW;
239  /// The colour for the reconstructed spectra
240  const int DUCHAMP_RECON_SPECTRA_COLOUR = mycpgplot::RED;
241  /// The colour for the baseline spectra
242  const int DUCHAMP_BASELINE_SPECTRA_COLOUR = mycpgplot::YELLOW;
243  /// The colour for the object outline
244  const int DUCHAMP_OBJECT_OUTLINE_COLOUR = mycpgplot::BLUE;
245  /// The colour for the Milky-way region spectral boundaries
246  const int DUCHAMP_MILKY_WAY_COLOUR = mycpgplot::DARKGREEN;
247  /// The colour for the tick marks in the image cutouts
248  const int DUCHAMP_TICKMARK_COLOUR = mycpgplot::RED;
249  /// The colour for the text identifying objects on the maps
250  const int DUCHAMP_ID_TEXT_COLOUR = mycpgplot::RED;
251  /// The colour for the WCS axes on the maps
252  const int DUCHAMP_WCS_AXIS_COLOUR = mycpgplot::WCSGREEN;
253
254}
255
256#else
257namespace duchamp
258{
259  /// The colour for the text identifying objects on the maps
260  const int DUCHAMP_ID_TEXT_COLOUR = 2;
261  /// The colour for the WCS axes on the maps
262  const int DUCHAMP_WCS_AXIS_COLOUR = 3;
263
264}
265
266#endif
267
268
269#endif
Note: See TracBrowser for help on using the repository browser.