unable to use ',' in -setattribute strings
Added by Brian Højen-Sørensen 6 months ago
Hi,
I've just discovered what i believe is a bug in -setattribute
when attempting to set a string with a comma included. It is parsed as a list of inputs (splitting on the comma).
I've attached a file but it is independent of the file.
To reproduce the issue simply do a:
cdo -setattribute,bathymetry@some_string="a,b" test.nc out.nc
It will return:cdo setattribute (Abort): Multidimensional string attributes not supported! txt="b"
I think it is a bug as it is quite common to have something like long_name="land mask (0=water, 1=land)"
which will fail with CDO but work just fine with NCO or using Python.
Cheers,
Brian
Replies (2)
RE: unable to use ',' in -setattribute strings - Added by Uwe Schulzweida 6 months ago
Hi Brian,
The comma is a special character in the CDO command line. It is used to separate operators and parameters.
In the CDO command line parser, the problem is now solved in such a way that a comma in strings must be escaped with a backslash:
cdo -setattribute,bathymetry@some_string="a\,b" test.nc out.ncThis change will be available in the next CDO version.
Unfortunately, the equals sign is also a special character when parsing parameters. Simple apostrophes are sufficient to solve the problem:
cdo -setattribute,bathymetry@some_string='land mask (0=water\, 1=land)' test.nc out.ncA general workaround to avoid problems on the command line is to read the attributes from a file:
cat > myattributes << EOF bathymetry@some_string="land mask (0=water, 1=land)" EOF cdo -setattribute,FILE=myattributes test.nc out.nc
Cheers,
Uwe
RE: unable to use ',' in -setattribute strings - Added by Brian Højen-Sørensen 6 months ago
Hi Uwe,
That is really good news, and I forgot to write that I did test if I could escape the comma.
Thanks again for the swift work.
Cheers,
Brian
PS. next time I will remember todo a real bug report and not just a forum post.