MATLAB Answers

0

How to write the Netcdf file including latitude, longitude and time.

Asked by Shakir Hussain on 15 Mar 2018
Latest activity Answered by KSSV
on 15 Mar 2018
I am not a native English speaker so ignore the language mistakes.
I have 2 variables along with lat, long and time, trying to write in a single nc file. The properties of data is lat 42*1 lon 42*1 time 1392*1 (year and month. i.d YYYYMM format) var1 75*42*1392 var 75*42*1392
I have tried as below ncid = netcdf.create('test.nc','CLASSIC_MODEL'); dim_lon = netcdf.defDim(ncid,'lon',75); dim_lat = netcdf.defDim(ncid,'lat',42); dim_time= netcdf.defDim(ncid,'time',1392); dim_var1= netcdf.defDim(ncid,'var1',75*42*1392); dim_var2= netcdf.defDim(ncid,'var2',75*42*1392);
var_lon = netcdf.defVar(ncid,'lon','single',dim_lon); var_lat = netcdf.defVar(ncid,'lat','single',dim_lat); var_ti = netcdf.defVar(ncid,'time','single',dim_time); var_var1 = netcdf.defVar(ncid,'var1','double',dim_var1); var_var2 = netcdf.defVar(ncid,'var2','double',dim_var2);
netcdf.putAtt(ncid,var_lon,'standard_name','longitude'); netcdf.putAtt(ncid,var_lon,'long_name','longitude'); netcdf.putAtt(ncid,var_lon,'units','degrees_east'); netcdf.putAtt(ncid,var_lon,'axis','X');
netcdf.putAtt(ncid,var_lat,'standard_name','latitude'); netcdf.putAtt(ncid,var_lat,'long_name','latitude'); netcdf.putAtt(ncid,var_lat,'units','degrees_north'); netcdf.putAtt(ncid,var_lat,'axis','Y');
netcdf.putAtt(ncid,var_var1,'standard_name','var1'); netcdf.putAtt(ncid,var_var1,'long_name','m_var1');
netcdf.putAtt(ncid,var_var2,'standard_name','var2'); netcdf.putAtt(ncid,var_var2,'long_name','x_var2');
netcdf.putAtt(ncid,var_ti,'standard_name','month'); netcdf.putAtt(ncid,var_ti,'units','month since 1901-01');
netcdf.putAtt(ncid,var_1392,'table','1392'); netcdf.putAtt(ncid,var_1392,'table','1392');
In the result of these line, I am getting the errors as Error using netcdflib The NetCDF library encountered an error during execution of 'create' function - 'No such file or directory (2)'.
Error in netcdf.create (line 53) ncid = netcdflib('create', filename, mode);

  0 Comments

Sign in to comment.

1 Answer

Answer by KSSV
on 15 Mar 2018

MATLAB has very simple netcdf interface......you need to know read about nccreate, ncwrite and ncwriteatt. Just with these three functions, you can create your netcdf file.
You may refer this link for code:

  0 Comments

Sign in to comment.