Project

General

Profile

Deleting dates based on timesteps

Added by Lyndon Mark Olaguera over 4 years ago

Dear CDO experts,

I want to delete specific dates that are listed in a text file and with the following format: YYYY-MM-DD.

According to this post: https://code.mpimet.mpg.de/boards/2/topics/2169
One can only delete dates using the time steps.

So, I tried to extract first the timesteps after reading the dates from the text file.
My code is as follows using bash:

for y in 1979

do
input="withrain_${y}.txt" 
while IFS= read -r line
 do
  echo "$line" 
  cdo delete,timestep=$(cdo -s -outputtab,nohead,timestep,$line -selname,precip ../aphro_$y_AMJ.nc | grep $line | sed -e 's/[ ]\+/ /g' | cut -f 2 -d ' ') aphro_${y}_AMJ.nc norain_${y}_AMJ.nc
 done < "$input" 
done

I am getting the following errors:

cdo outputtab (Abort): Key 1979-04-18 unsupported!

Attached are the input NetCDF and text file.

I'll appreciate any guidance on how to do this correctly in CDO.

Sincerely,
Lyndz

aphro_1979_AMJ.nc (30.8 MB) aphro_1979_AMJ.nc Input NetCDF file
withrain_1979.txt (55 Bytes) withrain_1979.txt Input text file with dates

Replies (1)

RE: Deleting dates based on timesteps - Added by Karin Meier-Fleischer over 4 years ago

Hi Lyndon,

try

infile=aphro_1979_AMJ.nc
datesfile=withrain_1979.txt

dates=$(cat $datesfile | xargs echo | sed -e 's/ /,/g')

cdo delete,date=${dates} -selname,precip $infile tmp.nc

-Karin
    (1-1/1)