source: trunk/src/duchamp.hh @ 913

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

A large swathe of changes aimed at improving warning/error/exception handling. Now make use of macros and streams. Also, there is now a distinction between DUCHAMPERROR and DUCHAMPTHROW.

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