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