I am a very beginner of nco, and I want to split my .nc file (from 1996010110 to 2019123110) as daily file, from 10AM to 10PM. In that case, each split file contains YYYY-MM-DD:10:00
to YYYY-MM-(DD+1):10:00
. Note that the end hour of DD day is repeated in the beginning of next day. That is the data of YYYY-MM-DD:10:00
occurs twice in file_YYYY_MM_DD.nc
as the starting data and also the ending data of file_YYYY_MM_(DD-1).nc
.
Thanks!
The way to do this in NCO is to wrap a loop over time around use the sub-cycling form of the hyperslabber to eliminate the dupicate timestamps then loop over the days to create each file similar to this documented example here. For input where the first desired record is index 10, the last desired index is unbounded, the number of records in a repeating series (i.e., the stride between groups) is 25, and the number of consecutive desired records (the desired subset of a group) is 24, the first command would like this:
ncrcat -d time,10,,25,24 in.nc out.nc
Then out.nc
will contain thousands of days of data with no repeated timesteps, and you can split that file into daily files however you like, including with ncrcat
wrapped in a loop something like
EDIT 20210924: Based on clarification below you can ignore the above part of this message and proceed directly to this loop, which has been modified to extract 25 timesteps per day.
for yr in {1996..2019}; do
for mth in {1..12}; do
for day in {1..${dpm[mth]}}; do # Days-per-month array exercise left for the reader :)
yyyy=`printf "%04d" $yr`
mm=`printf "%02d" $mth`
dd=`printf "%02d" $day`
ncrcat -d time,${yyyy}-${mm}-${dd}T10:00:00,${yyyy}-${mm}-${ddp1}T10:00:00 out.nc file_${yyyy}_${mm}_${dd}.nc
done
done
done