Menu

ncap2 scripts and attributes with dots in their name

2019-01-03
2019-01-04
  • Daniel Neumann

    Daniel Neumann - 2019-01-03

    Hey,

    Happy new year!

    Some global attributes of a netCDF I am working with contain a dot in their name. E.g.:

    SURF_ugN_NOX.coordinates="abc";
    

    I would like to work with these global attributes in a ncap2 scripts. But none of these solutions work:

    global@SURF_ugN_NOX.coordinates.ram_delete();
    global@`SURF_ugN_NOX.coordinates`.ram_delete();
    global@"SURF_ugN_NOX.coordinates".ram_delete();
    global@'SURF_ugN_NOX.coordinates'.ram_delete();
    

    Does there exist a workaround? Or should I rename these attributes first -- e.g. with ncatted.

    Cheers,
    Daniel

     
  • henry Butowsky

    henry Butowsky - 2019-01-03

    Hi Daniel,
    you need to replace the "." with @
    the "." in ncap2 is used to specify a ncap2 method.
    e.g
    SURF_ugN_NOX@coordinates="abc";
    or
    'global@'SURF_ugN_NOX.coordinates'.ram_delete();

    To use the "." in a name you need to quote the var/att name with "'" as I have done above.
    ...Henry

     
  • Daniel Neumann

    Daniel Neumann - 2019-01-04

    Hi Henry,

    Thanks for the quick reply.

    you need to replace the "." with @
    the "." in ncap2 is used to specify a ncap2 method.
    e.g
    SURF_ugN_NOX@coordinates="abc";
    or
    'global@'SURF_ugN_NOX.coordinates'.ram_delete();

    To use the "." in a name you need to quote the var/att name with "'" as I have done above.

    Unfortunately, both solutions do not work (global@SURF_ugN_NOX@coordinates and 'global@'SURF_ugN_NOX.coordinates'; see bottom of this post). Probably, I explained my issue wrongly. This is my cdl file definition:

    netcdf test1 {
    dimensions:
            time = UNLIMITED ; // (4 currently)
            lat = 4 ;
            lon = 4 ;
    variables:
            float SURF_ugN_NOX(time, lat, lon) ;
                    SURF_ugN_NOX:_FillValue = 9.96921e+36f ;
                    SURF_ugN_NOX:coordinates = "lat lon" ;
                    SURF_ugN_NOX:units = "mmol N/m**2/day" ;
    
    // global attributes:
                    :vert_coord = "atmosphere_hybrid_sigma_pressure_coordinate" ;
                    :SURF_ugN_NOX._FillValue = 9.96920996838687e+36 ;
                    :SURF_ugN_NOX.coordinates = "lat lon" ;
                    :SURF_ugN_NOX.units = "ugN/m3" ;
    }
    

    All attributes of each variable are duplicated as global attributes due to an issue with a THREDDS server, from which I downloaded these data. I want to remove the duplicate global attributes.

    Here is, what I tried in ncap2 scripts. The comment lines indicate the resulting error.

    global@SURF_ugN_NOX.coordinates.ram_delete();
          /* test2.ncap:1:14: expecting FUNC, found 'coordinates' */
    global@'SURF_ugN_NOX.coordinates'.ram_delete();
          /* testA.ncap line 1, column 11: unexpected character 'g' */
    global@"SURF_ugN_NOX.coordinates".ram_delete();
          /* testA.ncap line 1, column 11: unexpected character 'g' */
    global@`SURF_ugN_NOX.coordinates`.ram_delete();
          /* testA.ncap line 1, column 11: unexpected character 'g' */
    global@SURF_ugN_NOX\.coordinates.ram_delete();
          /* testA.ncap line 1, column 23: unexpected character '\' */
    global@SURF_ugN_NOX@coordinates.ram_delete();
          /* test2.ncap:1:13: unexpected token: global@coordinates */
    'global@'SURF_ugN_NOX.coordinates'.ram_delete();
          /* testA.ncap line 1, column 12: unexpected character ''' */
    
     

    Last edit: Daniel Neumann 2019-01-04
  • Daniel Neumann

    Daniel Neumann - 2019-01-04

    Actually, I am confused about the usage of ram_delete(). I understood the definition

    ram_delete()
    Deletes a RAM variable or an attribute

    as delete a RAM variable or delete any attribute (not a newly created attribute). But

    global@vert_coord.ram_delete();
    

    yields

    ncap2: WARNING utl_cls::fnd(): ram_delete unable to find variable: global@vert_coord
    
     

Log in to post a comment.