source: trunk/src/Cubes/ReadExistingSmooth.cc @ 1095

Last change on this file since 1095 was 1095, checked in by MatthewWhiting, 12 years ago

Classes to address #166, that solve (I think) #164 in the process. Need a bit of testing

File size: 4.3 KB
Line 
1#include <duchamp/Cubes/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().getFlagReconExists()){
44      DUCHAMPWARN("readReconCube",
45                  "reconExists flag is not set. Not reading anything in!");
46      return FAILURE;
47    }
48    else if(!this->itsCube->pars().getFlagSmooth()){
49      DUCHAMPWARN("readReconCube",
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=SUCCESS;
59    int exists,status=0;
60    std::string smoothFile = this->itsCube->pars().outputSmoothFile();
61    DUCHAMPWARN("readSmoothCube", "Trying file " << smoothFile );
62    fits_file_exists(smoothFile.c_str(),&exists,&status);
63    if(exists<=0){
64      fits_report_error(stderr, status);
65      DUCHAMPERROR("readSmoothCube","SmoothFile not present.");
66      result = FAILURE;
67    }
68
69    if(result==SUCCESS){
70      // were able to open this new file -- use this, so reset the
71      //  relevant parameter
72      this->itsCube->pars().setSmoothFile(smoothFile);
73    }
74
75    this->itsFilename = smoothFile;
76    return result;
77
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 recon or resid files 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.