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

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

A couple of changes:

  • Removed the Fortran search in the configure script -- we don't use it.
  • Cleaned up some of the fits-I/O tasks, adding some functions that check for the existence of the FITS file (fits_file_exists).
  • This task is only in v2.5+ of cfitsio, so added notes to this effect in README and the Guide.
  • Improved the exiting and warning messages in mainDuchamp.cc.
File size: 3.2 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  int exists;
36  fits_file_exists(fname.c_str(),&exists,&status);
37  if(exists<=0){
38    fits_report_error(stderr, status);
39    duchampWarning("getCube", "Requested image does not exist!\n");
40    return FAILURE;   
41  }
42
43  // Open the FITS file -- make sure it exists
44  status = 0;
45  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
46    fits_report_error(stderr, status);
47    if(((status==URL_PARSE_ERROR)||(status==BAD_NAXIS))
48       &&(this->pars().getFlagSubsection()))
49      duchampError("getCube",
50                   "It may be that the subsection you've entered is invalid.\n\
51Either it has the wrong number of axes, or one axis has too large a range.\n");
52    return FAILURE;
53  }
54
55  // Read the size information -- number and lengths of all axes.
56  // Just use this for reporting purposes.
57  status = 0;
58  if(fits_get_img_dim(fptr, &numAxes, &status)){
59    fits_report_error(stderr, status);
60    return FAILURE;
61  }
62  long *dimAxes = new long[numAxes];
63  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
64  status = 0;
65  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
66    fits_report_error(stderr, status);
67    return FAILURE;
68  }
69 
70  // Close the FITS file.
71  status = 0;
72  fits_close_file(fptr, &status);
73  if (status){
74    duchampWarning("getCube","Error closing file: ");
75    fits_report_error(stderr, status);
76  }
77
78  // Report the size of the FITS file
79  std::cout << "Dimensions of FITS file: ";
80  int dim = 0;
81  std::cout << dimAxes[dim];
82  while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim];
83  std::cout << std::endl;
84
85  delete [] dimAxes;
86
87  // Get the WCS information
88  this->head.defineWCS(fname, this->par);
89
90  if(!this->head.isWCS())
91    duchampWarning("getCube","WCS is not good enough to be used.\n");
92
93  // Get the data array from the FITS file.
94  // Report the dimensions of the data array that was read (this can be
95  //   different to the full FITS array).
96  std::cerr << "Reading data ... ";
97  this->getFITSdata(fname);
98  std::cerr << "Done. Data array has dimensions: ";
99  std::cerr << this->axisDim[0] <<"x"
100            << this->axisDim[1] <<"x"
101            << this->axisDim[2] << std::endl;
102
103  // Read the necessary header information, and copy some of it into the Param.
104  this->head.readHeaderInfo(fname, this->par);
105  this->par.copyHeaderInfo(this->head);
106
107  return SUCCESS;
108
109}
110
Note: See TracBrowser for help on using the repository browser.