mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Correcting Celcius to Celsius
This commit is contained in:
parent
ca8b0899d0
commit
0213bc7aef
@ -932,7 +932,7 @@ do -- COORDINATE
|
||||
if Settings:IsMetric() then
|
||||
return string.format( " %-2.2f °C", DegreesCelcius )
|
||||
else
|
||||
return string.format( " %-2.2f °F", UTILS.CelciusToFarenheit( DegreesCelcius ) )
|
||||
return string.format( " %-2.2f °F", UTILS.CelsiusToFarenheit( DegreesCelcius ) )
|
||||
end
|
||||
else
|
||||
return " no temperature"
|
||||
|
||||
@ -2755,7 +2755,7 @@ function RANGE:_DisplayRangeWeather( _unitname )
|
||||
local tW = string.format( "%.1f m/s", Ws )
|
||||
local tP = string.format( "%.1f mmHg", P * hPa2mmHg )
|
||||
if settings:IsImperial() then
|
||||
-- tT=string.format("%d°F", UTILS.CelciusToFarenheit(T))
|
||||
-- tT=string.format("%d°F", UTILS.CelsiusToFarenheit(T))
|
||||
tW = string.format( "%.1f knots", UTILS.MpsToKnots( Ws ) )
|
||||
tP = string.format( "%.2f inHg", P * hPa2inHg )
|
||||
end
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
-- @module Utils
|
||||
-- @image MOOSE.JPG
|
||||
|
||||
|
||||
--- @type SMOKECOLOR
|
||||
-- @field Green
|
||||
-- @field Red
|
||||
@ -58,9 +59,10 @@ DCSMAP = {
|
||||
PersianGulf="PersianGulf",
|
||||
TheChannel="TheChannel",
|
||||
Syria="Syria",
|
||||
MarianaIslands = "MarianaIslands",
|
||||
MarianaIslands="MarianaIslands"
|
||||
}
|
||||
|
||||
|
||||
--- See [DCS_enum_callsigns](https://wiki.hoggitworld.com/view/DCS_enum_callsigns)
|
||||
-- @type CALLSIGN
|
||||
CALLSIGN={
|
||||
@ -256,6 +258,7 @@ UTILS.IsInstanceOf = function( object, className )
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Deep copy a table. See http://lua-users.org/wiki/CopyTable
|
||||
-- @param #table object The input table.
|
||||
-- @return #table Copy of the input table.
|
||||
@ -287,6 +290,7 @@ UTILS.DeepCopy = function( object )
|
||||
return objectreturn
|
||||
end
|
||||
|
||||
|
||||
--- Porting in Slmod's serialize_slmod2.
|
||||
-- @param #table tbl Input table.
|
||||
UTILS.OneLineSerialize = function( tbl ) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function
|
||||
@ -379,6 +383,7 @@ UTILS.BasicSerialize = function( s )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
UTILS.ToDegree = function(angle)
|
||||
return angle*180/math.pi
|
||||
end
|
||||
@ -468,21 +473,21 @@ UTILS.KnotsToMps = function( knots )
|
||||
end
|
||||
end
|
||||
|
||||
--- Convert temperature from Celsius to Fahrenheit.
|
||||
-- @param #number Celsius Temperature in degrees Celsius.
|
||||
-- @return #number Temperature in degrees Fahrenheit.
|
||||
UTILS.CelsiusToFahrenheit = function( Celsius )
|
||||
return Celsius * 9 / 5 + 32
|
||||
--- Convert temperature from Celsius to Farenheit.
|
||||
-- @param #number Celcius Temperature in degrees Celsius.
|
||||
-- @return #number Temperature in degrees Farenheit.
|
||||
UTILS.CelsiusToFarenheit = function( Celcius )
|
||||
return Celcius * 9/5 + 32
|
||||
end
|
||||
|
||||
--- Convert pressure from hectopascal (hPa) to inches of mercury (inHg).
|
||||
--- Convert pressure from hecto Pascal (hPa) to inches of mercury (inHg).
|
||||
-- @param #number hPa Pressure in hPa.
|
||||
-- @return #number Pressure in inHg.
|
||||
UTILS.hPa2inHg = function( hPa )
|
||||
return hPa * 0.0295299830714
|
||||
end
|
||||
|
||||
--- Convert knots to altitude corrected KIAS, e.g. for tankers.
|
||||
--- Convert knots to alitude corrected KIAS, e.g. for tankers.
|
||||
-- @param #number knots Speed in knots.
|
||||
-- @param #number altitude Altitude in feet
|
||||
-- @return #number Corrected KIAS
|
||||
@ -490,14 +495,14 @@ UTILS.KnotsToAltKIAS = function( knots, altitude )
|
||||
return (knots * 0.018 * (altitude / 1000)) + knots
|
||||
end
|
||||
|
||||
--- Convert pressure from hectopascal (hPa) to millimeters of mercury (mmHg).
|
||||
--- Convert pressure from hecto Pascal (hPa) to millimeters of mercury (mmHg).
|
||||
-- @param #number hPa Pressure in hPa.
|
||||
-- @return #number Pressure in mmHg.
|
||||
UTILS.hPa2mmHg = function( hPa )
|
||||
return hPa * 0.7500615613030
|
||||
end
|
||||
|
||||
--- Convert kilograms (kg) to pounds (lbs).
|
||||
--- Convert kilo gramms (kg) to pounds (lbs).
|
||||
-- @param #number kg Mass in kg.
|
||||
-- @return #number Mass in lbs.
|
||||
UTILS.kg2lbs = function( kg )
|
||||
@ -564,7 +569,8 @@ UTILS.tostringLL = function( lat, lon, acc, DMS )
|
||||
end
|
||||
|
||||
-- 024° 23' 12"N or 024° 23' 12.03"N
|
||||
return string.format( '%03d°', latDeg ) .. string.format( '%02d', latMin ) .. '\'' .. string.format( secFrmtStr, latSec ) .. '"' .. latHemi .. ' ' .. string.format( '%03d°', lonDeg ) .. string.format( '%02d', lonMin ) .. '\'' .. string.format( secFrmtStr, lonSec ) .. '"' .. lonHemi
|
||||
return string.format('%03d°', latDeg)..string.format('%02d', latMin)..'\''..string.format(secFrmtStr, latSec)..'"'..latHemi..' '
|
||||
.. string.format('%03d°', lonDeg)..string.format('%02d', lonMin)..'\''..string.format(secFrmtStr, lonSec)..'"'..lonHemi
|
||||
|
||||
else -- degrees, decimal minutes.
|
||||
latMin = UTILS.Round(latMin, acc)
|
||||
@ -589,7 +595,8 @@ UTILS.tostringLL = function( lat, lon, acc, DMS )
|
||||
end
|
||||
|
||||
-- 024 23'N or 024 23.123'N
|
||||
return string.format( '%03d°', latDeg ) .. ' ' .. string.format( minFrmtStr, latMin ) .. '\'' .. latHemi .. ' ' .. string.format( '%03d°', lonDeg ) .. ' ' .. string.format( minFrmtStr, lonMin ) .. '\'' .. lonHemi
|
||||
return string.format('%03d°', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' '
|
||||
.. string.format('%03d°', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
|
||||
|
||||
end
|
||||
end
|
||||
@ -614,12 +621,8 @@ UTILS.tostringMGRS = function( MGRS, acc ) -- R2.1
|
||||
local nN=5-string.len(Northing)
|
||||
|
||||
-- Get leading zeros (if any).
|
||||
for i = 1, nE do
|
||||
Easting = "0" .. Easting
|
||||
end
|
||||
for i = 1, nN do
|
||||
Northing = "0" .. Northing
|
||||
end
|
||||
for i=1,nE do Easting="0"..Easting end
|
||||
for i=1,nN do Northing="0"..Northing end
|
||||
|
||||
-- Return MGRS string.
|
||||
return string.format("%s %s %s %s", MGRS.UTMZone, MGRS.MGRSDigraph, string.sub(Easting, 1, acc), string.sub(Northing, 1, acc))
|
||||
@ -627,6 +630,7 @@ UTILS.tostringMGRS = function( MGRS, acc ) -- R2.1
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- From http://lua-users.org/wiki/SimpleRound
|
||||
-- use negative idp for rounding ahead of decimal place, positive for rounding after decimal place
|
||||
function UTILS.Round( num, idp )
|
||||
@ -648,16 +652,12 @@ end
|
||||
function UTILS.spairs( t, order )
|
||||
-- collect the keys
|
||||
local keys = {}
|
||||
for k in pairs( t ) do
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
for k in pairs(t) do keys[#keys+1] = k end
|
||||
|
||||
-- if order function given, sort by it by passing the table and keys a, b,
|
||||
-- otherwise just sort the keys
|
||||
if order then
|
||||
table.sort( keys, function( a, b )
|
||||
return order( t, a, b )
|
||||
end )
|
||||
table.sort(keys, function(a,b) return order(t, a, b) end)
|
||||
else
|
||||
table.sort(keys)
|
||||
end
|
||||
@ -672,22 +672,18 @@ function UTILS.spairs( t, order )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first.
|
||||
function UTILS.kpairs( t, getkey, order )
|
||||
-- collect the keys
|
||||
local keys = {}
|
||||
local keyso = {}
|
||||
for k, o in pairs( t ) do
|
||||
keys[#keys + 1] = k
|
||||
keyso[#keyso + 1] = getkey( o )
|
||||
end
|
||||
for k, o in pairs(t) do keys[#keys+1] = k keyso[#keyso+1] = getkey( o ) end
|
||||
|
||||
-- if order function given, sort by it by passing the table and keys a, b,
|
||||
-- otherwise just sort the keys
|
||||
if order then
|
||||
table.sort( keys, function( a, b )
|
||||
return order( t, a, b )
|
||||
end )
|
||||
table.sort(keys, function(a,b) return order(t, a, b) end)
|
||||
else
|
||||
table.sort(keys)
|
||||
end
|
||||
@ -707,9 +703,7 @@ function UTILS.rpairs( t )
|
||||
-- collect the keys
|
||||
|
||||
local keys = {}
|
||||
for k in pairs( t ) do
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
for k in pairs(t) do keys[#keys+1] = k end
|
||||
|
||||
local random = {}
|
||||
local j = #keys
|
||||
@ -748,6 +742,7 @@ function UTILS.RemoveMark( MarkID, Delay )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Test if a Vec2 is in a radius of another Vec2
|
||||
function UTILS.IsInRadius( InVec2, Vec2, Radius )
|
||||
|
||||
@ -814,9 +809,9 @@ function UTILS.BeaufortScale( speed )
|
||||
return bn,bd
|
||||
end
|
||||
|
||||
--- Split string at separators. C.f. http://stackoverflow.com/questions/1426954/split-string-in-lua
|
||||
--- Split string at seperators. C.f. http://stackoverflow.com/questions/1426954/split-string-in-lua
|
||||
-- @param #string str Sting to split.
|
||||
-- @param #string sep Separator for split.
|
||||
-- @param #string sep Speparator for split.
|
||||
-- @return #table Split text.
|
||||
function UTILS.Split(str, sep)
|
||||
local result = {}
|
||||
@ -893,7 +888,7 @@ function UTILS.SecondsOfToday()
|
||||
return UTILS.ClockToSeconds(clock)
|
||||
end
|
||||
|
||||
--- Count seconds until next midnight.
|
||||
--- Cound seconds until next midnight.
|
||||
-- @return #number Seconds to midnight.
|
||||
function UTILS.SecondsToMidnight()
|
||||
return 24*60*60-UTILS.SecondsOfToday()
|
||||
@ -1044,6 +1039,7 @@ function UTILS.Vec2Dot( a, b )
|
||||
return a.x*b.x + a.y*b.y
|
||||
end
|
||||
|
||||
|
||||
--- Calculate the [euclidean norm](https://en.wikipedia.org/wiki/Euclidean_distance) (length) of a 3D vector.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @return #number Norm of the vector.
|
||||
@ -1071,6 +1067,7 @@ function UTILS.VecDist2D( a, b )
|
||||
return d
|
||||
end
|
||||
|
||||
|
||||
--- Calculate the distance between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
@ -1100,6 +1097,14 @@ function UTILS.VecSubstract( a, b )
|
||||
return {x=a.x-b.x, y=a.y-b.y, z=a.z-b.z}
|
||||
end
|
||||
|
||||
--- Calculate the difference between two 2D vectors by substracting the x,y components from each other.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 2D with x, y components.
|
||||
-- @return DCS#Vec2 Vector c=a-b with c(i)=a(i)-b(i), i=x,y.
|
||||
function UTILS.Vec2Substract(a, b)
|
||||
return {x=a.x-b.x, y=a.y-b.y}
|
||||
end
|
||||
|
||||
--- Calculate the total vector of two 3D vectors by adding the x,y,z components of each other.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
@ -1108,6 +1113,14 @@ function UTILS.VecAdd( a, b )
|
||||
return {x=a.x+b.x, y=a.y+b.y, z=a.z+b.z}
|
||||
end
|
||||
|
||||
--- Calculate the total vector of two 2D vectors by adding the x,y components of each other.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 2D with x, y components.
|
||||
-- @return DCS#Vec2 Vector c=a+b with c(i)=a(i)+b(i), i=x,y.
|
||||
function UTILS.Vec2Add(a, b)
|
||||
return {x=a.x+b.x, y=a.y+b.y}
|
||||
end
|
||||
|
||||
--- Calculate the angle between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
@ -1169,6 +1182,7 @@ function UTILS.HdgDiff( h1, h2 )
|
||||
return math.abs(delta)
|
||||
end
|
||||
|
||||
|
||||
--- Translate 3D vector in the 2D (x,z) plane. y-component (usually altitude) unchanged.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param #number distance The distance to translate.
|
||||
@ -1240,6 +1254,7 @@ function UTILS.Vec2Rotate2D( a, angle )
|
||||
return A
|
||||
end
|
||||
|
||||
|
||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz.
|
||||
-- @param #number TACANChannel The TACAN channel, i.e. the 10 in "10X".
|
||||
-- @param #string TACANMode The TACAN mode, i.e. the "X" in "10X".
|
||||
@ -1276,6 +1291,7 @@ function UTILS.TACANToFrequency( TACANChannel, TACANMode )
|
||||
return (A + TACANChannel - B) * 1000000
|
||||
end
|
||||
|
||||
|
||||
--- Returns the DCS map/theatre as optained by env.mission.theatre
|
||||
-- @return #string DCS map name.
|
||||
function UTILS.GetDCSMap()
|
||||
@ -1321,26 +1337,6 @@ function UTILS.GetMissionDayOfYear( Time )
|
||||
|
||||
end
|
||||
|
||||
--- Returns the current date.
|
||||
-- @return #string Mission date in yyyy/mm/dd format.
|
||||
-- @return #number The year anno domini.
|
||||
-- @return #number The month.
|
||||
-- @return #number The day.
|
||||
function UTILS.GetDate()
|
||||
|
||||
-- Mission start date
|
||||
local date, year, month, day = UTILS.GetDCSMissionDate()
|
||||
|
||||
local time = timer.getAbsTime()
|
||||
|
||||
local clock = UTILS.SecondsToClock( time, false )
|
||||
|
||||
local x = tonumber( UTILS.Split( clock, "+" )[2] )
|
||||
|
||||
local day = day + x
|
||||
|
||||
end
|
||||
|
||||
--- Returns the magnetic declination of the map.
|
||||
-- Returned values for the current maps are:
|
||||
--
|
||||
@ -1410,7 +1406,8 @@ function UTILS.CheckMemory( output )
|
||||
return mem
|
||||
end
|
||||
|
||||
--- Get the coalition name from its numerical ID, e.g. coalition.side.RED.
|
||||
|
||||
--- Get the coalition name from its numerical ID, e.g. coaliton.side.RED.
|
||||
-- @param #number Coalition The coalition ID.
|
||||
-- @return #string The coalition name, i.e. "Neutral", "Red" or "Blue" (or "Unknown").
|
||||
function UTILS.GetCoalitionName(Coalition)
|
||||
@ -1509,6 +1506,7 @@ function UTILS.GMTToLocalTimeDifference()
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Get the day of the year. Counting starts on 1st of January.
|
||||
-- @param #number Year The year.
|
||||
-- @param #number Month The month.
|
||||
@ -1542,31 +1540,18 @@ function UTILS.GetSunRiseAndSet( DayOfYear, Latitude, Longitude, Rising, Tlocal
|
||||
local n=DayOfYear
|
||||
Tlocal=Tlocal or 0
|
||||
|
||||
|
||||
-- Short cuts.
|
||||
local rad = math.rad
|
||||
local deg = math.deg
|
||||
local floor = math.floor
|
||||
local frac = function( n )
|
||||
return n - floor( n )
|
||||
end
|
||||
local cos = function( d )
|
||||
return math.cos( rad( d ) )
|
||||
end
|
||||
local acos = function( d )
|
||||
return deg( math.acos( d ) )
|
||||
end
|
||||
local sin = function( d )
|
||||
return math.sin( rad( d ) )
|
||||
end
|
||||
local asin = function( d )
|
||||
return deg( math.asin( d ) )
|
||||
end
|
||||
local tan = function( d )
|
||||
return math.tan( rad( d ) )
|
||||
end
|
||||
local atan = function( d )
|
||||
return deg( math.atan( d ) )
|
||||
end
|
||||
local frac = function(n) return n - floor(n) end
|
||||
local cos = function(d) return math.cos(rad(d)) end
|
||||
local acos = function(d) return deg(math.acos(d)) end
|
||||
local sin = function(d) return math.sin(rad(d)) end
|
||||
local asin = function(d) return deg(math.asin(d)) end
|
||||
local tan = function(d) return math.tan(rad(d)) end
|
||||
local atan = function(d) return deg(math.atan(d)) end
|
||||
|
||||
local function fit_into_range(val, min, max)
|
||||
local range = max - min
|
||||
@ -1770,6 +1755,7 @@ function UTILS.IsLoadingDoorOpen( unit_name )
|
||||
if ret_val == false then
|
||||
BASE:T(unit_name .. " all doors are closed")
|
||||
end
|
||||
|
||||
return ret_val
|
||||
|
||||
end -- nil
|
||||
@ -1910,7 +1896,9 @@ function UTILS.GenerateLaserCodes()
|
||||
while _code < 1777 and _count < 30 do
|
||||
while true do
|
||||
_code = _code + 1
|
||||
if not ContainsDigit( _code, 8 ) and not ContainsDigit( _code, 9 ) and not ContainsDigit( _code, 0 ) then
|
||||
if not ContainsDigit(_code, 8)
|
||||
and not ContainsDigit(_code, 9)
|
||||
and not ContainsDigit(_code, 0) then
|
||||
table.insert(jtacGeneratedLaserCodes, _code)
|
||||
break
|
||||
end
|
||||
@ -2177,9 +2165,7 @@ end
|
||||
-- @return #table Table of data objects (tables) containing groupname, coordinate and group object. Returns nil when file cannot be read.
|
||||
function UTILS.LoadStationaryListOfGroups(Path,Filename,Reduce)
|
||||
local reduce = true
|
||||
if Reduce == false then
|
||||
reduce = false
|
||||
end
|
||||
if Reduce == false then reduce = false end
|
||||
local filename = Filename or "StateListofGroups"
|
||||
local datatable = {}
|
||||
if UTILS.CheckFileExists(Path,filename) then
|
||||
@ -2198,9 +2184,8 @@ function UTILS.LoadStationaryListOfGroups( Path, Filename, Reduce )
|
||||
local data = { groupname=groupname, size=size, coordinate=coordinate, group=GROUP:FindByName(groupname) }
|
||||
if reduce then
|
||||
local actualgroup = GROUP:FindByName(groupname)
|
||||
local actualsize = actualgroup:CountAliveUnits()
|
||||
if actualsize > size then
|
||||
local reduction = actualsize - size
|
||||
if actualgroup and actualgroup:IsAlive() and actualgroup:CountAliveUnits() > size then
|
||||
local reduction = actualgroup:CountAliveUnits() - size
|
||||
BASE:I("Reducing groupsize by ".. reduction .. " units!")
|
||||
-- reduce existing group
|
||||
local units = actualgroup:GetUnits()
|
||||
@ -2226,9 +2211,7 @@ end
|
||||
-- Returns nil when file cannot be read. Returns a table of data entries if Spawn is false: `{ groupname=groupname, size=size, coordinate=coordinate }`
|
||||
function UTILS.LoadSetOfGroups(Path,Filename,Spawn)
|
||||
local spawn = true
|
||||
if Spawn == false then
|
||||
spawn = false
|
||||
end
|
||||
if Spawn == false then spawn = false end
|
||||
BASE:I("Spawn = "..tostring(spawn))
|
||||
local filename = Filename or "SetOfGroups"
|
||||
local setdata = SET_GROUP:New()
|
||||
@ -2251,7 +2234,10 @@ function UTILS.LoadSetOfGroups( Path, Filename, Spawn )
|
||||
local data = { groupname=groupname, size=size, coordinate=coordinate }
|
||||
table.insert(datatable,data)
|
||||
if spawn then
|
||||
local group = SPAWN:New( groupname ):InitDelayOff():OnSpawnGroup( function( spwndgrp )
|
||||
local group = SPAWN:New(groupname)
|
||||
:InitDelayOff()
|
||||
:OnSpawnGroup(
|
||||
function(spwndgrp)
|
||||
setdata:AddObject(spwndgrp)
|
||||
local actualsize = spwndgrp:CountAliveUnits()
|
||||
if actualsize > size then
|
||||
@ -2263,7 +2249,9 @@ function UTILS.LoadSetOfGroups( Path, Filename, Spawn )
|
||||
units2[i]:Destroy(false)
|
||||
end
|
||||
end
|
||||
end ):SpawnFromCoordinate( coordinate )
|
||||
end
|
||||
)
|
||||
:SpawnFromCoordinate(coordinate)
|
||||
end
|
||||
end
|
||||
else
|
||||
@ -2311,9 +2299,7 @@ end
|
||||
-- Returns nil when file cannot be read.
|
||||
function UTILS.LoadStationaryListOfStatics(Path,Filename,Reduce)
|
||||
local reduce = true
|
||||
if Reduce == false then
|
||||
reduce = false
|
||||
end
|
||||
if Reduce == false then reduce = false end
|
||||
local filename = Filename or "StateListofStatics"
|
||||
local datatable = {}
|
||||
if UTILS.CheckFileExists(Path,filename) then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user