Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.
> The replies are providing an interesting comparison of packages for > manipulating netCDF files. I would add an example using Ruby, which is an object-oriented language like Python. % cat edit_nc.rb require 'numru/netcdf' include NumRu # Or use NumRu::NetCDF instead of NetCDF below file = NetCDF.open('G.nc','a') # 'a' (append) or 'r+' like fopen in C x = file.var('X') val = x.get val[ val.eq(32.0) ] = 45.0 x.put(val) file.close Here, I use the same netcdf file as a privious reporter used, but the program works regardress the rank (# of dimensions) of the varibale. % ncdump G.nc netcdf G { dimensions: d = 8 ; variables: float X(d) ; data: X = 27 , 32.5 , 32 , 30.1 , 29 , 40 , 32 , 45 ; } % ruby edit_nc.rb % ncdump G.nc netcdf G { dimensions: d = 8 ; variables: float X(d) ; data: X = 27 , 32.5 , 45 , 30.1 , 29 , 40 , 45 , 45 ; } -- Takeshi Horinouchi (Kyoto Univ.) > > Here is my solution using (and shameless plug for) NAP (a.k.a. tcl-nap), > whose home is > http://tcl-nap.sourceforge.net > > I wrote the following shell script named 'change_nc_value': > > $ cat change_nc_value > #!/bin/sh > tclsh << END > nap "in = [nap_get netcdf $1 $2]" > [nap "in == $3 ? $4 : in"] netcdf $1 $2 > END > > I then tested it as follows: > > $ ncdump G.nc > netcdf G { > dimensions: > d = 8 ; > variables: > float X(d) ; > data: > > X = 27, 32.5, 32, 30.1, 29, 40, 32, 45 ; > } > $ change_nc_value G.nc X 32 45 > $ ncdump G.nc > netcdf G { > dimensions: > d = 8 ; > variables: > float X(d) ; > data: > > X = 27, 32.5, 45, 30.1, 29, 40, 45, 45 ; > } > > Harvey Davies, CSIRO Marine and Atmospheric Research, > Private Bag No. 1, Aspendale 3195 > E-mail: harvey.davies@xxxxxxxx > Office: 03 9239 4556 > Mobile: 04 2241 7563 > > > -----Original Message----- > > From: owner-ncdigest@xxxxxxxxxxxxxxxx [mailto:owner- > > ncdigest@xxxxxxxxxxxxxxxx] > > Sent: Saturday, 12 November 2005 15:25 > > To: ncdigest@xxxxxxxxxxxxxxxx > > Subject: ncdigest V1 #922 > > > > > > ncdigest Friday, November 11 2005 Volume 01 : > Number > > 922 > > > > > > > > Today's Topics: > > Manipulating netCDF files > > Re: Manipulating netCDF files > > Re: Manipulating netCDF files > > Re: Manipulating netCDF files > > Re: Manipulating netCDF files > > RE: Manipulating netCDF files > > > > > ---------------------------------------------------------------------- > > > > Date: Fri, 11 Nov 2005 07:32:16 -0600 > > From: "Waylon.Collins" <Waylon.Collins@xxxxxxxx> > > Subject: Manipulating netCDF files > > > > Dear group members, > > > > After reviewed the Unidata list of software that manipulates netCDF > > files, I have yet to find one that can perform the following task -- > I > > need command-line software (that can run in a Redhat Enterprise > Linux > > environment) that will allow me to replace data values, associated > with > > a particular variable, with values that I can specify. It needs to > allow > > for a logical operation. For example, the software needs to be able > to > > perform the following -- "Any datum of variable X, within netCDF > file > > with filename F.nc, that equals 32, change it to the value 45. Thus, > the > > original file F.nc is now altered, or the altered file is now named > > G.nc". Any help will be greatly appreciated. > > > > Sincerely, > > > > Waylon > > > > - -- > > > ********************************************************************** > > * Waylon G. Collins Voice: (361)289-0959 > * > > * NOAA/National Weather Service E-Mail: Waylon.Collins@xxxxxxxx > * > > * 300 Pinson Drive > * > > * Corpus Christi, TX 78406 > * > > * USA > * > > > **********************************************************************
netcdfgroup
archives: