MATLAB Answers

How to create a netcdf in matlab which can be read by grads without using descriptor file?

32 views (last 30 days)
UTKARSH VERMA
UTKARSH VERMA on 7 Jan 2021
Commented: UTKARSH VERMA on 28 Feb 2021
I have data containing lat, lon, time and precipitation values:
lat: 128*1double
lon 256*1double
time 3652*1double
pr 256*128*3652double
I have masked my original data and now I want to create netcdf file which has all the information of original files and most importantly it can be read by grads without the use of descriptor file.

Answers (1)

KSSV
KSSV on 26 Feb 2021
% nc filename to be written
file = 'myfile.nc' ;
%% Write lon and lat variables
% Get data
lon = 1:10 ;
lat = 1:10 ;
nx = length(lon) ;
nccreate(file,'lon','Dimensions',{'lon',1,nx},'DeflateLevel',7) ;
ny = length(lat) ;
nccreate(file,'lat','Dimensions',{'lat',1,ny},'DeflateLevel',7) ;
nccreate(file,'time','Dimensions',{'time',1,Inf},'DeflateLevel',7) ;
nccreate(file,'z','Dimensions',{'lon','lat','time'},'DeflateLevel',7) ;
for i = 1:10
ncwrite(file,'time',i,i) % write time
data = rand(10) ;
ncwrite(file,'z',data,[1,1,i]) ; % write 3D data
end
  1 Comment
UTKARSH VERMA
UTKARSH VERMA on 28 Feb 2021
Hi KSSV,
Thanks for replying.
I ran the above code and I tried to open the same file in Grads but it's not working.
Grads shows while opening the above generated nc file:
ga-> sdfopen myfile.nc
Scanning self-describing file: myfile.nc
gadsdf: SDF file has no discernable X coordinate.
To open this file with GrADS, use a descriptor file with an XDEF entry.
Documentation is at http://iges.org/grads/gadoc/SDFdescriptorfile.html
ga->
Can you suggest some changes or addition to above code?
Best,
Utkarsh

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by