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
RevLine 
[3]1#include <iostream>
2#include <string>
[142]3#include <string.h>
[3]4#include <wcs.h>
5#include <wcshdr.h>
6#include <fitshdr.h>
7#include <wcsfix.h>
[103]8#include <wcsunits.h>
[142]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+
[66]11#include <fitsio.h>
[69]12#include <math.h>
[71]13#include <duchamp.hh>
[3]14#include <Cubes/cubes.hh>
15
[71]16string imageType[4] = {"point", "spectrum", "image", "cube"};
[3]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).
[161]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.
[3]28   */
29
30  long nelements;
[71]31  int bitpix,numAxes;
[3]32  int status = 0,  nkeys;  /* MUST initialize status */
33  fitsfile *fptr;         
34
[161]35  // Open the FITS file -- make sure it exists
[159]36  status = 0;
[3]37  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
38    fits_report_error(stderr, status);
39    return FAILURE;
40  }
41
[161]42  // Read the size information -- number and lengths of all axes.
43  // Just use this for reporting purposes.
[3]44  status = 0;
[159]45  if(fits_get_img_dim(fptr, &numAxes, &status)){
[3]46    fits_report_error(stderr, status);
47    return FAILURE;
48  }
[159]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  }
[161]56 
57  // Close the FITS file.
[71]58  status = 0;
[159]59  fits_close_file(fptr, &status);
[3]60  if (status){
[159]61    duchampWarning("getCube","Error closing file: ");
[3]62    fits_report_error(stderr, status);
63  }
64
[161]65  // Report the size of the FITS file
[160]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;
[103]71
[160]72  delete [] dimAxes;
[3]73
[161]74  // Get the WCS information
[160]75  this->head.defineWCS(fname, this->par);
[103]76
[160]77  if(!this->head.isWCS())
78    duchampWarning("getCube","WCS is not good enough to be used.\n");
[3]79
[161]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).
[160]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;
[46]89
[161]90  // Read the necessary header information, and copy some of it into the Param.
[160]91  this->head.readHeaderInfo(fname, this->par);
92  this->par.copyHeaderInfo(this->head);
[3]93
[103]94  return SUCCESS;
[3]95
96}
97
Note: See TracBrowser for help on using the repository browser.