ncatted help

ocehugo
2010-06-28
2013-10-17
  • ocehugo
    ocehugo
    2010-06-28

    Hello to all,

    iam facing a problem with ncatted.
    in my code i use an attribute to control some functions , i check if the attribute is defined to some string  and so on.

    The problem :

    When i use the ncatted to add,modify,any operator an attribute the size is different from others tools ( like matlab).

    variable example:

    double temp(time,lat, lon) ;
    temp:long_name = "temp";
    temp:myflag = "true true" ;
    temp:units = "kelvin";

    So ncks -m -v temp gives me:

    temp attribute 1: myflag, size = 9 NC_CHAR, value = true true
    temp attribute 2: units, size = 6 NC_CHAR, value = kelvin


    Now…suppose that i want to give the myflag attribute the following value: "false false", i use ncatted and ncks givesme:

    temp attribute 1: myflag, size = 12 NC_CHAR, value = false false
    temp attribute 2: units, size = 6 NC_CHAR, value = kelvin

    if i do the same task, with the nc_attput from matlab i got this:

    temp attribute 1: myflag, size = 11 NC_CHAR, value = false false
    temp attribute 2: units, size = 6 NC_CHAR, value = kelvin

    So where the extra character !???!!?!?!? How to make the ncatted works like my other routine? This almost drives me crazy heeheh. This little difference make my other script that reads the attribute breaok, i think that is beacuse of the spaces between the two words that i split.

    Thankz

     
  • Charlie Zender
    Charlie Zender
    2010-06-28

    This appears to be an example of an off-by-one error in ncatted that is fixed in NCO 4.0.2, released yesterday.
    Upgrading should solve this problem.
    Here are examples of ncatted behavior before and after upgrading, respectively:

    zender@pbs:~$ ncatted -O -a foo,one,a,c,'true true' ~/nco/data/in.nc ~/foo.nc ; ncks -m -C -v one ~/foo.nc | grep foo
    one attribute 1: foo, size = 10 NC_CHAR, value = true true

    ender@givre:~/nco/data$ ncatted -O -a foo,one,a,c,'true true' ~/nco/data/in.nc ~/foo.nc ; ncks -m -C -v one ~/foo.nc | grep foo
    one attribute 1: foo, size = 9 NC_CHAR, value = true true

     
  • ocehugo
    ocehugo
    2010-06-30

    thankz

     
  • ocehugo
    ocehugo
    2013-03-27

    Rise from your grave… this bug came back in 4.2.6 and others…

    I had some issues this last week and after long hours i have found that this annoying bug again…

    here we go:

    [b]~/cat xx[/b]
    netcdf alpha {
    dimensions:
            a = 1 ;
    variables:
            float abc(a) ;
                    abc:error = "true true" ;
    }
    [b]~/ncgen xx -o in.nc[/b]
    [b]~/ncks -m -C -v abc in.nc[/b]
    abc: type NC_FLOAT, 1 dimension, 1 attribute, chunked? no, compressed? no, packed? no
    abc size (in RAM) is 1*sizeof(NC_FLOAT) = 1*4 = 4 bytes
    abc dimension 0: a, size = 1 (Non-coordinate dimension)
    abc attribute 0: error, size = 9 NC_CHAR, value = true true
    [b]~/ncatted -O -a error,abc,o,c,"true true" in.nc [/b]
    abc: type NC_FLOAT, 1 dimension, 1 attribute, chunked? no, compressed? no, packed? no
    abc size (in RAM) is 1*sizeof(NC_FLOAT) = 1*4 = 4 bytes
    abc dimension 0: a, size = 1 (Non-coordinate dimension)
    abc attribute 0: error, size = 10 NC_CHAR, value = true true
    

    The bug was introduced at 20120902 on nco_att_utl.c file…i've patched the file back with the line from the 4.0.2  and it's working again now …

     
  • Charlie Zender
    Charlie Zender
    2013-03-27

    OK, more people have complained about NUL-terminating string attributes than have complained about not NUL-terminating string attributes so I will go with the flow and revert to the 4.0.2 behavior. This will be in the next NCO release any day now.
    cz