text:
# Julia wrapper for header: /home/jgoldfar/Documents/work/projects/Silo.jl/deps/usr/include/silo.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

function DBOpenReal(arg1::Ptr{UInt8},arg2::Cint,arg3::Cint)
  ccall((:DBOpenReal,libsilo),Ptr{DBfile},(Ptr{UInt8},Cint,Cint),arg1,arg2,arg3)
end
function DBOpen{T1<:AbstractString}(name::T1, target::Int, mode::Int)
  ccall((:DBOpenReal,libsilo),Ptr{DBfile},(Ptr{UInt8},Cint,Cint),name,target,mode)
end

function DBCreateReal(arg1::Ptr{UInt8},arg2::Cint,arg3::Cint,arg4::Ptr{UInt8},arg5::Cint)
  ccall((:DBCreateReal,libsilo),Ptr{DBfile},(Ptr{UInt8},Cint,Cint,Ptr{UInt8},Cint),arg1,arg2,arg3,arg4,arg5)
end
function DBCreate(name::AbstractString, mode::Int, target::Int, info::AbstractString, dtype::Int)
  ccall((:DBCreateReal,libsilo),Ptr{DBfile},(Ptr{UInt8},Cint,Cint,Ptr{UInt8},Cint),name,mode,target,info,dtype)
end

function DBInqFileReal(arg1::Ptr{UInt8})
  ccall((:DBInqFileReal,libsilo),Cint,(Ptr{UInt8},),arg1)
end
function DBInqFile(name::AbstractString)
  ccall((:DBInqFileReal,libsilo),Cint,(Ptr{UInt8},),name)
end

function DBAllocCompoundarray()
  ccall((:DBAllocCompoundarray,libsilo),Ptr{DBcompoundarray},())
end

function DBAllocCurve()
  ccall((:DBAllocCurve,libsilo),Ptr{DBcurve},())
end

function DBAllocDefvars(arg1::Cint)
  ccall((:DBAllocDefvars,libsilo),Ptr{DBdefvars},(Cint,),arg1)
end

function DBAllocMultimesh(arg1::Cint)
  ccall((:DBAllocMultimesh,libsilo),Ptr{DBmultimesh},(Cint,),arg1)
end

function DBAllocMultimeshadj(arg1::Cint)
  ccall((:DBAllocMultimeshadj,libsilo),Ptr{DBmultimeshadj},(Cint,),arg1)
end

function DBAllocMultivar(arg1::Cint)
  ccall((:DBAllocMultivar,libsilo),Ptr{DBmultivar},(Cint,),arg1)
end

function DBAllocMultimat(arg1::Cint)
  ccall((:DBAllocMultimat,libsilo),Ptr{DBmultimat},(Cint,),arg1)
end

function DBAllocMultimatspecies(arg1::Cint)
  ccall((:DBAllocMultimatspecies,libsilo),Ptr{DBmultimatspecies},(Cint,),arg1)
end

function DBAllocCsgmesh()
  ccall((:DBAllocCsgmesh,libsilo),Ptr{DBcsgmesh},())
end

function DBAllocQuadmesh()
  ccall((:DBAllocQuadmesh,libsilo),Ptr{DBquadmesh},())
end

function DBAllocPointmesh()
  ccall((:DBAllocPointmesh,libsilo),Ptr{DBpointmesh},())
end

function DBAllocMeshvar()
  ccall((:DBAllocMeshvar,libsilo),Ptr{DBmeshvar},())
end

function DBAllocUcdmesh()
  ccall((:DBAllocUcdmesh,libsilo),Ptr{DBucdmesh},())
end

function DBAllocCsgvar()
  ccall((:DBAllocCsgvar,libsilo),Ptr{DBcsgvar},())
end

function DBAllocQuadvar()
  ccall((:DBAllocQuadvar,libsilo),Ptr{DBquadvar},())
end

function DBAllocUcdvar()
  ccall((:DBAllocUcdvar,libsilo),Ptr{DBucdvar},())
end

function DBAllocZonelist()
  ccall((:DBAllocZonelist,libsilo),Ptr{DBzonelist},())
end

function DBAllocPHZonelist()
  ccall((:DBAllocPHZonelist,libsilo),Ptr{DBphzonelist},())
end

function DBAllocCSGZonelist()
  ccall((:DBAllocCSGZonelist,libsilo),Ptr{DBcsgzonelist},())
end

function DBAllocEdgelist()
  ccall((:DBAllocEdgelist,libsilo),Ptr{DBedgelist},())
end

function DBAllocFacelist()
  ccall((:DBAllocFacelist,libsilo),Ptr{DBfacelist},())
end

function DBAllocMaterial()
  ccall((:DBAllocMaterial,libsilo),Ptr{DBmaterial},())
end

function DBAllocMatspecies()
  ccall((:DBAllocMatspecies,libsilo),Ptr{DBmatspecies},())
end

function DBAllocNamescheme()
  ccall((:DBAllocNamescheme,libsilo),Ptr{DBnamescheme},())
end

function DBAllocGroupelmap(arg1::Cint,arg2::Cint)
  ccall((:DBAllocGroupelmap,libsilo),Ptr{DBgroupelmap},(Cint,Cint),arg1,arg2)
end

function DBFreeMatspecies(arg1::Ptr{DBmatspecies})
  ccall((:DBFreeMatspecies,libsilo),Void,(Ptr{DBmatspecies},),arg1)
end

function DBFreeMaterial(arg1::Ptr{DBmaterial})
  ccall((:DBFreeMaterial,libsilo),Void,(Ptr{DBmaterial},),arg1)
end

function DBFreeFacelist(arg1::Ptr{DBfacelist})
  ccall((:DBFreeFacelist,libsilo),Void,(Ptr{DBfacelist},),arg1)
end

function DBFreeEdgelist(arg1::Ptr{DBedgelist})
  ccall((:DBFreeEdgelist,libsilo),Void,(Ptr{DBedgelist},),arg1)
end

function DBFreeZonelist(arg1::Ptr{DBzonelist})
  ccall((:DBFreeZonelist,libsilo),Void,(Ptr{DBzonelist},),arg1)
end

function DBFreePHZonelist(arg1::Ptr{DBphzonelist})
  ccall((:DBFreePHZonelist,libsilo),Void,(Ptr{DBphzonelist},),arg1)
end

function DBFreeCSGZonelist(arg1::Ptr{DBcsgzonelist})
  ccall((:DBFreeCSGZonelist,libsilo),Void,(Ptr{DBcsgzonelist},),arg1)
end

function DBResetUcdvar(arg1::Ptr{DBucdvar})
  ccall((:DBResetUcdvar,libsilo),Void,(Ptr{DBucdvar},),arg1)
end

function DBFreeUcdvar(arg1::Ptr{DBucdvar})
  ccall((:DBFreeUcdvar,libsilo),Void,(Ptr{DBucdvar},),arg1)
end

function DBResetQuadvar(arg1::Ptr{DBquadvar})
  ccall((:DBResetQuadvar,libsilo),Void,(Ptr{DBquadvar},),arg1)
end

function DBFreeCsgvar(arg1::Ptr{DBcsgvar})
  ccall((:DBFreeCsgvar,libsilo),Void,(Ptr{DBcsgvar},),arg1)
end

function DBFreeQuadvar(arg1::Ptr{DBquadvar})
  ccall((:DBFreeQuadvar,libsilo),Void,(Ptr{DBquadvar},),arg1)
end

function DBFreeUcdmesh(arg1::Ptr{DBucdmesh})
  ccall((:DBFreeUcdmesh,libsilo),Void,(Ptr{DBucdmesh},),arg1)
end

function DBFreeMeshvar(arg1::Ptr{DBmeshvar})
  ccall((:DBFreeMeshvar,libsilo),Void,(Ptr{DBmeshvar},),arg1)
end

function DBFreePointvar(arg1::Ptr{DBpointvar})
  ccall((:DBFreePointvar,libsilo),Void,(Ptr{DBpointvar},),arg1)
end

function DBFreePointmesh(arg1::Ptr{DBpointmesh})
  ccall((:DBFreePointmesh,libsilo),Void,(Ptr{DBpointmesh},),arg1)
end

function DBFreeQuadmesh(arg1::Ptr{DBquadmesh})
  ccall((:DBFreeQuadmesh,libsilo),Void,(Ptr{DBquadmesh},),arg1)
end

function DBFreeCsgmesh(arg1::Ptr{DBcsgmesh})
  ccall((:DBFreeCsgmesh,libsilo),Void,(Ptr{DBcsgmesh},),arg1)
end

function DBFreeDefvars(arg1::Ptr{DBdefvars})
  ccall((:DBFreeDefvars,libsilo),Void,(Ptr{DBdefvars},),arg1)
end

function DBFreeMultimesh(arg1::Ptr{DBmultimesh})
  ccall((:DBFreeMultimesh,libsilo),Void,(Ptr{DBmultimesh},),arg1)
end

function DBFreeMultimeshadj(arg1::Ptr{DBmultimeshadj})
  ccall((:DBFreeMultimeshadj,libsilo),Void,(Ptr{DBmultimeshadj},),arg1)
end

function DBFreeMultivar(arg1::Ptr{DBmultivar})
  ccall((:DBFreeMultivar,libsilo),Void,(Ptr{DBmultivar},),arg1)
end

function DBFreeMultimat(arg1::Ptr{DBmultimat})
  ccall((:DBFreeMultimat,libsilo),Void,(Ptr{DBmultimat},),arg1)
end

function DBFreeMultimatspecies(arg1::Ptr{DBmultimatspecies})
  ccall((:DBFreeMultimatspecies,libsilo),Void,(Ptr{DBmultimatspecies},),arg1)
end

function DBFreeCompoundarray(arg1::Ptr{DBcompoundarray})
  ccall((:DBFreeCompoundarray,libsilo),Void,(Ptr{DBcompoundarray},),arg1)
end

function DBFreeCurve(arg1::Ptr{DBcurve})
  ccall((:DBFreeCurve,libsilo),Void,(Ptr{DBcurve},),arg1)
end

function DBFreeNamescheme(arg1::Ptr{DBnamescheme})
  ccall((:DBFreeNamescheme,libsilo),Void,(Ptr{DBnamescheme},),arg1)
end

function DBIsEmptyCurve(curve::Ptr{DBcurve})
  ccall((:DBIsEmptyCurve,libsilo),Cint,(Ptr{DBcurve},),curve)
end

function DBIsEmptyPointmesh(msh::Ptr{DBpointmesh})
  ccall((:DBIsEmptyPointmesh,libsilo),Cint,(Ptr{DBpointmesh},),msh)
end

function DBIsEmptyPointvar(var::Ptr{DBpointvar})
  ccall((:DBIsEmptyPointvar,libsilo),Cint,(Ptr{DBpointvar},),var)
end

function DBIsEmptyMeshvar(var::Ptr{DBmeshvar})
  ccall((:DBIsEmptyMeshvar,libsilo),Cint,(Ptr{DBmeshvar},),var)
end

function DBIsEmptyQuadmesh(msh::Ptr{DBquadmesh})
  ccall((:DBIsEmptyQuadmesh,libsilo),Cint,(Ptr{DBquadmesh},),msh)
end

function DBIsEmptyQuadvar(var::Ptr{DBquadvar})
  ccall((:DBIsEmptyQuadvar,libsilo),Cint,(Ptr{DBquadvar},),var)
end

function DBIsEmptyUcdmesh(msh::Ptr{DBucdmesh})
  ccall((:DBIsEmptyUcdmesh,libsilo),Cint,(Ptr{DBucdmesh},),msh)
end

function DBIsEmptyFacelist(fl::Ptr{DBfacelist})
  ccall((:DBIsEmptyFacelist,libsilo),Cint,(Ptr{DBfacelist},),fl)
end

function DBIsEmptyZonelist(zl::Ptr{DBzonelist})
  ccall((:DBIsEmptyZonelist,libsilo),Cint,(Ptr{DBzonelist},),zl)
end

function DBIsEmptyPHZonelist(zl::Ptr{DBphzonelist})
  ccall((:DBIsEmptyPHZonelist,libsilo),Cint,(Ptr{DBphzonelist},),zl)
end

function DBIsEmptyUcdvar(var::Ptr{DBucdvar})
  ccall((:DBIsEmptyUcdvar,libsilo),Cint,(Ptr{DBucdvar},),var)
end

function DBIsEmptyCsgmesh(msh::Ptr{DBcsgmesh})
  ccall((:DBIsEmptyCsgmesh,libsilo),Cint,(Ptr{DBcsgmesh},),msh)
end

function DBIsEmptyCSGZonelist(zl::Ptr{DBcsgzonelist})
  ccall((:DBIsEmptyCSGZonelist,libsilo),Cint,(Ptr{DBcsgzonelist},),zl)
end

function DBIsEmptyCsgvar(var::Ptr{DBcsgvar})
  ccall((:DBIsEmptyCsgvar,libsilo),Cint,(Ptr{DBcsgvar},),var)
end

function DBIsEmptyMaterial(mat::Ptr{DBmaterial})
  ccall((:DBIsEmptyMaterial,libsilo),Cint,(Ptr{DBmaterial},),mat)
