---
name: "ncbo"
section: "1"
platform: "linux"
package: "nco"
version: "5.3.3-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/ncbo"
---

# ncbo(1)

netCDF Binary Operator

## NAME

ncbo - netCDF Binary Operator

## SYNTAX

ncbo \[-3\] \[-4\] \[-5\] \[-6\] \[-7\] \[-A\] \[--bfr *sz\_byt*\]*\[-C\]*\[-c\] \[--cmp *cmp\_sng*\] \[--cnk\_byt *sz\_byt*\]*\[--cnk\_csh* *sz\_byt*\]*\[--cnk\_dmn* *nm,sz\_lmn*\] \[--cnk\_map  *map*\] \[--cnk\_min *sz\_byt*\] \[--cnk\_plc  *plc*\] \[--cnk\_scl  *sz\_lmn*\]*\[-D* *dbg\_lvl*\] \[-d  *dim*,\[ *min*\]\[,\[ *max*\]\]\] \[-F\] \[--fl\_fmt=fmt\] \[-G *gpe\_dsc*\] \[-g   *grp*\[,...\]\] \[--glb *att\_name=* *att\_val*\]\] \[-H\] \[-h\] \[--hdf\] \[--hdr\_pad *sz\_byt*\]*\[--hpss\_try\]* \[-L  *dfl\_lvl*\] \[-l  *path*\] \[--msa\] \[--no\_cll\_msr\] \[--no\_frm\_trm\] \[--no\_tmp\_fl\] \[-O\] \[-p  *path*\] \[--qnt *var1*\[, *var2*\[,...\]\]= *prc*\]\] \[--qnt\_alg *alg\_nm\]* \[-R\] \[-r\] \[--ram\_all\] \[-t *thr\_nbr*\] \[--uio\] \[--unn\] \[-v  *var*\[,...\]\] \[-X  *box*\] \[-x\]  *file\_1* *file\_2* *file\_3*

## DESCRIPTION

**ncbo** subtracts variables in  *file\_2* from the corresponding variables (those with the same name) in  *file\_1* and stores the results in  *file\_3*. Variables in  *file\_2* are  *broadcast* to conform to the corresponding variable in  *file\_1* if necessary.   Broadcasting a variable means creating data in non-existing dimensions from the data in existing dimensions. For example, a two dimensional variable in  *file\_2* can be subtracted from a four, three, or two (but not one or zero) dimensional variable (of the same name) in  **file\_1**. This functionality allows the user to compute anomalies from the mean. Note that variables in  *file\_1* are *not* broadcast to conform to the dimensions in  *file\_2*. Thus,  **ncbo**, the number of dimensions, or  *rank*, of any processed variable in  *file\_1* must be greater than or equal to the rank of the same variable in  *file\_2*. Furthermore, the size of all dimensions common to both  *file\_1* and *file\_2* must be equal.

When computing anomalies from the mean it is often the case that *file\_2* was created by applying an averaging operator to a file with the same dimensions as  *file\_1*, if not  *file\_1* itself. In these cases, creating  *file\_2* with  **ncra** rather than **ncwa** will cause the  **ncbo** operation to fail. For concreteness say the record dimension in  **file\_1** is **time**. If  *file\_2* were created by averaging  *file\_1* over the **time** dimension with the  **ncra** operator rather than with the **ncwa** operator, then  *file\_2* will have a  **time** dimension of size 1 rather than having no  **time** dimension at all  In this case the input files to  **ncbo**, *file\_1* and *file\_2*, will have unequally sized  **time** dimensions which causes  **ncbo** to fail. To prevent this from occurring, use  **ncwa** to remove the  **time** dimension from  *file\_2*. An example is given below.

**ncbo** will never difference coordinate variables or variables of type  **NC\_CHAR** or  **NC\_BYTE**. This ensures that coordinates like (e.g., latitude and longitude) are physically meaningful in the output file,  *file\_3*. This behavior is hardcoded. **ncbo** applies special rules to some NCAR CSM fields (e.g., **ORO**). See *NCAR CSM Conventions* for a complete description. Finally, we note that  **ncflint** (ncflint netCDF File Interpolator) can be also perform file subtraction (as well as addition, multiplication and interpolation).

## EXAMPLES

Say files  **85\_0112.nc** and  **86\_0112.nc** each contain 12 months of data. Compute the change in the monthly averages from 1985 to 1986:

