text:
module CellularInfo

using Images, VideoIO

export EQUIVALENT_RULES, ECA_RULES, ECA_CLASS_I, ECA_CLASS_II, ECA_CLASS_III, ECA_CLASS_IV
export simulate, tovideo, transferentropy

include("ca.jl")
include("te.jl")

function toimage(state, cellsize)
    img = fill(Gray(0.5), cellsize, length(state)*(cellsize + 1) - 1)
    for (i, x) in enumerate(state)
        img[1:cellsize, (cellsize*(i-1)+i):((cellsize + 1)*i-1)] .= Gray(x)
    end
    convert(Array{Gray{N0f8}}, img)
end

function tovideo(filename, series; cellwidth=10, framerate=25)
    frames = []
    for i in 1:size(series,1)
        push!(frames, toimage(series[i,:], cellwidth))
    end
    encodevideo(filename, frames, framerate=framerate)
end

end

max_stars_repo_name: ELIFE-ASU/dglmoore

max_issues_repo_name: ELIFE-ASU/dglmoore

max_forks_repo_name: ELIFE-ASU/dglmoore


text:
function nocodeelem3(filename::String)

foldername = "app";
opufile = "opu" * filename;
cpufile = "cpu" * filename;
gpufile = "gpu" * filename;

stropu = "template <typename T> void " * opufile;

tmp = "(T *f, T *xdg, T *uinf, T *param, int modelnumber, int ng, int ncx, int nce, int npe, int ne)\n";

stropu = stropu * tmp * "{\n";
stropu = stropu * "}\n\n";

tmp = "template void " * opufile;
tmp = tmp * "(double *, double *, double *, double *, int, int, int, int, int, int);\n";
tmp = tmp * "template void " * opufile;
tmp = tmp * "(float *, float *, float *, float *, int, int, int, int, int, int);\n";

stropu = stropu * tmp;
strcpu = replace(stropu, "opu" => "cpu");
strgpu = replace(stropu, "opu" => "gpu");

ioopu = open(foldername * "/" * opufile * ".cpp", "w");
write(ioopu, stropu);
close(ioopu);

iocpu = open(foldername * "/" * cpufile * ".cpp", "w");
write(iocpu, strcpu);
close(iocpu);

iogpu = open(foldername * "/" * gpufile * ".cu", "w");
write(iogpu, strgpu);
close(iogpu);

end

ext: jl

max_stars_repo_name: rloekvh/Exasim

max_issues_repo_name: rloekvh/Exasim

max_forks_repo_name: rloekvh/Exasim


text:
abstract type AbstractIntegratorSPARK{dType, tType, D, S, R} <: PDAEIntegrator{dType, tType} end
abstract type AbstractIntegratorHSPARK{dType, tType, D, S, R} <: AbstractIntegratorSPARK{dType, tType, D, S, R} end
abstract type AbstractIntegratorVSPARK{dType, tType, D, S, R} <: AbstractIntegratorSPARK{dType, tType, D, S, R} end

@inline parameters(int::AbstractIntegratorSPARK) = int.params
@inline nstages(int::AbstractIntegratorSPARK{DT,TT,D,S,R}) where {DT,TT,D,S,R} = S
@inline pstages(int::AbstractIntegratorSPARK{DT,TT,D,S,R}) where {DT,TT,D,S,R} = R
@inline Base.ndims(int::AbstractIntegratorSPARK{DT,TT,D,S,R}) where {DT,TT,D,S,R} = D
@inline eachstage(integrator::AbstractIntegratorSPARK) = 1:nstages(integrator)


text:
# load modules
push!(LOAD_PATH, "../dvi")

addprocs(int(CPU_CORES / 2))

using DiscreteValueIteration
using SCAs, SCAIterators, SCAConst
using GridInterpolations

mdp = SCA()

# check size of mdp
function getBytes(x)
   total = 0;
   fieldNames = typeof(x).names;
   if fieldNames == ()
      return sizeof(x);
   else
     for fieldName in fieldNames
        total += getBytes(getfield(x,fieldName));
     end
     return total;
   end
end

println("mdp of type ", typeof(mdp), " takes up ", getBytes(mdp) / 1000.0, " kB")

# parallel solution
numProcs = int(CPU_CORES / 2)
solver = ParallelSolver(
    numProcs,
    maxIterations = 1000,
    tolerance = 1e-6,
    gaussSiedel = false,
    includeV = true,
    includeQ = true,
    includeA = true)

policy = solve(solver, mdp, verbose = true)

# save solution
using JLD

function sharray2array(sharray::SharedArray{Float64, 2})
    result = zeros(sharray.dims)
    for i = 1:sharray.dims[1]
        for j = 1:sharray.dims[2]
            result[i, j] = sharray[i, j]
        end # for j
    end # for i
    return result
end # function sharray2array

