Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

What is NCO?

The netCDF Operators (NCO) comprise a dozen standalone, command-line programs that take netCDF files as input, then operate (e.g., derive new data, average, print, hyperslab, manipulate metadata) and output the results to screen or files in text, binary, or netCDF formats. NCO aids manipulation and analysis of gridded scientific data. The shell-command style of NCO allows users to manipulate and analyze files interactively, or with simple scripts that avoid some overhead (and power) of higher level programming environments.

See http://nco.sourceforge.net/ for all details.

Example

This example is based on a netCDF XBeach result file ("xboutput.nc") of a 1D model with a number of variables, having a size of 12M. Of course, 12M is not that big, but you can imagine that in case of 2D and/or large numbers of simulations the file size easily becomes large. In such cases, it can be useful to leave the large original files on the network, but have a small subset containing the main results on your local drive, e.g. for plotting purposes.
In this example, the original file contains 5 hours of simulation time, a output time step of 100s, being 181 time steps. Assuming that we are mainly interested in the initial and final cross-shore profiles, we create a copy of the file, leaving out all the additional data.

The command for this is:

Code Block
ncks -v zb -d globaltime,,,180 xboutput.nc xboutputselection.nc

It takes the variable (-v) "zb" with a stride of 180 of the dimension (-d) "globaltime", using "xboutput.nc" as source and "xboutpuselection.nc" as destination. The headers of both files are shown below. The new file is only 14K.

Please note that the origin of the selection file stays clear by means of the history attribute.

The header of "xboutpuselection.nc" looks like:

Code Block
netcdf xboutputselection {
dimensions:
	globaltime = UNLIMITED ; // (2 currently)
	globaly = 1 ;
	globalx = 405 ;
variables:
	double globaltime(globaltime) ;
		globaltime:units = "s" ;
		globaltime:axis = "T" ;
		globaltime:standard_name = "time" ;
	double globalx(globaly, globalx) ;
		globalx:units = "m" ;
		globalx:long_name = "local x coordinate" ;
		globalx:standard_name = "projection_x_coordinate" ;
		globalx:axis = "X" ;
	double globaly(globaly, globalx) ;
		globaly:units = "m" ;
		globaly:long_name = "local y coordinate" ;
		globaly:standard_name = "projection_y_coordinate" ;
		globaly:axis = "Y" ;
	double zb(globaltime, globaly, globalx) ;
		zb:coordinates = "globalx globaly" ;
		zb:units = "m" ;
		zb:standard_name = "altitude" ;
		zb:long_name = "bed level" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:Producer = "XBeach littoral zone wave model (http://www.xbeach.org)" ;
		:Build-Revision = "2231" ;
		:Build-Date = "Mon Aug 29 08:34:00 CEST 2011" ;
		:URL = "URL: https://repos.deltares.nl/repos/XBeach/trunk" ;
		:history = "Tue Sep 13 15:38:41 2011: ncks -v zb -d globaltime,,,180 xboutput.nc xboutputselection.nc" ;
		:NCO = "20110913" ;
}

While the header of the original file "xboutput.nc" looks like:

