Blog

  • Handling netcdf file format

This page contains simple commands that I use to handle NetCDF data in different tools. This page will be updated as I will stumble upon on to new commands:

(1) Bash commands:

See data that nc file contains: ncdump file.nc

See only header of the data: ncdump -c file.nc (great for if you only want see the file information)

Compress nc data by removing unlimited time dimension and make file smaller: nccopy -u -s -d6 file.nc file_compressed.nc


(2) CDO:

Concatenate all nc files in a directory: cdo cat *.nc merged_file.nc

Shift Longitude of data from 0:360 to -180:180: cdo sellonlatbox,-180,180,-90,90 input.nc output.nc

Convert grib to nc: cdo -f nc copy file.grb file.nc

Merge datasets with the same number of timesteps and different variables in each dataset: cdo merge infile1.nc infile2.nc infile3.nc outfile.nc

Convert variable ts by subtraction from K to C: cdo expr,’var1=ts-273.15;’ ifile.nc ofile.nc