Phi: nicer scroll animation for METAR widget
[fg:fgdata.git] / Nasal / contrail.nas
1 #########
2 # contrail calculator. Based on an approxmation to the "Appleman Chart"
3 # y = -0.077x2 + 2.7188x - 64.36
4 #
5 ########
6
7 updateContrail = func{
8     var pressure_Node = props.globals.getNode("environment/pressure-inhg");
9     var temperature_Node = props.globals.getNode("environment/temperature-degc");
10     var contrail_Node = props.globals.getNode("environment/contrail");
11     var contrail_temp_Node = props.globals.getNode("environment/contrail-temperature-degc");
12
13     var x = pressure_Node.getValue();
14     var y = temperature_Node.getValue();
15     var con_temp = -0.077 * x * x + 2.7188 * x - 64.36;
16     contrail_temp_Node.setValue(con_temp);
17
18     if (y < con_temp and y < -40){
19         contrail_Node.setValue(1);
20     } else {
21         contrail_Node.setValue(0);
22     }
23
24     settimer(updateContrail,30)
25 }
26
27 ### Contrail
28
29 _setlistener("/sim/signals/nasal-dir-initialized", func {
30     printlog ("debug", "init contrail");
31     props.globals.initNode("environment/pressure-inhg", 1, "DOUBLE");
32     props.globals.initNode("environment/temperature-degc", 1, "DOUBLE");
33     props.globals.initNode("environment/contrail", 1, "BOOL");
34     props.globals.initNode("environment/contrail-temperature-degc", 1, "DOUBLE");
35     var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1);
36     var time_node = props.globals.getNode("sim/time/elapsed-sec", 1);
37
38     updateContrail();
39 });