[Kst] branches/work/kst/1.6/kst/src/datasources/fitsimage

Andrew Walker arwalker at sumusltd.com
Wed Jan 16 21:00:50 CET 2008


SVN commit 762313 by arwalker:

format changes and ensure status equals zero before various FITS operations

 M  +34 -20    fitsimage.cpp  
 M  +1 -19     fitsimage.h  


--- branches/work/kst/1.6/kst/src/datasources/fitsimage/fitsimage.cpp #762312:762313
@@ -35,15 +35,19 @@
 
 
 FitsimageSource::~FitsimageSource() {
-  int status;
-  if ( _fptr )
+  int status = 0;
+
+  if ( _fptr ) {
     fits_close_file( _fptr, &status );
+  }
+
   _fptr = 0L;
 }
 
 
 bool FitsimageSource::reset() {
   init();
+
   return true;
 }
 
@@ -65,6 +69,7 @@
     fits_close_file( _fptr, &status );
     _fptr = 0L;
   }
+
   return false;
 }
 
@@ -84,11 +89,11 @@
   _frameCount = newNF;
 
   updateNumFramesScalar();
+
   return setLastUpdateResult(isnew ? KstObject::UPDATE : KstObject::NO_CHANGE);
 }
 
-bool FitsimageSource::matrixDimensions( const QString& matrix,
-                                           int* xDim, int* yDim) {
+bool FitsimageSource::matrixDimensions( const QString& matrix, int* xDim, int* yDim) {
   long n_axes[3];
   int status = 0;
 
@@ -98,10 +103,13 @@
 
   fits_get_img_size( _fptr,  2,  n_axes,  &status );
 
-  if ( status ) return false;
+  if ( status ) {
+    return false;
+  }
 
   *xDim = n_axes[0];
   *yDim = n_axes[1];
+
   return true;
 }
 
@@ -125,14 +133,16 @@
 
   fits_get_img_size( _fptr,  2,  n_axes,  &status );
 
-  if ( status ) return false;
+  if ( status ) {
+    return false;
+  }
 
   n_elements = n_axes[0]*n_axes[1];
   buffer = ( double * )malloc( n_elements*sizeof( double ) );
 
   fits_read_pix( _fptr,  TDOUBLE, fpixel, n_elements,
                  &nullval, buffer, &anynull,  &status );
-  
+
   // Check to see if the file is using the BLANK keyword
   // to indicate the NULL value for the image.  This is
   // not correct useage for floating point images, but 
@@ -156,7 +166,7 @@
   x1 = xStart+xNumSteps;
   ni = xNumSteps*yNumSteps-1;
 
-  i=0;
+  i = 0;
 
   z = data->z;
   if ( field=="1" ) {
@@ -182,13 +192,13 @@
   if ( status ) {
     data->xMin = x0;
     data->yMin = y0;
-    data->xStepSize = 1;
-    data->yStepSize = 1;
+    data->xStepSize = 1.0;
+    data->yStepSize = 1.0;
   } else {
     dx = fabs( dx );
     dy = fabs( dy );
-    data->xStepSize =dx;
-    data->yStepSize =dy;
+    data->xStepSize = dx;
+    data->yStepSize = dy;
     data->xMin = x - cx*dx;
     data->yMin = y - cy*dy;
   }
@@ -196,7 +206,7 @@
 }
 
 int FitsimageSource::readField(double *v, const QString& field, int s, int n) {
-  int i=0;
+  int i = 0;
 
   if ( !_matrixList.contains( field ) ) {
     return false;
@@ -231,21 +241,23 @@
 
 
 bool FitsimageSource::isValidField(const QString& field) const {
-  return  _fieldList.contains( field );
+  return _fieldList.contains( field );
 }
 
 bool FitsimageSource::isValidMatrix(const QString& field) const {
-  return  _matrixList.contains( field );
+  return _matrixList.contains( field );
 }
 
 int FitsimageSource::samplesPerFrame(const QString &field) {
   Q_UNUSED(field)
+
   return 1;
 }
 
 
 int FitsimageSource::frameCount(const QString& field) const {
   Q_UNUSED(field)
+
   return _frameCount;
 }
 
@@ -264,7 +276,6 @@
   KstDataSource::save(ts, indent);
 }
 
-//#include <kdebug.h>
 
 extern "C" {
 KstDataSource *create_fitsimage(KConfig *cfg, const QString& filename, const QString& type) {
@@ -273,7 +284,9 @@
 
 QStringList provides_fitsimage() {
   QStringList rc;
+
   rc += "FITS Image";
+
   return rc;
 }
 
@@ -287,12 +300,14 @@
   fits_open_image( &ffits, filename.latin1( ), READONLY, &status );
   fits_get_img_dim( ffits, &naxis,  &status);
 
-  if( ( status == 0 ) && ( naxis>1 ) )
+  if( status == 0 && naxis > 1 ) {
     ret_val = 95;
-  else
+  } else {
     ret_val = 0;
+  }
 
-  // status !=0 should prevent close from having trouble...
+  status = 0;
+
   fits_close_file( ffits ,  &status );
 
   return ret_val;
@@ -321,4 +336,3 @@
 
 KST_KEY_DATASOURCE_PLUGIN(fitsimage)
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/datasources/fitsimage/fitsimage.h #762312:762313
@@ -25,37 +25,20 @@
 class FitsimageSource : public KstDataSource {
   public:
     FitsimageSource(KConfig *cfg, const QString& filename, const QString& type);
-
     ~FitsimageSource();
 
     bool init();
-
     KstObject::UpdateType update(int = -1);
-
     int readField(double *v, const QString &field, int s, int n);
-
-    int readMatrix(KstMatrixData* data, const QString& matrix, int xStart,
-                   int yStart, int xNumSteps, int yNumSteps);
-/*     int readMatrix(KstMatrixData* data, const QString& matrix, int xStart, */
-/*                    int yStart, int xNumSteps, int yNumSteps, int skip); */
-
-    
+    int readMatrix(KstMatrixData* data, const QString& matrix, int xStart, int yStart, int xNumSteps, int yNumSteps);
     bool isValidField(const QString &field) const;
-
     bool isValidMatrix(const QString& field) const;
-
     bool matrixDimensions( const QString& matrix, int* xDim, int* yDim);
-
     int samplesPerFrame(const QString &field);
-
     int frameCount(const QString& field = QString::null) const;
-
     QString fileType() const;
-
     void save(QTextStream &ts, const QString& indent = QString::null);
-
     bool isEmpty() const;
-
     bool reset();
 
   private:
@@ -65,4 +48,3 @@
 
 
 #endif
-// vim: ts=2 sw=2 et


More information about the Kst mailing list