Project

General

Profile

select date with a condition

Added by Álvaro Sánchez almost 5 years ago

Hi everyone.
I have a file with dates,for each date i have a 1 or a 0,how can I save in other file the dates with a 1?
Thank you very much


Replies (3)

RE: select date with a condition - Added by Ralf Mueller almost 5 years ago

hi!

That sounds somewhat awkward to me - can you uploads some sample data??

cheers
ralf

RE: select date with a condition - Added by Álvaro Sánchez almost 5 years ago

Hi Ralf,happy to talk with you again.
Here I have in prueba1.nc a single point where I have 1 (for dust rain) and a 0 (no dust rain) for each day,and I need a file that tell me the dates where I have a 1,something like 2003-02-05,2003-02-12,2003-04-02...
And I need to do it with cdo.
Thank you very much

RE: select date with a condition - Added by Ralf Mueller almost 5 years ago

hola Alvaro!

this is a common problem, that exceeds the CF-convention because dates like '2003-02-05' are not proper values of a data variable according to CF. But since you have on one location in your grid there might be an easy solution:

cdo -outputkey,value,date `lf` | grep -F ' 1 ' | sed 's/[ ]\+/ /g' | cut -d ' ' -f 3
prints all dates with value 1. Just replace '1' with '0' for the complementary dates. In case you need a comma separated list:
cdo -s outputkey,value,date `lf` | grep -F ' 1 ' | sed 's/[ ]\+/ /g' | cut -d ' ' -f 3 | perl -pi -e 's/\n/,/g' 2>>/dev/null
The only issue is the final comma, but that does not harm if you use the select operator afterwards:
date=$(cdo -s outputkey,value,date prueba1.nc | grep -F ' 1 ' | sed 's/[ ]\+/ /g' | cut -d ' ' -f 3 | perl -pi -e 's/\n/,/g' 2>>/dev/null)
cdo -seldate=$date prueba1.nc dateAccordingToValue_1.nc

There might be shorter solutions for this scripting, but I tend to combine the stuff I know until I get the result I want. If you know a shorter solution, please let me know.

hth
ralf

    (1-3/3)