Project

General

Profile

setgatts: can CDO deal with "\n" in attribute text?

Added by Michael Weimer almost 6 years ago

Hello everyone,

I am trying to copy the global attributes of one file to the other. Using CDO, I think the solution would be to create a file containing pairs of attribute name and its content. E.g. the content of this file containing the attibutes (attfile.txt) could look like:

history Fri May 04 17:42:30 2018: cdo sellonlatbox,-180,180,-90,90 infile0.nc outfile0.nc

By using
cdo setgatts,attfile.txt infile.nc outfile.nc

this would copy infile.nc to outfile.nc and create the attribute history therein with the given value "Fri [...]".

However, CDO struggles if an "\n" occurs in the value for the attribute such as

history "first entry\nsecond entry" 

This error message occurs within netCDF:
Error (cdf_put_att_text) : NetCDF: Name contains illegal characters

That is why my questions are:
  1. Is there an error in my creation of the attfile.txt?
  2. How does the attfile have to look like if there should be multi-line attributes in it?
  3. Is there another way to copy the global attributes with CDO (i.e. apart from the nco command ncks -A -x...)?

Thanks a lot for your help!


Replies (2)

RE: setgatts: can CDO deal with "\n" in attribute text? - Added by Uwe Schulzweida almost 6 years ago

Thanks for this example! "\n" is not supported in text attributes. This problem will be solved in the next CDO release.
Please note that the CDO operator setgatts is obsolete and will not further developed. We replaced it by the more powerful operator setattribute. The syntax to define an attribute has also slightly changed.

RE: setgatts: can CDO deal with "\n" in attribute text? - Added by Michael Weimer almost 6 years ago

Thanks a lot for your help! Then, I will have to update my cdo version.

    (1-2/2)