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

0001 /***************************************************************************
0002                 netcdf_source.h  -  netCDF data source reader
0003                              -------------------
0004     begin                : 28/01/2005
0005     copyright            : (C) 2004 Nicolas Brisset <nicodev@users.sourceforge.net>
0006     email                : kst@kde.org
0007     modified             : 03/16/05 by K. Scott
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 #ifndef NETCDFSOURCE_H
0020 #define NETCDFSOURCE_H
0021 
0022 #include "datasource.h"
0023 #include "dataplugin.h"
0024 
0025 #include <netcdf.h>
0026 #include <netcdfcpp.h>
0027 
0028 
0029 class DataInterfaceNetCdfScalar;
0030 class DataInterfaceNetCdfString;
0031 class DataInterfaceNetCdfVector;
0032 class DataInterfaceNetCdfMatrix;
0033 
0034 class NetcdfSource : public Kst::DataSource {
0035   public:
0036     NetcdfSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement &element);
0037 
0038     ~NetcdfSource();
0039 
0040     bool initFile();
0041 
0042     Kst::Object::UpdateType internalDataSourceUpdate();
0043 
0044 
0045     virtual const QString& typeString() const;
0046 
0047     static const QString netcdfTypeKey();
0048 
0049 
0050     int readScalar(double *v, const QString& field);
0051 
0052     int readString(QString *stringValue, const QString& stringName);
0053 
0054     int readField(double *v, const QString& field, int s, int n);
0055 
0056     int readMatrix(double *v, const QString& field);
0057 
0058     int samplesPerFrame(const QString& field);
0059 
0060     int frameCount(const QString& field = QString()) const;
0061 
0062     QString fileType() const;
0063 
0064     //void save(QTextStream &ts, const QString& indent = QString());
0065 
0066     bool isEmpty() const;
0067 
0068     void  reset();
0069 
0070   private:
0071     QMap<QString, int> _frameCounts;
0072 
0073     int _maxFrameCount;
0074     NcFile *_ncfile;
0075 
0076     // we must hold an NcError to overwrite the exit-on-error behaviour of netCDF
0077     NcError _ncErr;
0078 
0079     QMap<QString, QString> _strings;
0080 
0081     // TODO remove friend
0082     QStringList _scalarList;
0083     QStringList _fieldList;
0084     QStringList _matrixList;
0085     //QStringList _stringList;
0086 
0087 
0088     friend class DataInterfaceNetCdfScalar;
0089     friend class DataInterfaceNetCdfString;
0090     friend class DataInterfaceNetCdfVector;
0091     friend class DataInterfaceNetCdfMatrix;
0092     DataInterfaceNetCdfScalar* is;
0093     DataInterfaceNetCdfString* it;
0094     DataInterfaceNetCdfVector* iv;
0095     DataInterfaceNetCdfMatrix* im;
0096 };
0097 
0098 
0099 
0100 #endif
0101