source: branches/pixel-map-branch/src/Cubes/getImage.cc

Last change on this file was 232, checked in by Matthew Whiting, 17 years ago

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 3.3 KB
Line 
1#include <iostream>
2#include <string>
3#include <string.h>
4#include <wcs.h>
5#include <wcshdr.h>
6#include <fitshdr.h>
7#include <wcsfix.h>
8#include <wcsunits.h>
9#define WCSLIB_GETWCSTAB // define this so that we don't try and redefine
10                         //  wtbarr (this is a problem when using gcc v.4+
11#include <fitsio.h>
12#include <math.h>
13#include <duchamp.hh>
14#include <Cubes/cubes.hh>
15
16std::string imageType[4] = {"point", "spectrum", "image", "cube"};
17
18int Cube::getCube(std::string fname)
19{
20  /**
21   * Read in a cube from the file fname (assumed to be in FITS format).
22   *  Function is a front end to the I/O functions in the FitsIO/ directory.
23   *  This function will check that the file exists, report the dimensions
24   *   and then get other functions to read the data, WCS, and necessary
25   *   header keywords.
26   *  \param fname A std::string with name of FITS file.
27   *  \return SUCCESS or FAILURE.
28   */
29
30  long nelements;
31  int bitpix,numAxes;
32  int status = 0,  nkeys;  /* MUST initialize status */
33  fitsfile *fptr;         
34
35  int exists;
36  fits_file_exists(fname.c_str(),&exists,&status);
37  if(exists<=0){
38    fits_report_error(stderr, status);
39    std::stringstream errmsg;
40    errmsg << "Requested image (" << fname << ") does not exist!\n";
41    duchampError("getCube", errmsg.str());
42    return FAILURE;
43  }
44
45  // Open the FITS file -- make sure it exists
46  status = 0;
47  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
48    fits_report_error(stderr, status);
49    if(((status==URL_PARSE_ERROR)||(status==BAD_NAXIS))
50       &&(this->pars().getFlagSubsection()))
51      duchampError("getCube",
52                   "It may be that the subsection you've entered is invalid.\n\
53Either it has the wrong number of axes, or one axis has too large a range.\n");
54    return FAILURE;
55  }
56
57  // Read the size information -- number and lengths of all axes.
58  // Just use this for reporting purposes.
59  status = 0;
60  if(fits_get_img_dim(fptr, &numAxes, &status)){
61    fits_report_error(stderr, status);
62    return FAILURE;
63  }
64  long *dimAxes = new long[numAxes];
65  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
66  status = 0;
67  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
68    fits_report_error(stderr, status);
69    return FAILURE;
70  }
71 
72  // Close the FITS file.
73  status = 0;
74  fits_close_file(fptr, &status);
75  if (status){
76    duchampWarning("getCube","Error closing file: ");
77    fits_report_error(stderr, status);
78  }
79
80  // Report the size of the FITS file
81  std::cout << "Dimensions of FITS file: ";
82  int dim = 0;
83  std::cout << dimAxes[dim];
84  while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim];
85  std::cout << std::endl;
86
87  delete [] dimAxes;
88
89  // Get the WCS information
90  this->head.defineWCS(fname, this->par);
91
92  if(!this->head.isWCS())
93    duchampWarning("getCube","WCS is not good enough to be used.\n");
94
95  // Get the data array from the FITS file.
96  // Report the dimensions of the data array that was read (this can be
97  //   different to the full FITS array).
98  std::cerr << "Reading data ... ";
99  this->getFITSdata(fname);
100  std::cerr << "Done. Data array has dimensions: ";
101  std::cerr << this->axisDim[0] <<"x"
102            << this->axisDim[1] <<"x"
103            << this->axisDim[2] << std::endl;
104
105  // Read the necessary header information, and copy some of it into the Param.
106  this->head.readHeaderInfo(fname, this->par);
107
108  return SUCCESS;
109
110}
111
Note: See TracBrowser for help on using the repository browser.