solQ = sharray2array(policy.Q')
save("../../data/par-alpha.jld", "solQ", solQ)


text:
#!/usr/bin/env julia
using TOML

# Default to the `stdlib/vX.Y` directory
STDLIB_DIR = get(ARGS, 1, joinpath(@__DIR__, "..", "usr", "share", "julia", "stdlib"))
vXYdirs = readdir(STDLIB_DIR)
if length(vXYdirs) == 1 && match(r"v\d\.\d", vXYdirs[1]) !== nothing
    STDLIB_DIR = joinpath(STDLIB_DIR, vXYdirs[1])
end

project_deps = Dict{String,Set{String}}()
for project_dir in readdir(STDLIB_DIR, join=true)
    files = readdir(project_dir)
    if "Project.toml" in files
        project = TOML.parsefile(joinpath(project_dir, "Project.toml"))

        if !haskey(project, "name")
            continue
        end
        name = project["name"]
        deps = Set(collect(keys(get(project, "deps", Dict{String,String}()))))
        project_deps[name] = deps
    end
end

#println("Found $(length(keys(project_deps))) stdlib projects")

function project_depth(project)
    deps = project_deps[project]
    if isempty(deps)
        return 0
    end

    depth = 1
    while !all(isempty(project_deps[d]) for d in deps)
        depth += 1

        if depth > 100
            error("Failed to converge while finding project depth for $(project)!")
        end

        new_deps = Set{String}()
        for d in deps
            union!(new_deps, project_deps[d])
        end
        deps = new_deps
    end
    return depth
end

project_depths = Dict(p => project_depth(p) for p in keys(project_deps))

function project_isless(p1, p2)
    if project_depths[p1] != project_depths[p2]
        return isless(project_depths[p1], project_depths[p2])
    end
    return isless(p1, p2)
end

sorted_projects = sort(collect(keys(project_depths)), lt=project_isless)

# Print out sorted projects, ready to be pasted into `sysimg.jl`
last_depth = 0
println("    # Stdlibs sorted in dependency, then alphabetical, order by contrib/print_sorted_stdlibs.jl")
println("    stdlibs = [")
println("        # No dependencies")
for p in sorted_projects
    if project_depths[p] != last_depth
        global last_depth = project_depths[p]
        println()
        println("        # $(last_depth)-depth packages")
    end
    println("        :$(p),")
end
println("    ]")

max_stars_repo_name: vanillajonathan/julia

max_issues_repo_name: vanillajonathan/julia

max_forks_repo_name: vanillajonathan/julia


text:
using MittagLefflerFunctions
using PyPlot
using SpecialFunctions: erfcx

α = 1/2
β = 1.0

#x = range(0, 10, length=201)
x = range(-5, 3, length=300)
y = erfcx.(-x)

Nvals = collect(4:2:10)

style = ("-", "--", ":", "-.")
function draw_errors(contour::Symbol)
    for row = 1:length(Nvals)
        N = Nvals[row]
        E = MLQuad(α, β, N, contour)
        err = abs.( y - E.(x) )
        semilogy(x, err, style[row], label="N = $N")
    end
    legend(loc="upper right")
    grid(true)
    xlabel(L"$x$")
end

figure(1)
draw_errors(:parabola)
xylims = (-5.4, 3.4, 3e-12, 6e-4)
axis(xylims)
savefig("figure07L.pdf")

figure(2)
draw_errors(:hyperbola)
savefig("figure07R.pdf")
axis(xylims)


text:
Base.promote_rule(::Type{Constant{name,S,D,SU}},
                  ::Type{Quantity{T,D,TU}}) where {name,S,T,D,SU,TU} =
                      promote_type(Quantity{S,D,SU}, Quantity{T,D,TU})
Base.promote_rule(::Type{Quantity{T,D,TU}},
                  ::Type{Constant{name,S,D,SU}}) where {name,S,T,D,SU,TU} =
                      promote_type(Quantity{S,D,SU}, Quantity{T,D,TU})

Base.promote_rule(::Type{Constant{name,S,NoDims,U}},
                  ::Type{T}) where {name,S,U,T<:Number} =
                      promote_type(S, T)
Base.promote_rule(::Type{Constant{name,S,NoDims,U}},
                  ::Type{Quantity{T,NoDims,TU}}) where {name,S,U,T,TU} =
                      promote_type(S, T)

Base.convert(::Type{T},
             x::Constant{name,S,NoDims,U}) where {T<:AbstractFloat,name,S,U} =
                 float(T, x)

Unitful.uconvert(u::Unitful.Units, c::Constant{name,T,D,TU}) where {name,T,D,TU} =
    uconvert(u, float(T, c))


text:
#=
  From
  Yi Wu, Lei Li, Stuart Russell, Rastislav Bodik
  "Swift: Compiled Inference for Probabilistic Programming Languages"
  Page 3

  Summary Statistics
  parameters      mean       std   naive_se       mcse         ess       rhat   ess_per_sec
      Symbol   Float64   Float64    Float64   Float64?    Float64?   Float64?      Float64?

     cluster    3.5614    1.4721     0.0147     0.0347   1385.1836     1.0003      111.8346
       mu[1]   -0.1752    7.9247     0.0792     0.1902   1447.7438     1.0002      116.8855
       mu[2]    0.1621    8.1310     0.0813     0.2017   1361.4057     1.0007      109.9149
        z[1]    2.2715    1.2967     0.0130     0.0352   1192.9498     1.0004       96.3144
        z[2]    2.2670    1.2947     0.0129     0.0341   1242.9694     1.0001      100.3528
        z[3]    2.2901    1.2907     0.0129     0.0340   1366.0522     1.0006      110.2900
   x_post[1]    0.0905    1.4039     0.0140     0.0223   4274.1990     1.0006      345.0831
   x_post[2]    0.0648    7.9544     0.0795     0.2009   1411.9730     1.0021      113.9975
   x_post[3]   -0.2165    8.3757     0.0838     0.2278   1344.0788     1.0010      108.5160
       mu[3]    0.1385    8.4502     0.0998     0.2856     missing    missing       missing
       mu[4]    0.1468    8.7843     0.1334     0.3392     missing    missing       missing
       mu[5]   -0.9117    8.9978     0.1853     0.5347     missing    missing       missing
       mu[6]   -0.1977    9.2914     0.2807     0.9323     missing    missing       missing
       mu[7]   -0.3155    8.8300     0.4176     0.6646     missing    missing       missing
       mu[8]    4.1820   12.8344     1.1005    missing     missing    missing       missing
       mu[9]    5.5301    9.7624     1.4240    missing     missing    missing       missing
      mu[10]    2.6899    2.7582     0.6501    missing     missing    missing       missing
   ...

  Distributions of variable cluster (num:0)
  3.00000 =>    2838  (0.283800)
  2.00000 =>    2825  (0.282500)
  4.00000 =>    1979  (0.197900)
  5.00000 =>    1262  (0.126200)
  6.00000 =>     649  (0.064900)
  7.00000 =>     311  (0.031100)
  8.00000 =>      89  (0.008900)
  9.00000 =>      29  (0.002900)
  10.00000 =>      18  (0.001800)

   cf ~/webppl/infinite_gaussian_mixture.wppl

=#

using Turing, StatsPlots, DataFrames
include("jl_utils.jl")

#=
BLOG model:

distinct Data D[20]; // 20 data points
#Cluster ~ Poisson(4); // Number of clusters

random Real mu(Cluster c) ~ Gaussian(0.0,10.0); // Cluster mean
random Cluster z(Data d) ~ UniformChoice({c for Cluster c});

random Real x(Data d) ~ Gaussian(mu(z(d)), 1.0); // data

=#
@model function infinite_gaussian_mixture(x=[0.1],n=3)
    # n = length(x)

    cluster ~ Truncated(Poisson(3),1,Inf) # Number of clusters
    mu ~ filldist(Normal(0,10),cluster) # Cluster mean

    # Number of clusters per data points
    z = tzeros(n)
    for i in 1:n
        z[i] ~ DiscreteUniform(1,cluster)
    end

    # Observe the data.
    # z[i] returns a float, hence the round
    for i in 1:length(x)
        zi = round(Int,z[i])
        x[i] ~ Normal(mu[zi], 1.0)
    end

    # Here we want n posterior data points
    x_post = tzeros(n)
    for i in 1:n
        zi = round(Int,z[i])
        x_post[i] ~ Normal(mu[zi], 1.0)
    end

    # x1 ~ Dirac(x_post[1])
    # x2 ~ Dirac(x_post[2])
    # x3 ~ Dirac(x_post[3])

end

# x=[0.1,0.1,0.1]
x = [0.1]
n = 3 # we want 3 predictions
model = infinite_gaussian_mixture(x,n)

# chns = sample(model, Prior(), 10_000)
# chns = sample(model, MH(), 100_000)
# chns = sample(model, PG(5), 10_000)
chns = sample(model, SMC(), 10_000)
# chns = sample(model, IS(), 10_000)

display(chns)
# display(plot(chns))

show_var_dist_pct(chns,:cluster)

max_stars_repo_name: tias/hakank

max_issues_repo_name: tias/hakank

max_forks_repo_name: tias/hakank


text:
# SCIP typedefs
{% for type_name, type_ref in parser.typedefs.items() %}
typealias {{ type_name }} {{ type_ref }}{% endfor %}


text:
using StatsModels,DataFrames,MLStyle
include("Chain.jl")

data = DataFrame(A=[1,2,3], B=[2,4,7],C=[1,3,2],D=[3,2,5])

function form(expr)
    @match expr begin
        :($var~$data-$drop)=>
            let res=@chain propertynames(eval(data)).filter(i->i!=var&&i!=drop).join('+')
                :(@formula($var~$(Meta.parse(res))))
            end
        :($var~$data)=>
            let res=@chain propertynames(eval(data)).filter(i->i!=var).join('+')
                :(@formula($var~$(Meta.parse(res))))
            end
    end
end

macro form(expr)
    form(expr)|>esc
end

@info @form(A~data)==@formula(A~B+C+D)
@info @form(A~data-B)==@formula(A~C+D)

max_stars_repo_name: cherichy/MLStyle-Playground

max_issues_repo_name: cherichy/MLStyle-Playground

max_forks_repo_name: cherichy/MLStyle-Playground


text:
function testFourierTransform()
    M = 4
    N = 5

    grid = Grid2d(M,N)
    ft   = FourierTransform(grid; ℳcut=2, 𝒩cut=2)

    println(ft)
end

function testRealFourierTransforms()
    M  = 32
    N  = 32

    grid = Grid2d(M,N)
    u    = get_field(grid)
    ufft = get_field(grid)
    ft   = FourierTransform(grid; ℳcut=4, 𝒩cut=4)
    û    = get_trans(ft)

    evaluate_function_on_grid(grid, cos_test, u)

    prfft!(ft, u, û)
    irfft!(ft, û, ufft)

    @test maximum(u - ufft) ≈ zero(eltype(u)) atol=1E-15

    frfft!(ft, u, û)
    irfft!(ft, û, ufft)

    @test maximum(u - ufft) ≈ zero(eltype(u)) atol=1E-15

end

testFourierTransform()
testRealFourierTransforms()


text:
module Prerequisites

using Formatting: FormatSpec,fmt

export atol,rtol,Float
export decimaltostr,ordinal,delta
export rawtype

"Absolute tolerance for float numbers."
const atol=5*10^-14

"Relative tolerance for float numbers."
const rtol=√atol

"Default float type."
const Float=Float64

"""
    decimaltostr(number,::Int=5)
    decimaltostr(number::Integer,n::Int=5)
    decimaltostr(number::Rational,n::Int=5)
    decimaltostr(number::AbstractFloat,n::Int=5)
    decimaltostr(number::Complex,n::Int=5)

Convert a number to a string with at most `n` decimal places.
"""
decimaltostr(number,::Int=5)=repr(number)
decimaltostr(number::Integer,::Int=5)=string(number)
decimaltostr(number::Rational,::Int=5)=string(number)
function decimaltostr(number::AbstractFloat,n::Int=5)
    if number==0.0
        result="0.0"
    elseif 10^-5<abs(number)<10^6
        result=rstrip(fmt(FormatSpec(".$(n)f"),number),'0')
        result[end]=='.' && (result=result*'0')
    else
        result=fmt(FormatSpec(".$(n)e"),number)
        epos=findfirst(isequal('e'),result)
        temp=rstrip(result[1:epos-1],'0')
        result=temp[end]=='.' ? temp*"0"*result[epos:end] : temp*result[epos:end]
    end
    result
end
function decimaltostr(number::Complex,n::Int=5)
    sreal=real(number)==0 ? "0" : decimaltostr(real(number),n)
    simag=imag(number)==0 ? "0" : decimaltostr(imag(number),n)
    result=""
    sreal=="0" || (result=result*sreal)
    simag=="0" || (result=(simag[1]=='-' ? result*simag : length(result)==0 ? simag : result*"+"*simag)*"im")
    length(result)==0 && (result="0.0")
    return result
end

"""
    ordinal(number::Interger)

Convert a positive number to its corresponding ordinal.
"""
function ordinal(number)
    @assert number>0
    number==1 ? "1st" : number==2 ? "2nd" : number==3 ? "3rd" : "$(number)th"
end

"""
    delta(i,j) -> Int

Kronecker delta function.
"""
delta(i,j)=i==j ? 1 : 0

"""
    rawtype(T::DataType) -> Union{DataType,UnionAll}
    rawtype(T::UnionAll) -> Union{DataType,UnionAll}

Get the "raw" type without the type parameters.
"""
rawtype(T::DataType)=T.name.wrapper
rawtype(T::UnionAll)=T.body.name.wrapper

include("TypeTraits.jl")
include("Factories.jl")
include("CompositeStructures.jl")
include("SimpleTrees.jl")
include("NamedVectors.jl")

end # module


text:
# __BEGIN_LICENSE__
#
# WaveOptics.jl
#
# Copyright (c) 2015, Stanford University
#
# All rights reserved.
#
# Redistribution and use in source and binary forms for academic and other
# non-commercial purposes with or without modification, are permitted provided
# that the following conditions are met:
#
# * Redistributions of source code, including modified source code, must retain
#   the above copyright notice, this list of conditions and the following
#   disclaimer.
#
# * Redistributions in binary form or a modified form of the source code must
#   reproduce the above copyright notice, this list of conditions and the
#   following disclaimer in the documentation and/or other materials provided with
#   the distribution.
#
# * Neither the name of The Leland Stanford Junior University, any of its
#   trademarks, the names of its employees, nor contributors to the source code
#   may be used to endorse or promote products derived from this software without
#   specific prior written permission.
#
# * Where a modified version of the source code is redistributed publicly in
#   source or binary forms, the modified source code must be published in a freely
#   accessible manner, or otherwise redistributed at no charge to anyone
#   requesting a copy of the modified source code, subject to the same terms as
#   this agreement.
#
# THIS SOFTWARE IS PROVIDED BY THE TRUSTEES OF THE LELAND STANFORD JUNIOR
# UNIVERSITY "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LELAND STANFORD JUNIOR
# UNIVERSITY OR ITS TRUSTEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
#
# __END_LICENSE__

using Interpolations
using QuadGK, SpecialFunctions

# -----------------------------------------------------------------------------
#               WIDE FIELD MICROSCOPE APSF (DEBYE MODEL)
# -----------------------------------------------------------------------------

mutable struct DebyeModel <: PointSpreadFunctionModel
    recipe::OpticalRecipe
    sim_size_m::Float64
    sim_size_px::Int64
    num_observations::Int32
    include_intensity_scalefactor::Bool

end # type DebyeModel

"""
Computes the amplitude PSF of a point source at (x,y,z) using a scalar Debye
model. This code implements Equation 3.4.15 and 6.2.17 in 'Advanced Optical Imaging
Theory' by Min Gu.

This model assumes that the 3D APSF of the microscope is tranlationally invariant
in x, y, and z. While this assumption is accurate for a large range of depths
around the native object plane, it can break down for zery large z-depths.  The
approximation only holds if eqn. 3.4.4 in Gu's book is satisfied.  See Sections 3.3
and 3.4 for more discussion, and be careful when using this PSF to model large
z offsets.

**Parameters**

    recipe - an optical recipe containing important simulation parameters
    sim_size_m - linear dimension (used for width & height) in meters (or other units
             of your choice) to be used for the PSF simulation.
    sim_size_px - the number of pixel in each linear dimension.  All simulations are square.
    include_intensity_scalefactor - Include the intensity scaling found in Gu's original
           equations.  Off by default since this makes the intensities very large, which
           can lead to numerical problems.  Intensities are not really calibrated here anyway.
"""
function DebyeModel(
    recipe::OpticalRecipe,
    sim_size_m::Float64,
    sim_size_px::Int64;
    include_intensity_scalefactor::Bool = false,
)

    num_observations = 1

    return DebyeModel(
        recipe,
        sim_size_m,
        sim_size_px,
        num_observations,
        include_intensity_scalefactor,
    )

end # DebyeModel constructor

function num_parameters(model::DebyeModel)
    return 0
end

#-------
# Numerical integration helper functions

"""
`function complex_quadrature(func, a, b)`

Allows numerical integration of complex valued functions.  The real and imaginary parts of the
function are integrated seperately and then combined together.
"""
function complex_quadrature(func, a, b)
    real_integral, err = quadgk(x -> real(func(x)), a, b, rtol = 1e-6, atol = 1e-9)
    imag_integral, err = quadgk(x -> imag(func(x)), a, b, rtol = 1e-6, atol = 1e-9)
    return real_integral + 1im * imag_integral
end

"""
The Fresnel integral function is suitable for low numerical aperture (eqn.
3.4.15). This is an approximation of the full Debye function below.
"""
function fresnel_integrand_fn(rho::Float64, u::Float64, v::Float64)
    return exp(1im * u / 2 * rho .^ 2) * besselj(0, rho * v) * 2 * pi .* rho
end

function fresnel_apsf_fn(u::Float64, v::Float64, alpha_o::Float64)
    cmplx_integral = complex_quadrature(rho -> fresnel_integrand_fn(rho, u, v), 0.0, 1.0)
    return exp(-1im * u / (4 * sin(alpha_o / 2)^2)) * cmplx_integral
end

"""
The Debye integral function (based on eqn. 6.2.17).

We use a abbe sine apodization function here: P(theta) = P(r) * sqrt(cos(theta))
"""
function debye_integrand_fn(theta::Float64, alpha::Float64, u::Float64, v::Float64)
    apodization = sqrt(cos(theta))       # Abbe sine apodization
    return apodization * exp(1im * u * sin(theta / 2) .^ 2 / (2 * sin(alpha / 2) .^ 2)) .*
           besselj(0, sin(theta) / sin(alpha) * v) .* sin(theta)
end

function debye_apsf_fn(
    u::Float64,
    v::Float64,
    alpha_o::Float64,
    k::Float64,
    z_image::Float64,
)
    cmplx_integral =
        complex_quadrature(theta -> debye_integrand_fn(theta, alpha_o, u, v), 0.0, alpha_o)
    return 1im * exp(-1im * k * z_image) * cmplx_integral
end

"""
Compute the amplitude point spread function.

**Parameters**

    p - position of the point source
    theta - the parameters to pass to the aperture_mask.  If theta = Float64[], the aperture's default
      parameters will be used.

**Returns**

    apsf - 2D image of the APSF on the image sensor
"""
function apsf(model::DebyeModel, p, theta = Float64[])
    x, y, z = p   # unpack p

    sample_period = model.sim_size_m / model.sim_size_px
    f_objective = model.recipe.f_tubelens / model.recipe.objective_mag          # Objective focal length
    d1 = f_objective                                                            # d1 = f1 ?? (I'm not sure of this...)
    alpha_o = asin(model.recipe.objective_na / model.recipe.medium_index)       # Object side numerical aperture angle
    k = model.recipe.medium_index * 2.0 * pi / model.recipe.wavelength           # Wave number, with medium_index factored in

    # Compute the Fresnel number of the objective at this z depth.
    a = model.recipe.objective_na / model.recipe.medium_index * f_objective
    d10 = f_objective - z
    fresnel_number = pi * a^2 / (model.recipe.wavelength * d10)

    # The PSF is radially symmetric, so we will convert a set of cartesian
    # coordinates to polar coordinates and use those below to interpolate
    # radial coordinates and produce a 2D image.
    x_ticks = range(
        -model.sim_size_m / 2.0 + sample_period / 2.0,
        stop = model.sim_size_m / 2.0 - sample_period / 2.0,
        length = model.sim_size_px,
    )
    X, Y = WaveOptics.meshgrid(x_ticks, x_ticks)
    R = sqrt.(X .^ 2 + Y .^ 2)
    max_r = maximum(R)

    # Create a lookup table of PSF values as a function of radius. Sample at
    # 2x the cartesian sampling rate to make sure we can intepolate back to
    # a cartesian grid without introducing artifacts.
    dr = model.sim_size_m / (2.0 * model.sim_size_px)
    rho = 0:dr:max_r+sample_period/2

    # Compute the APSF for each element of the lookup table.
    apsf_vals = zeros(ComplexF32, size(rho))
    z_image = 0.0
    z_object = z

    # Set intensity scale factor
    scale_factor = 1.0
    if (fresnel_number < 1.0) && model.include_intensity_scalefactor
        scale_factor = M / (d1^2.0 * wavelength^2)
    end

    if (fresnel_number >= 1.0) && model.include_intensity_scalefactor
        scale_factor = 2.0 * pi / wavelength
    end

    for i = 1:length(rho)
        # Normalized optical coordinates, Eqns. 6.2.16
        v = k * rho[i] * sin(alpha_o)           # Radial (transverse) optical coordinate
        u = 4 * k * z_object * sin(alpha_o / 2)^2 # Axial optical coordinate

        if fresnel_number < 1.0
            apsf_vals[i] = scale_factor * fresnel_apsf_fn(u, v, alpha_o)
        else
            apsf_vals[i] = scale_factor * debye_apsf_fn(u, v, alpha_o, k, z_image)
        end
    end

    # Interpolate to populate the image.
    apsf_img_real = Interpolations.scale(
        interpolate(real(apsf_vals), BSpline(Quadratic(Line(Interpolations.OnCell())))),
        rho,
    )
    apsf_img_imag = Interpolations.scale(
        interpolate(imag(apsf_vals), BSpline(Quadratic(Line(Interpolations.OnCell())))),
        rho,
    )

    # Interpolate
    apsf = zeros(ComplexF32, size(R))
    for i in eachindex(R)  # Efficiently iterate over array elements
        apsf[i] = apsf_img_real(R[i]) + 1im * apsf_img_imag(R[i])
    end

    if !(x == 0 && y == 0)
        # Translate and return the result.
        apsf = translate_apsf(model.sim_size_m, model.sim_size_px, apsf, x, y)
    end

    return apsf
end


text:
# Automatically generated using Clang.jl

"Callback for CPLPushFileFinder"
const CPLFileFinder = Ptr{Cvoid}

struct CPLSharedFileInfo
    fp::Ptr{Cint}
    nRefCount::Cint
    bLarge::Cint
    pszFilename::Cstring
    pszAccess::Cstring
end

"No error"
const CPLE_None = 0

"Application defined error"
const CPLE_AppDefined = 1

"Out of memory error"
const CPLE_OutOfMemory = 2

"File I/O error"
const CPLE_FileIO = 3

"Open failed"
const CPLE_OpenFailed = 4

"Illegal argument"
const CPLE_IllegalArg = 5

"Not supported"
const CPLE_NotSupported = 6

"Assertion failed"
const CPLE_AssertionFailed = 7

"No write access"
const CPLE_NoWriteAccess = 8

"User interrupted"
const CPLE_UserInterrupt = 9

"NULL object"
const CPLE_ObjectNull = 10

"HTTP response"
const CPLE_HttpResponse = 11

"AWSBucketNotFound"
const CPLE_AWSBucketNotFound = 12

"AWSObjectNotFound"
const CPLE_AWSObjectNotFound = 13

"AWSAccessDenied"
const CPLE_AWSAccessDenied = 14

"AWSInvalidCredentials"
const CPLE_AWSInvalidCredentials = 15

"AWSSignatureDoesNotMatch"
const CPLE_AWSSignatureDoesNotMatch = 16

"VSIE_AWSError"
const CPLE_AWSError = 17

# Skipping MacroDefinition: CPLAssertAlwaysEval ( expr ) ( void ) ( expr )

"Error category"
@cenum CPLErr::UInt32 begin
    CE_None = 0
    CE_Debug = 1
    CE_Warning = 2
    CE_Failure = 3
    CE_Fatal = 4
end

# Skipping MacroDefinition: VALIDATE_POINTER0 ( ptr , func ) do { if ( CPL_NULLPTR == ptr ) { CPLErr const ret = VALIDATE_POINTER_ERR ; CPLError ( ret , CPLE_ObjectNull , "Pointer \'%s\' is NULL in \'%s\'.\n" , # ptr , ( func ) ) ; return ; } } while ( 0 )
# Skipping MacroDefinition: VALIDATE_POINTER1 ( ptr , func , rc ) do { if ( CPL_NULLPTR == ptr ) { CPLErr const ret = VALIDATE_POINTER_ERR ; CPLError ( ret , CPLE_ObjectNull , "Pointer \'%s\' is NULL in \'%s\'.\n" , # ptr , ( func ) ) ; return ( rc ) ; } } while ( 0 )

"Error number"
const CPLErrorNum = Cint

"Callback for a custom error handler"
const CPLErrorHandler = Ptr{Cvoid}

"XML node type"
@cenum CPLXMLNodeType::UInt32 begin
    CXT_Element = 0
    CXT_Text = 1
    CXT_Attribute = 2
    CXT_Comment = 3
    CXT_Literal = 4
end

"Document node structure"
struct CPLXMLNode
    eType::CPLXMLNodeType
    pszValue::Cstring
    psNext::Ptr{CPLXMLNode}
    psChild::Ptr{CPLXMLNode}
end

# Skipping MacroDefinition: CPL_STATIC_CAST ( type , expr ) ( ( type ) ( expr ) )
# Skipping MacroDefinition: CPL_REINTERPRET_CAST ( type , expr ) ( ( type ) ( expr ) )
# Skipping MacroDefinition: GINTBIG_MIN ( CPL_STATIC_CAST ( GIntBig , 0x80000000 ) << 32 )
# Skipping MacroDefinition: GINTBIG_MAX ( ( CPL_STATIC_CAST ( GIntBig , 0x7FFFFFFF ) << 32 ) | 0xFFFFFFFFU )
# Skipping MacroDefinition: GUINTBIG_MAX ( ( CPL_STATIC_CAST ( GUIntBig , 0xFFFFFFFFU ) << 32 ) | 0xFFFFFFFFU )

const CPL_HAS_GINT64 = 1

"Printf formatting suffix for GIntBig"
const CPL_FRMT_GB_WITHOUT_PREFIX = "I64"

# Skipping MacroDefinition: CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
# Skipping MacroDefinition: CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
# Skipping MacroDefinition: GUINTBIG_TO_DOUBLE ( x ) CPL_STATIC_CAST ( double , x )
# Skipping MacroDefinition: CPL_INT64_FITS_ON_INT32 ( x ) ( CPL_STATIC_CAST ( GIntBig , CPL_STATIC_CAST ( int , x ) ) == ( x ) )
# Skipping MacroDefinition: MIN ( a , b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
# Skipping MacroDefinition: MAX ( a , b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
# Skipping MacroDefinition: ABS ( x ) ( ( ( x ) < 0 ) ? ( - 1 * ( x ) ) : ( x ) )

"PI definition"
const M_PI = 3.141592653589793

# Skipping MacroDefinition: CPLIsEqual ( x , y ) ( fabs ( ( x ) - ( y ) ) < 0.0000000000001 )
# Skipping MacroDefinition: STRCASECMP ( a , b ) ( stricmp ( a , b ) )
# Skipping MacroDefinition: STRNCASECMP ( a , b , n ) ( strnicmp ( a , b , n ) )
# Skipping MacroDefinition: EQUALN ( a , b , n ) ( STRNCASECMP ( a , b , n ) == 0 )
# Skipping MacroDefinition: EQUAL ( a , b ) ( STRCASECMP ( a , b ) == 0 )
# Skipping MacroDefinition: STARTS_WITH ( a , b ) ( strncmp ( a , b , strlen ( b ) ) == 0 )
# Skipping MacroDefinition: STARTS_WITH_CI ( a , b ) EQUALN ( a , b , strlen ( b ) )
# Skipping MacroDefinition: CPLIsNan ( x ) isnan ( x )
# Skipping MacroDefinition: CPLIsInf ( x ) ( 0 )
# Skipping MacroDefinition: CPLIsFinite ( x ) ( ! isnan ( x ) )

const CPL_IS_LSB = 1

# Skipping MacroDefinition: CPL_SWAP16 ( x ) CPL_STATIC_CAST ( GUInt16 , ( CPL_STATIC_CAST ( GUInt16 , x ) << 8 ) | ( CPL_STATIC_CAST ( GUInt16 , x ) >> 8 ) )
# Skipping MacroDefinition: CPL_SWAP32 ( x ) CPL_STATIC_CAST ( GUInt32 , __builtin_bswap32 ( CPL_STATIC_CAST ( GUInt32 , x ) ) )
# Skipping MacroDefinition: CPL_SWAP64 ( x ) CPL_STATIC_CAST ( GUInt64 , __builtin_bswap64 ( CPL_STATIC_CAST ( GUInt64 , x ) ) )
# Skipping MacroDefinition: CPL_SWAP16PTR ( x ) \
#{ GByte byTemp , * _pabyDataT = CPL_REINTERPRET_CAST ( GByte * , x ) ; CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 2 ) ; byTemp = _pabyDataT [ 0 ] ; _pabyDataT [ 0 ] = _pabyDataT [ 1 ] ; _pabyDataT [ 1 ] = byTemp ; \
#}
# Skipping MacroDefinition: CPL_SWAP32PTR ( x ) \
#{ GUInt32 _n32 ; void * _lx = x ; memcpy ( & _n32 , _lx , 4 ) ; CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 4 ) ; _n32 = CPL_SWAP32 ( _n32 ) ; memcpy ( _lx , & _n32 , 4 ) ; \
#}
# Skipping MacroDefinition: CPL_SWAP64PTR ( x ) \
#{ GUInt64 _n64 ; void * _lx = x ; memcpy ( & _n64 , _lx , 8 ) ; CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 8 ) ; _n64 = CPL_SWAP64 ( _n64 ) ; memcpy ( _lx , & _n64 , 8 ) ; \
#}
# Skipping MacroDefinition: CPL_SWAPDOUBLE ( p ) CPL_SWAP64PTR ( p )
# Skipping MacroDefinition: CPL_LSBWORD16 ( x ) ( x )
# Skipping MacroDefinition: CPL_MSBWORD16 ( x ) CPL_SWAP16 ( x )
# Skipping MacroDefinition: CPL_LSBWORD32 ( x ) ( x )
# Skipping MacroDefinition: CPL_MSBWORD32 ( x ) CPL_SWAP32 ( x )
# Skipping MacroDefinition: CPL_LSBPTR16 ( x ) CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 2 )
# Skipping MacroDefinition: CPL_MSBPTR16 ( x ) CPL_SWAP16PTR ( x )
# Skipping MacroDefinition: CPL_LSBPTR32 ( x ) CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 4 )
# Skipping MacroDefinition: CPL_MSBPTR32 ( x ) CPL_SWAP32PTR ( x )
# Skipping MacroDefinition: CPL_LSBPTR64 ( x ) CPL_STATIC_ASSERT_IF_AVAILABLE ( sizeof ( * ( x ) ) == 1 || sizeof ( * ( x ) ) == 8 )
# Skipping MacroDefinition: CPL_MSBPTR64 ( x ) CPL_SWAP64PTR ( x )
# Skipping MacroDefinition: CPL_LSBINT16PTR ( x ) ( ( * CPL_REINTERPRET_CAST ( const GByte * , x ) ) | ( * ( ( CPL_REINTERPRET_CAST ( const GByte * , x ) ) + 1 ) << 8 ) )
# Skipping MacroDefinition: CPL_LSBINT32PTR ( x ) ( ( * CPL_REINTERPRET_CAST ( const GByte * , x ) ) | ( * ( ( CPL_REINTERPRET_CAST ( const GByte * , x ) ) + 1 ) << 8 ) | ( * ( ( CPL_REINTERPRET_CAST ( const GByte * , x ) ) + 2 ) << 16 ) | ( * ( ( CPL_REINTERPRET_CAST ( const GByte * , x ) ) + 3 ) << 24 ) )
# Skipping MacroDefinition: CPL_LSBSINT16PTR ( x ) CPL_STATIC_CAST ( GInt16 , CPL_LSBINT16PTR ( x ) )
# Skipping MacroDefinition: CPL_LSBUINT16PTR ( x ) CPL_STATIC_CAST ( GUInt16 , CPL_LSBINT16PTR ( x ) )
# Skipping MacroDefinition: CPL_LSBSINT32PTR ( x ) CPL_STATIC_CAST ( GInt32 , CPL_LSBINT32PTR ( x ) )
# Skipping MacroDefinition: CPL_LSBUINT32PTR ( x ) CPL_STATIC_CAST ( GUInt32 , CPL_LSBINT32PTR ( x ) )
# Skipping MacroDefinition: UNREFERENCED_PARAM ( param ) ( ( void ) param )
# Skipping MacroDefinition: CPL_CVSID ( string ) static const char cpl_cvsid [ ] __attribute__ ( ( used ) ) = string ;
# Skipping MacroDefinition: CPL_NULL_TERMINATED __attribute__ ( ( __sentinel__ ) )
# Skipping MacroDefinition: CPL_PRINT_FUNC_FORMAT ( format_idx , arg_idx ) __attribute__ ( ( __format__ ( __printf__ , format_idx , arg_idx ) ) )
# Skipping MacroDefinition: CPL_SCAN_FUNC_FORMAT ( format_idx , arg_idx ) __attribute__ ( ( __format__ ( __scanf__ , format_idx , arg_idx ) ) )
# Skipping MacroDefinition: CPL_FORMAT_STRING ( arg ) arg
# Skipping MacroDefinition: CPL_SCANF_FORMAT_STRING ( arg ) arg
# Skipping MacroDefinition: CPL_WARN_UNUSED_RESULT __attribute__ ( ( warn_unused_result ) )
# Skipping MacroDefinition: CPL_UNUSED __attribute ( ( __unused__ ) )
# Skipping MacroDefinition: CPL_NO_RETURN __attribute__ ( ( noreturn ) )
# Skipping MacroDefinition: CPL_RETURNS_NONNULL __attribute__ ( ( returns_nonnull ) )
# Skipping MacroDefinition: CPL_WARN_DEPRECATED ( x ) __attribute__ ( ( deprecated ( x ) ) )
# Skipping MacroDefinition: CPL_FALLTHROUGH [ [ clang : : fallthrough ] ] ;

const FALSE = 0
const TRUE = 1

# Skipping MacroDefinition: VOLATILE_BOOL volatile bool
# Skipping MacroDefinition: CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__ ( ( no_sanitize ( "unsigned-integer-overflow" ) ) )

"Int32 type"
const GInt32 = Cint

"Unsigned int32 type"
const GUInt32 = UInt32

"Int16 type"
const GInt16 = Int16

"Unsigned int16 type"
const GUInt16 = UInt16

"Unsigned byte type"
const GByte = Cuchar

"Type for boolean values (alias to int)"
const GBool = Cint

"Large signed integer type (generally 64-bit integer type)"
const GIntBig = Clonglong

"Large unsigned integer type (generally 64-bit unsigned integer type)"
const GUIntBig = Culonglong

"Signed 64 bit integer type"
const GInt64 = GIntBig

"Unsigned 64 bit integer type"
const GUInt64 = GUIntBig

"Integer type large enough to hold the difference between 2 addresses"
const GPtrDiff_t = GIntBig

"Type of a constant null-terminated list of nul terminated strings"
const CSLConstList = Ptr{Cstring}

"Callback progress definition for long operations"
const GDALProgressFunc = Ptr{Cvoid}

"Opaque type that represents a virtual memory mapping"
const CPLVirtualMem = Cvoid

"Callback triggered when a still unmapped page of virtual memory is accessed"
const CPLVirtualMemCachePageCbk = Ptr{Cvoid}

"Callback triggered when a dirty mapped page is going to be freed"
const CPLVirtualMemUnCachePageCbk = Ptr{Cvoid}

"Callback triggered when a virtual memory mapping is destroyed"
const CPLVirtualMemFreeUserData = Ptr{Cvoid}

"Access mode of a virtual memory mapping"
@cenum CPLVirtualMemAccessMode::UInt32 begin
    VIRTUALMEM_READONLY = 0
    VIRTUALMEM_READONLY_ENFORCED = 1
    VIRTUALMEM_READWRITE = 2
end

# Skipping MacroDefinition: VSI_ISLNK ( x ) ( 0 )
# Skipping MacroDefinition: VSI_ISREG ( x ) ( ( x ) & S_IFREG )
# Skipping MacroDefinition: VSI_ISDIR ( x ) ( ( x ) & S_IFDIR )
# Skipping MacroDefinition: VSI_ISCHR ( x ) ( ( x ) & S_IFCHR )
# Skipping MacroDefinition: VSI_ISBLK ( x ) ( 0 )

"Flag provided to VSIStatExL() to test if the file exists"
const VSI_STAT_EXISTS_FLAG = 0x01

"Flag provided to VSIStatExL() to query the nature (file/dir) of the file"
const VSI_STAT_NATURE_FLAG = 0x02

"Flag provided to VSIStatExL() to query the file size"
const VSI_STAT_SIZE_FLAG = 0x04

"Flag provided to VSIStatExL() to issue a VSIError in case of failure"
const VSI_STAT_SET_ERROR_FLAG = 0x08

# Skipping MacroDefinition: VSI_MALLOC_ALIGNED_AUTO_VERBOSE ( size ) VSIMallocAlignedAutoVerbose ( size , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_MALLOC_VERBOSE ( size ) VSIMallocVerbose ( size , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_MALLOC2_VERBOSE ( nSize1 , nSize2 ) VSIMalloc2Verbose ( nSize1 , nSize2 , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_MALLOC3_VERBOSE ( nSize1 , nSize2 , nSize3 ) VSIMalloc3Verbose ( nSize1 , nSize2 , nSize3 , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_CALLOC_VERBOSE ( nCount , nSize ) VSICallocVerbose ( nCount , nSize , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_REALLOC_VERBOSE ( pOldPtr , nNewSize ) VSIReallocVerbose ( pOldPtr , nNewSize , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSI_STRDUP_VERBOSE ( pszStr ) VSIStrdupVerbose ( pszStr , __FILE__ , __LINE__ )
# Skipping MacroDefinition: VSIDebug4 ( f , a1 , a2 , a3 , a4 ) { }
# Skipping MacroDefinition: VSIDebug3 ( f , a1 , a2 , a3 ) { }
# Skipping MacroDefinition: VSIDebug2 ( f , a1 , a2 ) { }
# Skipping MacroDefinition: VSIDebug1 ( f , a1 ) { }

const VSIStatBuf = Cvoid

"Type for a file offset"
const vsi_l_offset = GUIntBig

"Opaque type for a FILE that implements the VSIVirtualHandle API"
const VSILFILE = Cint

"Range status"
@cenum VSIRangeStatus::UInt32 begin
    VSI_RANGE_STATUS_UNKNOWN = 0
    VSI_RANGE_STATUS_DATA = 1
    VSI_RANGE_STATUS_HOLE = 2
end

"Type for VSIStatL()"
const VSIStatBufL = Cvoid

"Opaque type for a directory iterator"
const VSIDIR = Cvoid

"Directory entry"
struct VSIDIREntry
    pszName::Cstring
    nMode::Cint
    nSize::vsi_l_offset
    nMTime::GIntBig
    bModeKnown::UInt8
    bSizeKnown::UInt8
    bMTimeKnown::UInt8
    papszExtra::Ptr{Cstring}
end

# Skipping Typedef: CXType_FunctionProto size_t

"Return information about a handle"
const VSIFilesystemPluginStatCallback = Ptr{Cvoid}

"Remove handle by name"
const VSIFilesystemPluginUnlinkCallback = Ptr{Cvoid}

"Rename handle"
const VSIFilesystemPluginRenameCallback = Ptr{Cvoid}

"Create Directory"
const VSIFilesystemPluginMkdirCallback = Ptr{Cvoid}

"Delete Directory"
const VSIFilesystemPluginRmdirCallback = Ptr{Cvoid}

"List directory content"
const VSIFilesystemPluginReadDirCallback = Ptr{Cvoid}

"Open a handle"
const VSIFilesystemPluginOpenCallback = Ptr{Cvoid}

"Return current position in handle"
const VSIFilesystemPluginTellCallback = Ptr{Cvoid}

"Seek to position in handle"
const VSIFilesystemPluginSeekCallback = Ptr{Cvoid}

"Read data from current position, returns the number of blocks correctly read"
const VSIFilesystemPluginReadCallback = Ptr{Cvoid}

"Read from multiple offsets"
const VSIFilesystemPluginReadMultiRangeCallback = Ptr{Cvoid}

"Get empty ranges"
const VSIFilesystemPluginGetRangeStatusCallback = Ptr{Cvoid}

"Has end of file been reached"
const VSIFilesystemPluginEofCallback = Ptr{Cvoid}

"Write bytes at current offset"
const VSIFilesystemPluginWriteCallback = Ptr{Cvoid}

"Sync written bytes"
const VSIFilesystemPluginFlushCallback = Ptr{Cvoid}

"Truncate handle"
const VSIFilesystemPluginTruncateCallback = Ptr{Cvoid}

"Close file handle"
const VSIFilesystemPluginCloseCallback = Ptr{Cvoid}

struct VSIFilesystemPluginCallbacksStruct
    pUserData::Ptr{Cvoid}
    stat::VSIFilesystemPluginStatCallback
    unlink::VSIFilesystemPluginUnlinkCallback
    rename::VSIFilesystemPluginRenameCallback
    mkdir::VSIFilesystemPluginMkdirCallback
    rmdir::VSIFilesystemPluginRmdirCallback
    read_dir::VSIFilesystemPluginReadDirCallback
    open::VSIFilesystemPluginOpenCallback
    tell::VSIFilesystemPluginTellCallback
    seek::VSIFilesystemPluginSeekCallback
    read::VSIFilesystemPluginReadCallback
    read_multi_range::VSIFilesystemPluginReadMultiRangeCallback
    get_range_status::VSIFilesystemPluginGetRangeStatusCallback
    eof::VSIFilesystemPluginEofCallback
    write::VSIFilesystemPluginWriteCallback
    flush::VSIFilesystemPluginFlushCallback
    truncate::VSIFilesystemPluginTruncateCallback
    close::VSIFilesystemPluginCloseCallback
end

const RASTERIO_EXTRA_ARG_CURRENT_VERSION = 1

# Skipping MacroDefinition: INIT_RASTERIO_EXTRA_ARG ( s ) do { ( s ) . nVersion = RASTERIO_EXTRA_ARG_CURRENT_VERSION ; ( s ) . eResampleAlg = GRIORA_NearestNeighbour ; ( s ) . pfnProgress = CPL_NULLPTR ; ( s ) . pProgressData = CPL_NULLPTR ; ( s ) . bFloatingPointWindowValidity = FALSE ; } while ( 0 )

"Metadata item for dataset that indicates the spatial interpretation of a pixel"
const GDALMD_AREA_OR_POINT = "AREA_OR_POINT"

"Value for GDALMD_AREA_OR_POINT that indicates that a pixel represents an area"
const GDALMD_AOP_AREA = "Area"

"Value for GDALMD_AREA_OR_POINT that indicates that a pixel represents a point"
const GDALMD_AOP_POINT = "Point"

# Skipping MacroDefinition: CPLE_WrongFormat CPL_STATIC_CAST ( CPLErrorNum , 200 )

"Long name of the driver"
const GDAL_DMD_LONGNAME = "DMD_LONGNAME"

"URL (relative to http://gdal.org/) to the help page of the driver"
const GDAL_DMD_HELPTOPIC = "DMD_HELPTOPIC"

"MIME type handled by the driver"
const GDAL_DMD_MIMETYPE = "DMD_MIMETYPE"

"Extension handled by the driver"
const GDAL_DMD_EXTENSION = "DMD_EXTENSION"

"Connection prefix to provide as the file name of the open function"
const GDAL_DMD_CONNECTION_PREFIX = "DMD_CONNECTION_PREFIX"

"List of (space separated) extensions handled by the driver"
const GDAL_DMD_EXTENSIONS = "DMD_EXTENSIONS"

"XML snippet with creation options"
const GDAL_DMD_CREATIONOPTIONLIST = "DMD_CREATIONOPTIONLIST"

"XML snippet with open options"
const GDAL_DMD_OPENOPTIONLIST = "DMD_OPENOPTIONLIST"

"List of (space separated) raster data types support by the Create()/CreateCopy() API"
const GDAL_DMD_CREATIONDATATYPES = "DMD_CREATIONDATATYPES"

"List of (space separated) vector field types support by the CreateField() API"
const GDAL_DMD_CREATIONFIELDDATATYPES = "DMD_CREATIONFIELDDATATYPES"

"List of (space separated) vector field sub-types support by the CreateField() API"
const GDAL_DMD_CREATIONFIELDDATASUBTYPES = "DMD_CREATIONFIELDDATASUBTYPES"

"Capability set by a driver that exposes Subdatasets"
const GDAL_DMD_SUBDATASETS = "DMD_SUBDATASETS"

"Capability set by a driver that implements the Open() API"
const GDAL_DCAP_OPEN = "DCAP_OPEN"

"Capability set by a driver that implements the Create() API"
const GDAL_DCAP_CREATE = "DCAP_CREATE"

"Capability set by a driver that implements the CreateCopy() API"
const GDAL_DCAP_CREATECOPY = "DCAP_CREATECOPY"

"Capability set by a driver that can copy over subdatasets"
const GDAL_DCAP_SUBCREATECOPY = "DCAP_SUBCREATECOPY"

"Capability set by a driver that can read/create datasets through the VSI*L API"
const GDAL_DCAP_VIRTUALIO = "DCAP_VIRTUALIO"

"Capability set by a driver having raster capability"
const GDAL_DCAP_RASTER = "DCAP_RASTER"

"Capability set by a driver having vector capability"
const GDAL_DCAP_VECTOR = "DCAP_VECTOR"

"Capability set by a driver having geographical network model capability"
const GDAL_DCAP_GNM = "DCAP_GNM"

"Capability set by a driver that can create fields with NOT NULL constraint"
const GDAL_DCAP_NOTNULL_FIELDS = "DCAP_NOTNULL_FIELDS"

"Capability set by a driver that can create fields with DEFAULT values"
const GDAL_DCAP_DEFAULT_FIELDS = "DCAP_DEFAULT_FIELDS"

"Capability set by a driver that can create geometry fields with NOT NULL constraint"
const GDAL_DCAP_NOTNULL_GEOMFIELDS = "DCAP_NOTNULL_GEOMFIELDS"

"Capability set by a non-spatial driver having no support for geometries"
const GDAL_DCAP_NONSPATIAL = "DCAP_NONSPATIAL"

"Capability set by drivers which support feature styles"
const GDAL_DCAP_FEATURE_STYLES = "DCAP_FEATURE_STYLES"

"Open in read-only mode"
const GDAL_OF_READONLY = 0x00

"Open in update mode"
const GDAL_OF_UPDATE = 0x01

"Allow raster and vector drivers to be used"
const GDAL_OF_ALL = 0x00

"Allow raster drivers to be used"
const GDAL_OF_RASTER = 0x02

"Allow vector drivers to be used"
const GDAL_OF_VECTOR = 0x04

"Allow gnm drivers to be used"
const GDAL_OF_GNM = 0x08
const GDAL_OF_KIND_MASK = 0x1e

"Open in shared mode"
const GDAL_OF_SHARED = 0x20

"Emit error message in case of failed open"
const GDAL_OF_VERBOSE_ERROR = 0x40

"Open as internal dataset"
const GDAL_OF_INTERNAL = 0x80

"Let GDAL decide if a array-based or hashset-based storage strategy for cached blocks must be used"
const GDAL_OF_DEFAULT_BLOCK_ACCESS = 0

"Use a array-based storage strategy for cached blocks"
const GDAL_OF_ARRAY_BLOCK_ACCESS = 0x0100

"Use a hashset-based storage strategy for cached blocks"
const GDAL_OF_HASHSET_BLOCK_ACCESS = 0x0200
const GDAL_OF_RESERVED_1 = 0x0300
const GDAL_OF_BLOCK_ACCESS_MASK = 0x0300

"Name of driver metadata item for layer creation option list"
const GDAL_DS_LAYER_CREATIONOPTIONLIST = "DS_LAYER_CREATIONOPTIONLIST"

# Skipping MacroDefinition: SRCVAL ( papoSource , eSrcType , ii ) ( eSrcType == GDT_Byte ? CPL_REINTERPRET_CAST ( const GByte * , papoSource ) [ ii ] : ( eSrcType == GDT_Float32 ? CPL_REINTERPRET_CAST ( const float * , papoSource ) [ ii ] : ( eSrcType == GDT_Float64 ? CPL_REINTERPRET_CAST ( const double * , papoSource ) [ ii ] : ( eSrcType == GDT_Int32 ? CPL_REINTERPRET_CAST ( const GInt32 * , papoSource ) [ ii ] : ( eSrcType == GDT_UInt16 ? CPL_REINTERPRET_CAST ( const GUInt16 * , papoSource ) [ ii ] : ( eSrcType == GDT_Int16 ? CPL_REINTERPRET_CAST ( const GInt16 * , papoSource ) [ ii ] : ( eSrcType == GDT_UInt32 ? CPL_REINTERPRET_CAST ( const GUInt32 * , papoSource ) [ ii ] : ( eSrcType == GDT_CInt16 ? CPL_REINTERPRET_CAST ( const GInt16 * , papoSource ) [ ( ii ) * 2 ] : ( eSrcType == GDT_CInt32 ? CPL_REINTERPRET_CAST ( const GInt32 * , papoSource ) [ ( ii ) * 2 ] : ( eSrcType == GDT_CFloat32 ? CPL_REINTERPRET_CAST ( const float * , papoSource ) [ ( ii ) * 2 ] : ( eSrcType == GDT_CFloat64 ? CPL_REINTERPRET_CAST ( const double * , papoSource ) [ ( ii ) * 2 ] : 0 ) ) ) ) ) ) ) ) ) ) )

"Flag returned by GDALGetMaskFlags() to indicate that all pixels are valid"
const GMF_ALL_VALID = 0x01

"Flag returned by GDALGetMaskFlags() to indicate that the mask band is valid for all bands"
const GMF_PER_DATASET = 0x02

"Flag returned by GDALGetMaskFlags() to indicate that the mask band is an alpha band"
const GMF_ALPHA = 0x04

"Flag returned by GDALGetMaskFlags() to indicate that the mask band is computed from nodata values"
const GMF_NODATA = 0x08

"Flag returned by GDALGetDataCoverageStatus() when the driver does not implement GetDataCoverageStatus()"
const GDAL_DATA_COVERAGE_STATUS_UNIMPLEMENTED = 0x01

"Flag returned by GDALGetDataCoverageStatus() when there is (potentially) data in the queried window"
const GDAL_DATA_COVERAGE_STATUS_DATA = 0x02

"Flag returned by GDALGetDataCoverageStatus() when there is nodata in the queried window"
const GDAL_DATA_COVERAGE_STATUS_EMPTY = 0x04

@cenum GDALDataType::UInt32 begin
    GDT_Unknown = 0
    GDT_Byte = 1
    GDT_UInt16 = 2
    GDT_Int16 = 3
    GDT_UInt32 = 4
    GDT_Int32 = 5
    GDT_Float32 = 6
    GDT_Float64 = 7
    GDT_CInt16 = 8
    GDT_CInt32 = 9
    GDT_CFloat32 = 10
    GDT_CFloat64 = 11
    GDT_TypeCount = 12
end

"status of the asynchronous stream"
@cenum GDALAsyncStatusType::UInt32 begin
    GARIO_PENDING = 0
    GARIO_UPDATE = 1
    GARIO_ERROR = 2
    GARIO_COMPLETE = 3
    GARIO_TypeCount = 4
end

@cenum GDALAccess::UInt32 begin
    GA_ReadOnly = 0
    GA_Update = 1
end

@cenum GDALRWFlag::UInt32 begin
    GF_Read = 0
    GF_Write = 1
end

"RasterIO() resampling method"
@cenum GDALRIOResampleAlg::UInt32 begin
    GRIORA_NearestNeighbour = 0
    GRIORA_Bilinear = 1
    GRIORA_Cubic = 2
    GRIORA_CubicSpline = 3
    GRIORA_Lanczos = 4
    GRIORA_Average = 5
    GRIORA_Mode = 6
    GRIORA_Gauss = 7
end

struct GDALRasterIOExtraArg
    nVersion::Cint
    eResampleAlg::GDALRIOResampleAlg
    pfnProgress::GDALProgressFunc
    pProgressData::Ptr{Cvoid}
    bFloatingPointWindowValidity::Cint
    dfXOff::Cdouble
    dfYOff::Cdouble
    dfXSize::Cdouble
    dfYSize::Cdouble
end

@cenum GDALColorInterp::UInt32 begin
    GCI_Undefined = 0
    GCI_GrayIndex = 1
    GCI_PaletteIndex = 2
    GCI_RedBand = 3
    GCI_GreenBand = 4
    GCI_BlueBand = 5
    GCI_AlphaBand = 6
    GCI_HueBand = 7
    GCI_SaturationBand = 8
    GCI_LightnessBand = 9
    GCI_CyanBand = 10
    GCI_MagentaBand = 11
    GCI_YellowBand = 12
    GCI_BlackBand = 13
    GCI_YCbCr_YBand = 14
    GCI_YCbCr_CbBand = 15
    GCI_YCbCr_CrBand = 16
    GCI_Max = 16
end

@cenum GDALPaletteInterp::UInt32 begin
    GPI_Gray = 0
    GPI_RGB = 1
    GPI_CMYK = 2
    GPI_HLS = 3
end

"Opaque type used for the C bindings of the C++ GDALMajorObject class"
const GDALMajorObjectH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALDataset class"
const GDALDatasetH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALRasterBand class"
const GDALRasterBandH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALDriver class"
const GDALDriverH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALColorTable class"
const GDALColorTableH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALRasterAttributeTable class"
const GDALRasterAttributeTableH = Ptr{Cvoid}

"Opaque type used for the C bindings of the C++ GDALAsyncReader class"
const GDALAsyncReaderH = Ptr{Cvoid}

"Type to express pixel, line or band spacing"
const GSpacing = GIntBig

struct GDAL_GCP
    pszId::Cstring
    pszInfo::Cstring
    dfGCPPixel::Cdouble
    dfGCPLine::Cdouble
    dfGCPX::Cdouble
    dfGCPY::Cdouble
    dfGCPZ::Cdouble
end

"Type of functions to pass to GDALAddDerivedBandPixelFunc"
const GDALDerivedPixelFunc = Ptr{Cvoid}

struct GDALRPCInfo
    dfLINE_OFF::Cdouble
    dfSAMP_OFF::Cdouble
    dfLAT_OFF::Cdouble
    dfLONG_OFF::Cdouble
    dfHEIGHT_OFF::Cdouble
    dfLINE_SCALE::Cdouble
    dfSAMP_SCALE::Cdouble
    dfLAT_SCALE::Cdouble
    dfLONG_SCALE::Cdouble
    dfHEIGHT_SCALE::Cdouble
    adfLINE_NUM_COEFF::NTuple{20, Cdouble}
    adfLINE_DEN_COEFF::NTuple{20, Cdouble}
    adfSAMP_NUM_COEFF::NTuple{20, Cdouble}
    adfSAMP_DEN_COEFF::NTuple{20, Cdouble}
    dfMIN_LONG::Cdouble
    dfMIN_LAT::Cdouble
    dfMAX_LONG::Cdouble
    dfMAX_LAT::Cdouble
end

struct GDALColorEntry
    c1::Int16
    c2::Int16
    c3::Int16
    c4::Int16
end

"Field type of raster attribute table"
@cenum GDALRATFieldType::UInt32 begin
    GFT_Integer = 0
    GFT_Real = 1
    GFT_String = 2
end

"Field usage of raster attribute table"
@cenum GDALRATFieldUsage::UInt32 begin
    GFU_Generic = 0
    GFU_PixelCount = 1
    GFU_Name = 2
    GFU_Min = 3
    GFU_Max = 4
    GFU_MinMax = 5
    GFU_Red = 6
    GFU_Green = 7
    GFU_Blue = 8
    GFU_Alpha = 9
    GFU_RedMin = 10
    GFU_GreenMin = 11
    GFU_BlueMin = 12
    GFU_AlphaMin = 13
    GFU_RedMax = 14
    GFU_GreenMax = 15
    GFU_BlueMax = 16
    GFU_AlphaMax = 17
    GFU_MaxCount = 18
end

"RAT table type (thematic or athematic)"
@cenum GDALRATTableType::UInt32 begin
    GRTT_THEMATIC = 0
    GRTT_ATHEMATIC = 1
end

"! Enumeration to describe the tile organization"
@cenum GDALTileOrganization::UInt32 begin
    GTO_TIP = 0
    GTO_BIT = 1
    GTO_BSQ = 2
end

const GDAL_GTI2_SIGNATURE = "GTI2"
const GDALTransformerFunc = Ptr{Cvoid}

struct GDALTransformerInfo
    abySignature::NTuple{4, GByte}
    pszClassName::Cstring
    pfnTransform::GDALTransformerFunc
    pfnCleanup::Ptr{Cvoid}
    pfnSerialize::Ptr{Cvoid}
    pfnCreateSimilar::Ptr{Cvoid}
end

"Contour writer callback type"
const GDALContourWriter = Ptr{Cvoid}

"Contour generator opaque type"
const GDALContourGeneratorH = Ptr{Cvoid}

struct OGRContourWriterInfo
    hLayer::Ptr{Cvoid}
    adfGeoTransform::NTuple{6, Cdouble}
    nElevField::Cint
    nElevFieldMin::Cint
    nElevFieldMax::Cint
    nIDField::Cint
    nNextID::Cint
end

"Gridding Algorithms"
@cenum GDALGridAlgorithm::UInt32 begin
    GGA_InverseDistanceToAPower = 1
    GGA_MovingAverage = 2
    GGA_NearestNeighbor = 3
    GGA_MetricMinimum = 4
    GGA_MetricMaximum = 5
    GGA_MetricRange = 6
    GGA_MetricCount = 7
    GGA_MetricAverageDistance = 8
    GGA_MetricAverageDistancePts = 9
    GGA_Linear = 10
    GGA_InverseDistanceToAPowerNearestNeighbor = 11
end

struct GDALGridInverseDistanceToAPowerOptions
    dfPower::Cdouble
    dfSmoothing::Cdouble
    dfAnisotropyRatio::Cdouble
    dfAnisotropyAngle::Cdouble
    dfRadius1::Cdouble
    dfRadius2::Cdouble
    dfAngle::Cdouble
    nMaxPoints::GUInt32
    nMinPoints::GUInt32
    dfNoDataValue::Cdouble
end

struct GDALGridInverseDistanceToAPowerNearestNeighborOptions
    dfPower::Cdouble
    dfRadius::Cdouble
    dfSmoothing::Cdouble
    nMaxPoints::GUInt32
    nMinPoints::GUInt32
    dfNoDataValue::Cdouble
end

struct GDALGridMovingAverageOptions
    dfRadius1::Cdouble
    dfRadius2::Cdouble
    dfAngle::Cdouble
    nMinPoints::GUInt32
    dfNoDataValue::Cdouble
end

struct GDALGridNearestNeighborOptions
    dfRadius1::Cdouble
    dfRadius2::Cdouble
    dfAngle::Cdouble
    dfNoDataValue::Cdouble
end

struct GDALGridDataMetricsOptions
    dfRadius1::Cdouble
    dfRadius2::Cdouble
    dfAngle::Cdouble
    nMinPoints::GUInt32
    dfNoDataValue::Cdouble
end

struct GDALGridLinearOptions
    dfRadius::Cdouble
    dfNoDataValue::Cdouble
end

"Grid context opaque type"
const GDALGridContext = Cvoid

struct GDALTriFacet
    anVertexIdx::NTuple{3, Cint}
    anNeighborIdx::NTuple{3, Cint}
end

struct GDALTriBarycentricCoefficients
    dfMul1X::Cdouble
    dfMul1Y::Cdouble
    dfMul2X::Cdouble
    dfMul2Y::Cdouble
    dfCstX::Cdouble
    dfCstY::Cdouble
end

struct GDALTriangulation
    nFacets::Cint
    pasFacets::Ptr{GDALTriFacet}
    pasFacetCoefficients::Ptr{GDALTriBarycentricCoefficients}
end

@cenum GDALResampleAlg::UInt32 begin
    GRA_NearestNeighbour = 0
    GRA_Bilinear = 1
    GRA_Cubic = 2
    GRA_CubicSpline = 3
    GRA_Lanczos = 4
    GRA_Average = 5
    GRA_Mode = 6
    GRA_Max = 8
    GRA_Min = 9
    GRA_Med = 10
    GRA_Q1 = 11
    GRA_Q3 = 12
end

@cenum GWKAverageOrModeAlg::UInt32 begin
    GWKAOM_Average = 1
    GWKAOM_Fmode = 2
    GWKAOM_Imode = 3
    GWKAOM_Max = 4
    GWKAOM_Min = 5
    GWKAOM_Quant = 6
end

const GDALMaskFunc = Ptr{Cvoid}

struct GDALWarpOptions
    papszWarpOptions::Ptr{Cstring}
    dfWarpMemoryLimit::Cdouble
    eResampleAlg::GDALResampleAlg
    eWorkingDataType::GDALDataType
    hSrcDS::GDALDatasetH
    hDstDS::GDALDatasetH
    nBandCount::Cint
    panSrcBands::Ptr{Cint}
    panDstBands::Ptr{Cint}
    nSrcAlphaBand::Cint
    nDstAlphaBand::Cint
    padfSrcNoDataReal::Ptr{Cdouble}
    padfSrcNoDataImag::Ptr{Cdouble}
    padfDstNoDataReal::Ptr{Cdouble}
    padfDstNoDataImag::Ptr{Cdouble}
    pfnProgress::GDALProgressFunc
    pProgressArg::Ptr{Cvoid}
    pfnTransformer::GDALTransformerFunc
    pTransformerArg::Ptr{Cvoid}
    papfnSrcPerBandValidityMaskFunc::Ptr{GDALMaskFunc}
    papSrcPerBandValidityMaskFuncArg::Ptr{Ptr{Cvoid}}
    pfnSrcValidityMaskFunc::GDALMaskFunc
    pSrcValidityMaskFuncArg::Ptr{Cvoid}
    pfnSrcDensityMaskFunc::GDALMaskFunc
    pSrcDensityMaskFuncArg::Ptr{Cvoid}
    pfnDstDensityMaskFunc::GDALMaskFunc
    pDstDensityMaskFuncArg::Ptr{Cvoid}
    pfnDstValidityMaskFunc::GDALMaskFunc
    pDstValidityMaskFuncArg::Ptr{Cvoid}
    pfnPreWarpChunkProcessor::Ptr{Cvoid}
    pPreWarpProcessorArg::Ptr{Cvoid}
    pfnPostWarpChunkProcessor::Ptr{Cvoid}
    pPostWarpProcessorArg::Ptr{Cvoid}
    hCutline::Ptr{Cvoid}
    dfCutlineBlendDist::Cdouble
end

"Opaque type representing a GDALWarpOperation object"
const GDALWarpOperationH = Ptr{Cvoid}
const FilterFuncType = Ptr{Cvoid}
const FilterFunc4ValuesType = Ptr{Cvoid}

"Special value to indicate that nodata is not set"
const VRT_NODATA_UNSET = -1234.56

"Type for a function that returns the pixel data in a provided window"
const VRTImageReadFunc = Ptr{Cvoid}
const VRTAveragedSourceH = Ptr{Cvoid}
const VRTAverageFilteredSourceH = Ptr{Cvoid}
const VRTComplexSourceH = Ptr{Cvoid}
const VRTDerivedRasterBandH = Ptr{Cvoid}
const VRTDriverH = Ptr{Cvoid}
const VRTFilteredSourceH = Ptr{Cvoid}
const VRTFuncSourceH = Ptr{Cvoid}
const VRTKernelFilteredSourceH = Ptr{Cvoid}
const VRTRasterBandH = Ptr{Cvoid}
const VRTRawRasterBandH = Ptr{Cvoid}
const VRTSimpleSourceH = Ptr{Cvoid}
const VRTSourceH = Ptr{Cvoid}
const VRTWarpedDatasetH = Ptr{Cvoid}
const VRTWarpedRasterBandH = Ptr{Cvoid}

"Opaque type for a VRT dataset"
const VRTDatasetH = Ptr{Cvoid}

"Opaque type for a VRT sourced raster band"
const VRTSourcedRasterBandH = Ptr{Cvoid}
const GDALInfoOptions = Cvoid

"Opaque type"
const GDALInfoOptionsForBinary = Cvoid
const GDALTranslateOptions = Cvoid

"Opaque type"
const GDALTranslateOptionsForBinary = Cvoid
const GDALWarpAppOptions = Cvoid

"Opaque type"
const GDALWarpAppOptionsForBinary = Cvoid
const GDALVectorTranslateOptions = Cvoid

"Opaque type"
const GDALVectorTranslateOptionsForBinary = Cvoid
const GDALDEMProcessingOptions = Cvoid

"Opaque type"
const GDALDEMProcessingOptionsForBinary = Cvoid
const GDALNearblackOptions = Cvoid

"Opaque type"
const GDALNearblackOptionsForBinary = Cvoid
const GDALGridOptions = Cvoid

"Opaque type"
const GDALGridOptionsForBinary = Cvoid

"""
    GDALRasterizeOptions(char ** papszOptions,
                         int * pbAllTouched,
                         GDALBurnValueSrc * peBurnValueSource,
                         GDALRasterMergeAlg * peMergeAlg,
                         GDALRasterizeOptim * peOptim) -> CPLErr
"""
const GDALRasterizeOptions = Cvoid

"Opaque type"
const GDALRasterizeOptionsForBinary = Cvoid
const GDALBuildVRTOptions = Cvoid

"Opaque type"
const GDALBuildVRTOptionsForBinary = Cvoid

# Skipping MacroDefinition: OGR_FOR_EACH_FEATURE_BEGIN ( hFeat , hLayer ) { OGRFeatureH hFeat = CPL_NULLPTR ; OGR_L_ResetReading ( hLayer ) ; while ( true ) { if ( hFeat ) OGR_F_Destroy ( hFeat ) ; hFeat = OGR_L_GetNextFeature ( hLayer ) ; if ( ! hFeat ) break ;
# Skipping MacroDefinition: OGR_FOR_EACH_FEATURE_END ( hFeat ) } OGR_F_Destroy ( hFeat ) ; }

"Opaque type for a geometry"
const OGRGeometryH = Ptr{Cvoid}

"Opaque type for a spatial reference system"
const OGRSpatialReferenceH = Ptr{Cvoid}

"Opaque type for a coordinate transformation object"
const OGRCoordinateTransformationH = Ptr{Cvoid}
const _CPLXMLNode = Cvoid

"Opaque type for a field definition (OGRFieldDefn)"
const OGRFieldDefnH = Ptr{Cvoid}

"Opaque type for a feature definition (OGRFeatureDefn)"
const OGRFeatureDefnH = Ptr{Cvoid}

"Opaque type for a feature (OGRFeature)"
const OGRFeatureH = Ptr{Cvoid}

"Opaque type for a style table (OGRStyleTable)"
const OGRStyleTableH = Ptr{Cvoid}
const OGRGeomFieldDefnHS = Cvoid

"Opaque type for a geometry field definition (OGRGeomFieldDefn)"
const OGRGeomFieldDefnH = Ptr{OGRGeomFieldDefnHS}

"Opaque type for a layer (OGRLayer)"
const OGRLayerH = Ptr{Cvoid}

"Opaque type for a OGR datasource (OGRDataSource)"
const OGRDataSourceH = Ptr{Cvoid}

"Opaque type for a OGR driver (OGRSFDriver)"
const OGRSFDriverH = Ptr{Cvoid}

"Style manager opaque type"
const OGRStyleMgrH = Ptr{Cvoid}

"Style tool opaque type"
const OGRStyleToolH = Ptr{Cvoid}

"Success"
const OGRERR_NONE = 0

"Not enough data to deserialize"
const OGRERR_NOT_ENOUGH_DATA = 1

"Not enough memory"
const OGRERR_NOT_ENOUGH_MEMORY = 2

"Unsupported geometry type"
const OGRERR_UNSUPPORTED_GEOMETRY_TYPE = 3

"Unsupported operation"
const OGRERR_UNSUPPORTED_OPERATION = 4

"Corrupt data"
const OGRERR_CORRUPT_DATA = 5

"Failure"
const OGRERR_FAILURE = 6

"Unsupported SRS"
const OGRERR_UNSUPPORTED_SRS = 7

"Invalid handle"
const OGRERR_INVALID_HANDLE = 8

"Non existing feature"
const OGRERR_NON_EXISTING_FEATURE = 9
const wkb25DBit = 0x80000000

# Skipping MacroDefinition: wkbFlatten ( x ) OGR_GT_Flatten ( ( OGRwkbGeometryType ) ( x ) )
# Skipping MacroDefinition: wkbHasZ ( x ) ( OGR_GT_HasZ ( x ) != 0 )
# Skipping MacroDefinition: wkbSetZ ( x ) OGR_GT_SetZ ( x )
# Skipping MacroDefinition: wkbHasM ( x ) ( OGR_GT_HasM ( x ) != 0 )
# Skipping MacroDefinition: wkbSetM ( x ) OGR_GT_SetM ( x )

const ogrZMarker = 0x21125711

# Skipping MacroDefinition: DB2_V72_FIX_BYTE_ORDER ( x ) ( ( ( ( x ) & 0x31 ) == ( x ) ) ? ( ( x ) & 0x1 ) : ( x ) )
# Skipping MacroDefinition: DB2_V72_UNFIX_BYTE_ORDER ( x ) CPL_STATIC_CAST ( unsigned char , OGRGeometry : : bGenerate_DB2_V72_BYTE_ORDER ? ( ( x ) | 0x30 ) : ( x ) )

"Alter field name"
const ALTER_NAME_FLAG = 0x01

"Alter field type"
const ALTER_TYPE_FLAG = 0x02

"Alter field width and precision"
const ALTER_WIDTH_PRECISION_FLAG = 0x04

"Alter field NOT NULL constraint"
const ALTER_NULLABLE_FLAG = 0x08

"Alter field DEFAULT value"
const ALTER_DEFAULT_FLAG = 0x10

"Alter all parameters of field definition"
const ALTER_ALL_FLAG = (((ALTER_NAME_FLAG | ALTER_TYPE_FLAG) | ALTER_WIDTH_PRECISION_FLAG) | ALTER_NULLABLE_FLAG) | ALTER_DEFAULT_FLAG

"Validate that fields respect not-null constraints"
const OGR_F_VAL_NULL = 0x00000001

"Validate that geometries respect geometry column type"
const OGR_F_VAL_GEOM_TYPE = 0x00000002

"Validate that (string) fields respect field width"
const OGR_F_VAL_WIDTH = 0x00000004

"Allow fields that are null when there's an associated default value"
const OGR_F_VAL_ALLOW_NULL_WHEN_DEFAULT = 0x00000008

"Allow geometry fields to have a different coordinate dimension that their geometry column type"
const OGR_F_VAL_ALLOW_DIFFERENT_GEOM_DIM = 0x00000010

# Skipping MacroDefinition: OGR_F_VAL_ALL ( 0x7FFFFFFF & ~ OGR_F_VAL_ALLOW_DIFFERENT_GEOM_DIM )

"Special value for a unset FID"
const OGRNullFID = -1

# Skipping MacroDefinition: OGRUnknownType static_cast < OGRFieldType > ( - 1 )

"Special value set in OGRField.Set.nMarker1, nMarker2 and nMarker3 for a unset field"
const OGRUnsetMarker = -21121

"Special value set in OGRField.Set.nMarker1, nMarker2 and nMarker3 for a null field"
const OGRNullMarker = -21122

"Layer capability for random read"
const OLCRandomRead = "RandomRead"

"Layer capability for sequential write"
const OLCSequentialWrite = "SequentialWrite"

"Layer capability for random write"
const OLCRandomWrite = "RandomWrite"

"Layer capability for fast spatial filter"
const OLCFastSpatialFilter = "FastSpatialFilter"

"Layer capability for fast feature count retrieval"
const OLCFastFeatureCount = "FastFeatureCount"

"Layer capability for fast extent retrieval"
const OLCFastGetExtent = "FastGetExtent"

"Layer capability for field creation"
const OLCCreateField = "CreateField"

"Layer capability for field deletion"
const OLCDeleteField = "DeleteField"

"Layer capability for field reordering"
const OLCReorderFields = "ReorderFields"

"Layer capability for field alteration"
const OLCAlterFieldDefn = "AlterFieldDefn"

"Layer capability for transactions"
const OLCTransactions = "Transactions"

"Layer capability for feature deletion"
const OLCDeleteFeature = "DeleteFeature"

"Layer capability for setting next feature index"
const OLCFastSetNextByIndex = "FastSetNextByIndex"

"Layer capability for strings returned with UTF-8 encoding"
const OLCStringsAsUTF8 = "StringsAsUTF8"

"Layer capability for field ignoring"
const OLCIgnoreFields = "IgnoreFields"

"Layer capability for geometry field creation"
const OLCCreateGeomField = "CreateGeomField"

"Layer capability for curve geometries support"
const OLCCurveGeometries = "CurveGeometries"

"Layer capability for measured geometries support"
const OLCMeasuredGeometries = "MeasuredGeometries"

"Dataset capability for layer creation"
const ODsCCreateLayer = "CreateLayer"

"Dataset capability for layer deletion"
const ODsCDeleteLayer = "DeleteLayer"

"Dataset capability for geometry field creation support"
const ODsCCreateGeomFieldAfterCreateLayer = "CreateGeomFieldAfterCreateLayer"

"Dataset capability for curve geometries support"
const ODsCCurveGeometries = "CurveGeometries"

"Dataset capability for dataset transcations"
const ODsCTransactions = "Transactions"

"Dataset capability for emulated dataset transactions"
const ODsCEmulatedTransactions = "EmulatedTransactions"

"Dataset capability for measured geometries support"
const ODsCMeasuredGeometries = "MeasuredGeometries"

"Dataset capability for GetNextFeature() returning features from random layers"
const ODsCRandomLayerRead = "RandomLayerRead"

"Dataset capability for supporting CreateFeature on layer in random order"
const ODsCRandomLayerWrite = "RandomLayerWrite "

"Driver capability for datasource creation"
const ODrCCreateDataSource = "CreateDataSource"

"Driver capability for datasource deletion"
const ODrCDeleteDataSource = "DeleteDataSource"

"Capability set to YES as metadata on a layer that has features with 64 bit identifiers"
const OLMD_FID64 = "OLMD_FID64"

# Skipping MacroDefinition: GDAL_CHECK_VERSION ( pszCallingComponentName ) GDALCheckVersion ( GDAL_VERSION_MAJOR , GDAL_VERSION_MINOR , pszCallingComponentName )

struct OGREnvelope
    MinX::Cdouble
    MaxX::Cdouble
    MinY::Cdouble
    MaxY::Cdouble
end

struct OGREnvelope3D
    MinX::Cdouble
    MaxX::Cdouble
    MinY::Cdouble
    MaxY::Cdouble
    MinZ::Cdouble
    MaxZ::Cdouble
end

"Simple container for a bounding region"
const OGRErr = Cint

"Type for a OGR boolean"
const OGRBoolean = Cint

"List of well known binary geometry types"
@cenum OGRwkbGeometryType::UInt32 begin
    wkbUnknown = 0
    wkbPoint = 1
    wkbLineString = 2
    wkbPolygon = 3
    wkbMultiPoint = 4
    wkbMultiLineString = 5
    wkbMultiPolygon = 6
    wkbGeometryCollection = 7
    wkbCircularString = 8
    wkbCompoundCurve = 9
    wkbCurvePolygon = 10
    wkbMultiCurve = 11
    wkbMultiSurface = 12
    wkbCurve = 13
    wkbSurface = 14
    wkbPolyhedralSurface = 15
    wkbTIN = 16
    wkbTriangle = 17
    wkbNone = 100
    wkbLinearRing = 101
    wkbCircularStringZ = 1008
    wkbCompoundCurveZ = 1009
    wkbCurvePolygonZ = 1010
    wkbMultiCurveZ = 1011
    wkbMultiSurfaceZ = 1012
    wkbCurveZ = 1013
    wkbSurfaceZ = 1014
    wkbPolyhedralSurfaceZ = 1015
    wkbTINZ = 1016
    wkbTriangleZ = 1017
    wkbPointM = 2001
    wkbLineStringM = 2002
    wkbPolygonM = 2003
    wkbMultiPointM = 2004
    wkbMultiLineStringM = 2005
    wkbMultiPolygonM = 2006
    wkbGeometryCollectionM = 2007
    wkbCircularStringM = 2008
    wkbCompoundCurveM = 2009
    wkbCurvePolygonM = 2010
    wkbMultiCurveM = 2011
    wkbMultiSurfaceM = 2012
    wkbCurveM = 2013
    wkbSurfaceM = 2014
    wkbPolyhedralSurfaceM = 2015
    wkbTINM = 2016
    wkbTriangleM = 2017
    wkbPointZM = 3001
    wkbLineStringZM = 3002
    wkbPolygonZM = 3003
    wkbMultiPointZM = 3004
    wkbMultiLineStringZM = 3005
    wkbMultiPolygonZM = 3006
    wkbGeometryCollectionZM = 3007
    wkbCircularStringZM = 3008
    wkbCompoundCurveZM = 3009
    wkbCurvePolygonZM = 3010
    wkbMultiCurveZM = 3011
    wkbMultiSurfaceZM = 3012
    wkbCurveZM = 3013
    wkbSurfaceZM = 3014
    wkbPolyhedralSurfaceZM = 3015
    wkbTINZM = 3016
    wkbTriangleZM = 3017
    wkbPoint25D = 2147483649
    wkbLineString25D = 2147483650
    wkbPolygon25D = 2147483651
    wkbMultiPoint25D = 2147483652
    wkbMultiLineString25D = 2147483653
    wkbMultiPolygon25D = 2147483654
    wkbGeometryCollection25D = 2147483655
end

"Output variants of WKB we support"
@cenum OGRwkbVariant::UInt32 begin
    wkbVariantOldOgc = 0
    wkbVariantIso = 1
    wkbVariantPostGIS1 = 2
end

"Enumeration to describe byte order"
@cenum OGRwkbByteOrder::UInt32 begin
    wkbXDR = 0
    wkbNDR = 1
end

"List of feature field types"
@cenum OGRFieldType::UInt32 begin
    OFTInteger = 0
    OFTIntegerList = 1
    OFTReal = 2
    OFTRealList = 3
    OFTString = 4
    OFTStringList = 5
    OFTWideString = 6
    OFTWideStringList = 7
    OFTBinary = 8
    OFTDate = 9
    OFTTime = 10
    OFTDateTime = 11
    OFTInteger64 = 12
    OFTInteger64List = 13
    OFTMaxType = 13
end

"List of field subtypes"
@cenum OGRFieldSubType::UInt32 begin
    OFSTNone = 0
    OFSTBoolean = 1
    OFSTInt16 = 2
    OFSTFloat32 = 3
    OFSTJSON = 4
    OFSTMaxSubType = 4
end

"Display justification for field values"
@cenum OGRJustification::UInt32 begin
    OJUndefined = 0
    OJLeft = 1
    OJRight = 2
end

struct ANONYMOUS1_IntegerList
    nCount::Cint
    paList::Ptr{Cint}
end

struct OGRField
    IntegerList::ANONYMOUS1_IntegerList
end

"OGRStyleTool derived class types (returned by GetType())"
@cenum ogr_style_tool_class_id::UInt32 begin
    OGRSTCNone = 0
    OGRSTCPen = 1
    OGRSTCBrush = 2
    OGRSTCSymbol = 3
    OGRSTCLabel = 4
    OGRSTCVector = 5
end

"OGRStyleTool derived class types (returned by GetType())"
const OGRSTClassId = ogr_style_tool_class_id

"List of units supported by OGRStyleTools"
@cenum ogr_style_tool_units_id::UInt32 begin
    OGRSTUGround = 0
    OGRSTUPixel = 1
    OGRSTUPoints = 2
    OGRSTUMM = 3
    OGRSTUCM = 4
    OGRSTUInches = 5
end

"List of units supported by OGRStyleTools"
const OGRSTUnitId = ogr_style_tool_units_id

"List of parameters for use with OGRStylePen"
@cenum ogr_style_tool_param_pen_id::UInt32 begin
    OGRSTPenColor = 0
    OGRSTPenWidth = 1
    OGRSTPenPattern = 2
    OGRSTPenId = 3
    OGRSTPenPerOffset = 4
    OGRSTPenCap = 5
    OGRSTPenJoin = 6
    OGRSTPenPriority = 7
    OGRSTPenLast = 8
end

"List of parameters for use with OGRStylePen"
const OGRSTPenParam = ogr_style_tool_param_pen_id

"List of parameters for use with OGRStyleBrush"
@cenum ogr_style_tool_param_brush_id::UInt32 begin
    OGRSTBrushFColor = 0
    OGRSTBrushBColor = 1
    OGRSTBrushId = 2
    OGRSTBrushAngle = 3
    OGRSTBrushSize = 4
    OGRSTBrushDx = 5
    OGRSTBrushDy = 6
    OGRSTBrushPriority = 7
    OGRSTBrushLast = 8
end

"List of parameters for use with OGRStyleBrush"
const OGRSTBrushParam = ogr_style_tool_param_brush_id

"List of parameters for use with OGRStyleSymbol"
@cenum ogr_style_tool_param_symbol_id::UInt32 begin
    OGRSTSymbolId = 0
    OGRSTSymbolAngle = 1
    OGRSTSymbolColor = 2
    OGRSTSymbolSize = 3
    OGRSTSymbolDx = 4
    OGRSTSymbolDy = 5
    OGRSTSymbolStep = 6
    OGRSTSymbolPerp = 7
    OGRSTSymbolOffset = 8
    OGRSTSymbolPriority = 9
    OGRSTSymbolFontName = 10
    OGRSTSymbolOColor = 11
    OGRSTSymbolLast = 12
end

"List of parameters for use with OGRStyleSymbol"
const OGRSTSymbolParam = ogr_style_tool_param_symbol_id

"List of parameters for use with OGRStyleLabel"
@cenum ogr_style_tool_param_label_id::UInt32 begin
    OGRSTLabelFontName = 0
    OGRSTLabelSize = 1
    OGRSTLabelTextString = 2
    OGRSTLabelAngle = 3
    OGRSTLabelFColor = 4
    OGRSTLabelBColor = 5
    OGRSTLabelPlacement = 6
    OGRSTLabelAnchor = 7
    OGRSTLabelDx = 8
    OGRSTLabelDy = 9
    OGRSTLabelPerp = 10
    OGRSTLabelBold = 11
    OGRSTLabelItalic = 12
    OGRSTLabelUnderline = 13
    OGRSTLabelPriority = 14
    OGRSTLabelStrikeout = 15
    OGRSTLabelStretch = 16
    OGRSTLabelAdjHor = 17
    OGRSTLabelAdjVert = 18
    OGRSTLabelHColor = 19
    OGRSTLabelOColor = 20
    OGRSTLabelLast = 21
end

"List of parameters for use with OGRStyleLabel"
const OGRSTLabelParam = ogr_style_tool_param_label_id

"WGS 84 geodetic (lat/long) WKT / EPSG:4326 with lat,long ordering"
const SRS_WKT_WGS84_LAT_LONG = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"

"Albers_Conic_Equal_Area projection"
const SRS_PT_ALBERS_CONIC_EQUAL_AREA = "Albers_Conic_Equal_Area"

"Azimuthal_Equidistant projection"
const SRS_PT_AZIMUTHAL_EQUIDISTANT = "Azimuthal_Equidistant"

"Cassini_Soldner projection"
const SRS_PT_CASSINI_SOLDNER = "Cassini_Soldner"

"Cylindrical_Equal_Area projection"
const SRS_PT_CYLINDRICAL_EQUAL_AREA = "Cylindrical_Equal_Area"

"Cylindrical_Equal_Area projection"
const SRS_PT_BONNE = "Bonne"

"Eckert_I projection"
const SRS_PT_ECKERT_I = "Eckert_I"

"Eckert_II projection"
const SRS_PT_ECKERT_II = "Eckert_II"

"Eckert_III projection"
const SRS_PT_ECKERT_III = "Eckert_III"

"Eckert_IV projection"
const SRS_PT_ECKERT_IV = "Eckert_IV"

"Eckert_V projection"
const SRS_PT_ECKERT_V = "Eckert_V"

"Eckert_VI projection"
const SRS_PT_ECKERT_VI = "Eckert_VI"

"Equidistant_Conic projection"
const SRS_PT_EQUIDISTANT_CONIC = "Equidistant_Conic"

"Equirectangular projection"
const SRS_PT_EQUIRECTANGULAR = "Equirectangular"

"Gall_Stereographic projection"
const SRS_PT_GALL_STEREOGRAPHIC = "Gall_Stereographic"

"Gauss_Schreiber_Transverse_Mercator projection"
const SRS_PT_GAUSSSCHREIBERTMERCATOR = "Gauss_Schreiber_Transverse_Mercator"

"Geostationary_Satellite projection"
const SRS_PT_GEOSTATIONARY_SATELLITE = "Geostationary_Satellite"

"Goode_Homolosine projection"
const SRS_PT_GOODE_HOMOLOSINE = "Goode_Homolosine"

"Interrupted_Goode_Homolosine projection"
const SRS_PT_IGH = "Interrupted_Goode_Homolosine"

"Gnomonic projection"
const SRS_PT_GNOMONIC = "Gnomonic"

"Hotine_Oblique_Mercator_Azimuth_Center projection"
const SRS_PT_HOTINE_OBLIQUE_MERCATOR_AZIMUTH_CENTER = "Hotine_Oblique_Mercator_Azimuth_Center"

"Hotine_Oblique_Mercator projection"
const SRS_PT_HOTINE_OBLIQUE_MERCATOR = "Hotine_Oblique_Mercator"

"Hotine_Oblique_Mercator_Two_Point_Natural_Origin projection"
const SRS_PT_HOTINE_OBLIQUE_MERCATOR_TWO_POINT_NATURAL_ORIGIN = "Hotine_Oblique_Mercator_Two_Point_Natural_Origin"

"Laborde_Oblique_Mercator projection"
const SRS_PT_LABORDE_OBLIQUE_MERCATOR = "Laborde_Oblique_Mercator"

"Lambert_Conformal_Conic_1SP projection"
const SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP = "Lambert_Conformal_Conic_1SP"

"Lambert_Conformal_Conic_2SP projection"
const SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP = "Lambert_Conformal_Conic_2SP"

"Lambert_Conformal_Conic_2SP_Belgium projection"
const SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP_BELGIUM = "Lambert_Conformal_Conic_2SP_Belgium"

"Lambert_Azimuthal_Equal_Area projection"
const SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA = "Lambert_Azimuthal_Equal_Area"

"Mercator_1SP projection"
const SRS_PT_MERCATOR_1SP = "Mercator_1SP"

"Mercator_2SP projection"
const SRS_PT_MERCATOR_2SP = "Mercator_2SP"

"Mercator_Auxiliary_Sphere is used used by ESRI to mean EPSG:3875"
const SRS_PT_MERCATOR_AUXILIARY_SPHERE = "Mercator_Auxiliary_Sphere"

"Miller_Cylindrical projection"
const SRS_PT_MILLER_CYLINDRICAL = "Miller_Cylindrical"

"Mollweide projection"
const SRS_PT_MOLLWEIDE = "Mollweide"

"New_Zealand_Map_Grid projection"
const SRS_PT_NEW_ZEALAND_MAP_GRID = "New_Zealand_Map_Grid"

"Oblique_Stereographic projection"
const SRS_PT_OBLIQUE_STEREOGRAPHIC = "Oblique_Stereographic"

"Orthographic projection"
const SRS_PT_ORTHOGRAPHIC = "Orthographic"

"Polar_Stereographic projection"
const SRS_PT_POLAR_STEREOGRAPHIC = "Polar_Stereographic"

"Polyconic projection"
const SRS_PT_POLYCONIC = "Polyconic"

"Robinson projection"
const SRS_PT_ROBINSON = "Robinson"

"Sinusoidal projection"
const SRS_PT_SINUSOIDAL = "Sinusoidal"

"Stereographic projection"
const SRS_PT_STEREOGRAPHIC = "Stereographic"

"Swiss_Oblique_Cylindrical projection"
const SRS_PT_SWISS_OBLIQUE_CYLINDRICAL = "Swiss_Oblique_Cylindrical"

"Transverse_Mercator projection"
const SRS_PT_TRANSVERSE_MERCATOR = "Transverse_Mercator"

"Transverse_Mercator_South_Orientated projection"
const SRS_PT_TRANSVERSE_MERCATOR_SOUTH_ORIENTED = "Transverse_Mercator_South_Orientated"

"Transverse_Mercator_MapInfo_21 projection"
const SRS_PT_TRANSVERSE_MERCATOR_MI_21 = "Transverse_Mercator_MapInfo_21"

"Transverse_Mercator_MapInfo_22 projection"
const SRS_PT_TRANSVERSE_MERCATOR_MI_22 = "Transverse_Mercator_MapInfo_22"

"Transverse_Mercator_MapInfo_23 projection"
const SRS_PT_TRANSVERSE_MERCATOR_MI_23 = "Transverse_Mercator_MapInfo_23"

"Transverse_Mercator_MapInfo_24 projection"
const SRS_PT_TRANSVERSE_MERCATOR_MI_24 = "Transverse_Mercator_MapInfo_24"

"Transverse_Mercator_MapInfo_25 projection"
const SRS_PT_TRANSVERSE_MERCATOR_MI_25 = "Transverse_Mercator_MapInfo_25"

"Tunisia_Mining_Grid projection"
const SRS_PT_TUNISIA_MINING_GRID = "Tunisia_Mining_Grid"

"Two_Point_Equidistant projection"
const SRS_PT_TWO_POINT_EQUIDISTANT = "Two_Point_Equidistant"

"VanDerGrinten projection"
const SRS_PT_VANDERGRINTEN = "VanDerGrinten"

"Krovak projection"
const SRS_PT_KROVAK = "Krovak"

"International_Map_of_the_World_Polyconic projection"
const SRS_PT_IMW_POLYCONIC = "International_Map_of_the_World_Polyconic"

"Wagner_I projection"
const SRS_PT_WAGNER_I = "Wagner_I"

"Wagner_II projection"
const SRS_PT_WAGNER_II = "Wagner_II"

"Wagner_III projection"
const SRS_PT_WAGNER_III = "Wagner_III"

"Wagner_IV projection"
const SRS_PT_WAGNER_IV = "Wagner_IV"

"Wagner_V projection"
const SRS_PT_WAGNER_V = "Wagner_V"

"Wagner_VI projection"
const SRS_PT_WAGNER_VI = "Wagner_VI"

"Wagner_VII projection"
const SRS_PT_WAGNER_VII = "Wagner_VII"

"Quadrilateralized_Spherical_Cube projection"
const SRS_PT_QSC = "Quadrilateralized_Spherical_Cube"

"Aitoff projection"
const SRS_PT_AITOFF = "Aitoff"

"Winkel_I projection"
const SRS_PT_WINKEL_I = "Winkel_I"

"Winkel_II projection"
const SRS_PT_WINKEL_II = "Winkel_II"

"Winkel_Tripel projection"
const SRS_PT_WINKEL_TRIPEL = "Winkel_Tripel"

"Craster_Parabolic projection"
const SRS_PT_CRASTER_PARABOLIC = "Craster_Parabolic"

"Loximuthal projection"
const SRS_PT_LOXIMUTHAL = "Loximuthal"

"Quartic_Authalic projection"
const SRS_PT_QUARTIC_AUTHALIC = "Quartic_Authalic"

"Spherical_Cross_Track_Height projection"
const SRS_PT_SCH = "Spherical_Cross_Track_Height"

"central_meridian projection parameter"
const SRS_PP_CENTRAL_MERIDIAN = "central_meridian"

"scale_factor projection parameter"
const SRS_PP_SCALE_FACTOR = "scale_factor"

"standard_parallel_1 projection parameter"
const SRS_PP_STANDARD_PARALLEL_1 = "standard_parallel_1"

"standard_parallel_2 projection parameter"
const SRS_PP_STANDARD_PARALLEL_2 = "standard_parallel_2"

"pseudo_standard_parallel_1 projection parameter"
const SRS_PP_PSEUDO_STD_PARALLEL_1 = "pseudo_standard_parallel_1"

"longitude_of_center projection parameter"
const SRS_PP_LONGITUDE_OF_CENTER = "longitude_of_center"

"latitude_of_center projection parameter"
const SRS_PP_LATITUDE_OF_CENTER = "latitude_of_center"

"longitude_of_origin projection parameter"
const SRS_PP_LONGITUDE_OF_ORIGIN = "longitude_of_origin"

"latitude_of_origin projection parameter"
const SRS_PP_LATITUDE_OF_ORIGIN = "latitude_of_origin"

"false_easting projection parameter"
const SRS_PP_FALSE_EASTING = "false_easting"

"false_northing projection parameter"
const SRS_PP_FALSE_NORTHING = "false_northing"

"azimuth projection parameter"
const SRS_PP_AZIMUTH = "azimuth"

"longitude_of_point_1 projection parameter"
const SRS_PP_LONGITUDE_OF_POINT_1 = "longitude_of_point_1"

"latitude_of_point_1 projection parameter"
const SRS_PP_LATITUDE_OF_POINT_1 = "latitude_of_point_1"

"longitude_of_point_2 projection parameter"
const SRS_PP_LONGITUDE_OF_POINT_2 = "longitude_of_point_2"

"latitude_of_point_2 projection parameter"
const SRS_PP_LATITUDE_OF_POINT_2 = "latitude_of_point_2"

"longitude_of_point_3 projection parameter"
const SRS_PP_LONGITUDE_OF_POINT_3 = "longitude_of_point_3"

"latitude_of_point_3 projection parameter"
const SRS_PP_LATITUDE_OF_POINT_3 = "latitude_of_point_3"

"rectified_grid_angle projection parameter"
const SRS_PP_RECTIFIED_GRID_ANGLE = "rectified_grid_angle"

"landsat_number projection parameter"
const SRS_PP_LANDSAT_NUMBER = "landsat_number"

"path_number projection parameter"
const SRS_PP_PATH_NUMBER = "path_number"

"perspective_point_height projection parameter"
const SRS_PP_PERSPECTIVE_POINT_HEIGHT = "perspective_point_height"

"satellite_height projection parameter"
const SRS_PP_SATELLITE_HEIGHT = "satellite_height"

"fipszone projection parameter"
const SRS_PP_FIPSZONE = "fipszone"

"zone projection parameter"
const SRS_PP_ZONE = "zone"

"Latitude_Of_1st_Point projection parameter"
const SRS_PP_LATITUDE_OF_1ST_POINT = "Latitude_Of_1st_Point"

"Longitude_Of_1st_Point projection parameter"
const SRS_PP_LONGITUDE_OF_1ST_POINT = "Longitude_Of_1st_Point"

"Latitude_Of_2nd_Point projection parameter"
const SRS_PP_LATITUDE_OF_2ND_POINT = "Latitude_Of_2nd_Point"

"Longitude_Of_2nd_Point projection parameter"
const SRS_PP_LONGITUDE_OF_2ND_POINT = "Longitude_Of_2nd_Point"

"peg_point_latitude projection parameter"
const SRS_PP_PEG_POINT_LATITUDE = "peg_point_latitude"

"peg_point_longitude projection parameter"
const SRS_PP_PEG_POINT_LONGITUDE = "peg_point_longitude"

"peg_point_heading projection parameter"
const SRS_PP_PEG_POINT_HEADING = "peg_point_heading"

"peg_point_height projection parameter"
const SRS_PP_PEG_POINT_HEIGHT = "peg_point_height"

"Linear unit Meter"
const SRS_UL_METER = "Meter"

"Linear unit Foot (International)"
const SRS_UL_FOOT = "Foot (International)"

"Linear unit Foot (International) conversion factor to meter"
const SRS_UL_FOOT_CONV = "0.3048"

"Linear unit Foot"
const SRS_UL_US_FOOT = "Foot_US"

"Linear unit Foot conversion factor to meter"
const SRS_UL_US_FOOT_CONV = "0.3048006096012192"

"Linear unit Nautical Mile"
const SRS_UL_NAUTICAL_MILE = "Nautical Mile"

"Linear unit Nautical Mile conversion factor to meter"
const SRS_UL_NAUTICAL_MILE_CONV = "1852.0"

"Linear unit Link"
const SRS_UL_LINK = "Link"

"Linear unit Link conversion factor to meter"
const SRS_UL_LINK_CONV = "0.20116684023368047"

"Linear unit Chain"
const SRS_UL_CHAIN = "Chain"

"Linear unit Chain conversion factor to meter"
const SRS_UL_CHAIN_CONV = "20.116684023368047"

"Linear unit Rod"
const SRS_UL_ROD = "Rod"

"Linear unit Rod conversion factor to meter"
const SRS_UL_ROD_CONV = "5.02921005842012"

"Linear unit Link_Clarke"
const SRS_UL_LINK_Clarke = "Link_Clarke"

"Linear unit Link_Clarke conversion factor to meter"
const SRS_UL_LINK_Clarke_CONV = "0.2011661949"

"Linear unit Kilometer"
const SRS_UL_KILOMETER = "Kilometer"

"Linear unit Kilometer conversion factor to meter"
const SRS_UL_KILOMETER_CONV = "1000."

"Linear unit Decimeter"
const SRS_UL_DECIMETER = "Decimeter"

"Linear unit Decimeter conversion factor to meter"
const SRS_UL_DECIMETER_CONV = "0.1"

"Linear unit Decimeter"
const SRS_UL_CENTIMETER = "Centimeter"

"Linear unit Decimeter conversion factor to meter"
const SRS_UL_CENTIMETER_CONV = "0.01"

"Linear unit Millimeter"
const SRS_UL_MILLIMETER = "Millimeter"

"Linear unit Millimeter conversion factor to meter"
const SRS_UL_MILLIMETER_CONV = "0.001"

"Linear unit Nautical_Mile_International"
const SRS_UL_INTL_NAUT_MILE = "Nautical_Mile_International"

"Linear unit Nautical_Mile_International conversion factor to meter"
const SRS_UL_INTL_NAUT_MILE_CONV = "1852.0"

"Linear unit Inch_International"
const SRS_UL_INTL_INCH = "Inch_International"

"Linear unit Inch_International conversion factor to meter"
const SRS_UL_INTL_INCH_CONV = "0.0254"

"Linear unit Foot_International"
const SRS_UL_INTL_FOOT = "Foot_International"

"Linear unit Foot_International conversion factor to meter"
const SRS_UL_INTL_FOOT_CONV = "0.3048"

"Linear unit Yard_International"
const SRS_UL_INTL_YARD = "Yard_International"

"Linear unit Yard_International conversion factor to meter"
const SRS_UL_INTL_YARD_CONV = "0.9144"

"Linear unit Statute_Mile_International"
const SRS_UL_INTL_STAT_MILE = "Statute_Mile_International"

"Linear unit Statute_Mile_Internationalconversion factor to meter"
const SRS_UL_INTL_STAT_MILE_CONV = "1609.344"

"Linear unit Fathom_International"
const SRS_UL_INTL_FATHOM = "Fathom_International"

"Linear unit Fathom_International conversion factor to meter"
const SRS_UL_INTL_FATHOM_CONV = "1.8288"

"Linear unit Chain_International"
const SRS_UL_INTL_CHAIN = "Chain_International"

"Linear unit Chain_International conversion factor to meter"
const SRS_UL_INTL_CHAIN_CONV = "20.1168"

"Linear unit Link_International"
const SRS_UL_INTL_LINK = "Link_International"

"Linear unit Link_International conversion factor to meter"
const SRS_UL_INTL_LINK_CONV = "0.201168"

"Linear unit Inch_US_Surveyor"
const SRS_UL_US_INCH = "Inch_US_Surveyor"

"Linear unit Inch_US_Surveyor conversion factor to meter"
const SRS_UL_US_INCH_CONV = "0.025400050800101603"

"Linear unit Yard_US_Surveyor"
const SRS_UL_US_YARD = "Yard_US_Surveyor"

"Linear unit Yard_US_Surveyor conversion factor to meter"
const SRS_UL_US_YARD_CONV = "0.914401828803658"

"Linear unit Chain_US_Surveyor"
const SRS_UL_US_CHAIN = "Chain_US_Surveyor"

"Linear unit Chain_US_Surveyor conversion factor to meter"
const SRS_UL_US_CHAIN_CONV = "20.11684023368047"

"Linear unit Statute_Mile_US_Surveyor"
const SRS_UL_US_STAT_MILE = "Statute_Mile_US_Surveyor"

"Linear unit Statute_Mile_US_Surveyor conversion factor to meter"
const SRS_UL_US_STAT_MILE_CONV = "1609.347218694437"

"Linear unit Yard_Indian"
const SRS_UL_INDIAN_YARD = "Yard_Indian"

"Linear unit Yard_Indian conversion factor to meter"
const SRS_UL_INDIAN_YARD_CONV = "0.91439523"

"Linear unit Foot_Indian"
const SRS_UL_INDIAN_FOOT = "Foot_Indian"

"Linear unit Foot_Indian conversion factor to meter"
const SRS_UL_INDIAN_FOOT_CONV = "0.30479841"

"Linear unit Chain_Indian"
const SRS_UL_INDIAN_CHAIN = "Chain_Indian"

"Linear unit Chain_Indian conversion factor to meter"
const SRS_UL_INDIAN_CHAIN_CONV = "20.11669506"

"Angular unit degree"
const SRS_UA_DEGREE = "degree"

"Angular unit degree conversion factor to radians"
const SRS_UA_DEGREE_CONV = "0.0174532925199433"

"Angular unit radian"
const SRS_UA_RADIAN = "radian"

"Prime meridian Greenwich"
const SRS_PM_GREENWICH = "Greenwich"

"North_American_Datum_1927 datum name"
const SRS_DN_NAD27 = "North_American_Datum_1927"

"North_American_Datum_1983 datum name"
const SRS_DN_NAD83 = "North_American_Datum_1983"

"WGS_1972 datum name"
const SRS_DN_WGS72 = "WGS_1972"

"WGS_1984 datum name"
const SRS_DN_WGS84 = "WGS_1984"

"Semi-major axis of the WGS84 ellipsoid"
const SRS_WGS84_SEMIMAJOR = 6.378137e6

"Inverse flattening of the WGS84 ellipsoid"
const SRS_WGS84_INVFLATTENING = 298.257223563

"Axis orientations (corresponds to CS_AxisOrientationEnum)"
@cenum OGRAxisOrientation::UInt32 begin
    OAO_Other = 0
    OAO_North = 1
    OAO_South = 2
    OAO_East = 3
    OAO_West = 4
    OAO_Up = 5
    OAO_Down = 6
end

"Data axis to CRS axis mapping strategy"
@cenum OSRAxisMappingStrategy::UInt32 begin
    OAMS_TRADITIONAL_GIS_ORDER = 0
    OAMS_AUTHORITY_COMPLIANT = 1
    OAMS_CUSTOM = 2
end

"Type of Coordinate Reference System (CRS)"
@cenum OSRCRSType::UInt32 begin
    OSR_CRS_TYPE_GEOGRAPHIC_2D = 0
    OSR_CRS_TYPE_GEOGRAPHIC_3D = 1
    OSR_CRS_TYPE_GEOCENTRIC = 2
    OSR_CRS_TYPE_PROJECTED = 3
    OSR_CRS_TYPE_VERTICAL = 4
    OSR_CRS_TYPE_COMPOUND = 5
    OSR_CRS_TYPE_OTHER = 6
end

struct OSRCRSInfo
    pszAuthName::Cstring
    pszCode::Cstring
    pszName::Cstring
    eType::OSRCRSType
    bDeprecated::Cint
    bBboxValid::Cint
    dfWestLongitudeDeg::Cdouble
    dfSouthLatitudeDeg::Cdouble
    dfEastLongitudeDeg::Cdouble
    dfNorthLatitudeDeg::Cdouble
    pszAreaName::Cstring
    pszProjectionMethod::Cstring
end

"Structure to describe optional parameters to OSRGetCRSInfoListFromDatabase()"
const OSRCRSListParameters = Cvoid

"""
    OGRCoordinateTransformationOptions() ->

Constructs a new OGRCoordinateTransformationOptions.
"""
const OGRCoordinateTransformationOptions = Cvoid

"Coordinate transformation options"
const OGRCoordinateTransformationOptionsH = Ptr{OGRCoordinateTransformationOptions}


text:
## Jacobi Polynomials
@registerN Jacobi AbstractCCOP2 α β
export Jacobi

"""
    Jacobi{α,  β, T}

Implements the [Jacobi](https://en.wikipedia.org/wiki/Jacobi_polynomials) polynomials. These have weight function `w(x) = (1-x)^α ⋅ (1+x)^β` over the domain `[-1,1]`. Many orthogonal polynomial types are special cases. The parameters are  specified to the constructors:

```jldoctest
julia> using Polynomials, SpecialPolynomials

julia> p = Jacobi{-1/2, -1/2}([0,0,1])
typename(Jacobi){-0.5,-0.5}(1⋅Jᵅᵝ₂(x))

julia> convert(Polynomial, p)
Polynomials.Polynomial(-0.375 + 0.75*x^2)

julia> monic(p) = (q=convert(Polynomial,p); q/q[end])
monic (generic function with 1 method)

julia> monic(p) ≈  monic(basis(Chebyshev, 2))
true

```

"""
Jacobi

basis_symbol(::Type{<:Jacobi{α,β}}) where {α,β} = "Jᵅᵝ"
Polynomials.domain(::Type{<:Jacobi{α,β}}) where {α,β} =
    Polynomials.Interval{β >= 0 ? Open : Closed,α >= 0 ? Open : Closed}(-1, 1)
abcde(::Type{<:Jacobi{α,β}}) where {α,β} =
    NamedTuple{(:a, :b, :c, :d, :e)}((-1, 0, 1, -(α + β + 2), β - α))

k0(P::Type{<:Jacobi}) = one(eltype(P))
function k1k0(P::Type{<:Jacobi{α,β}}, n::Int) where {α,β}
    n == -1 && return one(eltype(P)) / 1
    γ = 2n + α + β
    val = one(eltype(P))
    if n == 0
        val *= (α + β) / 2 + 1
    else
        num = (γ + 1) * (γ + 2)
        den = 2 * (n + 1) * (γ - n + 1)
        iszero(den) && return k1k0(P, Val(n))
        val *= num / den
    end
    val
end

#kn =  1/2^n ⋅ choose(2n+α+β, n) = (2n+α+β)_n / (2^b  n!)
function leading_term(P::Type{<:Jacobi{α,β}}, n::Int) where {α,β}
    a = α + β + n + 1
    nn = n
    tot = one(eltype(P)) / 1
    for i in 0:(n - 1)
        tot *= a / (2 * nn)
        a += 1
        nn -= 1
    end
    tot
end

weight_function(::Type{<:Jacobi{α,β}}) where {α,β} = x -> (1 - x)^α * (1 + x)^β
generating_function(::Type{<:Jacobi{α,β}}) where {α,β} =
    (t, x) -> begin
        R = sqrt(1 - 2x * t + t^2)
        2^(α + β) * 1 / R * (1 - t + R)^(-α) * (1 + t + R)^(-β)
    end

"""
    jacobi_eval(α, β, n, z)

Evaluate the nth basis element of `Pᵅᵝ` at `z` using

`Pₙᵅᵝ(z) = 2⁻ⁿ∑ (α+n, k) × (β+n, n-k) ⋅ (z+1)ᵏ ⋅ (z-1)ⁿ⁻ᵏ`

This alternate evaluation is  useful when `α` or `β ≤ -1` (and consequently the polynomials are not orthogonal)
"""
function jacobi_eval(α, β, n, z)
    T = eltype(z / 2)
    tot = zero(T)
    for k in 0:n
        tot +=
            generalized_binomial′(α + n, k) *
            generalized_binomial′(β + n, n - k) *
            ((z + 1) / 2)^k *
            ((z - 1) / 2)^(n - k)
    end
    tot
end

# gauss_nodes_weights(p::Type{P}, n) where {α, β, P <: Jacobi{α, β}} =
#     FastGaussQuadrature.gaussjacobi(n, α, β)

function classical_hypergeometric(::Type{<:Jacobi{α,β}}, n, x) where {α,β}
    (α ≤ -1 || β ≤ -1) && throw(ArgumentError("α and β must be > -1"))

    as = (-n, n + α + β + 1)
    bs = (α + 1,)

    Pochhammer_factorial(α + 1, n) * pFq(as, bs, (1 - x) / 2)
end

function norm2(::Type{<:Jacobi{α,β}}, n) where {α,β}
    α > -1 && β > -1 || throw(ArgumentError("α, β > -1 is necessary"))
    2^(α + β + 1) / (2n + α + β + 1) * (Γ(n + α + 1) * Γ(n + β + 1)) /
    (Γ(n + α + β + 1) * Γ(n + 1))
end
function ω₁₀(::Type{<:Jacobi{α,β}}, n) where {α,β}
    val = Γ(n + 1 + α + 1) / Γ(n + α + 1)
    val *= Γ(n + 1 + β + 1) / Γ(n + β + 1)
    val *= Γ(n + α + β + 1) / Γ(n + 1 + α + β + 1)
    val *= Γ(n + 1) / Γ(n + 1 + 1)
    val *= (2n + α + β + 1) / (2(n + 1) + α + β + 1)
    sqrt(val)
end

# overrides
B̃n(P::Type{<:Jacobi{α,β}}, ::Val{0}) where {α,β} =
    iszero(α + β) ? (α - β) * one(eltype(P)) / 2 : (α - β) * one(eltype(P)) / (2(α + β + 2))
C̃n(P::Type{<:Jacobi{α,β}}, ::Val{1}) where {α,β} =
    -one(eltype(P)) * ((α - β)^2 - (α + β + 2)^2) / ((α + β + 2)^2 * (α + β + 3))

b̂̃n(P::Type{<:Jacobi{α,β}}, ::Val{0}) where {α,β} = one(eltype(P)) * NaN
ĉ̃n(P::Type{<:Jacobi}, ::Val{0}) = zero(eltype(P))
ĉ̃n(P::Type{<:Jacobi{α,β}}, ::Val{1}) where {α,β} =
    one(eltype(P)) * ((α - β)^2 - (α + β + 2)^2) /
    ((α + β + 1) * (α + β + 2)^2 * (α + β + 3))

##
## --------------------------------------------------
##

@registerN MonicJacobi AbstractCCOP2 α β
export MonicJacobi
ϟ(::Type{<:MonicJacobi{α,β}}) where {α,β} = Jacobi{α,β}
ϟ(::Type{<:MonicJacobi{α,β,T}}) where {α,β,T} = Jacobi{α,β,T}

@register_monic(MonicJacobi)

@registerN OrthonormalJacobi AbstractCCOP2 α β
export OrthonormalJacobi
ϟ(::Type{<:OrthonormalJacobi{α,β}}) where {α,β} = Jacobi{α,β}
ϟ(::Type{<:OrthonormalJacobi{α,β,T}}) where {α,β,T} = Jacobi{α,β,T}

@register_orthonormal(OrthonormalJacobi)


text:
"""
Entropy term -TS, where S is the electronic entropy.
Turns the energy E into the free energy F=E-TS.
This is in particular useful because the free energy,
not the energy, is minimized at self-consistency.
"""
struct Entropy end
(::Entropy)(basis) = TermEntropy(basis)

struct TermEntropy <: Term
    basis::PlaneWaveBasis
end

function ene_ops(term::TermEntropy, ψ, occ; kwargs...)
    basis = term.basis
    T = eltype(basis)
    ops = [NoopOperator(term.basis, kpoint) for kpoint in basis.kpoints]

    smearing = basis.model.smearing
    temperature = basis.model.temperature

    temperature == 0 && return (E=zero(T), ops=ops)
    ψ == nothing && return (E=T(Inf), ops=ops)

    filled_occ = filled_occupation(basis.model)
    eigenvalues = kwargs[:eigenvalues]
    εF = kwargs[:εF]

    E = zero(T)
    for (ik, k) in enumerate(basis.kpoints)
        for iband = 1:size(ψ[1], 2)
            E -= (temperature
                  * basis.kweights[ik]
                  * filled_occ
                  * Smearing.entropy(smearing, (eigenvalues[ik][iband] - εF) / temperature))
        end
    end

    (E=E, ops=ops)
end