如何使用 expr cdo-climate 基于间隔条件计算变量

发布于 2025-01-10 07:52:28 字数 385 浏览 3 评论 0原文

我正在尝试根据两个离散条件计算 fsa 变量值。最后,我想要一个带有变量 fsa 的输出文件。第一个条件是当tas大于275.15时fsa等于1。在第二个条件中,当 tas 在 273.15 和 275.15 之间时,我希望 fsa 等于 (1-0.5*( tas -273.15))。这是我第一次尝试使用 expr,感谢任何帮助。任何方法都可以,不必是 expr。我的文件很大,所以首选简洁的方法。

cdo -expr, 'fsa = ((tas>275.15)) ? 1.0 : 0; fsa = ((tas<=275.15 & tas>273.15)) ? (1-0.5*(tas-273.15)) : fsa; <infile> <outfile>

I am trying to calculate fsa variable values based on two discrete conditions. In the end, I want one output file with variable fsa. The first condition is fsa equals 1 when tas is greater than 275.15. In the second condition, I want fsa to be equal to (1-0.5*( tas -273.15)) when tas is between 273.15 and 275.15. Here is my first try using expr, any help is appreciated. any approach will be ok it doesn't have to be expr. my file size is big so a concise method is preferred.

cdo -expr, 'fsa = ((tas>275.15)) ? 1.0 : 0; fsa = ((tas<=275.15 & tas>273.15)) ? (1-0.5*(tas-273.15)) : fsa; <infile> <outfile>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2025-01-17 07:52:28

这是 CDO 社区主论坛 Ralf 的回答。

您可以像这样使用嵌套三元运算符:

cdo -expr,'fsa = ((tas<=275.15 && tas>273.15)) ? (1-0.5*(tas-273.15)) : ((tas>275.15) ? 1.0 : 0)' <infile> <outfile>

逻辑 OR 是 && !

Here is the answer by Ralf from CDO community main forum.

You can use nest the ternary operators like this:

cdo -expr,'fsa = ((tas<=275.15 && tas>273.15)) ? (1-0.5*(tas-273.15)) : ((tas>275.15) ? 1.0 : 0)' <infile> <outfile>

The logical OR is && !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文