Writing data to Netcdf File

6 views (last 30 days)
Andrew Goenner
Andrew Goenner on 13 Feb 2018
Hello
I'm trying to write data to a netcdf file I keep on getting
Error using netcdflib The NetCDF library encountered an error during execution of 'putVaraDouble' function - 'Start+count exceeds dimension bound (NC_EEDGE)'.
Error in netcdf.putVar (line 84) netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/write (line 831) netcdf.putVar(gid, varid,start, count, varData);
Error in ncwrite (line 75) ncObj.write(varName, varData, start, stride);
Error in testplot2 (line 205) ncwrite(file,'prob_5',rain5)
The file that I'm starting with is Netcdf with data from the HRRRe model. The data that I'm trying to add is precipitation values that have been interpolated at the 5% and 95% probability of occuring.
file='C:\Users\agoenner\Desktop\190-17-15-06.nc';
for i = 1:y
for j = 1:x % rain(row,col)
a = POPvalue0(i,j); % Matrix with probability of 0 rainfall occurring
b = precip12(i,j); % Matrix with probability of .5 inches of rainfall
c = precip25(i,j); % Matrix with probability of 1 inches of rainfall
d = precip50(i,j); % Matrix with probability of 1.5 inches of rainfall
e = precip76(i,j); % Matrix with probability of 2 inches of rainfall
f = POPvaluemax(i,j); % Matrix with 0 probability of any rainfall occurring
o = [a,b,c,d,e,f];
o = unique(o,'stable'); Interpolation
len = length(o);
if (len == 2)
p =[0 .5];
POPvalue5(i,j) = 0;
POPvalue95(i,j) = 0;
elseif (len == 3)
p = [0 .5 1];
POPvalue5(i,j) = interp1(o,p,y5,'pchip');
POPvalue95(i,j) = interp1(o,p,y95, 'pchip');
elseif (len == 4)
p = [0 .5 1 1.5];
POPvalue5(i,j) = interp1(o,p,y5, 'pchip');
POPvalue95(i,j) = interp1(o,p,y95, 'pchip');
elseif (len ==5)
p = [0 .5 1 1.5 2];
POPvalue5(i,j) = interp1(o,p,y5, 'pchip');
POPvalue95(i,j) = interp1(o,p,y95, 'pchip');
else
p = [0 .5 1 1.5 2 APCP];
POPvalue5(i,j) = interp1(o,p,y5, 'pchip');
POPvalue95(i,j) = interp1(o,p,y95, 'pchip');
end
end
end
rain5= POPvalue5;
rain95=POPvalue95;
rain5 = double(squeeze(rain5));
rain95 = double(squeeze(rain95));
end
ncdisp(file);
attrib = ncreadatt(file,'APCP_prob_GT_76D2_surface','level') Using Attributes from a different variable in the original file to assign them to prob_5
attrib2 = ncreadatt(file,'APCP_prob_GT_76D2_surface','coordinates');
attrib3 = ncreadatt(file,'APCP_prob_GT_76D2_surface','units')
attrib4 = ncreadatt(file,'APCP_prob_GT_76D2_surface','_FillValue')
nccreate(file,'prob_5','Datatype','single');
ncwrite(file,'prob_5',rain5) %Here is where I'm have the issue.
ncwriteatt(file,'prob_5','FillValue',attrib4)
ncwriteatt(file,'prob_5','short_name', 'prob_5')
ncwriteatt(file,'prob_5','long_name','The_amount_rainfall_at_5_percent')
ncwriteatt(file,'prob_5','level',attrib)
ncwriteatt(file,'prob_5','units',attrib3)
ncwriteatt(file,'prob_5','coordinates',attrib2)

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!