source: trunk/src/param.cc @ 1240

Last change on this file since 1240 was 1240, checked in by MatthewWhiting, 11 years ago

Initial bit of solving #193 - new parameters flaggedChannelList and flaggedChannels, holding a list of channels to be ignored. Not yet implemented. At the same time have added checks in the objectList parsing, using the new function and giving a warning message about requested objects not covered by the list of detections.

File size: 69.1 KB
Line 
1// -----------------------------------------------------------------------
2// param.cc: Dealing with the set of parameters for 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#include <iostream>
29#include <iomanip>
30#include <fstream>
31#include <sstream>
32#include <string>
33#include <algorithm>
34#include <stdlib.h>
35#include <ctype.h>
36#include <math.h>
37#include <unistd.h>
38#include <duchamp/param.hh>
39#include <duchamp/fitsHeader.hh>
40#include <duchamp/duchamp.hh>
41#include <duchamp/pgheader.hh>
42#include <duchamp/ATrous/filter.hh>
43#include <duchamp/Utils/utils.hh>
44#include <duchamp/Utils/Section.hh>
45#include <duchamp/Utils/VOParam.hh>
46#include <duchamp/Outputs/columns.hh>
47
48namespace duchamp
49{
50  const std::string defaultSection = "[*,*,*]";
51
52  /****************************************************************/
53  ///////////////////////////////////////////////////
54  //// Accessor Functions for Parameter class:
55  ///////////////////////////////////////////////////
56  Param::~Param()
57  {
58    /// Deletes the offsets array if the sizeOffsets parameter is
59    /// positive.
60    if(this->sizeOffsets>0) delete [] this->offsets;
61  }
62
63  Param::Param()
64  {
65    this->defaultValues();
66  }
67
68  void Param::defaultValues()
69  {
70    /// Provides default intial values for the parameters. Note that
71    /// imageFile has no default value!
72
73    // Input files
74    this->imageFile         = "";
75    this->flagSubsection    = false;
76    this->pixelSec          = Section();
77    this->flagReconExists   = false;
78    this->reconFile         = "";
79    this->flagSmoothExists  = false;
80    this->smoothFile        = "";
81    this->usePrevious       = false;
82    this->objectList        = "";
83    // Output files
84    this->flagLog           = false;
85    this->logFile           = "duchamp-Logfile.txt";
86    this->outFile           = "duchamp-Results.txt";
87    this->flagSeparateHeader= false;
88    this->headerFile        = "duchamp-Results.hdr";
89    this->flagWriteBinaryCatalogue = true;
90    this->binaryCatalogue   = "duchamp-Catalogue.dpc";
91    this->flagPlotSpectra   = true;
92    this->spectraFile       = "duchamp-Spectra.ps";
93    this->flagPlotIndividualSpectra = false;
94    this->flagTextSpectra   = false;
95    this->spectraTextFile   = "duchamp-Spectra.txt";
96    this->flagOutputBaseline    = false;
97    this->fileOutputBaseline    = "";
98    this->flagOutputMomentMap    = false;
99    this->fileOutputMomentMap    = "";
100    this->flagOutputMomentMask    = false;
101    this->fileOutputMomentMask    = "";
102    this->flagOutputMask    = false;
103    this->fileOutputMask    = "";
104    this->flagMaskWithObjectNum = false;
105    this->flagOutputSmooth  = false;
106    this->fileOutputSmooth  = "";
107    this->flagOutputRecon   = false;
108    this->fileOutputRecon   = "";
109    this->flagOutputResid   = false;
110    this->fileOutputResid   = "";
111    this->flagVOT           = false;
112    this->votFile           = "duchamp-Results.xml";
113    this->flagKarma         = false;
114    this->karmaFile         = "duchamp-Results.ann";
115    this->flagDS9           = false;
116    this->ds9File           = "duchamp-Results.reg";
117    this->flagCasa          = false;
118    this->casaFile          = "duchamp-Results.crf";
119    this->annotationType    = "borders";
120    this->flagMaps          = true;
121    this->detectionMap      = "duchamp-DetectionMap.ps";
122    this->momentMap         = "duchamp-MomentMap.ps";
123    this->flagXOutput       = true;
124    this->precFlux          = Catalogues::prFLUX;
125    this->precVel           = Catalogues::prVEL;
126    this->precSNR           = Catalogues::prSNR;
127    // Cube related parameters
128    this->flagBlankPix      = false;
129    this->blankPixValue     = -8.00061;
130    this->blankKeyword      = 1;
131    this->bscaleKeyword     = -8.00061;
132    this->bzeroKeyword      = 0.;
133    this->newFluxUnits      = "";
134    // Milky-Way parameters
135    this->flaggedChannelList = "";
136    this->flaggedChannels   = std::vector<int>(0);
137    this->flagMW            = false;
138    this->maxMW             = 112;
139    this->minMW             = 75;
140    this->areaBeam          = 0.;
141    this->fwhmBeam          = 0.;
142    this->beamAsUsed.empty();
143    this->searchType        = "spatial";
144    // Trim-related         
145    this->flagTrim          = false;
146    this->hasBeenTrimmed    = false;
147    this->borderLeft        = 0;
148    this->borderRight       = 0;
149    this->borderBottom      = 0;
150    this->borderTop         = 0;
151    // Subsection offsets
152    this->sizeOffsets       = 0;
153    this->xSubOffset        = 0;
154    this->ySubOffset        = 0;
155    this->zSubOffset        = 0;
156    // Baseline related
157    this->flagBaseline      = false;
158    // Detection-related   
159    this->flagNegative      = false;
160    // Object growth       
161    this->flagGrowth        = false;
162    this->growthCut         = 3.;
163    this->flagUserGrowthThreshold = false;
164    this->growthThreshold   = 0.;
165    // FDR analysis         
166    this->flagFDR           = false;
167    this->alphaFDR          = 0.01;
168    this->FDRnumCorChan     = 2;
169    // Other detection     
170    this->flagStatSec       = false;
171    this->statSec           = Section();
172    this->flagRobustStats   = true;
173    this->snrCut            = 5.;
174    this->threshold         = 0.;
175    this->flagUserThreshold = false;
176    // Smoothing
177    this->flagSmooth        = false;
178    this->smoothType        = "spectral";
179    this->hanningWidth      = 5;
180    this->kernMaj           = 3.;
181    this->kernMin           = -1.;
182    this->kernPA            = 0.;
183    // A trous reconstruction parameters
184    this->flagATrous        = false;
185    this->reconDim          = 1;
186    this->scaleMin          = 1;
187    this->scaleMax          = 0;
188    this->snrRecon          = 4.;
189    this->reconConvergence  = 0.005;
190    this->filterCode        = 1;
191    this->reconFilter.define(this->filterCode);
192    // Volume-merging parameters
193    this->flagAdjacent      = true;
194    this->threshSpatial     = 3.;
195    this->threshVelocity    = 7.;
196    this->minChannels       = 3;
197    this->minPix            = 2;
198    this->minVoxels         = 4;
199    this->flagRejectBeforeMerge = false;
200    this->flagTwoStageMerging = true;
201    // Input-Output related
202    this->spectralMethod    = "peak";
203    this->spectralType      = "";
204    this->restFrequency     = -1.;
205    this->restFrequencyUsed = false;
206    this->spectralUnits     = "";
207    this->pixelCentre       = "centroid";
208    this->sortingParam      = "vel";
209    this->borders           = true;
210    this->blankEdge         = true;
211    this->verbose           = true;
212    this->commentStr        = "";
213  }
214
215  Param::Param (const Param& p)
216  {
217    operator=(p);
218  }
219
220  Param& Param::operator= (const Param& p)
221  {
222    if(this == &p) return *this;
223    this->imageFile         = p.imageFile;
224    this->flagSubsection    = p.flagSubsection;
225    this->pixelSec          = p.pixelSec;
226    this->flagReconExists   = p.flagReconExists;
227    this->reconFile         = p.reconFile;     
228    this->flagSmoothExists  = p.flagSmoothExists;
229    this->smoothFile        = p.smoothFile;     
230    this->usePrevious       = p.usePrevious;
231    this->objectList        = p.objectList;
232    this->flagLog           = p.flagLog;       
233    this->logFile           = p.logFile;       
234    this->outFile           = p.outFile;       
235    this->flagSeparateHeader= p.flagSeparateHeader;
236    this->headerFile        = p.headerFile;
237    this->flagWriteBinaryCatalogue = p.flagWriteBinaryCatalogue;
238    this->binaryCatalogue   = p.binaryCatalogue;
239    this->flagPlotSpectra   = p.flagPlotSpectra;
240    this->spectraFile       = p.spectraFile;   
241    this->flagPlotIndividualSpectra = p.flagPlotIndividualSpectra;
242    this->flagTextSpectra   = p.flagTextSpectra;   
243    this->spectraTextFile   = p.spectraTextFile;   
244    this->flagOutputBaseline    = p.flagOutputBaseline;
245    this->fileOutputBaseline    = p.fileOutputBaseline;
246    this->flagOutputMomentMap    = p.flagOutputMomentMap;
247    this->fileOutputMomentMap    = p.fileOutputMomentMap;
248    this->flagOutputMomentMask   = p.flagOutputMomentMask;
249    this->fileOutputMomentMask   = p.fileOutputMomentMask;
250    this->flagOutputMask    = p.flagOutputMask;
251    this->fileOutputMask    = p.fileOutputMask;
252    this->flagMaskWithObjectNum = p.flagMaskWithObjectNum;
253    this->flagOutputSmooth  = p.flagOutputSmooth;
254    this->fileOutputSmooth  = p.fileOutputSmooth;
255    this->flagOutputRecon   = p.flagOutputRecon;
256    this->fileOutputRecon   = p.fileOutputRecon;
257    this->flagOutputResid   = p.flagOutputResid;
258    this->fileOutputResid   = p.fileOutputResid;
259    this->flagVOT           = p.flagVOT;         
260    this->votFile           = p.votFile;       
261    this->flagKarma         = p.flagKarma;     
262    this->karmaFile         = p.karmaFile;     
263    this->flagDS9           = p.flagDS9;     
264    this->ds9File           = p.ds9File;     
265    this->flagCasa          = p.flagCasa;     
266    this->casaFile          = p.casaFile;     
267    this->annotationType    = p.annotationType;
268    this->flagMaps          = p.flagMaps;       
269    this->detectionMap      = p.detectionMap;   
270    this->momentMap         = p.momentMap;     
271    this->flagXOutput       = p.flagXOutput;       
272    this->precFlux          = p.precFlux;
273    this->precVel           = p.precVel;
274    this->precSNR           = p.precSNR;
275    this->flagNegative      = p.flagNegative;
276    this->flagBlankPix      = p.flagBlankPix;   
277    this->blankPixValue     = p.blankPixValue; 
278    this->blankKeyword      = p.blankKeyword;   
279    this->bscaleKeyword     = p.bscaleKeyword; 
280    this->bzeroKeyword      = p.bzeroKeyword;   
281    this->newFluxUnits      = p.newFluxUnits;
282    this->flaggedChannelList = p.flaggedChannelList;
283    this->flaggedChannels   = p.flaggedChannels;
284    this->flagMW            = p.flagMW;         
285    this->maxMW             = p.maxMW;         
286    this->minMW             = p.minMW;         
287    this->areaBeam          = p.areaBeam;     
288    this->fwhmBeam          = p.fwhmBeam;     
289    this->beamAsUsed        = p.beamAsUsed;
290    this->searchType        = p.searchType;
291    this->flagTrim          = p.flagTrim;   
292    this->hasBeenTrimmed    = p.hasBeenTrimmed;   
293    this->borderLeft        = p.borderLeft;     
294    this->borderRight       = p.borderRight;   
295    this->borderBottom      = p.borderBottom;   
296    this->borderTop         = p.borderTop;     
297    if(this->sizeOffsets>0) delete [] this->offsets;
298    this->sizeOffsets       = p.sizeOffsets;
299    if(this->sizeOffsets>0){
300      this->offsets           = new long[this->sizeOffsets];
301      for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
302    }
303    this->xSubOffset        = p.xSubOffset;     
304    this->ySubOffset        = p.ySubOffset;     
305    this->zSubOffset        = p.zSubOffset;
306    this->flagBaseline      = p.flagBaseline;
307    this->flagGrowth        = p.flagGrowth;
308    this->growthCut         = p.growthCut;
309    this->growthThreshold   = p.growthThreshold;
310    this->flagUserGrowthThreshold = p.flagUserGrowthThreshold;
311    this->flagFDR           = p.flagFDR;
312    this->alphaFDR          = p.alphaFDR;
313    this->FDRnumCorChan     = p.FDRnumCorChan;
314    this->flagStatSec       = p.flagStatSec;
315    this->statSec           = p.statSec;
316    this->flagRobustStats   = p.flagRobustStats;
317    this->snrCut            = p.snrCut;
318    this->threshold         = p.threshold;
319    this->flagUserThreshold = p.flagUserThreshold;
320    this->flagSmooth        = p.flagSmooth;
321    this->smoothType        = p.smoothType;
322    this->hanningWidth      = p.hanningWidth;
323    this->kernMaj           = p.kernMaj;
324    this->kernMin           = p.kernMin;
325    this->kernPA            = p.kernPA;
326    this->flagATrous        = p.flagATrous;
327    this->reconDim          = p.reconDim;
328    this->scaleMin          = p.scaleMin;
329    this->scaleMax          = p.scaleMax;
330    this->snrRecon          = p.snrRecon;
331    this->reconConvergence  = p.reconConvergence;
332    this->filterCode        = p.filterCode;
333    this->reconFilter       = p.reconFilter;
334    this->flagAdjacent      = p.flagAdjacent;
335    this->threshSpatial     = p.threshSpatial;
336    this->threshVelocity    = p.threshVelocity;
337    this->minChannels       = p.minChannels;
338    this->minPix            = p.minPix;
339    this->minVoxels         = p.minVoxels;
340    this->flagRejectBeforeMerge = p.flagRejectBeforeMerge;
341    this->flagTwoStageMerging = p.flagTwoStageMerging;
342    this->spectralMethod    = p.spectralMethod;
343    this->spectralType      = p.spectralType;
344    this->restFrequency     = p.restFrequency;
345    this->restFrequencyUsed = p.restFrequencyUsed;
346    this->spectralUnits     = p.spectralUnits;
347    this->pixelCentre       = p.pixelCentre;
348    this->sortingParam      = p.sortingParam;
349    this->borders           = p.borders;
350    this->blankEdge         = p.blankEdge;
351    this->verbose           = p.verbose;
352    this->commentStr        = p.commentStr;
353    return *this;
354  }
355  //--------------------------------------------------------------------
356
357  OUTCOME Param::getopts(int argc, char ** argv, std::string progname)
358  {
359    ///   A function that reads in the command-line options, in a manner
360    ///    tailored for use with the main Duchamp program.
361    ///
362    ///   \param argc The number of command line arguments.
363    ///   \param argv The array of command line arguments.
364
365    OUTCOME returnValue = FAILURE;
366    if(argc==1){
367      std::cout << ERR_USAGE_MSG;
368      returnValue = FAILURE;
369    }
370    else {
371      std::string file;
372      float thresh;
373      bool changeX = false, changeThresh=false;
374      this->defaultValues();
375      char c;
376      while( ( c = getopt(argc,argv,"p:f:t:hvx") )!=-1){
377        switch(c) {
378        case 'p':
379          file = optarg;
380          if(this->readParams(file)==FAILURE){
381            DUCHAMPERROR(progname,"Could not open parameter file " << file);
382          }
383          else returnValue = SUCCESS;
384          break;
385        case 'f':
386          file = optarg;
387          this->imageFile = file;
388          returnValue = SUCCESS;
389          break;
390        case 'v':
391          std::cout << PROGNAME << " version " << VERSION << std::endl;
392          break;
393        case 'x':
394          changeX = true;
395          break;
396        case 't':
397          thresh = atof(optarg);
398          changeThresh = true;
399          break;
400        case 'h':
401        default :
402          std::cout << ERR_USAGE_MSG;
403          break;
404        }
405      }
406      if(changeX){
407        if(returnValue == SUCCESS) this->setFlagXOutput(false);
408        else {
409          DUCHAMPERROR(progname, "You need to specify either a parameter file or FITS image.\n");
410          std::cout << "\n" << ERR_USAGE_MSG;
411        }
412      }
413      if(changeThresh){
414        this->threshold = thresh;
415        this->flagUserThreshold = true;
416        this->checkPars();
417      }
418    }
419    return returnValue;
420  }
421  //--------------------------------------------------------------------
422
423  bool Param::isBlank(float &value)
424  {
425    ///  Tests whether the value passed as the argument is BLANK or not.
426    ///  \param value Pixel value to be tested.
427    ///  \return False if flagBlankPix is false. Else, compare to the
428    ///  relevant FITS keywords, using integer comparison.
429
430    return this->flagBlankPix &&
431      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
432  }
433
434  bool *Param::makeBlankMask(float *array, size_t size)
435  {
436    ///  This returns an array of bools, saying whether each pixel in the
437    ///  given array is BLANK or not. If the pixel is BLANK, set mask to
438    ///  false, else set to true. The array is allocated by the function.
439
440    bool *mask = new bool[size];
441    for(size_t i=0;i<size;i++) mask[i] = !this->isBlank(array[i]);
442    return mask;
443  }
444
445
446  bool *Param::makeStatMask(float *array, size_t *dim)
447  {
448    ///  This returns an array of bools, saying whether each pixel in
449    ///  the given array is suitable for a stats calculation. It needs
450    ///  to be in the StatSec (if defined), not blank and not a MW
451    ///  channel. The array is allocated by the function with a 'new' call.
452
453    bool *mask = new bool[dim[0]*dim[1]*dim[2]];
454    for(size_t x=0;x<dim[0];x++) {
455      for(size_t y=0;y<dim[1];y++) {
456        for(size_t z=0;z<dim[2];z++) {
457          size_t i = x+y*dim[0]+z*dim[0]*dim[1];
458          mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z);
459        }
460      }
461    }
462    return mask;
463  }
464
465
466  bool Param::isInMW(int z)
467  {
468    ///  Tests whether we are flagging Milky Way channels, and if so
469    /// whether the given channel number is in the Milky Way range. The
470    /// channels are assumed to start at number 0. 
471    /// \param z The channel number
472    /// \return True if we are flagging Milky Way channels and z is in
473    ///  the range.
474
475    return ( this->flagMW && (z>=this->getMinMW()) && (z<=this->getMaxMW()) );
476  }
477
478  bool Param::isStatOK(int x, int y, int z)
479  {
480    /// Test whether a given pixel position lies within the subsection
481    /// given by the statSec parameter. Only tested if the flagSubsection
482    /// parameter is true -- if it isn't, we just return true since all
483    /// pixels are therefore available for statstical calculations.
484    /// \param x X-value of pixel being tested.
485    /// \param y Y-value of pixel being tested.
486    /// \param z Z-value of pixel being tested.
487    /// \return True if pixel is able to be used for statistical
488    /// calculations. False otherwise.
489
490    int xval=x,yval=y,zval=z;
491    if(flagSubsection){
492      xval += pixelSec.getStart(0);
493      yval += pixelSec.getStart(1);
494      zval += pixelSec.getStart(2);
495    }
496    return !flagStatSec || statSec.isInside(xval,yval,zval);
497  }
498
499  std::vector<bool> Param::getObjectChoices()
500  {
501    ///  Returns a list of bool values, indicating whether a given
502    ///  object was requested or not. The size of the vector is
503    ///  determined by the maximum value in objectList. For instance,
504    ///  if objectList="2,3,5-8", then the returned vector will be
505    ///  [0,1,1,0,1,1,1,1].
506    ///  \return Vector of bool values.
507
508      if(this->objectChoices.size()==0) return std::vector<bool>(0);
509      else {
510          int maxNum = *std::max_element(this->objectChoices.begin(), this->objectChoices.end());
511          std::vector<bool> choices(maxNum,false);
512          for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
513              choices[*obj-1] = true;
514          return choices;
515      }
516  }
517
518  std::vector<bool> Param::getObjectChoices(int numObjects)
519  {
520    ///  Returns a list of bool values, indicating whether a given
521    ///  object was requested or not. The size of the vector is given
522    ///  by the numObjects parameter. So, if objectList="2,3,5-8", then
523    ///  the returned vector from a getObjectChoices(10) call will be
524    ///  [0,1,1,0,1,1,1,1,0,0].
525    ///  \param numObjects How many objects there are in total.
526    ///  \return Vector of bool values.
527
528    if(this->objectList==""){
529      std::vector<bool> choices(numObjects,true);
530      return choices;
531    }
532    else{
533      std::vector<bool> choices(numObjects,false);
534      std::vector<int> duds,goodlist;
535      for(std::vector<int>::iterator obj = this->objectChoices.begin();obj!=this->objectChoices.end();obj++){
536          if(*obj<=numObjects) {
537              choices[*obj-1] = true;
538              goodlist.push_back(*obj);
539          }
540          else duds.push_back(*obj);
541      }
542      if(duds.size()>0){
543          this->objectChoices = goodlist;
544          std::stringstream dudlist;
545          dudlist << duds[0];
546          for(size_t i=1;i<duds.size();i++) dudlist << ","<<duds[i];
547          std::string obj="object";
548          if(duds.size()>1) obj+= "s";
549          DUCHAMPWARN("Object Selection", "You have only detected " << numObjects << " objects, so the requested "
550                      << obj << " '" << dudlist.str() << "' cannot be returned. Please check your request, as it doesn't match the results.");
551      }
552      return choices;
553    }
554  }
555
556  /****************************************************************/
557  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
558  /// / Other Functions using the  Parameter class:
559  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
560
561  OUTCOME Param::readParams(std::string paramfile)
562  {
563    /// The parameters are read in from a disk file, on the assumption that each
564    ///  line of the file has the format "parameter value" (eg. alphafdr 0.1)
565    ///
566    /// The case of the parameter name does not matter, nor does the
567    /// formatting of the spaces (it can be any amount of whitespace or
568    /// tabs).
569    ///
570    /// \param paramfile A std::string containing the parameter filename.
571    ///
572    /// \return FAILURE if the parameter file does not exist. SUCCESS if
573    /// it is able to read it.
574
575    if(!USE_PGPLOT){
576      // Change default values for these parameters when we don't use PGPlot
577      this->flagXOutput = false;
578      this->flagMaps = false;
579      this->flagPlotSpectra = false;
580    }
581
582    std::ifstream fin(paramfile.c_str());
583    if(!fin.is_open()) return FAILURE;
584    std::string line;
585    while( !std::getline(fin,line,'\n').eof()){
586
587      if(line[0]!='#'){
588        std::stringstream ss;
589        ss.str(line);
590        std::string arg;
591        ss >> arg;
592        arg = makelower(arg);
593        if(arg=="imagefile")       this->imageFile = readFilename(ss);
594        if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
595        if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
596        if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
597        if(arg=="reconfile")       this->reconFile = readSval(ss);
598        if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
599        if(arg=="smoothfile")      this->smoothFile = readSval(ss);
600        if(arg=="beamarea")        this->areaBeam = readFval(ss);
601        if(arg=="beamfwhm")        this->fwhmBeam = readFval(ss);
602        if(arg=="useprevious")     this->usePrevious = readFlag(ss);
603        if(arg=="objectlist")      this->objectList = readSval(ss);
604
605        if(arg=="flaglog")         this->flagLog = readFlag(ss);
606        if(arg=="logfile")         this->logFile = readSval(ss);
607        if(arg=="outfile")         this->outFile = readSval(ss);
608        if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss);
609        if(arg=="headerfile")      this->headerFile = readFilename(ss);
610        if(arg=="flagwritebinarycatalogue") this->flagWriteBinaryCatalogue = readFlag(ss);
611        if(arg=="binarycatalogue") this->binaryCatalogue = readFilename(ss);
612        if(arg=="flagplotspectra") this->flagPlotSpectra = readFlag(ss);
613        if(arg=="spectrafile")     this->spectraFile = readFilename(ss);
614        if(arg=="flagplotindividualspectra") this->flagPlotIndividualSpectra = readFlag(ss);
615        if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss);
616        if(arg=="spectratextfile") this->spectraTextFile = readFilename(ss);
617        if(arg=="flagoutputbaseline")  this->flagOutputBaseline = readFlag(ss);
618        if(arg=="fileoutputbaseline")  this->fileOutputBaseline = readFilename(ss);
619        if(arg=="flagoutputmomentmap")  this->flagOutputMomentMap = readFlag(ss);
620        if(arg=="fileoutputmomentmap")  this->fileOutputMomentMap = readFilename(ss);
621        if(arg=="flagoutputmomentmask")  this->flagOutputMomentMask = readFlag(ss);
622        if(arg=="fileoutputmomentmask")  this->fileOutputMomentMask = readFilename(ss);
623        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
624        if(arg=="fileoutputmask")  this->fileOutputMask = readFilename(ss);
625        if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss);
626        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
627        if(arg=="fileoutputsmooth")this->fileOutputSmooth = readFilename(ss);
628        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
629        if(arg=="fileoutputrecon") this->fileOutputRecon = readFilename(ss);
630        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
631        if(arg=="fileoutputresid") this->fileOutputResid = readFilename(ss);
632        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
633        if(arg=="votfile")         this->votFile = readFilename(ss);
634        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
635        if(arg=="karmafile")       this->karmaFile = readFilename(ss);
636        if(arg=="flagds9")         this->flagDS9 = readFlag(ss);
637        if(arg=="ds9file")         this->ds9File = readFilename(ss);
638        if(arg=="flagcasa")        this->flagCasa = readFlag(ss);
639        if(arg=="casafile")        this->casaFile = readFilename(ss);
640        if(arg=="annotationtype")  this->annotationType = readSval(ss);
641        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
642        if(arg=="detectionmap")    this->detectionMap = readFilename(ss);
643        if(arg=="momentmap")       this->momentMap = readFilename(ss);
644        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
645        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
646        if(arg=="precflux")        this->precFlux = readIval(ss);
647        if(arg=="precvel")         this->precVel = readIval(ss);
648        if(arg=="precsnr")         this->precSNR = readIval(ss);
649
650        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
651        if(arg=="flaggedchannels") this->flaggedChannelList = readSval(ss);
652        if(arg=="flagmw")          this->flagMW = readFlag(ss);
653        if(arg=="maxmw")           this->maxMW = readIval(ss);
654        if(arg=="minmw")           this->minMW = readIval(ss);
655        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
656        if(arg=="searchtype")      this->searchType = readSval(ss);
657
658        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
659        if(arg=="minpix")          this->minPix = readIval(ss);
660        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
661        if(arg=="growthcut")       this->growthCut = readFval(ss);
662        if(arg=="growththreshold"){
663          this->growthThreshold = readFval(ss);
664          this->flagUserGrowthThreshold = true;
665        }
666
667        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
668        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
669        if(arg=="fdrnumcorchan")   this->FDRnumCorChan = readIval(ss);
670        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
671        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
672        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
673        if(arg=="snrcut")          this->snrCut = readFval(ss);
674        if(arg=="threshold"){
675          this->threshold = readFval(ss);
676          this->flagUserThreshold = true;
677        }
678     
679        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
680        if(arg=="smoothtype")      this->smoothType = readSval(ss);
681        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
682        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
683        if(arg=="kernmin")         this->kernMin = readFval(ss);
684        if(arg=="kernpa")          this->kernPA = readFval(ss);
685
686        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
687        if(arg=="recondim")        this->reconDim = readIval(ss);
688        if(arg=="scalemin")        this->scaleMin = readIval(ss);
689        if(arg=="scalemax")        this->scaleMax = readIval(ss);
690        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
691        if(arg=="reconconvergence") this->reconConvergence = readFval(ss);
692        if(arg=="filtercode")      this->filterCode = readIval(ss);
693
694        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
695        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
696        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
697        if(arg=="minchannels")     this->minChannels = readIval(ss);
698        if(arg=="minvoxels")       this->minVoxels = readIval(ss);
699        if(arg=="flagrejectbeforemerge") this->flagRejectBeforeMerge = readFlag(ss);
700        if(arg=="flagtwostagemerging") this->flagTwoStageMerging = readFlag(ss);
701
702        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
703        if(arg=="spectraltype")    this->spectralType = readSval(ss);
704        if(arg=="restfrequency")   this->restFrequency = readFval(ss);
705        if(arg=="spectralunits")   this->spectralUnits = readSval(ss);
706        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
707        if(arg=="sortingparam")    this->sortingParam = makelower(readSval(ss));
708        if(arg=="drawborders")     this->borders = readFlag(ss);
709        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
710        if(arg=="verbose")         this->verbose = readFlag(ss);
711
712        // Dealing with deprecated parameters.
713        if(arg=="flagblankpix"){
714          this->flagTrim = readFlag(ss);
715          DUCHAMPWARN("Reading parameters","The parameter flagBlankPix is deprecated. Please use the flagTrim parameter in future.");
716          DUCHAMPWARN("Reading parameters","Setting flagTrim = " << stringize(this->flagTrim));
717        }
718        if(arg=="blankpixvalue"){
719          DUCHAMPWARN("Reading parameters","The parameter blankPixValue is deprecated. This value is only taken from the FITS header.");
720        }
721        if(arg=="beamsize"){
722          this->areaBeam = readFval(ss);
723          DUCHAMPWARN("Reading parameters","The parameter beamSize is deprecated. You can specify the beam size by beamArea or beamFWHM.");
724          DUCHAMPWARN("Reading parameters","Setting beamArea = " << this->areaBeam);
725        }
726
727      }
728    }
729
730    this->checkPars();
731
732    return SUCCESS;
733
734  }
735 
736  void Param::checkPars()
737  {
738
739    // If flagSubsection is false, but the parset had a subsection string in it, we want to set this back to the default.
740    if(!this->flagSubsection){
741      this->pixelSec.setSection(defaultSection);
742    }
743    if(!this->flagStatSec){
744      this->statSec.setSection(defaultSection);
745    }
746
747    // If we have usePrevious=false, set the objectlist to blank so that we use all of them. Otherwise, define the vector list of choices.
748    if(!this->usePrevious) this->objectList = "";
749    else this->objectChoices = selectionToIntVec(this->objectList);
750
751    // Defining the vector list of flagged channels
752    this->flaggedChannels = selectionToIntVec(this->flaggedChannelList);
753
754    // If pgplot was not included in the compilation, need to set flagXOutput to false
755    if(!USE_PGPLOT){
756      if(this->flagXOutput || this->flagMaps || this->flagPlotSpectra || this->flagPlotIndividualSpectra)
757        DUCHAMPWARN("Reading parameters","PGPlot has not been enabled, so setting flagXOutput, flagMaps, flagPlotSpectra and flagPlotIndividualSpectra to false.");
758      this->flagXOutput = false;
759      this->flagMaps = false;
760      this->flagPlotSpectra = false;
761      this->flagPlotIndividualSpectra = false;
762    }
763
764    if(!this->flagPlotSpectra && this->flagPlotIndividualSpectra){
765      DUCHAMPWARN("Reading parameters","flagPlotSpectra is false, so setting flagPlotIndividualSpectra to false as well.");
766      this->flagPlotIndividualSpectra = false;
767    }
768
769    // Correcting bad precision values -- if negative, set to 0
770    if(this->precFlux<0) this->precFlux = 0;
771    if(this->precVel<0)  this->precVel = 0;
772    if(this->precSNR<0)  this->precSNR = 0;
773
774    // Can only have "spatial" or "spectral" as search types
775    if(this->searchType != "spatial" && this->searchType != "spectral"){
776      DUCHAMPWARN("Reading parameters","You have requested a search type of \""<<this->searchType<<"\" -- Only \"spectral\" and \"spatial\" are accepted, so setting to \"spatial\".");
777      this->searchType = "spatial";
778    }
779
780    // The wavelet reconstruction takes precendence over the smoothing.
781    if(this->flagATrous) this->flagSmooth = false;
782
783    // Check validity of recon parameters
784    if(this->flagATrous){
785      if(this->reconConvergence < 0.){
786        DUCHAMPWARN("Reading Parameters","Your reconConvergence value is negative ("<<this->reconConvergence<<") - setting to " << -this->reconConvergence <<".");
787        this->reconConvergence *= -1.;
788      }
789
790      this->reconFilter.define(this->filterCode);
791
792      if((this->scaleMax) > 0 && (this->scaleMax < this->scaleMin)){
793        DUCHAMPWARN("Reading Parameters","Reconstruction scaleMax ("<<this->scaleMax<<") is less than scaleMin ("<<this->scaleMin<<"): setting both to "<<this->scaleMin);
794        this->scaleMax = this->scaleMin;
795      }
796
797      if( (this->reconDim < 1) || (this->reconDim > 3) ){
798        DUCHAMPWARN("Reading Parameters", "You requested a " << this->reconDim << " dimensional reconstruction. Setting reconDim to 1");
799        this->reconDim = 1;
800      }
801
802      if( this->snrRecon < 0.){
803        DUCHAMPWARN("Reading Parameters", "Your snrRecon value is negative (" << this->snrRecon<<"). Turning reconstruction off -- fix your parameter file!");
804        this->flagATrous = false;
805      }
806
807    }
808
809    if(this->flagUserThreshold){
810
811      // If we specify a manual threshold, need to also specify a manual growth threshold
812      // If we haven't done so, turn growing off
813      if(this->flagGrowth && !this->flagUserGrowthThreshold){
814        DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, but not a manual growth threshold. You need to do so using the \"growthThreshold\" parameter.");
815        DUCHAMPWARN("Reading parameters","The growth function is being turned off.");
816        this->flagGrowth = false;
817      }
818
819      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
820      if(this->flagFDR){
821        DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, so we don't need to use the FDR method. Setting \"flagFDR=false\".");
822        this->flagFDR = false;
823      }
824
825    }   
826
827    // Make sure the growth level is less than the detection level. Else turn off growing.
828    if(this->flagGrowth){
829      std::stringstream errmsg;
830      bool doWarn = false;
831      if(this->flagUserThreshold &&
832         ( (this->threshold < this->growthThreshold)
833           || (this->snrCut < this->growthCut) ) ){
834        errmsg << "Your \"growthThreshold\" parameter" << this->growthThreshold <<" is larger than your \"threshold\"" << this->threshold;
835        doWarn = true;
836      }
837     
838      if(!this->flagUserThreshold &&
839         (this->snrCut < this->growthCut)) {
840        errmsg << "Your \"growthCut\" parameter " << this->growthCut << " is larger than your \"snrCut\"" << this->snrCut;
841        doWarn = true;
842      }
843
844      if(doWarn){
845        DUCHAMPWARN("Reading parameters",errmsg);
846        DUCHAMPWARN("Reading parameters","The growth function is being turned off.");
847
848      }
849    }
850
851    // Make sure the annnotationType is an acceptable option -- default is "borders"
852    if((this->annotationType != "borders") && (this->annotationType!="circles") && (this->annotationType!="ellipses")){
853      DUCHAMPWARN("Reading parameters","The requested value of the parameter annotationType, \"" << this->annotationType << "\", is invalid -- changing to \"borders\".");
854      this->annotationType = "borders";
855    }
856     
857    // Make sure smoothType is an acceptable type -- default is "spectral"
858    if((this->smoothType!="spectral")&&
859       (this->smoothType!="spatial")){
860      DUCHAMPWARN("Reading parameters","The requested value of the parameter smoothType, \"" << this->smoothType << "\", is invalid -- changing to \"spectral\".");
861      this->smoothType = "spectral";
862    }
863    // If kernMin has not been given, or is negative, make it equal to kernMaj
864    if(this->kernMin < 0) this->kernMin = this->kernMaj;
865
866    // Make sure spectralMethod is an acceptable type -- default is "peak"
867    if((this->spectralMethod!="peak")&&
868       (this->spectralMethod!="sum")){
869      DUCHAMPWARN("Reading parameters","The requested value of the parameter spectralMethod, \"" << this->spectralMethod << "\", is invalid -- changing to \"peak\".");
870      this->spectralMethod = "peak";
871    }
872
873    // make sure pixelCentre is an acceptable type -- default is "peak"
874    if((this->pixelCentre!="centroid")&&
875       (this->pixelCentre!="average") &&
876       (this->pixelCentre!="peak")       ){
877      DUCHAMPWARN("Reading parameters","The requested value of the parameter pixelCentre, \"" << this->pixelCentre << "\", is invalid -- changing to \"centroid\".");
878      this->pixelCentre = "centroid";
879    }
880
881    // Make sure sortingParam is an acceptable type -- default is "vel"
882    bool OK = false;
883    int loc=(this->sortingParam[0]=='-') ? 1 : 0;
884    for(int i=0;i<numSortingParamOptions;i++)
885      OK = OK || this->sortingParam.substr(loc)==sortingParamOptions[i];
886    if(!OK){
887      DUCHAMPWARN("Reading parameters","The requested value of the parameter sortingParam, \"" << this->sortingParam << "\", is invalid. -- changing to \"vel\".");
888      this->sortingParam = "vel";
889    }
890
891    // Make sure minVoxels is appropriate given minChannels & minPixels
892    if(this->minVoxels < (this->minPix + this->minChannels - 1) ){
893      DUCHAMPWARN("Reading parameters","Changing minVoxels to " << this->minPix + this->minChannels - 1 << " given minPix="<<this->minPix << " and minChannels="<<this->minChannels);
894      this->minVoxels = this->minPix + this->minChannels - 1;
895    }
896
897    // check that baselines are being calculated if we want to save them to a FITS file
898    if(this->flagOutputBaseline && !this->flagBaseline){
899      DUCHAMPWARN("Reading parameters","Saving of baseline values to a FITS file has been requested, but baselines are not being calculated. Turning off saving of baseline values.");
900      this->flagOutputBaseline = false;
901    }
902     
903  }
904
905  OUTCOME Param::checkImageExists()
906  {
907    /// A simple check to see whether the image actually exists or not, using the cfitsio interface.
908    /// If it does, we return SUCCESS, otherwise we throw an exception.
909
910    int exists,status = 0;  /* MUST initialize status */
911    fits_file_exists(this->imageFile.c_str(),&exists,&status);
912    if(exists<=0){
913      fits_report_error(stderr, status);
914      DUCHAMPTHROW("Cube Reader","Requested image " << this->imageFile << " does not exist!");
915      return FAILURE;
916    }
917    return SUCCESS;
918  }
919
920
921  void recordParameters(std::ostream& theStream, Param &par, std::string paramName, std::string paramDesc, std::string paramValue)
922  {
923   
924    const int width = 60;
925    int widthText = width - paramName.size();
926
927    theStream << par.commentString()
928              << std::setw(widthText) << paramDesc
929              << setiosflags(std::ios::right) << paramName
930              << "  =  " << resetiosflags(std::ios::right) << paramValue
931              <<std::endl;
932  }
933
934  std::string fileOption(bool flag, std::string file)
935  {
936    std::ostringstream ss;
937    ss << stringize(flag);
938    if(flag) ss << " --> " << file;
939    return ss.str();
940   
941  }
942
943  std::ostream& operator<< ( std::ostream& theStream, Param& par)
944  {
945    /// Print out the parameter set in a formatted, easy to read style.
946    /// Lists the parameters, a description of them, and their value.
947
948    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
949    //   theStream.setf(std::ios::boolalpha);
950    theStream.setf(std::ios::left);
951    theStream  <<par.commentString()<<"\n"<<par.commentString()<<"---- Parameters ----"<<std::endl;
952    theStream  << std::setfill('.');
953    if(par.getFlagSubsection())
954      recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection());
955    else
956      recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile());
957    if(par.getFlagRestFrequencyUsed()){
958      recordParam(theStream, par, "[restFrequency]","Rest frequency as used", par.getRestFrequency());
959    }
960    if(par.getFlagReconExists() && par.getFlagATrous()){
961      recordParam(theStream, par, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists()));
962      recordParam(theStream, par, "[reconFile]", "FITS file containing reconstruction", par.getReconFile());
963    }
964    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
965      recordParam(theStream, par, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists()));
966      recordParam(theStream, par, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile());
967    }
968    recordParam(theStream, par, "[logFile]", "Intermediate Logfile", par.logFile);
969    recordParam(theStream, par, "[outFile]", "Final Results file", par.getOutFile());
970    if(par.getFlagSeparateHeader()){
971      recordParam(theStream, par, "[headerFile]", "Header for results file", par.getHeaderFile());
972    }
973    if(USE_PGPLOT && par.getFlagPlotSpectra()){
974      std::string label=par.getSpectraFile();
975      if(par.getFlagPlotIndividualSpectra()) label += ", with individual spectra too";
976      recordParam(theStream, par, "[spectraFile]", "Spectrum file", label);
977    }
978    if(par.getFlagTextSpectra()){
979      recordParam(theStream, par, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile());
980    }
981    if(par.getFlagVOT()){
982      recordParam(theStream, par, "[votFile]", "VOTable file", par.getVOTFile());
983    }
984    if(par.getFlagKarma()){
985      recordParam(theStream, par, "[karmaFile]", "Karma annotation file" , par.getKarmaFile());
986    }
987    if(par.getFlagDS9()){
988      recordParam(theStream, par, "[ds9File]", "DS9 annotation file" , par.getDS9File());
989    }
990    if(par.getFlagCasa()){
991      recordParam(theStream, par, "[casaFile]", "CASA annotation file" , par.getCasaFile());
992    }
993    if(USE_PGPLOT && par.getFlagMaps()){
994      recordParam(theStream, par, "[momentMap]", "0th Moment Map", par.getMomentMap());
995      recordParam(theStream, par, "[detectionMap]", "Detection Map", par.getDetectionMap());
996    }
997    if(USE_PGPLOT){
998      recordParam(theStream, par, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput()));
999    }
1000    if(par.getFlagATrous()){
1001      recordParam(theStream, par, "[flagOutputRecon]", "Saving reconstructed cube?", fileOption(par.getFlagOutputRecon(),par.outputReconFile()));
1002      recordParam(theStream, par, "[flagOutputResid]", "Saving residuals from reconstruction?", fileOption(par.getFlagOutputResid(),par.outputResidFile()));
1003    }                                                 
1004    if(par.getFlagSmooth()){   
1005      recordParam(theStream, par, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile()));
1006    }                                                 
1007    recordParam(theStream, par, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile()));
1008    recordParam(theStream, par, "[flagOutputMomentMap]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile()));
1009    recordParam(theStream, par, "[flagOutputMomentMask]", "Saving 0th moment mask to FITS file?", fileOption(par.getFlagOutputMomentMask(),par.outputMomentMaskFile()));
1010    recordParam(theStream, par, "[flagOutputBaseline]", "Saving baseline values to FITS file?", fileOption(par.getFlagOutputBaseline(),par.outputBaselineFile()));
1011
1012    theStream  << par.commentString() <<"------"<<std::endl;
1013
1014    recordParam(theStream, par, "[searchType]", "Type of searching performed", par.getSearchType());
1015    if(par.getFlagBlankPix()){
1016      recordParam(theStream, par, "", "Blank Pixel Value", par.getBlankPixVal());
1017    }
1018    recordParam(theStream, par, "[flagTrim]", "Trimming Blank Pixels?", stringize(par.getFlagTrim()));
1019    recordParam(theStream, par, "[flagNegative]", "Searching for Negative features?", stringize(par.getFlagNegative()));
1020    recordParam(theStream, par, "[flagMW]", "Removing Milky Way channels?", stringize(par.getFlagMW()));
1021    if(par.getFlagMW()){
1022      // need to remove the offset correction, as we want to report the parameters actually entered
1023      recordParam(theStream, par, "[minMW - maxMW]", "Milky Way Channels", par.getMinMW()+par.getZOffset()<<"-"<<par.getMaxMW()+par.getZOffset());
1024    }
1025    if(par.beamAsUsed.origin()==EMPTY){  // No beam in FITS file and no information provided
1026      recordParam(theStream, par, "", "Area of Beam", "No beam");
1027    }
1028    else if(par.beamAsUsed.origin()==HEADER){ // Report beam size from FITS file
1029      recordParam(theStream, par, "", "Area of Beam (pixels)", par.beamAsUsed.area() << "   (beam: " << par.beamAsUsed.maj() << " x " << par.beamAsUsed.min() <<" pixels)");
1030    }
1031    else if(par.beamAsUsed.origin()==PARAM){ // Report beam size requested in parameter set input
1032      if(par.fwhmBeam>0.) recordParam(theStream, par, "[beamFWHM]", "FWHM of Beam (pixels)", par.beamAsUsed.maj() << "   (beam area = " << par.beamAsUsed.area() <<" pixels)");
1033      else  recordParam(theStream, par, "[beamArea]", "Area of Beam (pixels)", par.beamAsUsed.area());
1034    }
1035    else{
1036      recordParam(theStream, par, "[beam info]", "Size & shape of beam", "No information available!");
1037    }
1038    recordParam(theStream, par, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline()));
1039    recordParam(theStream, par, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth()));
1040    if(par.getFlagSmooth()){           
1041      recordParam(theStream, par, "[smoothType]", "Type of smoothing", par.getSmoothType());
1042      if(par.getSmoothType()=="spectral")
1043        recordParam(theStream, par, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth());
1044      else{
1045        recordParam(theStream, par, "[kernMaj]", "Gaussian kernel semi-major axis [pix]", par.getKernMaj());
1046        recordParam(theStream, par, "[kernMin]", "Gaussian kernel semi-minor axis [pix]", par.getKernMin());
1047        recordParam(theStream, par, "[kernPA]",  "Gaussian kernel position angle [deg]",  par.getKernPA());
1048      }
1049    }
1050    recordParam(theStream, par, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous()));
1051    if(par.getFlagATrous()){                           
1052      recordParam(theStream, par, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim());
1053      if(par.getMaxScale()>0){
1054        recordParam(theStream, par, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale());
1055      }
1056      else{
1057        recordParam(theStream, par, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale());
1058      }
1059      recordParam(theStream, par, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut());
1060      recordParam(theStream, par, "[reconConvergence]", "Residual convergence criterion", par.getReconConvergence());
1061      recordParam(theStream, par, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")");
1062    }                                                 
1063    recordParam(theStream, par, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats()));
1064    if(par.getFlagStatSec()){
1065      recordParam(theStream, par, "[statSec]", "Section used by statistics calculation", par.statSec.getSection());
1066    }
1067    recordParam(theStream, par, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR()));
1068    if(par.getFlagFDR()){                                     
1069      recordParam(theStream, par, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha());
1070      recordParam(theStream, par, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan());
1071    }                                                 
1072    else {
1073      if(par.getFlagUserThreshold()){
1074        recordParam(theStream, par, "[threshold]", "Detection Threshold", par.getThreshold());
1075      }
1076      else{
1077        recordParam(theStream, par, "[snrCut]", "SNR Threshold (in sigma)", par.getCut());
1078      }
1079    }
1080    recordParam(theStream, par, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix());
1081    recordParam(theStream, par, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels());
1082    recordParam(theStream, par, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels());
1083    recordParam(theStream, par, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth()));
1084    if(par.getFlagGrowth()) {                         
1085      if(par.getFlagUserGrowthThreshold()){
1086        recordParam(theStream, par, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold());
1087      }
1088      else{
1089        recordParam(theStream, par, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut());
1090      }
1091    }
1092    recordParam(theStream, par, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent()));
1093    if(!par.getFlagAdjacent()){
1094      recordParam(theStream, par, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS());
1095    }
1096    recordParam(theStream, par, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV());
1097    recordParam(theStream, par, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge()));
1098    recordParam(theStream, par, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging()));
1099    recordParam(theStream, par, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod());
1100    recordParam(theStream, par, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre());
1101
1102    theStream  << par.commentString() <<"--------------------\n";
1103    theStream  << std::setfill(' ');
1104    theStream.unsetf(std::ios::left);
1105    //  theStream.unsetf(std::ios::boolalpha);
1106    return theStream;
1107  }
1108
1109  std::vector<VOParam> Param::getVOParams()
1110  {
1111    std::vector<VOParam> vopars;
1112    vopars.push_back(VOParam("imageFile","meta.file;meta.fits","char",this->imageFile,this->imageFile.size(),""));
1113    vopars.push_back(VOParam("flagSubsection","meta.code","boolean",this->flagSubsection,0,""));
1114    if(this->flagSubsection)
1115      vopars.push_back(VOParam("subsection","","char",this->pixelSec.getSection(),this->pixelSec.getSection().size(),""));
1116    vopars.push_back(VOParam("flagStatSec","meta.code","boolean",this->flagStatSec,0,""));
1117    if(this->flagSubsection)
1118      vopars.push_back(VOParam("StatSec","","char",this->statSec.getSection(),this->statSec.getSection().size(),""));
1119    if(this->flagReconExists)
1120      vopars.push_back(VOParam("reconfile","meta.file;meta.fits","char",this->reconFile, this->reconFile.size(),""));
1121    if(this->flagSmoothExists)
1122      vopars.push_back(VOParam("smoothfile","meta.file;meta.fits","char",this->smoothFile, this->smoothFile.size(),""));
1123    if(this->usePrevious)
1124      vopars.push_back(VOParam("objectlist","","char",this->objectList,this->objectList.size(),""));
1125
1126    vopars.push_back(VOParam("searchType","meta.note","char",this->searchType,this->searchType.size(),""));
1127    vopars.push_back(VOParam("flagNegative","meta.code","boolean",this->flagNegative,0,""));
1128    vopars.push_back(VOParam("flagBaseline","meta.code","boolean",this->flagBaseline,0,""));
1129    vopars.push_back(VOParam("flagRobustStats","meta.code","boolean",this->flagRobustStats,0,""));
1130    vopars.push_back(VOParam("flagFDR","meta.code","boolean",this->flagFDR,0,""));
1131    if(this->flagFDR){
1132      vopars.push_back(VOParam("alphaFDR","stat.param","float",this->alphaFDR,0,""));
1133      vopars.push_back(VOParam("FDRnumCorChan","stat.param","int",this->FDRnumCorChan,0,""));
1134    }
1135    else{
1136      if(this->flagUserThreshold)
1137            vopars.push_back(VOParam("threshold","phot.flux;stat.min","float",this->threshold,0,""));
1138      else
1139        vopars.push_back(VOParam("snrCut","stat.snr;phot;stat.min","float",this->snrCut,0,""));
1140    }
1141    vopars.push_back(VOParam("flagGrowth","meta.code","boolean",this->flagGrowth,0,""));
1142    if(this->flagGrowth){
1143      if(this->flagUserGrowthThreshold)
1144        vopars.push_back(VOParam("growthThreshold","phot.flux;stat.min","float",this->growthThreshold,0,""));
1145      else
1146        vopars.push_back(VOParam("growthCut","stat.snr;phot;stat.min","float",this->growthCut,0,""));
1147    }
1148    vopars.push_back(VOParam("minVoxels","","int",minVoxels,0,""));
1149    vopars.push_back(VOParam("minPix","","int",minPix,0,""));
1150    vopars.push_back(VOParam("minChannels","","int",minChannels,0,""));
1151    vopars.push_back(VOParam("flagAdjacent","meta.code","boolean",this->flagAdjacent,0,""));
1152    if(!this->flagAdjacent)
1153      vopars.push_back(VOParam("threshSpatial","","float",this->threshSpatial,0,""));
1154    vopars.push_back(VOParam("threshVelocity","","float",this->threshVelocity,0,""));
1155    vopars.push_back(VOParam("flagRejectBeforeMerge","","boolean",this->flagRejectBeforeMerge,0,""));
1156    vopars.push_back(VOParam("flagTwoStageMerging","","boolean",this->flagTwoStageMerging,0,""));
1157    vopars.push_back(VOParam("pixelCentre","","char",this->pixelCentre,this->pixelCentre.size(),""));
1158    vopars.push_back(VOParam("flagSmooth","meta.code","boolean",this->flagSmooth,0,""));
1159    if(this->flagSmooth){
1160      vopars.push_back(VOParam("smoothType","","char",this->smoothType,this->smoothType.size(),""));
1161      if(this->smoothType=="spectral")
1162        vopars.push_back(VOParam("hanningWidth","","int",this->hanningWidth,0,""));
1163      else{
1164        vopars.push_back(VOParam("kernMaj","","float",this->kernMaj,0,""));
1165        vopars.push_back(VOParam("kernMin","","float",this->kernMin,0,""));
1166        vopars.push_back(VOParam("kernPA","","float",this->kernPA,0,""));
1167      }
1168    }
1169    vopars.push_back(VOParam("flagATrous","meta.code","boolean",this->flagATrous,0,""));
1170    if(this->flagATrous){
1171      vopars.push_back(VOParam("reconDim","","int",this->reconDim,0,""));
1172      vopars.push_back(VOParam("scaleMin","","int",this->scaleMin,0,""));
1173      if(this->scaleMax>0)
1174        vopars.push_back(VOParam("scaleMax","","int",this->scaleMax,0,""));
1175      vopars.push_back(VOParam("snrRecon","","float",this->snrRecon,0,""));
1176      vopars.push_back(VOParam("reconConvergence","","float",this->reconConvergence,0,""));
1177      vopars.push_back(VOParam("filterCode","","int",this->filterCode,0,""));
1178    }
1179    if(this->beamAsUsed.origin()==PARAM){
1180      if(this->fwhmBeam>0)
1181        vopars.push_back(VOParam("beamFWHM","","float",this->fwhmBeam,0,""));
1182      else
1183        vopars.push_back(VOParam("beamArea","","float",this->areaBeam,0,""));
1184    }
1185    if(this->restFrequencyUsed){
1186      vopars.push_back(VOParam("restFrequency","em.freq","float",this->restFrequency,0,"Hz"));
1187    }
1188
1189    return vopars;
1190
1191  }
1192
1193  void Param::writeToBinaryFile(std::string &filename)
1194  {
1195    std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
1196    writeStringToBinaryFile(outfile,this->imageFile);
1197    outfile.write(reinterpret_cast<const char*>(&this->flagSubsection), sizeof this->flagSubsection);
1198    if(this->flagSubsection) writeStringToBinaryFile(outfile,this->pixelSec.getSection());
1199    outfile.write(reinterpret_cast<const char*>(&this->flagStatSec), sizeof this->flagStatSec);
1200    if(this->flagStatSec) writeStringToBinaryFile(outfile,this->statSec.getSection());
1201    outfile.write(reinterpret_cast<const char*>(&this->flagReconExists), sizeof this->flagReconExists);
1202    if(this->flagReconExists) writeStringToBinaryFile(outfile,this->reconFile);
1203    outfile.write(reinterpret_cast<const char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists);
1204    if(this->flagSmoothExists) writeStringToBinaryFile(outfile,this->smoothFile);
1205    //
1206    writeStringToBinaryFile(outfile,this->searchType);
1207    outfile.write(reinterpret_cast<const char*>(&this->flagNegative), sizeof this->flagNegative);
1208    outfile.write(reinterpret_cast<const char*>(&this->flagBaseline), sizeof this->flagBaseline);
1209    outfile.write(reinterpret_cast<const char*>(&this->flagRobustStats), sizeof this->flagRobustStats);
1210    outfile.write(reinterpret_cast<const char*>(&this->flagFDR), sizeof this->flagFDR);
1211    if(this->flagFDR){
1212      outfile.write(reinterpret_cast<const char*>(&this->alphaFDR), sizeof this->alphaFDR);
1213      outfile.write(reinterpret_cast<const char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan);
1214      if(this->beamAsUsed.origin()==PARAM){
1215        outfile.write(reinterpret_cast<const char*>(&this->fwhmBeam), sizeof this->fwhmBeam);
1216        outfile.write(reinterpret_cast<const char*>(&this->areaBeam), sizeof this->areaBeam);
1217      }
1218    }
1219    else{
1220      outfile.write(reinterpret_cast<const char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold);
1221      if(this->flagUserThreshold)
1222        outfile.write(reinterpret_cast<const char*>(&this->threshold), sizeof this->threshold);
1223      else
1224        outfile.write(reinterpret_cast<const char*>(&this->snrCut), sizeof this->snrCut);
1225    }
1226    outfile.write(reinterpret_cast<const char*>(&this->flagGrowth), sizeof this->flagGrowth);
1227    if(this->flagGrowth){
1228      if(this->flagUserGrowthThreshold)
1229        outfile.write(reinterpret_cast<const char*>(&this->growthThreshold), sizeof this->growthThreshold);
1230      else
1231        outfile.write(reinterpret_cast<const char*>(&this->growthCut), sizeof this->growthCut);
1232    }
1233    outfile.write(reinterpret_cast<const char*>(&this->minVoxels), sizeof this->minVoxels);
1234    outfile.write(reinterpret_cast<const char*>(&this->minPix), sizeof this->minPix);
1235    outfile.write(reinterpret_cast<const char*>(&this->minChannels), sizeof this->minChannels);
1236    outfile.write(reinterpret_cast<const char*>(&this->flagAdjacent), sizeof this->flagAdjacent);
1237    if(!this->flagAdjacent)
1238      outfile.write(reinterpret_cast<const char*>(&this->threshSpatial), sizeof this->threshSpatial);
1239    outfile.write(reinterpret_cast<const char*>(&this->threshVelocity), sizeof this->threshVelocity);
1240    outfile.write(reinterpret_cast<const char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge);
1241    outfile.write(reinterpret_cast<const char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging);
1242    outfile.write(reinterpret_cast<const char*>(&this->flagSmooth), sizeof this->flagSmooth);
1243    if(this->flagSmooth){
1244      bool type=(this->smoothType=="spectral");
1245      outfile.write(reinterpret_cast<const char*>(&type), sizeof type);
1246      if(type)
1247        outfile.write(reinterpret_cast<const char*>(&this->hanningWidth), sizeof this->hanningWidth);
1248      else{
1249        outfile.write(reinterpret_cast<const char*>(&this->kernMaj), sizeof this->kernMaj);
1250        outfile.write(reinterpret_cast<const char*>(&this->kernMin), sizeof this->kernMin);
1251        outfile.write(reinterpret_cast<const char*>(&this->kernPA), sizeof this->kernPA);
1252      }
1253    }
1254    outfile.write(reinterpret_cast<const char*>(&this->flagATrous), sizeof this->flagATrous);
1255    if(this->flagATrous){
1256      outfile.write(reinterpret_cast<const char*>(&this->reconDim), sizeof this->reconDim);
1257      outfile.write(reinterpret_cast<const char*>(&this->scaleMin), sizeof this->scaleMin);
1258      outfile.write(reinterpret_cast<const char*>(&this->scaleMax), sizeof this->scaleMax);
1259      outfile.write(reinterpret_cast<const char*>(&this->snrRecon), sizeof this->snrRecon);
1260      outfile.write(reinterpret_cast<const char*>(&this->reconConvergence), sizeof this->reconConvergence);
1261      outfile.write(reinterpret_cast<const char*>(&this->filterCode), sizeof this->filterCode);
1262    }
1263    outfile.write(reinterpret_cast<const char*>(&this->flagMW), sizeof this->flagMW);
1264    if(this->flagMW){
1265      outfile.write(reinterpret_cast<const char*>(&this->minMW), sizeof this->minMW);
1266      outfile.write(reinterpret_cast<const char*>(&this->maxMW), sizeof this->maxMW);
1267    }
1268   
1269    outfile.close();
1270  }
1271
1272  std::streampos Param::readFromBinaryFile(std::string &filename, std::streampos loc)
1273  {
1274    std::ifstream infile(filename.c_str(), std::ios::in | std::ios::binary);
1275    if(!infile.is_open()){
1276      DUCHAMPERROR("read binary parameters","Could not open binary catalogue \""<<filename <<"\"");
1277      return -1;
1278    }
1279    infile.seekg(loc);
1280    this->imageFile = readStringFromBinaryFile(infile);
1281    infile.read(reinterpret_cast<char*>(&this->flagSubsection), sizeof this->flagSubsection);
1282    if(this->flagSubsection){
1283      std::string sec=readStringFromBinaryFile(infile);
1284      this->pixelSec.setSection(sec);
1285    }
1286    infile.read(reinterpret_cast<char*>(&this->flagStatSec), sizeof this->flagStatSec);
1287    if(this->flagStatSec){
1288      std::string sec=readStringFromBinaryFile(infile);
1289      this->statSec.setSection(sec);
1290    }
1291    infile.read(reinterpret_cast<char*>(&this->flagReconExists), sizeof this->flagReconExists);
1292    if(this->flagReconExists) this->reconFile=readStringFromBinaryFile(infile);
1293    infile.read(reinterpret_cast<char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists);
1294    if(this->flagSmoothExists) this->smoothFile=readStringFromBinaryFile(infile);
1295    //
1296    this->searchType=readStringFromBinaryFile(infile);
1297    infile.read(reinterpret_cast<char*>(&this->flagNegative), sizeof this->flagNegative);
1298    infile.read(reinterpret_cast<char*>(&this->flagBaseline), sizeof this->flagBaseline);
1299    infile.read(reinterpret_cast<char*>(&this->flagRobustStats), sizeof this->flagRobustStats);
1300    infile.read(reinterpret_cast<char*>(&this->flagFDR), sizeof this->flagFDR);
1301    if(this->flagFDR){
1302      infile.read(reinterpret_cast<char*>(&this->alphaFDR), sizeof this->alphaFDR);
1303      infile.read(reinterpret_cast<char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan);
1304      if(this->beamAsUsed.origin()==PARAM){
1305        infile.read(reinterpret_cast<char*>(&this->fwhmBeam), sizeof this->fwhmBeam);
1306        infile.read(reinterpret_cast<char*>(&this->areaBeam), sizeof this->areaBeam);
1307      }
1308    }
1309    else{
1310      infile.read(reinterpret_cast<char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold);
1311      if(this->flagUserThreshold)
1312        infile.read(reinterpret_cast<char*>(&this->threshold), sizeof this->threshold);
1313      else
1314        infile.read(reinterpret_cast<char*>(&this->snrCut), sizeof this->snrCut);
1315    }
1316    infile.read(reinterpret_cast<char*>(&this->flagGrowth), sizeof this->flagGrowth);
1317    if(this->flagGrowth){
1318      if(this->flagUserGrowthThreshold)
1319        infile.read(reinterpret_cast<char*>(&this->growthThreshold), sizeof this->growthThreshold);
1320      else
1321        infile.read(reinterpret_cast<char*>(&this->growthCut), sizeof this->growthCut);
1322    }
1323    infile.read(reinterpret_cast<char*>(&this->minVoxels), sizeof this->minVoxels);
1324    infile.read(reinterpret_cast<char*>(&this->minPix), sizeof this->minPix);
1325    infile.read(reinterpret_cast<char*>(&this->minChannels), sizeof this->minChannels);
1326    infile.read(reinterpret_cast<char*>(&this->flagAdjacent), sizeof this->flagAdjacent);
1327    if(!this->flagAdjacent)
1328      infile.read(reinterpret_cast<char*>(&this->threshSpatial), sizeof this->threshSpatial);
1329    infile.read(reinterpret_cast<char*>(&this->threshVelocity), sizeof this->threshVelocity);
1330    infile.read(reinterpret_cast<char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge);
1331    infile.read(reinterpret_cast<char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging);
1332    infile.read(reinterpret_cast<char*>(&this->flagSmooth), sizeof this->flagSmooth);
1333    if(this->flagSmooth){
1334      bool type;
1335      infile.read(reinterpret_cast<char*>(&type), sizeof type);
1336      this->smoothType = type ? "spectral" : "spatial";
1337      if(type)
1338        infile.read(reinterpret_cast<char*>(&this->hanningWidth), sizeof this->hanningWidth);
1339      else{
1340        infile.read(reinterpret_cast<char*>(&this->kernMaj), sizeof this->kernMaj);
1341        infile.read(reinterpret_cast<char*>(&this->kernMin), sizeof this->kernMin);
1342        infile.read(reinterpret_cast<char*>(&this->kernPA), sizeof this->kernPA);
1343      }
1344    }
1345    infile.read(reinterpret_cast<char*>(&this->flagATrous), sizeof this->flagATrous);
1346    if(this->flagATrous){
1347      infile.read(reinterpret_cast<char*>(&this->reconDim), sizeof this->reconDim);
1348      infile.read(reinterpret_cast<char*>(&this->scaleMin), sizeof this->scaleMin);
1349      infile.read(reinterpret_cast<char*>(&this->scaleMax), sizeof this->scaleMax);
1350      infile.read(reinterpret_cast<char*>(&this->snrRecon), sizeof this->snrRecon);
1351      infile.read(reinterpret_cast<char*>(&this->reconConvergence), sizeof this->reconConvergence);
1352      infile.read(reinterpret_cast<char*>(&this->filterCode), sizeof this->filterCode);
1353    }
1354    infile.read(reinterpret_cast<char*>(&this->flagMW), sizeof this->flagMW);
1355    if(this->flagMW){
1356      infile.read(reinterpret_cast<char*>(&this->minMW), sizeof this->minMW);
1357      infile.read(reinterpret_cast<char*>(&this->maxMW), sizeof this->maxMW);
1358    }
1359   
1360    std::streampos newloc = infile.tellg();
1361    infile.close();
1362    return newloc;
1363
1364  }
1365
1366
1367
1368
1369  void Param::copyHeaderInfo(FitsHeader &head)
1370  {
1371    ///  A function to copy across relevant header keywords from the
1372    ///  FitsHeader class to the Param class, as they are needed by
1373    ///  functions in the Param class.
1374    ///  The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1375
1376    this->blankKeyword  = head.getBlankKeyword();
1377    this->bscaleKeyword = head.getBscaleKeyword();
1378    this->bzeroKeyword  = head.getBzeroKeyword();
1379    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1380      this->bzeroKeyword;
1381  }
1382
1383  std::string Param::outputMaskFile()
1384  {
1385    ///  This function produces the required filename in which to save
1386    ///  the mask image, indicating which pixels have been detected as
1387    ///  part of an object. If the input image is image.fits, then the
1388    ///  output will be image.MASK.fits.
1389
1390    if(this->fileOutputMask==""){
1391      std::string inputName = this->imageFile;
1392      std::string outputName = inputName;
1393      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1394        outputName = inputName.substr(0,inputName.size()-5); 
1395      // remove the ".fits" on the end.
1396      outputName += ".MASK.fits";
1397      return outputName;
1398    }
1399    else return this->fileOutputMask;
1400  }
1401
1402  std::string Param::outputMomentMapFile()
1403  {
1404    ///  This function produces the required filename in which to save
1405    ///  the moment-0 FITS image. If the input image is image.fits, then the
1406    ///  output will be image.MOM0.fits.
1407
1408    if(this->fileOutputMomentMap==""){
1409      std::string inputName = this->imageFile;
1410      std::string outputName = inputName;
1411      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1412        outputName = inputName.substr(0,inputName.size()-5); 
1413      // remove the ".fits" on the end.
1414      outputName += ".MOM0.fits";
1415      return outputName;
1416    }
1417    else return this->fileOutputMomentMap;
1418  }
1419
1420  std::string Param::outputMomentMaskFile()
1421  {
1422    ///  This function produces the required filename in which to save
1423    ///  the moment-0 FITS image. If the input image is image.fits, then the
1424    ///  output will be image.MOM0.fits.
1425
1426    if(this->fileOutputMomentMask==""){
1427      std::string inputName = this->imageFile;
1428      std::string outputName = inputName;
1429      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1430        outputName = inputName.substr(0,inputName.size()-5); 
1431      // remove the ".fits" on the end.
1432      outputName += ".MOM0MASK.fits";
1433      return outputName;
1434    }
1435    else return this->fileOutputMomentMask;
1436  }
1437
1438  std::string Param::outputBaselineFile()
1439  {
1440    ///  This function produces the required filename in which to save
1441    ///  the baseline FITS image. If the input image is image.fits, then the
1442    ///  output will be image.BASE.fits.
1443
1444    if(this->fileOutputBaseline==""){
1445      std::string inputName = this->imageFile;
1446      std::string outputName = inputName;
1447      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1448        outputName = inputName.substr(0,inputName.size()-5); 
1449      // remove the ".fits" on the end.
1450      outputName += ".BASE.fits";
1451      return outputName;
1452    }
1453    else return this->fileOutputBaseline;
1454  }
1455
1456  std::string Param::outputSmoothFile()
1457  {
1458    ///  This function produces the required filename in which to save
1459    ///   the smoothed array. If the input image is image.fits, then
1460    ///   the output will be:
1461    ///    <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1462    ///             width of the Hanning filter was 3 pixels.
1463    ///        <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1464    ///             kernMaj=3, kernMin=2 and kernPA=20 degrees.
1465    ///    </ul>
1466
1467    if(this->fileOutputSmooth==""){
1468      std::string inputName = this->imageFile;
1469      std::stringstream ss;
1470      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1471        ss << inputName.substr(0,inputName.size()-5); 
1472      else
1473        ss << inputName;
1474      // remove the ".fits" on the end if necessary.
1475      if(this->flagSubsection) ss<<".sub";
1476      if(this->smoothType=="spectral")
1477        ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1478      else if(this->smoothType=="spatial")
1479        ss << ".SMOOTH-2D-"
1480           << this->kernMaj << "-"
1481           << this->kernMin << "-"
1482           << this->kernPA  << ".fits";
1483      return ss.str();
1484    }
1485    else return this->fileOutputSmooth;
1486  }
1487
1488  std::string Param::outputReconFile()
1489  {
1490    /// This function produces the required filename in which to save
1491    ///  the reconstructed array. If the input image is image.fits, then
1492    ///  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1493    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1494
1495    if(this->fileOutputRecon==""){
1496      std::string inputName = this->imageFile;
1497      std::stringstream ss;
1498      // First we remove the ".fits" from the end of the filename.
1499      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1500          ss << inputName.substr(0,inputName.size()-5); 
1501      else
1502          ss << inputName;
1503      if(this->flagSubsection) ss<<".sub";
1504      ss << ".RECON-" << this->reconDim
1505         << "-"       << this->filterCode
1506         << "-"       << this->snrRecon
1507         << "-"       << this->scaleMin
1508         << "-"       << this->scaleMax
1509         << "-"       << this->reconConvergence
1510         << ".fits";
1511      return ss.str();
1512    }
1513    else return this->fileOutputRecon;
1514  }
1515
1516  std::string Param::outputResidFile()
1517  {
1518    /// This function produces the required filename in which to save
1519    ///  the reconstructed array. If the input image is image.fits, then
1520    ///  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1521    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1522
1523    if(this->fileOutputResid==""){
1524      std::string inputName = this->imageFile;
1525      std::stringstream ss;
1526      // First we remove the ".fits" from the end of the filename.
1527      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1528          ss << inputName.substr(0,inputName.size()-5);
1529      else
1530          ss << inputName;
1531      if(this->flagSubsection) ss<<".sub";
1532      ss << ".RESID-" << this->reconDim
1533         << "-"       << this->filterCode
1534         << "-"       << this->snrRecon
1535         << "-"       << this->scaleMin
1536         << "-"       << this->scaleMax
1537         << "-"       << this->reconConvergence
1538         << ".fits";
1539      return ss.str();
1540    }
1541    else return this->fileOutputResid;
1542  }
1543
1544}
Note: See TracBrowser for help on using the repository browser.