1NCDIFF(1)                   General Commands Manual                  NCDIFF(1)
2
3
4

NAME

6       ncdiff - netCDF Differencer
7

SYNTAX

9       ncdiff  [-A]  [-C] [-c] [-D dbg] [-d dim,[ min][,[ max]]] [-F] [-h] [-l
10       path] [-O] [-p path] [-R]  [-r]  [-v  var[,...]]   [-x]  file_1  file_2
11       file_3
12

DESCRIPTION

14       ncdiff  subtracts  variables in file_2 from the corresponding variables
15       (those with the same name) in file_1 and stores the results in  file_3.
16       Variables in file_2 are broadcast to conform to the corresponding vari‐
17       able in file_1 if necessary.  Broadcasting a  variable  means  creating
18       data  in  non-existing dimensions from the data in existing dimensions.
19       For example, a two dimensional variable in  file_2  can  be  subtracted
20       from  a  four, three, or two (but not one or zero) dimensional variable
21       (of the same name) in file_1.  This functionality allows  the  user  to
22       compute anomalies from the mean.  Note that variables in file_1 are not
23       broadcast to conform to the dimensions in file_2.   Thus,  ncdiff,  the
24       number of dimensions, or rank, of any processed variable in file_1 must
25       be greater than or equal to the rank of the same  variable  in  file_2.
26       Furthermore,  the  size  of  all  dimensions  common to both file_1 and
27       file_2 must be equal.
28
29       When computing anomalies from the mean it is often the case that file_2
30       was  created  by applying an averaging operator to a file with the same
31       dimensions as file_1, if not file_1 itself.  In these  cases,  creating
32       file_2  with  ncra  rather than ncwa will cause the ncdiff operation to
33       fail.  For concreteness say the record dimension in file_1 is time.  If
34       file_2  were  created  by averaging file_1 over the time dimension with
35       the ncra operator rather than with the ncwa operator, then file_2  will
36       have a time dimension of size 1 rather than having no time dimension at
37       all In this case the input files to ncdiff,  file_1  and  file_2,  will
38       have  unequally  sized time dimensions which causes ncdiff to fail.  To
39       prevent this from occuring, use ncwa to remove the time dimension  from
40       file_2.  An example is given below.
41
42       ncdiff  will never difference coordinate variables or variables of type
43       NC_CHAR or NC_BYTE.  This ensures that coordinates like (e.g., latitude
44       and  longitude)  are  physically meaningful in the output file, file_3.
45       This behavior is hardcoded.  ncdiff applies special rules to some  NCAR
46       CSM  fields  (e.g.,  ORO).   See  NCAR  CSM  Conventions for a complete
47       description.  Finally, we note that ncflint (ncflint netCDF File Inter‐
48       polator)  can  be  also  perform file subtraction (as well as addition,
49       multiplication and interpolation).
50

EXAMPLES

52       Say files 85_0112.nc and 86_0112.nc each contain  12  months  of  data.
53       Compute the change in the monthly averages from 1985 to 1986:
54              ncdiff 86_0112.nc 85_0112.nc 86m85_0112.nc
55
56       The  following examples demonstrate the broadcasting feature of ncdiff.
57       Say we wish to compute the monthly anomalies of T from the yearly aver‐
58       age  of T for the year 1985.  First we create the 1985 average from the
59       monthly data, which is stored with the record dimension time.
60              ncra 85_0112.nc 85.nc
61              ncwa -O -a time 85.nc 85.nc
62       The second command, ncwa, gets rid of the time dimension of size 1 that
63       ncra  left  in  85.nc.   Now  none of the variables in 85.nc has a time
64       dimension.  A quicker way to accomplish this is to use  ncwa  from  the
65       beginning:
66              ncwa -a time 85_0112.nc 85.nc
67       We are now ready to use ncdiff to compute the anomalies for 1985:
68              ncdiff -v T 85_0112.nc 85.nc t_anm_85_0112.nc
69       Each  of  the  12  records in t_anm_85_0112.nc now contains the monthly
70       deviation of T from the annual mean of T for each gridpoint.
71
72       Say we wish to compute the monthly gridpoint anomalies from  the  zonal
73       annual  mean.   A  zonal mean is a quantity that has been averaged over
74       the longitudinal (or x) direction.  First we use ncwa to  average  over
75       longitudinal  direction  lon,  creating  xavg_85.nc,  the zonal mean of
76       85.nc.  Then we use ncdiff to subtract the zonal annual means from  the
77       monthly gridpoint data:
78              ncwa -a lon 85.nc xavg_85.nc
79              ncdiff 85_0112.nc xavg_85.nc tx_anm_85_0112.nc
80       Assuming  85_0112.nc  has  dimensions  time  and lon, this example only
81       works if xavg_85.nc has no time or lon dimension.
82
83       As a final example, say we have five years of monthly  data  (i.e.,  60
84       months)  stored in 8501_8912.nc and we wish to create a file which con‐
85       tains the twelve month seasonal cycle of the  average  monthly  anomaly
86       from the five-year mean of this data.  The following method is just one
87       permutation of many which will accomplish the same result.   First  use
88       ncwa to create the file containing the five-year mean:
89              ncwa -a time 8501_8912.nc 8589.nc
90       Next  use  ncdiff  to  create  a file containing the difference of each
91       month's data from the five-year mean:
92              ncdiff 8501_8912.nc 8589.nc t_anm_8501_8912.nc
93       Now use ncks to group the five January anomalies together in one  file,
94       and  use  ncra  to  create  the  average anomaly for all five Januarys.
95       These commands are embedded in a shell loop so they  are  repeated  for
96       all twelve months:
97              foreach idx (01 02 03 04 05 06 07 08 09 10 11 12)
98              ncks -F -d time,,,12 t_anm_8501_8912.nc foo.
99              ncra foo. t_anm_8589_.nc
100              end
101       Note  that  ncra  understands  the  stride argument so the two commands
102       inside the loop may be combined into the single command
103              ncra -F -d time,,,12 t_anm_8501_8912.nc foo.
104       Finally, use ncrcat to concatenate the 12 average monthly anomaly files
105       into one twelve-record file which contains the entire seasonal cycle of
106       the monthly anomalies:
107              ncrcat t_anm_8589_??.nc t_anm_8589_0112.nc
108
109

AUTHOR

111       NCO manual pages written by Charlie Zender and Brian Mays.
112
113

REPORTING BUGS

115       Report bugs to <http://sf.net/bugs/?group_id=3331>.
116
117
119       Copyright © 1995-2004 Charlie Zender
120       This is free software; see the source for copying conditions.  There is
121       NO  warranty;  not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
122       PURPOSE.
123
124

SEE ALSO

126       The full documentation for NCO is maintained as a Texinfo manual called
127       the NCO User's Guide.  Because NCO is mathematical in nature, the docu‐
128       mentation includes TeX-intensive portions not  viewable  on  character-
129       based  displays.  Hence the only complete and authoritative versions of
130       the NCO User's Guide are the PDF  (recommended),  DVI,  and  Postscript
131       versions  at  <http://nco.sf.net/nco.pdf>, <http://nco.sf.net/nco.dvi>,
132       and <http://nco.sf.net/nco.ps>, respectively.  HTML  and  XML  versions
133       are       available       at      <http://nco.sf.net/nco.html>      and
134       <http://nco.sf.net/nco.xml>, respectively.
135
136       If the info and NCO programs are properly installed at your  site,  the
137       command
138
139              info nco
140
141       should  give  you  access  to  the complete manual, except for the TeX-
142       intensive portions.
143
144

HOMEPAGE

146       The NCO homepage at <http://nco.sf.net> contains more information.
147
148
149
150                                                                     NCDIFF(1)
Impressum