[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #SQZ-618269]: ncdump and C_format attribute



Hi Chris,

> I am having issues with viewing a particular variable in a netCDF file when I
> use ncdump.  The file contains variable attributes C_format and F_format for
> each variable.  All of the values are listed as DOUBLE and the mentioned
> attributes define them as a FLOAT (f), however one of the variable's 
> attributes
> list it as an INTEGER (d).  So all of the variables are translated properly
> except for the variable defined as an INTEGER.  Now, the variable is water 
> depth
> and should read: 1, 2, 3, ..... 900.  However the data displayed are: 2,  32,
> 32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32, 32, 4225076,  31,  32,
> 32,  32,  32,  32,  32,  32,  32,  32,  32,  32,...
> However, when I dump the file in Matlab, the depth variable is translated
> accurately.
> 
> I did some searching around on the web, but was unable to identify this issue.
> Could you please help me.  I have added the .nc file and the .cdl file I 
> dumped out.

Yes, the C_format attribute is intended to be used to control the
precision with which a floating point value is printed.  It does not
provide a conversion service from floating point to integer, for
example.  So using 

> depth:C_format = "%3d" ;

when depth is a double-precision variable doesn't work, as it just
does the same thing that a C program would do if the function

  printf("$3d", double_val);

were called, printing a double value using an integer format
specifier, which is not useful and not what you intend.  Our 
documentation should be clearer on this attribute.

If you know the value of the depths are actually all integers,
represented as double precision floating point values, then you don't
need to specify a C_format attribute for depth, and the values will be
printed out as

 depth = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
  ...
    891, 892, 893, 894, 895, 896, 897, 898, 899, 900 ;

for example, because ncdump doesn't print unnecessary precision or
trailing zeros in fractional values.

You could get the same effect with

  depth:C_format = "%3.0f" ;

for example, to specify that no fractional part should be printed, but
it's not necessary because that's what ncdump as a default.

By the way, your use of the global attribute

> :_FillValue = -9990. ;

will also not work as intended, and will be flagged as a syntax error by
ncgen, because _FillValue must be defined separately for each variable.  No
meaning is currently defined for a global _FillValue attribute.  If all
variables were of the same type, it might be useful to have variables
inherit the fill value, but we haven't implemented such a convention.

--Russ

> netcdf xbt_07 {
> dimensions:
> position = 89 ;
> depth = 901 ;
> variables:
> double latitude(position) ;
> latitude:name = "latitude" ;
> latitude:standard_name = "latitude" ;
> latitude:long_name = "latitude of xbt drop" ;
> latitude:units = "degree_north" ;
> latitude:data_min = 4.158 ;
> latitude:data_max = 20.4726666666667 ;
> latitude:C_format = "%8.4f" ;
> latitude:F_format = "f8.4" ;
> latitude:epic_code = 500. ;
> double longitude(position) ;
> longitude:name = "longitude" ;
> longitude:standard_name = "longitude" ;
> longitude:long_name = "longitude of xbt drop" ;
> longitude:units = "degree_east" ;
> longitude:data_min = -55.795 ;
> longitude:data_max = -22.7333333333333 ;
> longitude:C_format = "%8.4f" ;
> longitude:F_format = "f8.4" ;
> longitude:epic_code = 502. ;
> double depth(depth) ;
> depth:name = "z" ;
> depth:standard_name = "z" ;
> depth:long_name = "depth of xbt temp measurement" ;
> depth:units = "meters" ;
> depth:data_min = 0. ;
> depth:data_max = 900. ;
> depth:C_format = "%3d" ;
> depth:F_format = "d3" ;
> depth:epic_code = 3. ;
> double temperature(depth, position) ;
> temperature:name = "temp" ;
> temperature:standard_name = "sea_water_temperature" ;
> temperature:long_name = "temperature" ;
> temperature:units = "degC" ;
> temperature:data_min = -9990. ;
> temperature:data_max = 28.9620184109083 ;
> temperature:C_format = "%10.4f" ;
> temperature:F_format = "f10.4" ;
> temperature:_FillValue = -9990. ;
> temperature:epic_code = 32. ;
> 
> // global attributes:
> :title = "PIRATA Northeast Extension Cruise 2007: XBT data." ;
> :history = "Initial release. 20Jun2008" ;
> :institution = "Atlantic Oceanographic and Meteorological Laboratory/PhOD" ;
> :source = "R Lumpkin, C Schmid, C Meinen" ;
> :CONVENTIONS = "CF-1.2" ;
> :DATA_AUTHOR = "R Lumpkin, C Schmid, C Meinen" ;
> :FILE_AUTHOR = "original (for ctd data): D Snowden, edited (for xbt data) by: 
> CM Alex" ;
> :FILE_CREATION_DATE = "11:50 23-Jun-2008" ;
> :FILE_SOURCE = "Atlantic Oceanographic and Meteorological Laboratory/PhOD" ;
> :ACKNOWLEDGEMENT01 = "This data is distributed in good faith." ;
> :ACKNOWLEDGEMENT02 = "It is an estimate and may not be considered exact." ;
> :ACKNOWLEDGEMENT03 = "If you choose to use this data, the source can be " ;
> :ACKNOWLEDGEMENT04 = "acknowledged by citing:" ;
> :missing_value = -9990. ;
> :_FillValue = -9990. ;
> data:
> 
> latitude =  16.4997,  16.4997,  16.4997,  16.6482,  16.8355,  16.8505,
> 16.9992,  16.9992,  16.9992,  16.9992,  17.1753,  17.3352,  17.6620,
> 17.8248,  18.1592,  18.3238,  18.6600,  18.8283,  18.9998,  18.9998,
> 18.9998,  18.9998,  19.1577,  19.3255,  19.4997,  19.4997,  19.4997,
> 19.4997,  19.6663,  20.1742,  20.3265,  20.4727,  20.4727,  20.4727,
> 20.4727,  12.6850,  11.4950,  11.4950,  11.4950,  11.4950,  11.4950,
> 5.3350,   5.1800,   4.8410,   4.6820,   4.3240,   4.1580,   5.7120,
> 5.8320,   6.1640,   6.3330,   6.6690,   6.8370,   7.1820,   7.3430,
> 7.6600,   7.8160,   8.1670,   8.3320,   8.6750,   8.8310,   9.1790,
> 9.3310,   9.6650,   9.8320,  10.3250,  10.6670,  10.8170,  11.1750,
> 11.3350,  11.6590,  11.8330,  12.1680,  12.3450,  12.6690,  12.8290,
> 13.1800,  13.3570,  13.6720,  13.8380,  14.1630,  14.6620,  14.6730,
> 14.8290,  14.9990,  14.9990,  14.9990,  14.9990,  15.1890 ;
> 
> longitude = -22.7333, -22.7333, -22.7333, -22.7580, -22.7883, -22.7917,
> -22.8170, -22.8170, -22.8170, -22.8170, -22.8803, -22.9395, -22.9998,
> -22.9998, -22.9982, -22.9998, -22.9998, -22.9998, -23.0002, -23.0002,
> -23.0002, -23.0002, -29.9998, -29.9998, -29.9997, -29.9997, -29.9997,
> -29.9997, -29.9998, -22.9998, -22.9998, -23.0678, -23.0678, -23.0678,
> -23.0678, -55.7950, -38.0350, -38.0350, -38.0350, -38.0350, -38.0350,
> -23.0000, -23.0000, -23.0000, -23.0000, -22.9960, -22.9930, -22.9980,
> -22.9990, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000,
> -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000,
> -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000,
> -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000, -23.0000,
> -23.0000, -23.0000, -22.9950, -23.0000, -23.0000, -22.9570, -22.9540,
> -22.9120, -22.8670, -22.8670, -22.8670, -22.8670, -22.8160 ;
> 
> depth =   2,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,
> 32, 4225076,  31,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,
  ...
> _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;
> }

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: SQZ-618269
Department: Support netCDF
Priority: Normal
Status: Closed