File indexing completed on 2025-01-05 04:12:04

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2014 Northwestern University                          *
0004  *                   nchapman@u.northwestern.edu                           *
0005  *                   g-novak@northwestern.edu                              *
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or modify  *
0008  *   it under the terms of the GNU General Public License as published by  *
0009  *   the Free Software Foundation; either version 2 of the License, or     *
0010  *   (at your option) any later version.                                   *
0011  *                                                                         *
0012  ***************************************************************************/
0013 
0014 
0015 #ifndef FITSTABLE_H
0016 #define FITSTABLE_H
0017 
0018 #include <datasource.h>
0019 #include <dataplugin.h>
0020 
0021 #include <fitsio.h>
0022 
0023 class DataInterfaceFitsTableScalar;
0024 class DataInterfaceFitsTableString;
0025 class DataInterfaceFitsTableVector;
0026 class DataInterfaceFitsTableMatrix;
0027 
0028 class FitsTableSource : public Kst::DataSource {
0029   Q_OBJECT
0030 
0031   public:
0032     FitsTableSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e);
0033 
0034     ~FitsTableSource();
0035 
0036     bool init();
0037     virtual void reset();
0038 
0039     Kst::Object::UpdateType internalDataSourceUpdate();
0040 
0041     int readScalar(double *v, const QString& field);
0042 
0043     int readString(QString *stringValue, const QString& stringName);
0044 
0045     int readField(double *v, const QString& field, int s, int n);
0046 
0047     int readMatrix(double *v, const QString& field);
0048 
0049     int samplesPerFrame(const QString& field);
0050     int frameCount(const QString& field = QString()) const;
0051     
0052     int validField(int typecode);
0053     
0054     QString fileType() const;
0055 
0056     void save(QXmlStreamWriter &streamWriter);
0057 
0058     class Config;
0059 
0060 
0061   private:
0062     QMap<QString, long> _frameCounts;
0063     long _maxFrameCount;
0064 
0065     // FITS file object
0066     fitsfile *_fptr;
0067     mutable Config *_config;
0068 
0069     // Primitive lists
0070     QMap<QString, QString> _strings; /* dictionary-like container of strings */
0071     QMap<QString, double> _scalars; /* dictionary-like container of scalars */
0072     QStringList _fieldList;  /* list of vector names */
0073     QStringList _matrixList; /* list of matrix names (not implemented) */
0074     
0075     QStringList _colName;  /* Name in FITS file of each item in _fieldList */
0076     QList<int> _colRepeat; /* FITS repeat count of each item in _fieldList */
0077     QList<int> _colType;   /* FITS typecode for each item in _fieldList */
0078     QList<int> _colOffset; /* Offset of data, useful when repeat > 1 */
0079     QList<int> tableHDU;   /* Array of HDU numbers with FITS tables */
0080     QList<int> tableRow;   /* number of rows for each HDU in tableHDU */ 
0081 
0082     friend class DataInterfaceFitsTableScalar;
0083     friend class DataInterfaceFitsTableString;
0084     friend class DataInterfaceFitsTableVector;
0085     friend class DataInterfaceFitsTableMatrix;
0086     DataInterfaceFitsTableScalar* is;
0087     DataInterfaceFitsTableString* it;
0088     DataInterfaceFitsTableVector* iv;
0089     DataInterfaceFitsTableMatrix* im;
0090 };
0091 
0092 
0093 class FitsTableSourcePlugin : public QObject, public Kst::DataSourcePluginInterface {
0094     Q_OBJECT
0095     Q_INTERFACES(Kst::DataSourcePluginInterface)
0096     Q_PLUGIN_METADATA(IID "com.kst.DataSourcePluginInterface/2.0")
0097   public:
0098     virtual ~FitsTableSourcePlugin() {}
0099 
0100     virtual QString pluginName() const;
0101     virtual QString pluginDescription() const;
0102 
0103     virtual bool hasConfigWidget() const { return false; }
0104 
0105     virtual Kst::DataSource *create(Kst::ObjectStore *store,
0106                                   QSettings *cfg,
0107                                   const QString &filename,
0108                                   const QString &type,
0109                                   const QDomElement &element) const;
0110 
0111     virtual QStringList matrixList(QSettings *cfg,
0112                                   const QString& filename,
0113                                   const QString& type,
0114                                   QString *typeSuggestion,
0115                                   bool *complete) const;
0116 
0117     virtual QStringList fieldList(QSettings *cfg,
0118                                   const QString& filename,
0119                                   const QString& type,
0120                                   QString *typeSuggestion,
0121                                   bool *complete) const;
0122 
0123     virtual QStringList scalarList(QSettings *cfg,
0124                                   const QString& filename,
0125                                   const QString& type,
0126                                   QString *typeSuggestion,
0127                                   bool *complete) const;
0128 
0129     virtual QStringList stringList(QSettings *cfg,
0130                                   const QString& filename,
0131                                   const QString& type,
0132                                   QString *typeSuggestion,
0133                                   bool *complete) const;
0134 
0135     virtual int understands(QSettings *cfg, const QString& filename) const;
0136 
0137     virtual bool supportsTime(QSettings *cfg, const QString& filename) const;
0138 
0139     virtual QStringList provides() const;
0140 
0141     virtual Kst::DataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const;
0142 };
0143 
0144 
0145 #endif
0146 // vim: ts=2 sw=2 et