ncbo 86\_0112.nc 85\_0112.nc 86m85\_0112.nc

The following examples demonstrate the broadcasting feature of **ncbo**. Say we wish to compute the monthly anomalies of  **T** from the yearly average of  **T** for the year 1985. First we create the 1985 average from the monthly data, which is stored with the record dimension  **time**.

ncra 85\_0112.nc 85.nc\
 ncwa -O -a time 85.nc 85.nc

The second command,  **ncwa**, gets rid of the  **time** dimension of size 1 that  **ncra** left in  **85.nc**. Now none of the variables in  **85.nc** has a  **time** dimension. A quicker way to accomplish this is to use  **ncwa** from the beginning:

ncwa -a time 85\_0112.nc 85.nc

We are now ready to use  **ncbo** to compute the anomalies for 1985:

ncbo -v T 85\_0112.nc 85.nc t\_anm\_85\_0112.nc

Each of the 12 records in  **t\_anm\_85\_0112.nc** now contains the monthly deviation of  **T** from the annual mean of  **T** for each gridpoint.

Say we wish to compute the monthly gridpoint anomalies from the zonal annual mean.  A  *zonal mean* is a quantity that has been averaged over the longitudinal (or  *x*) direction. First we use  **ncwa** to average over longitudinal direction **lon**, creating  **xavg\_85.nc**, the zonal mean of  **85.nc**. Then we use  **ncbo** to subtract the zonal annual means from the monthly gridpoint data:

ncwa -a lon 85.nc xavg\_85.nc\
 ncbo 85\_0112.nc xavg\_85.nc tx\_anm\_85\_0112.nc

Assuming  **85\_0112.nc** has dimensions  **time** and  **lon**, this example only works if  **xavg\_85.nc** has no  **time** or **lon** dimension.

As a final example, say we have five years of monthly data (i.e., 60  months) stored in  **8501\_8912.nc** and we wish to create a file which contains the twelve month seasonal cycle of the average monthly anomaly from the five-year mean of this data.  The following method is just one permutation of many which will accomplish the same result. First use  **ncwa** to create the file containing the five-year mean:

ncwa -a time 8501\_8912.nc 8589.nc

Next use  **ncbo** to create a file containing the difference of each month's data from the five-year mean:

ncbo 8501\_8912.nc 8589.nc t\_anm\_8501\_8912.nc

Now use  **ncks** to group the five January anomalies together in one  file, and use  **ncra** to create the average anomaly for all five Januarys.  These commands are embedded in a shell loop so they are repeated for all twelve months:

foreach idx (01 02 03 04 05 06 07 08 09 10 11 12) \
 ncks -F -d time,,,12 t\_anm\_8501\_8912.nc foo.\
 ncra foo. t\_anm\_8589\_.nc\
 end

Note that  **ncra** understands the  **stride** argument so the two commands inside the loop may be combined into the single command

ncra -F -d time,,,12 t\_anm\_8501\_8912.nc foo.

Finally, use  **ncrcat** to concatenate the 12 average monthly anomaly files into one twelve-record file which contains the entire seasonal cycle of the monthly anomalies:

ncrcat t\_anm\_8589\_??.nc t\_anm\_8589\_0112.nc

## AUTHOR

**NCO** manual pages written by Charlie Zender and originally formatted by Brian Mays.

## REPORTING BUGS

Report bugs to \<http://sf.net/bugs/?group\_id=3331\>.

## COPYRIGHT

Copyright © 1995-present Charlie Zender\
 This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

## SEE ALSO

The full documentation for **NCO** is maintained as a Texinfo manual called the  **NCO Users Guide.** Because  **NCO** is mathematical in nature, the documentation includes TeX-intensive portions not viewable on character-based displays.  Hence the only complete and authoritative versions of the  **NCO Users Guide** are the PDF (recommended), DVI, and Postscript versions at \<http://nco.sf.net/nco.pdf\>, \<http://nco.sf.net/nco.dvi\>, and \<http://nco.sf.net/nco.ps\>, respectively. HTML and XML versions are available at \<http://nco.sf.net/nco.html\> and \<http://nco.sf.net/nco.xml\>, respectively.

If the **info** and **NCO** programs are properly installed at your site, the command

-

  **info nco**

should give you access to the complete manual, except for the TeX-intensive portions.

## HOMEPAGE

The  **NCO** homepage at \<http://nco.sf.net\> contains more information.
