File indexing completed on 2024-12-22 04:17:15
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 KST_HDF5_H 0015 #define KST_HDF5_H 0016 0017 #include <datasource.h> 0018 #include <dataplugin.h> 0019 0020 #include <QFileInfo> 0021 #include <hdf5/serial/H5Cpp.h> 0022 #include <exception> 0023 0024 #include "debug.h" 0025 0026 class DataInterfaceHDF5Vector; 0027 class DataInterfaceHDF5Scalar; 0028 class DataInterfaceHDF5Matrix; 0029 class DataInterfaceHDF5String; 0030 0031 class HDF5Source : public Kst::DataSource { 0032 Q_OBJECT 0033 0034 public: 0035 HDF5Source(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e); 0036 0037 //HDF5Source(HDF5Source& s); 0038 0039 ~HDF5Source(); 0040 0041 friend class DataInterfaceHDF5Vector; 0042 friend class DataInterfaceHDF5Matrix; 0043 friend class DataInterfaceHDF5Scalar; 0044 friend class DataInterfaceHDF5String; 0045 0046 bool init(); 0047 virtual void reset(); 0048 0049 Kst::Object::UpdateType internalDataSourceUpdate(); 0050 0051 QString fileType() const; 0052 0053 void save(QXmlStreamWriter &streamWriter); 0054 0055 class Config; 0056 0057 unsigned samplesPerFrame(const QString& field); 0058 0059 unsigned frameCount(const QString& field); 0060 0061 int readField(double *v, const QString& field, int start, int numFrames); 0062 0063 int readScalar(double& s, const QString& field); 0064 0065 int readMatrix(Kst::DataMatrix::ReadInfo& m, const QString& field); 0066 0067 int readString(QString &data, const QString& field); 0068 0069 private: 0070 mutable Config *_config; 0071 H5::H5File* _hdfFile; 0072 0073 static herr_t visitFunc(hid_t id, const char* name, const H5L_info_t* info, void* opData); 0074 static herr_t attrIterFunc(hid_t id, const char* name, const H5A_info_t* info, void* opData); 0075 QString _directoryName; 0076 0077 DataInterfaceHDF5Vector* iv; 0078 DataInterfaceHDF5Scalar* ix; 0079 DataInterfaceHDF5Matrix* im; 0080 DataInterfaceHDF5String* is; 0081 0082 QStringList _scalarList; 0083 QStringList _vectorList; 0084 QStringList _matrixList; 0085 QStringList _stringList; 0086 QStringList _fieldList; 0087 QStringList _indexList; 0088 QStringList _mpfList; //List of dim-3 objects that are a matrix per frame (mpf) 0089 //Not implemented yet but could be 0090 0091 bool _resetNeeded; 0092 0093 QVector<int> lengths; 0094 0095 }; 0096 0097 0098 class HDF5Plugin : public QObject, public Kst::DataSourcePluginInterface { 0099 Q_OBJECT 0100 Q_INTERFACES(Kst::DataSourcePluginInterface) 0101 Q_PLUGIN_METADATA(IID "com.kst.DataSourcePluginInterface/2.0") 0102 public: 0103 virtual ~HDF5Plugin() {} 0104 0105 virtual QString pluginName() const; 0106 virtual QString pluginDescription() const; 0107 0108 virtual bool hasConfigWidget() const { return false; } 0109 0110 virtual Kst::DataSource *create(Kst::ObjectStore *store, 0111 QSettings *cfg, 0112 const QString &filename, 0113 const QString &type, 0114 const QDomElement &element) const; 0115 0116 virtual QStringList matrixList(QSettings *cfg, 0117 const QString& filename, 0118 const QString& type, 0119 QString *typeSuggestion, 0120 bool *complete) const; 0121 0122 virtual QStringList fieldList(QSettings *cfg, 0123 const QString& filename, 0124 const QString& type, 0125 QString *typeSuggestion, 0126 bool *complete) const; 0127 0128 virtual QStringList scalarList(QSettings *cfg, 0129 const QString& filename, 0130 const QString& type, 0131 QString *typeSuggestion, 0132 bool *complete) const; 0133 0134 virtual QStringList stringList(QSettings *cfg, 0135 const QString& filename, 0136 const QString& type, 0137 QString *typeSuggestion, 0138 bool *complete) const; 0139 0140 virtual int understands(QSettings *cfg, const QString& filename) const; 0141 0142 virtual bool supportsTime(QSettings *cfg, const QString& filename) const; 0143 0144 virtual QStringList provides() const; 0145 0146 virtual Kst::DataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const; 0147 }; 0148 0149 0150 #endif 0151 // vim: ts=2 sw=2 et