Menu

incrementing a variable

Help
2001-04-05
2013-10-17
  • Nobody/Anonymous

    I apologize if this is too simple; I started using NCO today!

    I'd like to increment a variable (an int-type coordinate variable) -- just add 1 to the current values. I can't find anything in the manual that suggests NCO can do this; is that so? It seems unbelievable, because it does other operations that are much more sophisticated. If it can't, can anyone suggest a simple combination of ncdump, ncget, and shell commands that would accomplish the same thing? I've never used ncget, and I've used ncdump only to see variable data and file metadata.

    Thanks.

    Emilio
    emiliom@u.washington.edu

     
    • Charlie Zender

      Charlie Zender - 2001-04-05

      The simplest way to do this with NCO is to subtract negative one from your variable
      using ncdiff. There is an example of this
      in the bld/nco_tst.sh script.

       
    • Emilio Mayorga

      Emilio Mayorga - 2001-04-06

      Thanks, Charlie. That file is a gold mine of examples.

      I did a search on all ncdiff's in the file. The ones that seem to refer to what you're saying are near the beginning, and they operate on the files nco_tst.nc and in.nc. The subtraction of negative one is actually done between two nc files that have the same variable, but the one in file2 (in.nc) is a pre-existing scalar variable with a value of -1. I don't know how to insert such a scalar variable into an nc file using nco.

      Also, I want to do this increment on a coordinate variable, and it looks like there are some restrictions on operating on coord. variables.

      It seems so simple...

      BTW, I am really enjoying NCO! I hope I can help you with it in the future (in 6 months?), *after* I finish my PhD. I have worked with the netcdf 3.4 API in C; I've created a toolkit to help me manage, ingest, and analyze my data (mostly of dimensions XYT; http://boto.ocean.washington.edu/emu/\), so I have some experience with it.

      Thanks!

      Emilio

       
      • Charlie Zender

        Charlie Zender - 2001-04-06

        Thanks, Charlie. That file is a gold mine of examples.
        >
        > I did a search on all ncdiff's in the file. The ones that seem to refer to what
        > you're saying are near the beginning, and they operate on the files nco_tst.nc
        > and in.nc. The subtraction of negative one is actually done between two nc files
        > that have the same variable, but the one in file2 (in.nc) is a pre-existing
        > scalar variable with a value of -1. I don't know how to insert such a scalar
        > variable into an nc file using nco.

        ncdiff requires that the variables it subtracts be in different files but have the same name. so to accomplish what you want you just need to
        have a file containing a scalar -1 in it with the same name as the variable you want to add +1 to. use ncks -A -v negative_one to move
        the variable from in.nc to the file you want. or just hack the in.cdl file.

        >
        > Also, I want to do this increment on a coordinate variable, and it looks like
        > there are some restrictions on operating on coord. variables.

        then rename it so it's not a coordinate variable, do the operation, and then rename it to be a coordinate variable again

        >
        > It seems so simple...
        >
        > BTW, I am really enjoying NCO! I hope I can help you with it in the future (in
        > 6 months?), *after* I finish my PhD. I have worked with the netcdf 3.4 API in
        > C; I've created a toolkit to help me manage, ingest, and analyze my data (mostly
        > of dimensions XYT; http://boto.ocean.washington.edu/emu/\), so I have some experience
        > with it.
        >
        good, I look forward to your contributions. good luck with your defense.

        > Thanks!
        >
        > Emilio
        >

         
        • Emilio Mayorga

          Emilio Mayorga - 2001-04-06

          Thanks, it works! That didn't occur to me. Very clever.

          What I've done now is create a dummy nc file with a scalar variable of value 1. I can use this variable to add any number to a variable in another nc file, by using ncrename to set the names to be the same, and ncflint to multiply the scalar to any value I want.

          Emilio

           

Log in to post a comment.

MongoDB Logo MongoDB