I have a directory of NetCDF files with names of the following format:
foo_d1_t1.nc
foo_d1_t2.nc
foo_d1_t3.nc
foo_d1_t4.nc
foo_d2_t1.nc
foo_d2_t2.nc
foo_d2_t3.nc
foo_d2_t4.nc
...
where "d" refers to the day and "t" to the timestep.
The files contain accumulated values since the start of the day, which I need to convert to an average rate per timestep by subtracting t1 from t2, t2 from t3 and t3 from t4 for each day. Individually this can be achieved through ncdiff, which for one day would look like this:
cp foo_d1_t1.nc bar_d1_t1.nc #t1 needs no modification
ncdiff foo_d1_t2.nc foo_d1_t1.nc bar_d1_t2.nc
ncdiff foo_d1_t3.nc foo_d1_t2.nc bar_d1_t3.nc
ncdiff foo_d1_t4.nc foo_d1_t3.nc bar_d1_t4.nc
Can anyone assist with a shell script to automate this for all days present in a directory? Cheers.