source: trunk/src/FitsIO/subsection.cc @ 258

Last change on this file since 258 was 258, checked in by Matthew Whiting, 17 years ago

Merging pixel-map-branch revisions 236:257 back into trunk.
The use of the PixelMap? functions is sorted now, so we put everything back into a uniform location.

File size: 3.1 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <string>
4#include <vector>
5#include <math.h>
6#include <wcs.h>
7#define WCSLIB_GETWCSTAB // define this so that we don't try and redefine
8                         //  wtbarr (this is a problem when using gcc v.4+
9#include <fitsio.h>
10#include <param.hh>
11#include <duchamp.hh>
12#include <Utils/Section.hh>
13
14void Param::setOffsets(struct wcsprm *wcs)
15{
16  /**
17   * If there is a subsection being used, set the offset values
18   * according to the correct dimensions given by the WCS struct. 
19   * If not, set the offsets to zero.
20   * \param wcs The WCSLIB wcsprm struct that defines which axis is which.
21   */
22  if(this->flagSubsection){ // if so, then the offsets array is defined.
23    this->xSubOffset = this->pixelSec.getStart(wcs->lng);
24    this->ySubOffset = this->pixelSec.getStart(wcs->lat);
25    this->zSubOffset = this->pixelSec.getStart(wcs->spec);
26  }
27  else{// else they should be 0
28    this->xSubOffset = this->ySubOffset = this->zSubOffset = 0;
29  }
30}
31
32int Param::verifySubsection()
33{
34  /**
35   *   Checks that the subsection string is in the appropriate format, with
36   *    the correct number of entries (one for each axis).
37   *   This involves reading the individual substrings and converting to
38   *    integers, and storing in the offsets array.
39   *   Steps in the subsection string are not dealt with -- a warning message
40   *    is written to the screen, and the step values are removed from the
41   *    subsection string.
42   */
43
44  // First open the requested FITS file and check its existence and
45  //  number of axes.
46  int numAxes,status = 0;  /* MUST initialize status */
47  fitsfile *fptr;         
48
49  // Make sure the FITS file exists
50  int exists;
51  fits_file_exists(this->imageFile.c_str(),&exists,&status);
52  if(exists<=0){
53    fits_report_error(stderr, status);
54    duchampWarning("verifySubsection", "Requested image does not exist!\n");
55    return FAILURE;
56  }
57  // Open the FITS file
58  if( fits_open_file(&fptr,this->imageFile.c_str(),READONLY,&status) ){
59    fits_report_error(stderr, status);
60    return FAILURE;
61  }
62  // Read the size information -- number of axes and their sizes
63  status = 0;
64  if(fits_get_img_dim(fptr, &numAxes, &status)){
65    fits_report_error(stderr, status);
66    return FAILURE;
67  }
68  long *dimAxes = new long[numAxes];
69  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
70  status = 0;
71  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
72    fits_report_error(stderr, status);
73    return FAILURE;
74  }
75  // Close the FITS file.
76  status = 0;
77  fits_close_file(fptr, &status);
78  if (status){
79    duchampWarning("verifySubsection","Error closing file: ");
80    fits_report_error(stderr, status);
81  }
82
83  ///////////////////
84  // Now parse the subsection and make sure all that works.
85 
86  std::vector<long> dim(numAxes);
87  for(int i=0;i<numAxes;i++) dim[i] = dimAxes[i];
88  delete [] dimAxes;
89  if(this->pixelSec.parse(dim)==FAILURE){
90    std::cerr << "fnord\n";
91    return FAILURE;
92  }
93  if(this->statSec.parse(dim)==FAILURE){
94    std::cerr << "aarrgghh!\n";
95    return FAILURE;
96  }
97
98  std::cerr << this->statSec.getSection()<<" <=====> " << this->statSec.getStart(0) << "\n";
99
100  return SUCCESS;
101}
Note: See TracBrowser for help on using the repository browser.