Outputtab with a condition (constant)
Added by S BR over 6 years ago
Dear Users,
I have an one-dimensional annual mean surface temperature data for 500 years.
I can extract the years and values from the given time series with the following syntax.
cdo outputtab,year,value ts_yearmean.nc > output.txt
However, I would like to use a condition to select the only years that are value greater than a constant (ex: 28 C).
Is it possible to use a condition along with outputtab.
Thank you.
S
Replies (15)
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Hi,
cdo outputtab,year,value -expr,'ts=((ts > 28.0)) ? ts : 0' ts_yearmean.nc | awk '$2!=0' > output.txt-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
The said syntax worked fine. However, I want the output as only the years and not the values (the years based on the conditions of the values). I can delete the value column but it takes a lot of time.
I tried to modify the syntax but couldn't success.
Thanks for your time.
S
RE: Outputtab with a condition (constant) - Added by Ralf Mueller over 6 years ago
pad this
| sed -e 's/\s$//' | rev | cut -d ' ' -f 1 | revto the awk command before re directing it to the text file
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Do I understand it right that you only want to write the years without any other variable value output to a file? Then write only the year with the output operator.
cdo outputtab,year -expr,'ts=((ts > 28.0)) ? ts : 0' ts_yearmean.nc | awk '$2!=0' > output.txt-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
You understood it correct but the given syntax writes all the 500 years in the output file.
I need only the list of years that have values greater than 28.0.
Thanks.
S
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Dear Ralf,
Thanks for your reply. Your syntax gives only the values instead of years.
I need only the list of years that have values greater than 28.0.
Thanks.
S
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
cdo outputtab,year,value -expr,'ts=((ts > 28.0)) ? ts : 0' ts_yearmean.nc | awk '$2!=0' | cut -d " " -f 1 > output.txt-Karin
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Sorry, I've corrected the last answer it must be outputtab,year,value
cdo outputtab,year,value -expr,'ts=((ts > 28.0)) ? ts : 0' ts_yearmean.nc | awk '$2!=0' | cut -d " " -f 1 > output.txt-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
Thanks for your suggestions. Now the output file is completely blank with the given syntax.
It has required number of lines in the output file but it doesn't contain any data (list of years).
Thanks.
S
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Ok, then I need your data file because with my data everything works fine.
Which CDO version are you using? Send the output of 'cdo -V'.
-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
Please find herewith attached my data with variable name 'tos'. Now I am using an anomaly series, so I want to use the threshold value greater than 1.0 (instead of 28.0 earlier).
I am using the following syntax.
cdo outputtab,year,value -expr,'tos=((tos > 1.0)) ? tos : 0' ts_yearmean.nc | awk '$2!=0' | cut -d " " -f 1 > output.txt
I am using CDO version 1.9.5
Thank you.
S
ts_yearmean.nc (7.82 KB) ts_yearmean.nc |
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Did you have a look at your data? The variable name is tos and not ts and if you want to see only values which are above 28.0 then there's no value!
cdo infov ts_yearmean.nc -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 0900-01-01 00:00:00 0 1 0 : -1.3707 : tos 2 : 0901-01-01 00:00:00 0 1 0 : -1.1753 : tos 3 : 0902-01-01 00:00:00 0 1 0 : -0.96291 : tos 4 : 0903-01-01 00:00:00 0 1 0 : -0.74008 : tos 5 : 0904-01-01 00:00:00 0 1 0 : -0.51390 : tos 6 : 0905-01-01 00:00:00 0 1 0 : -0.29021 : tos 7 : 0906-01-01 00:00:00 0 1 0 : -0.074603 : tos 8 : 0907-01-01 00:00:00 0 1 0 : 0.12746 : tos 9 : 0908-01-01 00:00:00 0 1 0 : 0.31012 : tos 10 : 0909-01-01 00:00:00 0 1 0 : 0.46779 : tos 11 : 0910-01-01 00:00:00 0 1 0 : 0.59542 : tos 12 : 0911-01-01 00:00:00 0 1 0 : 0.68962 : tos 13 : 0912-01-01 00:00:00 0 1 0 : 0.74951 : tos 14 : 0913-01-01 00:00:00 0 1 0 : 0.77422 : tos 15 : 0914-01-01 00:00:00 0 1 0 : 0.76360 : tos
cdo outputtab,year,value ts_yearmean.nc > output.txt
# year value 900 -1.37074 901 -1.17534 902 -0.962913 903 -0.74008 904 -0.513905 905 -0.290207 906 -0.0746027 907 0.12746 908 0.310117 909 0.467793 910 0.595417 911 0.689619 912 0.749508 913 0.774218 914 0.763604-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
While providing the data I have already mentioned the syntax I am using for my data with the variable name 'tos' but it still doesn't work.
Now I am using the anomaly, so I would like to extract the years that have values greater than 1.0.
Thank you.
S
RE: Outputtab with a condition (constant) - Added by Karin Meier-Fleischer over 6 years ago
Ok, the last problem was the cut call for which interestingly the value for -f must be 2 to retrieve the years.
cdo outputtab,year,value -expr,'tos=((tos >= 1.0)) ? tos : 0' ts_yearmean.nc | awk '$2!=0' | cut -d ' ' -f 2 > output.txt
year 1040 1041 1042 1068 1069 1070 1071 1072 1073 1074 1075 1076 1192 1193 ...-Karin
RE: Outputtab with a condition (constant) - Added by S BR over 6 years ago
Hi Karin,
Many thanks. It worked now fine.
Thanks for your time efforts.
Best regards
S