module Drasil.GlassBR.ModuleDefs (allMods, implVars, interpY, interpZ) where
import Language.Drasil (QuantityDict, Space(..), implVar, nounPhraseSP,
label, sub, HasSymbol(..), HasUID, Symbol)
import Language.Drasil.Display (Symbol(..))
import Language.Drasil.ShortHands
import Language.Drasil.Code (($:=), Func, FuncStmt(..), Mod,
asVC, funcDef, fDecDef, ffor, funcData, quantvar,
multiLine, packmod, repeated, singleLine)
import Language.Drasil.CodeExpr
import qualified Drasil.GlassBR.Unitals as U
import Language.Drasil.Printers
allMods :: [Mod]
allMods :: [Mod]
allMods = [Mod
readTableMod, Mod
interpMod]
implVars :: [QuantityDict]
implVars :: [QuantityDict]
implVars = [QuantityDict
v, QuantityDict
x_z_1, QuantityDict
y_z_1, QuantityDict
x_z_2, QuantityDict
y_z_2, QuantityDict
mat, QuantityDict
col,
QuantityDict
i, QuantityDict
j, QuantityDict
k, QuantityDict
z, QuantityDict
zVector, QuantityDict
yMatrix, QuantityDict
xMatrix, QuantityDict
y, QuantityDict
arr, QuantityDict
filename,
QuantityDict
y_2, QuantityDict
y_1, QuantityDict
x_2, QuantityDict
x_1, QuantityDict
x]
readTableMod :: Mod
readTableMod :: Mod
readTableMod = Name -> Name -> [Class] -> [Func] -> Mod
packmod Name
"ReadTable"
Name
"Provides a function for reading glass ASTM data" [] [Func
readTable]
readTable :: Func
readTable :: Func
readTable = Name -> Name -> DataDesc -> Func
funcData Name
"read_table"
Name
"Reads glass ASTM data from a file with the given file name"
[ LinePattern -> Delim -> Data
singleLine ([DataItem] -> LinePattern
repeated [QuantityDict -> DataItem
forall c. (Quantity c, MayHaveUnit c) => c -> DataItem
quantvar QuantityDict
zVector]) Delim
',',
LinePattern -> Delim -> Data
multiLine ([DataItem] -> LinePattern
repeated ((QuantityDict -> DataItem) -> [QuantityDict] -> [DataItem]
forall a b. (a -> b) -> [a] -> [b]
map QuantityDict -> DataItem
forall c. (Quantity c, MayHaveUnit c) => c -> DataItem
quantvar [QuantityDict
xMatrix, QuantityDict
yMatrix])) Delim
','
]
one, two :: Symbol
one :: Symbol
one = Int -> Symbol
Integ Int
1
two :: Symbol
two = Int -> Symbol
Integ Int
2
var :: String -> String -> Symbol -> Space -> QuantityDict
var :: Name -> Name -> Symbol -> Space -> QuantityDict
var Name
nam Name
np Symbol
symb Space
sp = Name -> NP -> Space -> Symbol -> QuantityDict
implVar Name
nam (Name -> NP
nounPhraseSP Name
np) Space
sp Symbol
symb
y_2, y_1, x_2, x_1, x :: QuantityDict
y_1 :: QuantityDict
y_1 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"y1" Name
"lower y-coordinate" (Symbol -> Symbol -> Symbol
sub Symbol
lY Symbol
one) Space
Real
y_2 :: QuantityDict
y_2 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"y2" Name
"upper y-coordinate" (Symbol -> Symbol -> Symbol
sub Symbol
lY Symbol
two) Space
Real
x_1 :: QuantityDict
x_1 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"x1" Name
"lower x-coordinate" (Symbol -> Symbol -> Symbol
sub Symbol
lX Symbol
one) Space
Real
x_2 :: QuantityDict
x_2 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"x2" Name
"upper x-coordinate" (Symbol -> Symbol -> Symbol
sub Symbol
lX Symbol
two) Space
Real
x :: QuantityDict
x = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"x" Name
"x-coordinate to interpolate at" Symbol
lX Space
Real
v, x_z_1, y_z_1, x_z_2, y_z_2, mat, col,
i, j, k, z, zVector, yMatrix, xMatrix, y, arr, filename :: QuantityDict
i :: QuantityDict
i = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"i" Name
"index" Symbol
lI Space
Natural
j :: QuantityDict
j = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"j" Name
"index" Symbol
lJ Space
Natural
k :: QuantityDict
k = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"k" Name
"index" (Symbol -> Symbol -> Symbol
sub Symbol
lK Symbol
two) Space
Natural
v :: QuantityDict
v = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"v" Name
"value whose index will be found" Symbol
lV Space
Real
y :: QuantityDict
y = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"y" Name
"y-coordinate to interpolate at" Symbol
lY Space
Real
z :: QuantityDict
z = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"z" Name
"z-coordinate to interpolate at" Symbol
lZ Space
Real
zVector :: QuantityDict
zVector = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"zVector" Name
"list of z values"
(Symbol -> Symbol -> Symbol
sub Symbol
lZ (Name -> Symbol
label Name
"vector")) (Space -> Space
Vect Space
Real)
yMatrix :: QuantityDict
yMatrix = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"yMatrix" Name
"lists of y values at different z values"
(Symbol -> Symbol -> Symbol
sub Symbol
lY (Name -> Symbol
label Name
"matrix")) (Space -> Space
Vect (Space -> Space) -> Space -> Space
forall a b. (a -> b) -> a -> b
$ Space -> Space
Vect Space
Real)
xMatrix :: QuantityDict
xMatrix = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"xMatrix" Name
"lists of x values at different z values"
(Symbol -> Symbol -> Symbol
sub Symbol
lX (Name -> Symbol
label Name
"matrix")) (Space -> Space
Vect (Space -> Space) -> Space -> Space
forall a b. (a -> b) -> a -> b
$ Space -> Space
Vect Space
Real)
arr :: QuantityDict
arr = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"arr" Name
"array in which value should be found"
(Name -> Symbol
label Name
"arr") (Space -> Space
Vect Space
Real)
x_z_1 :: QuantityDict
x_z_1 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"x_z_1" Name
"list of x values at a specific z value"
(Symbol -> Symbol -> Symbol
sub Symbol
lX (Symbol -> Symbol -> Symbol
sub Symbol
lZ Symbol
one)) (Space -> Space
Vect Space
Real)
y_z_1 :: QuantityDict
y_z_1 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"y_z_1" Name
"list of y values at a specific z value"
(Symbol -> Symbol -> Symbol
sub Symbol
lY (Symbol -> Symbol -> Symbol
sub Symbol
lZ Symbol
one)) (Space -> Space
Vect Space
Real)
x_z_2 :: QuantityDict
x_z_2 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"x_z_2" Name
"list of x values at a specific z value"
(Symbol -> Symbol -> Symbol
sub Symbol
lX (Symbol -> Symbol -> Symbol
sub Symbol
lZ Symbol
two)) (Space -> Space
Vect Space
Real)
y_z_2 :: QuantityDict
y_z_2 = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"y_z_2" Name
"list of y values at a specific z value"
(Symbol -> Symbol -> Symbol
sub Symbol
lY (Symbol -> Symbol -> Symbol
sub Symbol
lZ Symbol
two)) (Space -> Space
Vect Space
Real)
mat :: QuantityDict
mat = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"mat" Name
"matrix from which column will be extracted"
(Name -> Symbol
label Name
"mat") (Space -> Space
Vect (Space -> Space) -> Space -> Space
forall a b. (a -> b) -> a -> b
$ Space -> Space
Vect Space
Real)
col :: QuantityDict
col = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"col" Name
"extracted column"
(Name -> Symbol
label Name
"col") (Space -> Space
Vect Space
Real)
filename :: QuantityDict
filename = Name -> Name -> Symbol -> Space -> QuantityDict
var Name
"filename" Name
"name of file with x y and z data"
(Name -> Symbol
label Name
"filename") Space
String
slope :: (CodeExpr, CodeExpr) -> (CodeExpr, CodeExpr) -> CodeExpr
slope :: (CodeExpr, CodeExpr) -> (CodeExpr, CodeExpr) -> CodeExpr
slope (CodeExpr
x1, CodeExpr
y1) (CodeExpr
x2, CodeExpr
y2) = (CodeExpr
y2 CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$- CodeExpr
y1) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$/ (CodeExpr
x2 CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$- CodeExpr
x1)
onLine :: (CodeExpr, CodeExpr) -> (CodeExpr, CodeExpr) -> CodeExpr -> CodeExpr
onLine :: (CodeExpr, CodeExpr)
-> (CodeExpr, CodeExpr) -> CodeExpr -> CodeExpr
onLine p1 :: (CodeExpr, CodeExpr)
p1@(CodeExpr
x1, CodeExpr
y1) (CodeExpr, CodeExpr)
p2 CodeExpr
x_ = (CodeExpr
m CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$* (CodeExpr
x_ CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$- CodeExpr
x1)) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$+ CodeExpr
y1
where m :: CodeExpr
m = (CodeExpr, CodeExpr) -> (CodeExpr, CodeExpr) -> CodeExpr
slope (CodeExpr, CodeExpr)
p1 (CodeExpr, CodeExpr)
p2
vLook :: (HasSymbol a, HasSymbol i, HasUID a, HasUID i) => a -> i -> CodeExpr -> CodeExpr
vLook :: forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook a
a i
i_ CodeExpr
p = CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx (a -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy a
a) (i -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy i
i_ CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$+ CodeExpr
p)
aLook :: (HasSymbol a, HasSymbol i, HasSymbol j, HasUID a, HasUID i, HasUID j) =>
a -> i -> j -> CodeExpr
aLook :: forall a i j.
(HasSymbol a, HasSymbol i, HasSymbol j, HasUID a, HasUID i,
HasUID j) =>
a -> i -> j -> CodeExpr
aLook a
a i
i_ j
j_ = CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx (CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx (a -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy a
a) (i -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy i
i_)) (j -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy j
j_)
getCol :: (HasSymbol a, HasSymbol i, HasUID a, HasUID i) => a -> i -> CodeExpr -> CodeExpr
getCol :: forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol a
a_ i
i_ CodeExpr
p = QuantityDict -> [CodeExpr] -> CodeExpr
forall f. (HasUID f, HasSymbol f) => f -> [CodeExpr] -> CodeExpr
forall r f. (ExprC r, HasUID f, HasSymbol f) => f -> [r] -> r
apply (Func -> QuantityDict
asVC Func
extractColumnCT) [a -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy a
a_, i -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy i
i_ CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$+ CodeExpr
p]
call :: Func -> [QuantityDict] -> FuncStmt
call :: Func -> [QuantityDict] -> FuncStmt
call Func
f [QuantityDict]
l = CodeExpr -> FuncStmt
FVal (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ QuantityDict -> [CodeExpr] -> CodeExpr
forall f. (HasUID f, HasSymbol f) => f -> [CodeExpr] -> CodeExpr
forall r f. (ExprC r, HasUID f, HasSymbol f) => f -> [r] -> r
apply (Func -> QuantityDict
asVC Func
f) ([CodeExpr] -> CodeExpr) -> [CodeExpr] -> CodeExpr
forall a b. (a -> b) -> a -> b
$ (QuantityDict -> CodeExpr) -> [QuantityDict] -> [CodeExpr]
forall a b. (a -> b) -> [a] -> [b]
map QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy [QuantityDict]
l
find :: (HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) => zv -> z -> CodeExpr
find :: forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find zv
zv z
z_ = QuantityDict -> [CodeExpr] -> CodeExpr
forall f. (HasUID f, HasSymbol f) => f -> [CodeExpr] -> CodeExpr
forall r f. (ExprC r, HasUID f, HasSymbol f) => f -> [r] -> r
apply (Func -> QuantityDict
asVC Func
findCT) [zv -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy zv
zv, z -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy z
z_]
linInterp :: [CodeExpr] -> CodeExpr
linInterp :: [CodeExpr] -> CodeExpr
linInterp = QuantityDict -> [CodeExpr] -> CodeExpr
forall f. (HasUID f, HasSymbol f) => f -> [CodeExpr] -> CodeExpr
forall r f. (ExprC r, HasUID f, HasSymbol f) => f -> [r] -> r
apply (Func -> QuantityDict
asVC Func
linInterpCT)
interpOver :: (HasUID ptx, HasUID pty, HasUID ind, HasUID vv,
HasSymbol ptx, HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver :: forall ptx pty ind vv.
(HasUID ptx, HasUID pty, HasUID ind, HasUID vv, HasSymbol ptx,
HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver ptx
ptx pty
pty ind
ind vv
vv =
[ ptx -> ind -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook ptx
ptx ind
ind (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0), pty -> ind -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook pty
pty ind
ind (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0)
, ptx -> ind -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook ptx
ptx ind
ind (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1), pty -> ind -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook pty
pty ind
ind (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1)
, vv -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy vv
vv ]
linInterpCT :: Func
linInterpCT :: Func
linInterpCT = Name
-> Name
-> [QuantityDict]
-> Space
-> Maybe Name
-> [FuncStmt]
-> Func
forall c.
(Quantity c, MayHaveUnit c) =>
Name -> Name -> [c] -> Space -> Maybe Name -> [FuncStmt] -> Func
funcDef Name
"lin_interp" Name
"Performs linear interpolation"
[QuantityDict
x_1, QuantityDict
y_1, QuantityDict
x_2, QuantityDict
y_2, QuantityDict
x] Space
Real (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
"y value interpolated at given x value")
[ CodeExpr -> FuncStmt
FRet (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ (CodeExpr, CodeExpr)
-> (CodeExpr, CodeExpr) -> CodeExpr -> CodeExpr
onLine (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
x_1, QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_1) (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
x_2, QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_2) (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
x) ]
findCT :: Func
findCT :: Func
findCT = Name
-> Name
-> [QuantityDict]
-> Space
-> Maybe Name
-> [FuncStmt]
-> Func
forall c.
(Quantity c, MayHaveUnit c) =>
Name -> Name -> [c] -> Space -> Maybe Name -> [FuncStmt] -> Func
funcDef Name
"find"
Name
"Finds the array index for a value closest to the given value"
[QuantityDict
arr, QuantityDict
v] Space
Natural (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
"index of given value in given array")
[
QuantityDict -> CodeExpr -> [FuncStmt] -> FuncStmt
forall c.
(Quantity c, MayHaveUnit c) =>
c -> CodeExpr -> [FuncStmt] -> FuncStmt
ffor QuantityDict
i (CodeExpr -> CodeExpr
forall r. ExprC r => r -> r
dim (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
arr) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$- Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1)
[ CodeExpr -> [FuncStmt] -> [FuncStmt] -> FuncStmt
FCond ((QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
arr QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$<= QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
v) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$&& (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
v CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$<= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
arr QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1)))
[ CodeExpr -> FuncStmt
FRet (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
i ] [] ],
Name -> FuncStmt
FThrow Name
"Bound error"
]
extractColumnCT :: Func
extractColumnCT :: Func
extractColumnCT = Name
-> Name
-> [QuantityDict]
-> Space
-> Maybe Name
-> [FuncStmt]
-> Func
forall c.
(Quantity c, MayHaveUnit c) =>
Name -> Name -> [c] -> Space -> Maybe Name -> [FuncStmt] -> Func
funcDef Name
"extractColumn" Name
"Extracts a column from a 2D matrix"
[QuantityDict
mat, QuantityDict
j] (Space -> Space
Vect Space
Real) (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
"column of the given matrix at the given index")
[
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
col ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
QuantityDict -> CodeExpr -> [FuncStmt] -> FuncStmt
forall c.
(Quantity c, MayHaveUnit c) =>
c -> CodeExpr -> [FuncStmt] -> FuncStmt
ffor QuantityDict
i (CodeExpr -> CodeExpr
forall r. ExprC r => r -> r
dim (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
mat))
[ CodeExpr -> CodeExpr -> FuncStmt
FAppend (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
col) (QuantityDict -> QuantityDict -> QuantityDict -> CodeExpr
forall a i j.
(HasSymbol a, HasSymbol i, HasSymbol j, HasUID a, HasUID i,
HasUID j) =>
a -> i -> j -> CodeExpr
aLook QuantityDict
mat QuantityDict
i QuantityDict
j) ],
CodeExpr -> FuncStmt
FRet (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
col)
]
interpY :: Func
interpY :: Func
interpY = Name
-> Name
-> [QuantityDict]
-> Space
-> Maybe Name
-> [FuncStmt]
-> Func
forall c.
(Quantity c, MayHaveUnit c) =>
Name -> Name -> [c] -> Space -> Maybe Name -> [FuncStmt] -> Func
funcDef (QuantityDict -> Name
forall x. HasSymbol x => x -> Name
showHasSymbImpl QuantityDict
U.interpY)
Name
"Linearly interpolates a y value at given x and z values"
[QuantityDict
filename, QuantityDict
x, QuantityDict
z] Space
Real (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
"y value interpolated at given x and z values")
[
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
xMatrix ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
yMatrix ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
zVector ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
Func -> [QuantityDict] -> FuncStmt
call Func
readTable [QuantityDict
filename, QuantityDict
zVector, QuantityDict
xMatrix, QuantityDict
yMatrix],
QuantityDict
i QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr
forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find QuantityDict
zVector QuantityDict
z,
QuantityDict
x_z_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
xMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0),
QuantityDict
y_z_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
yMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0),
QuantityDict
x_z_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
xMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1),
QuantityDict
y_z_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
yMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1),
[FuncStmt] -> [FuncStmt] -> FuncStmt
FTry
[ QuantityDict
j QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr
forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find QuantityDict
x_z_1 QuantityDict
x,
QuantityDict
k QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr
forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find QuantityDict
x_z_2 QuantityDict
x ]
[ Name -> FuncStmt
FThrow Name
"Interpolation of y failed" ],
QuantityDict
y_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= [CodeExpr] -> CodeExpr
linInterp (QuantityDict
-> QuantityDict -> QuantityDict -> QuantityDict -> [CodeExpr]
forall ptx pty ind vv.
(HasUID ptx, HasUID pty, HasUID ind, HasUID vv, HasSymbol ptx,
HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver QuantityDict
x_z_1 QuantityDict
y_z_1 QuantityDict
j QuantityDict
x),
QuantityDict
y_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= [CodeExpr] -> CodeExpr
linInterp (QuantityDict
-> QuantityDict -> QuantityDict -> QuantityDict -> [CodeExpr]
forall ptx pty ind vv.
(HasUID ptx, HasUID pty, HasUID ind, HasUID vv, HasSymbol ptx,
HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver QuantityDict
x_z_2 QuantityDict
y_z_2 QuantityDict
k QuantityDict
x),
CodeExpr -> FuncStmt
FRet (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> CodeExpr
linInterp [ QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
zVector QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0), QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_1, QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
zVector QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1), QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_2, QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
z ]
]
interpZ :: Func
interpZ :: Func
interpZ = Name
-> Name
-> [QuantityDict]
-> Space
-> Maybe Name
-> [FuncStmt]
-> Func
forall c.
(Quantity c, MayHaveUnit c) =>
Name -> Name -> [c] -> Space -> Maybe Name -> [FuncStmt] -> Func
funcDef (QuantityDict -> Name
forall x. HasSymbol x => x -> Name
showHasSymbImpl QuantityDict
U.interpZ)
Name
"Linearly interpolates a z value at given x and y values"
[QuantityDict
filename, QuantityDict
x, QuantityDict
y] Space
Real (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
"z value interpolated at given x and y values")
[
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
xMatrix ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
yMatrix ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
fDecDef QuantityDict
zVector ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[]]),
Func -> [QuantityDict] -> FuncStmt
call Func
readTable [QuantityDict
filename, QuantityDict
zVector, QuantityDict
xMatrix, QuantityDict
yMatrix],
QuantityDict -> CodeExpr -> [FuncStmt] -> FuncStmt
forall c.
(Quantity c, MayHaveUnit c) =>
c -> CodeExpr -> [FuncStmt] -> FuncStmt
ffor QuantityDict
i (CodeExpr -> CodeExpr
forall r. ExprC r => r -> r
dim (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
zVector) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$- Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1)
[
QuantityDict
x_z_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
xMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0),
QuantityDict
y_z_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
yMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0),
QuantityDict
x_z_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
xMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1),
QuantityDict
y_z_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
getCol QuantityDict
yMatrix QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1),
[FuncStmt] -> [FuncStmt] -> FuncStmt
FTry
[ QuantityDict
j QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr
forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find QuantityDict
x_z_1 QuantityDict
x,
QuantityDict
k QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= QuantityDict -> QuantityDict -> CodeExpr
forall zv z.
(HasUID zv, HasUID z, HasSymbol zv, HasSymbol z) =>
zv -> z -> CodeExpr
find QuantityDict
x_z_2 QuantityDict
x ]
[ FuncStmt
FContinue ],
QuantityDict
y_1 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= [CodeExpr] -> CodeExpr
linInterp (QuantityDict
-> QuantityDict -> QuantityDict -> QuantityDict -> [CodeExpr]
forall ptx pty ind vv.
(HasUID ptx, HasUID pty, HasUID ind, HasUID vv, HasSymbol ptx,
HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver QuantityDict
x_z_1 QuantityDict
y_z_1 QuantityDict
j QuantityDict
x),
QuantityDict
y_2 QuantityDict -> CodeExpr -> FuncStmt
forall c. (Quantity c, MayHaveUnit c) => c -> CodeExpr -> FuncStmt
$:= [CodeExpr] -> CodeExpr
linInterp (QuantityDict
-> QuantityDict -> QuantityDict -> QuantityDict -> [CodeExpr]
forall ptx pty ind vv.
(HasUID ptx, HasUID pty, HasUID ind, HasUID vv, HasSymbol ptx,
HasSymbol pty, HasSymbol ind, HasSymbol vv) =>
ptx -> pty -> ind -> vv -> [CodeExpr]
interpOver QuantityDict
x_z_2 QuantityDict
y_z_2 QuantityDict
k QuantityDict
x),
CodeExpr -> [FuncStmt] -> [FuncStmt] -> FuncStmt
FCond ((QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_1 CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$<= QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y) CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$&& (QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$<= QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_2))
[ CodeExpr -> FuncStmt
FRet (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> CodeExpr
linInterp [ QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_1, QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
zVector QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0), QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y_2, QuantityDict -> QuantityDict -> CodeExpr -> CodeExpr
forall a i.
(HasSymbol a, HasSymbol i, HasUID a, HasUID i) =>
a -> i -> CodeExpr -> CodeExpr
vLook QuantityDict
zVector QuantityDict
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1), QuantityDict -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy QuantityDict
y ]
] []
],
Name -> FuncStmt
FThrow Name
"Interpolation of z failed"
]
interpMod :: Mod
interpMod :: Mod
interpMod = Name -> Name -> [Class] -> [Func] -> Mod
packmod Name
"Interpolation"
Name
"Provides functions for linear interpolation on three-dimensional data" []
[Func
linInterpCT, Func
findCT, Func
extractColumnCT, Func
interpY, Func
interpZ]