Creating a loop to use cdo commands
Added by Mudit Mudit almost 3 years ago
Hello everyone,
I'm trying to Create a loop to use cdo commands.
the script file is attached here alongwith data sample files.
I tried to write bash sh script file and inside that i wanted to create multiple loops that will:
1st loop will run to open and execute different time step number from t1 to t5 and also to create different temporary folders in which various files are created and removed after final processing is done.
2nd loop will run to read and execute different years from file name (which was helped by Ralf Muller earlier)
3rd loop will run to change the "seltimestep" i.e. for 1st file, the seltimestep,1/12; for 2nd file, the seltimestep,23/24; similarly for 5th file, the seltimestep,49/60.
here is the code of the script file that i tried to make:
#!/bin/bash
tmpdir=./tmp5
mkdir p $tmpdir$((year+9))12.nc $tmpdir/series${year}.nc
for year in $(seq -w 1961 2014) ; do
echo $year
cdo -seltimestep,49/60 pr_Amon_BCC-CSM2-MR_dcppA-hindcast_s${year}-r1i1p1f1_gn_${year}01
done
cd $tmpdir
cdo mergetime '*.nc' series_s1961_t5.nc
cdo remapbil,/run/media/user20/data_cmip6/newgrid1deg.txt series_s1961_t5.nc series_s1961_t5_pr.nc
cdo -ymonsub series_s1961_t5_pr.nc -ymonmean series_s1961_t5_pr.nc series_s1961_t5_BCC-CSM2-MR_pr_anom.nc
cdo sellonlatbox,70,90,10,30 series_s1961_t5_BCC-CSM2-MR_pr_anom.nc series_s1961_t5_BCC-CSM2-MR_pr_ismr.nc
cdo fldavg series_s1961_t5_BCC-CSM2-MR_pr_ismr.nc series_s1961_t5_BCC-CSM2-MR_pr_ismr_index.nc
rm -rf series_s1961_t5_BCC-CSM2-MR_pr_ismr.nc
rm -rf series_s1961_t5_BCC-CSM2-MR_pr_anom.nc
rm -rf series_s1961_t5_pr.nc
exit 0
Thanks in advance for help!