필터 지우기
필터 지우기

Data not written correctly to netcdf file

조회 수: 2 (최근 30일)
Anna
Anna 2011년 10월 7일
Hello,
I am trying to create a netcdf file with variables 'latitude', 'longitude' and 'zeros' to create a map of the world. I want to create a 0.5 degree grid so my latitude and longitude vectors have lengths of 360 and 720, respectively. My code (below) runs fine but when it creates the variable 'zeros' it does not write any data (i.e. has a cell value of 9.9692100e+36) for rows 714 (columns 246-360) and 715-720 (all columns). This produces a stripe going across my map when I visualise the data. Do you have any idea why this might be happening?
ncid = netcdf.create('Annual.nc','NC_NOCLOBBER');
%Define dimensions
londimid = netcdf.defDim(ncid,'lon', 720);
latdimid = netcdf.defDim(ncid,'lat', 360);
%Define variables
latvarid=netcdf.defVar(ncid, 'lat', 'float', latdimid);
lonvarid=netcdf.defVar(ncid, 'lon', 'float', londimid);
zerosvarid=netcdf.defVar(ncid, 'zeros', 'float', [latdimid londimid]);
netcdf.endDef(ncid)
%Write data to variables
netcdf.putVar(ncid,lonvarid,longitude);
netcdf.putVar(ncid,latvarid,latitude);
netcdf.putVar(ncid, zerosvarid, zeros(360,720));

채택된 답변

Ashish Uthama
Ashish Uthama 2011년 10월 7일
Anna, the data might not get fully written unless you close the file. A call to close would flush out all the data to the file:
netcdf.close(ncid);
Of course, you would then have to use netcdf.open to open the file again for reading.
Aside, if you have the latest version, you could look at functions like nccreate, ncwrite and ncread which might make it easier to read and write netcdf data.
  댓글 수: 1
Anna
Anna 2011년 10월 10일
Problem solved, thanks very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by