⇐ ⇒

[CF-metadata] CF Conventions and NetCDF4 string attributes

From: Charlie Zender <zender>
Date: Fri, 24 Jan 2014 08:14:40 -0800

Stephen,

This feature is new to NCO as of version 4.4.0,
i.e., you must install the latest NCO to take advantage of it.

zender at roulee:~$ ncgen -k netCDF-4 -b -o ~/my_string_file.nc ~/foo.cdl
zender at roulee:~$ ncks --cdl ~/my_string_file.nc
netcdf my_string_file {

  // global attributes:
    string :my_string_attribute = "this is a single-valued NC_STRING
variable" ;
} // group /
zender at roulee:~$ ncks -3 ~/my_string_file.nc ~/foo.nc
zender at roulee:~$ ncks --cdl ~/foo.nc
netcdf foo {

  // global attributes:
    :my_string_attribute = "this is a single-valued NC_STRING variable" ;
    :history = "Fri Jan 24 08:03:14 2014: ncks -3
/home/zender/my_string_file.nc /home/zender/foo.nc" ;
    :NCO = "20140124" ;
} // group /

There is no problem mapping scalar NC_STRING attributes
to NC_CHAR array attributes. The difficult, messy,
ugly problems arise when dealing with NC_STRING arrays
and/or with NC_STRING variables (as opposed to attributes).
Fortunately NC_STRING is usually used as a scalar attribute,
not as a variable, so this workaround solves most real-world
examples of converting netCDF4->netCDF3 that I have encountered
so far.

Producers of netCDF4 datasets should think twice before using
NC_STRING for anything except scalar attributes if they value
interoperability with netCDF3 applications.

Charlie

Le 24/01/2014 01:06, stephen.pascoe at stfc.ac.uk a ?crit :
> Hi Charlie,
>
>> However this issue is resolved, there is a workaround available now:
>> ncdismember (and ncks -3) automatically translates netCDF4 files to
>> netCDF3 files, and optionally sends them to a cfchecker. It translates scalar NC_STRING attributes to NC_CHAR arrays.
>
> I've tried this and it doesn't seem to work with ncks version 4.3.4. I get the same error as I would if I used "nccopy -k 1":
>
> $ ncks -3 my_string_file.nc my_nc3_file.nc
> nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_copy_att()
> nco_err_exit(): ERROR Error code is -45. Translation into English with nc_strerror(-45) is "NetCDF: Not a valid data type or _FillValue type mismatch"
> nco_err_exit(): ERROR NCO will now exit with system call exit(EXIT_FAILURE)
>
> where nc_string_file.nc is:
>
> $ ncdump my_string_file.nc
> netcdf my_string_file {
>
> // global attributes:
> string :my_string_attribute = "this is a single-valued NC_STRING variable" ;
> }
>
> I guess in theory the attribute is a length-1 array of strings which cannot be mapped to an NC_CHAR array without some approximations.
>
> S.
>
> ---
> Stephen Pascoe +44 (0)1235 445980
> Centre of Environmental Data Archival
> STFC Rutherford Appleton Laboratory, Harwell Oxford, Didcot OX11 0QX, UK
>
>
> -----Original Message-----
> From: Charlie Zender [mailto:zender at uci.edu]
> Sent: 23 January 2014 17:36
> To: CF Metadata Mail List
> Subject: Re: [CF-metadata] CF Conventions and NetCDF4 string attributes
>
> Hi Stephen,
>
> The example you posted illustrates one of many netCDF4 features that are creeping into datasets. One of your suggestions is to explicitly loosen the rules and to allow CF to accept scalar NC_STRINGs.
> There are trade-offs to such exceptions.
> This might put CF on a slippery slope to greater netCDF4 acceptance (good, IMHO) yet immediately puts a whole class of CF applications in jeopardy of not working with files that are nominally CF-compliant because they have an NC_STRING the application does not understand (awkward, until application is "fixed").
>
> However this issue is resolved, there is a workaround available now:
> ncdismember (and ncks -3) automatically translates netCDF4 files to
> netCDF3 files, and optionally sends them to a cfchecker. It translates scalar NC_STRING attributes to NC_CHAR arrays.
> http://nco.sf.net/nco.html#ncdismember
> http://nco.sf.net/nco.html#ncks
>
> Best,
> Charlie
> --
> Charlie Zender, Earth System Sci. & Computer Sci.
> University of California, Irvine 949-891-2429 )'( _______________________________________________
> CF-metadata mailing list
> CF-metadata at cgd.ucar.edu
> http://mailman.cgd.ucar.edu/mailman/listinfo/cf-metadata
>

-- 
Charlie Zender, Earth System Sci. & Computer Sci.
University of California, Irvine 949-891-2429 )'(
Received on Fri Jan 24 2014 - 09:14:40 GMT

This archive was generated by hypermail 2.3.0 : Tue Sep 13 2022 - 23:02:41 BST

⇐ ⇒