Borrar filtros
Borrar filtros

modifying the shape or dimension of the netcdf datafile

16 visualizaciones (últimos 30 días)
Aib E
Aib E el 19 de Feb. de 2018
Comentada: KSSV el 28 de Feb. de 2018
a

Respuestas (1)

KSSV
KSSV el 20 de Feb. de 2018
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 comentarios
Aib E
Aib E el 20 de Feb. de 2018
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 el 28 de Feb. de 2018
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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by