source: trunk/src/param.cc @ 1251

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

Ticket #193 - Adding a warning message should anyone try to use flagMW.

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