Menu

ncap2 cannot find variable with "-" in its name

2017-06-20
2017-06-20
  • joaquim pereira bento

    Dears

    I have a nc file (in.nc) with a variable called "CHL-OC5_mean". When I try:

    ncap2 -O -h -s 'where(CHL-OC5_mean>30) CHL-OC5_mean=30' in.nc out.nc
    

    I got this error:

    ncap2: WARNING prs_cls::ncap_var_init(): Unable to find variable CHL in in.nc
    ncap2: ERROR out(): Could not read var CHL

    if I change the name of the variable to "var" with:

    ncrename -v CHL-OC5_mean,var in.nc
    

    and run the first command again, I got the result, there is no problem.

    ncap2 -O -h -s 'where(var>30) var=30' in.nc out.nc
    

    So, I guess the problem is the "-" sign. The point is that I have "-" and it is really not convenient to change this. In fact the variable's name goes inside a variable in bash, like this:

    varname="CHL-OC5_mean"
    ncap2 -O -h -s "where($varname>30) $varname=30" in.nc out.nc
    

    My question is: Is there any way to force ncap2 to understand the "-" sign as being part of the variable's name?

    All the best,

    jb

     
  • henry Butowsky

    henry Butowsky - 2017-06-20

    quote the variable with ' '

    ncap2 -O -h -s "where('CHL-OC5'_mean>30) 'CHL-OC5_mean'=30" in.nc out.nc
    
     

Log in to post a comment.