1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | #define WCSLIB_GETWCSTAB // define this so that we don't try and redefine |
---|
4 | // wtbarr (this is a problem when using gcc v.4+ |
---|
5 | #include <fitsio.h> |
---|
6 | #include <math.h> |
---|
7 | #include <duchamp.hh> |
---|
8 | #include <Cubes/cubes.hh> |
---|
9 | |
---|
10 | int Cube::getFITSdata(string fname) |
---|
11 | { |
---|
12 | |
---|
13 | long nelements; |
---|
14 | int bitpix,numAxes; |
---|
15 | int status = 0, nkeys; /* MUST initialize status */ |
---|
16 | fitsfile *fptr; |
---|
17 | |
---|
18 | status = 0; |
---|
19 | if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){ |
---|
20 | fits_report_error(stderr, status); |
---|
21 | return FAILURE; |
---|
22 | } |
---|
23 | status = 0; |
---|
24 | if(fits_get_img_dim(fptr, &numAxes, &status)){ |
---|
25 | fits_report_error(stderr, status); |
---|
26 | return FAILURE; |
---|
27 | } |
---|
28 | long *dimAxes = new long[numAxes]; |
---|
29 | for(int i=0;i<numAxes;i++) dimAxes[i]=1; |
---|
30 | status = 0; |
---|
31 | if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){ |
---|
32 | fits_report_error(stderr, status); |
---|
33 | return FAILURE; |
---|
34 | } |
---|
35 | |
---|
36 | int lng = this->head.getWCS()->lng; |
---|
37 | int lat = this->head.getWCS()->lat; |
---|
38 | int spc = this->head.getWCS()->spec; |
---|
39 | |
---|
40 | int anynul; |
---|
41 | int npix = dimAxes[lng]*dimAxes[lat]*dimAxes[spc]; |
---|
42 | float *array = new float[npix]; |
---|
43 | char *nullarray = new char[npix]; |
---|
44 | long *fpixel = new long[numAxes]; |
---|
45 | long *lpixel = new long[numAxes]; |
---|
46 | long *inc = new long[numAxes]; // the data-sampling increment |
---|
47 | for(int i=0;i<numAxes;i++){ |
---|
48 | inc[i] = fpixel[i] = lpixel[i] = 1; |
---|
49 | } |
---|
50 | lpixel[lng] = dimAxes[lng]; |
---|
51 | lpixel[lat] = dimAxes[lat]; |
---|
52 | lpixel[spc] = dimAxes[spc]; |
---|
53 | |
---|
54 | int colnum = 0; |
---|
55 | status = 0; |
---|
56 | if(fits_read_subsetnull_flt(fptr, colnum, numAxes, dimAxes, |
---|
57 | fpixel, lpixel, inc, |
---|
58 | array, nullarray, &anynul, &status)){ |
---|
59 | duchampError("getFITSdata", |
---|
60 | "There was an error reading in the data array:"); |
---|
61 | fits_report_error(stderr, status); |
---|
62 | return FAILURE; |
---|
63 | } |
---|
64 | |
---|
65 | if(anynul==0){ |
---|
66 | // no blank pixels, so don't bother with any trimming or checking... |
---|
67 | if(this->par.getFlagBlankPix()) { |
---|
68 | // if user requested fixing, inform them of change. |
---|
69 | duchampWarning("getFITSdata", |
---|
70 | "No blank pixels, so setting flagBlankPix to false.\n"); |
---|
71 | } |
---|
72 | this->par.setFlagBlankPix(false); |
---|
73 | } |
---|
74 | |
---|
75 | this->initialiseCube(dimAxes); |
---|
76 | this->saveArray(array,npix); |
---|
77 | //------------------------------------------------------------- |
---|
78 | // Once the array is saved, change the value of the blank pixels from |
---|
79 | // 0 (as they are set by fits_read_pixnull) to the correct blank value |
---|
80 | // as determined by the above code. |
---|
81 | for(int i=0; i<npix;i++){ |
---|
82 | // if(nullarray[i]==1) this->array[i] = blank*bscale + bzero; |
---|
83 | if(isnan(array[i])) this->array[i] = par.getBlankPixVal(); |
---|
84 | if(nullarray[i]==1) this->array[i] = this->par.getBlankPixVal(); |
---|
85 | } |
---|
86 | |
---|
87 | return SUCCESS; |
---|
88 | |
---|
89 | } |
---|