Re: [netcdf-java] Removing a dimension from a variable

Hi Christopher,

Christopher Mueller wrote:
I am subsetting an opendap nc file to a local nc file and I’m running into a bit of a problem. After subsetting, the variable of interest has 4 dimensions (x, y, level, record) however there is only 1 level. I would like to remove the level dimension as it is unnecessary and causes some problems later in the application. Is there a way to do this? I’ve tried removing the dimension from the “root group” of the NetcdfWritable file with no luck. I’ve also tried iterating through the dimensions (var.getDimensions().remove(i)) and removing the one with length = 1, also no luck.

Has anyone done this before? Is it possible, or do I need to extract the data, reduce the resulting array, and then recreate the variable by hand?

I haven't tried this but you can create a new Variable without the level dimension by calling Variable.slice() on the existing Variable and specifying the level dimension. Then, before you call create() on your NetcdfFileWritable, you can remove the old Variable and add the new one.

Hope that helps,


Ethan R. Davis                                Telephone: (303) 497-8155
Software Engineer                             Fax:       (303) 497-8690
UCAR Unidata Program Center                   E-mail:    edavis@xxxxxxxx
P.O. Box 3000
Boulder, CO  80307-3000             

  • 2007 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: