[3] | 1 | #include <iostream> |
---|
| 2 | #include <string> |
---|
[142] | 3 | #include <string.h> |
---|
[3] | 4 | #include <wcs.h> |
---|
| 5 | #include <wcshdr.h> |
---|
| 6 | #include <fitshdr.h> |
---|
| 7 | #include <wcsfix.h> |
---|
[103] | 8 | #include <wcsunits.h> |
---|
[142] | 9 | #define WCSLIB_GETWCSTAB // define this so that we don't try and redefine |
---|
| 10 | // wtbarr (this is a problem when using gcc v.4+ |
---|
[66] | 11 | #include <fitsio.h> |
---|
[69] | 12 | #include <math.h> |
---|
[71] | 13 | #include <duchamp.hh> |
---|
[3] | 14 | #include <Cubes/cubes.hh> |
---|
| 15 | |
---|
[71] | 16 | string imageType[4] = {"point", "spectrum", "image", "cube"}; |
---|
[3] | 17 | |
---|
| 18 | int Cube::getCube(string fname) |
---|
| 19 | { |
---|
| 20 | /** |
---|
| 21 | * Cube::getCube(string ) |
---|
| 22 | * Read in a cube from the file fname (assumed to be in FITS format). |
---|
| 23 | * Function reads in the following: |
---|
| 24 | * - axis dimensions |
---|
| 25 | * - pixel array |
---|
| 26 | * - WCS information (in form of WCSLIB wcsprm structure) |
---|
| 27 | * - Header keywords: BUNIT (brightness unit), |
---|
[142] | 28 | * BLANK, BZERO, BSCALE (for blank pixel value) |
---|
| 29 | * BMAJ, BMIN, CDELT1, CDELT2 (for beam size) |
---|
[3] | 30 | */ |
---|
| 31 | |
---|
| 32 | long nelements; |
---|
[71] | 33 | int bitpix,numAxes; |
---|
[3] | 34 | int status = 0, nkeys; /* MUST initialize status */ |
---|
| 35 | fitsfile *fptr; |
---|
| 36 | |
---|
[159] | 37 | status = 0; |
---|
[3] | 38 | if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){ |
---|
| 39 | fits_report_error(stderr, status); |
---|
| 40 | return FAILURE; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | status = 0; |
---|
[159] | 44 | if(fits_get_img_dim(fptr, &numAxes, &status)){ |
---|
[3] | 45 | fits_report_error(stderr, status); |
---|
| 46 | return FAILURE; |
---|
| 47 | } |
---|
[159] | 48 | long *dimAxes = new long[numAxes]; |
---|
| 49 | for(int i=0;i<numAxes;i++) dimAxes[i]=1; |
---|
| 50 | status = 0; |
---|
| 51 | if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){ |
---|
| 52 | fits_report_error(stderr, status); |
---|
| 53 | return FAILURE; |
---|
| 54 | } |
---|
[71] | 55 | status = 0; |
---|
[159] | 56 | fits_close_file(fptr, &status); |
---|
[3] | 57 | if (status){ |
---|
[159] | 58 | duchampWarning("getCube","Error closing file: "); |
---|
[3] | 59 | fits_report_error(stderr, status); |
---|
| 60 | } |
---|
| 61 | |
---|
[160] | 62 | if(numAxes<=3) std::cout << "Dimensions of FITS file: "; |
---|
| 63 | int dim = 0; |
---|
| 64 | std::cout << dimAxes[dim]; |
---|
| 65 | while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim]; |
---|
| 66 | std::cout << std::endl; |
---|
[103] | 67 | |
---|
[160] | 68 | delete [] dimAxes; |
---|
[3] | 69 | |
---|
[160] | 70 | this->head.defineWCS(fname, this->par); |
---|
[103] | 71 | |
---|
[160] | 72 | if(!this->head.isWCS()) |
---|
| 73 | duchampWarning("getCube","WCS is not good enough to be used.\n"); |
---|
[3] | 74 | |
---|
[160] | 75 | std::cerr << "Reading data ... "; |
---|
| 76 | this->getFITSdata(fname); |
---|
| 77 | std::cerr << "Done. Data array has dimensions: "; |
---|
| 78 | std::cerr << this->axisDim[0] <<"x" |
---|
| 79 | << this->axisDim[1] <<"x" |
---|
| 80 | << this->axisDim[2] << std::endl; |
---|
[46] | 81 | |
---|
[160] | 82 | this->head.readHeaderInfo(fname, this->par); |
---|
| 83 | this->par.copyHeaderInfo(this->head); |
---|
[3] | 84 | |
---|
[103] | 85 | return SUCCESS; |
---|
[3] | 86 | |
---|
| 87 | } |
---|
| 88 | |
---|