text:
# Syntax → Graph

type LateVertex{T}
  val::DVertex{T}
  args::Vector{Any}
end

function bindings(ex)
  bs = []
  for ex in ex.args
    @capture(ex, x_ = _) && push!(bs, x)
  end
  return bs
end

function normedges(ex)
  map!(ex.args, ex.args) do ex
    isline(ex) ? ex :
    @capture(ex, _ = _) ? ex :
    :($(gensym("edge")) = $ex)
  end
  return ex
end

normalise(ex) =
  @> ex normsplits normclosures normedges normlines desugar

function latenodes(exs)
  bindings = d()
  for ex in exs
    @capture(ex, b_Symbol = (f_(a__) | f_)) || error("invalid flow binding `$ex`")
    bindings[b] = a == nothing ? constant(f) : LateVertex(dvertex(f), a)
  end
  return bindings
end

graphm(bindings, node) = constant(node)
graphm(bindings, node::Vertex) = node
graphm(bindings, ex::Symbol) =
  haskey(bindings, ex) ? graphm(bindings, bindings[ex]) : constant(ex)
graphm(bindings, node::LateVertex) = node.val

function graphm(bindings, ex::Expr)
  isexpr(ex, :block) && return graphm(bindings, ex.args)
  @capture(ex, f_(args__)) || return constant(ex)
  dvertex(f, map(ex -> graphm(bindings, ex), args)...)
end

function fillnodes!(bindings)
  for (b, node) in bindings
    if isa(node, Vertex) && isconstant(node) && haskey(bindings, value(node).value)
      alias = bindings[value(node).value]
      isa(alias, LateVertex) && (alias = alias.val)
      bindings[b] = alias
    end
  end
  for (b, node) in bindings
    isa(node, LateVertex) || continue
    for arg in node.args
      thread!(node.val, graphm(bindings, arg))
    end
    bindings[b] = node.val
  end
  return bindings
end

function graphm(bindings, exs::Vector)
  exs = normalise(:($(exs...);)).args
  @capture(exs[end], result_Symbol = _)
  merge!(bindings, latenodes(exs))
  fillnodes!(bindings)
  output = graphm(bindings, result)
end

graphm(x) = graphm(d(), x)


text:
### A Pluto.jl notebook ###
# v0.15.1

using Markdown
using InteractiveUtils

# ╔═╡ 08d32844-010a-11ec-1ccf-2359999874d2
using Javis, Colors

# ╔═╡ 5f34a9e3-4970-4871-beb2-9554d00bd43c
begin

    n_frames = 1000
    n_poly = 50
    radius = 150

    function ground(args...)
        background("white")
        sethue("black")
    end

    function circoradius(r, n)
        halfl = r / tan(π * ((n - 2) / 2n))
        newr = sqrt(r^2 + halfl^2)
    end

    my_video = Video(450, 450)
    step_size = n_frames ÷ n_poly
    colors = range(colorant"red", colorant"blue", length = n_poly - 1)
    Background(1:n_frames, ground)

    for i in 1:(n_poly - 1)
        Object(
            ((i - 1) * step_size):(i * step_size),
            @JShape begin
                setline(2)
                sethue(colors[i])
                ngon(O, circoradius(radius, i), i, 0, :stroke)
                ngon(O, radius, i, 0, :stroke)
            end
        )
        Object(
            ((i - 1) * step_size):(i * step_size),
            @JShape begin
                fontsize(30)
                label("N. Sides", :N, offset = 20)
                fontsize(40)
                sethue(colors[i])
                text(string(i), valign = :top, halign = :center)
            end
        )
    end

    Object(1:n_frames, @JShape begin
        sethue(colors[end])
        setline(2)
        circle(O, radius, :stroke)
    end)

    render(my_video, pathname = "../output/circle_area.gif")
end

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Javis = "78b212ba-a7f9-42d4-b726-60726080707e"

[compat]
Colors = "~0.12.8"
Javis = "~0.6.2"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

