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

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

Ticket #164: Getting the filename checking correct for the reading of existing cubes.

File size: 4.8 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=FAILURE;
59    int exists,status=0;
60    if(this->par.getSmoothFile() != ""){
61      fits_file_exists(this->par.getSmoothFile().c_str(),&exists,&status);
62      if(exists<=0){
63        fits_report_error(stderr, status);
64        DUCHAMPWARN("readSmoothCube", "Cannot find requested SmoothFile. Trying with parameters. Bad smoothFile was: "<<this->par.getSmoothFile());
65      }
66      else result = SUCCESS;
67    }
68    else{
69      DUCHAMPWARN("readSmoothCube", "SmoothFile not specified. Working out name from parameters.");
70
71      std::string smoothFile = this->itsCube->pars().outputSmoothFile();
72      DUCHAMPWARN("readSmoothCube", "Trying file " << smoothFile );
73      fits_file_exists(smoothFile.c_str(),&exists,&status);
74      if(exists<=0){
75        fits_report_error(stderr, status);
76        DUCHAMPERROR("readSmoothCube","SmoothFile not present.");
77        result = FAILURE;
78      }
79      else result=SUCCESS;
80             
81      if(result==SUCCESS){
82        // were able to open this new file -- use this, so reset the
83        //  relevant parameter
84        this->itsCube->pars().setSmoothFile(smoothFile);
85      }
86    }
87
88    this->itsFilename = smoothFile;
89    return result;
90  }
91
92  OUTCOME ReadExistingSmooth::checkHeaders()
93  {
94    OUTCOME result=SUCCESS;
95    if(this->itsFptr==0){
96      DUCHAMPERROR("readSmoothCube","FITS file not open");
97      result=FAILURE;
98    }
99    else{
100
101      int status = 0;
102      char *comment = new char[80];
103
104      if(this->itsCube->pars().getSmoothType()=="spectral"){
105
106        int hannWidth;
107        fits_read_key(this->itsFptr, TINT, (char *)keyword_hanningwidth.c_str(),
108                      &hannWidth, comment, &status);
109        if(hannWidth != this->itsCube->pars().getHanningWidth()){
110          DUCHAMPERROR("readSmoothCube", keyword_hanningwidth << " keyword in smoothFile (" << hannWidth << ") does not match the hanningWidth parameter (" << this->itsCube->pars().getHanningWidth() << ").");
111          result = FAILURE;
112        }
113
114      }
115      else if(this->itsCube->pars().getSmoothType()=="spatial"){
116
117        float maj,min,pa;
118        status = 0;
119        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernmaj.c_str(),
120                      &maj, comment, &status);
121        if(maj != this->itsCube->pars().getKernMaj()){
122          DUCHAMPERROR("readSmoothCube", keyword_kernmaj << " keyword in smoothFile (" << maj << ") does not match the kernMaj parameter (" << this->itsCube->pars().getKernMaj() << ").");
123          result = FAILURE;
124        }
125        status = 0;
126        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernmin.c_str(),
127                      &min, comment, &status);
128        if(min != this->itsCube->pars().getKernMin()){
129          DUCHAMPERROR("readSmoothCube", keyword_kernmin << " keyword in smoothFile (" << maj << ") does not match the kernMin parameter (" << this->itsCube->pars().getKernMin() << ").");
130          result = FAILURE;
131        }
132        status = 0;
133        fits_read_key(this->itsFptr, TFLOAT, (char *)keyword_kernpa.c_str(),
134                      &pa, comment, &status);
135        if(pa != this->itsCube->pars().getKernPA()){
136          DUCHAMPERROR("readSmoothCube", keyword_kernpa << " keyword in smoothFile (" << maj << ") does not match the kernPA parameter (" << this->itsCube->pars().getKernPA() << ").");
137          result = FAILURE;
138        }
139
140      }
141
142    }
143
144    if(result==FAILURE){
145      DUCHAMPERROR("readSmoothCube","Header keyword mismatch - not reading smoothed array from " << this->itsFilename);
146    }
147
148
149    return result;
150
151  }
152
153  OUTCOME ReadExistingSmooth::readFromFile()
154  {
155    OUTCOME result = this->ReadExisting::readFromFile();
156    if(result == SUCCESS){
157      // We don't want to write out the smooth file at the end
158      this->itsCube->pars().setFlagOutputSmooth(false);
159    }
160    return result;
161  }
162
163
164}
Note: See TracBrowser for help on using the repository browser.