byJacob Davis| Updated: 01/06/2016 | Comments: 2
Do you feel lost when sifting through wind direction data that is listed in degrees? For example, can you picture in your mind what direction 195 degrees is? Would it be easier if your data logger could put your data in compass directions instead? In this article, I’ll share with you an easy method for converting your wind direction data from degrees to compass directions using the CRBasic programming language.
如果你喜欢我,指南针方向(北,南,东西和西)比学位更容易理解。例如,如果有人要求我驾驶方向,我不说,“在270度标题上旅行五个街区。”对我而言,如果我说,那么丢失的司机更容易,“追逐五个街区。”
同样,在描述风向时,罗盘点往往更容易理解学位。气象学家在天气预报中使用罗盘积分,因为他们更容易让人想象和记住。例如,气象学家可能会说,“风暴会从西方吹。”
In terms of wind direction, it is both fortunate and unfortunate that data loggers don’t “think” like us humans do.
从风向数据中造成以度的风向数据,let’s get started in our conversion process. To convert degrees to compass directions, I first divide the compass into 16 sectors of 22.5 degrees each. The sectors are like slices of pie, centered on the compass points.
提示:If you would like to use eight sectors instead of 16, with a shorter lookup table, divide by 45 degrees instead of 22.5 degrees.
To do the conversion, I use an indexed array as a lookup table instead of a案子操作说明。I prefer the indexed array because the code is faster and more compact than the code of a案子操作说明。此外,索引阵列适用于均匀间隔的数据箱,例如设定的度数。(数据箱是数字范围的类别。)相比之下,a案子instruction is a better choice for applications where your data bins aren’t evenly spaced, such as determining temperature ranges that describe water as hot, warm, or cold. (“Hot” and “cold” values would be larger bins, and “warm” would be a smaller bin.)
因为北方罗盘可以被描述为0度或360度,我们必须为它使用两个数据箱。这意味着,对于我们的16个罗盘扇区,我们实际需要在我们的查找表中需要17个值。第一个值和最后一个值都是北方。下表显示了16个不同的罗盘扇区的17个值:
Values | Compass Sectors |
1 |
N |
2 |
NNE |
3 |
ne |
4 |
ENE |
5 |
E |
6 |
伊斯 |
7 |
SE |
8 |
上席 |
9 |
S |
10 |
SSW. |
11 |
SW |
12 |
WSW |
13 |
W |
14 |
WNW |
15 |
NW. |
16 |
NNW |
17 |
N |
You can use an array in your data logger program as a lookup table. A simple way to fill the array is to assign initial values. Be sure you use typeString并将每个值括在引号内。代码线有点长,但它很简单:
Dim Sector(17)作为字符串* 3 = {“N”,“NNE”,“NE”,“ENE”,“E”,“ESE”,“SE”,“SSE”,“SSE”,“SSW”,“SSW”,“sw”,“wsw”,“w”,“wnw”,“nw”,“nnw”,“nnw”,“n”}
现在我们需要将风向转换为与我们数组中的17个索引值相对应的整数值。
要将风向限制为360度,我们需要执行模制操作以在将总学位划分360后找到其余的。
例如,如果我们都在工作with 405 degrees, we divide that value by 360. Doing so gives us 1 with a remainder (or modulus) of 45:
在此示例中,45度的剩余部分是需要转换为指南针方向的东西。 |
Note:Although this step isn’t necessary with most sensors, it won’t cause any problems if you include it in your programs.
如果我们将风向除以22.5(每个扇区的学位)和圆形,我们得到0到16的数字。因为存储在数组中的标签从1到17索引,我们必须添加1以适合范围:
index = winddir mod 360索引= round(索引/ 22.5,0)+1 compassdir = sector(索引)
在前面的例子中,如果我们将剩余的45度划分并将其划分为22.5,我们得到2:
If we add 1, the result is 3:
On our table the value of “3” corresponds to a direction of “NE.” 因此,我们的45度剩余时间换成了东北的方向。 |
我们可以将整个数学函数放在数组的索引参数中。括号强制来自内部的操作顺序:
CompassDir = Sector(Round((WindDir MOD 360)/ 22.5,0)+1)
将所有部分放在一起,我们得到以下数据记录程序。只需添加您的测量和数据表。
'公共变量公共Winddir作为浮动单元winddir = dive dim sector(17)作为字符串* 3 = {“n”,“nne”,“ne”,“ene”,“E”,“ESE”,“ESE”,“SE”。,“SSE”,“SSE”,“SSW”,“SW”,“WSW”,“W”,“WNW”,“NW”,“NNW”,“NNW”,“NNW”,“N”,“N”}公众CompartDIR作为String * 3'主程序BeginProg扫描(1,SEC,0,0)'在此处添加风传感器测量Comproundir =扇区(圆形((Winddir Mod 360)/ 22.5,0)+1)'将风向转向17个部门。第1和17扇区都是N. nextScan endprog
In this article, I hope I helped you find your way to better understand, use, and share your wind direction data using some CRBasic programming code. If you have any of ourRTMC software products, this software is able to take your wind direction data and directly convert the degrees into a compass display.
随意分享您希望使用罗盘积分报告风向的情况。您能认为与您可以使用此方法的均匀间隔数据箱的类似情况吗?发布您的想法下面。
注释
蒂亚戈|10/31/2018 at 01:11 PM
好贴。
How do I write the calculate compass data into a Table?
I need to calculate a 30 minute average data from wind sensor e write the compass data from it in a table. I don´t know how to do it.
JDavis|10/31/2018 at 01:29 PM
罗盘扇区是一个字符串变量,只能保存到具有示例指令的表。在您的情况下,难度是必须首先计算风的矢量平均值。可以读取数据表中的值。但是,您无法将该指南针扇区保存到同一张表中。
We have worked around limitations before by making a table with just the Windvector. You then read that value back out, and can save it with other data in your main table. GetRecord is the easiest way to read values back out of a table.
Pleaselog in or register评论。