[71] | 1 | #include <iostream> |
---|
| 2 | #include <sstream> |
---|
| 3 | #include <string> |
---|
| 4 | #include <wcs.h> |
---|
| 5 | #include <wcshdr.h> |
---|
[99] | 6 | #define WCSLIB_GETWCSTAB // define this so that we don't try and redefine wtbarr |
---|
| 7 | // (this is a problem when using gcc v.4+ |
---|
[71] | 8 | #include <fitsio.h> |
---|
| 9 | #include <duchamp.hh> |
---|
| 10 | #include <Cubes/cubes.hh> |
---|
| 11 | |
---|
| 12 | int Cube::readReconCube() |
---|
| 13 | { |
---|
[86] | 14 | /** |
---|
| 15 | * Cube::readReconCube() |
---|
| 16 | * |
---|
| 17 | * A way to read in a previously reconstructed array, corresponding to the |
---|
| 18 | * requested parameters, or in the filename given by reconFile. |
---|
| 19 | * Performs various tests to make sure there are no clashes between the requested |
---|
| 20 | * parameters and those stored in the header of the FITS file. |
---|
| 21 | */ |
---|
[71] | 22 | |
---|
[86] | 23 | |
---|
[71] | 24 | fitsfile *fptr; |
---|
| 25 | int status = 0; |
---|
| 26 | |
---|
| 27 | // Check to see whether the parameters reconFile and/or residFile are defined. |
---|
| 28 | bool reconGood = false; |
---|
| 29 | bool residGood = false; |
---|
| 30 | int exists; |
---|
| 31 | if(this->par.getReconFile() != ""){ |
---|
| 32 | reconGood = true; |
---|
| 33 | fits_file_exists(this->par.getReconFile().c_str(),&exists,&status); |
---|
| 34 | if(exists<=0){ |
---|
| 35 | fits_report_error(stderr, status); |
---|
| 36 | std::cerr << |
---|
[95] | 37 | " WARNING <readReconCube> : Cannot find requested ReconFile. Trying with parameters.\n"; |
---|
[71] | 38 | std::cerr << |
---|
[95] | 39 | " Bad reconFile was: "<<this->par.getReconFile()<<std::endl; |
---|
[71] | 40 | reconGood = false; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | else{ |
---|
| 44 | std::cerr << |
---|
[95] | 45 | " WARNING <readReconCube> : ReconFile not specified. Working out name from parameters.\n"; |
---|
[71] | 46 | } |
---|
| 47 | |
---|
| 48 | if(!reconGood){ // if bad, need to look at parameters |
---|
| 49 | |
---|
[100] | 50 | string reconFile = this->par.outputReconFile(); |
---|
[95] | 51 | std::cerr << " : Trying file " << reconFile << std::endl; |
---|
[71] | 52 | reconGood = true; |
---|
| 53 | fits_file_exists(reconFile.c_str(),&exists,&status); |
---|
| 54 | if(exists<=0){ |
---|
| 55 | fits_report_error(stderr, status); |
---|
| 56 | std::cerr << |
---|
[95] | 57 | " WARNING <readReconCube> : ReconFile not present\n"; |
---|
[71] | 58 | reconGood = false; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if(reconGood){ // were able to open this file -- use this, so reset the relevant parameter |
---|
| 62 | this->par.setReconFile(reconFile); |
---|
| 63 | } |
---|
| 64 | else { // if STILL bad, give error message and exit. |
---|
[95] | 65 | std::cerr << " ERROR <readReconCube> : Cannot find reconstructed file.\n"; |
---|
[71] | 66 | return FAILURE; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // if we get to here, reconGood is true (ie. file is open); |
---|
| 72 | status=0; |
---|
| 73 | fits_open_file(&fptr,this->par.getReconFile().c_str(),READONLY,&status); |
---|
| 74 | short int maxdim=3; |
---|
| 75 | long *fpixel = new long[maxdim]; |
---|
| 76 | for(int i=0;i<maxdim;i++) fpixel[i]=1; |
---|
| 77 | long *dimAxesNew = new long[maxdim]; |
---|
| 78 | for(int i=0;i<maxdim;i++) dimAxesNew[i]=1; |
---|
| 79 | long nelements; |
---|
| 80 | int bitpix,numAxesNew,anynul; |
---|
| 81 | |
---|
| 82 | status = 0; |
---|
| 83 | fits_get_img_param(fptr, maxdim, &bitpix, &numAxesNew, dimAxesNew, &status); |
---|
| 84 | if(status){ |
---|
| 85 | fits_report_error(stderr, status); |
---|
| 86 | return FAILURE; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if(numAxesNew != this->numDim){ |
---|
[95] | 90 | std::cerr << " ERROR <readReconCube> : " |
---|
| 91 | << " Reconstructed cube has a different number of axes to original! (" |
---|
[71] | 92 | << numAxesNew << " cf. " << this->numDim << ")\n"; |
---|
| 93 | return FAILURE; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | for(int i=0;i<numAxesNew;i++){ |
---|
| 97 | if(dimAxesNew[i]!=this->axisDim[i]){ |
---|
[95] | 98 | std::cerr << " ERROR <readReconCube> : " |
---|
| 99 | << " Reconstructed cube has different axis dimensions to original!\n" |
---|
| 100 | << " Axis #" << i << " has size " << dimAxesNew[i] |
---|
| 101 | << " cf. " << this->axisDim[i] <<" in original.\n"; |
---|
[71] | 102 | return FAILURE; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | float *reconArray = new float[this->numPixels]; |
---|
| 107 | // fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, this->recon, &anynul, &status); |
---|
[96] | 108 | status = 0; |
---|
[71] | 109 | fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, reconArray, &anynul, &status); |
---|
| 110 | this->saveRecon(reconArray,this->numPixels); |
---|
| 111 | |
---|
[73] | 112 | if(!this->par.getFlagATrous()){ |
---|
| 113 | this->par.setFlagATrous(true); |
---|
[95] | 114 | std::cerr << " WARNING <readReconCube> : Setting flagAtrous from false to true, as the reconstruction exists.\n"; |
---|
[71] | 115 | } |
---|
| 116 | |
---|
[96] | 117 | status = 0; |
---|
[71] | 118 | fits_close_file(fptr, &status); |
---|
| 119 | if (status){ |
---|
[95] | 120 | std::cerr << " WARNING <readReconCube> : Error closing file: "; |
---|
[71] | 121 | fits_report_error(stderr, status); |
---|
| 122 | // return FAILURE; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | // We don't want to write out the recon or resid files at the end |
---|
| 126 | this->par.setFlagOutputRecon(false); |
---|
| 127 | this->par.setFlagOutputResid(false); |
---|
| 128 | |
---|
| 129 | // The reconstruction is done -- set the appropriate flag |
---|
| 130 | this->reconExists = true; |
---|
| 131 | |
---|
| 132 | return SUCCESS; |
---|
| 133 | } |
---|