#include #include #include #include #include #include #include #include int Cube::readReconCube() { /** * Cube::readReconCube() * * A way to read in a previously reconstructed array, corresponding to the * requested parameters, or in the filename given by reconFile. * Performs various tests to make sure there are no clashes between the requested * parameters and those stored in the header of the FITS file. */ fitsfile *fptr; int status = 0; // Check to see whether the parameters reconFile and/or residFile are defined. bool reconGood = false; bool residGood = false; int exists; if(this->par.getReconFile() != ""){ reconGood = true; fits_file_exists(this->par.getReconFile().c_str(),&exists,&status); if(exists<=0){ fits_report_error(stderr, status); std::cerr << "WARNING : Cannot find requested ReconFile. Trying with parameters.\n"; std::cerr << " Bad reconFile was: "<par.getReconFile()< : ReconFile not specified. Working out name from parameters.\n"; } if(!reconGood){ // if bad, need to look at parameters string reconFile = this->par.getImageFile(); reconFile = reconFile.substr(0,reconFile.size()-5); // remove the ".fits" on the end. std::stringstream ss; ss << ".RECON"<par.getAtrousCut()<<".fits"; reconFile += ss.str(); reconGood = true; fits_file_exists(reconFile.c_str(),&exists,&status); if(exists<=0){ fits_report_error(stderr, status); std::cerr << "WARNING : ReconFile based on reconstruction parameters is not present\n"; std::cerr << " Looking for: "<par.getReconFile()<par.setReconFile(reconFile); } else { // if STILL bad, give error message and exit. std::cerr << "WARNING : Cannot find reconstructed file.\n"; return FAILURE; } } // if we get to here, reconGood is true (ie. file is open); status=0; fits_open_file(&fptr,this->par.getReconFile().c_str(),READONLY,&status); short int maxdim=3; long *fpixel = new long[maxdim]; for(int i=0;inumDim){ std::cerr << "ERROR : " << "Reconstructed cube has a different number of axes to original! (" << numAxesNew << " cf. " << this->numDim << ")\n"; return FAILURE; } for(int i=0;iaxisDim[i]){ std::cerr << "ERROR : " << "Reconstructed cube has different axis dimensions to original!\n" << " Axis #" << i << " has size " << dimAxesNew[i] << " cf. " << this->axisDim[i] <<" in original.\n"; return FAILURE; } } char *comment = new char[80]; int minMW; fits_read_key(fptr, TINT, (char *)keyword_minMW.c_str(), &minMW, comment, &status); if(minMW != this->par.getMinMW()){ std::cerr << "ERROR : Reconstructed cube has different minMW parameter to original!\n" << " Reconstructed cube has "<par.getMinMW() << " as requested.\n"; return FAILURE; } int maxMW; fits_read_key(fptr, TINT, (char *)keyword_maxMW.c_str(), &maxMW, comment, &status); if(maxMW != this->par.getMaxMW()){ std::cerr << "ERROR : Reconstructed cube has different maxMW parameter to original!\n" << " Reconstructed cube has "<par.getMaxMW() << " as requested.\n"; return FAILURE; } float *reconArray = new float[this->numPixels]; // fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, this->recon, &anynul, &status); fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, reconArray, &anynul, &status); this->saveRecon(reconArray,this->numPixels); // Make the a trous parameters match what the recon file has. int scaleMin,filterCode; float snrRecon; if(!this->par.getFlagATrous()){ this->par.setFlagATrous(true); std::cerr << "WARNING : Setting flagAtrous from false to true, as the reconstruction exists.\n"; } fits_read_key(fptr, TINT, (char *)keyword_scaleMin.c_str(), &scaleMin, comment, &status); if(scaleMin != this->par.getMinScale()){ this->par.setMinScale(scaleMin); std::cerr << "WARNING : Changing scaleMin parameter to match ReconFile.\n"; } fits_read_key(fptr, TINT, (char *)keyword_filterCode.c_str(), &filterCode, comment, &status); if(filterCode != this->par.getFilterCode()){ this->par.setFilterCode(filterCode); std::cerr << "WARNING : Changing filterCode parameter to match ReconFile.\n"; } fits_read_key(fptr, TFLOAT, (char *)keyword_snrRecon.c_str(), &snrRecon, comment, &status); if(snrRecon != this->par.getAtrousCut()){ this->par.setAtrousCut(snrRecon); std::cerr << "WARNING : Changing snrRecon parameter to match ReconFile.\n"; } fits_close_file(fptr, &status); if (status){ std::cerr << "WARNING : Error closing file: "; fits_report_error(stderr, status); // return FAILURE; } // We don't want to write out the recon or resid files at the end this->par.setFlagOutputRecon(false); this->par.setFlagOutputResid(false); // The reconstruction is done -- set the appropriate flag this->reconExists = true; return SUCCESS; }