Why is ncread reading in times which are wrong by a year?
4 views (last 30 days)
I am getting the wrong year when I read in data from the file below using ncread.
url = 'http://nomads.ncep.noaa.gov:9090/dods/wave/wna/wna20150804/wna20150804_00z';
timeFromNetcdf = ncread(url, 'time');
You can see from the file name that the year is actually 2015 not 2014. Am I doing something wrong in ncread, perhaps due to the zero-based index in netcdf vs. one-based index in matlab, or is the time variable in the netcdf file simply wrong?
Kelly Kearney on 6 Aug 2015
Edited: Kelly Kearney on 6 Aug 2015
No, it's not a bug. Matlab datenumbers are defined as days since Jan 0, 0000. But if you look at the attributes for your time variable:
>> ncdisp(url, 'time')
time = 61
grads_dim = 't'
grads_mapping = 'linear'
grads_size = '61'
grads_min = '00z04aug2015'
grads_step = '3hr'
units = 'days since 1-1-1 00:00:0.0'
long_name = 'time'
minimum = '00z04aug2015'
maximum = '12z11aug2015'
resolution = 0.125
you'll see that the reference time for that variable is Jan 1, 0001. So the proper conversion is
t = ncread(url, 'time') + datenum(1,1,1);
(Though there seems to be a 2-day shift in there... if this is model data based on a 365-day year or something like that, then datenumbers may not be the best thing to use).
More Answers (1)
Rohit Kudva on 6 Aug 2015
I executed the code you provided and I was able to reproduce this issue. This seems to be a bug in MATLAB. I work for MathWorks and I have forwarded this feedback to the appropriate product team.