source: trunk/src/param.cc @ 1259

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

Ticket #107 - Implementing the median baseline algorithm, with a few tweaks to make it work. The interface is now similar to the atrous baseline algorithm (which has been renamed).

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