Code Block
netcdf xboutput {
dimensions:
	globalx = 405 ;
	globaly = 1 ;
	wave_angle = 1 ;
	bed_layers = 3 ;
	sediment_classes = 1 ;
	inout = 2 ;
	globaltime = UNLIMITED ; // (181 currently)
	meantime = 1 ;
	tidetime = 2 ;
	windtime = 1 ;
variables:
	double parameter ;
		parameter:depfile = "bed.dep" ;
		parameter:xfile = "x.grd" ;
		parameter:yfile = "y.grd" ;
		parameter:gridform = "xbeach" ;
		parameter:xyfile = "abc" ;
		parameter:tunits = "s" ;
		parameter:zsinitfile = "" ;
		parameter:instat = "jons" ;
		parameter:lateralwave = "neumann" ;
		parameter:leftwave = "neumann" ;
		parameter:rightwave = "neumann" ;
		parameter:bcfile = "jonswap.txt" ;
		parameter:front = "abs_1d" ;
		parameter:left = "neumann" ;
		parameter:right = "neumann" ;
		parameter:back = "abs_1d" ;
		parameter:tidetype = "velocity" ;
		parameter:zs0file = "abc" ;
		parameter:paulrevere = "abc" ;
		parameter:break = "roelvink2" ;
		parameter:bedfriction = "chezy" ;
		parameter:bedfricfile = "" ;
		parameter:windfile = "" ;
		parameter:gw0file = "abc" ;
		parameter:waveform = "vanthiel" ;
		parameter:form = "vanthiel_va" ;
		parameter:turb = "bore_averag" ;
		parameter:swtable = "abc" ;
		parameter:ne_layer = "abc" ;
		parameter:tsglobal = "" ;
		parameter:tspoints = "" ;
		parameter:tscross = "" ;
		parameter:tsmean = "" ;
		parameter:ncfilename = "xboutput.nc" ;
		parameter:projection = "" ;
		parameter:drifterfile = "" ;
		parameter:scheme = "upwind_2" ;
		parameter:mpiboundary = "auto" ;
		parameter:swave = 1 ;
		parameter:lwave = 1 ;
		parameter:flow = 1 ;
		parameter:sedtrans = 1 ;
		parameter:morphology = 1 ;
		parameter:avalanching = 1 ;
		parameter:nonh = 0 ;
		parameter:gwflow = 0 ;
		parameter:q3d = 0 ;
		parameter:nx = 404 ;
		parameter:ny = 0 ;
		parameter:vardx = 1 ;
		parameter:thetanaut = 1 ;
		parameter:m = -123 ;
		parameter:random = 0 ;
		parameter:nspr = 0 ;
		parameter:oldwbc = 0 ;
		parameter:newstatbc = 1 ;
		parameter:correctHm0 = 1 ;
		parameter:oldnyq = 0 ;
		parameter:Tm01switch = 0 ;
		parameter:ARC = 1 ;
		parameter:freewave = 0 ;
		parameter:carspan = 0 ;
		parameter:tideloc = 0 ;
		parameter:ndischarge = 0 ;
		parameter:ntdischarge = 0 ;
		parameter:shoaldelay = 0 ;
		parameter:roller = 1 ;
		parameter:rfb = 0 ;
		parameter:wci = 0 ;
		parameter:smag = 1 ;
		parameter:kmax = -123 ;
		parameter:solver = -123 ;
		parameter:ngd = 1 ;
		parameter:nd = 3 ;
		parameter:sws = 1 ;
		parameter:lws = 1 ;
		parameter:lwt = 0 ;
		parameter:sus = 1 ;
		parameter:bed = 1 ;
		parameter:bulk = 1 ;
		parameter:morfacopt = 1 ;
		parameter:struct = 0 ;
		parameter:timings = 1 ;
		parameter:nglobalvar = 21 ;
		parameter:nmeanvar = 2 ;
		parameter:npointvar = 0 ;
		parameter:npoints = 0 ;
		parameter:nrugauge = 0 ;
		parameter:ncross = 0 ;
		parameter:ndrifter = 0 ;
		parameter:maxiter = -123 ;
		parameter:secorder = 0 ;
		parameter:oldhu = 0 ;
		parameter:sourcesink = 0 ;
		parameter:nd_var = 2 ;
		parameter:posdwn = -1. ;
		parameter:alfa = 0. ;
		parameter:dx = -1. ;
		parameter:dy = -1. ;
		parameter:xori = -3221.76 ;
		parameter:yori = 0. ;
		parameter:thetamin = 225. ;
		parameter:thetamax = 315. ;
		parameter:dtheta = 90. ;
		parameter:tstop = 3992. ;
		parameter:CFL = 0.7 ;
		parameter:g = 9.81 ;
		parameter:rho = 1025. ;
		parameter:depthscale = 1. ;
		parameter:zs0 = 5. ;
		parameter:taper = 100. ;
		parameter:Hrms = -123. ;
		parameter:Tm01 = -123. ;
		parameter:Trep = 10. ;
		parameter:Tlong = -123. ;
		parameter:dir0 = -123. ;
		parameter:nmax = 0.8 ;
		parameter:fcutoff = 0. ;
		parameter:trepfac = 0.01 ;
		parameter:sprdthr = 0.08 ;
		parameter:rt = 9000. ;
		parameter:dtbc = 1. ;
		parameter:dthetaS_XB = -123. ;
		parameter:order = 2. ;
		parameter:epsi = 0. ;
		parameter:gamma = 0.55 ;
		parameter:gamma2 = -123. ;
		parameter:alpha = 1. ;
		parameter:n = 10. ;
		parameter:gammax = 2. ;
		parameter:delta = 0. ;
		parameter:fw = 0. ;
		parameter:facsd = 1. ;
		parameter:beta = 0.1 ;
		parameter:hwci = 0.1 ;
		parameter:cats = 4. ;
		parameter:C = 55. ;
		parameter:cf = 0.00324297520661157 ;
		parameter:nuh = 0.1 ;
		parameter:nuhfac = 1. ;
		parameter:nuhv = 1. ;
		parameter:wearth = 7.27220521664304e-05 ;
		parameter:lat = 0. ;
		parameter:rhoa = 1.25 ;
		parameter:Cd = 0.002 ;
		parameter:windv = 0. ;
		parameter:windth = 270. ;
		parameter:kx = -123. ;
		parameter:ky = -123. ;
		parameter:kz = -123. ;
		parameter:dwetlayer = -123. ;
		parameter:aquiferbot = -123. ;
		parameter:gw0 = -123. ;
		parameter:gwdelay = -123. ;
		parameter:vonkar = -123. ;
		parameter:vicmol = -123. ;
		parameter:sigfac = -123. ;
		parameter:solver_acc = -123. ;
		parameter:kdmin = -123. ;
		parameter:dispc = -123. ;
		parameter:Topt = -123. ;
		parameter:rhos = 2650. ;
		parameter:dzg1 = 0.1 ;
		parameter:dzg2 = 0.1 ;
		parameter:dzg3 = 0.1 ;
		parameter:por = 0.4 ;
		parameter:BRfac = 1. ;
		parameter:facsl = 1.6 ;
		parameter:z0 = 0.006 ;
		parameter:smax = 1.79769313486232e+308 ;
		parameter:tsfac = 0.1 ;
		parameter:facua = 0.1 ;
		parameter:facSk = 0.1 ;
		parameter:facAs = 0.1 ;
		parameter:Tbfac = 1. ;
		parameter:Tsmin = 0.5 ;
		parameter:betad = 1. ;
		parameter:morfac = 5. ;
		parameter:morstart = 392. ;
		parameter:morstop = 19960. ;
		parameter:wetslp = 0.3 ;
		parameter:dryslp = 1. ;
		parameter:hswitch = 0.1 ;
		parameter:dzmax = 0.05 ;
		parameter:tstart = 392. ;
		parameter:tint = 0.2 ;
		parameter:tintg = 20. ;
		parameter:tintp = 0.2 ;
		parameter:tintc = 0.2 ;
		parameter:tintm = 3600. ;
		parameter:rugdepth = 0.005 ;
		parameter:wavint = -24.6 ;
		parameter:maxerror = -123. ;
		parameter:eps = 0.005 ;
		parameter:umin = 0. ;
		parameter:hmin = 0.2 ;
		parameter:thetanum = 1. ;
		parameter:cmax = 0.1 ;
		parameter:frac_dz = 0.7 ;
		parameter:split = 1.01 ;
		parameter:merge = 0.01 ;
		parameter:px = 3.14159265358979 ;
		parameter:rhog8 = 1256.90625 ;
		parameter:dt = -123. ;
		parameter:t = 0. ;
		parameter:tnext = -123. ;
	double globalx(globaly, globalx) ;
		globalx:units = "m" ;
		globalx:long_name = "local x coordinate" ;
		globalx:standard_name = "projection_x_coordinate" ;
		globalx:axis = "X" ;
	double globaly(globaly, globalx) ;
		globaly:units = "m" ;
		globaly:long_name = "local y coordinate" ;
		globaly:standard_name = "projection_y_coordinate" ;
		globaly:axis = "Y" ;
	double globaltime(globaltime) ;
		globaltime:units = "s" ;
		globaltime:axis = "T" ;
		globaltime:standard_name = "time" ;
	double H(globaltime, globaly, globalx) ;
		H:coordinates = "globalx globaly" ;
		H:units = "m" ;
		H:long_name = "Hrms wave height based on instantaneous wave energy" ;
	double zs(globaltime, globaly, globalx) ;
		zs:coordinates = "globalx globaly" ;
		zs:units = "m" ;
		zs:standard_name = "sea_surface_height_above_sea_level" ;
		zs:long_name = "water level" ;
	double zs0(globaltime, globaly, globalx) ;
		zs0:coordinates = "globalx globaly" ;
		zs0:units = "m" ;
		zs0:standard_name = "sea_surface_height_above_sea_level" ;
		zs0:long_name = "water level due to tide alone" ;
	double zb(globaltime, globaly, globalx) ;
		zb:coordinates = "globalx globaly" ;
		zb:units = "m" ;
		zb:standard_name = "altitude" ;
		zb:long_name = "bed level" ;
	double hh(globaltime, globaly, globalx) ;
		hh:coordinates = "globalx globaly" ;
		hh:units = "m" ;
		hh:long_name = "water depth" ;
	double u(globaltime, globaly, globalx) ;
		u:coordinates = "globalx globaly" ;
		u:units = "m/s" ;
		u:standard_name = "sea_water_x_velocity" ;
		u:long_name = "GLM velocity in cell centre, x-component" ;
	double v(globaltime, globaly, globalx) ;
		v:coordinates = "globalx globaly" ;
		v:units = "m/s" ;
		v:standard_name = "sea_water_y_velocity" ;
		v:long_name = "GLM velocity in cell centre, y-component" ;
	double ue(globaltime, globaly, globalx) ;
		ue:coordinates = "globalx globaly" ;
		ue:units = "m/s" ;
		ue:standard_name = "sea_water_x_velocity" ;
		ue:long_name = "Eulerian velocity in cell centre, x-component" ;
	double ve(globaltime, globaly, globalx) ;
		ve:coordinates = "globalx globaly" ;
		ve:units = "m/s" ;
		ve:standard_name = "sea_water_y_velocity" ;
		ve:long_name = "Eulerian velocity in cell centre, y-component" ;
	double urms(globaltime, globaly, globalx) ;
		urms:coordinates = "globalx globaly" ;
		urms:units = "m/s" ;
		urms:long_name = "orbital velocity" ;
	double Fx(globaltime, globaly, globalx) ;
		Fx:coordinates = "globalx globaly" ;
		Fx:units = "N/m2" ;
		Fx:long_name = "wave force, x-component" ;
	double Fy(globaltime, globaly, globalx) ;
		Fy:coordinates = "globalx globaly" ;
		Fy:units = "N/m2" ;
		Fy:long_name = "wave force, y-component" ;
	double ccg(globaltime, sediment_classes, globaly, globalx) ;
		ccg:coordinates = "globalx globaly" ;
		ccg:units = "m3/m3" ;
		ccg:long_name = "depth-averaged suspended concentration for each sediment fraction" ;
	double ceqsg(globaltime, sediment_classes, globaly, globalx) ;
		ceqsg:coordinates = "globalx globaly" ;
		ceqsg:units = "m3/m3" ;
		ceqsg:long_name = "depth-averaged suspended equilibrium concentration for each sediment class" ;
	double ceqbg(globaltime, sediment_classes, globaly, globalx) ;
		ceqbg:coordinates = "globalx globaly" ;
		ceqbg:units = "m3/m3" ;
		ceqbg:long_name = "depth-averaged bed equilibrium concentration for each sediment class" ;
	double Susg(globaltime, sediment_classes, globaly, globalx) ;
		Susg:coordinates = "globalx globaly" ;
		Susg:units = "m2/s" ;
		Susg:long_name = "suspended sediment transport for each sediment class (excluding pores), x-component" ;
	double Svsg(globaltime, sediment_classes, globaly, globalx) ;
		Svsg:coordinates = "globalx globaly" ;
		Svsg:units = "m2/s" ;
		Svsg:long_name = "suspended sediment transport for each sediment class (excluding pores), y-component" ;
	double E(globaltime, globaly, globalx) ;
		E:coordinates = "globalx globaly" ;
		E:units = "Nm/m2" ;
		E:long_name = "wave energy" ;
	double R(globaltime, globaly, globalx) ;
		R:coordinates = "globalx globaly" ;
		R:units = "Nm/m2" ;
		R:long_name = "roller energy" ;
	double D(globaltime, globaly, globalx) ;
		D:coordinates = "globalx globaly" ;
		D:units = "W/m2" ;
		D:long_name = "dissipation" ;
	double DR(globaltime, globaly, globalx) ;
		DR:coordinates = "globalx globaly" ;
		DR:units = "W/m2" ;
		DR:long_name = "roller energy dissipation" ;
	double meantime(meantime) ;
		meantime:units = "s" ;
		meantime:axis = "T" ;
		meantime:standard_name = "time" ;
	double H_mean(meantime, globaly, globalx) ;
		H_mean:coordinates = "globalx globaly" ;
		H_mean:units = "m" ;
		H_mean:long_name = "Hrms wave height based on instantaneous wave energy" ;
		H_mean:cell_methods = "meantime: rms" ;
	double H_var(meantime, globaly, globalx) ;
		H_var:coordinates = "globalx globaly" ;
		H_var:units = "m" ;
		H_var:long_name = "Hrms wave height based on instantaneous wave energy" ;
		H_var:cell_methods = "meantime: var" ;
	double H_min(meantime, globaly, globalx) ;
		H_min:coordinates = "globalx globaly" ;
		H_min:units = "m" ;
		H_min:long_name = "Hrms wave height based on instantaneous wave energy" ;
		H_min:cell_methods = "meantime: min" ;
	double H_max(meantime, globaly, globalx) ;
		H_max:coordinates = "globalx globaly" ;
		H_max:units = "m" ;
		H_max:long_name = "Hrms wave height based on instantaneous wave energy" ;
		H_max:cell_methods = "meantime: max" ;
	double zs_mean(meantime, globaly, globalx) ;
		zs_mean:coordinates = "globalx globaly" ;
		zs_mean:units = "m" ;
		zs_mean:standard_name = "sea_surface_height_above_sea_level" ;
		zs_mean:long_name = "water level" ;
		zs_mean:cell_methods = "meantime: mean" ;
	double zs_var(meantime, globaly, globalx) ;
		zs_var:coordinates = "globalx globaly" ;
		zs_var:units = "m" ;
		zs_var:standard_name = "sea_surface_height_above_sea_level" ;
		zs_var:long_name = "water level" ;
		zs_var:cell_methods = "meantime: var" ;
	double zs_min(meantime, globaly, globalx) ;
		zs_min:coordinates = "globalx globaly" ;
		zs_min:units = "m" ;
		zs_min:standard_name = "sea_surface_height_above_sea_level" ;
		zs_min:long_name = "water level" ;
		zs_min:cell_methods = "meantime: min" ;
	double zs_max(meantime, globaly, globalx) ;
		zs_max:coordinates = "globalx globaly" ;
		zs_max:units = "m" ;
		zs_max:standard_name = "sea_surface_height_above_sea_level" ;
		zs_max:long_name = "water level" ;
		zs_max:cell_methods = "meantime: max" ;

// global attributes:
		:Conventions = "CF-1.4" ;
		:Producer = "XBeach littoral zone wave model (http://www.xbeach.org)" ;
		:Build-Revision = "2231" ;
		:Build-Date = "Mon Aug 29 08:34:00 CEST 2011" ;
		:URL = "URL: https://repos.deltares.nl/repos/XBeach/trunk" ;
}