source: trunk/src/FitsIO/dataIO.cc @ 160

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

Changed the way the FITS file is read in, so that it can deal with
naxis>4 files, where the order of the dimensions is not necessarily
lng,lat,spec,...

Summary of changes:

*Cubes/getImage.cc:

*Removed most of the code that goes in new functions.
*Changed order of tasks, so that the WCS is derived first, then the data array, and then the remaining header information.
*Also reports both the FITS dimensions and the data array dimensions.

*FitsIO/headerIO.cc:

*Moved defineWCS to wcsIO.cc.
*Made array declarations more robust (use CFITSIO constants for lengths).
*Changed type of BLANK keyword to TINT.

*FitsIO/dataIO.cc:

*New function, designed to read in data from FITS file.
*Reads in subset of just the spatial and spectral axes.
*Also takes care of setting blank pixels to appropriate value.

*FitsIO/wcsIO.cc:

*New file, contains the function FitsHeader::defineWCS

  • Utils/wcsFunctions.cc:

*Generalised the wcs functions, so that they make no

assumptions about the location of the spatial and spectral axes.

*Cubes/cubes.cc:

*Improved Cube::initialiseCube so that it gets the dimensions correct.
*Enabled Cube::getopts to deal with non-existant param file.
*Improved error reporting in saveArray functions.

*Cubes/cubes.hh:

*Changed prototypes for readParam. Added one for getFITSdata

*Cubes/ReadAndSearch?.cc :

*Minor comment added.

*param.cc:

*Generalised way fixUnits works, to cope with new axis concept.
*Made readParams return int, so it can indicate whether reading failed.

*ATrous/ReconSearch.cc:

*Improved way the goodness of the pixels and channels was determined.

*src/param.hh

*New prototype for Param::readParams

*Guide:

*Changed text about dimensionality of FITS files.
*Changed location of images.
*Minor changes to improve readability.

File size: 2.6 KB
Line 
1#include <iostream>
2#include <string>
3#define WCSLIB_GETWCSTAB // define this so that we don't try and redefine
4                         //  wtbarr (this is a problem when using gcc v.4+
5#include <fitsio.h>
6#include <math.h>
7#include <duchamp.hh>
8#include <Cubes/cubes.hh>
9
10int Cube::getFITSdata(string fname)
11{
12
13  long nelements;
14  int bitpix,numAxes;
15  int status = 0,  nkeys;  /* MUST initialize status */
16  fitsfile *fptr; 
17
18  status = 0;
19  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
20    fits_report_error(stderr, status);
21    return FAILURE;
22  }
23  status = 0;
24  if(fits_get_img_dim(fptr, &numAxes, &status)){
25    fits_report_error(stderr, status);
26    return FAILURE;
27  }
28  long *dimAxes = new long[numAxes];
29  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
30  status = 0;
31  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
32    fits_report_error(stderr, status);
33    return FAILURE;
34  }
35
36  int lng = this->head.getWCS()->lng;
37  int lat = this->head.getWCS()->lat;
38  int spc = this->head.getWCS()->spec;
39
40  int anynul;
41  int npix = dimAxes[lng]*dimAxes[lat]*dimAxes[spc];
42  float *array = new float[npix];
43  char *nullarray = new char[npix];
44  long *fpixel = new long[numAxes];
45  long *lpixel = new long[numAxes];
46  long *inc = new long[numAxes];    // the data-sampling increment
47  for(int i=0;i<numAxes;i++){
48    inc[i] = fpixel[i] = lpixel[i] = 1;
49  }
50  lpixel[lng] = dimAxes[lng];
51  lpixel[lat] = dimAxes[lat];
52  lpixel[spc] = dimAxes[spc];
53   
54  int colnum = 0;
55  status = 0;
56  if(fits_read_subsetnull_flt(fptr, colnum, numAxes, dimAxes,
57                              fpixel, lpixel, inc,
58                              array, nullarray, &anynul, &status)){
59    duchampError("getFITSdata",
60                 "There was an error reading in the data array:");
61    fits_report_error(stderr, status);
62    return FAILURE;
63  }
64
65  if(anynul==0){   
66    // no blank pixels, so don't bother with any trimming or checking...
67    if(this->par.getFlagBlankPix()) { 
68      // if user requested fixing, inform them of change.
69      duchampWarning("getFITSdata",
70                     "No blank pixels, so setting flagBlankPix to false.\n");
71    }
72    this->par.setFlagBlankPix(false);
73  }
74
75  this->initialiseCube(dimAxes);
76  this->saveArray(array,npix);
77  //-------------------------------------------------------------
78  // Once the array is saved, change the value of the blank pixels from
79  // 0 (as they are set by fits_read_pixnull) to the correct blank value
80  // as determined by the above code.
81  for(int i=0; i<npix;i++){
82//     if(nullarray[i]==1) this->array[i] = blank*bscale + bzero; 
83    if(isnan(array[i])) this->array[i] = par.getBlankPixVal();
84    if(nullarray[i]==1) this->array[i] = this->par.getBlankPixVal(); 
85  }
86
87  return SUCCESS;
88
89}
Note: See TracBrowser for help on using the repository browser.