source: trunk/src/param.cc @ 782

Last change on this file since 782 was 733, checked in by MatthewWhiting, 14 years ago

Moving the string manipulation functions to their own file in Utils/, and fixing the filname parameter reading so that it can read filenames with spaces in them.

File size: 45.1 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/Detection/columns.hh>
46
47namespace duchamp
48{
49
50  /****************************************************************/
51  ///////////////////////////////////////////////////
52  //// Accessor Functions for Parameter class:
53  ///////////////////////////////////////////////////
54  Param::~Param()
55  {
56    /// Deletes the offsets array if the sizeOffsets parameter is
57    /// positive.
58    if(this->sizeOffsets>0) delete [] this->offsets;
59  }
60
61  Param::Param()
62  {
63    this->defaultValues();
64  }
65
66  void Param::defaultValues()
67  {
68    /// Provides default intial values for the parameters. Note that
69    /// imageFile has no default value!
70
71    std::string baseSection = "[*,*,*]";
72    // Input files
73    this->imageFile         = "";
74    this->flagSubsection    = false;
75    this->pixelSec.setSection(baseSection);
76    this->flagReconExists   = false;
77    this->reconFile         = "";
78    this->flagSmoothExists  = false;
79    this->smoothFile        = "";
80    this->usePrevious       = false;
81    this->objectList        = "";
82    // Output files
83    this->flagLog           = false;
84    this->logFile           = "duchamp-Logfile.txt";
85    this->outFile           = "duchamp-Results.txt";
86    this->flagSeparateHeader= false;
87    this->headerFile        = "duchamp-Results.hdr";
88    this->spectraFile       = "duchamp-Spectra.ps";
89    this->flagTextSpectra   = false;
90    this->spectraTextFile   = "duchamp-Spectra.txt";
91    this->flagOutputMomentMap    = false;
92    this->fileOutputMomentMap    = "";
93    this->flagOutputMask    = false;
94    this->fileOutputMask    = "";
95    this->flagMaskWithObjectNum = false;
96    this->flagOutputSmooth  = false;
97    this->fileOutputSmooth  = "";
98    this->flagOutputRecon   = false;
99    this->fileOutputRecon   = "";
100    this->flagOutputResid   = false;
101    this->fileOutputResid   = "";
102    this->flagVOT           = false;
103    this->votFile           = "duchamp-Results.xml";
104    this->flagKarma         = false;
105    this->karmaFile         = "duchamp-Results.ann";
106    this->annotationType    = "borders";
107    this->flagMaps          = true;
108    this->detectionMap      = "duchamp-DetectionMap.ps";
109    this->momentMap         = "duchamp-MomentMap.ps";
110    this->flagXOutput       = true;
111    this->precFlux          = Column::prFLUX;
112    this->precVel           = Column::prVEL;
113    this->precSNR           = Column::prSNR;
114    // Cube related parameters
115    this->flagBlankPix      = true;
116    this->blankPixValue     = -8.00061;
117    this->blankKeyword      = 1;
118    this->bscaleKeyword     = -8.00061;
119    this->bzeroKeyword      = 0.;
120    this->newFluxUnits      = "";
121    // Milky-Way parameters
122    this->flagMW            = false;
123    this->maxMW             = 112;
124    this->minMW             = 75;
125    this->areaBeam          = 10.;
126    this->fwhmBeam          = -1.;
127    this->flagUsingBeam     = false;
128    this->searchType        = "spatial";
129    // Trim-related         
130    this->flagTrim          = false;
131    this->hasBeenTrimmed    = false;
132    this->borderLeft        = 0;
133    this->borderRight       = 0;
134    this->borderBottom      = 0;
135    this->borderTop         = 0;
136    // Subsection offsets
137    this->sizeOffsets       = 0;
138    this->xSubOffset        = 0;
139    this->ySubOffset        = 0;
140    this->zSubOffset        = 0;
141    // Baseline related
142    this->flagBaseline      = false;
143    // Detection-related   
144    this->flagNegative      = false;
145    // Object growth       
146    this->flagGrowth        = false;
147    this->growthCut         = 3.;
148    this->flagUserGrowthThreshold = false;
149    this->growthThreshold   = 0.;
150    // FDR analysis         
151    this->flagFDR           = false;
152    this->alphaFDR          = 0.01;
153    this->FDRnumCorChan     = 2;
154    // Other detection     
155    this->flagStatSec       = false;
156    this->statSec.setSection(baseSection);
157    this->flagRobustStats   = true;
158    this->snrCut            = 3.;
159    this->threshold         = 0.;
160    this->flagUserThreshold = false;
161    // Smoothing
162    this->flagSmooth        = false;
163    this->smoothType        = "spectral";
164    this->hanningWidth      = 5;
165    this->kernMaj           = 3.;
166    this->kernMin           = -1.;
167    this->kernPA            = 0.;
168    // A trous reconstruction parameters
169    this->flagATrous        = false;
170    this->reconDim          = 1;
171    this->scaleMin          = 1;
172    this->scaleMax          = 0;
173    this->snrRecon          = 4.;
174    this->filterCode        = 1;
175    this->reconFilter.define(this->filterCode);
176    // Volume-merging parameters
177    this->flagAdjacent      = true;
178    this->threshSpatial     = 3.;
179    this->threshVelocity    = 7.;
180    this->minChannels       = 3;
181    this->minPix            = 2;
182    this->minVoxels         = 4;
183    this->flagRejectBeforeMerge = false;
184    this->flagTwoStageMerging = true;
185    // Input-Output related
186    this->spectralMethod    = "peak";
187    this->spectralUnits     = "km/s";
188    this->pixelCentre       = "centroid";
189    this->sortingParam      = "vel";
190    this->borders           = true;
191    this->blankEdge         = true;
192    this->verbose           = true;
193  }
194
195  Param::Param (const Param& p)
196  {
197    operator=(p);
198  }
199
200  Param& Param::operator= (const Param& p)
201  {
202    if(this == &p) return *this;
203    this->imageFile         = p.imageFile;
204    this->flagSubsection    = p.flagSubsection;
205    this->pixelSec          = p.pixelSec;
206    this->flagReconExists   = p.flagReconExists;
207    this->reconFile         = p.reconFile;     
208    this->flagSmoothExists  = p.flagSmoothExists;
209    this->smoothFile        = p.smoothFile;     
210    this->usePrevious       = p.usePrevious;
211    this->objectList        = p.objectList;
212    this->flagLog           = p.flagLog;       
213    this->logFile           = p.logFile;       
214    this->outFile           = p.outFile;       
215    this->flagSeparateHeader= p.flagSeparateHeader;
216    this->headerFile        = p.headerFile;
217    this->spectraFile       = p.spectraFile;   
218    this->flagTextSpectra   = p.flagTextSpectra;   
219    this->spectraTextFile   = p.spectraTextFile;   
220    this->flagOutputMomentMap    = p.flagOutputMomentMap;
221    this->fileOutputMomentMap    = p.fileOutputMomentMap;
222    this->flagOutputMask    = p.flagOutputMask;
223    this->fileOutputMask    = p.fileOutputMask;
224    this->flagMaskWithObjectNum = p.flagMaskWithObjectNum;
225    this->flagOutputSmooth  = p.flagOutputSmooth;
226    this->fileOutputSmooth  = p.fileOutputSmooth;
227    this->flagOutputRecon   = p.flagOutputRecon;
228    this->fileOutputRecon   = p.fileOutputRecon;
229    this->flagOutputResid   = p.flagOutputResid;
230    this->fileOutputResid   = p.fileOutputResid;
231    this->flagVOT           = p.flagVOT;         
232    this->votFile           = p.votFile;       
233    this->flagKarma         = p.flagKarma;     
234    this->karmaFile         = p.karmaFile;     
235    this->annotationType    = p.annotationType;
236    this->flagMaps          = p.flagMaps;       
237    this->detectionMap      = p.detectionMap;   
238    this->momentMap         = p.momentMap;     
239    this->flagXOutput       = p.flagXOutput;       
240    this->precFlux          = p.precFlux;
241    this->precVel           = p.precVel;
242    this->precSNR           = p.precSNR;
243    this->flagBlankPix      = p.flagBlankPix;   
244    this->blankPixValue     = p.blankPixValue; 
245    this->blankKeyword      = p.blankKeyword;   
246    this->bscaleKeyword     = p.bscaleKeyword; 
247    this->bzeroKeyword      = p.bzeroKeyword;   
248    this->newFluxUnits      = p.newFluxUnits;
249    this->flagMW            = p.flagMW;         
250    this->maxMW             = p.maxMW;         
251    this->minMW             = p.minMW;         
252    this->areaBeam          = p.areaBeam;     
253    this->fwhmBeam          = p.fwhmBeam;     
254    this->searchType        = p.searchType;
255    this->flagTrim          = p.flagTrim;   
256    this->hasBeenTrimmed    = p.hasBeenTrimmed;   
257    this->borderLeft        = p.borderLeft;     
258    this->borderRight       = p.borderRight;   
259    this->borderBottom      = p.borderBottom;   
260    this->borderTop         = p.borderTop;     
261    if(this->sizeOffsets>0) delete [] this->offsets;
262    this->sizeOffsets       = p.sizeOffsets;
263    if(this->sizeOffsets>0){
264      this->offsets           = new long[this->sizeOffsets];
265      for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
266    }
267    this->xSubOffset        = p.xSubOffset;     
268    this->ySubOffset        = p.ySubOffset;     
269    this->zSubOffset        = p.zSubOffset;
270    this->flagBaseline      = p.flagBaseline;
271    this->flagNegative      = p.flagNegative;
272    this->flagGrowth        = p.flagGrowth;
273    this->growthCut         = p.growthCut;
274    this->growthThreshold   = p.growthThreshold;
275    this->flagUserGrowthThreshold = p.flagUserGrowthThreshold;
276    this->flagFDR           = p.flagFDR;
277    this->alphaFDR          = p.alphaFDR;
278    this->FDRnumCorChan     = p.FDRnumCorChan;
279    this->flagStatSec       = p.flagStatSec;
280    this->statSec           = p.statSec;
281    this->flagRobustStats   = p.flagRobustStats;
282    this->snrCut            = p.snrCut;
283    this->threshold         = p.threshold;
284    this->flagUserThreshold = p.flagUserThreshold;
285    this->flagSmooth        = p.flagSmooth;
286    this->smoothType        = p.smoothType;
287    this->hanningWidth      = p.hanningWidth;
288    this->kernMaj           = p.kernMaj;
289    this->kernMin           = p.kernMin;
290    this->kernPA            = p.kernPA;
291    this->flagATrous        = p.flagATrous;
292    this->reconDim          = p.reconDim;
293    this->scaleMin          = p.scaleMin;
294    this->scaleMax          = p.scaleMax;
295    this->snrRecon          = p.snrRecon;
296    this->filterCode        = p.filterCode;
297    this->reconFilter       = p.reconFilter;
298    this->flagAdjacent      = p.flagAdjacent;
299    this->threshSpatial     = p.threshSpatial;
300    this->threshVelocity    = p.threshVelocity;
301    this->minChannels       = p.minChannels;
302    this->minPix            = p.minPix;
303    this->minVoxels         = p.minVoxels;
304    this->flagRejectBeforeMerge = p.flagRejectBeforeMerge;
305    this->flagTwoStageMerging = p.flagTwoStageMerging;
306    this->spectralMethod    = p.spectralMethod;
307    this->spectralUnits     = p.spectralUnits;
308    this->pixelCentre       = p.pixelCentre;
309    this->sortingParam      = p.sortingParam;
310    this->borders           = p.borders;
311    this->blankEdge         = p.blankEdge;
312    this->verbose           = p.verbose;
313    return *this;
314  }
315  //--------------------------------------------------------------------
316
317  OUTCOME Param::getopts(int argc, char ** argv, std::string progname)
318  {
319    ///   A function that reads in the command-line options, in a manner
320    ///    tailored for use with the main Duchamp program.
321    ///
322    ///   \param argc The number of command line arguments.
323    ///   \param argv The array of command line arguments.
324
325    OUTCOME returnValue = FAILURE;
326    if(argc==1){
327      if(progname=="Selavy") std::cout << SELAVY_ERR_USAGE_MSG;
328      else if(progname=="Duchamp") std::cout << ERR_USAGE_MSG;
329      else std::cout << ERR_USAGE_MSG;
330      returnValue = FAILURE;
331    }
332    else {
333      std::string file;
334      bool changeX = false;
335      this->defaultValues();
336      char c;
337      while( ( c = getopt(argc,argv,"p:f:hvx") )!=-1){
338        switch(c) {
339        case 'p':
340          file = optarg;
341          if(this->readParams(file)==FAILURE){
342            std::stringstream errmsg;
343            errmsg << "Could not open parameter file " << file << ".\n";
344            duchampError(progname,errmsg.str());
345          }
346          else returnValue = SUCCESS;
347          break;
348        case 'f':
349          file = optarg;
350          this->imageFile = file;
351          returnValue = SUCCESS;
352          break;
353        case 'v':
354          std::cout << PROGNAME << " version " << VERSION << std::endl;
355          break;
356        case 'x':
357          changeX = true;
358          break;
359        case 'h':
360        default :
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          break;
365        }
366      }
367      if(changeX){
368        if(returnValue == SUCCESS) this->setFlagXOutput(false);
369        else {
370          duchampError(progname,
371                       "You need to specify either a parameter file or FITS image.\n");
372          std::cout << "\n" << ERR_USAGE_MSG;
373        }
374      }
375    }
376    return returnValue;
377  }
378  //--------------------------------------------------------------------
379
380  bool Param::isBlank(float &value)
381  {
382    ///  Tests whether the value passed as the argument is BLANK or not.
383    ///  \param value Pixel value to be tested.
384    ///  \return False if flagBlankPix is false. Else, compare to the
385    ///  relevant FITS keywords, using integer comparison.
386
387    return this->flagBlankPix &&
388      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
389  }
390
391  bool *Param::makeBlankMask(float *array, int size)
392  {
393    ///  This returns an array of bools, saying whether each pixel in the
394    ///  given array is BLANK or not. If the pixel is BLANK, set mask to
395    ///  false, else set to true. The array is allocated by the function.
396
397    bool *mask = new bool[size];
398    for(int i=0;i<size;i++) mask[i] = !this->isBlank(array[i]);
399    return mask;
400  }
401
402
403  bool *Param::makeStatMask(float *array, long *dim)
404  {
405    ///  This returns an array of bools, saying whether each pixel in
406    ///  the given array is suitable for a stats calculation. It needs
407    ///  to be in the StatSec (if defined), not blank and not a MW
408    ///  channel. The array is allocated by the function with a 'new' call.
409
410    bool *mask = new bool[dim[0]*dim[1]*dim[2]];
411    for(int x=0;x<dim[0];x++) {
412      for(int y=0;y<dim[1];y++) {
413        for(int z=0;z<dim[2];z++) {
414          int i = x+y*dim[0]+z*dim[0]*dim[1];
415          mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z);
416        }
417      }
418    }
419    return mask;
420  }
421
422
423  bool Param::isInMW(int z)
424  {
425    ///  Tests whether we are flagging Milky Way channels, and if so
426    /// whether the given channel number is in the Milky Way range. The
427    /// channels are assumed to start at number 0. 
428    /// \param z The channel number
429    /// \return True if we are flagging Milky Way channels and z is in
430    ///  the range.
431
432    return ( this->flagMW && (z>=this->getMinMW()) && (z<=this->getMaxMW()) );
433  }
434
435  bool Param::isStatOK(int x, int y, int z)
436  {
437   /// Test whether a given pixel position lies within the subsection
438   /// given by the statSec parameter. Only tested if the flagSubsection
439   /// parameter is true -- if it isn't, we just return true since all
440   /// pixels are therefore available for statstical calculations.
441   /// \param x X-value of pixel being tested.
442   /// \param y Y-value of pixel being tested.
443   /// \param z Z-value of pixel being tested.
444   /// \return True if pixel is able to be used for statistical
445   /// calculations. False otherwise.
446
447    int xval=x,yval=y,zval=z;
448    if(flagSubsection){
449      xval += pixelSec.getStart(0);
450      yval += pixelSec.getStart(1);
451      zval += pixelSec.getStart(2);
452    }
453    return !flagStatSec || statSec.isInside(xval,yval,zval);
454  }
455
456  std::vector<int> Param::getObjectRequest()
457  {
458    ///  Returns a list of the object numbers requested via the objectList parameter.
459    /// \return a vector of integers, one for each number in the objectList set.
460
461    std::stringstream ss1;
462    std::string tmp;
463    std::vector<int> tmplist;
464    ss1.str(this->objectList);
465    while(!ss1.eof()){
466      getline(ss1,tmp,',');
467      for(size_t i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' ';
468      int a,b;
469      std::stringstream ss2;
470      ss2.str(tmp);
471      ss2 >>a;
472      if(!ss2.eof()) ss2 >> b;
473      else b=a;
474      for(int n=a;n<=b;n++){
475        tmplist.push_back(n);
476      }     
477    }
478    return tmplist;
479  }
480
481  std::vector<bool> Param::getObjectChoices()
482  {
483    ///  Returns a list of bool values, indicating whether a given
484    ///  object was requested or not. The size of the vector is
485    ///  determined by the maximum value in objectList. For instance,
486    ///  if objectList="2,3,5-8", then the returned vector will be
487    ///  [0,1,1,0,1,1,1,1].
488    ///  \return Vector of bool values.
489
490    std::vector<int> objectChoices = this->getObjectRequest();
491    int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end());
492    std::vector<bool> choices(maxNum,false);
493    for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
494      choices[*obj-1] = true;
495    return choices;
496  }
497
498  std::vector<bool> Param::getObjectChoices(int numObjects)
499  {
500    ///  Returns a list of bool values, indicating whether a given
501    ///  object was requested or not. The size of the vector is given
502    ///  by the numObjects parameter. So, if objectList="2,3,5-8", then
503    ///  the returned vector from a getObjectChoices(10) call will be
504    ///  [0,1,1,0,1,1,1,1,0,0].
505    ///  \param numObjects How many objects there are in total.
506    ///  \return Vector of bool values.
507
508    if(this->objectList==""){
509      std::vector<bool> choices(numObjects,true);
510      return choices;
511    }
512    else{
513      std::vector<int> objectChoices = this->getObjectRequest();
514      std::vector<bool> choices(numObjects,false);
515      for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
516        if(*obj<=numObjects) choices[*obj-1] = true;
517      return choices;
518    }
519  }
520
521  /****************************************************************/
522  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
523  /// / Other Functions using the  Parameter class:
524  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
525
526  OUTCOME Param::readParams(std::string paramfile)
527  {
528    /// The parameters are read in from a disk file, on the assumption that each
529    ///  line of the file has the format "parameter value" (eg. alphafdr 0.1)
530    ///
531    /// The case of the parameter name does not matter, nor does the
532    /// formatting of the spaces (it can be any amount of whitespace or
533    /// tabs).
534    ///
535    /// \param paramfile A std::string containing the parameter filename.
536    ///
537    /// \return FAILURE if the parameter file does not exist. SUCCESS if
538    /// it is able to read it.
539
540    std::ifstream fin(paramfile.c_str());
541    if(!fin.is_open()) return FAILURE;
542    std::string line;
543    while( !std::getline(fin,line,'\n').eof()){
544
545      if(line[0]!='#'){
546        std::stringstream ss;
547        ss.str(line);
548        std::string arg;
549        ss >> arg;
550        arg = makelower(arg);
551        if(arg=="imagefile")       this->imageFile = readFilename(ss);
552        if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
553        if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
554        if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
555        if(arg=="reconfile")       this->reconFile = readSval(ss);
556        if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
557        if(arg=="smoothfile")      this->smoothFile = readSval(ss);
558        if(arg=="beamarea")        this->areaBeam = readFval(ss);
559        if(arg=="beamfwhm")        this->fwhmBeam = readFval(ss);
560        if(arg=="useprevious")     this->usePrevious = readFlag(ss);
561        if(arg=="objectlist")      this->objectList = readSval(ss);
562
563        if(arg=="flaglog")         this->flagLog = readFlag(ss);
564        if(arg=="logfile")         this->logFile = readSval(ss);
565        if(arg=="outfile")         this->outFile = readSval(ss);
566        if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss);
567        if(arg=="headerfile")      this->headerFile = readFilename(ss);
568        if(arg=="spectrafile")     this->spectraFile = readFilename(ss);
569        if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss);
570        if(arg=="spectratextfile") this->spectraTextFile = readFilename(ss);
571        if(arg=="flagoutputmomentmap")  this->flagOutputMomentMap = readFlag(ss);
572        if(arg=="fileoutputmomentmap")  this->fileOutputMomentMap = readFilename(ss);
573        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
574        if(arg=="fileoutputmask")  this->fileOutputMask = readFilename(ss);
575        if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss);
576        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
577        if(arg=="fileoutputsmooth")this->fileOutputSmooth = readFilename(ss);
578        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
579        if(arg=="fileoutputrecon") this->fileOutputRecon = readFilename(ss);
580        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
581        if(arg=="fileoutputresid") this->fileOutputResid = readFilename(ss);
582        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
583        if(arg=="votfile")         this->votFile = readFilename(ss);
584        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
585        if(arg=="karmafile")       this->karmaFile = readFilename(ss);
586        if(arg=="annotationtype")  this->annotationType = readSval(ss);
587        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
588        if(arg=="detectionmap")    this->detectionMap = readFilename(ss);
589        if(arg=="momentmap")       this->momentMap = readFilename(ss);
590        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
591        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
592        if(arg=="precflux")        this->precFlux = readIval(ss);
593        if(arg=="precvel")         this->precVel = readIval(ss);
594        if(arg=="precsnr")         this->precSNR = readIval(ss);
595
596        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
597        if(arg=="flagmw")          this->flagMW = readFlag(ss);
598        if(arg=="maxmw")           this->maxMW = readIval(ss);
599        if(arg=="minmw")           this->minMW = readIval(ss);
600        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
601        if(arg=="searchtype")      this->searchType = readSval(ss);
602
603        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
604        if(arg=="minpix")          this->minPix = readIval(ss);
605        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
606        if(arg=="growthcut")       this->growthCut = readFval(ss);
607        if(arg=="growththreshold"){
608          this->growthThreshold = readFval(ss);
609          this->flagUserGrowthThreshold = true;
610        }
611
612        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
613        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
614        if(arg=="fdrnumcorchan")   this->FDRnumCorChan = readIval(ss);
615        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
616        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
617        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
618        if(arg=="snrcut")          this->snrCut = readFval(ss);
619        if(arg=="threshold"){
620          this->threshold = readFval(ss);
621          this->flagUserThreshold = true;
622        }
623     
624        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
625        if(arg=="smoothtype")      this->smoothType = readSval(ss);
626        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
627        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
628        if(arg=="kernmin")         this->kernMin = readFval(ss);
629        if(arg=="kernpa")          this->kernPA = readFval(ss);
630
631        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
632        if(arg=="recondim")        this->reconDim = readIval(ss);
633        if(arg=="scalemin")        this->scaleMin = readIval(ss);
634        if(arg=="scalemax")        this->scaleMax = readIval(ss);
635        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
636        if(arg=="filtercode"){
637          this->filterCode = readIval(ss);
638          this->reconFilter.define(this->filterCode);
639        }
640
641        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
642        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
643        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
644        if(arg=="minchannels")     this->minChannels = readIval(ss);
645        if(arg=="minvoxels")       this->minVoxels = readIval(ss);
646        if(arg=="flagrejectbeforemerge") this->flagRejectBeforeMerge = readFlag(ss);
647        if(arg=="flagtwostagemerging") this->flagTwoStageMerging = readFlag(ss);
648
649        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
650        if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
651        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
652        if(arg=="sortingparam")    this->sortingParam = makelower(readSval(ss));
653        if(arg=="drawborders")     this->borders = readFlag(ss);
654        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
655        if(arg=="verbose")         this->verbose = readFlag(ss);
656
657        // Dealing with deprecated parameters.
658        if(arg=="flagblankpix"){
659          this->flagTrim = readFlag(ss);
660          std::stringstream errmsg;
661          errmsg <<"The parameter flagBlankPix is deprecated. "
662                 <<"Please use the flagTrim parameter in future.\n"
663                 <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n";
664          duchampWarning("Reading parameters",errmsg.str());
665        }
666        if(arg=="blankpixvalue"){
667          std::stringstream errmsg;
668          errmsg <<"The parameter blankPixValue is deprecated.\n"
669                 <<"This value is only taken from the FITS header.\n";
670          duchampWarning("Reading parameters",errmsg.str());
671        }
672        if(arg=="beamsize"){
673          this->areaBeam = readFval(ss);
674          std::stringstream errmsg;
675          errmsg <<"The parameter beamSize is deprecated.\n"
676                 <<"You can specify the beam size by beamArea or beamFWHM.\n"
677                 <<"Setting beamArea = " << this->areaBeam << ".\n";
678          duchampWarning("Reading parameters",errmsg.str());
679        }
680
681      }
682    }
683
684    this->checkPars();
685
686    return SUCCESS;
687
688  }
689 
690  void Param::checkPars()
691  {
692
693    // If we have usePrevious=false, set the objectlist to blank so that we use all of them
694    if(!this->usePrevious) this->objectList = "";
695
696    // If pgplot was not included in the compilation, need to set flagXOutput to false
697    if(!USE_PGPLOT) this->flagXOutput = false;
698
699    // Correcting bad precision values -- if negative, set to 0
700    if(this->precFlux<0) this->precFlux = 0;
701    if(this->precVel<0)  this->precVel = 0;
702    if(this->precSNR<0)  this->precSNR = 0;
703
704    // Can only have "spatial" or "spectral" as search types
705    if(this->searchType != "spatial" && this->searchType != "spectral"){
706      std::stringstream errmsg;
707      errmsg << "You have requested a search type of \""<<this->searchType<<"\".\n"
708             << "Only \"spectral\" and \"spatial\" are accepted. Setting to \"spatial\".\n";
709      duchampWarning("Reading parameters",errmsg.str());
710      this->searchType = "spatial";
711    }
712
713    // The wavelet reconstruction takes precendence over the smoothing.
714    if(this->flagATrous) this->flagSmooth = false;
715
716    if(this->flagUserThreshold){
717
718      // If we specify a manual threshold, need to also specify a manual growth threshold
719      // If we haven't done so, turn growing off
720      if(this->flagGrowth && !this->flagUserGrowthThreshold){
721        std::stringstream errmsg;
722        errmsg << "You have specified a manual search threshold, but not a manual growth threshold.\n"
723               << "You need to do so using the \"growthThreshold\" parameter.\n"
724               << "The growth function is being turned off.\n";
725        duchampWarning("Reading parameters",errmsg.str());
726        this->flagGrowth = false;
727      }
728
729      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
730      if(this->flagFDR){
731        std::stringstream errmsg;
732        errmsg << "You have specified a manual search threshold, so we don't need to use the FDR method.\n"
733               << "Setting \"flagFDR=false\".\n";
734        duchampWarning("Reading parameters",errmsg.str());
735        this->flagFDR = false;
736      }
737
738    }   
739
740    // Make sure the growth level is less than the detection level. Else turn off growing.
741    if(this->flagGrowth){
742      std::stringstream errmsg;
743      bool doWarn = false;
744      if(this->flagUserThreshold &&
745         ( (this->threshold < this->growthThreshold)
746           || (this->snrCut < this->growthCut) ) ){
747        errmsg << "Your \"growthThreshold\" parameter is larger than your \"threshold\".\n"
748               << "The growth function is being turned off.\n";
749        doWarn = true;
750      }
751     
752      if(!this->flagUserThreshold &&
753         (this->snrCut < this->growthCut)) {
754        errmsg << "Your \"growthCut\" parameter is larger than your \"snrCut\".\n"
755               << "The growth function is being turned off.\n";
756        doWarn = true;
757      }
758
759      if(doWarn) duchampWarning("Reading parameters",errmsg.str());
760
761    }
762
763    // Make sure the annnotationType is an acceptable option -- default is "borders"
764    if((this->annotationType != "borders") && (this->annotationType!="circles")){
765      std::stringstream errmsg;
766      errmsg << "The requested value of the parameter annotationType, \""
767             << this->annotationType << "\", is invalid.\n"
768             << "Changing to \"borders\".\n";
769      duchampWarning("Reading parameters",errmsg.str());
770      this->annotationType = "borders";
771    }
772     
773    // Make sure smoothType is an acceptable type -- default is "spectral"
774    if((this->smoothType!="spectral")&&
775       (this->smoothType!="spatial")){
776      std::stringstream errmsg;
777      errmsg << "The requested value of the parameter smoothType, \""
778             << this->smoothType << "\", is invalid.\n"
779             << "Changing to \"spectral\".\n";
780      duchampWarning("Reading parameters",errmsg.str());
781      this->smoothType = "spectral";
782    }
783    // If kernMin has not been given, or is negative, make it equal to kernMaj
784    if(this->kernMin < 0) this->kernMin = this->kernMaj;
785
786    // Make sure spectralMethod is an acceptable type -- default is "peak"
787    if((this->spectralMethod!="peak")&&
788       (this->spectralMethod!="sum")){
789      std::stringstream errmsg;
790      errmsg << "The requested value of the parameter spectralMethod, \""
791             << this->spectralMethod << "\", is invalid.\n"
792             << "Changing to \"peak\".\n";
793      duchampWarning("Reading parameters",errmsg.str());
794      this->spectralMethod = "peak";
795    }
796
797    // Make sure pixelCentre is an acceptable type -- default is "peak"
798    if((this->pixelCentre!="centroid")&&
799       (this->pixelCentre!="average") &&
800       (this->pixelCentre!="peak")       ){
801      std::stringstream errmsg;
802      errmsg << "The requested value of the parameter pixelCentre, \""
803             << this->pixelCentre << "\", is invalid.\n"
804             << "Changing to \"centroid\".\n";
805      duchampWarning("Reading parameters",errmsg.str());
806      this->pixelCentre = "centroid";
807    }
808
809    // Make sure sortingParam is an acceptable type -- default is "vel"
810    bool OK = false;
811    for(int i=0;i<numSortingParamOptions;i++)
812      OK = OK || this->sortingParam==sortingParamOptions[i];
813    if(!OK){
814      std::stringstream errmsg;
815      errmsg << "The requested value of the parameter sortingParam, \""
816             << this->sortingParam << "\", is invalid.\n"
817             << "Changing to \"vel\".\n";
818      duchampWarning("Reading parameters",errmsg.str());
819      this->sortingParam = "vel";
820    }
821     
822  }
823
824  void recordParameters(std::ostream& theStream, std::string paramName, std::string paramDesc, std::string paramValue)
825  {
826   
827    const int width = 56;
828    int widthText = width - paramName.size();
829
830    theStream << std::setw(widthText) << paramDesc
831              << setiosflags(std::ios::right) << paramName
832              << "  =  " << resetiosflags(std::ios::right) << paramValue
833              <<std::endl;
834  }
835
836  std::string fileOption(bool flag, std::string file)
837  {
838    std::ostringstream ss;
839    ss << stringize(flag);
840    if(flag) ss << " --> " << file;
841    return ss.str();
842   
843  }
844
845  std::ostream& operator<< ( std::ostream& theStream, Param& par)
846  {
847    /// Print out the parameter set in a formatted, easy to read style.
848    /// Lists the parameters, a description of them, and their value.
849
850    // Only show the [beamSize] bit if we are using the parameter
851    // otherwise we have read it from the FITS header.
852    std::string beamParam = "";
853    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
854
855    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
856    //   theStream.setf(std::ios::boolalpha);
857    theStream.setf(std::ios::left);
858    theStream  <<"\n---- Parameters ----"<<std::endl;
859    theStream  << std::setfill('.');
860    if(par.getFlagSubsection())
861      recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection());
862    else
863      recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile());
864    if(par.getFlagReconExists() && par.getFlagATrous()){
865      recordParam(theStream, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists()));
866      recordParam(theStream, "[reconFile]", "FITS file containing reconstruction", par.getReconFile());
867    }
868    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
869      recordParam(theStream, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists()));
870      recordParam(theStream, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile());
871    }
872    recordParam(theStream, "[logFile]", "Intermediate Logfile", par.getLogFile());
873    recordParam(theStream, "[outFile]", "Final Results file", par.getOutFile());
874    if(par.getFlagSeparateHeader()){
875      recordParam(theStream, "[headerFile]", "Header for results file", par.getHeaderFile());
876    }
877    recordParam(theStream, "[spectraFile]", "Spectrum file", par.getSpectraFile());
878    if(par.getFlagTextSpectra()){
879      recordParam(theStream, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile());
880    }
881    if(par.getFlagVOT()){
882      recordParam(theStream, "[votFile]", "VOTable file", par.getVOTFile());
883    }
884    if(par.getFlagKarma()){
885      recordParam(theStream, "[karmaFile]", "Karma annotation file" , par.getKarmaFile());
886    }
887    if(par.getFlagMaps()){
888      recordParam(theStream, "[momentMap]", "0th Moment Map", par.getMomentMap());
889      recordParam(theStream, "[detectionMap]", "Detection Map", par.getDetectionMap());
890    }
891    recordParam(theStream, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput()));
892    if(par.getFlagATrous()){
893      recordParam(theStream, "[flagOutputRecon]", "Saving reconstructed cube?", fileOption(par.getFlagOutputRecon(),par.outputReconFile()));
894      recordParam(theStream, "[flagOutputResid]", "Saving residuals from reconstruction?", fileOption(par.getFlagOutputResid(),par.outputResidFile()));
895    }                                                 
896    if(par.getFlagSmooth()){   
897      recordParam(theStream, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile()));
898    }                                                 
899    recordParam(theStream, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile()));
900    recordParam(theStream, "[flagOutputMask]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile()));
901
902    theStream  <<"------"<<std::endl;
903
904    recordParam(theStream, "[searchType]", "Type of searching performed", par.getSearchType());
905    if(par.getFlagBlankPix()){
906      recordParam(theStream, "", "Blank Pixel Value", par.getBlankPixVal());
907    }
908    recordParam(theStream, "[flagTrim]", "Trimming Blank Pixels?", stringize(par.getFlagTrim()));
909    recordParam(theStream, "[flagNegative]", "Searching for Negative features?", stringize(par.getFlagNegative()));
910    recordParam(theStream, "[flagMW]", "Removing Milky Way channels?", stringize(par.getFlagMW()));
911    if(par.getFlagMW()){
912      // need to remove the offset correction, as we want to report the parameters actually entered
913      recordParam(theStream, "[minMW - maxMW]", "Milky Way Channels", par.getMinMW()+par.getZOffset()<<"-"<<par.getMaxMW()+par.getZOffset());
914    }
915    if(par.getFlagUsingBeam()){
916      if(par.getBeamFWHM()>0.) recordParam(theStream, "[beamFWHM]", "FWHM of Beam (pixels)", par.getBeamFWHM() << "   (beam area = " << par.getBeamSize() <<" pixels)");
917      else recordParam(theStream, "[beamArea]", "Area of Beam (pixels)", par.getBeamSize());
918    }
919    else {
920      recordParam(theStream, "", "Area of Beam (pixels)", par.getBeamSize());
921    }
922    recordParam(theStream, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline()));
923    recordParam(theStream, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth()));
924    if(par.getFlagSmooth()){           
925      recordParam(theStream, "[smoothType]", "Type of smoothing", par.getSmoothType());
926      if(par.getSmoothType()=="spectral")
927        recordParam(theStream, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth());
928      else{
929        recordParam(theStream, "[kernMaj]", "Gaussian kernel semi-major axis [pix]", par.getKernMaj());
930        recordParam(theStream, "[kernMin]", "Gaussian kernel semi-minor axis [pix]", par.getKernMin());
931        recordParam(theStream, "[kernPA]",  "Gaussian kernel position angle [deg]",  par.getKernPA());
932      }
933    }
934    recordParam(theStream, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous()));
935    if(par.getFlagATrous()){                           
936      recordParam(theStream, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim());
937      if(par.getMaxScale()>0){
938        recordParam(theStream, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale());
939      }
940      else{
941        recordParam(theStream, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale());
942      }
943      recordParam(theStream, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut());
944      recordParam(theStream, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")");
945    }                                                 
946    recordParam(theStream, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats()));
947    if(par.getFlagStatSec()){
948      recordParam(theStream, "[statSec]", "Section used by statistics calculation", par.statSec.getSection());
949    }
950    recordParam(theStream, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR()));
951    if(par.getFlagFDR()){                                     
952      recordParam(theStream, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha());
953      recordParam(theStream, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan());
954    }                                                 
955    else {
956      if(par.getFlagUserThreshold()){
957        recordParam(theStream, "[threshold]", "Detection Threshold", par.getThreshold());
958      }
959      else{
960        recordParam(theStream, "[snrCut]", "SNR Threshold (in sigma)", par.getCut());
961      }
962    }
963    recordParam(theStream, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix());
964    recordParam(theStream, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels());
965    recordParam(theStream, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels());
966    recordParam(theStream, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth()));
967    if(par.getFlagGrowth()) {                         
968      if(par.getFlagUserGrowthThreshold()){
969        recordParam(theStream, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold());
970      }
971      else{
972        recordParam(theStream, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut());
973      }
974    }
975    recordParam(theStream, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent()));
976    if(!par.getFlagAdjacent()){
977      recordParam(theStream, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS());
978    }
979    recordParam(theStream, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV());
980    recordParam(theStream, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge()));
981    recordParam(theStream, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging()));
982    recordParam(theStream, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod());
983    recordParam(theStream, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre());
984
985    theStream  <<"--------------------\n\n";
986    theStream  << std::setfill(' ');
987    theStream.unsetf(std::ios::left);
988    //  theStream.unsetf(std::ios::boolalpha);
989    return theStream;
990  }
991
992
993  void Param::copyHeaderInfo(FitsHeader &head)
994  {
995    ///  A function to copy across relevant header keywords from the
996    ///  FitsHeader class to the Param class, as they are needed by
997    ///  functions in the Param class.
998    ///  The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
999
1000    this->blankKeyword  = head.getBlankKeyword();
1001    this->bscaleKeyword = head.getBscaleKeyword();
1002    this->bzeroKeyword  = head.getBzeroKeyword();
1003    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1004      this->bzeroKeyword;
1005
1006    this->areaBeam    = head.getBeamSize();
1007  }
1008
1009  std::string Param::outputMaskFile()
1010  {
1011    ///  This function produces the required filename in which to save
1012    ///  the mask image, indicating which pixels have been detected as
1013    ///  part of an object. If the input image is image.fits, then the
1014    ///  output will be image.MASK.fits.
1015
1016    if(this->fileOutputMask==""){
1017      std::string inputName = this->imageFile;
1018      std::stringstream ss;
1019      ss << inputName.substr(0,inputName.size()-5); 
1020      // remove the ".fits" on the end.
1021      ss << ".MASK.fits";
1022      return ss.str();
1023    }
1024    else return this->fileOutputMask;
1025  }
1026
1027  std::string Param::outputMomentMapFile()
1028  {
1029    ///  This function produces the required filename in which to save
1030    ///  the moment-0 FITS image. If the input image is image.fits, then the
1031    ///  output will be image.MOM0.fits.
1032
1033    if(this->fileOutputMomentMap==""){
1034      std::string inputName = this->imageFile;
1035      std::stringstream ss;
1036      ss << inputName.substr(0,inputName.size()-5); 
1037      // remove the ".fits" on the end.
1038      ss << ".MOM0.fits";
1039      return ss.str();
1040    }
1041    else return this->fileOutputMomentMap;
1042  }
1043
1044  std::string Param::outputSmoothFile()
1045  {
1046    ///  This function produces the required filename in which to save
1047    ///   the smoothed array. If the input image is image.fits, then
1048    ///   the output will be:
1049    ///    <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1050    ///             width of the Hanning filter was 3 pixels.
1051    ///        <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1052    ///             kernMaj=3, kernMin=2 and kernPA=20 degrees.
1053    ///    </ul>
1054
1055    if(this->fileOutputSmooth==""){
1056      std::string inputName = this->imageFile;
1057      std::stringstream ss;
1058      ss << inputName.substr(0,inputName.size()-5); 
1059      // remove the ".fits" on the end.
1060      if(this->flagSubsection) ss<<".sub";
1061      if(this->smoothType=="spectral")
1062        ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1063      else if(this->smoothType=="spatial")
1064        ss << ".SMOOTH-2D-"
1065           << this->kernMaj << "-"
1066           << this->kernMin << "-"
1067           << this->kernPA  << ".fits";
1068      return ss.str();
1069    }
1070    else return this->fileOutputSmooth;
1071  }
1072
1073  std::string Param::outputReconFile()
1074  {
1075    /// This function produces the required filename in which to save
1076    ///  the reconstructed array. If the input image is image.fits, then
1077    ///  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1078    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1079
1080    if(this->fileOutputRecon==""){
1081      std::string inputName = this->imageFile;
1082      std::stringstream ss;
1083      // First we remove the ".fits" from the end of the filename.
1084      ss << inputName.substr(0,inputName.size()-5); 
1085      if(this->flagSubsection) ss<<".sub";
1086      ss << ".RECON-" << this->reconDim
1087         << "-"       << this->filterCode
1088         << "-"       << this->snrRecon
1089         << "-"       << this->scaleMin
1090         << ".fits";
1091      return ss.str();
1092    }
1093    else return this->fileOutputRecon;
1094  }
1095
1096  std::string Param::outputResidFile()
1097  {
1098    /// This function produces the required filename in which to save
1099    ///  the reconstructed array. If the input image is image.fits, then
1100    ///  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1101    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1102
1103    if(this->fileOutputResid==""){
1104      std::string inputName = this->imageFile;
1105      std::stringstream ss;
1106      // First we remove the ".fits" from the end of the filename.
1107      ss << inputName.substr(0,inputName.size()-5);
1108      if(this->flagSubsection) ss<<".sub";
1109      ss << ".RESID-" << this->reconDim
1110         << "-"       << this->filterCode
1111         << "-"       << this->snrRecon
1112         << "-"       << this->scaleMin
1113         << ".fits";
1114      return ss.str();
1115    }
1116    else return this->fileOutputResid;
1117  }
1118
1119}
Note: See TracBrowser for help on using the repository browser.