[Kst] extragear/graphics/kst/src/datasources/lfiio
Andrew Walker
arwalker at sumusltd.com
Tue Feb 13 20:04:31 CET 2007
SVN commit 633305 by arwalker:
add support for metadata
M +86 -36 lfiio.cpp
M +1 -0 lfiio.h
--- trunk/extragear/graphics/kst/src/datasources/lfiio/lfiio.cpp #633304:633305
@@ -23,11 +23,15 @@
#include <fitsio.h>
#include <stdlib.h>
+#include "kststring.h"
+
#define TIME_FIELD "TIME"
LFIIOSource::LFIIOSource( KConfig *cfg, const QString& filename, const QString& type )
: KstDataSource( cfg, filename, type )
{
+ _first = true;
+
if( type.isEmpty( ) || type == "LFIIO" )
{
if( initFile( ) )
@@ -54,8 +58,54 @@
{
KstObject::UpdateType updateType;
bool bRetVal = false;
+ int iResult = 0;
_numFrames = 0;
+
+ //
+ // read the metadata
+ //
+ if( !_filename.isNull( ) && !_filename.isEmpty( ) )
+ {
+ QString str;
+ fitsfile* ffits;
+ int iStatus = 0;
+
+ if( _first )
+ {
+ iResult = fits_open_table( &ffits, _filename.ascii( ), READONLY, &iStatus );
+ if( iResult == 0 )
+ {
+ int keysexist;
+ int morekeys;
+
+ iResult = fits_get_hdrspace( ffits, &keysexist, &morekeys, &iStatus );
+ if( iResult == 0 )
+ {
+ char keyname[FLEN_KEYWORD];
+ char value[FLEN_VALUE];
+ char comment[FLEN_COMMENT];
+ int keynum;
+
+ for( keynum=1; keynum <= keysexist; ++keynum )
+ {
+ iResult = fits_read_keyn( ffits, keynum, keyname, value, comment, &iStatus );
+ if( iResult == 0 )
+ {
+ KstString *metaString;
+
+ str.sprintf( "%s %s", value, comment );
+ metaString = new KstString( KstObjectTag( keyname, tag() ), this, str );
+ _metaData.insert( keyname, metaString );
+ }
+ }
+
+ _first = false;
+ }
+ }
+ }
+ }
+
updateType = update( );
if( updateType == KstObject::UPDATE )
{
@@ -90,7 +140,7 @@
int i;
_valid = false;
-
+
if( !_filename.isNull( ) && !_filename.isEmpty( ) )
{
iResult = fits_open_table( &ffits, _filename.ascii( ), READONLY, &iStatus );
@@ -117,20 +167,20 @@
for( i=0; i<iNumCols; i++ )
{
iStatus = 0;
-
+
sprintf( charTemplate, "%d", i+1 );
iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
if( iResult == 0 )
{
int iOffset = i;
-
+
strName = charName;
//
// ensure that we don't add duplicates to the _fieldList...
//
while( _fieldList.findIndex( strName ) != -1 )
{
- strName = QString("%1[%2]").arg( charName ). arg( iOffset );
+ strName = QString("%1[%2]").arg( charName ).arg( iOffset );
iOffset++;
}
}
@@ -174,7 +224,7 @@
}
}
}
-
+
if( lNumFrames * lMaxRepeat != _numFrames )
{
_numCols = iNumCols;
@@ -343,7 +393,8 @@
int LFIIOSource::frameCount(const QString& field) const
{
- Q_UNUSED(field)
+ Q_UNUSED( field )
+
return _numFrames;
}
@@ -366,47 +417,46 @@
extern "C" {
-KstDataSource *create_lfiio( KConfig *cfg, const QString& filename, const QString& type )
-{
- return new LFIIOSource( cfg, filename, type );
-}
+ KstDataSource *create_lfiio( KConfig *cfg, const QString& filename, const QString& type )
+ {
+ return new LFIIOSource( cfg, filename, type );
+ }
-QStringList provides_lfiio( )
-{
- QStringList rc;
+ QStringList provides_lfiio( )
+ {
+ QStringList rc;
- rc += "LFIIO";
+ rc += "LFIIO";
- return rc;
-}
+ return rc;
+ }
-int understands_lfiio( KConfig*, const QString& filename )
-{
- fitsfile* ffits;
- int iStatus = 0;
- int iRetVal = 0;
-
- //
- // determine if it is a FITS file...
- //
- if( fits_open_table( &ffits, filename.ascii( ), READONLY, &iStatus ) == 0 )
+ int understands_lfiio( KConfig*, const QString& filename )
{
- fits_close_file( ffits, &iStatus );
+ fitsfile* ffits;
+ int iStatus = 0;
+ int iRetVal = 0;
- iRetVal = 99;
- }
- else
- {
//
- // failed to open the file, so we can't understand it...
+ // determine if it is a FITS file...
//
+ if( fits_open_table( &ffits, filename.ascii( ), READONLY, &iStatus ) == 0 )
+ {
+ fits_close_file( ffits, &iStatus );
+
+ iRetVal = 90;
+ }
+ else
+ {
+ //
+ // failed to open the file, so we can't understand it...
+ //
+ }
+
+ return iRetVal;
}
-
- return iRetVal;
}
-}
-
KST_KEY_DATASOURCE_PLUGIN(lfiio)
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/datasources/lfiio/lfiio.h #633304:633305
@@ -44,6 +44,7 @@
double _dTimeZero;
double _dTimeDelta;
bool _bHasTime;
+ bool _first;
int _numFrames;
int _numCols;
};
More information about the Kst
mailing list