source: trunk/src/param.cc @ 1247

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

Ticket #193 - Fixing code so it works when no flaggedChannelList is provided.

File size: 69.0 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
736      }
737    }
738
739    this->checkPars();
740
741    return SUCCESS;
742
743  }
744 
745  void Param::checkPars()
746  {
747
748    // If flagSubsection is false, but the parset had a subsection string in it, we want to set this back to the default.
749    if(!this->flagSubsection){
750      this->pixelSec.setSection(defaultSection);
751    }
752    if(!this->flagStatSec){
753      this->statSec.setSection(defaultSection);
754    }
755
756    // If we have usePrevious=false, set the objectlist to blank so that we use all of them. Otherwise, define the vector list of choices.
757    if(!this->usePrevious) this->objectList = "";
758    else this->objectListVector = selectionToIntVec(this->objectList);
759
760    // Defining the vector list of flagged channels
761    if(this->flaggedChannelList.size()>0){
762        this->flaggedChannels = selectionToIntVec(this->flaggedChannelList);
763        this->flaggedChannelMask = std::vector<bool>(*std::max_element(this->flaggedChannels.begin(),this->flaggedChannels.end()),false);
764        for(size_t i=0;i<this->flaggedChannels.size();i++) this->flaggedChannelMask[ this->flaggedChannels[i] ] = true;
765    }
766
767    // If pgplot was not included in the compilation, need to set flagXOutput to false
768    if(!USE_PGPLOT){
769      if(this->flagXOutput || this->flagMaps || this->flagPlotSpectra || this->flagPlotIndividualSpectra)
770        DUCHAMPWARN("Reading parameters","PGPlot has not been enabled, so setting flagXOutput, flagMaps, flagPlotSpectra and flagPlotIndividualSpectra to false.");
771      this->flagXOutput = false;
772      this->flagMaps = false;
773      this->flagPlotSpectra = false;
774      this->flagPlotIndividualSpectra = false;
775    }
776
777    if(!this->flagPlotSpectra && this->flagPlotIndividualSpectra){
778      DUCHAMPWARN("Reading parameters","flagPlotSpectra is false, so setting flagPlotIndividualSpectra to false as well.");
779      this->flagPlotIndividualSpectra = false;
780    }
781
782    // Correcting bad precision values -- if negative, set to 0
783    if(this->precFlux<0) this->precFlux = 0;
784    if(this->precVel<0)  this->precVel = 0;
785    if(this->precSNR<0)  this->precSNR = 0;
786
787    // Can only have "spatial" or "spectral" as search types
788    if(this->searchType != "spatial" && this->searchType != "spectral"){
789      DUCHAMPWARN("Reading parameters","You have requested a search type of \""<<this->searchType<<"\" -- Only \"spectral\" and \"spatial\" are accepted, so setting to \"spatial\".");
790      this->searchType = "spatial";
791    }
792
793    // The wavelet reconstruction takes precendence over the smoothing.
794    if(this->flagATrous) this->flagSmooth = false;
795
796    // Check validity of recon parameters
797    if(this->flagATrous){
798      if(this->reconConvergence < 0.){
799        DUCHAMPWARN("Reading Parameters","Your reconConvergence value is negative ("<<this->reconConvergence<<") - setting to " << -this->reconConvergence <<".");
800        this->reconConvergence *= -1.;
801      }
802
803      this->reconFilter.define(this->filterCode);
804
805      if((this->scaleMax) > 0 && (this->scaleMax < this->scaleMin)){
806        DUCHAMPWARN("Reading Parameters","Reconstruction scaleMax ("<<this->scaleMax<<") is less than scaleMin ("<<this->scaleMin<<"): setting both to "<<this->scaleMin);
807        this->scaleMax = this->scaleMin;
808      }
809
810      if( (this->reconDim < 1) || (this->reconDim > 3) ){
811        DUCHAMPWARN("Reading Parameters", "You requested a " << this->reconDim << " dimensional reconstruction. Setting reconDim to 1");
812        this->reconDim = 1;
813      }
814
815      if( this->snrRecon < 0.){
816        DUCHAMPWARN("Reading Parameters", "Your snrRecon value is negative (" << this->snrRecon<<"). Turning reconstruction off -- fix your parameter file!");
817        this->flagATrous = false;
818      }
819
820    }
821
822    if(this->flagUserThreshold){
823
824      // If we specify a manual threshold, need to also specify a manual growth threshold
825      // If we haven't done so, turn growing off
826      if(this->flagGrowth && !this->flagUserGrowthThreshold){
827        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.");
828        DUCHAMPWARN("Reading parameters","The growth function is being turned off.");
829        this->flagGrowth = false;
830      }
831
832      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
833      if(this->flagFDR){
834        DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, so we don't need to use the FDR method. Setting \"flagFDR=false\".");
835        this->flagFDR = false;
836      }
837
838    }   
839
840    // Make sure the growth level is less than the detection level. Else turn off growing.
841    if(this->flagGrowth){
842      std::stringstream errmsg;
843      bool doWarn = false;
844      if(this->flagUserThreshold &&
845         ( (this->threshold < this->growthThreshold)
846           || (this->snrCut < this->growthCut) ) ){
847        errmsg << "Your \"growthThreshold\" parameter" << this->growthThreshold <<" is larger than your \"threshold\"" << this->threshold;
848        doWarn = true;
849      }
850     
851      if(!this->flagUserThreshold &&
852         (this->snrCut < this->growthCut)) {
853        errmsg << "Your \"growthCut\" parameter " << this->growthCut << " is larger than your \"snrCut\"" << this->snrCut;
854        doWarn = true;
855      }
856
857      if(doWarn){
858        DUCHAMPWARN("Reading parameters",errmsg);
859        DUCHAMPWARN("Reading parameters","The growth function is being turned off.");
860
861      }
862    }
863
864    // Make sure the annnotationType is an acceptable option -- default is "borders"
865    if((this->annotationType != "borders") && (this->annotationType!="circles") && (this->annotationType!="ellipses")){
866      DUCHAMPWARN("Reading parameters","The requested value of the parameter annotationType, \"" << this->annotationType << "\", is invalid -- changing to \"borders\".");
867      this->annotationType = "borders";
868    }
869     
870    // Make sure smoothType is an acceptable type -- default is "spectral"
871    if((this->smoothType!="spectral")&&
872       (this->smoothType!="spatial")){
873      DUCHAMPWARN("Reading parameters","The requested value of the parameter smoothType, \"" << this->smoothType << "\", is invalid -- changing to \"spectral\".");
874      this->smoothType = "spectral";
875    }
876    // If kernMin has not been given, or is negative, make it equal to kernMaj
877    if(this->kernMin < 0) this->kernMin = this->kernMaj;
878
879    // Make sure spectralMethod is an acceptable type -- default is "peak"
880    if((this->spectralMethod!="peak")&&
881       (this->spectralMethod!="sum")){
882      DUCHAMPWARN("Reading parameters","The requested value of the parameter spectralMethod, \"" << this->spectralMethod << "\", is invalid -- changing to \"peak\".");
883      this->spectralMethod = "peak";
884    }
885
886    // make sure pixelCentre is an acceptable type -- default is "peak"
887    if((this->pixelCentre!="centroid")&&
888       (this->pixelCentre!="average") &&
889       (this->pixelCentre!="peak")       ){
890      DUCHAMPWARN("Reading parameters","The requested value of the parameter pixelCentre, \"" << this->pixelCentre << "\", is invalid -- changing to \"centroid\".");
891      this->pixelCentre = "centroid";
892    }
893
894    // Make sure sortingParam is an acceptable type -- default is "vel"
895    bool OK = false;
896    int loc=(this->sortingParam[0]=='-') ? 1 : 0;
897    for(int i=0;i<numSortingParamOptions;i++)
898      OK = OK || this->sortingParam.substr(loc)==sortingParamOptions[i];
899    if(!OK){
900      DUCHAMPWARN("Reading parameters","The requested value of the parameter sortingParam, \"" << this->sortingParam << "\", is invalid. -- changing to \"vel\".");
901      this->sortingParam = "vel";
902    }
903
904    // Make sure minVoxels is appropriate given minChannels & minPixels
905    if(this->minVoxels < (this->minPix + this->minChannels - 1) ){
906      DUCHAMPWARN("Reading parameters","Changing minVoxels to " << this->minPix + this->minChannels - 1 << " given minPix="<<this->minPix << " and minChannels="<<this->minChannels);
907      this->minVoxels = this->minPix + this->minChannels - 1;
908    }
909
910    // check that baselines are being calculated if we want to save them to a FITS file
911    if(this->flagOutputBaseline && !this->flagBaseline){
912      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.");
913      this->flagOutputBaseline = false;
914    }
915     
916  }
917
918  OUTCOME Param::checkImageExists()
919  {
920    /// A simple check to see whether the image actually exists or not, using the cfitsio interface.
921    /// If it does, we return SUCCESS, otherwise we throw an exception.
922
923    int exists,status = 0;  /* MUST initialize status */
924    fits_file_exists(this->imageFile.c_str(),&exists,&status);
925    if(exists<=0){
926      fits_report_error(stderr, status);
927      DUCHAMPTHROW("Cube Reader","Requested image " << this->imageFile << " does not exist!");
928      return FAILURE;
929    }
930    return SUCCESS;
931  }
932
933
934  void recordParameters(std::ostream& theStream, Param &par, std::string paramName, std::string paramDesc, std::string paramValue)
935  {
936   
937    const int width = 60;
938    int widthText = width - paramName.size();
939
940    theStream << par.commentString()
941              << std::setw(widthText) << paramDesc
942              << setiosflags(std::ios::right) << paramName
943              << "  =  " << resetiosflags(std::ios::right) << paramValue
944              <<std::endl;
945  }
946
947  std::string fileOption(bool flag, std::string file)
948  {
949    std::ostringstream ss;
950    ss << stringize(flag);
951    if(flag) ss << " --> " << file;
952    return ss.str();
953   
954  }
955
956  std::ostream& operator<< ( std::ostream& theStream, Param& par)
957  {
958    /// Print out the parameter set in a formatted, easy to read style.
959    /// Lists the parameters, a description of them, and their value.
960
961    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
962    //   theStream.setf(std::ios::boolalpha);
963    theStream.setf(std::ios::left);
964    theStream  <<par.commentString()<<"\n"<<par.commentString()<<"---- Parameters ----"<<std::endl;
965    theStream  << std::setfill('.');
966    if(par.getFlagSubsection())
967      recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection());
968    else
969      recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile());
970    if(par.getFlagRestFrequencyUsed()){
971      recordParam(theStream, par, "[restFrequency]","Rest frequency as used", par.getRestFrequency());
972    }
973    if(par.getFlagReconExists() && par.getFlagATrous()){
974      recordParam(theStream, par, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists()));
975      recordParam(theStream, par, "[reconFile]", "FITS file containing reconstruction", par.getReconFile());
976    }
977    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
978      recordParam(theStream, par, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists()));
979      recordParam(theStream, par, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile());
980    }
981    recordParam(theStream, par, "[logFile]", "Intermediate Logfile", par.logFile);
982    recordParam(theStream, par, "[outFile]", "Final Results file", par.getOutFile());
983    if(par.getFlagSeparateHeader()){
984      recordParam(theStream, par, "[headerFile]", "Header for results file", par.getHeaderFile());
985    }
986    if(USE_PGPLOT && par.getFlagPlotSpectra()){
987      std::string label=par.getSpectraFile();
988      if(par.getFlagPlotIndividualSpectra()) label += ", with individual spectra too";
989      recordParam(theStream, par, "[spectraFile]", "Spectrum file", label);
990    }
991    if(par.getFlagTextSpectra()){
992      recordParam(theStream, par, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile());
993    }
994    if(par.getFlagVOT()){
995      recordParam(theStream, par, "[votFile]", "VOTable file", par.getVOTFile());
996    }
997    if(par.getFlagKarma()){
998      recordParam(theStream, par, "[karmaFile]", "Karma annotation file" , par.getKarmaFile());
999    }
1000    if(par.getFlagDS9()){
1001      recordParam(theStream, par, "[ds9File]", "DS9 annotation file" , par.getDS9File());
1002    }
1003    if(par.getFlagCasa()){
1004      recordParam(theStream, par, "[casaFile]", "CASA annotation file" , par.getCasaFile());
1005    }
1006    if(USE_PGPLOT && par.getFlagMaps()){
1007      recordParam(theStream, par, "[momentMap]", "0th Moment Map", par.getMomentMap());
1008      recordParam(theStream, par, "[detectionMap]", "Detection Map", par.getDetectionMap());
1009    }
1010    if(USE_PGPLOT){
1011      recordParam(theStream, par, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput()));
1012    }
1013    if(par.getFlagATrous()){
1014      recordParam(theStream, par, "[flagOutputRecon]", "Saving reconstructed cube?", fileOption(par.getFlagOutputRecon(),par.outputReconFile()));
1015      recordParam(theStream, par, "[flagOutputResid]", "Saving residuals from reconstruction?", fileOption(par.getFlagOutputResid(),par.outputResidFile()));
1016    }                                                 
1017    if(par.getFlagSmooth()){   
1018      recordParam(theStream, par, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile()));
1019    }                                                 
1020    recordParam(theStream, par, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile()));
1021    recordParam(theStream, par, "[flagOutputMomentMap]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile()));
1022    recordParam(theStream, par, "[flagOutputMomentMask]", "Saving 0th moment mask to FITS file?", fileOption(par.getFlagOutputMomentMask(),par.outputMomentMaskFile()));
1023    recordParam(theStream, par, "[flagOutputBaseline]", "Saving baseline values to FITS file?", fileOption(par.getFlagOutputBaseline(),par.outputBaselineFile()));
1024
1025    theStream  << par.commentString() <<"------"<<std::endl;
1026
1027    recordParam(theStream, par, "[searchType]", "Type of searching performed", par.getSearchType());
1028    if(par.getFlagBlankPix()){
1029      recordParam(theStream, par, "", "Blank Pixel Value", par.getBlankPixVal());
1030    }
1031    recordParam(theStream, par, "[flagTrim]", "Trimming Blank Pixels?", stringize(par.getFlagTrim()));
1032    recordParam(theStream, par, "[flagNegative]", "Searching for Negative features?", stringize(par.getFlagNegative()));
1033    if(par.getFlaggedChannelList().size()>0){
1034        recordParam(theStream, par, "[flaggedChannels]", "Channels flagged by user", par.getFlaggedChannelList());
1035    }
1036    if(par.beamAsUsed.origin()==EMPTY){  // No beam in FITS file and no information provided
1037      recordParam(theStream, par, "", "Area of Beam", "No beam");
1038    }
1039    else if(par.beamAsUsed.origin()==HEADER){ // Report beam size from FITS file
1040      recordParam(theStream, par, "", "Area of Beam (pixels)", par.beamAsUsed.area() << "   (beam: " << par.beamAsUsed.maj() << " x " << par.beamAsUsed.min() <<" pixels)");
1041    }
1042    else if(par.beamAsUsed.origin()==PARAM){ // Report beam size requested in parameter set input
1043      if(par.fwhmBeam>0.) recordParam(theStream, par, "[beamFWHM]", "FWHM of Beam (pixels)", par.beamAsUsed.maj() << "   (beam area = " << par.beamAsUsed.area() <<" pixels)");
1044      else  recordParam(theStream, par, "[beamArea]", "Area of Beam (pixels)", par.beamAsUsed.area());
1045    }
1046    else{
1047      recordParam(theStream, par, "[beam info]", "Size & shape of beam", "No information available!");
1048    }
1049    recordParam(theStream, par, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline()));
1050    recordParam(theStream, par, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth()));
1051    if(par.getFlagSmooth()){           
1052      recordParam(theStream, par, "[smoothType]", "Type of smoothing", par.getSmoothType());
1053      if(par.getSmoothType()=="spectral")
1054        recordParam(theStream, par, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth());
1055      else{
1056        recordParam(theStream, par, "[kernMaj]", "Gaussian kernel semi-major axis [pix]", par.getKernMaj());
1057        recordParam(theStream, par, "[kernMin]", "Gaussian kernel semi-minor axis [pix]", par.getKernMin());
1058        recordParam(theStream, par, "[kernPA]",  "Gaussian kernel position angle [deg]",  par.getKernPA());
1059      }
1060    }
1061    recordParam(theStream, par, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous()));
1062    if(par.getFlagATrous()){                           
1063      recordParam(theStream, par, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim());
1064      if(par.getMaxScale()>0){
1065        recordParam(theStream, par, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale());
1066      }
1067      else{
1068        recordParam(theStream, par, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale());
1069      }
1070      recordParam(theStream, par, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut());
1071      recordParam(theStream, par, "[reconConvergence]", "Residual convergence criterion", par.getReconConvergence());
1072      recordParam(theStream, par, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")");
1073    }                                                 
1074    recordParam(theStream, par, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats()));
1075    if(par.getFlagStatSec()){
1076      recordParam(theStream, par, "[statSec]", "Section used by statistics calculation", par.statSec.getSection());
1077    }
1078    recordParam(theStream, par, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR()));
1079    if(par.getFlagFDR()){                                     
1080      recordParam(theStream, par, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha());
1081      recordParam(theStream, par, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan());
1082    }                                                 
1083    else {
1084      if(par.getFlagUserThreshold()){
1085        recordParam(theStream, par, "[threshold]", "Detection Threshold", par.getThreshold());
1086      }
1087      else{
1088        recordParam(theStream, par, "[snrCut]", "SNR Threshold (in sigma)", par.getCut());
1089      }
1090    }
1091    recordParam(theStream, par, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix());
1092    recordParam(theStream, par, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels());
1093    recordParam(theStream, par, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels());
1094    recordParam(theStream, par, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth()));
1095    if(par.getFlagGrowth()) {                         
1096      if(par.getFlagUserGrowthThreshold()){
1097        recordParam(theStream, par, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold());
1098      }
1099      else{
1100        recordParam(theStream, par, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut());
1101      }
1102    }
1103    recordParam(theStream, par, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent()));
1104    if(!par.getFlagAdjacent()){
1105      recordParam(theStream, par, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS());
1106    }
1107    recordParam(theStream, par, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV());
1108    recordParam(theStream, par, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge()));
1109    recordParam(theStream, par, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging()));
1110    recordParam(theStream, par, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod());
1111    recordParam(theStream, par, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre());
1112
1113    theStream  << par.commentString() <<"--------------------\n";
1114    theStream  << std::setfill(' ');
1115    theStream.unsetf(std::ios::left);
1116    //  theStream.unsetf(std::ios::boolalpha);
1117    return theStream;
1118  }
1119
1120  std::vector<VOParam> Param::getVOParams()
1121  {
1122    std::vector<VOParam> vopars;
1123    vopars.push_back(VOParam("imageFile","meta.file;meta.fits","char",this->imageFile,this->imageFile.size(),""));
1124    vopars.push_back(VOParam("flagSubsection","meta.code","boolean",this->flagSubsection,0,""));
1125    if(this->flagSubsection)
1126      vopars.push_back(VOParam("subsection","","char",this->pixelSec.getSection(),this->pixelSec.getSection().size(),""));
1127    vopars.push_back(VOParam("flagStatSec","meta.code","boolean",this->flagStatSec,0,""));
1128    if(this->flagSubsection)
1129      vopars.push_back(VOParam("StatSec","","char",this->statSec.getSection(),this->statSec.getSection().size(),""));
1130    if(this->flagReconExists)
1131      vopars.push_back(VOParam("reconfile","meta.file;meta.fits","char",this->reconFile, this->reconFile.size(),""));
1132    if(this->flagSmoothExists)
1133      vopars.push_back(VOParam("smoothfile","meta.file;meta.fits","char",this->smoothFile, this->smoothFile.size(),""));
1134    if(this->usePrevious)
1135      vopars.push_back(VOParam("objectlist","","char",this->objectList,this->objectList.size(),""));
1136
1137    vopars.push_back(VOParam("searchType","meta.note","char",this->searchType,this->searchType.size(),""));
1138    vopars.push_back(VOParam("flagNegative","meta.code","boolean",this->flagNegative,0,""));
1139    vopars.push_back(VOParam("flagBaseline","meta.code","boolean",this->flagBaseline,0,""));
1140    vopars.push_back(VOParam("flagRobustStats","meta.code","boolean",this->flagRobustStats,0,""));
1141    vopars.push_back(VOParam("flagFDR","meta.code","boolean",this->flagFDR,0,""));
1142    if(this->flagFDR){
1143      vopars.push_back(VOParam("alphaFDR","stat.param","float",this->alphaFDR,0,""));
1144      vopars.push_back(VOParam("FDRnumCorChan","stat.param","int",this->FDRnumCorChan,0,""));
1145    }
1146    else{
1147      if(this->flagUserThreshold)
1148            vopars.push_back(VOParam("threshold","phot.flux;stat.min","float",this->threshold,0,""));
1149      else
1150        vopars.push_back(VOParam("snrCut","stat.snr;phot;stat.min","float",this->snrCut,0,""));
1151    }
1152    vopars.push_back(VOParam("flagGrowth","meta.code","boolean",this->flagGrowth,0,""));
1153    if(this->flagGrowth){
1154      if(this->flagUserGrowthThreshold)
1155        vopars.push_back(VOParam("growthThreshold","phot.flux;stat.min","float",this->growthThreshold,0,""));
1156      else
1157        vopars.push_back(VOParam("growthCut","stat.snr;phot;stat.min","float",this->growthCut,0,""));
1158    }
1159    vopars.push_back(VOParam("minVoxels","","int",minVoxels,0,""));
1160    vopars.push_back(VOParam("minPix","","int",minPix,0,""));
1161    vopars.push_back(VOParam("minChannels","","int",minChannels,0,""));
1162    vopars.push_back(VOParam("flagAdjacent","meta.code","boolean",this->flagAdjacent,0,""));
1163    if(!this->flagAdjacent)
1164      vopars.push_back(VOParam("threshSpatial","","float",this->threshSpatial,0,""));
1165    vopars.push_back(VOParam("threshVelocity","","float",this->threshVelocity,0,""));
1166    vopars.push_back(VOParam("flagRejectBeforeMerge","","boolean",this->flagRejectBeforeMerge,0,""));
1167    vopars.push_back(VOParam("flagTwoStageMerging","","boolean",this->flagTwoStageMerging,0,""));
1168    vopars.push_back(VOParam("pixelCentre","","char",this->pixelCentre,this->pixelCentre.size(),""));
1169    vopars.push_back(VOParam("flagSmooth","meta.code","boolean",this->flagSmooth,0,""));
1170    if(this->flagSmooth){
1171      vopars.push_back(VOParam("smoothType","","char",this->smoothType,this->smoothType.size(),""));
1172      if(this->smoothType=="spectral")
1173        vopars.push_back(VOParam("hanningWidth","","int",this->hanningWidth,0,""));
1174      else{
1175        vopars.push_back(VOParam("kernMaj","","float",this->kernMaj,0,""));
1176        vopars.push_back(VOParam("kernMin","","float",this->kernMin,0,""));
1177        vopars.push_back(VOParam("kernPA","","float",this->kernPA,0,""));
1178      }
1179    }
1180    vopars.push_back(VOParam("flagATrous","meta.code","boolean",this->flagATrous,0,""));
1181    if(this->flagATrous){
1182      vopars.push_back(VOParam("reconDim","","int",this->reconDim,0,""));
1183      vopars.push_back(VOParam("scaleMin","","int",this->scaleMin,0,""));
1184      if(this->scaleMax>0)
1185        vopars.push_back(VOParam("scaleMax","","int",this->scaleMax,0,""));
1186      vopars.push_back(VOParam("snrRecon","","float",this->snrRecon,0,""));
1187      vopars.push_back(VOParam("reconConvergence","","float",this->reconConvergence,0,""));
1188      vopars.push_back(VOParam("filterCode","","int",this->filterCode,0,""));
1189    }
1190    if(this->beamAsUsed.origin()==PARAM){
1191      if(this->fwhmBeam>0)
1192        vopars.push_back(VOParam("beamFWHM","","float",this->fwhmBeam,0,""));
1193      else
1194        vopars.push_back(VOParam("beamArea","","float",this->areaBeam,0,""));
1195    }
1196    if(this->restFrequencyUsed){
1197      vopars.push_back(VOParam("restFrequency","em.freq","float",this->restFrequency,0,"Hz"));
1198    }
1199
1200    return vopars;
1201
1202  }
1203
1204  void Param::writeToBinaryFile(std::string &filename)
1205  {
1206    std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
1207    writeStringToBinaryFile(outfile,this->imageFile);
1208    outfile.write(reinterpret_cast<const char*>(&this->flagSubsection), sizeof this->flagSubsection);
1209    if(this->flagSubsection) writeStringToBinaryFile(outfile,this->pixelSec.getSection());
1210    outfile.write(reinterpret_cast<const char*>(&this->flagStatSec), sizeof this->flagStatSec);
1211    if(this->flagStatSec) writeStringToBinaryFile(outfile,this->statSec.getSection());
1212    outfile.write(reinterpret_cast<const char*>(&this->flagReconExists), sizeof this->flagReconExists);
1213    if(this->flagReconExists) writeStringToBinaryFile(outfile,this->reconFile);
1214    outfile.write(reinterpret_cast<const char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists);
1215    if(this->flagSmoothExists) writeStringToBinaryFile(outfile,this->smoothFile);
1216    //
1217    writeStringToBinaryFile(outfile,this->searchType);
1218    outfile.write(reinterpret_cast<const char*>(&this->flagNegative), sizeof this->flagNegative);
1219    outfile.write(reinterpret_cast<const char*>(&this->flagBaseline), sizeof this->flagBaseline);
1220    outfile.write(reinterpret_cast<const char*>(&this->flagRobustStats), sizeof this->flagRobustStats);
1221    outfile.write(reinterpret_cast<const char*>(&this->flagFDR), sizeof this->flagFDR);
1222    if(this->flagFDR){
1223      outfile.write(reinterpret_cast<const char*>(&this->alphaFDR), sizeof this->alphaFDR);
1224      outfile.write(reinterpret_cast<const char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan);
1225      if(this->beamAsUsed.origin()==PARAM){
1226        outfile.write(reinterpret_cast<const char*>(&this->fwhmBeam), sizeof this->fwhmBeam);
1227        outfile.write(reinterpret_cast<const char*>(&this->areaBeam), sizeof this->areaBeam);
1228      }
1229    }
1230    else{
1231      outfile.write(reinterpret_cast<const char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold);
1232      if(this->flagUserThreshold)
1233        outfile.write(reinterpret_cast<const char*>(&this->threshold), sizeof this->threshold);
1234      else
1235        outfile.write(reinterpret_cast<const char*>(&this->snrCut), sizeof this->snrCut);
1236    }
1237    outfile.write(reinterpret_cast<const char*>(&this->flagGrowth), sizeof this->flagGrowth);
1238    if(this->flagGrowth){
1239      if(this->flagUserGrowthThreshold)
1240        outfile.write(reinterpret_cast<const char*>(&this->growthThreshold), sizeof this->growthThreshold);
1241      else
1242        outfile.write(reinterpret_cast<const char*>(&this->growthCut), sizeof this->growthCut);
1243    }
1244    outfile.write(reinterpret_cast<const char*>(&this->minVoxels), sizeof this->minVoxels);
1245    outfile.write(reinterpret_cast<const char*>(&this->minPix), sizeof this->minPix);
1246    outfile.write(reinterpret_cast<const char*>(&this->minChannels), sizeof this->minChannels);
1247    outfile.write(reinterpret_cast<const char*>(&this->flagAdjacent), sizeof this->flagAdjacent);
1248    if(!this->flagAdjacent)
1249      outfile.write(reinterpret_cast<const char*>(&this->threshSpatial), sizeof this->threshSpatial);
1250    outfile.write(reinterpret_cast<const char*>(&this->threshVelocity), sizeof this->threshVelocity);
1251    outfile.write(reinterpret_cast<const char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge);
1252    outfile.write(reinterpret_cast<const char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging);
1253    outfile.write(reinterpret_cast<const char*>(&this->flagSmooth), sizeof this->flagSmooth);
1254    if(this->flagSmooth){
1255      bool type=(this->smoothType=="spectral");
1256      outfile.write(reinterpret_cast<const char*>(&type), sizeof type);
1257      if(type)
1258        outfile.write(reinterpret_cast<const char*>(&this->hanningWidth), sizeof this->hanningWidth);
1259      else{
1260        outfile.write(reinterpret_cast<const char*>(&this->kernMaj), sizeof this->kernMaj);
1261        outfile.write(reinterpret_cast<const char*>(&this->kernMin), sizeof this->kernMin);
1262        outfile.write(reinterpret_cast<const char*>(&this->kernPA), sizeof this->kernPA);
1263      }
1264    }
1265    outfile.write(reinterpret_cast<const char*>(&this->flagATrous), sizeof this->flagATrous);
1266    if(this->flagATrous){
1267      outfile.write(reinterpret_cast<const char*>(&this->reconDim), sizeof this->reconDim);
1268      outfile.write(reinterpret_cast<const char*>(&this->scaleMin), sizeof this->scaleMin);
1269      outfile.write(reinterpret_cast<const char*>(&this->scaleMax), sizeof this->scaleMax);
1270      outfile.write(reinterpret_cast<const char*>(&this->snrRecon), sizeof this->snrRecon);
1271      outfile.write(reinterpret_cast<const char*>(&this->reconConvergence), sizeof this->reconConvergence);
1272      outfile.write(reinterpret_cast<const char*>(&this->filterCode), sizeof this->filterCode);
1273    }
1274    writeStringToBinaryFile(outfile,this->flaggedChannelList);
1275
1276    outfile.close();
1277  }
1278
1279  std::streampos Param::readFromBinaryFile(std::string &filename, std::streampos loc)
1280  {
1281    std::ifstream infile(filename.c_str(), std::ios::in | std::ios::binary);
1282    if(!infile.is_open()){
1283      DUCHAMPERROR("read binary parameters","Could not open binary catalogue \""<<filename <<"\"");
1284      return -1;
1285    }
1286    infile.seekg(loc);
1287    this->imageFile = readStringFromBinaryFile(infile);
1288    infile.read(reinterpret_cast<char*>(&this->flagSubsection), sizeof this->flagSubsection);
1289    if(this->flagSubsection){
1290      std::string sec=readStringFromBinaryFile(infile);
1291      this->pixelSec.setSection(sec);
1292    }
1293    infile.read(reinterpret_cast<char*>(&this->flagStatSec), sizeof this->flagStatSec);
1294    if(this->flagStatSec){
1295      std::string sec=readStringFromBinaryFile(infile);
1296      this->statSec.setSection(sec);
1297    }
1298    infile.read(reinterpret_cast<char*>(&this->flagReconExists), sizeof this->flagReconExists);
1299    if(this->flagReconExists) this->reconFile=readStringFromBinaryFile(infile);
1300    infile.read(reinterpret_cast<char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists);
1301    if(this->flagSmoothExists) this->smoothFile=readStringFromBinaryFile(infile);
1302    //
1303    this->searchType=readStringFromBinaryFile(infile);
1304    infile.read(reinterpret_cast<char*>(&this->flagNegative), sizeof this->flagNegative);
1305    infile.read(reinterpret_cast<char*>(&this->flagBaseline), sizeof this->flagBaseline);
1306    infile.read(reinterpret_cast<char*>(&this->flagRobustStats), sizeof this->flagRobustStats);
1307    infile.read(reinterpret_cast<char*>(&this->flagFDR), sizeof this->flagFDR);
1308    if(this->flagFDR){
1309      infile.read(reinterpret_cast<char*>(&this->alphaFDR), sizeof this->alphaFDR);
1310      infile.read(reinterpret_cast<char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan);
1311      if(this->beamAsUsed.origin()==PARAM){
1312        infile.read(reinterpret_cast<char*>(&this->fwhmBeam), sizeof this->fwhmBeam);
1313        infile.read(reinterpret_cast<char*>(&this->areaBeam), sizeof this->areaBeam);
1314      }
1315    }
1316    else{
1317      infile.read(reinterpret_cast<char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold);
1318      if(this->flagUserThreshold)
1319        infile.read(reinterpret_cast<char*>(&this->threshold), sizeof this->threshold);
1320      else
1321        infile.read(reinterpret_cast<char*>(&this->snrCut), sizeof this->snrCut);
1322    }
1323    infile.read(reinterpret_cast<char*>(&this->flagGrowth), sizeof this->flagGrowth);
1324    if(this->flagGrowth){
1325      if(this->flagUserGrowthThreshold)
1326        infile.read(reinterpret_cast<char*>(&this->growthThreshold), sizeof this->growthThreshold);
1327      else
1328        infile.read(reinterpret_cast<char*>(&this->growthCut), sizeof this->growthCut);
1329    }
1330    infile.read(reinterpret_cast<char*>(&this->minVoxels), sizeof this->minVoxels);
1331    infile.read(reinterpret_cast<char*>(&this->minPix), sizeof this->minPix);
1332    infile.read(reinterpret_cast<char*>(&this->minChannels), sizeof this->minChannels);
1333    infile.read(reinterpret_cast<char*>(&this->flagAdjacent), sizeof this->flagAdjacent);
1334    if(!this->flagAdjacent)
1335      infile.read(reinterpret_cast<char*>(&this->threshSpatial), sizeof this->threshSpatial);
1336    infile.read(reinterpret_cast<char*>(&this->threshVelocity), sizeof this->threshVelocity);
1337    infile.read(reinterpret_cast<char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge);
1338    infile.read(reinterpret_cast<char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging);
1339    infile.read(reinterpret_cast<char*>(&this->flagSmooth), sizeof this->flagSmooth);
1340    if(this->flagSmooth){
1341      bool type;
1342      infile.read(reinterpret_cast<char*>(&type), sizeof type);
1343      this->smoothType = type ? "spectral" : "spatial";
1344      if(type)
1345        infile.read(reinterpret_cast<char*>(&this->hanningWidth), sizeof this->hanningWidth);
1346      else{
1347        infile.read(reinterpret_cast<char*>(&this->kernMaj), sizeof this->kernMaj);
1348        infile.read(reinterpret_cast<char*>(&this->kernMin), sizeof this->kernMin);
1349        infile.read(reinterpret_cast<char*>(&this->kernPA), sizeof this->kernPA);
1350      }
1351    }
1352    infile.read(reinterpret_cast<char*>(&this->flagATrous), sizeof this->flagATrous);
1353    if(this->flagATrous){
1354      infile.read(reinterpret_cast<char*>(&this->reconDim), sizeof this->reconDim);
1355      infile.read(reinterpret_cast<char*>(&this->scaleMin), sizeof this->scaleMin);
1356      infile.read(reinterpret_cast<char*>(&this->scaleMax), sizeof this->scaleMax);
1357      infile.read(reinterpret_cast<char*>(&this->snrRecon), sizeof this->snrRecon);
1358      infile.read(reinterpret_cast<char*>(&this->reconConvergence), sizeof this->reconConvergence);
1359      infile.read(reinterpret_cast<char*>(&this->filterCode), sizeof this->filterCode);
1360    }
1361    this->flaggedChannelList=readStringFromBinaryFile(infile);
1362
1363    std::streampos newloc = infile.tellg();
1364    infile.close();
1365    return newloc;
1366
1367  }
1368
1369
1370
1371
1372  void Param::copyHeaderInfo(FitsHeader &head)
1373  {
1374    ///  A function to copy across relevant header keywords from the
1375    ///  FitsHeader class to the Param class, as they are needed by
1376    ///  functions in the Param class.
1377    ///  The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1378
1379    this->blankKeyword  = head.getBlankKeyword();
1380    this->bscaleKeyword = head.getBscaleKeyword();
1381    this->bzeroKeyword  = head.getBzeroKeyword();
1382    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1383      this->bzeroKeyword;
1384  }
1385
1386  std::string Param::outputMaskFile()
1387  {
1388    ///  This function produces the required filename in which to save
1389    ///  the mask image, indicating which pixels have been detected as
1390    ///  part of an object. If the input image is image.fits, then the
1391    ///  output will be image.MASK.fits.
1392
1393    if(this->fileOutputMask==""){
1394      std::string inputName = this->imageFile;
1395      std::string outputName = inputName;
1396      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1397        outputName = inputName.substr(0,inputName.size()-5); 
1398      // remove the ".fits" on the end.
1399      outputName += ".MASK.fits";
1400      return outputName;
1401    }
1402    else return this->fileOutputMask;
1403  }
1404
1405  std::string Param::outputMomentMapFile()
1406  {
1407    ///  This function produces the required filename in which to save
1408    ///  the moment-0 FITS image. If the input image is image.fits, then the
1409    ///  output will be image.MOM0.fits.
1410
1411    if(this->fileOutputMomentMap==""){
1412      std::string inputName = this->imageFile;
1413      std::string outputName = inputName;
1414      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1415        outputName = inputName.substr(0,inputName.size()-5); 
1416      // remove the ".fits" on the end.
1417      outputName += ".MOM0.fits";
1418      return outputName;
1419    }
1420    else return this->fileOutputMomentMap;
1421  }
1422
1423  std::string Param::outputMomentMaskFile()
1424  {
1425    ///  This function produces the required filename in which to save
1426    ///  the moment-0 FITS image. If the input image is image.fits, then the
1427    ///  output will be image.MOM0.fits.
1428
1429    if(this->fileOutputMomentMask==""){
1430      std::string inputName = this->imageFile;
1431      std::string outputName = inputName;
1432      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1433        outputName = inputName.substr(0,inputName.size()-5); 
1434      // remove the ".fits" on the end.
1435      outputName += ".MOM0MASK.fits";
1436      return outputName;
1437    }
1438    else return this->fileOutputMomentMask;
1439  }
1440
1441  std::string Param::outputBaselineFile()
1442  {
1443    ///  This function produces the required filename in which to save
1444    ///  the baseline FITS image. If the input image is image.fits, then the
1445    ///  output will be image.BASE.fits.
1446
1447    if(this->fileOutputBaseline==""){
1448      std::string inputName = this->imageFile;
1449      std::string outputName = inputName;
1450      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1451        outputName = inputName.substr(0,inputName.size()-5); 
1452      // remove the ".fits" on the end.
1453      outputName += ".BASE.fits";
1454      return outputName;
1455    }
1456    else return this->fileOutputBaseline;
1457  }
1458
1459  std::string Param::outputSmoothFile()
1460  {
1461    ///  This function produces the required filename in which to save
1462    ///   the smoothed array. If the input image is image.fits, then
1463    ///   the output will be:
1464    ///    <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1465    ///             width of the Hanning filter was 3 pixels.
1466    ///        <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1467    ///             kernMaj=3, kernMin=2 and kernPA=20 degrees.
1468    ///    </ul>
1469
1470    if(this->fileOutputSmooth==""){
1471      std::string inputName = this->imageFile;
1472      std::stringstream ss;
1473      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1474        ss << inputName.substr(0,inputName.size()-5); 
1475      else
1476        ss << inputName;
1477      // remove the ".fits" on the end if necessary.
1478      if(this->flagSubsection) ss<<".sub";
1479      if(this->smoothType=="spectral")
1480        ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1481      else if(this->smoothType=="spatial")
1482        ss << ".SMOOTH-2D-"
1483           << this->kernMaj << "-"
1484           << this->kernMin << "-"
1485           << this->kernPA  << ".fits";
1486      return ss.str();
1487    }
1488    else return this->fileOutputSmooth;
1489  }
1490
1491  std::string Param::outputReconFile()
1492  {
1493    /// This function produces the required filename in which to save
1494    ///  the reconstructed array. If the input image is image.fits, then
1495    ///  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1496    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1497
1498    if(this->fileOutputRecon==""){
1499      std::string inputName = this->imageFile;
1500      std::stringstream ss;
1501      // First we remove the ".fits" from the end of the filename.
1502      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1503          ss << inputName.substr(0,inputName.size()-5); 
1504      else
1505          ss << inputName;
1506      if(this->flagSubsection) ss<<".sub";
1507      ss << ".RECON-" << this->reconDim
1508         << "-"       << this->filterCode
1509         << "-"       << this->snrRecon
1510         << "-"       << this->scaleMin
1511         << "-"       << this->scaleMax
1512         << "-"       << this->reconConvergence
1513         << ".fits";
1514      return ss.str();
1515    }
1516    else return this->fileOutputRecon;
1517  }
1518
1519  std::string Param::outputResidFile()
1520  {
1521    /// This function produces the required filename in which to save
1522    ///  the reconstructed array. If the input image is image.fits, then
1523    ///  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1524    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1525
1526    if(this->fileOutputResid==""){
1527      std::string inputName = this->imageFile;
1528      std::stringstream ss;
1529      // First we remove the ".fits" from the end of the filename.
1530      if(this->imageFile.size()>5 && inputName.substr(inputName.size()-5,5)==".fits")
1531          ss << inputName.substr(0,inputName.size()-5);
1532      else
1533          ss << inputName;
1534      if(this->flagSubsection) ss<<".sub";
1535      ss << ".RESID-" << this->reconDim
1536         << "-"       << this->filterCode
1537         << "-"       << this->snrRecon
1538         << "-"       << this->scaleMin
1539         << "-"       << this->scaleMax
1540         << "-"       << this->reconConvergence
1541         << ".fits";
1542      return ss.str();
1543    }
1544    else return this->fileOutputResid;
1545  }
1546
1547}
Note: See TracBrowser for help on using the repository browser.