PDA

View Full Version : Weather Calculations with heavy math



Tobias
- 5th January 2011, 03:08
I am reading a temp sensor and want to calculate the saturation pressure of water vapor. Below is the formula.

One question, how in the hell am I going to do this?

=6.1078*(0.99999683+TempF*(-0.0090826951+TempF*(0.000078736169+TempF*(-0.00000061117958+TempF*(0.0000000043884187+TempF*(-0.000000000029883885+TempF*(2.1874425E-13+TempF*(-1.7892321E-15+TempF*(1.1112018E-17+TempF*(-3.0994571E-20))))))))))^-8

ScaleRobotics
- 5th January 2011, 04:20
I am reading a temp sensor and want to calculate the saturation pressure of water vapor. Below is the formula.

One question, how in the hell am I going to do this?

=6.1078*(0.99999683+TempF*(-0.0090826951+TempF*(0.000078736169+TempF*(-0.00000061117958+TempF*(0.0000000043884187+TempF*(-0.000000000029883885+TempF*(2.1874425E-13+TempF*(-1.7892321E-15+TempF*(1.1112018E-17+TempF*(-3.0994571E-20))))))))))^-8

This post calculates dew point: http://www.picbasic.co.uk/forum/showthread.php?t=9035&p=58155#post58155
Does that help, or am I way of base?

There are also some simplified equations for water vapor here: http://www.conservationphysics.org/atmcalc/atmoclc2.pdf

Tobias
- 5th January 2011, 04:42
Thanks for the info. I am not sure if that is the same as dew point. I have a weather geek friend I am helping out with this project. I will check with him in the morning.

rsocor01
- 6th January 2011, 00:50
One question, how in the hell am I going to do this?


Floating Point Numbers should do it.

http://melabs.com/resources/fp.htm

Robert

Acetronics2
- 6th January 2011, 08:10
Hi, Tobias

let's take it easy ...

your temp probably may be > -10°C and < 40°C ... right ???

make a 50°C range.

current thermometer sensors give a +/- 0.5°C PRECISION

so, ...

a 100 points retrieve table may be enough !!! PBP allows you 255 points !

if wanting more " whistles and bells " ... It will be easy to use an interpolation between table values ... and show for 1/10th of degree !!!

Soooooo simple !!! :rolleyes:

don't you think ???

Alain

J. Mark Wolf
- 6th January 2011, 12:49
I am reading a temp sensor and want to calculate the saturation pressure of water vapor. Below is the formula.

One question, how in the hell am I going to do this?

=6.1078*(0.99999683+TempF*(-0.0090826951+TempF*(0.000078736169+TempF*(-0.00000061117958+TempF*(0.0000000043884187+TempF*(-0.000000000029883885+TempF*(2.1874425E-13+TempF*(-1.7892321E-15+TempF*(1.1112018E-17+TempF*(-3.0994571E-20))))))))))^-8

Use Excel spreadsheet to generate a table of results for the desired temperature range, import the table into your code, use a lookup function to retreive the value relative to your temp reading.

Tobias
- 7th January 2011, 00:38
damn good ideas guys
Thank you

Tobias
- 7th January 2011, 16:38
I used a lookup table for the first math formula I posted and again a great idea. Amazing how simple things work so much better than complicated ones.

This is my first shot using the FP routines and I am trying to sort out an overflow problem. First off, I have MSP 3.0.0.5, compilier PBP 2.60L and an 18F4620 PIC.

Maybe I am interpreting the readme file in the FP.zip file incorrectly. The way I understand it is when using the FP1832L.BAS file I can use numbers larger than 65535. If that is correct I have something wrong with the code below because when the result of a fpmul routine is larger than 65535 the numbers start again at zero.


define osc 20
Include "modedefs.bas" ' Mode definitions for Serout
include "fp1832l.bas" ' Include file for 18xxxx (32-bit, PBPL.EXE)

Prefix con $FE ' needed before each command
LcdCls CON $51 ' clear LCD (use PAUSE 5 after)
LcdLine1 CON $00 ' move cursor to line 1
LcdLine2 con $40 ' move curson to line 2
LcdLine3 con $14 ' move curson to line 3
lcdLine4 con $54 ' move curson to line 4
LcdCol1 con $00 ' move cursor to column 1
LcdCol2 con $07 ' move cursor to column 7
LcdCR CON $0D ' move pos 0 of next line
LcdOn CON $41 ' LCD on; cursor off, blink off
LcdHome con $46
Backlight con $53 ' Backlighting 1-8
Contrast con $52 ' Contrast 1-50
CursorPS con $45 'Cursor Position
CursorOn con $47 'Cursof On
CursorOff con $48 'Cursor Off
BackSpace CON $4E 'Backspace
UnderlineOn con $47
UnderlineOff con $48

LCD VAR PortC.6 'LCD output

Inlet var word
RH Var word
RH1 var Word 'Used for math purposes
Baro var word
Baro1 var word 'Used for math purposes
Temp var word
Temp2 var word 'Used for math purposes
CurPos var word
SAP var word 'Saturation Pressure
AVP var word 'Actual Vapor Pressure
DAVP var word 'Dry Ait Vapor Pressure
WAVP var word 'Wet Air Vapor Pressure
DAD var word 'Dry Air Density
WVD var word 'Water Vapor Density
WAD var word 'Wet Air Density


Serout2 LCD, 84, [Prefix,LcdCLS]
Temp = 500
Temp2 = (Temp/10)-50
Lookup2 Temp2,[1227,1274,1322,1371,1422,1475,1530,1586,1644,1704, 1766,1830,1896,1964,2034,2107, _
2181,2258,2337,2419,2503,2590,2679,2771,2866,2963, 3064,3167,3273,3383,3496,3612, _
3731,3854,3980,4110,4243,4380,4522,4667,4816,4969, 5126,5288,5454,5625,5800,5980, _
6165,6355,6550,6750,6955,7166,7383,7605,7833,8066, 8306,8553],SAP

RH = 600
RH1 = RH/10
aint = RH1
Gosub itofa ' Convert int to float
bint = SAP
Gosub itofb ' Convert int to float
Gosub fpmul
Gosub ftoia
AVP = aint 'AVP = ((RH)*SAP)
'RH1 SAP AVP(code) AVP(real)
'Results 600 1227 8084 73620
'500 1227 61350 61350

Serout LCD, T9600,[Prefix,CursorPS,0,#RH1, " ", #SAP, " ", #AVP]
stop

Darrel Taylor
- 7th January 2011, 20:13
You would need LONG variables to hold values larger than 65535.

But you certainly don't need the floating point routines for the math you're doing.

Tobias
- 7th January 2011, 20:35
Thanks, the floating point part is the next step. I was just using some simple math to check the results.

Tobias
- 8th January 2011, 09:16
The Long helped and I learned tonite that I needed to use Serout2 to get the correct number to display. It took a few beers to sort it out. Thanks for pointing me to the Long.