How to run netcdf.defVarFill for a variable defined as 'float'
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am using Matlab 7.14.0.739 (R2012a) and I need to create forcing data for my model in NetCDF that should look something like this:
variables:
float T2D(Time, south_north, west_east) ;
T2D:layer_top = 0.f ;
T2D:layer_bottom = 0.1f ;
T2D:units = "K" ;
T2D:_FillValue = -1.e+36f ;
The NetCDF file is created like this:
ncid = netcdf.create(filenc,'NETCDF4');
... and this is how I am currently writing my Matlab script:
% Surface temperature
varid_t2d = netcdf.defVar(ncid,'T2D','float',dimid_west_east,dimid_south_north,dimid_Time]);
netcdf.putAtt(ncid,varid_t2d,'layer_top',0);
netcdf.putAtt(ncid,varid_t2d,'layer_bottom',0.1);
netcdf.putAtt(ncid,varid_t2d,'units','K');
netcdf.defVarFill(ncid,varid_t2d,false,-1.e+36);
This is the error message I get when running it:
Error using netcdflib
The fill value datatype class 'double' does not match the netCDF datatype for T2D.
Error in netcdf.defVarFill (line 32)
netcdflib('defVarFill',ncid,varid,noFillMode,fillvalue);
Error in noah2d_text_to_netcdf (line 164)
netcdf.defVarFill(ncid,varid_t2d,false,-1.e+36);
If I change "netcdf.defVar" line to 'double':
varid_t2d = netcdf.defVar(ncid,'T2D','double',...)]
the script runs fine!
Is there a way I can run "netcdf.defVarFill" for a variable which is originally defined as 'float'?
Thanks
댓글 수: 0
채택된 답변
John
2012년 8월 13일
If your netCDF variable is single precision, then your fill value must also be given as single precision, so
netcdf.defVarFill(ncid,varid_t2d,false,single(-1e+36));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 NetCDF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!