end

function DBIsEmptyMatspecies(spec::Ptr{DBmatspecies})
  ccall((:DBIsEmptyMatspecies,libsilo),Cint,(Ptr{DBmatspecies},),spec)
end

function DBSetDataReadMask(arg1::Clong)
  ccall((:DBSetDataReadMask,libsilo),Clong,(Clong,),arg1)
end

function DBGetDataReadMask()
  ccall((:DBGetDataReadMask,libsilo),Clong,())
end

function DBSetAllowOverwrites(allow::Cint)
  ccall((:DBSetAllowOverwrites,libsilo),Cint,(Cint,),allow)
end

function DBGetAllowOverwrites()
  ccall((:DBGetAllowOverwrites,libsilo),Cint,())
end

function DBSetAllowEmptyObjects(allow::Cint)
  ccall((:DBSetAllowEmptyObjects,libsilo),Cint,(Cint,),allow)
end

function DBGetAllowEmptyObjects()
  ccall((:DBGetAllowEmptyObjects,libsilo),Cint,())
end

function DBSetEnableChecksums(enable::Cint)
  ccall((:DBSetEnableChecksums,libsilo),Cint,(Cint,),enable)
end

function DBGetEnableChecksums()
  ccall((:DBGetEnableChecksums,libsilo),Cint,())
end

function DBSetCompression(arg1::Ptr{UInt8})
  ccall((:DBSetCompression,libsilo),Void,(Ptr{UInt8},),arg1)
end

function DBGetCompression()
  ccall((:DBGetCompression,libsilo),Ptr{UInt8},())
end

function DBSetFriendlyHDF5Names(enable::Cint)
  ccall((:DBSetFriendlyHDF5Names,libsilo),Cint,(Cint,),enable)
end

function DBGetFriendlyHDF5Names()
  ccall((:DBGetFriendlyHDF5Names,libsilo),Cint,())
end

function DBGuessHasFriendlyHDF5Names(f::Ptr{DBfile})
  ccall((:DBGuessHasFriendlyHDF5Names,libsilo),Cint,(Ptr{DBfile},),f)
end

function DBSetDeprecateWarnings(max::Cint)
  ccall((:DBSetDeprecateWarnings,libsilo),Cint,(Cint,),max)
end

function DBSetUnknownDriverPriorities(arg1::Ptr{Cint})
  ccall((:DBSetUnknownDriverPriorities,libsilo),Ptr{Cint},(Ptr{Cint},),arg1)
end

function DBRegisterFileOptionsSet(opts::Ptr{DBoptlist})
  ccall((:DBRegisterFileOptionsSet,libsilo),Cint,(Ptr{DBoptlist},),opts)
end

function DBUnregisterFileOptionsSet(opts_set_id::Cint)
  ccall((:DBUnregisterFileOptionsSet,libsilo),Cint,(Cint,),opts_set_id)
end

function DBGrabDriver(arg1::Ptr{DBfile})
  ccall((:DBGrabDriver,libsilo),Ptr{Void},(Ptr{DBfile},),arg1)
end

function DBUngrabDriver(arg1::Ptr{DBfile},arg2::Ptr{Void})
  ccall((:DBUngrabDriver,libsilo),Cint,(Ptr{DBfile},Ptr{Void}),arg1,arg2)
end

function DBGetDriverType(arg1::Ptr{DBfile})
  ccall((:DBGetDriverType,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBGetDriverTypeFromPath(arg1::Ptr{UInt8})
  ccall((:DBGetDriverTypeFromPath,libsilo),Cint,(Ptr{UInt8},),arg1)
end

function DBJoinPath(arg1::Ptr{UInt8},arg2::Ptr{UInt8})
  ccall((:DBJoinPath,libsilo),Ptr{UInt8},(Ptr{UInt8},Ptr{UInt8}),arg1,arg2)
end

function DBVersion()
  ccall((:DBVersion,libsilo),Ptr{UInt8},())
end

function DBVersionGE(Maj::Cint,Min::Cint,Pat::Cint)
  ccall((:DBVersionGE,libsilo),Cint,(Cint,Cint,Cint),Maj,Min,Pat)
end

function DBFileVersion(dbfile::Ptr{DBfile})
  ccall((:DBFileVersion,libsilo),Ptr{UInt8},(Ptr{DBfile},),dbfile)
end

function DBFileVersionGE(dbfile::Ptr{DBfile},Maj::Cint,Min::Cint,Pat::Cint)
  ccall((:DBFileVersionGE,libsilo),Cint,(Ptr{DBfile},Cint,Cint,Cint),dbfile,Maj,Min,Pat)
end

warn("Function DBShowErrors not wrapped (requires wrapping typedef'd function type.)")
# function DBShowErrors(arg1::Cint,arg2::DBErrFunc_t)
#     ccall((:DBShowErrors,libsilo),Void,(Cint,DBErrFunc_t),arg1,arg2)
# end

function DBErrString()
  ccall((:DBErrString,libsilo),Ptr{UInt8},())
end

function DBErrFunc()
  ccall((:DBErrFunc,libsilo),Ptr{UInt8},())
end

function DBErrFuncname()
  ccall((:DBErrFuncname,libsilo),Ptr{UInt8},())
end

function DBErrfunc()
  ccall((:DBErrfunc,libsilo),DBErrFunc_t,())
end

function DBErrno()
  ccall((:DBErrno,libsilo),Cint,())
end

function DBErrlvl()
  ccall((:DBErrlvl,libsilo),Cint,())
end

function DBClose(arg1::Ptr{DBfile})
  ccall((:DBClose,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBPause(arg1::Ptr{DBfile})
  ccall((:DBPause,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBContinue(arg1::Ptr{DBfile})
  ccall((:DBContinue,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBInqVarExists(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBInqVarExists,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBForceSingle(arg1::Cint)
  ccall((:DBForceSingle,libsilo),Cint,(Cint,),arg1)
end

function DBUninstall(arg1::Ptr{DBfile})
  ccall((:DBUninstall,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBMakeOptlist(arg1::Cint)
  ccall((:DBMakeOptlist,libsilo),Ptr{DBoptlist},(Cint,),arg1)
end
function DBMakeOptlist(maxOpts::Int)
  ccall((:DBMakeOptlist,libsilo),Ptr{DBoptlist},(Cint,),maxOpts)
end

function DBClearOptlist(arg1::Ptr{DBoptlist})
  ccall((:DBClearOptlist,libsilo),Cint,(Ptr{DBoptlist},),arg1)
end

function DBFreeOptlist(arg1::Ptr{DBoptlist})
  ccall((:DBFreeOptlist,libsilo),Cint,(Ptr{DBoptlist},),arg1)
end

function DBAddOption(arg1::Ptr{DBoptlist},arg2::Cint,arg3::Ptr{Void})
  ccall((:DBAddOption,libsilo),Cint,(Ptr{DBoptlist},Cint,Ptr{Void}),arg1,arg2,arg3)
end
function DBAddOption(optlist::Ptr{DBoptlist},option_id::Int, value)
  v = [value]
  ccall((:DBAddOption,libsilo),Cint,(Ptr{DBoptlist},Cint,Ptr{Void}),optlist,option_id,v)
end

function DBGetOption(arg1::Ptr{DBoptlist},arg2::Cint)
  ccall((:DBGetOption,libsilo),Ptr{Void},(Ptr{DBoptlist},Cint),arg1,arg2)
end

function DBClearOption(arg1::Ptr{DBoptlist},arg2::Cint)
  ccall((:DBClearOption,libsilo),Cint,(Ptr{DBoptlist},Cint),arg1,arg2)
end

function DBGetToc(arg1::Ptr{DBfile})
  ccall((:DBGetToc,libsilo),Ptr{DBtoc},(Ptr{DBfile},),arg1)
end

function DBNewToc(arg1::Ptr{DBfile})
  ccall((:DBNewToc,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBSortObjectsByOffset(arg1::Ptr{DBfile},nobjs::Cint,obj_names::Ptr{Ptr{UInt8}},ranks::Ptr{Cint})
  ccall((:DBSortObjectsByOffset,libsilo),Cint,(Ptr{DBfile},Cint,Ptr{Ptr{UInt8}},Ptr{Cint}),arg1,nobjs,obj_names,ranks)
end

warn("Function DBFilters not wrapped (requires stdio include parsing/FILE to be defined.)")
# function DBFilters(arg1::Ptr{DBfile},arg2::Ptr{FILE})
#     ccall((:DBFilters,libsilo),Cint,(Ptr{DBfile},Ptr{FILE}),arg1,arg2)
# end

function DBFilterRegistration(arg1::Ptr{UInt8},init::Ptr{Void},open::Ptr{Void})
  ccall((:DBFilterRegistration,libsilo),Cint,(Ptr{UInt8},Ptr{Void},Ptr{Void}),arg1,init,open)
end

function DBGetAtt(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBGetAtt,libsilo),Ptr{Void},(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBGetObject(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetObject,libsilo),Ptr{DBobject},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBChangeObject(arg1::Ptr{DBfile},arg2::Ptr{DBobject})
  ccall((:DBChangeObject,libsilo),Cint,(Ptr{DBfile},Ptr{DBobject}),arg1,arg2)
end

function DBWriteObject(arg1::Ptr{DBfile},arg2::Ptr{DBobject},arg3::Cint)
  ccall((:DBWriteObject,libsilo),Cint,(Ptr{DBfile},Ptr{DBobject},Cint),arg1,arg2,arg3)
end

function DBGetComponent(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBGetComponent,libsilo),Ptr{Void},(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBGetComponentType(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBGetComponentType,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBWriteComponent(arg1::Ptr{DBfile},arg2::Ptr{DBobject},arg3::Ptr{UInt8},arg4::Ptr{UInt8},arg5::Ptr{UInt8},arg6::Ptr{Void},arg7::Cint,arg8::Ptr{Clong})
  ccall((:DBWriteComponent,libsilo),Cint,(Ptr{DBfile},Ptr{DBobject},Ptr{UInt8},Ptr{UInt8},Ptr{UInt8},Ptr{Void},Cint,Ptr{Clong}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
end

function DBWrite(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void},arg4::Ptr{Cint},arg5::Cint,arg6::Cint)
  ccall((:DBWrite,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void},Ptr{Cint},Cint,Cint),arg1,arg2,arg3,arg4,arg5,arg6)
end

function DBWriteSlice(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void},arg4::Cint,arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Cint},arg8::Ptr{Cint},arg9::Cint)
  ccall((:DBWriteSlice,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
end

function DBCalcExternalFacelist(arg1::Ptr{Cint},arg2::Cint,arg3::Cint,arg4::Ptr{Cint},arg5::Ptr{Cint},arg6::Cint,arg7::Ptr{Cint},arg8::Cint)
  ccall((:DBCalcExternalFacelist,libsilo),Ptr{DBfacelist},(Ptr{Cint},Cint,Cint,Ptr{Cint},Ptr{Cint},Cint,Ptr{Cint},Cint),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
end

function DBCalcExternalFacelist2(arg1::Ptr{Cint},arg2::Cint,arg3::Cint,arg4::Cint,arg5::Cint,arg6::Ptr{Cint},arg7::Ptr{Cint},arg8::Ptr{Cint},arg9::Cint,arg10::Ptr{Cint},arg11::Cint)
  ccall((:DBCalcExternalFacelist2,libsilo),Ptr{DBfacelist},(Ptr{Cint},Cint,Cint,Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Ptr{Cint},Cint),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
end

function DBGetDir(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetDir,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBSetDir(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBSetDir,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBSetDirID(arg1::Ptr{DBfile},arg2::Cint)
  ccall((:DBSetDirID,libsilo),Cint,(Ptr{DBfile},Cint),arg1,arg2)
end

function DBListDir(arg1::Ptr{DBfile},arg2::Ptr{Ptr{UInt8}},arg3::Cint)
  ccall((:DBListDir,libsilo),Cint,(Ptr{DBfile},Ptr{Ptr{UInt8}},Cint),arg1,arg2,arg3)
end

function DBMkDir(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBMkDir,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end
const DBMkdir = DBMkDir

function DBCpDir(dbfile::Ptr{DBfile},srcDir::Ptr{UInt8},dstFile::Ptr{DBfile},dstDir::Ptr{UInt8})
  ccall((:DBCpDir,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{DBfile},Ptr{UInt8}),dbfile,srcDir,dstFile,dstDir)
end

function DBReadAtt(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Ptr{Void})
  ccall((:DBReadAtt,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Ptr{Void}),arg1,arg2,arg3,arg4)
end

function DBRead(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void})
  ccall((:DBRead,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void}),arg1,arg2,arg3)
end

function DBReadVar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void})
  ccall((:DBReadVar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void}),arg1,arg2,arg3)
end

function DBReadVar1(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Void})
  ccall((:DBReadVar1,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Void}),arg1,arg2,arg3,arg4)
end

function DBReadVarSlice(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Cint},arg4::Ptr{Cint},arg5::Ptr{Cint},arg6::Cint,arg7::Ptr{Void})
  ccall((:DBReadVarSlice,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Ptr{Void}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

function DBGetObjtypeTag(arg1::Ptr{UInt8})
  ccall((:DBGetObjtypeTag,libsilo),Cint,(Ptr{UInt8},),arg1)
end

function DBMakeObject(arg1::Ptr{UInt8},arg2::Cint,arg3::Cint)
  ccall((:DBMakeObject,libsilo),Ptr{DBobject},(Ptr{UInt8},Cint,Cint),arg1,arg2,arg3)
end

function DBFreeObject(arg1::Ptr{DBobject})
  ccall((:DBFreeObject,libsilo),Cint,(Ptr{DBobject},),arg1)
end

function DBClearObject(arg1::Ptr{DBobject})
  ccall((:DBClearObject,libsilo),Cint,(Ptr{DBobject},),arg1)
end

function DBAddVarComponent(arg1::Ptr{DBobject},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBAddVarComponent,libsilo),Cint,(Ptr{DBobject},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBAddIntComponent(arg1::Ptr{DBobject},arg2::Ptr{UInt8},arg3::Cint)
  ccall((:DBAddIntComponent,libsilo),Cint,(Ptr{DBobject},Ptr{UInt8},Cint),arg1,arg2,arg3)
end

function DBAddFltComponent(arg1::Ptr{DBobject},arg2::Ptr{UInt8},arg3::Cdouble)
  ccall((:DBAddFltComponent,libsilo),Cint,(Ptr{DBobject},Ptr{UInt8},Cdouble),arg1,arg2,arg3)
end

function DBAddDblComponent(arg1::Ptr{DBobject},arg2::Ptr{UInt8},arg3::Cdouble)
  ccall((:DBAddDblComponent,libsilo),Cint,(Ptr{DBobject},Ptr{UInt8},Cdouble),arg1,arg2,arg3)
end

function DBAddStrComponent(arg1::Ptr{DBobject},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBAddStrComponent,libsilo),Cint,(Ptr{DBobject},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBGetComponentNames(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Ptr{Ptr{UInt8}}},arg4::Ptr{Ptr{Ptr{UInt8}}})
  ccall((:DBGetComponentNames,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Ptr{Ptr{UInt8}}},Ptr{Ptr{Ptr{UInt8}}}),arg1,arg2,arg3,arg4)
end

function DBGetCompoundarray(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetCompoundarray,libsilo),Ptr{DBcompoundarray},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetCurve(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetCurve,libsilo),Ptr{DBcurve},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end
function DBGetCurve(arg1::Ptr{DBfile},arg2::ASCIIString)
  ccall((:DBGetCurve,libsilo),Ptr{DBcurve},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetDefvars(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetDefvars,libsilo),Ptr{DBdefvars},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMaterial(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMaterial,libsilo),Ptr{DBmaterial},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMatspecies(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMatspecies,libsilo),Ptr{DBmatspecies},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMultimesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMultimesh,libsilo),Ptr{DBmultimesh},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMultimeshadj(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Cint})
  ccall((:DBGetMultimeshadj,libsilo),Ptr{DBmultimeshadj},(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint}),arg1,arg2,arg3,arg4)
end

function DBGetMultivar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMultivar,libsilo),Ptr{DBmultivar},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMultimat(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMultimat,libsilo),Ptr{DBmultimat},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetMultimatspecies(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetMultimatspecies,libsilo),Ptr{DBmultimatspecies},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetPointmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetPointmesh,libsilo),Ptr{DBpointmesh},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetPointvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetPointvar,libsilo),Ptr{DBmeshvar},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetQuadmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetQuadmesh,libsilo),Ptr{DBquadmesh},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetQuadvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetQuadvar,libsilo),Ptr{DBquadvar},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetQuadvar1(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void},arg4::Ptr{Cint},arg5::Ptr{Cint},arg6::Ptr{Void},arg7::Ptr{Cint},arg8::Ptr{Cint},arg9::Ptr{Cint})
  ccall((:DBGetQuadvar1,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void},Ptr{Cint},Ptr{Cint},Ptr{Void},Ptr{Cint},Ptr{Cint},Ptr{Cint}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
end

function DBAnnotateUcdmesh(arg1::Ptr{DBucdmesh})
  ccall((:DBAnnotateUcdmesh,libsilo),Cint,(Ptr{DBucdmesh},),arg1)
end

function DBGetUcdmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetUcdmesh,libsilo),Ptr{DBucdmesh},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetUcdvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetUcdvar,libsilo),Ptr{DBucdvar},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetCsgmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetCsgmesh,libsilo),Ptr{DBcsgmesh},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetCsgvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetCsgvar,libsilo),Ptr{DBcsgvar},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetCSGZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetCSGZonelist,libsilo),Ptr{DBcsgzonelist},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetFacelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetFacelist,libsilo),Ptr{DBfacelist},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetZonelist,libsilo),Ptr{DBzonelist},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetPHZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetPHZonelist,libsilo),Ptr{DBphzonelist},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetVar(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetVar,libsilo),Ptr{Void},(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetVarByteLength(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetVarByteLength,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetVarLength(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetVarLength,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBGetVarDims(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Cint})
  ccall((:DBGetVarDims,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint}),arg1,arg2,arg3,arg4)
end

function DBGetVarType(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBGetVarType,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBInqFileHasObjects(arg1::Ptr{DBfile})
  ccall((:DBInqFileHasObjects,libsilo),Cint,(Ptr{DBfile},),arg1)
end

function DBInqMeshname(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8})
  ccall((:DBInqMeshname,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8}),arg1,arg2,arg3)
