source: branches/fitshead-branch/Cubes/readRecon.cc @ 1441

Last change on this file since 1441 was 100, checked in by Matthew Whiting, 18 years ago

Four major sets of changes and a couple of minor ones:

  • Changed name of saved recon/resid FITS file, so that it incorporates all reconstruction parameters.
  • Removed MW parameters from header file
  • Added hashed box to be drawn over MW range in spectral plots
  • Fixed bug that meant reon would be done in 1- or 2-d even if recon array has been read in.

Summary:
param.hh -- prototypes for FITS file name calculation functions
param.cc -- FITS file name calculation functions
Cubes/plots.hh -- drawMWRange function
ATrous/ReconSearch.cc -- tests to see if reconExists for 1- and 2-D recon
Cubes/cubes.cc -- work out enclosed flux correctly for flagNegative
Cubes/detectionIO.cc -- added reconDim line to VOTable output
Cubes/outputSpectra.cc -- added code to draw MW range
Cubes/readRecon.cc -- added call to FITS file name function, and removed

MW params and superfluous tests on atrous parameters

Cubes/saveImage.cc -- improved logical flow. added call to FITS file name func

removed MW keywords.

Detection/columns.cc -- added extra column to fluxes if negative.

File size: 4.2 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <string>
4#include <wcs.h>
5#include <wcshdr.h>
6#define WCSLIB_GETWCSTAB // define this so that we don't try and redefine wtbarr
7                         // (this is a problem when using gcc v.4+
8#include <fitsio.h>
9#include <duchamp.hh>
10#include <Cubes/cubes.hh>
11
12int Cube::readReconCube()
13{
14  /**
15   *  Cube::readReconCube()
16   *   
17   *   A way to read in a previously reconstructed array, corresponding to the
18   *    requested parameters, or in the filename given by reconFile.
19   *   Performs various tests to make sure there are no clashes between the requested
20   *    parameters and those stored in the header of the FITS file.
21   */
22
23
24  fitsfile *fptr;
25  int status = 0;
26
27  // Check to see whether the parameters reconFile and/or residFile are defined.
28  bool reconGood = false;
29  bool residGood = false;
30  int exists;
31  if(this->par.getReconFile() != ""){
32    reconGood = true;
33    fits_file_exists(this->par.getReconFile().c_str(),&exists,&status);
34    if(exists<=0){
35      fits_report_error(stderr, status);
36      std::cerr <<
37        "  WARNING <readReconCube> : Cannot find requested ReconFile. Trying with parameters.\n";
38      std::cerr <<
39        "                            Bad reconFile was: "<<this->par.getReconFile()<<std::endl;
40      reconGood = false;
41    }
42  }
43  else{
44    std::cerr <<
45      "  WARNING <readReconCube> : ReconFile not specified. Working out name from parameters.\n";
46  }
47 
48  if(!reconGood){ // if bad, need to look at parameters
49
50    string reconFile = this->par.outputReconFile();
51    std::cerr << "                          : Trying file " << reconFile << std::endl;
52    reconGood = true;
53    fits_file_exists(reconFile.c_str(),&exists,&status);
54    if(exists<=0){
55      fits_report_error(stderr, status);
56      std::cerr <<
57        "  WARNING <readReconCube> : ReconFile not present\n";
58      reconGood = false;
59    }
60
61    if(reconGood){ // were able to open this file -- use this, so reset the relevant parameter
62      this->par.setReconFile(reconFile);
63    }
64    else { // if STILL bad, give error message and exit.
65      std::cerr << "  ERROR <readReconCube> : Cannot find reconstructed file.\n";
66      return FAILURE;
67    }
68
69  }
70
71  // if we get to here, reconGood is true (ie. file is open);
72  status=0;
73  fits_open_file(&fptr,this->par.getReconFile().c_str(),READONLY,&status);
74  short int maxdim=3;
75  long *fpixel = new long[maxdim];
76  for(int i=0;i<maxdim;i++) fpixel[i]=1;
77  long *dimAxesNew = new long[maxdim];
78  for(int i=0;i<maxdim;i++) dimAxesNew[i]=1;
79  long nelements;
80  int bitpix,numAxesNew,anynul;
81
82  status = 0;
83  fits_get_img_param(fptr, maxdim, &bitpix, &numAxesNew, dimAxesNew, &status);
84  if(status){
85    fits_report_error(stderr, status);
86    return FAILURE;
87  }
88
89  if(numAxesNew != this->numDim){
90    std::cerr << "  ERROR <readReconCube> : "
91              << "  Reconstructed cube has a different number of axes to original! ("
92              << numAxesNew << " cf. " << this->numDim << ")\n";
93    return FAILURE;
94  }
95
96  for(int i=0;i<numAxesNew;i++){
97    if(dimAxesNew[i]!=this->axisDim[i]){
98      std::cerr << "  ERROR <readReconCube> : "
99                << "  Reconstructed cube has different axis dimensions to original!\n"
100                << "        Axis #" << i << " has size " << dimAxesNew[i]
101                << "   cf. " << this->axisDim[i] <<" in original.\n";   
102      return FAILURE;
103    }
104  }     
105
106  float *reconArray = new float[this->numPixels];
107  //  fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, this->recon, &anynul, &status);
108  status = 0;
109  fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, reconArray, &anynul, &status);
110  this->saveRecon(reconArray,this->numPixels);
111 
112  if(!this->par.getFlagATrous()){
113    this->par.setFlagATrous(true);
114    std::cerr << "  WARNING <readReconCube> : Setting flagAtrous from false to true, as the reconstruction exists.\n";
115  }
116
117  status = 0;
118  fits_close_file(fptr, &status);
119  if (status){
120    std::cerr << "  WARNING <readReconCube> : Error closing file: ";
121    fits_report_error(stderr, status);
122    //    return FAILURE;
123  }
124
125  // We don't want to write out the recon or resid files at the end
126  this->par.setFlagOutputRecon(false);
127  this->par.setFlagOutputResid(false);
128
129  // The reconstruction is done -- set the appropriate flag
130  this->reconExists = true;
131
132  return SUCCESS;
133}
Note: See TracBrowser for help on using the repository browser.