selyear loop
Added by Jonathan Tinsley over 1 year ago
Hi,
I want to select a particular year from my nc files using selyear.
The code that works for me for one file is:
cdo selyear,1986 Tmax.1986.nc Tmax.1986.365.nc
How can I loop this over multiple files in my directory ranging from 1986 to 2015 please?
Many thanks,
Jonathan
Replies (3)
RE: selyear loop - Added by Estanislao Gavilan over 1 year ago
Hi Jonathan
it depends on the loop mothod. I like to the things via bash script. You can do it like this
for n in {1986..2015}
do
filein= 'Tmax.'$n'.nc'
fileout='Tmax.'$n'.365.nc'
cdo selyear,$n filein fileout
done
Then, this script can even be more complex depending on your needs. Take a look on internet youc an find many bash script
Kind regards
Estanislao
RE: selyear loop - Added by Karin Meier-Fleischer over 1 year ago
Or you can use the splityear operator.
RE: selyear loop - Added by Jonathan Tinsley over 1 year ago
Dear Estanislao and Karina,
Thank you very much for your assistance. I am new to this form of coding, so this information and advice is very useful for me.
Best regards
Jonathan