end

function DBInqMeshtype(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBInqMeshtype,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBInqCompoundarray(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Ptr{Ptr{UInt8}}},arg4::Ptr{Ptr{Cint}},arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Cint})
  ccall((:DBInqCompoundarray,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Ptr{Ptr{UInt8}}},Ptr{Ptr{Cint}},Ptr{Cint},Ptr{Cint},Ptr{Cint}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

# Note: Now returns C-integer rather than DBObjectType
function DBInqVarType(arg1::Ptr{DBfile},arg2::Ptr{UInt8})
  ccall((:DBInqVarType,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),arg1,arg2)
end

function DBPutCompoundarray(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Ptr{UInt8}},arg4::Ptr{Cint},arg5::Cint,arg6::Ptr{Void},arg7::Cint,arg8::Cint,arg9::Ptr{DBoptlist})
  ccall((:DBPutCompoundarray,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Ptr{UInt8}},Ptr{Cint},Cint,Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
end

function DBPutCurve(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Void},arg4::Ptr{Void},arg5::Cint,arg6::Cint,arg7::Ptr{DBoptlist})
  ccall((:DBPutCurve,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void},Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end
function DBPutCurve{T1<:AbstractString}(dbfile::Ptr{DBfile},curvename::T1,xvals::Vector,yvals::Vector,datatype::Int,npoints::Int,optlist::Ptr{DBoptlist})
  ccall((:DBPutCurve,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Void},Ptr{Void},Cint,Cint,Ptr{DBoptlist}),dbfile,curvename,xvals,yvals,datatype,npoints,optlist)
end

function DBPutDefvars(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{Cint},arg6::Ptr{Ptr{UInt8}},arg7::Ptr{Ptr{DBoptlist}})
  ccall((:DBPutDefvars,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Cint},Ptr{Ptr{UInt8}},Ptr{Ptr{DBoptlist}}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

function DBPutFacelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Cint,arg5::Ptr{Cint},arg6::Cint,arg7::Cint,arg8::Ptr{Cint},arg9::Ptr{Cint},arg10::Ptr{Cint},arg11::Cint,arg12::Ptr{Cint},arg13::Ptr{Cint},arg14::Cint)
  ccall((:DBPutFacelist,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Cint,Ptr{Cint},Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Ptr{Cint},Ptr{Cint},Cint),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14)
end

function DBPutMaterial(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Cint},arg8::Cint,arg9::Ptr{Cint},arg10::Ptr{Cint},arg11::Ptr{Cint},arg12::Ptr{Void},arg13::Cint,arg14::Cint,arg15::Ptr{DBoptlist})
  ccall((:DBPutMaterial,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15)
end

function DBPutMatspecies(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Cint},arg8::Cint,arg9::Cint,arg10::Ptr{Void},arg11::Ptr{Cint},arg12::Cint,arg13::Cint,arg14::Ptr{DBoptlist})
  ccall((:DBPutMatspecies,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Cint,Ptr{Void},Ptr{Cint},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14)
end

function DBPutMultimesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{Cint},arg6::Ptr{DBoptlist})
  ccall((:DBPutMultimesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Cint},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6)
end

function DBPutMultimeshadj(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Cint},arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Cint},arg8::Ptr{Cint},arg9::Ptr{Ptr{Cint}},arg10::Ptr{Cint},arg11::Ptr{Ptr{Cint}},optlist::Ptr{DBoptlist})
  ccall((:DBPutMultimeshadj,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Ptr{Cint}},Ptr{Cint},Ptr{Ptr{Cint}},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,optlist)
end

function DBPutMultivar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{Cint},arg6::Ptr{DBoptlist})
  ccall((:DBPutMultivar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Cint},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6)
end

