Project

General

Profile

Getting timesteps of dates in CDO

Added by Lyndon Mark Olaguera over 5 years ago

Hi CDO-experts,

Is there a way to extract the timestep of a specified date, then save it to a text file in CDO?

For example, I would like to get the time step for the date: 1991-05-01
I have the following command:

cdo seldate,1991-05-01 uwnd.1991.nc

The available commands for the 'show' command are:

showatts showdate showltype showstdname showtime showtimestamp

If I use the showtimestamp (i.e., cdo showtimestamp -seldate,1991-05-01 uwnd.1991.nc)
This gives the following:

cdo(2) seldate: Process started
1991-05-01T00:00:00
cdo(2) seldate: Processed 178704 values from 1 variable over 122 timesteps
cdo showtimestamp: Processed 1 variable [0.26s 12MB]

The correct time step should be 121.

Is there any available command to do this?then save to a text/csv file?

I'll appreciate any support
Lyndz


Replies (8)

RE: Getting timesteps of dates in CDO - Added by Ralf Mueller over 5 years ago

hi!

to get this clear: you want to have the number of a specific timestep in the input file?

RE: Getting timesteps of dates in CDO - Added by Lyndon Mark Olaguera over 5 years ago

Hi Ralf,

Yes. I'd like to get the correct time step number.

RE: Getting timesteps of dates in CDO - Added by Ralf Mueller over 5 years ago

try this

cdo -s -outputtab,nohead,timestep,date <input> | grep '1991-05-01' | sed -e 's/[ ]\+/ /g' | cut -f 2 -d ' '

hth
ralf

RE: Getting timesteps of dates in CDO - Added by Lyndon Mark Olaguera over 5 years ago

Hi Ralf,

Thank you for this. I am not sure why I am getting 28 rows of 121 when I saved this to a text file.

RE: Getting timesteps of dates in CDO - Added by Ralf Mueller over 5 years ago

I guess this is the point where I NEED the input for a proper answer. Can you upload it?

RE: Getting timesteps of dates in CDO - Added by Lyndon Mark Olaguera over 5 years ago

Hi Ralf,

Here's the link to the file:

https://www.dropbox.com/s/3rvxa4kp6qz0bjo/uwnd.1991.nc?dl=0

Thank you so much for your help.

RE: Getting timesteps of dates in CDO - Added by Ralf Mueller over 5 years ago

I use this

% date=1991-05-01
% cdo -s -outputtab,nohead,timestep,date -sellevidx,1 -selindexbox,1,1,1,1 uwnd.1991.nc | grep $date
     121  1991-05-01 

selecting the first level and the first grid point speeds up the while thing a lot. This is also the reason, why you get multiple lines with the same results: outputtab operators loops over all levels and all grid point. When I add the remaining code with sed and cut I get the results directly:
% cdo -s -outputtab,nohead,timestep,date -sellevidx,1 -selindexbox,1,1,1,1 uwnd.1991.nc | grep $date | sed -e 's/[ ]\+/ /g' | cut -f 2 -d ' '

121


Instead of selecting first level and grid point (like above) you could also add sort -u to the command line, but this would only take longer with the same results.

hth
ralf

RE: Getting timesteps of dates in CDO - Added by Lyndon Mark Olaguera over 5 years ago

Hi Ralf,

Thank you so much for your help.

    (1-8/8)