-
Couldn't load subscription status.
- Fork 1
Description
Issue
The 'Data Set Statistics' window displays an incorrect number of points ('nPoints') for variables in a dataset. Specifically, if the variable is one-dimensional, the number of points displayed will be one less than the actual number present; if a HRT variable is viewed, the number of points shown will be less than the actual number by the sampling rate.
Steps to reproduce
- Download and extract the test NetCDF file: test.zip
- Use ncdump to determine the size of the arrays contained in the file:
ncdump -h test.nc
Observe that theTimedimension is equal to 2007 andsps20is equal to 20, and that theTimevariable has dimension(Time)andTHETAandWSPDhave dimensions(Time, sps20). This means that theTimevariable has 2007 points, andTHETAandWSPDhave 2007*20 = 40140 points. - Open the test file in ncplot and plot the variables by selecting them in the 'Variable Selection' window:
ncplot test.nc - Select 'View' -> 'Statistics' from the main ncplot window.
- Observe that ncplot shows
Timeto have 2006 points (2007-1) andTHETAandWSPDto have 40120 (40140-20) points.
I suspect also that the statistics that are shown do not factor in the last "row" of datapoints (see 'Cause' section below).
Cause
Statistics are printed in the PrintStats function in stats.c. This function uses the nPoints member of a DATASET_INFO structure set to print the number of points. As well, the ComputeStats() function in stats.c uses the same nPoints member as the upper bound on loops in which it computes statistics.
The nPoints member of set is initialized in readSet() in dataIO.c (called upon viewing a variable) from NumberSeconds:
count[0] = set->nPoints = NumberSeconds / file->baseDataRate;
NumberSeconds is itself initialized as
NumberSeconds = UserEndTime[3] - UserStartTime[3];
on line 116 of dataIO.c in NewDataFile().
The mistake appears to be in computing NumberSeconds; NumberSeconds is off by one in that it doesn't include the last second in the computation. This computation should perhaps be
NumberSeconds = UserEndTime[3] - UserStartTime[3] + 1;
however, I am not certain if this will break other parts of the program.