[[ATK_jll]]
deps = ["Artifacts", "Glib_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "58c36d8a1beeb12d63921bcfaa674baf30a1140e"
uuid = "7b86fcea-f67b-53e1-809c-8f1719c154e8"
version = "2.36.1+0"

[[AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "485ee0867925449198280d4af84bdb46a2a404d0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.0.1"

[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.1"

[[Animations]]
deps = ["Colors"]
git-tree-sha1 = "e81c509d2c8e49592413bfb0bb3b08150056c79d"
uuid = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
version = "0.4.1"

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[ArrayInterface]]
deps = ["IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "a4f25b43826d5847c04e925dd846692835956131"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "3.1.24"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[AssetRegistry]]
deps = ["Distributed", "JSON", "Pidfile", "SHA", "Test"]
git-tree-sha1 = "b25e88db7944f98789130d7b503276bc34bc098e"
uuid = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
version = "0.1.0"

[[AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.0.0"

[[AxisArrays]]
deps = ["Dates", "IntervalSets", "IterTools", "RangeArrays"]
git-tree-sha1 = "d127d5e4d86c7680b20c35d40b503c74b9a39b5e"
uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
version = "0.4.4"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"

[[CEnum]]
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.1"

[[CSSUtil]]
deps = ["Colors", "JSON", "Markdown", "Measures", "WebIO"]
git-tree-sha1 = "b9fb4b464ec10e860abe251b91d4d049934f7399"
uuid = "70588ee8-6100-5070-97c1-3cb50ed05fe8"
version = "0.1.1"

[[Cairo]]
deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"]
git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b"
uuid = "159f3aea-2a34-519c-b102-8c37f9878175"
version = "1.0.5"

[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "f2202b55d816427cd385a9a4f3ffb226bee80f99"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+0"

[[CatIndices]]
deps = ["CustomUnitRanges", "OffsetArrays"]
git-tree-sha1 = "a0f80a09780eed9b1d106a1bf62041c2efc995bc"
uuid = "aafaddc9-749c-510e-ac4f-586e18779b91"
version = "0.2.2"

[[ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "bdc0937269321858ab2a4f288486cb258b9a0af7"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.3.0"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "32a2b8af383f11cbb65803883837a149d10dfe8a"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.10.12"

[[ColorVectorSpace]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase"]
git-tree-sha1 = "4d17724e99f357bfd32afa0a9e2dda2af31a9aea"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.8.7"

[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "727e463cfebd0c7b999bbf3e9e7e16f254b94193"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.34.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[ComputationalResources]]
git-tree-sha1 = "52cb3ec90e8a8bea0e62e275ba577ad0f74821f7"
uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3"
version = "0.3.2"

[[CoordinateTransformations]]
deps = ["LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "6d1c23e740a586955645500bbec662476204a52c"
uuid = "150eb455-5306-5404-9cee-2592286d6298"
version = "0.6.1"

[[CustomUnitRanges]]
git-tree-sha1 = "1a3f97f907e6dd8983b744d2642651bb162a3f7a"
uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce"
version = "1.0.2"

[[DataAPI]]
git-tree-sha1 = "ee400abb2298bd13bfc3df1c412ed228061a2385"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.7.0"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.10"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Dbus_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "97f1325c10bd02b1cc1882e9c2bf6407ba630ace"
uuid = "ee1fde0b-3d02-5ea6-8484-8dfef6360eab"
version = "1.12.16+3"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distances]]
deps = ["LinearAlgebra", "Statistics", "StatsAPI"]
git-tree-sha1 = "abe4ad222b26af3337262b8afb28fab8d215e9f8"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.10.3"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "a32185f5428d3986f47c2ab78b1f216d5e6cc96f"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.5"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[EllipsisNotation]]
deps = ["ArrayInterface"]
git-tree-sha1 = "8041575f021cba5a099a456b4163c9a08b566a02"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "1.1.0"

[[Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b3bfd02e98aedfa5cf885665493c5598c350cd2f"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.2.10+0"

[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"

[[FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "d8a578692e3077ac998b50c0217dfd67f21d1e5f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.0+0"

[[FFTViews]]
deps = ["CustomUnitRanges", "FFTW"]
git-tree-sha1 = "70a0cfd9b1c86b0209e38fbfe6d8231fd606eeaf"
uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd"
version = "0.3.1"

[[FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"]
git-tree-sha1 = "f985af3b9f4e278b1d24434cbb546d6092fca661"
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
version = "1.4.3"

[[FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3676abafff7e4ff07bbd2c42b3d8201f31653dcc"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.9+8"

[[FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "937c29268e405b6808d958a9ac41bfe1a31b08e7"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.11.0"

[[FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"

[[Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.93+0"

[[FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.4+0"

[[FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0"

[[FunctionalCollections]]
deps = ["Test"]
git-tree-sha1 = "04cb9cfaa6ba5311973994fe3496ddec19b6292a"
uuid = "de31a74c-ac4f-5751-b3fd-e18cd04993ca"
version = "0.5.0"

[[GTK3_jll]]
deps = ["ATK_jll", "Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Libepoxy_jll", "Pango_jll", "Pkg", "Wayland_jll", "Xorg_libX11_jll", "Xorg_libXcomposite_jll", "Xorg_libXcursor_jll", "Xorg_libXdamage_jll", "Xorg_libXext_jll", "Xorg_libXfixes_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll", "Xorg_libXrender_jll", "at_spi2_atk_jll", "gdk_pixbuf_jll", "iso_codes_jll", "xkbcommon_jll"]
git-tree-sha1 = "f2922cb0105ba076b560e3922910f8e3749aa91a"
uuid = "77ec8976-b24b-556a-a1bf-49a033a670a6"
version = "3.24.30+0"

[[Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"

[[Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "7bf67e9a481712b3dbe9cb3dac852dc4b1162e02"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.3+0"

[[Glob]]
git-tree-sha1 = "4df9f7e06108728ebf00a0a11edee4b29a482bb2"
uuid = "c27321d9-0574-5035-807b-f59d2c89b15c"
version = "1.3.0"

[[Graphics]]
deps = ["Colors", "LinearAlgebra", "NaNMath"]
git-tree-sha1 = "2c1cf4df419938ece72de17f368a021ee162762e"
uuid = "a2bd30eb-e257-5431-a919-1863eab51364"
version = "1.1.0"

[[Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011"
uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472"
version = "1.3.14+0"

[[Gtk]]
deps = ["Cairo", "Cairo_jll", "Dates", "GTK3_jll", "Glib_jll", "Graphics", "Libdl", "Pkg", "Reexport", "Serialization", "Test", "Xorg_xkeyboard_config_jll", "adwaita_icon_theme_jll", "gdk_pixbuf_jll", "hicolor_icon_theme_jll"]
git-tree-sha1 = "d679fc90e75984e7b8eb25702eff7cf4718a9c10"
uuid = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
version = "1.1.9"

[[GtkReactive]]
deps = ["Cairo", "Colors", "Dates", "FixedPointNumbers", "Graphics", "Gtk", "IntervalSets", "Reactive", "Reexport", "RoundingIntegers"]
git-tree-sha1 = "2a82c9204afbd8bfb39c0d6735bface4a3df9917"
uuid = "27996c0f-39cd-5cc1-a27a-05f136f946b6"
version = "1.0.5"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
git-tree-sha1 = "c7ec02c4c6a039a98a15f955462cd7aea5df4508"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.8.19"

[[HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
git-tree-sha1 = "8a954fed8ac097d5be04921d595f741115c1b2ad"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "2.8.1+0"

[[Hungarian]]
deps = ["LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "371a7df7a6cce5909d6c576f234a2da2e3fa0c98"
uuid = "e91730f6-4275-51fb-a7a0-7064cfbd3b39"
version = "0.6.0"

[[IdentityRanges]]
deps = ["OffsetArrays"]
git-tree-sha1 = "be8fcd695c4da16a1d6d0cd213cb88090a150e3b"
uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca"
version = "0.3.1"

[[IfElse]]
git-tree-sha1 = "28e837ff3e7a6c3cdb252ce49fb412c8eb3caeef"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
version = "0.1.0"

[[ImageAxes]]
deps = ["AxisArrays", "ImageCore", "Reexport", "SimpleTraits"]
git-tree-sha1 = "794ad1d922c432082bc1aaa9fa8ffbd1fe74e621"
uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac"
version = "0.6.9"

[[ImageContrastAdjustment]]
deps = ["ColorVectorSpace", "ImageCore", "ImageTransformations", "Parameters"]
git-tree-sha1 = "2e6084db6cccab11fe0bc3e4130bd3d117092ed9"
uuid = "f332f351-ec65-5f6a-b3d1-319c6670881a"
version = "0.3.7"

[[ImageCore]]
deps = ["AbstractFFTs", "Colors", "FixedPointNumbers", "Graphics", "MappedArrays", "MosaicViews", "OffsetArrays", "PaddedViews", "Reexport"]
git-tree-sha1 = "db645f20b59f060d8cfae696bc9538d13fd86416"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.8.22"

[[ImageDistances]]
deps = ["ColorVectorSpace", "Distances", "ImageCore", "ImageMorphology", "LinearAlgebra", "Statistics"]
git-tree-sha1 = "6378c34a3c3a216235210d19b9f495ecfff2f85f"
uuid = "51556ac3-7006-55f5-8cb3-34580c88182d"
version = "0.2.13"

[[ImageFiltering]]
deps = ["CatIndices", "ColorVectorSpace", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "ImageCore", "LinearAlgebra", "OffsetArrays", "Requires", "SparseArrays", "StaticArrays", "Statistics", "TiledIteration"]
git-tree-sha1 = "bf96839133212d3eff4a1c3a80c57abc7cfbf0ce"
uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
version = "0.6.21"

[[ImageIO]]
deps = ["FileIO", "Netpbm", "OpenEXR", "PNGFiles", "TiffImages", "UUIDs"]
git-tree-sha1 = "ba5334adebad6bcf43f2586e7151d2c83f09f9b6"
uuid = "82e4d734-157c-48bb-816b-45c225c6df19"
version = "0.5.7"

[[ImageMagick]]
deps = ["FileIO", "ImageCore", "ImageMagick_jll", "InteractiveUtils", "Libdl", "Pkg", "Random"]
git-tree-sha1 = "5bc1cb62e0c5f1005868358db0692c994c3a13c6"
uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
version = "1.2.1"

[[ImageMagick_jll]]
deps = ["JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pkg", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "1c0a2295cca535fabaf2029062912591e9b61987"
uuid = "c73af94c-d91f-53ed-93a7-00f77d67a9d7"
version = "6.9.10-12+3"

[[ImageMetadata]]
deps = ["AxisArrays", "ColorVectorSpace", "ImageAxes", "ImageCore", "IndirectArrays"]
git-tree-sha1 = "ae76038347dc4edcdb06b541595268fca65b6a42"
uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49"
version = "0.9.5"

[[ImageMorphology]]
deps = ["ColorVectorSpace", "ImageCore", "LinearAlgebra", "TiledIteration"]
git-tree-sha1 = "68e7cbcd7dfaa3c2f74b0a8ab3066f5de8f2b71d"
uuid = "787d08f9-d448-5407-9aad-5290dd7ab264"
version = "0.2.11"

[[ImageQualityIndexes]]
deps = ["ColorVectorSpace", "ImageCore", "ImageDistances", "ImageFiltering", "OffsetArrays", "Statistics"]
git-tree-sha1 = "1198f85fa2481a3bb94bf937495ba1916f12b533"
uuid = "2996bd0c-7a13-11e9-2da2-2f5ce47296a9"
version = "0.2.2"

[[ImageShow]]
deps = ["Base64", "FileIO", "ImageCore", "OffsetArrays", "Requires", "StackViews"]
git-tree-sha1 = "832abfd709fa436a562db47fd8e81377f72b01f9"
uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31"
version = "0.3.1"

[[ImageTransformations]]
deps = ["AxisAlgorithms", "ColorVectorSpace", "CoordinateTransformations", "IdentityRanges", "ImageCore", "Interpolations", "OffsetArrays", "Rotations", "StaticArrays"]
git-tree-sha1 = "e4cc551e4295a5c96545bb3083058c24b78d4cf0"
uuid = "02fcd773-0e25-5acc-982a-7f6622650795"
version = "0.8.13"

[[Images]]
deps = ["AxisArrays", "Base64", "ColorVectorSpace", "FileIO", "Graphics", "ImageAxes", "ImageContrastAdjustment", "ImageCore", "ImageDistances", "ImageFiltering", "ImageIO", "ImageMagick", "ImageMetadata", "ImageMorphology", "ImageQualityIndexes", "ImageShow", "ImageTransformations", "IndirectArrays", "OffsetArrays", "Random", "Reexport", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "TiledIteration"]
git-tree-sha1 = "8b714d5e11c91a0d945717430ec20f9251af4bd2"
uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
version = "0.24.1"

[[Imath_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "87f7662e03a649cffa2e05bf19c303e168732d3e"
uuid = "905a6f67-0a94-5f89-b386-d35d92009cd1"
version = "3.1.2+0"

[[IndirectArrays]]
git-tree-sha1 = "c2a145a145dc03a7620af1444e0264ef907bd44f"
uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959"
version = "0.5.1"

[[Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.2"

[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"

[[IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d979e54b71da82f3a65b62553da4fc3d18c9004c"
uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"
version = "2018.0.3+2"

[[Interact]]
deps = ["CSSUtil", "InteractBase", "JSON", "Knockout", "Observables", "OrderedCollections", "Reexport", "WebIO", "Widgets"]
git-tree-sha1 = "381c584142ac744bcc23af64bff3e3dc44d7f632"
uuid = "c601a237-2ae4-5e1e-952c-7a85b0c7eef1"
version = "0.10.3"

[[InteractBase]]
deps = ["Base64", "CSSUtil", "Colors", "Dates", "JSExpr", "JSON", "Knockout", "Observables", "OrderedCollections", "Random", "WebIO", "Widgets"]
git-tree-sha1 = "e63b4726c282829617de0f57ce1e4e050702439a"
uuid = "d3863d7c-f0c8-5437-a7b4-3ae773c01009"
version = "0.10.6"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Interpolations]]
deps = ["AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]
git-tree-sha1 = "61aa005707ea2cebf47c8d780da8dc9bc4e0c512"
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
version = "0.13.4"

[[IntervalSets]]
deps = ["Dates", "EllipsisNotation", "Statistics"]
git-tree-sha1 = "3cc368af3f110a767ac786560045dceddfc16758"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.5.3"

[[IrrationalConstants]]
git-tree-sha1 = "f76424439413893a832026ca355fe273e93bce94"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.1.0"

[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"

[[JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"

[[JSExpr]]
deps = ["JSON", "MacroTools", "Observables", "WebIO"]
git-tree-sha1 = "bd6c034156b1e7295450a219c4340e32e50b08b1"
uuid = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
version = "0.5.3"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.2"

[[Javis]]
deps = ["Animations", "Cairo", "FFMPEG", "Gtk", "GtkReactive", "Hungarian", "ImageIO", "ImageMagick", "Images", "Interact", "LaTeXStrings", "LightXML", "Luxor", "ProgressMeter", "Random", "Statistics", "VideoIO"]
git-tree-sha1 = "bd8b23bd0f7382aaddb5332d92e692a8ee1e8db3"
uuid = "78b212ba-a7f9-42d4-b726-60726080707e"
version = "0.6.2"

[[JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d735490ac75c5cb9f1b00d8b5509c11984dc6943"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "2.1.0+0"

[[Juno]]
deps = ["Base64", "Logging", "Media", "Profile"]
git-tree-sha1 = "07cb43290a840908a771552911a6274bc6c072c7"
uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
version = "0.8.4"

[[Knockout]]
deps = ["JSExpr", "JSON", "Observables", "Test", "WebIO"]
git-tree-sha1 = "8b5552a7a9efc2b0565e2256c919651e6f4e7931"
uuid = "bcebb21b-c2e3-54f8-a781-646b90f6d2cc"
version = "0.2.4"

[[LAME_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac"
version = "2.10.1+0"

[[LaTeXStrings]]
git-tree-sha1 = "c7f1c695e06c01b95a67f0cd1d34994f3e7db104"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.2.1"

[[LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libcroco_jll]]
deps = ["Artifacts", "Glib_jll", "JLLWrappers", "Libdl", "Pkg", "XML2_jll"]
git-tree-sha1 = "a8e3b1b67458c8933992b95db9c4b37865906e3f"
uuid = "57eb2189-7eb1-52c8-ac0e-99495f550b14"
version = "0.6.13+2"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Libepoxy_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "ae76616c0e0cbcbedc68d0121fe409598efc0b05"
uuid = "42c93a91-0102-5b3f-8f9d-e41de60ac950"
version = "1.5.8+0"

[[Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "761a393aeccd6aa92ec3515e428c26bf99575b3b"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.2+0"

[[Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae"
uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4"
version = "1.8.7+0"

[[Libglvnd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll", "Xorg_libXext_jll"]
git-tree-sha1 = "7739f837d6447403596a75d19ed01fd08d6f56bf"
uuid = "7e76a0d4-f3c7-5321-8279-8d96eeed0f29"
version = "1.3.0+3"

[[Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.42.0+0"

[[Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.1+1"

[[Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[Librsvg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libcroco_jll", "Libdl", "Pango_jll", "Pkg", "gdk_pixbuf_jll"]
git-tree-sha1 = "af3e6dc6747e53a0236fbad80b37e3269cf66a9f"
uuid = "925c91fb-5dd6-59dd-8e8c-345e74382d89"
version = "2.42.2+3"

[[Libtiff_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
git-tree-sha1 = "340e257aada13f95f98ee352d316c3bed37c8ab9"
uuid = "89763e89-9b03-5906-acba-b20f662cd828"
version = "4.3.0+0"

[[Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.36.0+0"

[[LightXML]]
deps = ["Libdl", "XML2_jll"]
git-tree-sha1 = "e129d9391168c677cd4800f5c0abb1ed8cb3794f"
uuid = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
version = "0.9.0"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[LogExpFunctions]]
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "3d682c07e6dd250ed082f883dc88aee7996bf2cc"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.0"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Luxor]]
deps = ["Base64", "Cairo", "Colors", "Dates", "FFMPEG", "FileIO", "ImageMagick", "Juno", "QuartzImageIO", "Random", "Rsvg"]
git-tree-sha1 = "b2b3d49ffb3b89d9e052da47a0b6df13579738ea"
uuid = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
version = "2.15.0"

[[MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "c253236b0ed414624b083e6b72bfe891fbd2c7af"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2021.1.1+1"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "0fb723cd8c45858c22169b2e42269e53271a6df7"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.7"

[[MappedArrays]]
git-tree-sha1 = "e8b359ef06ec72e8c030463fe02efe5527ee5142"
uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
version = "0.4.1"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "1c38e51c3d08ef2278062ebceade0e46cefc96fe"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.3"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[Measures]]
git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f"
uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
version = "0.3.1"

[[Media]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58"
uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27"
version = "0.5.0"

[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "2ca267b08821e86c5ef4376cffed98a46c2cb205"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.1"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[MosaicViews]]
deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"]
git-tree-sha1 = "b34e3bc3ca7c94914418637cb10cc4d1d80d877d"
uuid = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389"
version = "0.3.3"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NaNMath]]
git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.5"

[[Netpbm]]
deps = ["ColorVectorSpace", "FileIO", "ImageCore"]
git-tree-sha1 = "09589171688f0039f13ebe0fdcc7288f50228b52"
uuid = "f09324ee-3d7c-5217-9330-fc30815ba969"
version = "1.0.1"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[Observables]]
git-tree-sha1 = "3469ef96607a6b9a1e89e54e6f23401073ed3126"
uuid = "510215fc-4207-5dde-b226-833fc4488ee2"
version = "0.3.3"

[[OffsetArrays]]
deps = ["Adapt"]
git-tree-sha1 = "c0f4a4836e5f3e0763243b8324200af6d0e0f90c"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.10.5"

[[Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7937eda4681660b4d6aeeecc2f7e1c81c8ee4e2f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+0"

[[OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
git-tree-sha1 = "327f53360fdb54df7ecd01e96ef1983536d1e633"
uuid = "52e1d378-f018-4a11-a4be-720524705ac7"
version = "0.3.2"

[[OpenEXR_jll]]
deps = ["Artifacts", "Imath_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "923319661e9a22712f24596ce81c54fc0366f304"
uuid = "18a262bb-aa17-5467-a713-aee519bc75cb"
version = "3.1.1+0"

[[OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "15003dcb7d8db3c6c857fda14891a539a8f2705a"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.10+0"

[[OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.5+0"

[[Opus_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.2+0"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.44.0+0"

[[PNGFiles]]
deps = ["Base64", "CEnum", "ImageCore", "IndirectArrays", "OffsetArrays", "libpng_jll"]
git-tree-sha1 = "520e28d4026d16dcf7b8c8140a3041f0e20a9ca8"
uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
version = "0.3.7"

[[PaddedViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "646eed6f6a5d8df6708f15ea7e02a7a2c4fe4800"
uuid = "5432bcbf-9aad-5242-b902-cca2824c8663"
version = "0.5.10"

[[Pango_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9bc1871464b12ed19297fbc56c4fb4ba84988b0d"
uuid = "36c8627f-9965-5494-a995-c6b170f724f3"
version = "1.47.0+0"

[[Parameters]]
deps = ["OrderedCollections", "UnPack"]
git-tree-sha1 = "2276ac65f1e236e0a6ea70baff3f62ad4c625345"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.12.2"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "438d35d2d95ae2c5e8780b330592b6de8494e779"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.0.3"

[[Pidfile]]
deps = ["FileWatching", "Test"]
git-tree-sha1 = "1be8660b2064893cd2dae4bd004b589278e4440d"
uuid = "fa939f87-e72e-5be4-a000-7fc836dbe307"
version = "1.2.0"

[[Pixman_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29"
uuid = "30392449-352a-5448-841d-b1acce4e97dc"
version = "0.40.1+0"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PkgVersion]]
deps = ["Pkg"]
git-tree-sha1 = "a7a7e1a88853564e551e4eba8650f8c38df79b37"
uuid = "eebad327-c553-4316-9ea0-9fa01ccd7688"
version = "0.1.1"

[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Profile]]
deps = ["Printf"]
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[[ProgressMeter]]
deps = ["Distributed", "Printf"]
git-tree-sha1 = "afadeba63d90ff223a6a48d2009434ecee2ec9e8"
uuid = "92933f4c-e287-5a05-a399-4b506db050ca"
version = "1.7.1"

[[QuartzImageIO]]
deps = ["ColorVectorSpace", "FileIO", "ImageCore", "Libdl"]
git-tree-sha1 = "29c1803a9d6d1c7c2130610df5da953c49366976"
uuid = "dca85d43-d64c-5e67-8c65-017450d5d020"
version = "0.7.3"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RangeArrays]]
git-tree-sha1 = "b9039e93773ddcfc828f12aadf7115b4b4d225f5"
uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d"
version = "0.3.2"

[[Ratios]]
deps = ["Requires"]
git-tree-sha1 = "7dff99fbc740e2f8228c6878e2aad6d7c2678098"
uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
version = "0.4.1"

[[Reactive]]
deps = ["DataStructures", "Distributed", "Test"]
git-tree-sha1 = "5862d915387ebb954016f50a88e34f79a9e5fcd2"
uuid = "a223df75-4e93-5b7c-acf9-bdd599c0f4de"
version = "0.8.3"

[[Reexport]]
deps = ["Pkg"]
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"

[[Rotations]]
deps = ["LinearAlgebra", "StaticArrays", "Statistics"]
git-tree-sha1 = "2ed8d8a16d703f900168822d83699b8c3c1a5cd8"
uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc"
version = "1.0.2"

[[RoundingIntegers]]
deps = ["Test"]
git-tree-sha1 = "293ba0ab32218b9ffd596040224228def84f8da0"
uuid = "d5f540fe-1c90-5db3-b776-2e2f362d9394"
version = "0.2.0"

[[Rsvg]]
deps = ["Cairo", "Glib_jll", "Librsvg_jll"]
git-tree-sha1 = "3d3dc66eb46568fb3a5259034bfc752a0eb0c686"
uuid = "c4c386cf-5103-5370-be45-f3a111cca3b8"
version = "1.0.0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[SimpleTraits]]
deps = ["InteractiveUtils", "MacroTools"]
git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231"
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
version = "0.9.4"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.1"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[SpecialFunctions]]
deps = ["ChainRulesCore", "LogExpFunctions", "OpenSpecFun_jll"]
git-tree-sha1 = "a322a9493e49c5f3a10b50df3aedaf1cdb3244b7"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "1.6.1"

[[StackViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c"
uuid = "cae243ae-269e-4f55-b966-ac2d0dc13c15"
version = "0.1.1"

[[Static]]
deps = ["IfElse"]
git-tree-sha1 = "62701892d172a2fa41a1f829f66d2b0db94a9a63"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
version = "0.3.0"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "3240808c6d463ac46f1c1cd7638375cd22abbccb"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.2.12"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[StatsAPI]]
git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.0.0"

[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "fed1ec1e65749c4d96fc20dd13bea72b55457e62"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.9"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[TiffImages]]
deps = ["ColorTypes", "DocStringExtensions", "FileIO", "FixedPointNumbers", "IndirectArrays", "Inflate", "OffsetArrays", "OrderedCollections", "PkgVersion", "ProgressMeter"]
git-tree-sha1 = "03fb246ac6e6b7cb7abac3b3302447d55b43270e"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
version = "0.4.1"

[[TiledIteration]]
deps = ["OffsetArrays"]
git-tree-sha1 = "52c5f816857bfb3291c7d25420b1f4aca0a74d18"
uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac"
version = "0.3.0"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[UnPack]]
git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b"
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
version = "1.0.2"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[VideoIO]]
deps = ["ColorTypes", "Dates", "FFMPEG", "Glob", "ImageCore", "ImageTransformations", "Libdl", "ProgressMeter", "Requires"]
git-tree-sha1 = "5beecd069b48a6d23a64328401489e6556d6cda3"
uuid = "d6d074c3-1acf-5d4c-9a43-ef38773959a2"
version = "0.8.4"

[[Wayland_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "3e61f0b86f90dacb0bc0e73a0c5a83f6a8636e23"
uuid = "a2964d1f-97da-50d4-b82a-358c7fce9d89"
version = "1.19.0+0"

[[Wayland_protocols_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll"]
git-tree-sha1 = "2839f1c1296940218e35df0bbb220f2a79686670"
uuid = "2381bf8a-dfd0-557d-9999-79630e7b1b91"
version = "1.18.0+4"

[[WebIO]]
deps = ["AssetRegistry", "Base64", "Distributed", "FunctionalCollections", "JSON", "Logging", "Observables", "Pkg", "Random", "Requires", "Sockets", "UUIDs", "WebSockets", "Widgets"]
git-tree-sha1 = "adc25e225bc334c7df6eec3b39496edfc451cc38"
uuid = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
version = "0.8.15"

[[WebSockets]]
deps = ["Base64", "Dates", "HTTP", "Logging", "Sockets"]
git-tree-sha1 = "f91a602e25fe6b89afc93cf02a4ae18ee9384ce3"
uuid = "104b5d7c-a370-577a-8038-80a2059c5097"
version = "1.5.9"

[[Widgets]]
deps = ["Colors", "Dates", "Observables", "OrderedCollections"]
git-tree-sha1 = "eae2fbbc34a79ffd57fb4c972b08ce50b8f6a00d"
uuid = "cc8bc4a8-27d6-5769-a93b-9d913e69aa62"
version = "0.6.3"

[[WoodburyMatrices]]
deps = ["LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "59e2ad8fd1591ea019a5259bd012d7aee15f995c"
uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6"
version = "0.5.3"

[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"

[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"

[[Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.6.9+4"

[[Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e"
uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec"
version = "1.0.9+4"

[[Xorg_libXcomposite_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll"]
git-tree-sha1 = "7c688ca9c957837539bbe1c53629bb871025e423"
uuid = "3c9796d7-64a0-5134-86ad-79f8eb684845"
version = "0.4.5+4"

[[Xorg_libXcursor_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "12e0eb3bc634fa2080c1c37fccf56f7c22989afd"
uuid = "935fb764-8cf2-53bf-bb30-45bb1f8bf724"
version = "1.2.0+4"

[[Xorg_libXdamage_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll"]
git-tree-sha1 = "fe4ffb2024ba3eddc862c6e1d70e2b070cd1c2bf"
uuid = "0aeada51-83db-5f97-b67e-184615cfc6f6"
version = "1.1.5+4"

[[Xorg_libXdmcp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4"
uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05"
version = "1.1.3+4"

[[Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.4+4"

[[Xorg_libXfixes_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "0e0dc7431e7a0587559f9294aeec269471c991a4"
uuid = "d091e8ba-531a-589c-9de9-94069b037ed8"
version = "5.0.3+4"

[[Xorg_libXi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXfixes_jll"]
git-tree-sha1 = "89b52bc2160aadc84d707093930ef0bffa641246"
uuid = "a51aa0fd-4e3c-5386-b890-e753decda492"
version = "1.7.10+4"

[[Xorg_libXinerama_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll"]
git-tree-sha1 = "26be8b1c342929259317d8b9f7b53bf2bb73b123"
uuid = "d1454406-59df-5ea1-beac-c340f2130bc3"
version = "1.1.4+4"

[[Xorg_libXrandr_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "34cea83cb726fb58f325887bf0612c6b3fb17631"
uuid = "ec84b674-ba8e-5d96-8ba1-2a689ba10484"
version = "1.5.2+4"

[[Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96"
uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa"
version = "0.9.10+4"

[[Xorg_libXtst_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXfixes_jll", "Xorg_libXi_jll"]
git-tree-sha1 = "0c0a60851f44add2a64069ddf213e941c30ed93c"
uuid = "b6f176f1-7aea-5357-ad67-1d3e565ea1c6"
version = "1.2.3+4"

[[Xorg_libpthread_stubs_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb"
uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74"
version = "0.1.0+3"

[[Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.13.0+3"

[[Xorg_libxkbfile_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "926af861744212db0eb001d9e40b5d16292080b2"
uuid = "cc61e674-0454-545c-8b26-ed2c68acab7a"
version = "1.1.0+4"

[[Xorg_xkbcomp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxkbfile_jll"]
git-tree-sha1 = "4bcbf660f6c2e714f87e960a171b119d06ee163b"
uuid = "35661453-b289-5fab-8a00-3d9160c6a3a4"
version = "1.4.2+4"

[[Xorg_xkeyboard_config_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xkbcomp_jll"]
git-tree-sha1 = "5c8424f8a67c3f2209646d4425f3d415fee5931d"
uuid = "33bec58e-1273-512f-9401-5d533626f822"
version = "2.27.0+4"

[[Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845"
uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10"
version = "1.4.0+3"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[Zstd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "cc4bf3fdde8b7e3e9fa0351bdeedba1cf3b7f6e6"
uuid = "3161d3a3-bdf6-5164-811a-617609db77b4"
version = "1.5.0+0"

[[adwaita_icon_theme_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "hicolor_icon_theme_jll"]
git-tree-sha1 = "37c9a36ccb876e02876c8a654f1b2e8c1b443a78"
uuid = "b437f822-2cd6-5e08-a15c-8bac984d38ee"
version = "3.33.92+5"

[[at_spi2_atk_jll]]
deps = ["ATK_jll", "Artifacts", "JLLWrappers", "Libdl", "Pkg", "XML2_jll", "Xorg_libX11_jll", "at_spi2_core_jll"]
git-tree-sha1 = "f16ae690aca4761f33d2cb338ee9899e541f5eae"
uuid = "de012916-1e3f-58c2-8f29-df3ef51d412d"
version = "2.34.1+4"

[[at_spi2_core_jll]]
deps = ["Artifacts", "Dbus_jll", "Glib_jll", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXtst_jll"]
git-tree-sha1 = "d2d540cd145f2b2933614649c029d222fe125188"
uuid = "0fc3237b-ac94-5853-b45c-d43d59a06200"
version = "2.34.0+4"

[[gdk_pixbuf_jll]]
deps = ["Artifacts", "Glib_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pkg", "Xorg_libX11_jll", "libpng_jll"]
git-tree-sha1 = "0facfc4bfd873c21b83a053bbf182b9ef19c69d8"
uuid = "da03df04-f53b-5353-a52f-6a8b0620ced0"
version = "2.42.6+0"

[[hicolor_icon_theme_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b458a6f6fc2b1a8ca74ed63852e4eaf43fb9f5ea"
uuid = "059c91fe-1bad-52ad-bddd-f7b78713c282"
version = "0.17.0+3"

[[iso_codes_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "5ee24c3ae30e006117ec2da5ea50f2ce457c019a"
uuid = "bf975903-5238-5d20-8243-bc370bc1e7e5"
version = "4.3.0+4"

[[libass_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.15.1+0"

[[libfdk_aac_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "2.0.2+0"

[[libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"

[[libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "c45f4e40e7aafe9d086379e5578947ec8b95a8fb"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+0"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

[[x264_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2021.5.5+0"

[[x265_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.5.0+0"

[[xkbcommon_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll", "Wayland_protocols_jll", "Xorg_libxcb_jll", "Xorg_xkeyboard_config_jll"]
git-tree-sha1 = "ece2350174195bb31de1a63bea3a41ae1aa593b6"
uuid = "d8fb68d0-12a3-5cfd-a85a-d49703b185fd"
version = "0.9.1+5"
"""

# ╔═╡ Cell order:
# ╠═08d32844-010a-11ec-1ccf-2359999874d2
# ╠═5f34a9e3-4970-4871-beb2-9554d00bd43c
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002

ext: jl


text:
@inline function eatwhitespaces(str::String, i=1, len=lastindex(str))
    while i<=len
        @inbounds b = codeunit(str, i)

        if b==0x20 # This is ' '
            i += 1
        else
            break
        end
    end
    return i
end

@inline function eatnewlines(str::String, i=1, len=lastindex(str))
    count = 0
    while i<=len
        @inbounds b = codeunit(str, i)
        if b == 0xd # '\r'
            i += 1
            if i<=len
                @inbounds b = codeunit(str, i)
                if b == 0xa # '\n'
                    i += 1
                end
            end
            count += 1
        elseif b == 0xa
            i += 1
            if i<=len
                @inbounds b = codeunit(str, i)
                if b == 0xd
                    i += 1
                end
            end
            count += 1
        else
            break
        end
    end

    return i, count
end

@inline function tryparsenext_base10_digit(T,str::String,i, len)
    i > len && @goto error
    @inbounds b = codeunit(str,i)
    diff = b-0x30
    diff >= UInt8(10) && @goto error
    return convert(T, diff), i+1

    @label error
    return nothing
end

@inline _isdigit(b::UInt8) = ( (0x30 ≤ b) & (b ≤ 0x39) )

@inline function parse_uint_and_stop(str::String, i, len, n::T) where {T <: Integer}
    ten = T(10)
    # specialize handling of the first digit so we can return an error
    max_without_overflow = div(typemax(T)-9,10) # the larg
    i <= len || return n, false, i
    @inbounds b = codeunit(str, i)
    diff = b-0x30
    if diff < UInt8(10) && n <= max_without_overflow
        n *= ten
        n += T(diff)
    else
        return n, false, i
    end
    i += 1

    while i <= len && n <= max_without_overflow
        @inbounds b = codeunit(str, i)
        diff = b-0x30
        if diff < UInt8(10)
            n *= ten
            n += T(diff)
        else
            return n, true, i
        end
        i += 1
    end
    return n, true, i
end

@inline function read_digits(str::String, i, len)
    # slurp up extra digits
    while i <= len
        @inbounds b = codeunit(str, i)
        if !_isdigit(b) # do nothing
            return i
        end
        i += 1
    end
    return i
end

@inline function _is_e(str::String, i)
    @inbounds b = codeunit(str, i)
    return  (b==0x65) | (b==0x45)
end

@inline function _is_negative(str::String, i)
    @inbounds b = codeunit(str, i)
    return b==0x2d
end

@inline function _is_positive(str::String, i)
    @inbounds b = codeunit(str, i)
    return b==0x2b
end

@inline function tryparsenext(::Numeric{F}, str::String, i, len) where {F<:AbstractFloat}
    R = Nullable{F}

    i>len && @goto error

    negate = false
    @inbounds b = codeunit(str, i)
    if b==0x2d # '-'
        negate = true
        i += 1
    elseif b==0x2b # '+'
        i +=1
    end

    f1::Int64 = 0

    # read an integer up to the decimal point
    f1, rval1, idecpt = parse_uint_and_stop(str, i, len, f1)
    idecpt = read_digits(str, idecpt, len) # get any trailing digits
    i = idecpt

    ie = i
    frac_digits = 0

    # next thing must be dec pt.
    if i <= len && @inbounds(codeunit(str, i)) == 0x2e # Check for '.'
        i += 1
        f1, rval2, ie = parse_uint_and_stop(str, i, len, f1)
        frac_digits = ie - i

        ie = read_digits(str, ie, len) # get any trailing digits
    elseif !rval1 # no first number, and now no deciaml point => invalid
        @goto error
    end

    # Next thing must be exponent
    i = ie
    eval::Int32 = 0

    if i <= len && _is_e(str, i)
        i += 1

        enegate = false
        if i<=len
            if _is_negative(str, i)
                enegate = true
                i += 1
            elseif _is_positive(str, i)
                i += 1
            end
        end
        eval, rval3, i = parse_uint_and_stop(str, i, len, eval)
        if enegate
            eval *= Int32(-1)
        end
    end

    exp = eval - frac_digits

    maxexp = 308
    minexp = -307

    if frac_digits <= 15 && -22 <= exp <= 22
        if exp >= 0
            f = F(f1)*10.0^exp
        else
            f = F(f1)/10.0^(-exp)
        end
    else
          f = convert_to_double(f1, exp)
    end

    if negate
        f = -f
    end

    @label done
    return R(convert(F, f)), i

    @label error
    return R(), i
end


text:
# DESCRIPTION
# Nonlinear simulation model of the rigid-body dynamics of an F-16
# aircraft.
#
# INPUT
# - x: state vector
# - p: control input vector
#
# OUTPUT
# - XD: state derivative
# - Y: output vector
#
# ------------------------------------------------------------------------------

function F16!(x,p)
    # unpack state
    VT=x[1]
    ALPHA=x[2]*R2D
    BETA=x[3]*R2D
    PHI=x[4]
    THETA=x[5]
    PSI=x[6]
    P=x[7]
    Q=x[8]
    R=x[9]
    NORTH=x[10]
    EAST=x[11]
    ALT=x[12]
    if ALT<0.0
        ALT=0.0
    end
    POW=x[13]
    # unpack controls
    THTL=p[1]
    AIL=p[2]
    EL=p[3]
    RDR=p[4]
    # define state derivative vector
    XD=zeros(13,1)
    # convert attitude and angular rates from [rad] to [deg]
    PHID = PHI*R2D
    THETAD = THETA*R2D
    PD = P*R2D
    QD = Q*R2D
    RD = R*R2D
    # air data computer and engine model
    MACH, QBAR = ADC(VT,ALT)
    CPOW = TGEAR(THTL)
    XD[13] = PDOT(POW,CPOW)
    T = THRUST(POW,ALT,MACH)
    # component buildup
    CXT = CX(ALPHA,EL)
    CYT = CY(BETA,AIL,RDR)
    CZT = CZ(ALPHA,BETA,EL)
    #
    DAIL= AIL/20.0
    DRDR= RDR/30.0
    #
    CLT = CL(ALPHA,BETA) + DLDA(ALPHA,BETA)*DAIL + DLDR(ALPHA,BETA)*DRDR
    CMT = CM(ALPHA,EL)
    CNT = CN(ALPHA,BETA) + DNDA(ALPHA,BETA)*DAIL + DNDR(ALPHA,BETA)*DRDR
    # add damping derivatives
    TVT = 0.5/VT
    B2V = B*TVT
    CQ = CBAR*Q*TVT
    D = DAMP(ALPHA)
    #
    CXT = CXT + CQ*D[1]
    CYT = CYT + B2V*(D[2]*R+D[3]*P)
    CZT = CZT + CQ*D[4]
    #
    CLT = CLT + B2V*(D[5]*R+D[6]*P)
    CMT = CMT + CQ*D[7] + CZT*(XCGR-XCG)
    CNT = CNT + B2V*(D[8]*R+D[9]*P) - CYT*(XCGR-XCG)*CBAR/B
    # prepare state equations
    CBTA  = cos(x[3])
    U = VT*cos(x[2])*CBTA
    V = VT*sin(x[3])
    W = VT*sin(x[2])*CBTA
    #
    STH = sin(THETA)
    CTH = cos(THETA)
    SPH = sin(PHI)
    CPH = cos(PHI)
    SPSI = sin(PSI)
    CPSI = cos(PSI)
    #
    RM = G/WEIGHT
    QS = QBAR*S
    QSB = QS*B
    RMQS = RM*QS
    GCTH = G*CTH
    QSPH = Q*SPH
    AX = RM*(QS*CXT+T)
    AY = RMQS*CYT
    AZ = RMQS*CZT
    # equations of motion
    # longitudinal dynamics
    UDOT = R*V - Q*W - G*STH + AX
    VDOT = P*W - R*U + GCTH*SPH + AY
    WDOT = Q*U - P*V + GCTH*CPH + AZ
    DUM = (U*U + W*W)
    XD[1] = (U*UDOT+V*VDOT+W*WDOT)/VT
    XD[2] = (U*WDOT-W*UDOT)/DUM
    XD[3] = (VT*VDOT-V*XD[1])*CBTA/DUM
    # rotational kinematics
    XD[4] = P + (STH/CTH)*(QSPH + R*CPH)
    XD[5] = Q*CPH - R*SPH
    XD[6] = (QSPH + R*CPH)/CTH
    # rotational dynamics
    XD[7] = (C2*P + C1*R + C4*HE)*Q + QSB*(C3*CLT + C4*CNT)
    XD[8] = (C5*P - C7*HE)*R + C6*(R*R-P*P) +QS*CBAR*C7*CMT
    XD[9] = (C8*P-C2*R+C9*HE)*Q + QSB*(C4*CLT + C9*CNT)
    # navigation
    T1 = SPH*CPSI
    T2 = CPH*STH
    T3 = SPH*SPSI
    S1 = CTH*CPSI
    S2 = CTH*SPSI
    S3 = T1*STH-CPH*SPSI
    S4 = T3*STH+CPH*CPSI
    S5 = SPH*CTH
    S6 = T2*CPSI+T3
    S7 = T2*SPSI-T1
    S8 = CPH*CTH
    XD[10] = U*S1 +V*S3 + W*S6
    XD[11] = U*S2 + V*S4 + W*S7
    XD[12] = -(-U*STH + V*S5 + W*S8)
    # outputs
    # measured accelerometer at pilot location
    AYN = AY/G
    AXN = AX/G
    AZN = (-AZ+XA*XD[8])/G
    # cstar parameter
    CSTAR = AZN + 12.4*Q
    Y = [AZN; AYN; AXN; QBAR; MACH; CSTAR]
    # return state derivative and vectors
    return XD, Y
end


text:
using Test

const test_file = let
    dir, cnt = mktempdir(), 0

    local function test_file(code)
        filename = joinpath(dir, "test$cnt.jl")

        open(filename, "w") do f
            println(f, "using Fire")
            println(f, code)
        end

        cnt += 1
        filename
    end
end

@testset "call" begin
    f = test_file("""
        function main()
            println("I won't get called")
        end
    """)

    @test length(read(`julia $f`)) == 0

    f = test_file("""
        @main function main()
            println("I will get called")
        end
    """)

    @test length(read(`julia $f`)) != 0
end

@testset "types" begin
    f = test_file("""
        @main function main(x::Int32)
            nothing
        end
    """)

    @test_nowarn run(`julia $f 4`)

    f = test_file("""
        @main function main(x::Symbol)
            nothing
        end
    """)

    @test_nowarn run(`julia $f 4`)

    f = test_file("""
        @main function main(x::AbstractFloat)
            nothing
        end
    """)

    @test_nowarn run(`julia $f 4e-2`)
    @test_warn r"." run(`julia $f foo`)
end

@testset "kwargs" begin
    f = test_file("""
        @main function main(x::Int32; y::Int=2, z::Int=3)
            println(x + y + z)
        end
    """)

    @test readchomp(`julia $f 4`) == "9"
    @test readchomp(`julia $f 4 --y 1`) == "8"
    @test readchomp(`julia $f 4 --y 1 --z 2`) == "7"

    f = test_file("""
        @main function main(; n::Vector{Int}=[2, 3], mult::Bool=false)
            mult ? println(*(n...)) : println(+(n...))
        end
    """)

    @test readchomp(`julia $f`) == "5"
    @test readchomp(`julia $f --mult`) == "6"
    @test readchomp(`julia $f --n 2 3 4 5`) == "14"
    @test readchomp(`julia $f --n 2 3 4 5 --mult`) == "120"
end

@testset "splat" begin
    f = test_file("""
        @main function main(x::Integer, y::Integer...)
            println(x * +(y...,))
        end
    """)

    @test readchomp(`julia $f 2 3 4`) == "14"
    @test readchomp(`julia $f 2 3 4 5`) == "24"
end

@testset "help" begin
    f = test_file("""
        "this is the doc string"
        @main function main(x::Integer=3; y::Integer=4)
            nothing
        end
    """)

    @test begin
        a = read(`julia $f --help`, String)
        all(("this is the doc string", "default: 3", "--y: Integer")) do x
            occursin(x, a)
        end
    end
end

@testset "dash to underscore" begin
    f = test_file("""
        @main function f_1(; arg_1="string_1", arg_2="string-2")
            println(arg_1, arg_2)
        end

        @main function f_2()
            nothing
        end
    """)

    @test readchomp(`julia $f f-1 --arg-1 mystr-1 --arg_2 mystr_2`) == "mystr-1mystr_2"

    @test occursin("f-1", read(`julia $f --help`, String))

    @test occursin("arg-2", read(`julia $f f-1 --help`, String))
end

rm(dirname(test_file("")), recursive=true)


text:
include("../common/utils.jl")
using ForwardDiff: derivative
using LinearAlgebra: eigen

abstract type AbstractProblem end
struct Isothermal{T} <: AbstractProblem
    T₀::T
    R::T
    p₀::T
    g::T
    ρ₀::T
    H::T
    Cᵥ::T
    γ::T
    function Isothermal{T}(;
        T₀ = 300,
        R = 287,
        p₀ = 10^5,
        g = T(98 // 100),
    ) where {T}
        H = R * T₀ / g
        ρ₀ = p₀ / (R * T₀)
        Cᵥ = 5R / 2
        γ = R / Cᵥ + 1
        new{T}(T₀, R, p₀, g, ρ₀, H, Cᵥ, γ)
    end
end

p̄_(s::AbstractProblem, z) = s.p₀ * exp(-z / s.H)
ρ̄_(s::AbstractProblem, z) = s.ρ₀ * exp(-z / s.H)
Ē_(s::AbstractProblem, z) = ρ̄_(s, z) * (s.Cᵥ * s.T₀ + s.g * z)
δp_(s::AbstractProblem, z, δE, δρ) = (s.R / s.Cᵥ) * (δE - s.g * z * δρ)
c̄_(s::AbstractProblem, _) = sqrt(s.γ * s.p₀ / s.ρ₀)

function create_mesh(K, z0, z1)
    Δz = (z1 - z0) / K
    zi = range(z0, stop = z1, length = K + 1)
    zc = zi[1:K] .+ Δz / 2
    return (zc = zc, zi = zi, Δz = Δz)
end

function tendency!(∂q, q, t, s, mesh, f = nothing)
    N = length(q.ρc)

    g = s.g

    Δz = mesh.Δz

    ρ̄i = ρ̄_.(Ref(s), mesh.zi)
    Ēi = Ē_.(Ref(s), mesh.zi)
    p̄i = p̄_.(Ref(s), mesh.zi)

    ρ̄_wi = ρ̄i .* q.wi

    Ē_p̄_wi = (Ēi + p̄i) .* q.wi

    g_ρi = g * (q.ρc[1:(end - 1)] + q.ρc[2:end]) / 2

    pc = δp_.(Ref(s), mesh.zc, q.Ec, q.ρc)

    # ∂zρ̄w
    ∂q.ρc .= -(ρ̄_wi[2:end] - ρ̄_wi[1:(end - 1)]) / Δz

    # (g * ρ′ + ∂zδp) / ρ̄
    ∂q.wi[2:(end - 1)] .= -g_ρi ./ ρ̄i[2:(end - 1)]
    ∂q.wi[2:(end - 1)] .+=
        -(pc[2:end] - pc[1:(end - 1)]) ./ (Δz * ρ̄i[2:(end - 1)])

    # ∂z((Ē + p̄) w′)
    ∂q.Ec .= -(Ē_p̄_wi[2:end] - Ē_p̄_wi[1:(end - 1)]) / Δz

    if !isnothing(f)
      ∂q.ρc .+= f.ρ.(mesh.zc, t)
      ∂q.wi[2:(end - 1)] .+= f.w.(mesh.zi[2:(end - 1)], t)
      ∂q.Ec .+= f.E.(mesh.zc, t)
    end
end

function mms(Ks = 10 * 2 .^ (0:6), z0 = 0.0, z1 = 1.0)
    ϵ = zeros(3, length(Ks))
    for (lvl, K) in enumerate(Ks)
        @show lvl, K

        T = Float64

        mesh = create_mesh(K, z0, z1)

        s = Isothermal{T}()
        # Calculate the wave speed
        c̄ = c̄_(s, 0)

        # mms solution
        κ = c̄ / (z1 - z0)
        f(z, t) = cos(t * κ * π) * sin(2π * (z - z0) / (z1 - z0))
        ρ′(z, t) = f(2z, 4t)
        w′(z, t) = f(1z, 2t)
        E′(z, t) = f(1z, 1t)

        ∂tρ′(z, t) = derivative(t -> ρ′(z, t), t)
        ∂tw′(z, t) = derivative(t -> w′(z, t), t)
        ∂tE′(z, t) = derivative(t -> E′(z, t), t)

        ∂zρ̄w(z, t) = derivative(z -> ρ̄_(s, z) * w′(z, t), z)
        ∂zδp(z, t) = derivative(z -> δp_(s, z, E′(z, t), ρ′(z, t)), z)
        ∂zĒ_p̄w′(z, t) = derivative(z -> (Ē_(s, z) + p̄_(s, z)) * w′(z, t), z)

        # Forcing for each term
        fρ(z, t) = ∂tρ′(z, t) + ∂zρ̄w(z, t)

        grav_source(z, t) = s.g * ρ′(z, t)
        fw(z, t) = ∂tw′(z, t) + (grav_source(z, t) + ∂zδp(z, t)) / ρ̄_(s, z)

        fE(z, t) = ∂tE′(z, t) + ∂zĒ_p̄w′(z, t)

        forcing = (ρ = fρ, w = fw, E = fE)

        cfl = 1

        # estimate time step
        dt = cfl * mesh.Δz / c̄
        tspan = (0, 1 / κ)
        steps = ceil(Int, (tspan[2] - tspan[1]) / dt)
        dt = (tspan[2] - tspan[1]) / steps

        rhs!(∂q, q, t) = tendency!(∂q, q, t, s, mesh, forcing)

        q = (
            ρc = ρ′.(mesh.zc, tspan[1]),
            wi = w′.(mesh.zi, tspan[1]),
            Ec = E′.(mesh.zc, tspan[1]),
        )
        timestep!(q, rhs!, dt, tspan)
        qe = (
            ρc = ρ′.(mesh.zc, tspan[2]),
            wi = w′.(mesh.zi, tspan[2]),
            Ec = E′.(mesh.zc, tspan[2]),
        )

        # Calculate the L2 error
        for i in 1:3
            ϵ[i, lvl] = sqrt(sum(mesh.Δz .* (q[i] - qe[i]) .^ 2))
        end
        @show ϵ[:, lvl]
        if lvl > 1
          rate = (log.(ϵ[:, lvl]) - log.(ϵ[:, lvl-1])) / (log(Ks[lvl-1]) - log(Ks[lvl]))
          @show rate
        end
        println()
    end
end

function form_matrix(K, z0, z1)
    mesh = create_mesh(K, z0, z1)

    s = Isothermal{Float64}()

    # Initial conditions
    q = (
        ρc = fill!(similar(mesh.zc), 0),
        wi = fill!(similar(mesh.zi), 0),
        Ec = fill!(similar(mesh.zc), 0),
    )

    # advance in time
    ∂q = (
        ρc = fill!(similar(mesh.zc), 0),
        wi = fill!(similar(mesh.zi), 0),
        Ec = fill!(similar(mesh.zc), 0),
    )

    rhs!(∂q, q, t) = tendency!(∂q, q, t, s, mesh)

    A = zeros(3K - 1, 3K - 1)
    pts = (ρc = 1:K, wi = K .+ (1:K-1), Ec = 2K-1 .+ (1:K))
    col = 0
    for f = 1:3
      # @show pts[f]
      q[f] .= 0
      ∂q[f] .= 0
    end
    # @show size(A)
    for i = 1:K
      col = col + 1
      q.ρc[i] = 1
      rhs!(∂q, q, 0)
      A[pts.ρc, col] .= ∂q.ρc
      A[pts.wi, col] .= ∂q.wi[2:end-1]
      A[pts.Ec, col] .= ∂q.Ec
      ∂q.ρc .= 0
      ∂q.wi .= 0
      ∂q.Ec .= 0
      q.ρc[i] = 0
    end
    for i = 2:K
      col = col + 1
      q.wi[i] = 1
      rhs!(∂q, q, 0)
      A[pts.ρc, col] .= ∂q.ρc
      A[pts.wi, col] .= ∂q.wi[2:end-1]
      A[pts.Ec, col] .= ∂q.Ec
      ∂q.ρc .= 0
      ∂q.wi .= 0
      ∂q.Ec .= 0
      q.wi[i] = 0
    end
    for i = 1:K
      col = col + 1
      q.Ec[i] = 1
      rhs!(∂q, q, 0)
      A[pts.ρc, col] .= ∂q.ρc
      A[pts.wi, col] .= ∂q.wi[2:end-1]
      A[pts.Ec, col] .= ∂q.Ec
      ∂q.ρc .= 0
      ∂q.wi .= 0
      ∂q.Ec .= 0
      q.Ec[i] = 0
    end

    q = (
        ρc = rand(K),
        wi = rand(K+1),
        Ec = rand(K),
    )
    q.wi[1] = 0
    q.wi[end] = 0

    rhs!(∂q, q, 0)

    q̄ = [q.ρc; q.wi[2:end-1]; q.Ec]
    ∂q̄ = A * q̄

    @assert all(∂q.ρc .≈ ∂q̄[pts.ρc])
    @assert all(∂q.wi[2:end-1] .≈ ∂q̄[pts.wi])
    @assert all(∂q.Ec .≈ ∂q̄[pts.Ec])

    return A
end

let
  K = 1000
  A = form_matrix(K, 0.0, 1.0)
  ev = eigen(A);
  vs = findall(abs.(ev.values) .< 1e-14)
  @show length(vs), K
  pts = (ρc = 1:K, wi = K .+ (1:K-1), Ec = 2K-1 .+ (1:K))
  for v in vs
     @assert maximum(abs.(ev.vectors[pts.wi, v])) < 1e-16
  end
end


text:
struct TableauVPRKpLegendre{T} <: AbstractTableauPRK{T}
    @HeaderTableau

    q::CoefficientsRK{T}
    p::CoefficientsRK{T}

    R∞::Int

    ω::Matrix{T}
    d::Vector{T}

    function TableauVPRKpLegendre{T}(name, o, q, p, R∞, ω, d) where {T}
        @assert q.s == p.s == length(d)
        new(name, o, q.s, q, p, R∞, ω, d)
    end

    function TableauVPRKpLegendre{T}(name, o, q, p, R∞, ω) where {T}
        @assert q.s == p.s
        new(name, o, q.s, q, p, R∞, ω)
    end
end

function TableauVPRKpLegendre(name::Symbol, order::Int, q::CoefficientsRK{T}, p::CoefficientsRK{T}, R∞::Int, ω::Matrix{T}, d::Vector{T}) where {T}
    TableauVPRKpLegendre{T}(name, order, q, p, R∞, ω, d)
end

function TableauVPRKpLegendre(name::Symbol, order::Int, q::CoefficientsRK{T}, p::CoefficientsRK{T}, R∞::Int, ω::Matrix{T}) where {T}
    TableauVPRKpLegendre{T}(name, order, q, p, R∞, ω)
end

function TableauVPRKpLegendre(name::Symbol, order::Int, q::CoefficientsRK{T}, R∞::Int, ω::Matrix{T}, d::Vector{T}) where {T}
    TableauVPRKpLegendre{T}(name, order, q, get_symplectic_conjugate_coefficients(q), R∞, ω, d)
end

function TableauVPRKpLegendre(name::Symbol, order::Int, q::CoefficientsRK{T}, R∞::Int, ω::Matrix{T}) where {T}
    TableauVPRKpLegendre{T}(name, order, q, get_symplectic_conjugate_coefficients(q), R∞, ω)
end

"Parameters for right-hand side function of variational special partitioned additive Runge-Kutta methods."
mutable struct ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S} <: Parameters{DT,TT}
    f_θ::ΘT
    f_f::FT

    Δt::TT

    t_q::CoefficientsRK{TT}
    t_p::CoefficientsRK{TT}
    d_v::Vector{TT}

    t::TT

    q::Vector{DT}
    p::Vector{DT}

    function ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S}(f_θ, f_f, Δt, t_q, t_p, d_v, q, p) where {DT,TT,ΘT,FT,D,S}
        new(f_θ, f_f, Δt, t_q, t_p, d_v, 0, q, p)
    end
end

struct NonlinearFunctionCacheVPRKpLegendre{ST}

    q̅::Vector{ST}
    p̅::Vector{ST}
    ϕ::Vector{ST}
    μ::Vector{ST}

    v::Vector{ST}
    y::Vector{ST}
    z::Vector{ST}

    Q::Matrix{ST}
    P::Matrix{ST}
    V::Matrix{ST}
    F::Matrix{ST}
    Φ::Matrix{ST}

    function NonlinearFunctionCacheVPRKpLegendre{ST}(d,s) where {ST}
        # create solution vectors
        q̅ = zeros(ST,d)
        p̅ = zeros(ST,d)
        ϕ = zeros(ST,d)
        μ = zeros(ST,d)

        v = zeros(ST,d)
        y = zeros(ST,d)
        z = zeros(ST,d)

        # create internal stage vectors
        Q = zeros(ST,d,s)
        P = zeros(ST,d,s)
        V = zeros(ST,d,s)
        F = zeros(ST,d,s)
        Φ = zeros(ST,d,s)

        new(q̅, p̅, ϕ, μ, v, y, z, Q, P, V, F, Φ)
    end
end

"Compute stages of variational special partitioned additive Runge-Kutta methods."
@generated function function_stages!(y::Vector{ST}, b::Vector{ST}, params::ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S}) where {ST,DT,TT,ΘT,FT,D,S}
    cache = IntegratorCacheVPRK{ST, D, S}(true)

    quote
        @assert length(y) == length(b)

        compute_stages!(y, $cache.Q, $cache.V, $cache.P, $cache.F, $cache.Φ, $cache.q̃, $cache.p̃, $cache.ϕ, $cache.μ, params)

        compute_rhs!(b, $cache.Q, $cache.V, $cache.P, $cache.F, $cache.Φ, $cache.q̃, $cache.p̃, $cache.ϕ, $cache.μ, params)

        # debug output
        # println()
        # for k in 1:D
        #     println(params.q[k], ",  ", params.p[k], ",  ", $cache.Q[k,1], ",  ", $cache.P[k,1], ",  ", $cache.q̅[k], ",  ", $cache.p̅[k])
        # end
        # println()
    end
end

@generated function compute_stages!(y::Vector{ST}, Q, V, P, F, Φ, q̅, p̅, ϕ, μ, params::ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S}) where {ST,DT,TT,ΘT,FT,D,S}
    # create temporary vectors
    Qt = zeros(ST,D)
    Pt = zeros(ST,D)
    Vt = zeros(ST,D)
    Ft = zeros(ST,D)

    quote
        local offset::Int
        local tqᵢ::TT

        for i in 1:S
            # copy y to Q and V
            for k in 1:D
                offset = 3*(D*(i-1)+k-1)
                Q[k,i] = y[offset+1]
                V[k,i] = y[offset+2]
                P[k,i] = y[offset+3]
            end

            # compute P=p(t,Q) and F=f(t,Q,V)
            tqᵢ = params.t + params.Δt * params.t_q.c[i]
            simd_copy_xy_first!($Qt, Q, i)
            simd_copy_xy_first!($Vt, V, i)
            params.f_θ(tqᵢ, $Qt, $Vt, $Pt)
            params.f_f(tqᵢ, $Qt, $Vt, $Ft)
            simd_copy_yx_first!($Pt, Φ, i)
            simd_copy_yx_first!($Ft, F, i)
        end

        # copy y to q̅ and p̅
        for k in 1:D
            q̅[k] = y[(3*S+0)*D+k]
            p̅[k] = y[(3*S+1)*D+k]
        end

        # compute p̅=p(t,q̅)
        $Vt .= 0
        params.f_θ(params.t + params.Δt, q̅, $Vt, ϕ)

        # for Lobatto-type methods, copy y to μ
        # if length(params.d_v) > 0
        #     offset = (3*S+2)*D
        #     for k in 1:D
        #         μ[k] = y[offset+k]
        #     end
        # end
    end
end

function compute_rhs!(b::Vector{ST}, Q::Matrix{ST}, V::Matrix{ST}, P::Matrix{ST}, F::Matrix{ST}, Φ::Matrix{ST}, q̅::Vector{ST}, p̅::Vector{ST}, ϕ::Vector{ST}, μ::Vector{ST}, params::ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S}) where {ST,DT,TT,ΘT,FT,D,S}
    local ω::ST
    local z::ST

    # compute b = - (Q-q-AV)
    for i in 1:S
        offset = 0*S*D + D*(i-1)
        for k in 1:D
            z = 0
            for j in 1:S
                z += params.t_q.a[i,j] * V[k,j]
            end
            b[offset+k] = (params.q[k] - Q[k,i]) + params.Δt * z
        end
    end

    # compute b = - (P-p-AF)
    for i in 1:S
        offset = 1*S*D + D*(i-1)
        for k in 1:D
            z = 0
            for j in 1:S
                z += params.t_p.a[i,j] * F[k,j]
            end
            b[offset+k] = (params.p[k] - P[k,i]) + params.Δt * z
        end
    end

    # compute b = - (P-Φ)
    for i in 1:S-1
        offset = 2*S*D + D*(i-1)
        for k in 1:D
            z = 0
            for j in 1:S
                ω = params.t_p.b[j] * params.t_p.c[j]^(i-1)
                # ω = params.t_q.a[i+1,j]
                z += ω * (Φ[k,j] - P[k,j])
            end
            b[offset+k] = z
        end
    end

    # compute b = - (q̅-q-AV)
    offset = (3*S-1)*D
    for k in 1:D
        z = 0
        for j in 1:S
            z += params.t_q.b[j] * V[k,j]
        end
        b[offset+k] = (params.q[k] - q̅[k]) + params.Δt * z
    end

    # compute b = - (p̅-p-AF)
    offset = (3*S+0)*D
    for k in 1:D
        z = 0
        for j in 1:S
            z += params.t_p.b[j] * F[k,j]
        end
        b[offset+k] = (params.p[k] - p̅[k]) + params.Δt * z
    end

    # compute b = - (p̅-ϕ)
    offset = (3*S+1)*D
    for k in 1:D
        b[offset+k] = ϕ[k] - p̅[k]
    end

    # if length(params.d_v) > 0
    #     offset = (3*S+2)*D
    #     for k in 1:D
    #         b[offset+k] = 0
    #         for i in 1:S
    #             b[offset+k] -= V[k,i] * params.d_v[i]
    #         end
    #     end
    # end

    if length(params.d_v) > 0
        sl     = div(S+1, 2)
        offset = D*(S+sl-1)

        # compute μ
        z = params.t_p.b[sl] / params.d_v[sl]
        for k in 1:D
            μ[k] = z * b[offset+k]
        end

        # replace equation for Pₗ with constraint on V
        for k in 1:D
            z = 0
            for i in 1:S
                z += V[k,i] * params.d_v[i]
            end
            b[offset+k] = z
        end

        # modify P₁, ..., Pₛ except for Pₗ
        for i in 1:S
            if i ≠ sl
                offset = D*(S+i-1)
                z = params.d_v[i] / params.t_p.b[i]
                for k in 1:D
                    b[offset+k] -= z * μ[k]
                end
            end
        end
    end
end

"Variational special partitioned additive Runge-Kutta integrator."
mutable struct IntegratorVPRKpLegendre{DT, TT, ΘT, FT, GT, VT, SPT, ST, IT} <: Integrator{DT, TT}
    equation::IODE{DT,TT,ΘT,FT,GT,VT}
    tableau::TableauVPRK{TT}
    Δt::TT

    params::SPT
    solver::ST
    iguess::InitialGuessPODE{DT, TT, VT, FT, IT}

    q::Vector{DT}
    p::Vector{DT}

    cache::NonlinearFunctionCacheVPRKpLegendre{DT}
end

function IntegratorVPRKpLegendre(equation::IODE{DT,TT,ΘT,FT,GT,VT}, tableau::TableauVPRK{TT}, Δt::TT) where {DT,TT,ΘT,FT,GT,VT}
    D = equation.d
    S = tableau.s

    N = (3*S+2)*D

    if isdefined(tableau, :d)
        d_v = tableau.d
    else
        d_v = DT[]
    end

    # create solution vectors
    q = zeros(DT,D)
    p = zeros(DT,D)

    # create solution vector for internal stages / nonlinear solver
    z = zeros(DT,N)

    # create cache for internal stage vectors and update vectors
    cache = NonlinearFunctionCacheVPRKpLegendre{DT}(D,S)

    # create params
    params = ParametersVPRKpLegendre{DT,TT,ΘT,FT,D,S}(
                                                equation.ϑ, equation.f,
                                                Δt, tableau.q, tableau.p, d_v, q, p)

    # create rhs function for nonlinear solver
    function_stages = (x,b) -> function_stages!(x, b, params)

    # create solver
    solver = get_config(:nls_solver)(z, function_stages)

    # create initial guess
    iguess = InitialGuessPODE(get_config(:ig_interpolation), equation, Δt)

    # create integrator
    IntegratorVPRKpLegendre{DT, TT, ΘT, FT, GT, VT, typeof(params), typeof(solver), typeof(iguess.int)}(
                equation, tableau, Δt, params, solver, iguess, q, p, cache)
end

function initialize!(int::IntegratorVPRKpLegendre, sol::SolutionPDAE, m::Int)
    @assert m ≥ 1
    @assert m ≤ sol.ni

    # copy initial conditions from solution
    get_initial_conditions!(sol, int.q, int.p, m)

    # initialise initial guess
    initialize!(int.iguess, m, sol.t[0], int.q, int.p)
end

function update_solution!(int::IntegratorVPRKpLegendre{DT,TT}, cache::NonlinearFunctionCacheVPRKpLegendre{DT}) where {DT,TT}
    update_solution!(int.q, cache.V, int.tableau.q.b, int.tableau.q.b̂, int.Δt)
    update_solution!(int.p, cache.F, int.tableau.p.b, int.tableau.p.b̂, int.Δt)
end

"Integrate DAE with variational special partitioned additive Runge-Kutta integrator."
function integrate_step!(int::IntegratorVPRKpLegendre{DT,TT,ΘT,FT,VT}, sol::SolutionPDAE{DT,TT,N}, m::Int, n::Int) where {DT,TT,ΘT,FT,VT,N}
    local offset::Int

    # set time for nonlinear solver
    int.params.t = sol.t[0] + (n-1)*int.Δt

    # compute initial guess
    for i in 1:int.tableau.s
        evaluate!(int.iguess, m, int.cache.y, int.cache.z, int.cache.v, int.tableau.q.c[i], int.tableau.p.c[i])
        for k in 1:int.equation.d
            offset = 3*(int.equation.d*(i-1)+k-1)
            int.solver.x[offset+1] = int.cache.y[k]
            int.solver.x[offset+2] = int.cache.v[k]
            int.solver.x[offset+3] = int.cache.z[k]
        end
    end

    evaluate!(int.iguess, m, int.cache.y, int.cache.z, int.cache.v, one(TT), one(TT))
    for k in 1:int.equation.d
        int.solver.x[(3*int.tableau.s+0)*int.equation.d+k] = int.cache.y[k]
        int.solver.x[(3*int.tableau.s+1)*int.equation.d+k] = int.cache.z[k]
    end

    # if isdefined(int.tableau, :d)
    #     offset = (3*int.tableau.s+2)*int.equation.d
    #     for k in 1:int.equation.d
    #         int.solver.x[offset+k] = 0
    #     end
    # end

    # debug output
    # println()
    # println(int.solver.x)

    # call nonlinear solver
    solve!(int.solver)

    # print solver status
    print_solver_status(int.solver.status, int.solver.params)

    # check if solution contains NaNs or error bounds are violated
    check_solver_status(int.solver.status, int.solver.params)

    # compute final update
    compute_stages!(int.solver.x, int.cache.Q, int.cache.V, int.cache.P, int.cache.F, int.cache.Φ, int.cache.q̅, int.cache.p̅, int.cache.ϕ, int.cache.μ, int.params)
    update_solution!(int, int.cache)

    # debug output
    # println(int.solver.x)
    # println()

    # copy solution to initial guess for next time step
    update!(int.iguess, m, sol.t[0] + n*int.Δt, int.q, int.p)
end


text:
iszero(x::T) where T = x == zero(T)

Maybe(T::Type) = Union{T, Nothing}

function in_expr_args(ex::Expr)
    ex.head === :in && return ex.args[1], ex.args[2]
(ex.head === :call && length(ex.args) == 3 && ex.args[1] === :in) &&
    return ex.args[2], ex.args[3]
    error("Not an `in` expression")
end

# Cycle-zip. Zip two or more arrays, cycling the short ones.
function cyclezip(xs::AbstractArray...)
    any(map(isempty, xs)) && return Any[]
    n = maximum([length(x) for x in xs])
    return takestrict(zip([Compat.Iterators.cycle(x) for x in xs]...), n)
end

# This generates optimized code for a reoccuring pattern in forms and patterns
# that looks like:
#
#   return Circle([CirclePrimitive((x, y), x_measure(r))
#                  for (x, y, r) in cyclezip(xs, ys, rs)])
#
# This macro does the equivalent with
#
#   return @makeform (x in xs, y in ys, r in rs),
#                    CirclePrimitive((x, y), x_measure(r)))
#
# but much more efficiently.
macro makeform(args...)
    @assert 1 <= length(args) <= 2
    tag = length(args) == 2 ? args[2] : empty_tag
    args = args[1]
    @assert args.head == :tuple
    @assert length(args.args) == 2
    iterators, constructor = args.args

    maxlen_ex = quote begin n = 0 end end
    type_ex = quote begin end end
    iter_ex = quote begin end end

    for iterator in iterators.args
        var, arr = in_expr_args(iterator::Expr)
        ivar = Symbol(string("i_", var))

        push!(maxlen_ex.args,
            quote
                n = max(n, length($(arr)))
                if isempty($(arr))
                    error("Form cannot be constructed from an empty array")
                end
            end)
        push!(type_ex.args, quote
              $(ivar) = 1
              $(var) = $(arr)[1]
              end)
        push!(iter_ex.args, quote
              $(ivar) += 1
              $(ivar) = $(ivar) > length($(arr)) ? 1 : $(ivar)
              $(var) = $(arr)[$(ivar)]
        end)
    end

    esc(quote
        $(maxlen_ex)

        $(type_ex)
        prim1 = $(constructor)
        T = typeof(prim1)

        primitives = Array{T}(n)
        primitives[1] = prim1
        for i in 2:n
            $(iter_ex)
            primitives[i] = $(constructor)::T
        end
        Form{T}(primitives, $(tag))
    end)
end

# TODO: Remove after replacing usage in property.jl
macro makeprimitives(args)
    @assert args.head == :tuple
    @assert length(args.args) == 3
    T, iterators, constructor = args.args

    maxlen_ex = quote begin n = 0 end end
    iter_ex = quote begin end end

    for iterator in iterators.args
        var, arr = in_expr_args(iterator::Expr)

        push!(maxlen_ex.args, quote
            if isempty($(esc(arr)))
                primitives = Array{$(T)}(0)
                @goto done
            end end)
        push!(maxlen_ex.args, quote n = max(n, length($(esc(arr)))) end)
        push!(iter_ex.args, quote
            $(esc(var)) = $(esc(arr))[((i - 1) % length($(esc(arr)))) + 1]
        end)
    end

    quote
        $(maxlen_ex)
        primitives = Array{$(esc(T))}(n)
        for i in 1:n
            $(iter_ex)
            primitives[i] = $(esc(constructor))
        end
        @label done
        primitives
    end
end

narrow_polygon_point_types(point_arrays::AbstractArray{Vector{Tuple{XM, YM}}}) where {XM <: Measure, YM <: Measure} = (XM, YM)

type_params(p::Type{Tuple{XM, YM}}) where {XM, YM} = (Any, Any)
type_params(p::Type{Tuple{XM, YM}}) where {XM <: Measure, YM <: Measure} = (XM, YM)
type_params(p::Type{Union{}}) = (Any, Any)

function narrow_polygon_point_types(point_arrays::AbstractArray)
    if !isempty(point_arrays) && all([eltype(arr) <: Vec for arr in point_arrays])
        xm, ym = type_params(eltype(point_arrays[1]))
        for i in 2:length(point_arrays)
            type_params(eltype(point_arrays[i])) == (xm, ym) || return Any, Any
        end
        return xm, ym
    else
        return Any, Any
    end
end

function narrow_polygon_point_types(ring_arrays::Vector{Vector{Vector{P}}}) where P <: Tuple
    type_params(p::Type{Tuple{XM, YM}}) where {XM, YM} = (XM, YM)

    xm = nothing
    ym = nothing
    for point_arrays in ring_arrays
        if !isempty(point_arrays) && all([eltype(arr) <: Vec for arr in point_arrays])
            if xm == nothing
                xm, ym = type_params(eltype(point_arrays[1]))
            end
            for i in 2:length(point_arrays)
                type_params(eltype(point_arrays[i])) == (xm, ym) || Any, Any
            end
        end
    end
    if xm == nothing
        return Any, Any
    else
        return xy, ym
    end
end

# Hacks to make Dates time work as coordinates

if !hasmethod(/, (Dates.Day, Dates.Day))
    /(a::Dates.Day, b::Dates.Day) = a.value / b.value
end

if !hasmethod(/, (Dates.Day, Real))
    /(a::Dates.Day, b::Real) = Dates.Day(round(Int64, (a.value / b)))
end
/(a::Dates.Day, b::AbstractFloat) = convert(Dates.Millisecond, a) / b

if !hasmethod(/, (Dates.Millisecond, Dates.Millisecond))
    /(a::Dates.Millisecond, b::Dates.Millisecond) = a.value / b.value
end

if !hasmethod(/, (Dates.Millisecond, Real))
    /(a::Dates.Millisecond, b::Real) = Dates.Millisecond(round(Int64, (a.value / b)))
end
/(a::Dates.Millisecond, b::AbstractFloat) = Dates.Millisecond(round(Int64, (a.value / b)))

if !hasmethod(-, (Dates.Date, Dates.DateTime))
    -(a::Dates.Date, b::Dates.DateTime) = convert(Dates.DateTime, a) - b
end

+(a::Dates.Date, b::Dates.Millisecond) = convert(Dates.DateTime, a) + b

if !hasmethod(-, (Dates.DateTime, Dates.Date))
    -(a::Dates.DateTime, b::Dates.Date) = a - convert(Dates.DateTime, b)
end

if !hasmethod(/, (Dates.Day, Dates.Millisecond))
    /(a::Dates.Day, b::Dates.Millisecond) = convert(Dates.Millisecond, a) / b
end

if !hasmethod(/, (Dates.Millisecond, Dates.Day))
    /(a::Dates.Millisecond, b::Dates.Day) = a / convert(Dates.Millisecond, b)
end

for T in [Dates.Hour, Dates.Minute, Dates.Second, Dates.Millisecond]
    if !hasmethod(-, (Dates.Date, T))
        @eval begin
            -(a::Dates.Date, b::$(T)) = convert(Dates.DateTime, a) - b
        end
    end
end

*(a::AbstractFloat, b::Dates.Day) = Dates.Day(round(Int64, (a * b.value)))
*(a::Dates.Day, b::AbstractFloat) = b * a
*(a::AbstractFloat, b::Dates.Millisecond) = Dates.Millisecond(round(Int64, (a * b.value)))
*(a::Dates.Millisecond, b::AbstractFloat) = b * a


text:
#
# Session Options
#

function SessionOptions(;
            host::Union{Nothing, S}=nothing,
            port::Union{Nothing, I}=nothing,
            client_mode::Union{Nothing, ClientMode}=nothing,
            service_check_timeout_msecs::Union{Nothing, I2}=nothing,
            service_download_timeout_msecs::Union{Nothing, I3}=nothing
        ) where {S<:AbstractString, I<:Integer, I2<:Integer, I3<:Integer}

    handle = blpapi_SessionOptions_create()
    ptr_check(handle, "Failed to create SessionOptions")

    if host != nothing
        err = blpapi_SessionOptions_setServerHost(handle, host)
        error_check(err)
    end

    if port != nothing
        err = blpapi_SessionOptions_setServerPort(handle, UInt16(port))
        error_check(err)
    end

    if client_mode != nothing
        blpapi_SessionOptions_setClientMode(handle, Int(client_mode))
    end

    if service_check_timeout_msecs != nothing
        err = blpapi_SessionOptions_setServiceCheckTimeout(handle, service_check_timeout_msecs)
        error_check(err)
    end

    if service_download_timeout_msecs != nothing
        err = blpapi_SessionOptions_setServiceDownloadTimeout(handle, service_download_timeout_msecs)
        error_check(err)
    end

    return SessionOptions(handle)
end

get_server_host(opt::SessionOptions) = unsafe_string(blpapi_SessionOptions_serverHost(opt.handle))
get_server_port(opt::SessionOptions) = blpapi_SessionOptions_serverPort(opt.handle)
get_client_mode(opt::SessionOptions) = ClientMode(blpapi_SessionOptions_clientMode(opt.handle))

"""
List of service names that the default `Session` constructor uses.
See also [`Session`](@ref).

```julia
julia> BLPData.Session()
Session services available: Set(["//blp/refdata", "//blp/mktdata"])

julia> BLPData.DEFAULT_SERVICE_NAMES
Set{String} with 2 elements:
  "//blp/refdata"
  "//blp/mktdata"
```
"""
const DEFAULT_SERVICE_NAMES = Set(["//blp/mktdata", "//blp/refdata"])

"""
List of all serice names based on the BLPAPI documentation.
See also [`Session`](@ref).

```julia
julia> session = BLPData.Session(BLPData.ALL_SERVICE_NAMES)
Session services available: Set(["//blp/mktlist", "//blp/mktdata", "//blp/mktdepthdata", "//blp/instruments", "//blp/pagedata", "//blp/mktvwap", "//blp/mktbar", "//blp/refdata", "//blp/irdctk3", "//blp/tasvc", "//blp/srcref", "//blp/apiflds"])
```
"""
const ALL_SERVICE_NAMES = union(DEFAULT_SERVICE_NAMES, Set([
        "//blp/srcref",
        "//blp/mktvwap",
        "//blp/mktdepthdata",
        "//blp/mktbar",
        "//blp/mktlist",
        "//blp/apiflds",
        "//blp/instruments",
        "//blp/pagedata",
        "//blp/tasvc",
        "//blp/irdctk3"
    ]))

function service_name_str(service_name::AbstractString) :: String
    @assert length(service_name) >= 2 "Short service name `$(service_name)`"

    if !(service_name[1] == '/' && service_name[2] == '/')
        return "//blp/$service_name"
    else
        return String(service_name)
    end
end

const DEFAULT_SESSION_START_TIMEOUT_MSECS = UInt32(5000) # 5 secs

"""
    Session(services;
            host=nothing,
            port=nothing,
            client_mode=nothing,
            service_check_timeout_msecs=nothing
            service_download_timeout_msecs=nothing,
            session_start_timeout_msecs=DEFAULT_SESSION_START_TIMEOUT_MSECS,
            verbose::Bool=false
        )

Creates a new session for Bloomberg API and opens the services listed in the `services` argument.

See also [`stop`](@ref), [`ClientMode`](@ref), [`DEFAULT_SERVICE_NAMES`](@ref), [`ALL_SERVICE_NAMES`](@ref).

# Example

```julia
# starts a session with default parameters:
# * host=127.0.0.1, port=8194
# * client_mode = BLPAPI_CLIENTMODE_AUTO.
# * services = BLPData.DEFAULT_SERVICE_NAMES
session = Blpapi.Session()

# session with customized parameters
customized_session = Blpapi.Session("//blp/refdata",
    host="my_host",
    port=4444,
    client_mode=Blpapi.BLPAPI_CLIENTMODE_DAPI)
```
"""
function Session(services::Set{T}=DEFAULT_SERVICE_NAMES;
            host=nothing,
            port=nothing,
            client_mode=nothing,
            service_check_timeout_msecs=nothing,
            service_download_timeout_msecs=nothing,
            session_start_timeout_msecs=DEFAULT_SESSION_START_TIMEOUT_MSECS,
            verbose::Bool=false
        ) where {T<:AbstractString}

    opt = SessionOptions(host=host, port=port, client_mode=client_mode, service_check_timeout_msecs=service_check_timeout_msecs, service_download_timeout_msecs=service_download_timeout_msecs)
    handle = blpapi_Session_create(opt.handle, C_NULL, C_NULL, C_NULL)
    ptr_check(handle, "Failed to create Session")

    # starts the session
    let
        err = blpapi_Session_start(handle)
        error_check(err, "Failed to start session.")
    end

    opened_services = Set{String}()

    for service_name in services
        service_name = service_name_str(service_name)

        # opens the service
        err = blpapi_Session_openService(handle, service_name)
        error_check(err, "Failed to open service $service_name.")

        push!(opened_services, service_name)
    end

    return Session(handle, opened_services, session_start_timeout_msecs, verbose)
end

# called by the struct constructor
function handle_session_start_events(session::Session, session_start_timeout_msecs::Integer, verbose::Bool)

    local evn

    try
        evn = next_event(session, timeout_milliseconds=session_start_timeout_msecs)
        @assert evn.event_type == BLPAPI_EVENTTYPE_SESSION_STATUS
        for message in each_message(evn)
            element = Element(message)
            @assert element.name.symbol == :SessionConnectionUp "Failed to start session: expected SessionConnectionUp, got $(element)"
            if verbose
                @info("SessionConnectionUp: server=$(element["server"]), encryptionStatus=$(element["encryptionStatus"])")
            end
        end
    finally
        # destroy this event early, before GC
        isa(evn, Event) && destroy!(evn)
    end

    try
        evn = next_event(session, timeout_milliseconds=session_start_timeout_msecs)
        @assert evn.event_type == BLPAPI_EVENTTYPE_SESSION_STATUS
        for message in each_message(evn)
            element = Element(message)
            @assert element.name.symbol == :SessionStarted "Failed to start session: expected SessionStarted, got $(element)"
            if verbose
                @info(element)
            end
        end
    finally
        # destroy this event early, before GC
        isa(evn, Event) && destroy!(evn)
    end

    # handle one ServiceOpened event for each opened service
    if !isempty(session.opened_services)
        for i in 1:length(session.opened_services)
            try
                evn = next_event(session, timeout_milliseconds=session_start_timeout_msecs)
                @assert evn.event_type == BLPAPI_EVENTTYPE_SERVICE_STATUS
                for message in each_message(evn)
                    element = Element(message)
                    @assert element.name.symbol == :ServiceOpened "Failed to start session: expected ServiceOpened, got $(element)"
                    if verbose
                        @info(element)
                    end
                end
            finally
                # destroy this event early, before GC
                isa(evn, Event) && destroy!(evn)
            end
        end
    end

    evn = try_next_event(session)
    if evn != nothing
        @warn("Unhandled event during Session opening: $evn.")
        destroy!(evn)
    end
end

function Session(service::AbstractString;
            host=nothing,
            port=nothing,
            client_mode=nothing,
            service_check_timeout_msecs=nothing,
            service_download_timeout_msecs=nothing,
            session_start_timeout_msecs=DEFAULT_SESSION_START_TIMEOUT_MSECS,
            verbose::Bool=false
        )

    Session(Set([String(service)]),
            host=host,
            port=port,
            client_mode=client_mode,
            service_check_timeout_msecs=service_check_timeout_msecs,
            service_download_timeout_msecs=service_download_timeout_msecs,
            session_start_timeout_msecs=session_start_timeout_msecs,
            verbose=verbose)
end

function Session(services::Vector{T};
            host=nothing,
            port=nothing,
            client_mode=nothing,
            service_check_timeout_msecs=nothing,
            service_download_timeout_msecs=nothing,
            session_start_timeout_msecs=DEFAULT_SESSION_START_TIMEOUT_MSECS,
            verbose::Bool=false
        ) where {T<:AbstractString}

    Session(Set(services),
            host=host,
            port=port,
            client_mode=client_mode,
            service_check_timeout_msecs=service_check_timeout_msecs,
            service_download_timeout_msecs=service_download_timeout_msecs,
            session_start_timeout_msecs=session_start_timeout_msecs,
            verbose=verbose)
end

"""
    stop(session::Session)

Stops a session.

Once a Session has been stopped
it can only be destroyed.
"""
function stop(session::Session)
    err = blpapi_Session_stop(session.handle)
    error_check(err, "Failed to stop session")
end

"""
    next_event(event_source; timeout_milliseconds::Integer=UInt32(0)) :: Event

Reads the next event in the stream events of the `event_source`.
This method blocks until an event is available.

See also [`try_next_event`](@ref).

# Event Sources

The `event_source` can be either a `Session` or an `EventQueue`.
"""
function next_event(session::Session; timeout_milliseconds::Integer=UInt32(0)) :: Event
    event_handle_ref = Ref{Ptr{Cvoid}}(C_NULL)
    err = blpapi_Session_nextEvent(session.handle, event_handle_ref, timeout_milliseconds)
    error_check(err, "Failed to get next event from session")
    return Event(event_handle_ref[], session)
end

"""
    try_next_event(event_source) :: Union{Nothing, Event}

Reads the next event in the stream events of the `event_source`.
If no event is available, returns `nothing`. This method never blocks.

See also [`next_event`](@ref).

# Event Sources

The `event_source` can be either a `Session` or an `EventQueue`.
"""
function try_next_event(session::Session) :: Union{Nothing, Event}
    event_handle_ref = Ref{Ptr{Cvoid}}(C_NULL)
    status = blpapi_Session_tryNextEvent(session.handle, event_handle_ref)
    if status == 0
        return Event(event_handle_ref[], session)
    else
        return nothing
    end
end

Base.getindex(session::Session, service_name::AbstractString) = Service(session, service_name)

"""
    get_opened_services_names(session::Session) :: Set{String}

Returns the set of names for opened services for this `session`.
"""
function get_opened_services_names(session::Session) :: Set{String}
    return deepcopy(session.opened_services)
end

"""
    is_service_open(session::Session, service_name::AbstractString) :: Bool

Returns `true` if `service_name` is opened in the `session`.
"""
@inline function is_service_open(session::Session, service_name::AbstractString) :: Bool
    return service_name_str(service_name) ∈ session.opened_services
end

@inline function check_service_is_open(session::Session, service_name::AbstractString)
    @assert is_service_open(session, service_name) "Service $service_name was not opened in this session."
end

max_stars_repo_licenses: OpenSSL MIT

max_issues_repo_licenses: OpenSSL MIT

max_forks_repo_licenses: OpenSSL MIT