{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
module Data.Aviation.Navigation.WindParameters (
WindParameters(..)
, WindParameters'
, HasWindParameters(..)
, optWindParameters
, optWindParametersVersion
) where
import Control.Category ( Category(id, (.)) )
import Control.Lens ( Lens' )
import Data.Aviation.Navigation.Vector
( Vector, vectorDegrees )
import Data.Eq ( Eq )
import Data.Functor ( Functor(fmap), (<$>) )
import Data.Maybe ( Maybe(Just, Nothing) )
import Data.Ord ( Ord )
import Data.Semigroup((<>))
import GHC.Show(Show)
import Options.Applicative
( Applicative((<*>)),
Alternative((<|>)),
auto,
flag',
help,
long,
metavar,
option,
short,
Parser )
import Prelude(Double)
data WindParameters a =
WindParameters
(Vector a)
(Vector a)
deriving (WindParameters a -> WindParameters a -> Bool
(WindParameters a -> WindParameters a -> Bool)
-> (WindParameters a -> WindParameters a -> Bool)
-> Eq (WindParameters a)
forall a. Eq a => WindParameters a -> WindParameters a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => WindParameters a -> WindParameters a -> Bool
== :: WindParameters a -> WindParameters a -> Bool
$c/= :: forall a. Eq a => WindParameters a -> WindParameters a -> Bool
/= :: WindParameters a -> WindParameters a -> Bool
Eq, Eq (WindParameters a)
Eq (WindParameters a) =>
(WindParameters a -> WindParameters a -> Ordering)
-> (WindParameters a -> WindParameters a -> Bool)
-> (WindParameters a -> WindParameters a -> Bool)
-> (WindParameters a -> WindParameters a -> Bool)
-> (WindParameters a -> WindParameters a -> Bool)
-> (WindParameters a -> WindParameters a -> WindParameters a)
-> (WindParameters a -> WindParameters a -> WindParameters a)
-> Ord (WindParameters a)
WindParameters a -> WindParameters a -> Bool
WindParameters a -> WindParameters a -> Ordering
WindParameters a -> WindParameters a -> WindParameters a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (WindParameters a)
forall a. Ord a => WindParameters a -> WindParameters a -> Bool
forall a. Ord a => WindParameters a -> WindParameters a -> Ordering
forall a.
Ord a =>
WindParameters a -> WindParameters a -> WindParameters a
$ccompare :: forall a. Ord a => WindParameters a -> WindParameters a -> Ordering
compare :: WindParameters a -> WindParameters a -> Ordering
$c< :: forall a. Ord a => WindParameters a -> WindParameters a -> Bool
< :: WindParameters a -> WindParameters a -> Bool
$c<= :: forall a. Ord a => WindParameters a -> WindParameters a -> Bool
<= :: WindParameters a -> WindParameters a -> Bool
$c> :: forall a. Ord a => WindParameters a -> WindParameters a -> Bool
> :: WindParameters a -> WindParameters a -> Bool
$c>= :: forall a. Ord a => WindParameters a -> WindParameters a -> Bool
>= :: WindParameters a -> WindParameters a -> Bool
$cmax :: forall a.
Ord a =>
WindParameters a -> WindParameters a -> WindParameters a
max :: WindParameters a -> WindParameters a -> WindParameters a
$cmin :: forall a.
Ord a =>
WindParameters a -> WindParameters a -> WindParameters a
min :: WindParameters a -> WindParameters a -> WindParameters a
Ord, Int -> WindParameters a -> ShowS
[WindParameters a] -> ShowS
WindParameters a -> String
(Int -> WindParameters a -> ShowS)
-> (WindParameters a -> String)
-> ([WindParameters a] -> ShowS)
-> Show (WindParameters a)
forall a. Show a => Int -> WindParameters a -> ShowS
forall a. Show a => [WindParameters a] -> ShowS
forall a. Show a => WindParameters a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WindParameters a -> ShowS
showsPrec :: Int -> WindParameters a -> ShowS
$cshow :: forall a. Show a => WindParameters a -> String
show :: WindParameters a -> String
$cshowList :: forall a. Show a => [WindParameters a] -> ShowS
showList :: [WindParameters a] -> ShowS
Show)
type WindParameters' =
WindParameters Double
class HasWindParameters a c | a -> c where
windParameters ::
Lens' a (WindParameters c)
{-# INLINE trackTAS #-}
trackTAS ::
Lens' a (Vector c)
trackTAS =
(WindParameters c -> f (WindParameters c)) -> a -> f a
forall a c. HasWindParameters a c => Lens' a (WindParameters c)
Lens' a (WindParameters c)
windParameters ((WindParameters c -> f (WindParameters c)) -> a -> f a)
-> ((Vector c -> f (Vector c))
-> WindParameters c -> f (WindParameters c))
-> (Vector c -> f (Vector c))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Vector c -> f (Vector c))
-> WindParameters c -> f (WindParameters c)
forall a c. HasWindParameters a c => Lens' a (Vector c)
Lens' (WindParameters c) (Vector c)
trackTAS
{-# INLINE windDirSpeed #-}
windDirSpeed ::
Lens' a (Vector c)
windDirSpeed =
(WindParameters c -> f (WindParameters c)) -> a -> f a
forall a c. HasWindParameters a c => Lens' a (WindParameters c)
Lens' a (WindParameters c)
windParameters ((WindParameters c -> f (WindParameters c)) -> a -> f a)
-> ((Vector c -> f (Vector c))
-> WindParameters c -> f (WindParameters c))
-> (Vector c -> f (Vector c))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Vector c -> f (Vector c))
-> WindParameters c -> f (WindParameters c)
forall a c. HasWindParameters a c => Lens' a (Vector c)
Lens' (WindParameters c) (Vector c)
windDirSpeed
instance HasWindParameters (WindParameters a) a where
windParameters :: Lens' (WindParameters a) (WindParameters a)
windParameters =
(WindParameters a -> f (WindParameters a))
-> WindParameters a -> f (WindParameters a)
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE trackTAS #-}
trackTAS :: Lens' (WindParameters a) (Vector a)
trackTAS Vector a -> f (Vector a)
f (WindParameters Vector a
tt Vector a
wsd) =
(Vector a -> WindParameters a)
-> f (Vector a) -> f (WindParameters a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Vector a -> Vector a -> WindParameters a
forall a. Vector a -> Vector a -> WindParameters a
`WindParameters` Vector a
wsd) (Vector a -> f (Vector a)
f Vector a
tt)
{-# INLINE windDirSpeed #-}
windDirSpeed :: Lens' (WindParameters a) (Vector a)
windDirSpeed Vector a -> f (Vector a)
f (WindParameters Vector a
tt Vector a
wsd) =
(Vector a -> WindParameters a)
-> f (Vector a) -> f (WindParameters a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Vector a -> Vector a -> WindParameters a
forall a. Vector a -> Vector a -> WindParameters a
WindParameters Vector a
tt) (Vector a -> f (Vector a)
f Vector a
wsd)
optWindParameters ::
Parser WindParameters'
optWindParameters :: Parser WindParameters'
optWindParameters =
(\Double
trk Double
tas Double
wd Double
ws -> Vector Double -> Vector Double -> WindParameters'
forall a. Vector a -> Vector a -> WindParameters a
WindParameters (Double -> Double -> Vector Double
vectorDegrees Double
trk Double
tas) (Double -> Double -> Vector Double
vectorDegrees Double
wd Double
ws)) (Double -> Double -> Double -> Double -> WindParameters')
-> Parser Double
-> Parser (Double -> Double -> Double -> WindParameters')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"trk" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
't' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"TRACK" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. String -> Mod f a
help String
"Track Direction °"
)
Parser (Double -> Double -> Double -> WindParameters')
-> Parser Double -> Parser (Double -> Double -> WindParameters')
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"tas" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'a' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"TRUE_AIRSPEED" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. String -> Mod f a
help String
"True Air Speed kt"
)
Parser (Double -> Double -> WindParameters')
-> Parser Double -> Parser (Double -> WindParameters')
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"wd" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'd' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"WIND_DIRECTION" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. String -> Mod f a
help String
"Wind Direction °"
)
Parser (Double -> WindParameters')
-> Parser Double -> Parser WindParameters'
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"ws" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"WIND_SPEED" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<>
String -> Mod OptionFields Double
forall (f :: * -> *) a. String -> Mod f a
help String
"Wind Speed kt"
)
optWindParametersVersion ::
Parser (Maybe WindParameters')
optWindParametersVersion :: Parser (Maybe WindParameters')
optWindParametersVersion =
Maybe WindParameters'
-> Mod FlagFields (Maybe WindParameters')
-> Parser (Maybe WindParameters')
forall a. a -> Mod FlagFields a -> Parser a
flag'
Maybe WindParameters'
forall a. Maybe a
Nothing
(
Char -> Mod FlagFields (Maybe WindParameters')
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'v' Mod FlagFields (Maybe WindParameters')
-> Mod FlagFields (Maybe WindParameters')
-> Mod FlagFields (Maybe WindParameters')
forall a. Semigroup a => a -> a -> a
<>
String -> Mod FlagFields (Maybe WindParameters')
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"version" Mod FlagFields (Maybe WindParameters')
-> Mod FlagFields (Maybe WindParameters')
-> Mod FlagFields (Maybe WindParameters')
forall a. Semigroup a => a -> a -> a
<>
String -> Mod FlagFields (Maybe WindParameters')
forall (f :: * -> *) a. String -> Mod f a
help String
"the program version"
) Parser (Maybe WindParameters')
-> Parser (Maybe WindParameters') -> Parser (Maybe WindParameters')
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
WindParameters' -> Maybe WindParameters'
forall a. a -> Maybe a
Just (WindParameters' -> Maybe WindParameters')
-> Parser WindParameters' -> Parser (Maybe WindParameters')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser WindParameters'
optWindParameters