2
votes

I have a daily netcdf file (20060101) and the time dimension has 144 steps, so 10 minutes time steps within the file. Now I want to create one netcdf file for each 10 min time step with nco. So at the end it should create 144 files.

I already found similar questions where they use

ncks -d time,min,max,stride infile.nc outfile.nc

But I don't know how to write a code creating these 144 files. Can someone help me with this? Thanks for your help!

2
What have you tried and where is it failing? Are you familiar with for loops? You are more likely to get help after showing us your attempt, rather than ask for someone else to write the code for you.N1B4

2 Answers

2
votes

Found Solution:

start=1131580800 # first time step in seconds
for f in *_test.nc; do #$files
    echo 'Processing' $f 
    for i in {0..17}; do
    time=$(expr $start + 600 \* $i)                   #  calculates the next time step --> 600s correspond to 10 minute steps I wanted to have
    time_new=$(date -d @$time '+_%H%M')               # extracting the time variable from my file and convert it to use them in the file names
    outfile=$(echo $f|sed "s/_level2/$time_new/g")
    ncks -d time,$i,$i $f $outfile                    # split my original file to 10 min steps
    done
done
2
votes

I haven't tested it but I think you can do it with one line in CDO:

cdo splitsel,1 input.nc output

The "1" means split the file with 1 timestep in each output file, which I think is what you were asking for.