source: trunk/src/Cubes/ReadExistingRecon.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.1 KB
Line 
1#include <duchamp/Cubes/ReadExistingRecon.hh>
2#include <duchamp/duchamp.hh>
3#include <duchamp/Cubes/cubes.hh>
4
5namespace duchamp {
6
7  ReadExistingRecon::ReadExistingRecon():
8    ReadExisting()
9  {
10  }
11 
12  ReadExistingRecon::ReadExistingRecon(Cube *cube):
13    ReadExisting(cube)
14  {
15  }
16
17  ReadExistingRecon::ReadExistingRecon(const ReadExistingRecon &other)
18  {
19    this->operator=(other);
20  }
21
22  ReadExistingRecon::ReadExistingRecon(const ReadExisting &base)
23  {
24    this->operator=(base);
25  }
26
27  ReadExistingRecon& ReadExistingRecon::operator= (const ReadExistingRecon& other)
28  {
29    if(this==&other) return *this;
30    ((ReadExisting &) *this) = other;
31    return *this;
32  }
33
34  ReadExistingRecon& ReadExistingRecon::operator= (const ReadExisting& base)
35  {
36    if(this==&base) return *this;
37    ((ReadExisting &) *this) = base;
38    return *this;
39  }
40
41  OUTCOME ReadExistingRecon::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().getFlagATrous()){
49      DUCHAMPWARN("readReconCube",
50                  "flagATrous is not set. Don't need to read in recon array!");
51      return FAILURE;
52    }
53    return SUCCESS;
54  }
55
56  OUTCOME ReadExistingRecon::checkFile()
57  {
58    OUTCOME result=SUCCESS;
59    int exists,status=0;
60    std::string reconFile = this->itsCube->pars().outputReconFile();
61    DUCHAMPWARN("readReconCube", "Trying file " << reconFile );
62    fits_file_exists(reconFile.c_str(),&exists,&status);
63    if(exists<=0){
64      fits_report_error(stderr, status);
65      DUCHAMPERROR("readReconCube","ReconFile 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().setReconFile(reconFile);
73    }
74
75    this->itsFilename = reconFile;
76    return result;
77
78  }
79
80  OUTCOME ReadExistingRecon::checkHeaders()
81  {
82    OUTCOME result=SUCCESS;
83    if(this->itsFptr==0){
84      DUCHAMPERROR("readReconCube","FITS file not open");
85      result=FAILURE;
86    }
87    else{
88      unsigned int scaleMin;
89      int filterCode,reconDim;
90      float snrRecon;
91      char *comment = new char[80];
92      int status = 0;
93      fits_read_key(this->itsFptr, TINT, (char *)keyword_reconDim.c_str(),
94                    &reconDim, comment, &status);
95      if(reconDim != this->itsCube->pars().getReconDim()){
96        DUCHAMPERROR("readReconCube", "reconDim keyword in reconFile (" << reconDim << ") does not match that requested (" << this->itsCube->pars().getReconDim() << ").");
97        result = FAILURE;
98      }
99      status = 0;
100      fits_read_key(this->itsFptr, TINT, (char *)keyword_filterCode.c_str(),
101                    &filterCode, comment, &status);
102      if(filterCode != this->itsCube->pars().getFilterCode()){
103        DUCHAMPERROR("readReconCube", "filterCode keyword in reconFile (" << filterCode << ") does not match that requested (" << this->itsCube->pars().getFilterCode() << ").");
104        result = FAILURE;
105      }
106      status = 0;
107      fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_snrRecon.c_str(),
108                    &snrRecon, comment, &status);
109      if(snrRecon != this->itsCube->pars().getAtrousCut()){
110        DUCHAMPERROR("readReconCube", "snrRecon keyword in reconFile (" << snrRecon << ") does not match that requested (" << this->itsCube->pars().getAtrousCut() << ").");
111        result = FAILURE;
112      }
113      status = 0;
114      fits_read_key(this->itsFptr, TINT, (char *)keyword_scaleMin.c_str(),
115                    &scaleMin, comment, &status);
116      if(scaleMin != this->itsCube->pars().getMinScale()){
117        DUCHAMPERROR("readReconCube", "scaleMin keyword in reconFile (" << scaleMin << ") does not match that requested (" << this->itsCube->pars().getMinScale() << ").");
118        result = FAILURE;
119      }
120
121    }
122
123    return result;
124
125  }
126
127  OUTCOME ReadExistingRecon::readFromFile()
128  {
129    OUTCOME result = this->ReadExisting::readFromFile();
130    if(result == SUCCESS){
131      // We don't want to write out the recon or resid files at the end
132      this->itsCube->pars().setFlagOutputRecon(false);
133      this->itsCube->pars().setFlagOutputResid(false);
134    }
135    return result;
136  }
137
138
139}
Note: See TracBrowser for help on using the repository browser.