function DBPutMultimat(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{DBoptlist})
  ccall((:DBPutMultimat,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5)
end

function DBPutMultimatspecies(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{DBoptlist})
  ccall((:DBPutMultimatspecies,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5)
end

function DBPutPointmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Void},arg5::Cint,arg6::Cint,arg7::Ptr{DBoptlist})
  ccall((:DBPutPointmesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

function DBPutPointvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Void},arg6::Cint,arg7::Cint,arg8::Ptr{DBoptlist})
  ccall((:DBPutPointvar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
end

function DBPutPointvar1(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Ptr{Void},arg5::Cint,arg6::Cint,arg7::Ptr{DBoptlist})
  ccall((:DBPutPointvar1,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Ptr{Void},Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

function DBPutQuadmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{Ptr{UInt8}},arg4::Ptr{Void},arg5::Ptr{Cint},arg6::Cint,arg7::Cint,arg8::Cint,arg9::Ptr{DBoptlist})
  ccall((:DBPutQuadmesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{Ptr{UInt8}},Ptr{Void},Ptr{Cint},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
end

function DBPutQuadvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Ptr{UInt8}},arg6::Ptr{Void},arg7::Ptr{Cint},arg8::Cint,arg9::Ptr{Void},arg10::Cint,arg11::Cint,arg12::Cint,arg13::Ptr{DBoptlist})
  ccall((:DBPutQuadvar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Void},Ptr{Cint},Cint,Ptr{Void},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13)
end

function DBPutQuadvar1(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Ptr{Void},arg5::Ptr{Cint},arg6::Cint,arg7::Ptr{Void},arg8::Cint,arg9::Cint,arg10::Cint,arg11::Ptr{DBoptlist})
  ccall((:DBPutQuadvar1,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Ptr{Void},Ptr{Cint},Cint,Ptr{Void},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
end

function DBPutUcdmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Ptr{UInt8}},arg5::Ptr{Void},arg6::Cint,arg7::Cint,arg8::Ptr{UInt8},arg9::Ptr{UInt8},arg10::Cint,arg11::Ptr{DBoptlist})
  ccall((:DBPutUcdmesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Void},Cint,Cint,Ptr{UInt8},Ptr{UInt8},Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
end

function DBPutUcdsubmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{UInt8},arg6::Ptr{UInt8},arg7::Ptr{DBoptlist})
  ccall((:DBPutUcdsubmesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{UInt8},Ptr{UInt8},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7)
end

function DBPutUcdvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Ptr{UInt8}},arg6::Ptr{Void},arg7::Cint,arg8::Ptr{Void},arg9::Cint,arg10::Cint,arg11::Cint,arg12::Ptr{DBoptlist})
  ccall((:DBPutUcdvar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Void},Cint,Ptr{Void},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)
end

function DBPutUcdvar1(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Ptr{Void},arg5::Cint,arg6::Ptr{Void},arg7::Cint,arg8::Cint,arg9::Cint,arg10::Ptr{DBoptlist})
  ccall((:DBPutUcdvar1,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Ptr{Void},Cint,Ptr{Void},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
end

function DBPutZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Cint,arg5::Ptr{Cint},arg6::Cint,arg7::Cint,arg8::Ptr{Cint},arg9::Ptr{Cint},arg10::Cint)
  ccall((:DBPutZonelist,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Cint,Ptr{Cint},Cint,Cint,Ptr{Cint},Ptr{Cint},Cint),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
end

function DBPutZonelist2(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Cint,arg5::Ptr{Cint},arg6::Cint,arg7::Cint,arg8::Cint,arg9::Cint,arg10::Ptr{Cint},arg11::Ptr{Cint},arg12::Ptr{Cint},arg13::Cint,arg14::Ptr{DBoptlist})
  ccall((:DBPutZonelist2,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Cint,Ptr{Cint},Cint,Cint,Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14)
end

function DBPutPHZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Cint},arg5::Cint,arg6::Ptr{Cint},arg7::Ptr{UInt8},arg8::Cint,arg9::Ptr{Cint},arg10::Cint,arg11::Ptr{Cint},arg12::Cint,arg13::Cint,arg14::Cint,arg15::Ptr{DBoptlist})
  ccall((:DBPutPHZonelist,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint},Cint,Ptr{Cint},Ptr{UInt8},Cint,Ptr{Cint},Cint,Ptr{Cint},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15)
end

function DBPutCsgmesh(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Cint,arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Void},arg8::Cint,arg9::Cint,arg10::Ptr{Cdouble},arg11::Ptr{UInt8},arg12::Ptr{DBoptlist})
  ccall((:DBPutCsgmesh,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{Void},Cint,Cint,Ptr{Cdouble},Ptr{UInt8},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)
end

function DBPutCSGZonelist(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Cint,arg4::Ptr{Cint},arg5::Ptr{Cint},arg6::Ptr{Cint},arg7::Ptr{Void},arg8::Cint,arg9::Cint,arg10::Cint,arg11::Ptr{Cint},arg12::Ptr{DBoptlist})
  ccall((:DBPutCSGZonelist,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Void},Cint,Cint,Cint,Ptr{Cint},Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)
end

function DBPutCsgvar(arg1::Ptr{DBfile},arg2::Ptr{UInt8},arg3::Ptr{UInt8},arg4::Cint,arg5::Ptr{Ptr{UInt8}},arg6::Ptr{Ptr{Void}},arg7::Cint,arg8::Cint,arg9::Cint,arg10::Ptr{DBoptlist})
  ccall((:DBPutCsgvar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Ptr{Ptr{Void}},Cint,Cint,Cint,Ptr{DBoptlist}),arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
end

function DBFreeMrgtree(tree::Ptr{DBmrgtree})
  ccall((:DBFreeMrgtree,libsilo),Void,(Ptr{DBmrgtree},),tree)
end

function DBPrintMrgtree(tnode::Ptr{DBmrgtnode},walk_order::Cint,data::Ptr{Void})
  ccall((:DBPrintMrgtree,libsilo),Void,(Ptr{DBmrgtnode},Cint,Ptr{Void}),tnode,walk_order,data)
end

function DBLinearizeMrgtree(tnode::Ptr{DBmrgtnode},walk_order::Cint,data::Ptr{Void})
  ccall((:DBLinearizeMrgtree,libsilo),Void,(Ptr{DBmrgtnode},Cint,Ptr{Void}),tnode,walk_order,data)
end

warn("Function DBWalkMrgtree not wrapped (requires function typedef)")
# function DBWalkMrgtree(tree::Ptr{DBmrgtree},cb::DBmrgwalkcb,wdata::Ptr{Void},traversal_order::Cint)
#     ccall((:DBWalkMrgtree,libsilo),Void,(Ptr{DBmrgtree},DBmrgwalkcb,Ptr{Void},Cint),tree,cb,wdata,traversal_order)
# end

function DBMakeMrgtree(source_mesh_type::Cint,mrgtree_info::Cint,max_root_descendents::Cint,opts::Ptr{DBoptlist})
  ccall((:DBMakeMrgtree,libsilo),Ptr{DBmrgtree},(Cint,Cint,Cint,Ptr{DBoptlist}),source_mesh_type,mrgtree_info,max_root_descendents,opts)
end

function DBAddRegion(tree::Ptr{DBmrgtree},region_name::Ptr{UInt8},type_info_bits::Cint,max_descendents::Cint,maps_name::Ptr{UInt8},nsegs::Cint,seg_ids::Ptr{Cint},seg_sizes::Ptr{Cint},seg_types::Ptr{Cint},opts::Ptr{DBoptlist})
  ccall((:DBAddRegion,libsilo),Cint,(Ptr{DBmrgtree},Ptr{UInt8},Cint,Cint,Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{DBoptlist}),tree,region_name,type_info_bits,max_descendents,maps_name,nsegs,seg_ids,seg_sizes,seg_types,opts)
end

function DBAddRegionArray(tree::Ptr{DBmrgtree},nregn::Cint,regn_names::Ptr{Ptr{UInt8}},type_info_bits::Cint,maps_name::Ptr{UInt8},nsegs::Cint,seg_ids::Ptr{Cint},seg_sizes::Ptr{Cint},seg_types::Ptr{Cint},opts::Ptr{DBoptlist})
  ccall((:DBAddRegionArray,libsilo),Cint,(Ptr{DBmrgtree},Cint,Ptr{Ptr{UInt8}},Cint,Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{DBoptlist}),tree,nregn,regn_names,type_info_bits,maps_name,nsegs,seg_ids,seg_sizes,seg_types,opts)
end

function DBSetCwr(tree::Ptr{DBmrgtree},path::Ptr{UInt8})
  ccall((:DBSetCwr,libsilo),Cint,(Ptr{DBmrgtree},Ptr{UInt8}),tree,path)
end

function DBGetCwr(tree::Ptr{DBmrgtree})
  ccall((:DBGetCwr,libsilo),Ptr{UInt8},(Ptr{DBmrgtree},),tree)
end

function DBPutMrgtree(dbfile::Ptr{DBfile},mrg_tree_name::Ptr{UInt8},mesh_name::Ptr{UInt8},tree::Ptr{DBmrgtree},opts::Ptr{DBoptlist})
  ccall((:DBPutMrgtree,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Ptr{DBmrgtree},Ptr{DBoptlist}),dbfile,mrg_tree_name,mesh_name,tree,opts)
end

function DBGetMrgtree(dbfile::Ptr{DBfile},mrg_tree_name::Ptr{UInt8})
  ccall((:DBGetMrgtree,libsilo),Ptr{DBmrgtree},(Ptr{DBfile},Ptr{UInt8}),dbfile,mrg_tree_name)
end

function DBPutMrgvar(dbfile::Ptr{DBfile},name::Ptr{UInt8},mrgt_name::Ptr{UInt8},ncomps::Cint,compnames::Ptr{Ptr{UInt8}},nregns::Cint,reg_pnames::Ptr{Ptr{UInt8}},datatype::Cint,data::Ptr{Ptr{Void}},opts::Ptr{DBoptlist})
  ccall((:DBPutMrgvar,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},Cint,Ptr{Ptr{UInt8}},Cint,Ptr{Ptr{Void}},Ptr{DBoptlist}),dbfile,name,mrgt_name,ncomps,compnames,nregns,reg_pnames,datatype,data,opts)
end

function DBGetMrgvar(dbfile::Ptr{DBfile},name::Ptr{UInt8})
  ccall((:DBGetMrgvar,libsilo),Ptr{DBmrgvar},(Ptr{DBfile},Ptr{UInt8}),dbfile,name)
end

function DBFreeMrgvar(mrgv::Ptr{DBmrgvar})
  ccall((:DBFreeMrgvar,libsilo),Void,(Ptr{DBmrgvar},),mrgv)
end

function DBPutGroupelmap(dbfile::Ptr{DBfile},map_name::Ptr{UInt8},num_segments::Cint,groupel_types::Ptr{Cint},segment_lengths::Ptr{Cint},segment_ids::Ptr{Cint},segment_data::Ptr{Ptr{Cint}},segment_fracs::Ptr{Ptr{Void}},fracs_data_type::Cint,opts::Ptr{DBoptlist})
  ccall((:DBPutGroupelmap,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8},Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Ptr{Cint}},Ptr{Ptr{Void}},Cint,Ptr{DBoptlist}),dbfile,map_name,num_segments,groupel_types,segment_lengths,segment_ids,segment_data,segment_fracs,fracs_data_type,opts)
end

function DBGetGroupelmap(dbfile::Ptr{DBfile},name::Ptr{UInt8})
  ccall((:DBGetGroupelmap,libsilo),Ptr{DBgroupelmap},(Ptr{DBfile},Ptr{UInt8}),dbfile,name)
end

function DBFreeGroupelmap(map::Ptr{DBgroupelmap})
  ccall((:DBFreeGroupelmap,libsilo),Void,(Ptr{DBgroupelmap},),map)
end

function DBFortranAccessPointer(value::Cint)
  ccall((:DBFortranAccessPointer,libsilo),Ptr{Void},(Cint,),value)
end

function DBFortranAllocPointer(pointer::Ptr{Void})
  ccall((:DBFortranAllocPointer,libsilo),Cint,(Ptr{Void},),pointer)
end

function DBFortranRemovePointer(value::Cint)
  ccall((:DBFortranRemovePointer,libsilo),Void,(Cint,),value)
end

function DBVariableNameValid(s::Ptr{UInt8})
  ccall((:DBVariableNameValid,libsilo),Cint,(Ptr{UInt8},),s)
end

function safe_strdup(s::Ptr{UInt8})
  ccall((:safe_strdup,libsilo),Ptr{UInt8},(Ptr{UInt8},),s)
end

function DBFreeCompressionResources(dbfile::Ptr{DBfile},meshname::Ptr{UInt8})
  ccall((:DBFreeCompressionResources,libsilo),Cint,(Ptr{DBfile},Ptr{UInt8}),dbfile,meshname)
end

function DBGetName(ns::Ptr{DBnamescheme},natnum::Cint)
  ccall((:DBGetName,libsilo),Ptr{UInt8},(Ptr{DBnamescheme},Cint),ns,natnum)
end

function DBStringArrayToStringList(strArray::Ptr{Ptr{UInt8}},n::Cint,strList::Ptr{Ptr{UInt8}},m::Ptr{Cint})
  ccall((:DBStringArrayToStringList,libsilo),Void,(Ptr{Ptr{UInt8}},Cint,Ptr{Ptr{UInt8}},Ptr{Cint}),strArray,n,strList,m)
end

function DBStringListToStringArray(strList::Ptr{UInt8},n::Ptr{Cint},handleSlashSwap::Cint,skipSemicolonAtIndexZero::Cint)
  ccall((:DBStringListToStringArray,libsilo),Ptr{Ptr{UInt8}},(Ptr{UInt8},Ptr{Cint},Cint,Cint),strList,n,handleSlashSwap,skipSemicolonAtIndexZero)
end

Version() = bytestring(ccall((:DBVersion, libsilo), Ptr{UInt8}, ()))
const _VERSION = convert(VersionNumber, Version())


text:
using BenchSweeps
using Test

ext: jl


text:
struct Regression <: Task end

function args(
    ::Type{Regression};
    binarize = true,
    threshold = Inf,
    kwargs...
)

    return (; binarize, threshold)
end

function partition(::Dataset{N, F, T}, targets, at::Real) where {N, F, T<:Regression}
    n = length(targets)
    k = round(Int, n*at)
    return (1:k, (k+1):n)
end

function partition(d::Dataset{N, F, T}, targets, at) where {N, F, T<:Regression}
    if length(at) == 1
        return partition(d, targets, at[1])
    end
    n = length(targets)
    i = 0
    inds = []
    for at_i in at
        k = round(Int, n*at_i)
        push!(inds, i .+ (1:k))
        i += k
    end
    return (inds..., (i+1):n)
end

function postprocess(
    N::Type{<:Name},
    ::Type{Regression},
    data;
    binarize,
    threshold,
    kwargs...
    )

    if binarize && !isinf(threshold)
        data = data_binarize_regression(data, threshold)
    end
    return data
end

max_stars_repo_name: VaclavMacha/DatasetProvider

max_issues_repo_name: VaclavMacha/DatasetProvider

max_forks_repo_name: VaclavMacha/DatasetProvider


text:
@inbounds for i = ix:ix-1+n
    x[i] = y[i]
end


text:
using Documenter, LazySets
import Polyhedra, Optim, Expokit

makedocs(
    sitename = "LazySets.jl",
    modules = Module[LazySets, Approximations],
    source = "src/lib",
    doctest = true,
    strict = true
)


text:
using PSDMatrices
using Test

using PSDMatrices: X_A_Xt
using LinearAlgebra

@testset "PSDMatrices.jl" begin

    d = 5
    L = LowerTriangular(randn(d,d))
    LLT = L*L'
    A = PSDMatrix(L)
    B = PSDMatrix(LowerTriangular(rand(d,d)))

    @testset "Basics" begin
        @test A == LLT
        @test all(A .== LLT)
        @test size(A) == size(LLT)
        @test A[:] == LLT[:]

        @test PSDMatrix(Matrix(A)) ≈ A

        @test copy(A) isa PSDMatrix
        copy!(B, A)
        @test B == A

        @test Matrix(A) == LLT
        @test typeof(Matrix(A)) === typeof(LLT)
    end

    @testset "LinearAlgebra" begin
        @test diag(A) == diag(LLT)
        @test det(A) ≈ det(LLT)
        @test logdet(A) ≈ logdet(LLT)

        @test inv(A) ≈ inv(LLT)
        x = rand(d)
        @test A\x ≈ LLT\x

        @test cholesky(A) == cholesky(LLT)
    end

    @testset "X_A_Xt" begin
        X = rand(d,d)
        @test X_A_Xt(A, X) isa PSDMatrix
        @test X_A_Xt(A, X) ≈ X*A*X'

        D = Diagonal(rand(d))
        @test X_A_Xt(A, D) isa PSDMatrix
        @test X_A_Xt(A, D) ≈ D*A*D'
    end

    @testset "Arithmetic" begin
        L2 = LowerTriangular(randn(d,d))
        B = PSDMatrix(L2)
        LLT2 = L2*L2'
        @test A+B isa PSDMatrix
        @test A+B ≈ LLT+LLT2

        c = rand()
        @test c*A isa PSDMatrix
        @test 0*A isa PSDMatrix
        @test !(-1*A isa PSDMatrix)
        @test c*A == A*c
    end

    @testset "BigFloats" begin
        L = LowerTriangular(big.(randn(d,d)))
        @test PSDMatrix(L) isa PSDMatrix
    end
end


text:
# ---
# jupyter:
#   jupytext:
#     formats: ipynb,jl:hydrogen
#     text_representation:
#       extension: .jl
#       format_name: hydrogen
#       format_version: '1.3'
#       jupytext_version: 1.11.2
#   kernelspec:
#     display_name: Julia 1.8.0-DEV
#     language: julia
#     name: julia-1.8
# ---

# %%
a = zeros(3)
x, y, z = ntuple(i -> similar(a), Val(3))

# %%
x, y, z

# %%
x[1] = 0
x, y, z

# %%
?ntuple

# %%

max_stars_repo_path: 0011/ntuple example.jl

max_stars_repo_name: genkuroki/public

max_issues_repo_path: 0011/ntuple example.jl

max_issues_repo_name: genkuroki/public

max_forks_repo_path: 0011/ntuple example.jl

max_forks_repo_name: genkuroki/public


text:
module SymbolServer

using Pkg, SHA
using Base: UUID

@info "Indexing Julia $VERSION..."

# This path will always be mounted in the docker container in which we are running
store_path = "/symcache"

cache_package_folder_path = joinpath(store_path, "v1", "stdlib")

mkpath(cache_package_folder_path)

module LoadingBay end

include("faketypes.jl")
include("symbols.jl")
include("utils.jl")
include("serialize.jl")
using .CacheStore

# TODO Make this load all the stdlibs and save them

# m = try
#     LoadingBay.eval(:(import $current_package_name))
#     getfield(LoadingBay, current_package_name)
# catch e
#     @info "Could not load package, exiting."
#     exit(10)
# end

# # Get the symbols
# env = getenvtree([current_package_name])
# symbols(env, m)

#  # Strip out paths
# modify_dirs(env[current_package_name], f -> modify_dir(f, pkg_src_dir(Base.loaded_modules[Base.PkgId(current_package_uuid, string(current_package_name))]), "PLACEHOLDER"))

# # There's an issue here - @enum used within CSTParser seems to add a method that is introduced from Enums.jl...

# Pkg.PlatformEngines.probe_platform_engines!()

# mktempdir() do path
#     # Write them to a file
#     open(joinpath(path, filename_with_extension), "w") do io
#         CacheStore.write(io, Package(string(current_package_name), env[current_package_name], current_package_uuid, nothing))
#     end

#     # cp(joinpath(path, filename_with_extension), cache_path)
#     Pkg.PlatformEngines.package(path, cache_path_compressed)
# end

@info "Finished indexing."

end


text:
using ApproxFunOrthogonalPolynomials, ApproxFunBase, Test, SpecialFunctions, LinearAlgebra
    import ApproxFunBase: testbandedbelowoperator, testbandedoperator, testspace, testtransforms, Vec,
                        maxspace, NoSpace, hasconversion, testfunctional,
                        reverseorientation, ReverseOrientation
    import ApproxFunOrthogonalPolynomials: jacobip

@testset "Jacobi" begin
    @testset "Basic" begin
        @test jacobip(0:5,2,0.5,0.1) ≈ [1.,0.975,-0.28031249999999996,-0.8636328125,-0.0022111816406250743,0.7397117980957031]

        testspace(Jacobi(.5,2.);haslineintegral=false)

        f=Fun(exp,Jacobi(.5,2.))
        @test f(.1) ≈ exp(.1)

        f=Fun(x->cos(100x),Jacobi(.5,2.124),500)
        @test f(.1) ≈ cos(100*.1)

        sp=Jacobi(.5,2.124)
        @time f=Fun(exp,sp)
        sp2=Jacobi(1.5,2.124)
        f2=Fun(exp,sp2)
        sp3=Jacobi(1.5,3.124)
        f3=Fun(exp,sp3)
        sp4=Jacobi(2.5,4.124)
        f4=Fun(exp,sp4)
        @test norm((Fun(f,sp2)-f2).coefficients)<100eps()
        @test norm((Fun(f,sp3)-f3).coefficients)<100eps()
        @test norm((Fun(f,sp4)-f4).coefficients)<200eps()
    end

    @testset "Conversion" begin
        testtransforms(Jacobi(-0.5,-0.5))
        @test norm(Fun(Fun(exp),Jacobi(-.5,-.5))-Fun(exp,Jacobi(-.5,-.5))) < 300eps()
    end

    @testset "Derivative" begin
        D=Derivative(Jacobi(0.,1.,Segment(1.,0.)))
        @time testbandedoperator(D)
    end

    @testset "Jacobi multiplication" begin
        x=Fun(identity,Jacobi(0.,0.))
        f=Fun(exp,Jacobi(0.,0.))

        @test (x*f)(.1) ≈ .1exp(.1)

        x=Fun(identity,Jacobi(12.324,0.123))
        f=Fun(exp,Jacobi(0.,0.))

        @test (x*f)(.1) ≈ .1exp(.1)

        x=Fun(identity,Jacobi(12.324,0.123))
        f=Fun(exp,Jacobi(0.590,0.213))

        @test (x*f)(.1) ≈ .1exp(.1)

        g=Fun(cos,Jacobi(12.324,0.123))
        f=Fun(exp,Jacobi(0.590,0.213))

        @test (g*f)(.1) ≈ cos(.1)*exp(.1)
    end

    @testset "Jacobi integrate and sum" begin
        testtransforms(Legendre(0..2))
        @test sum(Fun(exp,Legendre(0..2))) ≈ sum(Fun(exp,0..2))

        a=Arc(0.,.1,0.,π/2)
        g=Fun(exp,Legendre(a))

        @test sum(g) ≈ sum(Fun(exp,a))
    end
    @testset "implementation of conversion between Chebyshev and Jacobi spaces using FastTransforms" begin
        f = Fun(x->cospi(1000x))
        g = Fun(f,Legendre())
        h = Fun(g,Chebyshev())
        @test norm(f.coefficients-h.coefficients,Inf) < 100eps()
        @time h = Fun(h,Legendre())
        @test norm(g.coefficients-h.coefficients,Inf) < 1000eps()
    end

    @testset "conversion for non-compatible paramters" begin
        S=Jacobi(1.2,0.1)
        x=Fun()

        p=(S,k)->Fun(S,[zeros(k);1.])
        n=1;
        @test norm(x*p(S,n-1)-(ApproxFunOrthogonalPolynomials.recα(Float64,S,n)*p(S,n-1) + ApproxFunOrthogonalPolynomials.recβ(Float64,S,n)*p(S,n))) < 10eps()
    end

    @testset "Line sum for legendre" begin
        x = Fun(Legendre())
        @test sum(x+1) ≈ linesum(x+1)
        x=Fun(Legendre(Segment(2,1)))
        @test sum(x+1) ≈ -linesum(x+1)

        x=Fun(Segment(1,1+im))
        @test sum(x+1) ≈ im*linesum(x+1)

        x=Fun(Legendre(Segment(1,1+im)))
        @test sum(x+1) ≈ im*linesum(x+1)

        x=Fun(Legendre(Segment(im,1)))
        @test sum(x+1) ≈ (1-im)/sqrt(2)*linesum(x+1)
    end

    @testset "vector valued case" begin
        f=Fun((x,y)->real(exp(x+im*y)), Legendre(Segment(Vec(0.,0.),Vec(1.,1.))))
        @test f(0.1,0.1) ≈ real(exp(0.1+0.1im))
    end

    @testset "integer, float mixed" begin
        C=Conversion(Legendre(),Jacobi(1,0))
        testbandedoperator(C)
    end

    @testset "Addition of piecewise Legendre bug" begin
        f = Fun(exp,Legendre())
        f1 = Fun(exp,Legendre(-1..0))
        f2 = Fun(exp,Legendre(0..1))
        fp = f1+f2
        @test space(fp) isa PiecewiseSpace
        @test fp(0.1) ≈ exp(0.1)
        @test fp(0.) ≈ exp(0.)
        @test fp(-0.1) ≈ exp(-0.1)
    end

    @testset "Jacobi–Chebyshev conversion" begin
        a,b = (Jacobi(-0.5,-0.5), Legendre())
        @test maxspace(a,b) == NoSpace()
        @test union(a,b) == a
        @test !hasconversion(a,b)

        a,b = (Chebyshev(), Legendre())
        @test maxspace(a,b) == NoSpace()
        @test union(a,b) == Jacobi(-0.5,-0.5)
        @test !hasconversion(a,b)
    end

    @testset "Reverse orientation" begin
        S = Jacobi(0.1,0.2)

        @test_throws ArgumentError Conversion(S, Jacobi(1.1,1.2,0..1))

        f = Fun(S, randn(10))
        @test f(0.1) ≈ (ReverseOrientation(S)*f)(0.1) ≈ reverseorientation(f)(0.1)
        @test rangespace(ReverseOrientation(S)) == space(reverseorientation(f)) ==
                    Jacobi(0.2,0.1,Segment(1,-1))

        R = Conversion(S, reverseorientation(S))
        @test (R*f)(0.1) ≈ f(0.1) ≈ reverseorientation(f)(0.1)

        S = Legendre()
        f = Fun(S, randn(10))
        @test f(0.1) ≈ (ReverseOrientation(S)*f)(0.1) ≈ reverseorientation(f)(0.1)
        @test rangespace(ReverseOrientation(S)) == space(reverseorientation(f)) ==
                    Legendre(Segment(1,-1))

        R = Conversion(S, reverseorientation(S))
        @test rangespace(R) == reverseorientation(S) ==
            space(reverseorientation(f))
        @test f(0.1) ≈ (R*f)(0.1) ≈ reverseorientation(f)(0.1)
    end

    @testset "Full Jacobi" begin
        sp = Jacobi(.5,2.124)
        f = Fun(exp,sp)
        sp2 = Jacobi(1.5,2.124)
        M = Multiplication(f,sp2)
        @time testbandedoperator(M)

        ## Legendre conversions
        testspace(Ultraspherical(1); haslineintegral=false)
        testspace(Ultraspherical(2); haslineintegral=false)
        # minpoints is a tempory fix a bug
        @time testspace(Ultraspherical(1//2); haslineintegral=false, minpoints=2)
        @test norm(Fun(exp,Ultraspherical(1//2))-Fun(exp,Jacobi(0,0))) < 100eps()

        C=Conversion(Jacobi(0,0),Chebyshev())
        @time testbandedbelowoperator(C)
        @test norm(C*Fun(exp,Jacobi(0,0))  - Fun(exp)) < 100eps()

        C=Conversion(Ultraspherical(1//2),Chebyshev())
        @time testbandedbelowoperator(C)
        @test norm(C*Fun(exp,Ultraspherical(1//2))  - Fun(exp)) < 100eps()

        C=Conversion(Chebyshev(),Ultraspherical(1//2))
        @time testbandedbelowoperator(C)
        @test norm(C*Fun(exp)-Fun(exp,Legendre())) < 100eps()

        C=Conversion(Chebyshev(),Jacobi(0,0))
        @time testbandedbelowoperator(C)
        @test norm(C*Fun(exp)  - Fun(exp,Jacobi(0,0))) < 100eps()

        C=Conversion(Chebyshev(),Jacobi(1,1))
        @time testbandedbelowoperator(C)
        @test norm(C*Fun(exp) - Fun(exp,Jacobi(1,1))) < 100eps()

        C=Conversion(Ultraspherical(1//2),Ultraspherical(1))
        @time testbandedbelowoperator(C)

        λ1 = ApproxFunOrthogonalPolynomials.order(domainspace(C))
        λ2 = ApproxFunOrthogonalPolynomials.order(rangespace(C))

        # test against version that doesn't use lgamma
        Cex = Float64[(if j ≥ k && iseven(k-j)
                gamma(λ2)*(k-1+λ2)/(gamma(λ1)*gamma(λ1-λ2))*
                    (gamma((j-k)/2+λ1-λ2)/gamma((j-k)/2+1))*
                    (gamma((k+j-2)/2+λ1)/gamma((k+j-2)/2+λ2+1))
            else
                0.0
            end) for k=1:20,j=1:20]

        @test norm(Cex - C[1:20,1:20]) < 100eps()

        @test norm(C*Fun(exp,Ultraspherical(1//2))-Fun(exp,Ultraspherical(1))) < 100eps()

        C=Conversion(Jacobi(0,0),Ultraspherical(1))
        testbandedbelowoperator(C)
        @test norm(C*Fun(exp,Jacobi(0,0))-Fun(exp,Ultraspherical(1))) < 100eps()

        C=Conversion(Ultraspherical(1),Jacobi(0,0))
        testbandedbelowoperator(C)
        @test norm(C*Fun(exp,Ultraspherical(1))-Fun(exp,Jacobi(0,0))) < 100eps()
    end
end


text:
#### Simple example of a new Variable in Caesar.
#### This variable is a duplication of Pose2 in RoME.

"""
    $(SIGNATURES)

An example variable duplicated from the Pose2 variable in RoME.
"""
struct ExamplePose2 <: IncrementalInference.InferenceVariable
 dims::Int # x, y, theta - so it's 3 DOF
 labels::Vector{String}
 ExamplePose2() = new(3, String["POSE";])
end


text:
"""
Gloria.
"""
module Gloria

using Colors
using DataStructures: CircularBuffer, OrderedSet
using FileIO
using SimpleDirectMediaLayer

const SDL = SimpleDirectMediaLayer

function __init__()
    SDL.GL_SetAttribute(SDL.GL_MULTISAMPLEBUFFERS, 1)
    SDL.GL_SetAttribute(SDL.GL_MULTISAMPLESAMPLES, 4)
    SDL.init()
end

abstract type AbstractObject end

rgba_fromcolor(color::Colors.Color) = round(Int, color.r * 255), round(Int, color.g * 255), round(Int, color.b * 255), round(Int, color.alpha * 255)
rgba_fromcolor(color::Colors.Color3) = round(Int, color.r * 255), round(Int, color.g * 255), round(Int, color.b * 255), round(Int, 255)
rgba_fromcolor(color::Colors.Color3, a::Int) = round(Int, color.r * 255), round(Int, color.g * 255), round(Int, color.b * 255), a

include("window.jl")
include("resources.jl")
include("texture.jl")
include("text.jl")

include("Shapes.jl")
using .Shapes
using .Shapes: rotate, translate

include("parseevent.jl")
include("loops.jl")
include("mouse.jl")
include("keyboard.jl")
include("audio.jl")

include("graphics.jl")

include("model.jl")

# Submodules
include("Physics.jl")

end # module


text:
isblock(x) = length(x) == 1 && x[1] isa Expr && x[1].head == :block
function flatten_expr!(x)
    isblock(x) || return x
    x = MacroTools.striplines(x[1])
    filter!(z->z isa Symbol || z.head != :line, x.args)
    xs = []
    for ex in x.args
        if Meta.isexpr(ex, :tuple)
            append!(xs, ex.args)
        else
            push!(xs, ex)
        end
    end
    xs
end
function build_expr(head::Symbol, args)
    ex = Expr(head)
    append!(ex.args, args)
    ex
end

"""
    get_variables(O) -> Vector{Union{Sym, Term}}

Returns the variables in the expression. Note that the returned variables are
not wrapped in the `Num` type.

# Examples
```julia
julia> @parameters t
(t,)

julia> @variables x y z(t)
(x, y, z(t))

julia> ex = x + y + sin(z)
(x + y) + sin(z(t))

julia> Symbolics.get_variables(ex)
3-element Vector{Any}:
 x
 y
 z(t)
```
"""
get_variables(e::Num, varlist=nothing) = get_variables(value(e), varlist)
get_variables!(vars, e, varlist=nothing) = vars

is_singleton(e::Term) = operation(e) isa Sym
is_singleton(e::Sym) = true
is_singleton(e) = false

get_variables!(vars, e::Number, varlist=nothing) = vars

function get_variables!(vars, e::Symbolic, varlist=nothing)
    if is_singleton(e)
        if isnothing(varlist) || any(isequal(e), varlist)
            push!(vars, e)
        end
    else
        foreach(x -> get_variables!(vars, x, varlist), arguments(e))
    end
    return (vars isa AbstractVector) ? unique!(vars) : vars
end

function get_variables!(vars, e::Equation, varlist=nothing)
  get_variables!(vars, e.rhs, varlist)
end

get_variables(e, varlist=nothing) = get_variables!([], e, varlist)

# Sym / Term --> Symbol
Base.Symbol(x::Union{Num,Symbolic}) = tosymbol(x)
tosymbol(x; kwargs...) = x
tosymbol(x::Sym; kwargs...) = nameof(x)
tosymbol(t::Num; kwargs...) = tosymbol(value(t); kwargs...)

"""
    diff2term(x::Term) -> Symbolic
    diff2term(x) -> x

Convert a differential variable to a `Term`. Note that it only takes a `Term`
not a `Num`.

```julia
julia> @variables x t u(x, t); Dt = Differential(t); Dx = Differential(x);

julia> Symbolics.diff2term(Symbolics.value(Dx(Dt(u))))
uˍtx(x, t)
```
"""
function diff2term(O)
    istree(O) || return O
    if is_derivative(O)
        ds = ""
        while is_derivative(O)
            ds = string(operation(O).x) * ds
            O = arguments(O)[1]
        end
    else
        ds = nothing
    end
    T = symtype(O)
    if ds === nothing
        return similarterm(O, operation(O), map(diff2term, arguments(O)))
    else
        oldop = operation(O)
        if !(oldop isa Sym)
            throw(ArgumentError("A differentiated state's operation must be a `Sym`, so states like `D(u + u)` are disallowed. Got `$oldop`."))
        end
        d_separator = 'ˍ'
        opname = string(nameof(oldop))
        newname = occursin(d_separator, opname) ? Symbol(opname, ds) : Symbol(opname, d_separator, ds)
        return similarterm(O, rename(oldop, newname), arguments(O))
    end
end

"""
    tosymbol(x::Union{Num,Symbolic}; states=nothing, escape=true) -> Symbol

Convert `x` to a symbol. `states` are the states of a system, and `escape`
means if the target has escapes like `val"y(t)"`. If `escape` then it will only
output `y` instead of `y(t)`.

# Examples

```julia
julia> @parameters t; @variables z(t)
(z(t),)

julia> Symbolics.tosymbol(z)
Symbol("z(t)")
```
"""
function tosymbol(t::Term; states=nothing, escape=true)
    if operation(t) isa Sym
        if states !== nothing && !(t in states)
            return nameof(operation(t))
        end
        op = nameof(operation(t))
        args = arguments(t)
    elseif operation(t) isa Differential
        term = diff2term(t)
        op = Symbol(operation(term))
        args = arguments(term)
    else
        @goto err
    end

    return escape ? Symbol(op, "(", join(args, ", "), ")") : op
    @label err
    error("Cannot convert $t to a symbol")
end

function lower_varname(var::Symbolic, idv, order)
    order == 0 && return var
    D = Differential(idv)
    for _ in 1:order
        var = D(var)
    end
    return diff2term(var)
end

"""
    makesym(x::Union{Num,Symbolic}, kwargs...) -> Sym

`makesym` takes the same arguments as [`tosymbol`](@ref), but it converts a
`Term` in the form of `x(t)` to a `Sym` in the form of `x⦗t⦘`.

# Examples
```julia
julia> @parameters t; @variables x(t)
(x(t),)

julia> Symbolics.makesym(x)
x⦗t⦘
```
"""
makesym(t::Symbolic; kwargs...) = Sym{symtype(t)}(tosymbol(t; kwargs...))
makesym(t::Num; kwargs...) = makesym(value(t); kwargs...)

var_from_nested_derivative(x, i=0) = (missing, missing)
var_from_nested_derivative(x::Term,i=0) = operation(x) isa Differential ? var_from_nested_derivative(arguments(x)[1],i+1) : (x,i)
var_from_nested_derivative(x::Sym,i=0) = (x,i)


text:
using DynamicPolynomials

using GroupsCore
include(joinpath(pathof(GroupsCore), "..", "..", "test", "cyclic.jl"))

x,y = @polyvar x y
struct By90Rotation <: SymbolicWedderburn.ByLinearTransformation end
# (x, y) → (x+y, x-y)/sqrt(2)

SymbolicWedderburn.coeff_type(::By90Rotation) = Float64
function SymbolicWedderburn.action(::By90Rotation, g::CyclicGroupElement, m::Monomial)
    isone(g) && return m
    x, y = variables(m)
    return m(x => (x+y)/sqrt(2), y => (x-y)/sqrt(2)) # we need the action to be orthogonal
end

function SymbolicWedderburn.decompose(k::AbstractPolynomial, hom::SymbolicWedderburn.InducedActionHomomorphism)
    # correct only if features(hom) == monomials

    indcs = [hom[m] for m in monomials(k)]
    coeffs = coefficients(k)

    return indcs, coeffs
end

@testset "Linear Actions" begin

    G = CyclicGroup(2)
    monomial_basis = monomials([x,y], 0:4)
    ehom = SymbolicWedderburn.ExtensionHomomorphism(By90Rotation(), monomial_basis)

    @testset "decomposition in basis" begin
        g = gens(G, 1)

        k = SymbolicWedderburn.action(By90Rotation(), g, monomial_basis[2])
        idcs, vals = SymbolicWedderburn.decompose(k, ehom)
        @test sum(c*monomial_basis[i] for (c,i) in zip(vals, idcs)) == k

        for b in monomial_basis
            k = SymbolicWedderburn.action(By90Rotation(), g, b)
            idcs, vals = SymbolicWedderburn.decompose(k, ehom)
            @test sum(c*monomial_basis[i] for (c,i) in zip(vals, idcs)) == k
        end
    end

    @testset "induced Matrix Representation" begin
        g = gens(G, 1)
        M = SymbolicWedderburn.induce(By90Rotation(), ehom, g)

        @test M isa AbstractMatrix{Float64}
        @test size(M) == (length(monomial_basis), length(monomial_basis))

        @test !(M ≈ one(M))
        @test M^2 ≈ one(M)

        sa_basis = symmetry_adapted_basis(Float64, G, By90Rotation(), monomial_basis);
        @test sum(first ∘ size, sa_basis) == length(monomial_basis)
    end
end


text:
using YaoLang
using YaoArrayRegister
using Flux.Optimise
using LinearAlgebra

@device function qcbm(n::Int, depth::Int, ps::Vector)
    count = 1
    @inbounds for k in 1:n
        k => Rx(ps[count])
        k => Rz(ps[count+1])
        count += 2
    end

    @inbounds for j in 1:depth-1
        for k in 1:n
            @ctrl k mod1(k + 1, n) => X
        end

        for k in 1:n
            k => Rz(ps[count])
            k => Rx(ps[count+1])
            k => Rz(ps[count+2])
            count += 3
        end
    end

    # last layer
    for k in 1:n
        @ctrl k mod1(k + 1, n) => X
    end

    @inbounds for k in 1:n
        k => Rz(ps[count])
        k => Rx(ps[count+1])
        count += 2
    end
end

function nparameters(n, depth)
    2n + 3n * (depth - 1) + 2n
end

function shift_gradient(qcbm, n, depth, κ, ps::Vector, ptrain)
    ∇ps = similar(ps)
    prob = probs(zero_state(n) |> qcbm(n, depth, ps))

    @inbounds for k in eachindex(ps)
        x = ps[k]
        ps[k] = x - π / 2
        prob_negative = probs(zero_state(n) |> qcbm(n, depth, ps))
        ps[k] = x + π / 2
        prob_positive = probs(zero_state(n) |> qcbm(n, depth, ps))
        ps[k] = x
        grad_pos = kexpect(κ, prob, prob_positive) - kexpect(κ, prob, prob_negative)
        grad_neg = kexpect(κ, ptrain, prob_positive) - kexpect(κ, ptrain, prob_negative)
        ∇ps[k] = grad_pos - grad_neg
    end
    return ∇ps
end

struct RBFKernel
    σ::Float64
    m::Matrix{Float64}
end

function RBFKernel(σ::Float64, space)
    dx2 = (space .- space') .^ 2
    return RBFKernel(σ, exp.(-1 / 2σ * dx2))
end

kexpect(κ::RBFKernel, x, y) = x' * κ.m * y

function loss(κ, qcbm, n, depth, ps, target)
    p = probs(zero_state(n) |> qcbm(n, depth, ps)) - target
    return kexpect(κ, p, p)
end

function gaussian_pdf(x, μ::Real, σ::Real)
    pl = @. 1 / sqrt(2pi * σ^2) * exp(-(x - μ)^2 / (2 * σ^2))
    pl / sum(pl)
end

function train(qcbm, n, depth, ps, κ, opt, target)
    history = Float64[]
    for _ in 1:100
        push!(history, loss(κ, qcbm, n, depth, ps, target))
        Optimise.update!(opt, ps, shift_gradient(qcbm, n, depth, κ, ps, target))
    end
    return history
end

n, depth = 10, 10
pg = gaussian_pdf(1:1<<n, 1 << (n - 1) - 0.5, 1 << 4);
κ = RBFKernel(0.25, 0:2^n-1)
opt = ADAM()
ps = rand(nparameters(n, depth))
train(qcbm, n, depth, ps, κ, opt, pg)


text:
using Parameters
using SpecialFunctions
using LinearAlgebra
using Tracker

@inline function calcgibbs(ph::U,T::W) where {U<:IdealPhase,W<:Real}
    return getGibbs.(getfield.(ph.species,:thermo),T)
end
export calcgibbs

@inline function calcenthalpyinternalgibbs(ph::U,T::W,P::Z,V::Q) where {U<:IdealPhase,W,Z,Q<:Real}
    Hs = getEnthalpy.(getfield.(ph.species,:thermo),T)
    Us = Hs .- P*V
    Gs = Hs .- T.*getEntropy.(getfield.(ph.species,:thermo),T)
    return Hs,Us,Gs
end

@inline function calcenthalpyinternalgibbs(ph::Union{IdealGas,IdealSurface},T::W,P::Z,V::Q) where {W,Z,Q<:Real}
    Hs = getEnthalpy.(getfield.(ph.species,:thermo),T)
    Us = Hs .- R*T
    Gs = Hs .- T.*getEntropy.(getfield.(ph.species,:thermo),T)
    return Hs,Us,Gs
end

export calcenthalpyinternalgibbs

function makespcsvector(phase,spcdict)
    y0 = zeros(length(phase.species))
    spnames = [x.name for x in phase.species]
    for (key,val) in spcdict
        if key == "T"
            continue
        elseif key == "P"
            continue
        elseif key == "V"
            continue
        else
            ind = findfirst(isequal(key),spnames)
            @assert typeof(ind)<: Integer  "$key not found in species list: $spnames"
            y0[ind] = val
        end
    end
    return y0
end

export makespcsvector

@inline function getkf(rxn::ElementaryReaction,ph::U,T::W1,P::W2,C::W3,ns::Q,V::W4) where {U<:AbstractPhase,W1,W2,W3,W4<:Real,Q<:AbstractArray}
    if isdefined(rxn.kinetics,:efficiencies) && length(rxn.kinetics.efficiencies) > 0
        @views @inbounds @fastmath C += sum([ns[i]*val for (i,val) in rxn.kinetics.efficiencies])/V
    end
    return rxn.kinetics(T=T,P=P,C=C)
end
export getkf

@inline function getkfs(ph::U,T::W1,P::W2,C::W3,ns::Q,V::W4) where {U<:AbstractPhase,W1,W2,W3,W4<:Real,Q<:AbstractArray}
    kfs = zeros(Q.parameters[1],length(ph.reactions))
    i = 1
    oldind = 1
    ind = 0
    while i <= length(ph.veckineticsinds) #vectorized kinetics
        @inbounds ind = ph.veckineticsinds[i]
        @inbounds kfs[oldind:ind] = ph.veckinetics[i](;T=T,P=P,C=C)
        oldind = ind+1
        i += 1
    end
    @simd for i in ind+1:length(ph.reactions)
        @inbounds kfs[i] = getkf(ph.reactions[i],ph,T,P,C,ns,V)
    end
    return kfs
end
export getkfs

"""
Calculates the diffusion limited rate coefficient
for 1 spc returns Inf
for 2 spc calculates using the Smolchowski equation
for >2 spc calculates using the Generalized Smolchowski equation
Equations from Flegg 2016
"""
@inline function getDiffusiveRate(spcs::Q,diffs::Array{W,1}) where {Q<:AbstractArray,W<:Real}
    if length(spcs) == 1
        return Inf
    elseif length(spcs) == 2
        @fastmath @inbounds kf = 4.0*Base.pi*(diffs[spcs[1].index]+diffs[spcs[2].index])*(spcs[1].radius+spcs[2].radius)*Na
    else
        @views @inbounds diffusivity = diffs[getfield.(spcs,:index)]
        N = length(spcs)
        @fastmath a = (3.0*length(spcs)-5.0)/2.0
        @fastmath Dinv = 1.0./diffusivity
        @fastmath Dbar = 1.0./reverse(cumsum(Dinv))
        @fastmath Dhat = diffusivity .+ Dbar
        @fastmath @inbounds deltaN = sum(Dinv)/sum([sum([1.0/(diffusivity[i]*diffusivity[m]) for m in 1:N-1 if i>m]) for i in 2:N])
        @views @fastmath @inbounds kf = prod(Dhat[2:end].^1.5)*4*Base.pi^(a+1)/gamma(a)*(sum(getfield.(spcs,:radius))/sqrt(deltaN))^(2*a)*Na^(N-1)
    end
    return kf
end
export getDiffusiveRate

@inline function getKc(rxn::ElementaryReaction,ph::U,T::Z,Gs::Q) where {U<:AbstractPhase,Q,Z<:Real}
    Nreact = length(rxn.reactantinds)
    Nprod = length(rxn.productinds)
    dGrxn = 0.0
    if Nreact == 1
        @fastmath @inbounds dGrxn -= Gs[rxn.reactantinds[1]]
    elseif Nreact == 2
        @fastmath @inbounds dGrxn -= Gs[rxn.reactantinds[1]]+Gs[rxn.reactantinds[2]]
    elseif Nreact == 3
        @fastmath @inbounds dGrxn -= Gs[rxn.reactantinds[1]]+Gs[rxn.reactantinds[2]]+Gs[rxn.reactantinds[3]]
    end
    if Nprod == 1
        @fastmath @inbounds dGrxn += Gs[rxn.productinds[1]]
    elseif Nprod == 2
        @fastmath @inbounds dGrxn += Gs[rxn.productinds[1]]+Gs[rxn.productinds[2]]
    elseif Nprod == 3
        @fastmath @inbounds dGrxn += Gs[rxn.productinds[1]]+Gs[rxn.productinds[2]]+Gs[rxn.productinds[3]]
    end
    return @inbounds @fastmath exp(-dGrxn/(R*T))*(1.0e5/(R*T))^(Nprod-Nreact)
end
export getKc

@inline function getKcs(ph::U,T::Z,Gs::Q) where {U<:AbstractPhase,Q,Z<:Real}
    return @fastmath @inbounds exp.(ph.stoichmatrix*(Gs./(R*T)) .+ ph.Nrp.*log(1.0e5/(R*T)));
end
export getKcs

"""
Calculates the forward and reverse rate coefficients for a given reaction, phase and state
Maintains diffusion limitations if the phase has diffusionlimited=true
"""
@inline function getkfkrev(rxn::ElementaryReaction,ph::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Q2,diffs::Q3,V::W5;kf::W6=-1.0,f::W7=-1.0) where {U<:AbstractPhase,W6,W7,W5,W4,W1,W2,W3<:Real,Q1,Q2,Q3<:AbstractArray}
    if signbit(kf)
        if signbit(f)
            kf = getkf(rxn,ph,T,P,C,ns,V)
        else
            kf = getkf(rxn,ph,T,P,C,ns,V)*f
        end
    end
    Kc = getKc(rxn,ph,T,Gs)
    @fastmath krev = kf/Kc
    if ph.diffusionlimited
        if length(rxn.reactants) == 1
            if length(rxn.products) > 1
                krevdiff = getDiffusiveRate(rxn.products,diffs)
                @fastmath krev = krev*krevdiff/(krev+krevdiff)
                @fastmath kf = Kc*krev
            end
        elseif length(rxn.products) == 1
            kfdiff = getDiffusiveRate(rxn.reactants,diffs)
            @fastmath kf = kf*kfdiff/(kf+kfdiff)
            @fastmath krev = kf/Kc
        elseif length(rxn.products) == length(rxn.reactants)
            kfdiff = getDiffusiveRate(rxn.reactants,diffs)
            krevdiff = getDiffusiveRate(rxn.products,diffs)
            @fastmath kff = kf*kfdiff/(kf+kfdiff)
            @fastmath krevr = krev*krevdiff/(krev+krevdiff)
            @fastmath kfr = Kc*krevr
            if kff > kfr
                kf = kfr
                krev = krevr
            else
                kf = kff
                @fastmath krev = kf/Kc
            end
        end
    end
    return (kf,krev)
end
export getkfkrev

@inline function getkfkrevs(phase::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Q2,diffs::Q3,V::W5;kfs::W6=nothing) where {U<:AbstractPhase,W6,W5<:Real,W1<:Real,W2<:Real,W3<:Real,W4<:Real, Q1<:AbstractArray,Q2<:Array{Float64,1},Q3<:AbstractArray}
    if !phase.diffusionlimited && kfs === nothing
        kfs = getkfs(phase,T,P,C,ns,V)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif !phase.diffusionlimited && !(kfs === nothing)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif phase.diffusionlimited && !(kfs === nothing)
        len = length(phase.reactions)
        krev = zeros(typeof(N),len)
        @simd for i = 1:len
           @fastmath @inbounds kfs[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V;kf=kfs[i])
        end
    else
        len = length(phase.reactions)
        kfs = zeros(typeof(N),len)
        krev = zeros(typeof(N),len)
        @simd for i = 1:len
           @fastmath @inbounds kfs[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V)
        end
    end
    return kfs,krev
end

@inline function getkfkrevs(phase::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Q2,diffs::Q3,V::W5;kfs::W6=nothing) where {U<:AbstractPhase,W6,W5<:Real,W1<:Real,W2<:Real,W3<:Real,W4<:Real, Q1<:AbstractArray,Q2,Q3<:AbstractArray} #autodiff p
    if !phase.diffusionlimited && kfs === nothing
        kfs = getkfs(phase,T,P,C,ns,V)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif !phase.diffusionlimited && !(kfs === nothing)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif phase.diffusionlimited && !(kfs === nothing)
        len = length(phase.reactions)
        krev = similar(kfs)
        kfsdiff = similar(kfs)
        @simd for i = 1:len
           @fastmath @inbounds kfsdiff[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V;kf=kfs[i])
        end
        return kfsdiff, krev
    else
        len = length(phase.reactions)
        kfs = zeros(typeof(Gs[1]),len)
        krev = zeros(typeof(Gs[1]),len)
        @simd for i = 1:len
           @fastmath @inbounds kfs[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V)
        end
    end
    return kfs,krev
end

@inline function getkfkrevs(phase::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Array{Q2,1},diffs::Q3,V::W5;kfs::W6=nothing) where {U<:AbstractPhase,W6,W5<:Real,W1<:Real,W2<:Real,W3<:Real,W4<:Real, Q1<:AbstractArray,Q2<:ForwardDiff.Dual,Q3<:AbstractArray} #autodiff p
    if !phase.diffusionlimited && kfs === nothing
        kfs = getkfs(phase,T,P,C,ns,V)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif !phase.diffusionlimited && !(kfs === nothing)
        krev = @fastmath kfs./getKcs(phase,T,Gs)
    elseif phase.diffusionlimited && !(kfs === nothing)
        len = length(phase.reactions)
        krev = similar(kfs)
        @simd for i = 1:len
           @fastmath @inbounds kfs[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V;kf=kfs[i])
        end
    else
        len = length(phase.reactions)
        kfs = zeros(typeof(Gs[1]),len)
        krev = zeros(typeof(Gs[1]),len)
        @simd for i = 1:len
           @fastmath @inbounds kfs[i],krev[i] = getkfkrev(phase.reactions[i],phase,T,P,C,N,ns,Gs,diffs,V)
        end
    end
    return kfs,krev
end

export getkfkrevs


text:
using NCDatasets

nm(x) = nomissing(x, NaN)

case_dir = "test01"
grid_dir = "$(case_dir)"
data_dir = "$(case_dir)/analysis_members"

Dataset("$(grid_dir)/grid.nc", "r") do ds
    global nCell = ds.dim["nCells"]
    global latCell = ds["latCell"][:]  |> nm .|> rad2deg
    global lonCell = ds["lonCell"][:]  |> nm .|> rad2deg
end

Dataset("$(data_dir)/timeSeriesStatsMonthly.2000-01.nc", "r") do ds
    global iceVol = ds["timeMonthly_avg_iceVolumeCell"][:] |> nm
end

println("Data loaded")
using PyPlot
plt = PyPlot

fig, ax = plt.subplots(1, 1, constrained_layout=true)

ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")

mapping = ax.scatter(lonCell, latCell, c=iceVol, s=10, cmap=plt.get_cmap("jet"))
cb = plt.colorbar(mapping, ax=ax)
cb.ax.set_ylabel("iceVolume \$ [ \\mathrm{m}^3 / \\mathrm{m}^2] \$")

plt.show()


text:
using DocTests
using Test

@testset "DocTests.jl" begin
    # Write your tests here.
end


text:
immutable PolyharmonicSpline{K,S} <: AbstractInterpolation
end

PolyharmonicSpline() = PolyharmonicSpline{2,Val{0}}
PolyharmonicSpline(K) = PolyharmonicSpline{K,Val{0}}
PolyharmonicSpline(K,S) = PolyharmonicSpline{K,Val{S}}

typealias ThinPlateSpline{S} PolyharmonicSpline{2,S}
ThinPlateSpline() = ThinPlateSpline{Val{0}}
ThinPlateSpline(S) = ThinPlateSpline{Val{S}}

function default_settings{D,T,K,S}(::Type{PolyharmonicSpline{K,S}},axes::NTuple{D,T})
    N = length(axes[1])
    return Irregular{D,N}, None
end

type PolyharmonicSplineInterpolation{T,D,N}
  coeff::Vector{T}
  values::Vector{T}
  centers::Array{T,2}
end

@inline function polyharmonicK(r,K)
    if iseven(K)
        p = r < 1.0 ? (r^(K-1))*log(r^r) : (r^K)*log(r)
    else
        p = r^K
    end
    return p
end

function preprocess{K,S}(phs::Type{PolyharmonicSpline{K,S}}, axes, f)
    values = convert(Array, f)
    centers = hcat(axes...)'
    n, m = size(centers)
    m != length(values) && throw(DimensionMismatch())

    M = zeros(m,m)
    N = zeros(m,n+1)

    @inbounds for i=1:m
        N[i,1] = 1
        N[i,2:end] = centers[:,i]
        for j=i:m
            M[i,j] = polyharmonicK(norm(centers[:,i] .- centers[:,j]),K)
            M[j,i] = M[i,j]
        end
    end
    s = S.parameters[1]
    M = M .+ s.*eye(m)
    L = [[M N]; [N' zeros(n+1,n+1)]]

    w = pinv(L)*[values; zeros(n+1)]

    w, centers, values = promote(w, centers, values)
    return PolyharmonicSplineInterpolation{eltype(w),n,length(w)}(w,values,centers)
end

function apply_bc{K,S}(::Type{PolyharmonicSpline{K,S}},BC::Type{None}, I::Symbol, x::Symbol)
    apply_none()
end

@inline function get_indices{K,S,D,N}(::Type{PolyharmonicSpline{K,S}}, G::Type{Irregular{D,N}}, I, x)
    return ()
end

@inline function get_value{K,S,T,D,N}(::Type{PolyharmonicSpline{K,S}}, I::PolyharmonicSplineInterpolation{T,D,N}, x, inds)
    v = zero(Float64)
    l = N - (D+1)
    centers = I.centers
    coeff = I.coeff
    @inbounds for i=1:l
        v = v + coeff[i]*polyharmonicK(norm(x .- centers[:,i]),K)
    end
    v = v + coeff[l+1]
    @inbounds for i=2:D+1
        v = v + coeff[l+i]*x[i-1]
    end
    return v
end


text:
# This file is a part of SimilaritySearch.jl

export NegativeDistanceHack, SimilarityFromDistance

"""
    NegativeDistanceHack(dist)

Evaluates as the negative of the distance function being wrapped.
This is not a real distance function but a simple hack to get a similarity and use it
for searching for farthest elements (farthest points / farthest pairs) on indexes that
can handle this hack (e.g., `ExhaustiveSearch`, `ParallelExhaustiveSearch`, `SearchGraph`).
"""
struct NegativeDistanceHack{Dist<:SemiMetric} <: SemiMetric
    dist::Dist
end

@inline evaluate(neg::NegativeDistanceHack, u, v) = -evaluate(neg.dist, u, v)

"""
    SimilarityFromDistance(dist)

Evaluates as ``1/(1 + d)`` for a distance evaluation ``d`` of `dist`.
This is not a distance function and is part of the hacks to get a similarity
for searching farthest elements on indexes that can handle this hack
(e.g., `ExhaustiveSearch`, `ParallelExhaustiveSearch`, `SearchGraph`).
"""
struct SimilarityFromDistance{Dist<:SemiMetric} <: SemiMetric
    dist::Dist
end

@inline evaluate(sim::SimilarityFromDistance, u, v) = 1 / (1 + evaluate(sim.dist, u, v))

max_stars_repo_name: sadit/SimilaritySearch

max_issues_repo_name: sadit/SimilaritySearch

max_forks_repo_name: sadit/SimilaritySearch


text:
function Burgers(x,t;α::Real=1.0,β::Real=0.0)::Float64
    y=mod(x-β*t,2π)
    if y≤π
        flag=2
    else
        flag=1
        y=2π-y
    end
    N=100
    y0=range(0,π,length=N)
    y1=similar(y0)
    @.y1=y0+α*sin(y0)*t
    ℓ= α≥0 ? findlast(y1.≤y) : findfirst(y1.≥y)
    v=α*sin(y0[ℓ])
    err=abs(v-α*sin(y-t*v))
    while err > 1e-13
        v=v-(v-α*sin(y-t*v))/(1+α*t*cos(y-t*v))
        err=abs(v-α*sin(y-t*v))
    end
    u=(-1)^flag*v+β
end
function Burgers(x::AbstractArray,t;α::Real=1.0,β::Real=0.0)
    N=100
    y0=range(0,π,length=N)
    y1=y0+α*sin.(y0)*t
    y=mod.(x.-β*t,2π)
    u=similar(y)
    @inbounds Threads.@threads for k=1:length(u)
        if y[k]≤π
            flag=2
        else
            flag=1
            y[k]=2π-y[k]
        end
        ℓ= α≥0 ? findlast(y1.≤y[k]) : findfirst(y1.≥y[k])
        v=α*sin(y0[ℓ])
        err=abs(v-α*sin(y[k]-t*v))
        while err > 1e-13
            v=v-(v-α*sin(y[k]-t*v))/(1+α*t*cos(y[k]-t*v))
            err=abs(v-α*sin(y[k]-t*v))
        end
        u[k]=(-1)^flag*v+β
    end
    u
end

function Burgers(x,y,t;α::Real=1.0,β::Real=0.0)
    Burgers(x+y,2t;α=α,β=β)
end

function errLp(u::Function,mesh::Grid2DRect,U::AbstractMatrix,
    t,quad1D_num::Integer=10;p=2)::Float64
    P_dof=size(U,1)
    P_order=isqrt(P_dof)-1
    quad1D_p=range(-1,1,length=quad1D_num)
    quad_num=quad1D_num^2
    quad_p=Array{Float64,2}(undef,quad_num,2)
    quad_w=1/quad_num
    for ℓ₁=1:quad1D_num, ℓ₂=1:quad1D_num
        ℓ=(ℓ₂-1)*quad1D_num+ℓ₁
        quad_p[ℓ,1]=quad1D_p[ℓ₁]
        quad_p[ℓ,2]=quad1D_p[ℓ₂]
    end
    basisP = Array{Float64,2}(undef,P_dof,quad_num)
    for i=0:P_order, j=0:P_order, ℓ=1:quad_num
        basisP[i*(P_order+1)+j+1,ℓ]=JacobiP(i,0,0,quad_p[ℓ,1])*JacobiP(j,0,0,quad_p[ℓ,2])
    end
    quad_p = ( quad_p .+1 ) / 2 # uniform_p now is in [0,1].
    err = 0.0
    uₕ=basisP'*U
    if p<Inf
        @inbounds for j=1:mesh.NumofE
            x₁=mesh.Coordinates[mesh.Elements[1,j],1]
            x₂=mesh.Coordinates[mesh.Elements[2,j],1]
            y₁=mesh.Coordinates[mesh.Elements[1,j],2]
            y₂=mesh.Coordinates[mesh.Elements[4,j],2]
            for ℓ=1:quad_num
                x_ℓj=(1-quad_p[ℓ,1])*x₁+quad_p[ℓ,1]*x₂
                y_ℓj=(1-quad_p[ℓ,2])*y₁+quad_p[ℓ,2]*y₂
                u_ℓj=u(x_ℓj,y_ℓj,t)
                err+=mesh.Tarea[j]*quad_w*abs(u_ℓj-uₕ[ℓ,j])^p
            end
        end
        err=err^(1/p)
    else
        @inbounds for j=1:mesh.NumofE
            x₁=mesh.Coordinates[mesh.Elements[1,j],1]
            x₂=mesh.Coordinates[mesh.Elements[2,j],1]
            y₁=mesh.Coordinates[mesh.Elements[1,j],2]
            y₂=mesh.Coordinates[mesh.Elements[4,j],2]
            for ℓ=1:quad_num
                x_ℓj=(1-quad_p[ℓ,1])*x₁+quad_p[ℓ,1]*x₂
                y_ℓj=(1-quad_p[ℓ,2])*y₁+quad_p[ℓ,2]*y₂
                u_ℓj=u(x_ℓj,y_ℓj,t)
                Δu_ℓj=abs(u_ℓj-uₕ[ℓ,j])
                err=max(err,Δu_ℓj)
            end
        end
    end
    err
end


text:
begin
	function normalize_num(v,KL)
		R = 0
		i = 0
		n = 0
		x = 0
		y = 0

		while true
			if v & Int128(2)^i != 0
				R |= Int128(2)^x
			end
			x += 1
			i += 1
			n += 1
			if (KL & Int128(2)^n) != 0
				if x == 1
					R |= 1
					break
				end
				x = 0
				n += 1
			end
		end
		R
	end
	function not(v)
		v $ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
	end

	J1_5 = 221535295005332079421278918372840789
	J2_5 = 265843691043184692583024226401150566
	J3_5 = 312757189261815779310224648909125752
	J4_5 = 331011454359735873466059311716269952
	J5_5 = 332301083698321892166315820995018752
	KL_5 = 951498461772324920048247814144335051808047104

	function primtest()
		# binary 11101 -> 29
		v = J1_5 & not(J2_5) & J3_5 & J4_5 & J5_5
		v = normalize_num(v,KL_5)
		x = 2^0 | 2^28
		v = v $ x
		R = (v==0)
		R
	end

	@time print(primtest())
	@time print(isprime(29))

	#Output:
	#true  0.250568 seconds (104.94 k allocations: 4.327 MB)
	#true  0.045355 seconds (34.15 k allocations: 1.562 MB)

	# Oh well ,we loose this by time :(, but only they "cheat" by using a PRIME table.
	# (it basically just looks up any number < 2^16 in a table that way.)
	# See https://github.com/JuliaLang/julia/blob/master/base/primes.jl
	# But might have more performance on big numbers!

end

max_stars_repo_name: TheCrazyT/factorisation-maps

max_issues_repo_name: TheCrazyT/factorisation-maps

max_forks_repo_name: TheCrazyT/factorization-maps


text:
@safetestset "Parsing of route arguments with types" begin

  using Genie, Dates, HTTP

  Base.convert(::Type{Float64}, s::AbstractString) = parse(Float64, s)
  Base.convert(::Type{Int}, s::AbstractString) = parse(Int, s)
  Base.convert(::Type{Dates.Date}, s::AbstractString) = Date(s)

  route("/getparams/:s::String/:f::Float64/:i::Int/:d::Date", context = @__MODULE__) do
    "s = $(params(:s)) / f = $(params(:f)) / i = $(params(:i)) / $(params(:d))"
  end

  port = nothing
  port = rand(8500:8900)

  server = up(port; open_browser = false)

  response = HTTP.get("http://localhost:$port/getparams/foo/23.43/18/2019-02-15")

  @test response.status == 200
  @test String(response.body) == "s = foo / f = 23.43 / i = 18 / 2019-02-15"

  down()
  sleep(1)
  server = nothing
  port = nothing
end


text:
mutable struct pointfield_t <: LCMType
    name::String
    offset::Int32
    datatype::Int8
    count::Int32
end

@lcmtypesetup(pointfield_t)


text:
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

name = "Modflow6"
version = v"6.2.2"

# Collection of sources required to complete build
sources = [
    GitSource("https://github.com/MODFLOW-USGS/modflow6.git", "04ab9e1a9ccf428a16f84c477aa24ac76dd56224")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/modflow6

# lower the minimum required meson version
sed -i s/0.59.0/0.58.0/ meson.build

meson -Ddebug=false -Doptimization=2 --cross-file=${MESON_TARGET_TOOLCHAIN} builddir
meson compile -C builddir -j${nproc}
meson install -C builddir
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = supported_platforms(; experimental=true)
platforms = expand_gfortran_versions(platforms)

# The products that we will ensure are always built
products = [
    LibraryProduct("libmf6", :libmf6),
    ExecutableProduct("mf6", :mf6),
    ExecutableProduct("zbud6", :zbud6),
    ExecutableProduct("mf5to6", :mf5to6)
]

# Dependencies that must be installed before this package can be built
dependencies = Dependency[
    Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae")),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version = v"5.2.0")

max_stars_repo_name: sharanry/Yggdrasil

max_issues_repo_name: sharanry/Yggdrasil

max_forks_repo_name: sharanry/Yggdrasil


text:
# Utility functions for space data analysis.

using ImageFiltering, OffsetArrays, FFTW, Statistics, LinearAlgebra

export mag2db, sma, spectrum

"Convert `x` from magnitude to decibels."
mag2db(x) = 10. * log10.(x)

"""
    sma(x, n=(5,5))

Simple moving average of `x` with `n[1]` leading and `n[2]` trailing points.
Default boundary is "replicate", meaning that the border pixels extend beyond
the boundaries.
"""
function sma(x, n::Tuple{Int,Int}=(5,5))
   len = sum(n) + 1
   kernel = OffsetArray(fill(1/len, len), -n[1]:n[2])
   imfilter(x, kernel)
end

"""
    sma(x, n=5)

Simple moving box average of the vector data `x` with box length 'n'.
One-sided average on the left and right edge with replicate border.
"""
function sma(x::Vector, n::Int=5)
   iseven(n) && @warn "Even box length detected!"
   sma(x, ((n-1)÷2, (n-1)÷2))
end

"""
    spectrum(x, Fs)

Return the frequency and amplitude for the single-sided spectrum of vector `x`
given sample frequency of `Fs`.
"""
function spectrum(x::Vector, Fs)
   L = length(x)
   x̃ = fft(x)
   # Compute the two-sided spectrum amplitude P2.
   P₂ = @. abs(x̃/L)
   # Compute the single-sided spectrum amplitude P1.
   P₁ = P₂[1:floor(Int, L/2+1)]
   P₁[2:end-1] .= 2 .* P₁[2:end-1]

   f = Fs * (0:(L/2)) / L

   f, P₁
end