[Kst] branches/work/kst/portto4/kst/src/datasources/netcdf
Nicolas Brisset
nicolas.brisset at eurocopter.com
Fri Nov 19 00:14:07 CET 2010
SVN commit 1198560 by brisset:
Add support for vector scalars and strings for netCDF. I can see scalars in the View->Scalars dialog and strings in the debugger
as well as in labels. We only need to upgrade a bit the View->Strings dialog and do the same for other primitives (matrices,
...) and it will start looking real good for that data source :-)
I am also wondering whether I have to explicitly delete the *att and *var objects created in those functions, or if they get
cleared as soon as we leave the scope. Please check because that would mean a memleak (I haven't done it for now).
M +40 -2 kstnetcdf.cpp
--- branches/work/kst/portto4/kst/src/datasources/netcdf/kstnetcdf.cpp #1198559:1198560
@@ -147,8 +147,8 @@
void setDataInfo(const QString&, const DataVector::DataInfo&) {}
// meta data
- QMap<QString, double> metaScalars(const QString&) { return QMap<QString, double>(); }
- QMap<QString, QString> metaStrings(const QString&) { return QMap<QString, QString>(); }
+ QMap<QString, double> metaScalars(const QString&);
+ QMap<QString, QString> metaStrings(const QString&);
private:
@@ -177,7 +177,45 @@
return netcdf._fieldList.contains( field );
}
+QMap<QString, double> DataInterfaceNetCdfVector::metaScalars(const QString& field)
+{
+ QMap<QString, double> fieldScalars;
+ NcVar *var = netcdf._ncfile->get_var(field.toLatin1().constData());
+ fieldScalars["NbAttributes"] = var->num_atts();
+ for (int i=0; i<var->num_atts(); ++i) {
+ NcAtt *att = var->get_att(i);
+ // Only handle char attributes as fieldStrings, the others as fieldScalars
+ if (att->type() == NC_BYTE || att->type() == NC_SHORT || att->type() == NC_INT
+ || att->type() == NC_LONG || att->type() == NC_FLOAT || att->type() == NC_DOUBLE) {
+ // Some attributes may have multiple values => load the first as is, and for the others
+ // add a -2, -3, etc... suffix as obviously we can have only one value per scalar.
+ // Do it in two steps to avoid a test in the loop while keeping a "clean" name for the first one
+ fieldScalars[QString(att->name())] = att->values()->as_double(0);
+ for (int j=1; j<att->values()->num(); ++j) {
+ fieldScalars[QString(att->name()) + QString("-") + QString::number(j+1)] = att->values()->as_double(j);
+ }
+ }
+ }
+ return fieldScalars;
+}
+QMap<QString, QString> DataInterfaceNetCdfVector::metaStrings(const QString& field)
+{
+ QMap<QString, QString> fieldStrings;
+ QString tmpString;
+ NcVar *var = netcdf._ncfile->get_var(field.toLatin1().constData());
+ for (int i=0; i<var->num_atts(); ++i) {
+ NcAtt *att = var->get_att(i);
+ // Only handle char/unspecified attributes as fieldStrings, the others as fieldScalars
+ if (att->type() == NC_CHAR || att->type() == NC_UNSPECIFIED) {
+ fieldStrings[att->name()] = QString(att->values()->as_string(0));
+ }
+ // qDebug() << att->name() << ": " << att->values()->num() << endl;
+ }
+ return fieldStrings;
+}
+
+
//
// Matrix interface
//
More information about the Kst
mailing list