source: trunk/src/param.cc @ 1213

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

A better way of initialising the Section - the subsection string is set to the null string, and checks are made against that in the parsing.

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