source: trunk/src/Cubes/getImage.cc @ 164

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

A series of changes, prompted by the need to update the subsections parsing
to make it compliant with the new multi-dimensional FITS formalism.
Specifically:

  • FitsIO/subsection.cc
    • New file. Main task the Param::verifySubsection() function. Makes sure the subsection has correct format and number of axes.

Also removes any steps in the subsection string.

  • Another simple function, Param::setOffsets, to set the offset values if necessary.
  • FitsIO/dataIO.cc
    • Call to Param::setOffsets after array is read in.
  • mainDuchamp.cc
    • Added a call to Param::verifySubsection() before the cube is opened.
  • param.hh
    • New prototypes and definition of offsets array in Param class.
  • param.cc
    • Removed parseSubsection
  • Cubes/cubes.hh:
    • A simpler way of doing the Cube::getCube() function. No call to parseSubsection
  • Cubes/getImage.cc:
    • An error message if opening the FITS file fails due to bad subsection.
    • Fixed a bug for the reporting of the FITS file size.
  • duchamp.cc
    • Added a bell to the duchampError function.
File size: 3.0 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
16string imageType[4] = {"point", "spectrum", "image", "cube"};
17
18int Cube::getCube(string fname)
19{
20  /**
21   * Cube::getCube(string )
22   *  Read in a cube from the file fname (assumed to be in FITS format).
23   *  Function is a front end to the I/O functions in the FitsIO/ directory.
24   *  This function will check that the file exists, report the dimensions
25   *   and then get other functions to read the data, WCS, and necessary
26   *   header keywords.
27   *  Returns SUCCESS/FAILURE.
28   */
29
30  long nelements;
31  int bitpix,numAxes;
32  int status = 0,  nkeys;  /* MUST initialize status */
33  fitsfile *fptr;         
34
35  // Open the FITS file -- make sure it exists
36  status = 0;
37  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
38    fits_report_error(stderr, status);
39    if((status==URL_PARSE_ERROR)&&(this->pars().getFlagSubsection()))
40      duchampError("getCube",
41                   "It may be that the subsection you've entered is invalid.\n\
42Either it has the wrong number of axes, or one axis has too large a range.\n");
43    return FAILURE;
44  }
45
46  // Read the size information -- number and lengths of all axes.
47  // Just use this for reporting purposes.
48  status = 0;
49  if(fits_get_img_dim(fptr, &numAxes, &status)){
50    fits_report_error(stderr, status);
51    return FAILURE;
52  }
53  long *dimAxes = new long[numAxes];
54  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
55  status = 0;
56  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
57    fits_report_error(stderr, status);
58    return FAILURE;
59  }
60 
61  // Close the FITS file.
62  status = 0;
63  fits_close_file(fptr, &status);
64  if (status){
65    duchampWarning("getCube","Error closing file: ");
66    fits_report_error(stderr, status);
67  }
68
69  // Report the size of the FITS file
70  std::cout << "Dimensions of FITS file: ";
71  int dim = 0;
72  std::cout << dimAxes[dim];
73  while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim];
74  std::cout << std::endl;
75
76  delete [] dimAxes;
77
78  // Get the WCS information
79  this->head.defineWCS(fname, this->par);
80
81  if(!this->head.isWCS())
82    duchampWarning("getCube","WCS is not good enough to be used.\n");
83
84  // Get the data array from the FITS file.
85  // Report the dimensions of the data array that was read (this can be
86  //   different to the full FITS array).
87  std::cerr << "Reading data ... ";
88  this->getFITSdata(fname);
89  std::cerr << "Done. Data array has dimensions: ";
90  std::cerr << this->axisDim[0] <<"x"
91            << this->axisDim[1] <<"x"
92            << this->axisDim[2] << std::endl;
93
94  // Read the necessary header information, and copy some of it into the Param.
95  this->head.readHeaderInfo(fname, this->par);
96  this->par.copyHeaderInfo(this->head);
97
98  return SUCCESS;
99
100}
101
Note: See TracBrowser for help on using the repository browser.