フィルターのクリア

How to run netcdf.defVarFill for a variable defined as 'float'

1 回表示 (過去 30 日間)
Rafael
Rafael 2012 年 8 月 13 日
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

採用された回答

John
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));
  1 件のコメント
Rafael
Rafael 2012 年 8 月 13 日
That did the trick! Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by