The current CfRadial 2 draft (2019-02-03) specifies the type of attributes as either string, int, float, double, string[], or array of same type as field data.
For most of these types the mapping to a concrete netcdf data type is obvious:
int --> NC_INT
float --> NC_FLOAT
double --> NC_DOUBLE
For the string attributes things are a little more complicated due to there being two functions for writing string based attributes in the NetCDF API: nc_put_att_text and nc_put_att_string.
The nc_put_att_text function writes the attribute as a 1D array of NC_CHAR. This is the traditional and most common way to write a scalar string attribute.
The nc_put_att_string function writes the attribute as a NC_STRING. This API allows us to output arrays of strings, and is thus the only option for our string[] attributes.
These two methods of writing strings result in fundamentally different types in the output file. The difference is visible in ncdump output:
short KDP(time, range) ;
string KDP:ancillary_variables = "foo" ;
KDP:legend_xml = "bar" ;
Here the ancillary_variables attribute was written with nc_put_att_string (with a single string passed), while legend_xml was written with nc_put_att_text.
We probably need to clarify that string in the CfRadial 2 specification maps to the traditional array of NC_CHAR as output by nc_put_att_text, while string[] maps to an array of the NC_STRING type as output by nc_put_att_string.
The current CfRadial 2 draft (2019-02-03) specifies the type of attributes as either
string,int,float,double,string[], orarray of same type as field data.For most of these types the mapping to a concrete netcdf data type is obvious:
int-->NC_INTfloat-->NC_FLOATdouble-->NC_DOUBLEFor the string attributes things are a little more complicated due to there being two functions for writing string based attributes in the NetCDF API:
nc_put_att_textandnc_put_att_string.The
nc_put_att_textfunction writes the attribute as a 1D array ofNC_CHAR. This is the traditional and most common way to write a scalar string attribute.The
nc_put_att_stringfunction writes the attribute as aNC_STRING. This API allows us to output arrays of strings, and is thus the only option for ourstring[]attributes.These two methods of writing strings result in fundamentally different types in the output file. The difference is visible in
ncdumpoutput:Here the
ancillary_variablesattribute was written withnc_put_att_string(with a single string passed), whilelegend_xmlwas written withnc_put_att_text.We probably need to clarify that
stringin the CfRadial 2 specification maps to the traditional array ofNC_CHARas output bync_put_att_text, whilestring[]maps to an array of theNC_STRINGtype as output bync_put_att_string.