我们身边的STEM 05:露点温度计算的一种偷懒的方法——站在别人的肩膀上

in #cn-stem6 years ago (edited)

我在之前两贴从物理含义,公式等方面描述了露点温度的定义及计算方法。一定会有人说,你能不能直接给我一个程序,我只要用它就可以了。毕竟我们基本上只是一个使用者,并不需要做理论研究。

好的,我先直接给你一个程序和运行结果:

源程序是这样的:

下面我就告诉你这个程序是怎么来的。

其实,从公式出发,就已经可以自己写出程序了。如果你实在是懒得出奇,那么,恭喜你,我刚好也很懒,也找到了一个方法可以偷懒,就是——
找到别人已经写好的网页计算器,然后我们可以查看源代码,从而直接找到现成的程序。如果有心的话,还可以看看别人的程序写的是不是和自己的理解一样。

今天我们以www.easycalculation.com上的一个网页为例:
https://www.easycalculation.com/weather/dewpoint-humidity-calculator.php
从网址我们就可以看出,这是一个计算dewpoint的计算器,怎么算呢?打开就能看到,是根据已知温湿度和大气压力,计算dewpoint露点温度和wbt湿球温度。

输入温度25°C,相对湿度50%,然后按“Compute”,可以看到湿球温度Tw是17°C,露点温度Td是13.87°C。

这是怎么算出来的呢?鼠标右键单击,如图选择:

查看源代码的界面是这样的:

前面的html的一些代码我们不需要理会,直接找重点,果然,在从544行开始,干货出现了:

虽说一般敢于看源代码的,肯定都懂编程。但我还是给可能的小白解释一下:

Es = parseFloat(esubs(Ctemp));
这是从温度计算水的饱和蒸气压值,而函数esubs()在第610行:


E = parseFloat(invertedRH(Es,rh));
这是从当前的相对湿度rh和当前温度的饱和水蒸气压值Es,求得当前实际的水蒸气压值,函数invertedRH()在第617行:


dewpoint = (Dewpoint(E));
这是根据已经求得的当前实际水蒸气压力E,得出露点温度Td,Dewpoint()函数在第624行:


看到没,就这样,一个偷懒的码农,没费什么力气,就有了计算露点温度的所有程序,神奇吧?哈哈哈~~~

接下来,我把这几段程序合起来,做成一个完整的从当前温度T和相对湿度RH来计算露点温度Td的函数:
float DewpointCalculat(float Tair, float rh)//Tair: °C rh:%
{
float Es,E,dewpoint;

Es = 6.112 * exp(17.67 * Tair / (Tair + 243.5));

E = Es * (rh/100);

dewpoint = (243.5 * log(E/6.112))/(17.67 - log(E/6.112));

return(dewpoint);
}

如果你一直看我的文章到现在,你会发现这里面的常数6.112,243.5,17.67非常眼熟。对的,之前一直提过,昨天的我们身边的STEM 04:干湿球温度计及露点温度中马格努斯公式的应用还说过:

你会发现程序里的常数和昨天的有点点不一样。因为这些程序都是近似测量,具体怎么取值要看最终的精度要求。而精度昨天已经分析过,所以取昨天的数值比较确定,再做得高大上符合实际物理定义的话,把上面的常数宏定义一下:
α=6.1129hpa,是0℃时的饱和水蒸气压; 对水平面来说,β=17.62 , λ=243.12。

#define t2P_a 6.1129
#define t2P_b 17.62
#define t2P_c 243.12

float DewpointCalculat(float Tair, float rh)//Tair: °C rh:%
{

float Es,E,dewpoint;

Es = t2P_a * exp(t2P_b * Tair / (Tair + t2P_c));

E = Es * (rh/100);

dewpoint = (t2P_c * log(E/t2P_a))/(t2P_b - log(E/t2P_a));

return(dewpoint);
}

昨天介绍的算法中,实际计算举例如下:
RH=10%, T=25°C时, Dew point = -8.77°C RH=90%, T=50°C时,Dew point = 47.90°C

我们创建一个项目,实际带入温湿度确认一下,下面是RH=10%, T=25°C时, Dew point的计算值:

下面是RH=90%, T=50°C时, Dew point的计算值:

是不是和昨天的算法结果完全相同?

哈哈哈,怎么样?现在这个程序就很完美了,码农可以偷着乐了。


我们身边的STEM系列:

我们身边的STEM 01:单片机及其堆栈设计小窍门

我们身边的STEM 02:空气温湿度之水的饱和蒸汽压及其计算函数

我们身边的STEM 03:空气温湿度之露点温度及其计算函数

我们身边的STEM 04:干湿球温度计及露点温度中马格努斯公式的应用


希望喜欢我文字的人,去看看这个吧,说说对我的看法,请我吃星星

,谢谢啦~
我的 @ReviewMe 凭证留言板!

Posted using Partiko iOS

Sort:  




This post has been voted on by the SteemSTEM curation team and voting trail in collaboration with @utopian-io and @curie.

If you appreciate the work we are doing then consider voting all three projects for witness by selecting stem.witness, utopian-io and curie!

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Thank you

Posted using Partiko iOS

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by kissfirer from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

吃了吗?还在发愁自己的好文没人发现,收益惨淡吗?记得加上cn-curation标签,让飞鸽传书 帮你走出困境吧!假如我的留言打扰到你,请回复“取消”。

Thank you so much for participating the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Hi @julian2013!

Your post was upvoted by Utopian.io in cooperation with @steemstem - supporting knowledge, innovation and technological advancement on the Steem Blockchain.

Contribute to Open Source with utopian.io

Learn how to contribute on our website and join the new open source economy.

Want to chat? Join the Utopian Community on Discord https://discord.gg/h52nFrV

Thank you

Posted using Partiko iOS

机机厉害了,好专业

Posted using Partiko Android

哈哈,总算有点东西可以抱抱大腿了

Posted using Partiko iOS

原來你是程序員!馬上送外賣來 @teamcn-shop

Posted using Partiko iOS

哈哈哈,算是小半个码农吧😁

Posted using Partiko iOS

@coder-bts给您叫了一份外卖!

@softmetal 软哥 迎着飓风 吃着软哥咖喱给您送来
斋烤鹅

吃饱了吗?跟我猜拳吧! 石头,剪刀,布~

如果您对我的服务满意,请不要吝啬您的点赞~

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.030
BTC 60268.51
ETH 3201.96
USDT 1.00
SBD 2.43