source: trunk/src/FitsIO/ReadExistingSmooth.cc @ 1441

Last change on this file since 1441 was 1365, checked in by MatthewWhiting, 10 years ago

Report the name of the recon/smooth file we were searching for if it isn't found.

File size: 4.3 KB
Line 
1#include <duchamp/FitsIO/ReadExistingSmooth.hh>
2#include <duchamp/duchamp.hh>
3#include <duchamp/Cubes/cubes.hh>
4
5namespace duchamp {
6
7  ReadExistingSmooth::ReadExistingSmooth():
8    ReadExisting()
9  {
10  }
11 
12  ReadExistingSmooth::ReadExistingSmooth(Cube *cube):
13    ReadExisting(cube)
14  {
15  }
16
17  ReadExistingSmooth::ReadExistingSmooth(const ReadExistingSmooth &other)
18  {
19    this->operator=(other);
20  }
21
22  ReadExistingSmooth::ReadExistingSmooth(const ReadExisting &base)
23  {
24    this->operator=(base);
25  }
26
27  ReadExistingSmooth& ReadExistingSmooth::operator= (const ReadExistingSmooth& other)
28  {
29    if(this==&other) return *this;
30    ((ReadExisting &) *this) = other;
31    return *this;
32  }
33
34  ReadExistingSmooth& ReadExistingSmooth::operator= (const ReadExisting& base)
35  {
36    if(this==&base) return *this;
37    ((ReadExisting &) *this) = base;
38    return *this;
39  }
40
41  OUTCOME ReadExistingSmooth::checkPars()
42  {
43    if(!this->itsCube->pars().getFlagSmoothExists()){
44      DUCHAMPWARN("readSmoothCube",
45                  "smoothExists flag is not set. Not reading anything in!");
46      return FAILURE;
47    }
48    else if(!this->itsCube->pars().getFlagSmooth()){
49      DUCHAMPWARN("readSmoothCube",
50                  "flagSmooth is not set. Don't need to read in recon array!");
51      return FAILURE;
52    }
53    return SUCCESS;
54  }
55
56  OUTCOME ReadExistingSmooth::checkFile()
57  {
58    OUTCOME result=FAILURE;
59    int exists,status=0;
60    std::string smoothFile = this->itsCube->pars().outputSmoothFile();
61
62    if(this->itsCube->pars().getSmoothFile() == "")
63      DUCHAMPWARN("readSmoothCube", "SmoothFile not specified. Working out name from parameters.");
64
65    fits_file_exists(smoothFile.c_str(),&exists,&status);
66    if(exists<=0){
67      fits_report_error(stderr, status);
68      DUCHAMPERROR("readSmoothCube","SmoothFile " << smoothFile << " not present.");
69      result = FAILURE;
70    }
71    else{
72      result=SUCCESS;
73      this->itsCube->pars().setSmoothFile(smoothFile);
74    }
75
76    this->itsFilename = smoothFile;
77    return result;
78  }
79
80  OUTCOME ReadExistingSmooth::checkHeaders()
81  {
82    OUTCOME result=SUCCESS;
83    if(this->itsFptr==0){
84      DUCHAMPERROR("readSmoothCube","FITS file not open");
85      result=FAILURE;
86    }
87    else{
88
89      int status = 0;
90      char *comment = new char[80];
91
92      if(this->itsCube->pars().getSmoothType()=="spectral"){
93
94        int hannWidth;
95        fits_read_key(this->itsFptr, TINT, (char *)keyword_hanningwidth.c_str(),
96                      &hannWidth, comment, &status);
97        if(hannWidth != this->itsCube->pars().getHanningWidth()){
98          DUCHAMPERROR("readSmoothCube", keyword_hanningwidth << " keyword in smoothFile (" << hannWidth << ") does not match the hanningWidth parameter (" << this->itsCube->pars().getHanningWidth() << ").");
99          result = FAILURE;
100        }
101
102      }
103      else if(this->itsCube->pars().getSmoothType()=="spatial"){
104
105        float maj,min,pa;
106        status = 0;
107        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernmaj.c_str(),
108                      &maj, comment, &status);
109        if(maj != this->itsCube->pars().getKernMaj()){
110          DUCHAMPERROR("readSmoothCube", keyword_kernmaj << " keyword in smoothFile (" << maj << ") does not match the kernMaj parameter (" << this->itsCube->pars().getKernMaj() << ").");
111          result = FAILURE;
112        }
113        status = 0;
114        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernmin.c_str(),
115                      &min, comment, &status);
116        if(min != this->itsCube->pars().getKernMin()){
117          DUCHAMPERROR("readSmoothCube", keyword_kernmin << " keyword in smoothFile (" << maj << ") does not match the kernMin parameter (" << this->itsCube->pars().getKernMin() << ").");
118          result = FAILURE;
119        }
120        status = 0;
121        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernpa.c_str(),
122                      &pa, comment, &status);
123        if(pa != this->itsCube->pars().getKernPA()){
124          DUCHAMPERROR("readSmoothCube", keyword_kernpa << " keyword in smoothFile (" << maj << ") does not match the kernPA parameter (" << this->itsCube->pars().getKernPA() << ").");
125          result = FAILURE;
126        }
127
128      }
129
130    }
131
132    if(result==FAILURE){
133      DUCHAMPERROR("readSmoothCube","Header keyword mismatch - not reading smoothed array from " << this->itsFilename);
134    }
135
136
137    return result;
138
139  }
140
141  OUTCOME ReadExistingSmooth::readFromFile()
142  {
143    OUTCOME result = this->ReadExisting::readFromFile();
144    if(result == SUCCESS){
145      // We don't want to write out the smooth file at the end
146      this->itsCube->pars().setFlagOutputSmooth(false);
147    }
148    return result;
149  }
150
151
152}
Note: See TracBrowser for help on using the repository browser.