Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Rafael
Rafael le 13 Août 2012
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

Réponse acceptée

John
John le 13 Août 2012
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));

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by