[Kst] branches/work/kst/portto4/kst/src/datasources/netcdf

Peter Kümmel syntheticpp at yahoo.com
Sat Mar 27 21:17:05 CET 2010


SVN commit 1108100 by kuemmel:

add vector interface to netCDF data source. needs debugging-

 M  +70 -8     kstnetcdf.cpp  
 M  +5 -2      kstnetcdf.h  


--- branches/work/kst/portto4/kst/src/datasources/netcdf/kstnetcdf.cpp #1108099:1108100
@@ -32,10 +32,78 @@
 static const QString netCdfTypeString = I18N_NOOP("netCDF Files");
 
 
+
+//
+// Vector interface
+//
+
+class DataInterfaceNetCdf : public DataSource::DataInterface<DataVector>
+{
+public:
+  DataInterfaceNetCdf(NetcdfSource& s) : netcdf(s) {}
+
+  // read one element
+  int read(const QString&, const DataVector::Param&);
+
+  // named elements
+  QStringList list() const { return netcdf._fieldList; }
+  bool isListComplete() const { return true; }
+  bool isValid(const QString&) const;
+
+  // T specific
+  const DataVector::Optional optional(const QString&) const;
+  void setOptional(const QString&, const DataVector::Optional&) {}
+
+  // meta data
+  QMap<QString, double> metaScalars(const QString&) { return QMap<QString, double>(); }
+  QMap<QString, QString> metaStrings(const QString&) { return QMap<QString, QString>(); }
+
+
+private:
+  NetcdfSource& netcdf;
+};
+
+
+const DataVector::Optional DataInterfaceNetCdf::optional(const QString &field) const
+{
+  DataVector::Optional opt = {-1, -1, -1};
+  if (!netcdf._fieldList.contains(field))
+    return opt;
+
+  opt.samplesPerFrame = netcdf.samplesPerFrame(field);
+  opt.frameCount = netcdf.frameCount(field);
+  opt.vectorframeCount = -1;
+
+  return opt;
+}
+
+
+
+int DataInterfaceNetCdf::read(const QString& field, const DataVector::Param& p)
+{
+  return netcdf.readField(p.data, field, p.startingFrame, p.numberOfFrames);
+}
+
+
+bool DataInterfaceNetCdf::isValid(const QString& field) const
+{
+  return  netcdf._fieldList.contains( field );
+}
+
+
+
+
+//
+// NetcdfSource
+//
+
 NetcdfSource::NetcdfSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement &element) :
   Kst::DataSource(store, cfg, filename, type),
-  _ncfile(0L)
+  _ncfile(0L),
+  iv(new DataInterfaceNetCdf(*this))
 {
+  setInterface(iv);
+
   setUpdateType(None);
 
   if (!type.isEmpty() && type != "netCDF") {
@@ -50,7 +118,6 @@
 }
 
 
-
 NetcdfSource::~NetcdfSource() {
   delete _ncfile;
   _ncfile = 0L;
@@ -262,9 +329,6 @@
 
 
 
-bool NetcdfSource::isValidField(const QString& field) const {
-  return _fieldList.contains(field);
-}
 
 
 
@@ -365,8 +429,6 @@
   Q_UNUSED(type)
   QStringList stringList;
 
-  // TODO port
-
   return stringList;
 }
 
@@ -379,7 +441,7 @@
   Q_UNUSED(type)
 
   QStringList fieldList;
-  //TODO port
+
   return fieldList;
 }
 
--- branches/work/kst/portto4/kst/src/datasources/netcdf/kstnetcdf.h #1108099:1108100
@@ -26,6 +26,8 @@
 #include <netcdfcpp.h>
 
 
+class DataInterfaceNetCdf;
+
 class NetcdfSource : public Kst::DataSource {
   public:
     NetcdfSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement &element);
@@ -42,8 +44,6 @@
 
     int readField(double *v, const QString& field, int s, int n);
 
-    bool isValidField(const QString& field) const;
-
     int samplesPerFrame(const QString& field);
 
     int frameCount(const QString& field = QString::null) const;
@@ -64,6 +64,9 @@
 
     QMap<QString, QString> _metaData;
     QStringList _fieldList;
+
+    friend class DataInterfaceNetCdf;
+    DataInterfaceNetCdf* iv;
 };
 
 


More information about the Kst mailing list