source: trunk/src/param.cc @ 1146

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

Ticket #181 - Implementing the new catalogue writing, with new functions in Cube to handle the overall reading & writing. Briefly tested and seems to work OK. A couple of minor bug fixes as well, one in particular with the baseline-writing.

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