netcdfncocdo-climatencks

nco cut daily netcdf file to 10 minute files


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!


Solution

  • 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