필터 지우기
필터 지우기

modifying the shape or dimension of the netcdf datafile

조회 수: 16 (최근 30일)
Aib E
Aib E 2018년 2월 19일
댓글: KSSV 2018년 2월 28일
a

답변 (1개)

KSSV
KSSV 2018년 2월 20일
You need not to use such complex netcdf functions......you can achieve what you want with very simple netcdf functions of MATLAB. You need to know about ncdisp, ncwrite, ncread and nccreate. Below I have given a code which writes the output for xc, yc and DEM into a netcdf file. You can follow the same for the other variables.
file1 = 'nc_input.nc' ;
file2 = 'nc_output.nc' ;
xc = ncread(file1,'xc') ; xc = xc(:) ;
yc = ncread(file1,'yc') ; yc = yc(:) ;
DEM = ncread(file1,'DEM') ; DEM = DEM(:) ;
%%Write
% xc
nccreate(file2,'xc','Dimensions',{'xc',1,length(xc)}) ;
ncwrite(file2,'xc',xc) ;
ncwriteatt(file2,'xc','long_name','longitude of grid cell center');
ncwriteatt(file2,'xc','units','degrees_east');
ncwriteatt(file2,'xc','bounds','xv');
% yc
nccreate(file2,'yc','Dimensions',{'yc',1,length(yc)}) ;
ncwrite(file2,'yc',yc) ;
ncwriteatt(file2,'yc','long_name','latitude of grid cell center');
ncwriteatt(file2,'yc','units','degrees_north');
ncwriteatt(file2,'yc','bounds','yv');
% Bathymetry
nccreate(file2,'DEM','Dimensions',{'DEM',1,length(DEM)}) ;
ncwrite(file2,'DEM',DEM) ;
ncwriteatt(file2,'DEM','long_name','Digital Elevation Model');
ncwriteatt(file2,'DEM','units','meters');
  댓글 수: 2
Aib E
Aib E 2018년 2월 20일
Thank you very much, KSSV. I tried the code as per your suggestion. Its still giving me the following error.
Error using nccreate (line 133)
'Xc' exists in file. Can not modify existing variables.
Error in re_re_reshape (line 9)
nccreate(file2,'Xc','Dimensions',{'Xc',1,length(Xc)});
Could you please let me know how I can resolve the error? Thank you
KSSV
KSSV 2018년 2월 28일
This means.......file is already created and present in the folder......you are trying to write xc which is already present in the file.....you delete the file created and run the code. Delete the file present in the folder, every time you run the code.

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

카테고리

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