NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi Waylon, It looks like you are getting some good responses to your question. Here's another shameless plug, this one for NCL. The next release of NCL (in a couple of weeks) will have the ability to set command line arguments, and this kind of thing can be used for reading a file, changing some aspect of it, and writing it back out. I've attached an NCL script which you can run with: ncl 'f="seismic.nc"' 'v="z"' oldv=705. newv=0. newValue.ncl If it's not obvious, this will take a netCDF file called "seismic.nc", and change the locations where variable "z" is equal to 705. to be equal to 0. If you are already an NCL user, I can easily give you a new "ncl" binary to try before the official release. If you are not an NCL user, feel free to write to me personally if you want to know more. --Mary P.S. For convenience, I'll include the script below as well:; ; Usage:
; ; ncl 'f="F.nc"' 'v="X"' oldv=32. newv=45. newValue.ncl ; begin input_vars = (/"f","v","oldv","newv"/) if(.not.all(isvar(input_vars))) then print("Note: you must enter values for the following variables:") print("'"+input_vars+"'") exit end if fio = addfile (f, "w") x = fio->$v$ if (any(x.eq.oldv)) then x1d = ndtooned(x) i = ind(x1d.eq.oldv) x1d(i) = (/ newv /) x = onedtond(x1d, dimsizes(x)) fio->$v$ = (/ x /) ni = dimsizes(i) ; count number of values changed print(f+": "+v+" : value="+oldv+" changed to " \ +newv+" : "+ni+" times") else print(f+" : "+v+" : no replacements performed") end if end On Fri, 11 Nov 2005, Waylon.Collins wrote:
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 * **********************************************************************
; ; Usage: ; ; ncl 'f="F.nc"' 'v="X"' oldv=32. newv=45. newValue.ncl ; begin input_vars = (/"f","v","oldv","newv"/) if(.not.all(isvar(input_vars))) then print("Note: you must enter values for the following variables:") print("'"+input_vars+"'") exit end if fio = addfile (f, "w") x = fio->$v$ if (any(x.eq.oldv)) then x1d = ndtooned(x) i = ind(x1d.eq.oldv) x1d(i) = (/ newv /) x = onedtond(x1d, dimsizes(x)) fio->$v$ = (/ x /) ni = dimsizes(i) ; count number of values changed print(f+": "+v+" : value="+oldv+" changed to " \ +newv+" : "+ni+" times") else print(f+" : "+v+" : no replacements performed") end if end
netcdfgroup
archives: