Learning by doing.
NCO is a convenient command line tool to modify NetCDF files. Several frequently used examples will be listed in this post.
Merge different files with the same variables but different time spans
ncrcat file1.nc file2.nc file3.nc output.nc
Append a variable from one file to another file
ncks -h -A file1.nc file2.nc # so that the variables in file1 will be appended to file2
Calculations of variables
ncap2 -s "var3=(var1+var2)*1000" -v file1.nc output.nc # var1 and var2 are from file1.nc, and output.nc contains only var3
Modify meta information
ncatted -a units,pr,m,c,'mm/sec' file1.nc # modify the units of the variable pr in file1.nc to be 'mm/sec' ncatted -a long_name,pr,o,c,'(PRECC+PRECL)*1000' file1.nc # modify the long_name of the variable pr in file1.nc to be '(PRECC+PRECL)*1000'
Modify variable name
Below is an example from this webpage:
Rename the variable p to pressure and t to temperature in netCDF in.nc. In this case p must exist in the input file (or ncrename will abort), but the presence of t is optional:
ncrename -v p,pressure -v .t,temperature in.nc