source: trunk/src/FitsIO/ReadExistingRecon.cc @ 1133

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

Moving the code that reads from and writes to FITS files containing reconstructed, momentmap, mask etc arrays to the FitsIO directory, away from Cubes. Updating all include statements as well.

File size: 4.6 KB
Line 
1#include <duchamp/FitsIO/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=FAILURE;
59    int exists,status=0;
60    std::string reconFile = this->itsCube->pars().getReconFile();
61    if(reconFile != ""){
62      fits_file_exists(reconFile.c_str(),&exists,&status);
63      if(exists<=0){
64        fits_report_error(stderr, status);
65        DUCHAMPWARN("readReconCube", "Cannot find requested ReconFile. Trying with parameters. Bad reconFile was: "<<reconFile);
66      }
67      else result = SUCCESS;
68    }
69    else{
70      DUCHAMPWARN("readReconCube", "ReconFile not specified. Working out name from parameters.");
71
72      reconFile = this->itsCube->pars().outputReconFile();
73      DUCHAMPWARN("readReconCube", "Trying file " << reconFile );
74      fits_file_exists(reconFile.c_str(),&exists,&status);
75      if(exists<=0){
76        fits_report_error(stderr, status);
77        DUCHAMPERROR("readReconCube","ReconFile not present.");
78        result = FAILURE;
79      }
80      else result=SUCCESS;
81             
82      if(result==SUCCESS){
83        // were able to open this new file -- use this, so reset the
84        //  relevant parameter
85        this->itsCube->pars().setReconFile(reconFile);
86      }
87    }
88
89    this->itsFilename = reconFile;
90    return result;
91
92  }
93
94  OUTCOME ReadExistingRecon::checkHeaders()
95  {
96    OUTCOME result=SUCCESS;
97    if(this->itsFptr==0){
98      DUCHAMPERROR("readReconCube","FITS file not open");
99      result=FAILURE;
100    }
101    else{
102      unsigned int scaleMin;
103      int filterCode,reconDim;
104      float snrRecon;
105      char *comment = new char[80];
106      int status = 0;
107      fits_read_key(this->itsFptr, TINT, (char *)keyword_reconDim.c_str(),
108                    &reconDim, comment, &status);
109      if(reconDim != this->itsCube->pars().getReconDim()){
110        DUCHAMPERROR("readReconCube", "reconDim keyword in reconFile (" << reconDim << ") does not match that requested (" << this->itsCube->pars().getReconDim() << ").");
111        result = FAILURE;
112      }
113      status = 0;
114      fits_read_key(this->itsFptr, TINT, (char *)keyword_filterCode.c_str(),
115                    &filterCode, comment, &status);
116      if(filterCode != this->itsCube->pars().getFilterCode()){
117        DUCHAMPERROR("readReconCube", "filterCode keyword in reconFile (" << filterCode << ") does not match that requested (" << this->itsCube->pars().getFilterCode() << ").");
118        result = FAILURE;
119      }
120      status = 0;
121      fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_snrRecon.c_str(),
122                    &snrRecon, comment, &status);
123      if(snrRecon != this->itsCube->pars().getAtrousCut()){
124        DUCHAMPERROR("readReconCube", "snrRecon keyword in reconFile (" << snrRecon << ") does not match that requested (" << this->itsCube->pars().getAtrousCut() << ").");
125        result = FAILURE;
126      }
127      status = 0;
128      fits_read_key(this->itsFptr, TINT, (char *)keyword_scaleMin.c_str(),
129                    &scaleMin, comment, &status);
130      if(scaleMin != this->itsCube->pars().getMinScale()){
131        DUCHAMPERROR("readReconCube", "scaleMin keyword in reconFile (" << scaleMin << ") does not match that requested (" << this->itsCube->pars().getMinScale() << ").");
132        result = FAILURE;
133      }
134
135    }
136
137    return result;
138
139  }
140
141  OUTCOME ReadExistingRecon::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().setFlagOutputRecon(false);
147      this->itsCube->pars().setFlagOutputResid(false);
148    }
149    return result;
150  }
151
152
153}
Note: See TracBrowser for help on using the repository browser.