@@ -137,6 +137,53 @@ int NetCDFFilter::endColumn() const {
137
137
return d->endColumn ;
138
138
}
139
139
140
+ QString NetCDFFilter::fileInfoString (const QString& fileName) {
141
+ DEBUG (" NetCDFFilter::fileInfoString()" );
142
+
143
+ QByteArray bafileName = fileName.toLatin1 ();
144
+ DEBUG (" fileName = " << bafileName.data ());
145
+
146
+ QString info;
147
+ #ifdef HAVE_NETCDF
148
+ int ncid, status;
149
+ status = nc_open (bafileName.data (), NC_NOWRITE, &ncid);
150
+ NetCDFFilterPrivate::handleError (status, " nc_open" );
151
+ if (status != NC_NOERR) {
152
+ DEBUG (" File error. Giving up" );
153
+ return QString ();
154
+ }
155
+
156
+ int ndims, nvars, nattr, uldid;
157
+ status = nc_inq (ncid, &ndims, &nvars, &nattr, &uldid);
158
+ NetCDFFilterPrivate::handleError (status, " nc_inq" );
159
+ DEBUG (" nattr/ndims/nvars = " << nattr << ' ' << ndims << ' ' << nvars);
160
+
161
+ if (status == NC_NOERR) {
162
+ info += i18n (" Number of global attributes: %1" , QString::number (nattr));
163
+ info += QLatin1String (" <br>" );
164
+ info += i18n (" Number of dimensions: %1" , QString::number (ndims));
165
+ info += QLatin1String (" <br>" );
166
+ info += i18n (" Number of variables: %1" , QString::number (nvars));
167
+ info += QLatin1String (" <br>" );
168
+
169
+ int format;
170
+ status = nc_inq_format (ncid, &format);
171
+ if (status == NC_NOERR)
172
+ info += i18n (" Format version: %1" , NetCDFFilterPrivate::translateFormat (format));
173
+ info += QLatin1String (" <br>" );
174
+
175
+ info += i18n (" Using library version %1" , QString (nc_inq_libvers ()));
176
+ } else {
177
+ info += i18n (" Error getting file info" );
178
+ }
179
+
180
+ status = ncclose (ncid);
181
+ NetCDFFilterPrivate::handleError (status, " nc_close" );
182
+ #endif
183
+
184
+ return info;
185
+ }
186
+
140
187
// #####################################################################
141
188
// ################### Private implementation ##########################
142
189
// #####################################################################
@@ -150,7 +197,7 @@ NetCDFFilterPrivate::NetCDFFilterPrivate(NetCDFFilter* owner) : q(owner) {
150
197
#ifdef HAVE_NETCDF
151
198
void NetCDFFilterPrivate::handleError (int err, const QString& function) {
152
199
if (err != NC_NOERR)
153
- qDebug () << " NETCDF ERROR:" << function << " () - " << nc_strerror (m_status );
200
+ qDebug () << " NETCDF ERROR:" << function << " () - " << nc_strerror (err );
154
201
}
155
202
156
203
QString NetCDFFilterPrivate::translateDataType (nc_type type) {
@@ -200,6 +247,27 @@ QString NetCDFFilterPrivate::translateDataType(nc_type type) {
200
247
return typeString;
201
248
}
202
249
250
+ QString NetCDFFilterPrivate::translateFormat (int format) {
251
+ QString formatString;
252
+
253
+ switch (format) {
254
+ case NC_FORMAT_CLASSIC:
255
+ formatString = " NC_FORMAT_CLASSIC" ;
256
+ break ;
257
+ case NC_FORMAT_64BIT:
258
+ formatString = " NC_FORMAT_64BIT" ;
259
+ break ;
260
+ case NC_FORMAT_NETCDF4:
261
+ formatString = " NC_FORMAT_NETCDF4" ;
262
+ break ;
263
+ case NC_FORMAT_NETCDF4_CLASSIC:
264
+ formatString = " NC_FORMAT_NETCDF4_CLASSIC" ;
265
+ break ;
266
+ }
267
+
268
+ return formatString;
269
+ }
270
+
203
271
QString NetCDFFilterPrivate::scanAttrs (int ncid, int varid, int attid, QTreeWidgetItem* parentItem) {
204
272
char name[NC_MAX_NAME + 1 ];
205
273
0 commit comments