Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Change variable of type char values

c256
2012-11-29
2013-10-17
  • c256
    c256
    2012-11-29

    Hi all,

    I would like to change the values of a variable of type char  that has the following structure:

    ncdump -v,Times file.nc
    
    Times =
      "2004-01-25_00:00:00",
      "2004-01-25_01:00:00",
      "2004-01-25_02:00:00",
      "2004-01-25_03:00:00",
      "2004-01-25_04:00:00",
      "2004-01-25_05:00:00",
      "2004-01-25_06:00:00",
      "2004-01-25_07:00:00",
      "2004-01-25_08:00:00",
      "2004-01-25_09:00:00",
      "2004-01-25_10:00:00",
      "2004-01-25_11:00:00",
      "2004-01-25_12:00:00",
      "2004-01-25_13:00:00",
      "2004-01-25_14:00:00",
      "2004-01-25_15:00:00",
      "2004-01-25_16:00:00",
      "2004-01-25_17:00:00",
      "2004-01-25_18:00:00",
      "2004-01-25_19:00:00",
      "2004-01-25_20:00:00",
      "2004-01-25_21:00:00",
      "2004-01-25_22:00:00",
      "2004-01-25_23:00:00",
      "2004-01-26_00:00:00" ;
    }
    

    In the following:

    Times =
      "2004-02-25_00:00:00",
      "2004-02-25_01:00:00",
      "2004-02-25_02:00:00",
      "2004-02-25_03:00:00",
      "2004-02-25_04:00:00",
      "2004-02-25_05:00:00",
      "2004-02-25_06:00:00",
      "2004-02-25_07:00:00",
      "2004-02-25_08:00:00",
      "2004-02-25_09:00:00",
      "2004-02-25_10:00:00",
      "2004-02-25_11:00:00",
      "2004-02-25_12:00:00",
      "2004-02-25_13:00:00",
      "2004-02-25_14:00:00",
      "2004-02-25_15:00:00",
      "2004-02-25_16:00:00",
      "2004-02-25_17:00:00",
      "2004-02-25_18:00:00",
      "2004-02-25_19:00:00",
      "2004-02-25_20:00:00",
      "2004-02-25_21:00:00",
      "2004-02-25_22:00:00",
      "2004-02-25_23:00:00",
      "2004-02-26_00:00:00" ;
    }
    

    I tried with

    ncap -s 'Times(:)={.....}' file.nc nfile.nc
    

    But even even though I don't get an error the changes are not applied.

    Thanks for your support,

    Best.

     
  • Charlie Zender
    Charlie Zender
    2012-12-04

    It looks like you want to shift the time by a month. Probably the variable Time has a units attribute with value something like "days since 2004-01-01". Use ncatted to change the value of the units attribute. Or you can add 30 days to Time with
    ncap2 -s 'Time+=30' in.nc out.nc