1 /*************************************************************************** 2 netcdf_source.h - netCDF data source reader 3 ------------------- 4 begin : 28/01/2005 5 copyright : (C) 2004 Nicolas Brisset <nicodev@users.sourceforge.net> 6 email : kst@kde.org 7 modified : 03/16/05 by K. Scott 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 #ifndef NETCDFSOURCE_H 20 #define NETCDFSOURCE_H 21 22 #include "datasource.h" 23 #include "dataplugin.h" 24 25 #include <netcdf.h> 26 #include <netcdfcpp.h> 27 28 29 class DataInterfaceNetCdfScalar; 30 class DataInterfaceNetCdfString; 31 class DataInterfaceNetCdfVector; 32 class DataInterfaceNetCdfMatrix; 33 34 class NetcdfSource : public Kst::DataSource { 35 public: 36 NetcdfSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement &element); 37 38 ~NetcdfSource(); 39 40 bool initFile(); 41 42 Kst::Object::UpdateType internalDataSourceUpdate(); 43 44 45 virtual const QString& typeString() const; 46 47 static const QString netcdfTypeKey(); 48 49 50 int readScalar(double *v, const QString& field); 51 52 int readString(QString *stringValue, const QString& stringName); 53 54 int readField(double *v, const QString& field, int s, int n); 55 56 int readMatrix(double *v, const QString& field); 57 58 int samplesPerFrame(const QString& field); 59 60 int frameCount(const QString& field = QString()) const; 61 62 QString fileType() const; 63 64 //void save(QTextStream &ts, const QString& indent = QString()); 65 66 bool isEmpty() const; 67 68 void reset(); 69 70 private: 71 QMap<QString, int> _frameCounts; 72 73 int _maxFrameCount; 74 NcFile *_ncfile; 75 76 // we must hold an NcError to overwrite the exit-on-error behaviour of netCDF 77 NcError _ncErr; 78 79 QMap<QString, QString> _strings; 80 81 // TODO remove friend 82 QStringList _scalarList; 83 QStringList _fieldList; 84 QStringList _matrixList; 85 //QStringList _stringList; 86 87 88 friend class DataInterfaceNetCdfScalar; 89 friend class DataInterfaceNetCdfString; 90 friend class DataInterfaceNetCdfVector; 91 friend class DataInterfaceNetCdfMatrix; 92 DataInterfaceNetCdfScalar* is; 93 DataInterfaceNetCdfString* it; 94 DataInterfaceNetCdfVector* iv; 95 DataInterfaceNetCdfMatrix* im; 96 }; 97 98 99 100 #endif 101 102