Skip to content

ncplot reports incorrect number of points in variable statistics #2

@c-decicco

Description

@c-decicco

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

  1. Download and extract the test NetCDF file: test.zip
  2. Use ncdump to determine the size of the arrays contained in the file:
    ncdump -h test.nc
    Observe that the Time dimension is equal to 2007 and sps20 is equal to 20, and that the Time variable has dimension (Time) and THETA and WSPD have dimensions (Time, sps20). This means that the Time variable has 2007 points, and THETA and WSPD have 2007*20 = 40140 points.
  3. Open the test file in ncplot and plot the variables by selecting them in the 'Variable Selection' window:
    ncplot test.nc
  4. Select 'View' -> 'Statistics' from the main ncplot window.
  5. Observe that ncplot shows Time to have 2006 points (2007-1) and THETA and WSPD to 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions