File indexing completed on 2024-12-22 04:17:07

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 
0014 #ifndef PLANCKIDEF_H
0015 #define PLANCKIDEF_H
0016 
0017 #include <datasource.h>
0018 #include <dataplugin.h>
0019 #include <libcfitsio0/fitsio.h>
0020 
0021 typedef struct {
0022   QString file;
0023   double dTimeZero;
0024   double dTimeDelta;
0025   long frameLo;
0026   long frames;
0027 } folderField;
0028 
0029 typedef QList<folderField> fileList;
0030 
0031 typedef struct {
0032   QString basefile;
0033   int table;
0034   int column;
0035 } field;
0036 
0037 class PlanckIDEFSource : public Kst::DataSource {
0038   Q_OBJECT
0039 
0040   public:
0041     PlanckIDEFSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e);
0042 
0043     ~PlanckIDEFSource();
0044 
0045     bool init();
0046     bool reset();
0047 
0048     Kst::Object::UpdateType update();
0049 
0050     int readField(double *v, const QString &field, int s, int n);
0051     bool isValidField(const QString &field) const;
0052 
0053     int samplesPerFrame(const QString &field);
0054     int frameCount(const QString& field = QString::null) const;
0055     bool isEmpty() const;
0056     QString fileType() const;
0057 
0058     void save(QXmlStreamWriter &streamWriter);
0059     void parseProperties(QXmlStreamAttributes &properties);
0060 
0061     class Config;
0062 
0063     int readScalar(double &S, const QString& scalar);
0064     int readString(QString &S, const QString& string);
0065 
0066     static bool isValidFilename(const QString& filename, Config *config);
0067     static QString baseFilename(const QString& filename);
0068 
0069     static bool checkValidPlanckIDEFFile(const QString& filename, PlanckIDEFSource::Config *config);
0070     static bool checkValidPlanckIDEFFolder(const QString& filename);
0071 
0072     static QStringList fieldList(const QString& filename);
0073     static QStringList stringList(const QString& filename);
0074     static QStringList fieldListFromFile(const QString& filename);
0075     static QStringList stringListFromFile(const QString& filename);
0076     static QStringList fieldListFromFolder(const QString& filename);
0077     static QStringList stringListFromFolder(const QString& filename);
0078 
0079   private:
0080     bool initFile(const QString& filename);
0081     bool initFile();
0082     bool initFolderFile(const QString& filename, const QString& prefix, const QString& baseName);
0083     bool initFolder();
0084 
0085     void addToMetadata(fitsfile *ffits, int &iStatus);
0086     void addToFieldList(fitsfile *ffits, const int iNumCols, int &iStatus);
0087     void addToFieldList(fitsfile *ffits, const QString& prefix, const QString& baseName, const int iNumCols, int &iStatus);
0088 
0089     long getNumFrames(const QString& filename);
0090     static long getNumFrames(fitsfile* ffits, int iNumHeaderDataUnits);
0091     int readFileFrames(const QString& filename, field *fld, double *v, int s, int n);
0092     int readFolderFrames(field *fld, double *v, int s, int n);
0093 
0094     mutable Config *_config;
0095     friend class ConfigWidgetPlanckIDEF;
0096 
0097     QMap<QString, QString> _metaData;
0098     QMap<QString, field*> _fields;
0099     QMap<QString, fileList*> _basefiles;
0100     double _dTimeZero;
0101     double _dTimeDelta;
0102     bool _bHasTime;
0103     bool _first;
0104     bool _isSingleFile;
0105     int _numFrames;
0106     int _numCols;
0107 };
0108 
0109 
0110 class PlanckIDEFPlugin : public QObject, public Kst::DataSourcePluginInterface {
0111     Q_OBJECT
0112     Q_INTERFACES(Kst::DataSourcePluginInterface)
0113   public:
0114     virtual ~PlanckIDEFPlugin() {}
0115 
0116     virtual QString pluginName() const;
0117     virtual QString pluginDescription() const;
0118 
0119     virtual bool hasConfigWidget() const { return false; }
0120 
0121     virtual Kst::DataSource *create(Kst::ObjectStore *store,
0122                                   QSettings *cfg,
0123                                   const QString &filename,
0124                                   const QString &type,
0125                                   const QDomElement &element) const;
0126 
0127     virtual QStringList matrixList(QSettings *cfg,
0128                                   const QString& filename,
0129                                   const QString& type,
0130                                   QString *typeSuggestion,
0131                                   bool *complete) const;
0132 
0133     virtual QStringList fieldList(QSettings *cfg,
0134                                   const QString& filename,
0135                                   const QString& type,
0136                                   QString *typeSuggestion,
0137                                   bool *complete) const;
0138 
0139     virtual QStringList scalarList(QSettings *cfg,
0140                                   const QString& filename,
0141                                   const QString& type,
0142                                   QString *typeSuggestion,
0143                                   bool *complete) const;
0144 
0145     virtual QStringList stringList(QSettings *cfg,
0146                                   const QString& filename,
0147                                   const QString& type,
0148                                   QString *typeSuggestion,
0149                                   bool *complete) const;
0150 
0151     virtual int understands(QSettings *cfg, const QString& filename) const;
0152 
0153     virtual bool supportsTime(QSettings *cfg, const QString& filename) const;
0154 
0155     virtual QStringList provides() const;
0156 
0157     virtual Kst::DataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const;
0158 };
0159 
0160 
0161 #endif
0162 // vim: ts=2 sw=2 et