I have a NetCDF file, here is a truncated output of ncdump -h
:
dimensions:
lat = 720 ;
lon = 1440 ;
cft = 64 ;
natpft = 14 ;
double PCT_CFT(cft, lat, lon) ;
PCT_CFT:long_name = "percent cft" ;
PCT_CFT:units = "unitless" ;
PCT_CFT:_FillValue = -9999. ;
PCT_CFT:coordinates = "LON LAT" ;
double PCT_NAT_PFT(natpft, lat, lon) ;
PCT_NAT_PFT:long_name = "percent pft" ;
PCT_NAT_PFT:units = "unitless" ;
PCT_NAT_PFT:_FillValue = -9999. ;
PCT_NAT_PFT:coordinates = "LON LAT" ;
What I need is to extract and sum values from the variable PCT_CFT
for the layers 3, 4, 61 and 62 along the dimension cft
and then sum up almost all the remaining layers (ie. 5-60, 63, 64) and add these two results to the variable PCT_NAT_PFT
as layers 16 and 15 along the dimension natpft
respectively.
I would like to achieve this using NCO (or CDO) if possible, I want to avoid using other tools like Python or R... I only know how to sum up the variable across the whole dimension but not across selected layers only - I could therefore probably work around this problem, but I'd like to know if there's a better and cleaner way to do so.