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

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

Added more informative comments to the new functions.

File size: 2.8 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    return FAILURE;
40  }
41
42  // Read the size information -- number and lengths of all axes.
43  // Just use this for reporting purposes.
44  status = 0;
45  if(fits_get_img_dim(fptr, &numAxes, &status)){
46    fits_report_error(stderr, status);
47    return FAILURE;
48  }
49  long *dimAxes = new long[numAxes];
50  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
51  status = 0;
52  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
53    fits_report_error(stderr, status);
54    return FAILURE;
55  }
56 
57  // Close the FITS file.
58  status = 0;
59  fits_close_file(fptr, &status);
60  if (status){
61    duchampWarning("getCube","Error closing file: ");
62    fits_report_error(stderr, status);
63  }
64
65  // Report the size of the FITS file
66  if(numAxes<=3)  std::cout << "Dimensions of FITS file: ";
67  int dim = 0;
68  std::cout << dimAxes[dim];
69  while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim];
70  std::cout << std::endl;
71
72  delete [] dimAxes;
73
74  // Get the WCS information
75  this->head.defineWCS(fname, this->par);
76
77  if(!this->head.isWCS())
78    duchampWarning("getCube","WCS is not good enough to be used.\n");
79
80  // Get the data array from the FITS file.
81  // Report the dimensions of the data array that was read (this can be
82  //   different to the full FITS array).
83  std::cerr << "Reading data ... ";
84  this->getFITSdata(fname);
85  std::cerr << "Done. Data array has dimensions: ";
86  std::cerr << this->axisDim[0] <<"x"
87            << this->axisDim[1] <<"x"
88            << this->axisDim[2] << std::endl;
89
90  // Read the necessary header information, and copy some of it into the Param.
91  this->head.readHeaderInfo(fname, this->par);
92  this->par.copyHeaderInfo(this->head);
93
94  return SUCCESS;
95
96}
97
Note: See TracBrowser for help on using the repository browser.