[Kst] extragear/graphics/kst/kst/datasources/fitsimage
Barth Netterfield
netterfield at astro.utoronto.ca
Fri Aug 26 02:41:50 CEST 2005
SVN commit 453375 by netterfield:
Attempt to get scaling and offsets correct from fits header
M +27 -8 fitsimage.cpp
--- trunk/extragear/graphics/kst/kst/datasources/fitsimage/fitsimage.cpp #453374:453375
@@ -19,6 +19,7 @@
#include <fitsio.h>
#include <stdio.h>
+#include <math.h>
FitsimageSource::FitsimageSource(KConfig *cfg, const QString& filename, const QString& type)
: KstDataSource(cfg, filename, type) {
@@ -109,7 +110,7 @@
long n_axes[2], fpixel[2] = {1, 1};
double nullval = 0;
long n_elements;
- int i, px, py, anynull;
+ int i, px, py, anynull, ni;
int y0, y1, x0, x1;
double *z;
int status = 0;
@@ -132,8 +133,9 @@
y0 = yStart;
y1 = yStart+yNumSteps;
- x0 = yStart;
+ x0 = xStart;
x1 = xStart+xNumSteps;
+ ni = xNumSteps*yNumSteps-1;
i=0;
@@ -141,19 +143,36 @@
if ( field=="M1" ) {
for ( px = xStart; px<x1; px++ ) {
for ( py=y1-1; py>=yStart; py-- ) {
- z[i] = buffer[px + py*n_axes[0]];
+ z[ni - i] = buffer[px + py*n_axes[0]];
i++;
}
}
}
free( buffer );
- // set the suggested matrix transform params: pixel index....
- data->xMin = x0;
- data->yMin = y0;
- data->xStepSize = 1;
- data->yStepSize = 1;
+ // set the suggested matrix transform params: pixel index....
+ double x, y, dx, dy, cx, cy;
+ fits_read_key(_fptr, TDOUBLE, "CRVAL1", &x, NULL, &status );
+ fits_read_key(_fptr, TDOUBLE, "CRVAL2", &y, NULL, &status );
+ fits_read_key(_fptr, TDOUBLE, "CDELT1", &dx, NULL, &status );
+ fits_read_key(_fptr, TDOUBLE, "CDELT2", &dy, NULL, &status );
+ fits_read_key(_fptr, TDOUBLE, "CRPIX1", &cx, NULL, &status );
+ fits_read_key(_fptr, TDOUBLE, "CRPIX2", &cy, NULL, &status );
+
+ if ( status ) {
+ data->xMin = x0;
+ data->yMin = y0;
+ data->xStepSize = 1;
+ data->yStepSize = 1;
+ } else {
+ dx = fabs( dx );
+ dy = fabs( dy );
+ data->xStepSize =dx;
+ data->yStepSize =dy;
+ data->xMin = x - cx*dx;
+ data->yMin = y - cy*dy;
+ }
return( i );
}
More information about the Kst
mailing list