text:
# Julia wrapper for header: MessageFederate.h
# Automatically generated using Clang.jl

function helicsFederateRegisterEndpoint(fed, name, type, err)
    ccall((:helicsFederateRegisterEndpoint, libhelicsSharedLib), helics_endpoint, (helics_federate, Cstring, Cstring, Ptr{helics_error}), fed, name, type, err)
end

function helicsFederateRegisterGlobalEndpoint(fed, name, type, err)
    ccall((:helicsFederateRegisterGlobalEndpoint, libhelicsSharedLib), helics_endpoint, (helics_federate, Cstring, Cstring, Ptr{helics_error}), fed, name, type, err)
end

function helicsFederateGetEndpoint(fed, name, err)
    ccall((:helicsFederateGetEndpoint, libhelicsSharedLib), helics_endpoint, (helics_federate, Cstring, Ptr{helics_error}), fed, name, err)
end

function helicsFederateGetEndpointByIndex(fed, index, err)
    ccall((:helicsFederateGetEndpointByIndex, libhelicsSharedLib), helics_endpoint, (helics_federate, Cint, Ptr{helics_error}), fed, index, err)
end

function helicsEndpointIsValid(endpoint)
    ccall((:helicsEndpointIsValid, libhelicsSharedLib), helics_bool, (helics_endpoint,), endpoint)
end

function helicsEndpointSetDefaultDestination(endpoint, dest, err)
    ccall((:helicsEndpointSetDefaultDestination, libhelicsSharedLib), Cvoid, (helics_endpoint, Cstring, Ptr{helics_error}), endpoint, dest, err)
end

function helicsEndpointGetDefaultDestination(endpoint)
    ccall((:helicsEndpointGetDefaultDestination, libhelicsSharedLib), Cstring, (helics_endpoint,), endpoint)
end

function helicsEndpointSendMessageRaw(endpoint, dest, data, inputDataLength, err)
    ccall((:helicsEndpointSendMessageRaw, libhelicsSharedLib), Cvoid, (helics_endpoint, Cstring, Ptr{Cvoid}, Cint, Ptr{helics_error}), endpoint, dest, data, inputDataLength, err)
end

function helicsEndpointSendEventRaw(endpoint, dest, data, inputDataLength, time, err)
    ccall((:helicsEndpointSendEventRaw, libhelicsSharedLib), Cvoid, (helics_endpoint, Cstring, Ptr{Cvoid}, Cint, helics_time, Ptr{helics_error}), endpoint, dest, data, inputDataLength, time, err)
end

function helicsEndpointSendMessage(endpoint, message, err)
    ccall((:helicsEndpointSendMessage, libhelicsSharedLib), Cvoid, (helics_endpoint, Ptr{helics_message}, Ptr{helics_error}), endpoint, message, err)
end

function helicsEndpointSendMessageObject(endpoint, message, err)
    ccall((:helicsEndpointSendMessageObject, libhelicsSharedLib), Cvoid, (helics_endpoint, helics_message_object, Ptr{helics_error}), endpoint, message, err)
end

function helicsEndpointSendMessageObjectZeroCopy(endpoint, message, err)
    ccall((:helicsEndpointSendMessageObjectZeroCopy, libhelicsSharedLib), Cvoid, (helics_endpoint, helics_message_object, Ptr{helics_error}), endpoint, message, err)
end

function helicsEndpointSubscribe(endpoint, key, err)
    ccall((:helicsEndpointSubscribe, libhelicsSharedLib), Cvoid, (helics_endpoint, Cstring, Ptr{helics_error}), endpoint, key, err)
end

function helicsFederateHasMessage(fed)
    ccall((:helicsFederateHasMessage, libhelicsSharedLib), helics_bool, (helics_federate,), fed)
end

function helicsEndpointHasMessage(endpoint)
    ccall((:helicsEndpointHasMessage, libhelicsSharedLib), helics_bool, (helics_endpoint,), endpoint)
end

function helicsFederatePendingMessages(fed)
    ccall((:helicsFederatePendingMessages, libhelicsSharedLib), Cint, (helics_federate,), fed)
end

function helicsEndpointPendingMessages(endpoint)
    ccall((:helicsEndpointPendingMessages, libhelicsSharedLib), Cint, (helics_endpoint,), endpoint)
end

function helicsEndpointGetMessage(endpoint)
    ccall((:helicsEndpointGetMessage, libhelicsSharedLib), helics_message, (helics_endpoint,), endpoint)
end

function helicsEndpointGetMessageObject(endpoint)
    ccall((:helicsEndpointGetMessageObject, libhelicsSharedLib), helics_message_object, (helics_endpoint,), endpoint)
end

function helicsEndpointCreateMessageObject(endpoint, err)
    ccall((:helicsEndpointCreateMessageObject, libhelicsSharedLib), helics_message_object, (helics_endpoint, Ptr{helics_error}), endpoint, err)
end

function helicsFederateGetMessage(fed)
    ccall((:helicsFederateGetMessage, libhelicsSharedLib), helics_message, (helics_federate,), fed)
end

function helicsFederateGetMessageObject(fed)
    ccall((:helicsFederateGetMessageObject, libhelicsSharedLib), helics_message_object, (helics_federate,), fed)
end

function helicsFederateCreateMessageObject(fed, err)
    ccall((:helicsFederateCreateMessageObject, libhelicsSharedLib), helics_message_object, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateClearMessages(fed)
    ccall((:helicsFederateClearMessages, libhelicsSharedLib), Cvoid, (helics_federate,), fed)
end

function helicsEndpointClearMessages(endpoint)
    ccall((:helicsEndpointClearMessages, libhelicsSharedLib), Cvoid, (helics_endpoint,), endpoint)
end

function helicsEndpointGetType(endpoint)
    ccall((:helicsEndpointGetType, libhelicsSharedLib), Cstring, (helics_endpoint,), endpoint)
end

function helicsEndpointGetName(endpoint)
    ccall((:helicsEndpointGetName, libhelicsSharedLib), Cstring, (helics_endpoint,), endpoint)
end

function helicsFederateGetEndpointCount(fed)
    ccall((:helicsFederateGetEndpointCount, libhelicsSharedLib), Cint, (helics_federate,), fed)
end

function helicsEndpointGetInfo(_end)
    ccall((:helicsEndpointGetInfo, libhelicsSharedLib), Cstring, (helics_endpoint,), _end)
end

function helicsEndpointSetInfo(_end, info, err)
    ccall((:helicsEndpointSetInfo, libhelicsSharedLib), Cvoid, (helics_endpoint, Cstring, Ptr{helics_error}), _end, info, err)
end

function helicsEndpointSetOption(_end, option, value, err)
    ccall((:helicsEndpointSetOption, libhelicsSharedLib), Cvoid, (helics_endpoint, Cint, Cint, Ptr{helics_error}), _end, option, value, err)
end

function helicsEndpointGetOption(_end, option)
    ccall((:helicsEndpointGetOption, libhelicsSharedLib), Cint, (helics_endpoint, Cint), _end, option)
end

function helicsMessageGetSource(message)
    ccall((:helicsMessageGetSource, libhelicsSharedLib), Cstring, (helics_message_object,), message)
end

function helicsMessageGetDestination(message)
    ccall((:helicsMessageGetDestination, libhelicsSharedLib), Cstring, (helics_message_object,), message)
end

function helicsMessageGetOriginalSource(message)
    ccall((:helicsMessageGetOriginalSource, libhelicsSharedLib), Cstring, (helics_message_object,), message)
end

function helicsMessageGetOriginalDestination(message)
    ccall((:helicsMessageGetOriginalDestination, libhelicsSharedLib), Cstring, (helics_message_object,), message)
end

function helicsMessageGetTime(message)
    ccall((:helicsMessageGetTime, libhelicsSharedLib), helics_time, (helics_message_object,), message)
end

function helicsMessageGetString(message)
    ccall((:helicsMessageGetString, libhelicsSharedLib), Cstring, (helics_message_object,), message)
end

function helicsMessageGetMessageID(message)
    ccall((:helicsMessageGetMessageID, libhelicsSharedLib), Cint, (helics_message_object,), message)
end

function helicsMessageCheckFlag(message, flag)
    ccall((:helicsMessageCheckFlag, libhelicsSharedLib), helics_bool, (helics_message_object, Cint), message, flag)
end

function helicsMessageGetRawDataSize(message)
    ccall((:helicsMessageGetRawDataSize, libhelicsSharedLib), Cint, (helics_message_object,), message)
end

function helicsMessageGetRawData(message, data, maxMessagelen, actualSize, err)
    ccall((:helicsMessageGetRawData, libhelicsSharedLib), Cvoid, (helics_message_object, Ptr{Cvoid}, Cint, Ptr{Cint}, Ptr{helics_error}), message, data, maxMessagelen, actualSize, err)
end

function helicsMessageGetRawDataPointer(message)
    ccall((:helicsMessageGetRawDataPointer, libhelicsSharedLib), Ptr{Cvoid}, (helics_message_object,), message)
end

function helicsMessageIsValid(message)
    ccall((:helicsMessageIsValid, libhelicsSharedLib), helics_bool, (helics_message_object,), message)
end

function helicsMessageSetSource(message, src, err)
    ccall((:helicsMessageSetSource, libhelicsSharedLib), Cvoid, (helics_message_object, Cstring, Ptr{helics_error}), message, src, err)
end

function helicsMessageSetDestination(message, dest, err)
    ccall((:helicsMessageSetDestination, libhelicsSharedLib), Cvoid, (helics_message_object, Cstring, Ptr{helics_error}), message, dest, err)
end

function helicsMessageSetOriginalSource(message, src, err)
    ccall((:helicsMessageSetOriginalSource, libhelicsSharedLib), Cvoid, (helics_message_object, Cstring, Ptr{helics_error}), message, src, err)
end

function helicsMessageSetOriginalDestination(message, dest, err)
    ccall((:helicsMessageSetOriginalDestination, libhelicsSharedLib), Cvoid, (helics_message_object, Cstring, Ptr{helics_error}), message, dest, err)
end

function helicsMessageSetTime(message, time, err)
    ccall((:helicsMessageSetTime, libhelicsSharedLib), Cvoid, (helics_message_object, helics_time, Ptr{helics_error}), message, time, err)
end

function helicsMessageResize(message, newSize, err)
    ccall((:helicsMessageResize, libhelicsSharedLib), Cvoid, (helics_message_object, Cint, Ptr{helics_error}), message, newSize, err)
end

function helicsMessageReserve(message, reserveSize, err)
    ccall((:helicsMessageReserve, libhelicsSharedLib), Cvoid, (helics_message_object, Cint, Ptr{helics_error}), message, reserveSize, err)
end

function helicsMessageSetMessageID(message, messageID, err)
    ccall((:helicsMessageSetMessageID, libhelicsSharedLib), Cvoid, (helics_message_object, Int32, Ptr{helics_error}), message, messageID, err)
end

function helicsMessageClearFlags(message)
    ccall((:helicsMessageClearFlags, libhelicsSharedLib), Cvoid, (helics_message_object,), message)
end

function helicsMessageSetFlagOption(message, flag, flagValue, err)
    ccall((:helicsMessageSetFlagOption, libhelicsSharedLib), Cvoid, (helics_message_object, Cint, helics_bool, Ptr{helics_error}), message, flag, flagValue, err)
end

function helicsMessageSetString(message, str, err)
    ccall((:helicsMessageSetString, libhelicsSharedLib), Cvoid, (helics_message_object, Cstring, Ptr{helics_error}), message, str, err)
end

function helicsMessageSetData(message, data, inputDataLength, err)
    ccall((:helicsMessageSetData, libhelicsSharedLib), Cvoid, (helics_message_object, Ptr{Cvoid}, Cint, Ptr{helics_error}), message, data, inputDataLength, err)
end

function helicsMessageAppendData(message, data, inputDataLength, err)
    ccall((:helicsMessageAppendData, libhelicsSharedLib), Cvoid, (helics_message_object, Ptr{Cvoid}, Cint, Ptr{helics_error}), message, data, inputDataLength, err)
end

function helicsMessageCopy(source_message, dest_message, err)
    ccall((:helicsMessageCopy, libhelicsSharedLib), Cvoid, (helics_message_object, helics_message_object, Ptr{helics_error}), source_message, dest_message, err)
end

function helicsMessageClone(message, err)
    ccall((:helicsMessageClone, libhelicsSharedLib), helics_message_object, (helics_message_object, Ptr{helics_error}), message, err)
end

function helicsMessageFree(message)
    ccall((:helicsMessageFree, libhelicsSharedLib), Cvoid, (helics_message_object,), message)
end
# Julia wrapper for header: MessageFilters.h
# Automatically generated using Clang.jl

function helicsFederateRegisterFilter(fed, type, name, err)
    ccall((:helicsFederateRegisterFilter, libhelicsSharedLib), helics_filter, (helics_federate, helics_filter_type, Cstring, Ptr{helics_error}), fed, type, name, err)
end

function helicsFederateRegisterGlobalFilter(fed, type, name, err)
    ccall((:helicsFederateRegisterGlobalFilter, libhelicsSharedLib), helics_filter, (helics_federate, helics_filter_type, Cstring, Ptr{helics_error}), fed, type, name, err)
end

function helicsFederateRegisterCloningFilter(fed, name, err)
    ccall((:helicsFederateRegisterCloningFilter, libhelicsSharedLib), helics_filter, (helics_federate, Cstring, Ptr{helics_error}), fed, name, err)
end

function helicsFederateRegisterGlobalCloningFilter(fed, name, err)
    ccall((:helicsFederateRegisterGlobalCloningFilter, libhelicsSharedLib), helics_filter, (helics_federate, Cstring, Ptr{helics_error}), fed, name, err)
end

function helicsCoreRegisterFilter(core, type, name, err)
    ccall((:helicsCoreRegisterFilter, libhelicsSharedLib), helics_filter, (helics_core, helics_filter_type, Cstring, Ptr{helics_error}), core, type, name, err)
end

function helicsCoreRegisterCloningFilter(core, name, err)
    ccall((:helicsCoreRegisterCloningFilter, libhelicsSharedLib), helics_filter, (helics_core, Cstring, Ptr{helics_error}), core, name, err)
end

function helicsFederateGetFilterCount(fed)
    ccall((:helicsFederateGetFilterCount, libhelicsSharedLib), Cint, (helics_federate,), fed)
end

function helicsFederateGetFilter(fed, name, err)
    ccall((:helicsFederateGetFilter, libhelicsSharedLib), helics_filter, (helics_federate, Cstring, Ptr{helics_error}), fed, name, err)
end

function helicsFederateGetFilterByIndex(fed, index, err)
    ccall((:helicsFederateGetFilterByIndex, libhelicsSharedLib), helics_filter, (helics_federate, Cint, Ptr{helics_error}), fed, index, err)
end

function helicsFilterIsValid(filt)
    ccall((:helicsFilterIsValid, libhelicsSharedLib), helics_bool, (helics_filter,), filt)
end

function helicsFilterGetName(filt)
    ccall((:helicsFilterGetName, libhelicsSharedLib), Cstring, (helics_filter,), filt)
end

function helicsFilterSet(filt, prop, val, err)
    ccall((:helicsFilterSet, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Cdouble, Ptr{helics_error}), filt, prop, val, err)
end

function helicsFilterSetString(filt, prop, val, err)
    ccall((:helicsFilterSetString, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Cstring, Ptr{helics_error}), filt, prop, val, err)
end

function helicsFilterAddDestinationTarget(filt, dest, err)
    ccall((:helicsFilterAddDestinationTarget, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, dest, err)
end

function helicsFilterAddSourceTarget(filt, source, err)
    ccall((:helicsFilterAddSourceTarget, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, source, err)
end

function helicsFilterAddDeliveryEndpoint(filt, deliveryEndpoint, err)
    ccall((:helicsFilterAddDeliveryEndpoint, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, deliveryEndpoint, err)
end

function helicsFilterRemoveTarget(filt, target, err)
    ccall((:helicsFilterRemoveTarget, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, target, err)
end

function helicsFilterRemoveDeliveryEndpoint(filt, deliveryEndpoint, err)
    ccall((:helicsFilterRemoveDeliveryEndpoint, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, deliveryEndpoint, err)
end

function helicsFilterGetInfo(filt)
    ccall((:helicsFilterGetInfo, libhelicsSharedLib), Cstring, (helics_filter,), filt)
end

function helicsFilterSetInfo(filt, info, err)
    ccall((:helicsFilterSetInfo, libhelicsSharedLib), Cvoid, (helics_filter, Cstring, Ptr{helics_error}), filt, info, err)
end

function helicsFilterSetOption(filt, option, value, err)
    ccall((:helicsFilterSetOption, libhelicsSharedLib), Cvoid, (helics_filter, Cint, Cint, Ptr{helics_error}), filt, option, value, err)
end

function helicsFilterGetOption(filt, option)
    ccall((:helicsFilterGetOption, libhelicsSharedLib), Cint, (helics_filter, Cint), filt, option)
end
# Julia wrapper for header: ValueFederate.h
# Automatically generated using Clang.jl

function helicsFederateRegisterSubscription(fed, key, units, err)
    ccall((:helicsFederateRegisterSubscription, libhelicsSharedLib), helics_input, (helics_federate, Cstring, Cstring, Ptr{helics_error}), fed, key, units, err)
end

function helicsFederateRegisterPublication(fed, key, type, units, err)
    ccall((:helicsFederateRegisterPublication, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, helics_data_type, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterTypePublication(fed, key, type, units, err)
    ccall((:helicsFederateRegisterTypePublication, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, Cstring, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterGlobalPublication(fed, key, type, units, err)
    ccall((:helicsFederateRegisterGlobalPublication, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, helics_data_type, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterGlobalTypePublication(fed, key, type, units, err)
    ccall((:helicsFederateRegisterGlobalTypePublication, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, Cstring, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterInput(fed, key, type, units, err)
    ccall((:helicsFederateRegisterInput, libhelicsSharedLib), helics_input, (helics_federate, Cstring, helics_data_type, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterTypeInput(fed, key, type, units, err)
    ccall((:helicsFederateRegisterTypeInput, libhelicsSharedLib), helics_input, (helics_federate, Cstring, Cstring, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterGlobalInput(fed, key, type, units, err)
    ccall((:helicsFederateRegisterGlobalInput, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, helics_data_type, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateRegisterGlobalTypeInput(fed, key, type, units, err)
    ccall((:helicsFederateRegisterGlobalTypeInput, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, Cstring, Cstring, Ptr{helics_error}), fed, key, type, units, err)
end

function helicsFederateGetPublication(fed, key, err)
    ccall((:helicsFederateGetPublication, libhelicsSharedLib), helics_publication, (helics_federate, Cstring, Ptr{helics_error}), fed, key, err)
end

function helicsFederateGetPublicationByIndex(fed, index, err)
    ccall((:helicsFederateGetPublicationByIndex, libhelicsSharedLib), helics_publication, (helics_federate, Cint, Ptr{helics_error}), fed, index, err)
end

function helicsFederateGetInput(fed, key, err)
    ccall((:helicsFederateGetInput, libhelicsSharedLib), helics_input, (helics_federate, Cstring, Ptr{helics_error}), fed, key, err)
end

function helicsFederateGetInputByIndex(fed, index, err)
    ccall((:helicsFederateGetInputByIndex, libhelicsSharedLib), helics_input, (helics_federate, Cint, Ptr{helics_error}), fed, index, err)
end

function helicsFederateGetSubscription(fed, key, err)
    ccall((:helicsFederateGetSubscription, libhelicsSharedLib), helics_input, (helics_federate, Cstring, Ptr{helics_error}), fed, key, err)
end

function helicsFederateClearUpdates(fed)
    ccall((:helicsFederateClearUpdates, libhelicsSharedLib), Cvoid, (helics_federate,), fed)
end

function helicsFederateRegisterFromPublicationJSON(fed, json, err)
    ccall((:helicsFederateRegisterFromPublicationJSON, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, json, err)
end

function helicsFederatePublishJSON(fed, json, err)
    ccall((:helicsFederatePublishJSON, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, json, err)
end

function helicsPublicationIsValid(pub)
    ccall((:helicsPublicationIsValid, libhelicsSharedLib), helics_bool, (helics_publication,), pub)
end

function helicsPublicationPublishRaw(pub, data, inputDataLength, err)
    ccall((:helicsPublicationPublishRaw, libhelicsSharedLib), Cvoid, (helics_publication, Ptr{Cvoid}, Cint, Ptr{helics_error}), pub, data, inputDataLength, err)
end

function helicsPublicationPublishString(pub, str, err)
    ccall((:helicsPublicationPublishString, libhelicsSharedLib), Cvoid, (helics_publication, Cstring, Ptr{helics_error}), pub, str, err)
end

function helicsPublicationPublishInteger(pub, val, err)
    ccall((:helicsPublicationPublishInteger, libhelicsSharedLib), Cvoid, (helics_publication, Int64, Ptr{helics_error}), pub, val, err)
end

function helicsPublicationPublishBoolean(pub, val, err)
    ccall((:helicsPublicationPublishBoolean, libhelicsSharedLib), Cvoid, (helics_publication, helics_bool, Ptr{helics_error}), pub, val, err)
end

function helicsPublicationPublishDouble(pub, val, err)
    ccall((:helicsPublicationPublishDouble, libhelicsSharedLib), Cvoid, (helics_publication, Cdouble, Ptr{helics_error}), pub, val, err)
end

function helicsPublicationPublishTime(pub, val, err)
    ccall((:helicsPublicationPublishTime, libhelicsSharedLib), Cvoid, (helics_publication, helics_time, Ptr{helics_error}), pub, val, err)
end

function helicsPublicationPublishChar(pub, val, err)
    ccall((:helicsPublicationPublishChar, libhelicsSharedLib), Cvoid, (helics_publication, UInt8, Ptr{helics_error}), pub, val, err)
end

function helicsPublicationPublishComplex(pub, real, imag, err)
    ccall((:helicsPublicationPublishComplex, libhelicsSharedLib), Cvoid, (helics_publication, Cdouble, Cdouble, Ptr{helics_error}), pub, real, imag, err)
end

function helicsPublicationPublishVector(pub, vectorInput, vectorLength, err)
    ccall((:helicsPublicationPublishVector, libhelicsSharedLib), Cvoid, (helics_publication, Ptr{Cdouble}, Cint, Ptr{helics_error}), pub, vectorInput, vectorLength, err)
end

function helicsPublicationPublishNamedPoint(pub, str, val, err)
    ccall((:helicsPublicationPublishNamedPoint, libhelicsSharedLib), Cvoid, (helics_publication, Cstring, Cdouble, Ptr{helics_error}), pub, str, val, err)
end

function helicsPublicationAddTarget(pub, target, err)
    ccall((:helicsPublicationAddTarget, libhelicsSharedLib), Cvoid, (helics_publication, Cstring, Ptr{helics_error}), pub, target, err)
end

function helicsInputIsValid(ipt)
    ccall((:helicsInputIsValid, libhelicsSharedLib), helics_bool, (helics_input,), ipt)
end

function helicsInputAddTarget(ipt, target, err)
    ccall((:helicsInputAddTarget, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Ptr{helics_error}), ipt, target, err)
end

function helicsInputGetRawValueSize(ipt)
    ccall((:helicsInputGetRawValueSize, libhelicsSharedLib), Cint, (helics_input,), ipt)
end

function helicsInputGetRawValue(ipt, data, maxDatalen, actualSize, err)
    ccall((:helicsInputGetRawValue, libhelicsSharedLib), Cvoid, (helics_input, Ptr{Cvoid}, Cint, Ptr{Cint}, Ptr{helics_error}), ipt, data, maxDatalen, actualSize, err)
end

function helicsInputGetStringSize(ipt)
    ccall((:helicsInputGetStringSize, libhelicsSharedLib), Cint, (helics_input,), ipt)
end

function helicsInputGetString(ipt, outputString, maxStringLen, actualLength, err)
    ccall((:helicsInputGetString, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Cint, Ptr{Cint}, Ptr{helics_error}), ipt, outputString, maxStringLen, actualLength, err)
end

function helicsInputGetInteger(ipt, err)
    ccall((:helicsInputGetInteger, libhelicsSharedLib), Int64, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetBoolean(ipt, err)
    ccall((:helicsInputGetBoolean, libhelicsSharedLib), helics_bool, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetDouble(ipt, err)
    ccall((:helicsInputGetDouble, libhelicsSharedLib), Cdouble, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetTime(ipt, err)
    ccall((:helicsInputGetTime, libhelicsSharedLib), helics_time, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetChar(ipt, err)
    ccall((:helicsInputGetChar, libhelicsSharedLib), UInt8, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetComplexObject(ipt, err)
    ccall((:helicsInputGetComplexObject, libhelicsSharedLib), helics_complex, (helics_input, Ptr{helics_error}), ipt, err)
end

function helicsInputGetComplex(ipt, real, imag, err)
    ccall((:helicsInputGetComplex, libhelicsSharedLib), Cvoid, (helics_input, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{helics_error}), ipt, real, imag, err)
end

function helicsInputGetVectorSize(ipt)
    ccall((:helicsInputGetVectorSize, libhelicsSharedLib), Cint, (helics_input,), ipt)
end

function helicsInputGetVector(ipt, data, maxlen, actualSize, err)
    ccall((:helicsInputGetVector, libhelicsSharedLib), Cvoid, (helics_input, Ptr{Cdouble}, Cint, Ptr{Cint}, Ptr{helics_error}), ipt, data, maxlen, actualSize, err)
end

function helicsInputGetNamedPoint(ipt, outputString, maxStringLen, actualLength, val, err)
    ccall((:helicsInputGetNamedPoint, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Cint, Ptr{Cint}, Ptr{Cdouble}, Ptr{helics_error}), ipt, outputString, maxStringLen, actualLength, val, err)
end

function helicsInputSetDefaultRaw(ipt, data, inputDataLength, err)
    ccall((:helicsInputSetDefaultRaw, libhelicsSharedLib), Cvoid, (helics_input, Ptr{Cvoid}, Cint, Ptr{helics_error}), ipt, data, inputDataLength, err)
end

function helicsInputSetDefaultString(ipt, str, err)
    ccall((:helicsInputSetDefaultString, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Ptr{helics_error}), ipt, str, err)
end

function helicsInputSetDefaultInteger(ipt, val, err)
    ccall((:helicsInputSetDefaultInteger, libhelicsSharedLib), Cvoid, (helics_input, Int64, Ptr{helics_error}), ipt, val, err)
end

function helicsInputSetDefaultBoolean(ipt, val, err)
    ccall((:helicsInputSetDefaultBoolean, libhelicsSharedLib), Cvoid, (helics_input, helics_bool, Ptr{helics_error}), ipt, val, err)
end

function helicsInputSetDefaultTime(ipt, val, err)
    ccall((:helicsInputSetDefaultTime, libhelicsSharedLib), Cvoid, (helics_input, helics_time, Ptr{helics_error}), ipt, val, err)
end

function helicsInputSetDefaultChar(ipt, val, err)
    ccall((:helicsInputSetDefaultChar, libhelicsSharedLib), Cvoid, (helics_input, UInt8, Ptr{helics_error}), ipt, val, err)
end

function helicsInputSetDefaultDouble(ipt, val, err)
    ccall((:helicsInputSetDefaultDouble, libhelicsSharedLib), Cvoid, (helics_input, Cdouble, Ptr{helics_error}), ipt, val, err)
end

function helicsInputSetDefaultComplex(ipt, real, imag, err)
    ccall((:helicsInputSetDefaultComplex, libhelicsSharedLib), Cvoid, (helics_input, Cdouble, Cdouble, Ptr{helics_error}), ipt, real, imag, err)
end

function helicsInputSetDefaultVector(ipt, vectorInput, vectorLength, err)
    ccall((:helicsInputSetDefaultVector, libhelicsSharedLib), Cvoid, (helics_input, Ptr{Cdouble}, Cint, Ptr{helics_error}), ipt, vectorInput, vectorLength, err)
end

function helicsInputSetDefaultNamedPoint(ipt, str, val, err)
    ccall((:helicsInputSetDefaultNamedPoint, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Cdouble, Ptr{helics_error}), ipt, str, val, err)
end

function helicsInputGetType(ipt)
    ccall((:helicsInputGetType, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsInputGetPublicationType(ipt)
    ccall((:helicsInputGetPublicationType, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsPublicationGetType(pub)
    ccall((:helicsPublicationGetType, libhelicsSharedLib), Cstring, (helics_publication,), pub)
end

function helicsInputGetKey(ipt)
    ccall((:helicsInputGetKey, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsSubscriptionGetKey(ipt)
    ccall((:helicsSubscriptionGetKey, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsPublicationGetKey(pub)
    ccall((:helicsPublicationGetKey, libhelicsSharedLib), Cstring, (helics_publication,), pub)
end

function helicsInputGetUnits(ipt)
    ccall((:helicsInputGetUnits, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsInputGetInjectionUnits(ipt)
    ccall((:helicsInputGetInjectionUnits, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsInputGetExtractionUnits(ipt)
    ccall((:helicsInputGetExtractionUnits, libhelicsSharedLib), Cstring, (helics_input,), ipt)
end

function helicsPublicationGetUnits(pub)
    ccall((:helicsPublicationGetUnits, libhelicsSharedLib), Cstring, (helics_publication,), pub)
end

function helicsInputGetInfo(inp)
    ccall((:helicsInputGetInfo, libhelicsSharedLib), Cstring, (helics_input,), inp)
end

function helicsInputSetInfo(inp, info, err)
    ccall((:helicsInputSetInfo, libhelicsSharedLib), Cvoid, (helics_input, Cstring, Ptr{helics_error}), inp, info, err)
end

function helicsPublicationGetInfo(pub)
    ccall((:helicsPublicationGetInfo, libhelicsSharedLib), Cstring, (helics_publication,), pub)
end

function helicsPublicationSetInfo(pub, info, err)
    ccall((:helicsPublicationSetInfo, libhelicsSharedLib), Cvoid, (helics_publication, Cstring, Ptr{helics_error}), pub, info, err)
end

function helicsInputGetOption(inp, option)
    ccall((:helicsInputGetOption, libhelicsSharedLib), Cint, (helics_input, Cint), inp, option)
end

function helicsInputSetOption(inp, option, value, err)
    ccall((:helicsInputSetOption, libhelicsSharedLib), Cvoid, (helics_input, Cint, Cint, Ptr{helics_error}), inp, option, value, err)
end

function helicsPublicationGetOption(pub, option)
    ccall((:helicsPublicationGetOption, libhelicsSharedLib), Cint, (helics_publication, Cint), pub, option)
end

function helicsPublicationSetOption(pub, option, val, err)
    ccall((:helicsPublicationSetOption, libhelicsSharedLib), Cvoid, (helics_publication, Cint, Cint, Ptr{helics_error}), pub, option, val, err)
end

function helicsPublicationSetMinimumChange(pub, tolerance, err)
    ccall((:helicsPublicationSetMinimumChange, libhelicsSharedLib), Cvoid, (helics_publication, Cdouble, Ptr{helics_error}), pub, tolerance, err)
end

function helicsInputSetMinimumChange(inp, tolerance, err)
    ccall((:helicsInputSetMinimumChange, libhelicsSharedLib), Cvoid, (helics_input, Cdouble, Ptr{helics_error}), inp, tolerance, err)
end

function helicsInputIsUpdated(ipt)
    ccall((:helicsInputIsUpdated, libhelicsSharedLib), helics_bool, (helics_input,), ipt)
end

function helicsInputLastUpdateTime(ipt)
    ccall((:helicsInputLastUpdateTime, libhelicsSharedLib), helics_time, (helics_input,), ipt)
end

function helicsInputClearUpdate(ipt)
    ccall((:helicsInputClearUpdate, libhelicsSharedLib), Cvoid, (helics_input,), ipt)
end

function helicsFederateGetPublicationCount(fed)
    ccall((:helicsFederateGetPublicationCount, libhelicsSharedLib), Cint, (helics_federate,), fed)
end

function helicsFederateGetInputCount(fed)
    ccall((:helicsFederateGetInputCount, libhelicsSharedLib), Cint, (helics_federate,), fed)
end
# Julia wrapper for header: api-data.h
# Automatically generated using Clang.jl

# Julia wrapper for header: helics.h
# Automatically generated using Clang.jl

function helicsGetVersion()
    ccall((:helicsGetVersion, libhelicsSharedLib), Cstring, ())
end

function helicsGetBuildFlags()
    ccall((:helicsGetBuildFlags, libhelicsSharedLib), Cstring, ())
end

function helicsGetCompilerVersion()
    ccall((:helicsGetCompilerVersion, libhelicsSharedLib), Cstring, ())
end

function helicsErrorInitialize()
    ccall((:helicsErrorInitialize, libhelicsSharedLib), helics_error, ())
end

function helicsErrorClear(err)
    ccall((:helicsErrorClear, libhelicsSharedLib), Cvoid, (Ptr{helics_error},), err)
end

function helicsIsCoreTypeAvailable(type)
    ccall((:helicsIsCoreTypeAvailable, libhelicsSharedLib), helics_bool, (Cstring,), type)
end

function helicsCreateCore(type, name, initString, err)
    ccall((:helicsCreateCore, libhelicsSharedLib), helics_core, (Cstring, Cstring, Cstring, Ptr{helics_error}), type, name, initString, err)
end

function helicsCreateCoreFromArgs(type, name, argc, argv, err)
    ccall((:helicsCreateCoreFromArgs, libhelicsSharedLib), helics_core, (Cstring, Cstring, Cint, Ptr{Cstring}, Ptr{helics_error}), type, name, argc, argv, err)
end

function helicsCoreClone(core, err)
    ccall((:helicsCoreClone, libhelicsSharedLib), helics_core, (helics_core, Ptr{helics_error}), core, err)
end

function helicsCoreIsValid(core)
    ccall((:helicsCoreIsValid, libhelicsSharedLib), helics_bool, (helics_core,), core)
end

function helicsCreateBroker(type, name, initString, err)
    ccall((:helicsCreateBroker, libhelicsSharedLib), helics_broker, (Cstring, Cstring, Cstring, Ptr{helics_error}), type, name, initString, err)
end

function helicsCreateBrokerFromArgs(type, name, argc, argv, err)
    ccall((:helicsCreateBrokerFromArgs, libhelicsSharedLib), helics_broker, (Cstring, Cstring, Cint, Ptr{Cstring}, Ptr{helics_error}), type, name, argc, argv, err)
end

function helicsBrokerClone(broker, err)
    ccall((:helicsBrokerClone, libhelicsSharedLib), helics_broker, (helics_broker, Ptr{helics_error}), broker, err)
end

function helicsBrokerIsValid(broker)
    ccall((:helicsBrokerIsValid, libhelicsSharedLib), helics_bool, (helics_broker,), broker)
end

function helicsBrokerIsConnected(broker)
    ccall((:helicsBrokerIsConnected, libhelicsSharedLib), helics_bool, (helics_broker,), broker)
end

function helicsBrokerDataLink(broker, source, target, err)
    ccall((:helicsBrokerDataLink, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Cstring, Ptr{helics_error}), broker, source, target, err)
end

function helicsBrokerAddSourceFilterToEndpoint(broker, filter, endpoint, err)
    ccall((:helicsBrokerAddSourceFilterToEndpoint, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Cstring, Ptr{helics_error}), broker, filter, endpoint, err)
end

function helicsBrokerAddDestinationFilterToEndpoint(broker, filter, endpoint, err)
    ccall((:helicsBrokerAddDestinationFilterToEndpoint, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Cstring, Ptr{helics_error}), broker, filter, endpoint, err)
end

function helicsBrokerMakeConnections(broker, file, err)
    ccall((:helicsBrokerMakeConnections, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Ptr{helics_error}), broker, file, err)
end

function helicsCoreWaitForDisconnect(core, msToWait, err)
    ccall((:helicsCoreWaitForDisconnect, libhelicsSharedLib), helics_bool, (helics_core, Cint, Ptr{helics_error}), core, msToWait, err)
end

function helicsBrokerWaitForDisconnect(broker, msToWait, err)
    ccall((:helicsBrokerWaitForDisconnect, libhelicsSharedLib), helics_bool, (helics_broker, Cint, Ptr{helics_error}), broker, msToWait, err)
end

function helicsCoreIsConnected(core)
    ccall((:helicsCoreIsConnected, libhelicsSharedLib), helics_bool, (helics_core,), core)
end

function helicsCoreDataLink(core, source, target, err)
    ccall((:helicsCoreDataLink, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Cstring, Ptr{helics_error}), core, source, target, err)
end

function helicsCoreAddSourceFilterToEndpoint(core, filter, endpoint, err)
    ccall((:helicsCoreAddSourceFilterToEndpoint, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Cstring, Ptr{helics_error}), core, filter, endpoint, err)
end

function helicsCoreAddDestinationFilterToEndpoint(core, filter, endpoint, err)
    ccall((:helicsCoreAddDestinationFilterToEndpoint, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Cstring, Ptr{helics_error}), core, filter, endpoint, err)
end

function helicsCoreMakeConnections(core, file, err)
    ccall((:helicsCoreMakeConnections, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Ptr{helics_error}), core, file, err)
end

function helicsBrokerGetIdentifier(broker)
    ccall((:helicsBrokerGetIdentifier, libhelicsSharedLib), Cstring, (helics_broker,), broker)
end

function helicsCoreGetIdentifier(core)
    ccall((:helicsCoreGetIdentifier, libhelicsSharedLib), Cstring, (helics_core,), core)
end

function helicsBrokerGetAddress(broker)
    ccall((:helicsBrokerGetAddress, libhelicsSharedLib), Cstring, (helics_broker,), broker)
end

function helicsCoreGetAddress(core)
    ccall((:helicsCoreGetAddress, libhelicsSharedLib), Cstring, (helics_core,), core)
end

function helicsCoreSetReadyToInit(core, err)
    ccall((:helicsCoreSetReadyToInit, libhelicsSharedLib), Cvoid, (helics_core, Ptr{helics_error}), core, err)
end

function helicsCoreConnect(core, err)
    ccall((:helicsCoreConnect, libhelicsSharedLib), helics_bool, (helics_core, Ptr{helics_error}), core, err)
end

function helicsCoreDisconnect(core, err)
    ccall((:helicsCoreDisconnect, libhelicsSharedLib), Cvoid, (helics_core, Ptr{helics_error}), core, err)
end

function helicsGetFederateByName(fedName, err)
    ccall((:helicsGetFederateByName, libhelicsSharedLib), helics_federate, (Cstring, Ptr{helics_error}), fedName, err)
end

function helicsBrokerDisconnect(broker, err)
    ccall((:helicsBrokerDisconnect, libhelicsSharedLib), Cvoid, (helics_broker, Ptr{helics_error}), broker, err)
end

function helicsFederateDestroy(fed)
    ccall((:helicsFederateDestroy, libhelicsSharedLib), Cvoid, (helics_federate,), fed)
end

function helicsBrokerDestroy(broker)
    ccall((:helicsBrokerDestroy, libhelicsSharedLib), Cvoid, (helics_broker,), broker)
end

function helicsCoreDestroy(core)
    ccall((:helicsCoreDestroy, libhelicsSharedLib), Cvoid, (helics_core,), core)
end

function helicsCoreFree(core)
    ccall((:helicsCoreFree, libhelicsSharedLib), Cvoid, (helics_core,), core)
end

function helicsBrokerFree(broker)
    ccall((:helicsBrokerFree, libhelicsSharedLib), Cvoid, (helics_broker,), broker)
end

function helicsCreateValueFederate(fedName, fi, err)
    ccall((:helicsCreateValueFederate, libhelicsSharedLib), helics_federate, (Cstring, helics_federate_info, Ptr{helics_error}), fedName, fi, err)
end

function helicsCreateValueFederateFromConfig(configFile, err)
    ccall((:helicsCreateValueFederateFromConfig, libhelicsSharedLib), helics_federate, (Cstring, Ptr{helics_error}), configFile, err)
end

function helicsCreateMessageFederate(fedName, fi, err)
    ccall((:helicsCreateMessageFederate, libhelicsSharedLib), helics_federate, (Cstring, helics_federate_info, Ptr{helics_error}), fedName, fi, err)
end

function helicsCreateMessageFederateFromConfig(configFile, err)
    ccall((:helicsCreateMessageFederateFromConfig, libhelicsSharedLib), helics_federate, (Cstring, Ptr{helics_error}), configFile, err)
end

function helicsCreateCombinationFederate(fedName, fi, err)
    ccall((:helicsCreateCombinationFederate, libhelicsSharedLib), helics_federate, (Cstring, helics_federate_info, Ptr{helics_error}), fedName, fi, err)
end

function helicsCreateCombinationFederateFromConfig(configFile, err)
    ccall((:helicsCreateCombinationFederateFromConfig, libhelicsSharedLib), helics_federate, (Cstring, Ptr{helics_error}), configFile, err)
end

function helicsFederateClone(fed, err)
    ccall((:helicsFederateClone, libhelicsSharedLib), helics_federate, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsCreateFederateInfo()
    ccall((:helicsCreateFederateInfo, libhelicsSharedLib), helics_federate_info, ())
end

function helicsFederateInfoClone(fi, err)
    ccall((:helicsFederateInfoClone, libhelicsSharedLib), helics_federate_info, (helics_federate_info, Ptr{helics_error}), fi, err)
end

function helicsFederateInfoLoadFromArgs(fi, argc, argv, err)
    ccall((:helicsFederateInfoLoadFromArgs, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, Ptr{Cstring}, Ptr{helics_error}), fi, argc, argv, err)
end

function helicsFederateInfoFree(fi)
    ccall((:helicsFederateInfoFree, libhelicsSharedLib), Cvoid, (helics_federate_info,), fi)
end

function helicsFederateIsValid(fed)
    ccall((:helicsFederateIsValid, libhelicsSharedLib), helics_bool, (helics_federate,), fed)
end

function helicsFederateInfoSetCoreName(fi, corename, err)
    ccall((:helicsFederateInfoSetCoreName, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, corename, err)
end

function helicsFederateInfoSetCoreInitString(fi, coreInit, err)
    ccall((:helicsFederateInfoSetCoreInitString, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, coreInit, err)
end

function helicsFederateInfoSetBrokerInitString(fi, brokerInit, err)
    ccall((:helicsFederateInfoSetBrokerInitString, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, brokerInit, err)
end

function helicsFederateInfoSetCoreType(fi, coretype, err)
    ccall((:helicsFederateInfoSetCoreType, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, Ptr{helics_error}), fi, coretype, err)
end

function helicsFederateInfoSetCoreTypeFromString(fi, coretype, err)
    ccall((:helicsFederateInfoSetCoreTypeFromString, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, coretype, err)
end

function helicsFederateInfoSetBroker(fi, broker, err)
    ccall((:helicsFederateInfoSetBroker, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, broker, err)
end

function helicsFederateInfoSetBrokerKey(fi, brokerkey, err)
    ccall((:helicsFederateInfoSetBrokerKey, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, brokerkey, err)
end

function helicsFederateInfoSetBrokerPort(fi, brokerPort, err)
    ccall((:helicsFederateInfoSetBrokerPort, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, Ptr{helics_error}), fi, brokerPort, err)
end

function helicsFederateInfoSetLocalPort(fi, localPort, err)
    ccall((:helicsFederateInfoSetLocalPort, libhelicsSharedLib), Cvoid, (helics_federate_info, Cstring, Ptr{helics_error}), fi, localPort, err)
end

function helicsGetPropertyIndex(val)
    ccall((:helicsGetPropertyIndex, libhelicsSharedLib), Cint, (Cstring,), val)
end

function helicsGetFlagIndex(val)
    ccall((:helicsGetFlagIndex, libhelicsSharedLib), Cint, (Cstring,), val)
end

function helicsGetOptionIndex(val)
    ccall((:helicsGetOptionIndex, libhelicsSharedLib), Cint, (Cstring,), val)
end

function helicsGetOptionValue(val)
    ccall((:helicsGetOptionValue, libhelicsSharedLib), Cint, (Cstring,), val)
end

function helicsFederateInfoSetFlagOption(fi, flag, value, err)
    ccall((:helicsFederateInfoSetFlagOption, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, helics_bool, Ptr{helics_error}), fi, flag, value, err)
end

function helicsFederateInfoSetSeparator(fi, separator, err)
    ccall((:helicsFederateInfoSetSeparator, libhelicsSharedLib), Cvoid, (helics_federate_info, UInt8, Ptr{helics_error}), fi, separator, err)
end

function helicsFederateInfoSetTimeProperty(fi, timeProperty, propertyValue, err)
    ccall((:helicsFederateInfoSetTimeProperty, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, helics_time, Ptr{helics_error}), fi, timeProperty, propertyValue, err)
end

function helicsFederateInfoSetIntegerProperty(fi, intProperty, propertyValue, err)
    ccall((:helicsFederateInfoSetIntegerProperty, libhelicsSharedLib), Cvoid, (helics_federate_info, Cint, Cint, Ptr{helics_error}), fi, intProperty, propertyValue, err)
end

function helicsFederateRegisterInterfaces(fed, file, err)
    ccall((:helicsFederateRegisterInterfaces, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, file, err)
end

function helicsFederateGlobalError(fed, error_code, error_string)
    ccall((:helicsFederateGlobalError, libhelicsSharedLib), Cvoid, (helics_federate, Cint, Cstring), fed, error_code, error_string)
end

function helicsFederateLocalError(fed, error_code, error_string)
    ccall((:helicsFederateLocalError, libhelicsSharedLib), Cvoid, (helics_federate, Cint, Cstring), fed, error_code, error_string)
end

function helicsFederateFinalize(fed, err)
    ccall((:helicsFederateFinalize, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateFinalizeAsync(fed, err)
    ccall((:helicsFederateFinalizeAsync, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateFinalizeComplete(fed, err)
    ccall((:helicsFederateFinalizeComplete, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateFree(fed)
    ccall((:helicsFederateFree, libhelicsSharedLib), Cvoid, (helics_federate,), fed)
end

function helicsCloseLibrary()
    ccall((:helicsCloseLibrary, libhelicsSharedLib), Cvoid, ())
end

function helicsFederateEnterInitializingMode(fed, err)
    ccall((:helicsFederateEnterInitializingMode, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterInitializingModeAsync(fed, err)
    ccall((:helicsFederateEnterInitializingModeAsync, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateIsAsyncOperationCompleted(fed, err)
    ccall((:helicsFederateIsAsyncOperationCompleted, libhelicsSharedLib), helics_bool, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterInitializingModeComplete(fed, err)
    ccall((:helicsFederateEnterInitializingModeComplete, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterExecutingMode(fed, err)
    ccall((:helicsFederateEnterExecutingMode, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterExecutingModeAsync(fed, err)
    ccall((:helicsFederateEnterExecutingModeAsync, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterExecutingModeComplete(fed, err)
    ccall((:helicsFederateEnterExecutingModeComplete, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateEnterExecutingModeIterative(fed, iterate, err)
    ccall((:helicsFederateEnterExecutingModeIterative, libhelicsSharedLib), helics_iteration_result, (helics_federate, helics_iteration_request, Ptr{helics_error}), fed, iterate, err)
end

function helicsFederateEnterExecutingModeIterativeAsync(fed, iterate, err)
    ccall((:helicsFederateEnterExecutingModeIterativeAsync, libhelicsSharedLib), Cvoid, (helics_federate, helics_iteration_request, Ptr{helics_error}), fed, iterate, err)
end

function helicsFederateEnterExecutingModeIterativeComplete(fed, err)
    ccall((:helicsFederateEnterExecutingModeIterativeComplete, libhelicsSharedLib), helics_iteration_result, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateGetState(fed, err)
    ccall((:helicsFederateGetState, libhelicsSharedLib), helics_federate_state, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateGetCoreObject(fed, err)
    ccall((:helicsFederateGetCoreObject, libhelicsSharedLib), helics_core, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateRequestTime(fed, requestTime, err)
    ccall((:helicsFederateRequestTime, libhelicsSharedLib), helics_time, (helics_federate, helics_time, Ptr{helics_error}), fed, requestTime, err)
end

function helicsFederateRequestTimeAdvance(fed, timeDelta, err)
    ccall((:helicsFederateRequestTimeAdvance, libhelicsSharedLib), helics_time, (helics_federate, helics_time, Ptr{helics_error}), fed, timeDelta, err)
end

function helicsFederateRequestNextStep(fed, err)
    ccall((:helicsFederateRequestNextStep, libhelicsSharedLib), helics_time, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateRequestTimeIterative(fed, requestTime, iterate, outIteration, err)
    ccall((:helicsFederateRequestTimeIterative, libhelicsSharedLib), helics_time, (helics_federate, helics_time, helics_iteration_request, Ptr{helics_iteration_result}, Ptr{helics_error}), fed, requestTime, iterate, outIteration, err)
end

function helicsFederateRequestTimeAsync(fed, requestTime, err)
    ccall((:helicsFederateRequestTimeAsync, libhelicsSharedLib), Cvoid, (helics_federate, helics_time, Ptr{helics_error}), fed, requestTime, err)
end

function helicsFederateRequestTimeComplete(fed, err)
    ccall((:helicsFederateRequestTimeComplete, libhelicsSharedLib), helics_time, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateRequestTimeIterativeAsync(fed, requestTime, iterate, err)
    ccall((:helicsFederateRequestTimeIterativeAsync, libhelicsSharedLib), Cvoid, (helics_federate, helics_time, helics_iteration_request, Ptr{helics_error}), fed, requestTime, iterate, err)
end

function helicsFederateRequestTimeIterativeComplete(fed, outIterate, err)
    ccall((:helicsFederateRequestTimeIterativeComplete, libhelicsSharedLib), helics_time, (helics_federate, Ptr{helics_iteration_result}, Ptr{helics_error}), fed, outIterate, err)
end

function helicsFederateGetName(fed)
    ccall((:helicsFederateGetName, libhelicsSharedLib), Cstring, (helics_federate,), fed)
end

function helicsFederateSetTimeProperty(fed, timeProperty, time, err)
    ccall((:helicsFederateSetTimeProperty, libhelicsSharedLib), Cvoid, (helics_federate, Cint, helics_time, Ptr{helics_error}), fed, timeProperty, time, err)
end

function helicsFederateSetFlagOption(fed, flag, flagValue, err)
    ccall((:helicsFederateSetFlagOption, libhelicsSharedLib), Cvoid, (helics_federate, Cint, helics_bool, Ptr{helics_error}), fed, flag, flagValue, err)
end

function helicsFederateSetSeparator(fed, separator, err)
    ccall((:helicsFederateSetSeparator, libhelicsSharedLib), Cvoid, (helics_federate, UInt8, Ptr{helics_error}), fed, separator, err)
end

function helicsFederateSetIntegerProperty(fed, intProperty, propertyVal, err)
    ccall((:helicsFederateSetIntegerProperty, libhelicsSharedLib), Cvoid, (helics_federate, Cint, Cint, Ptr{helics_error}), fed, intProperty, propertyVal, err)
end

function helicsFederateGetTimeProperty(fed, timeProperty, err)
    ccall((:helicsFederateGetTimeProperty, libhelicsSharedLib), helics_time, (helics_federate, Cint, Ptr{helics_error}), fed, timeProperty, err)
end

function helicsFederateGetFlagOption(fed, flag, err)
    ccall((:helicsFederateGetFlagOption, libhelicsSharedLib), helics_bool, (helics_federate, Cint, Ptr{helics_error}), fed, flag, err)
end

function helicsFederateGetIntegerProperty(fed, intProperty, err)
    ccall((:helicsFederateGetIntegerProperty, libhelicsSharedLib), Cint, (helics_federate, Cint, Ptr{helics_error}), fed, intProperty, err)
end

function helicsFederateGetCurrentTime(fed, err)
    ccall((:helicsFederateGetCurrentTime, libhelicsSharedLib), helics_time, (helics_federate, Ptr{helics_error}), fed, err)
end

function helicsFederateSetGlobal(fed, valueName, value, err)
    ccall((:helicsFederateSetGlobal, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Cstring, Ptr{helics_error}), fed, valueName, value, err)
end

function helicsFederateAddDependency(fed, fedName, err)
    ccall((:helicsFederateAddDependency, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, fedName, err)
end

function helicsFederateSetLogFile(fed, logFile, err)
    ccall((:helicsFederateSetLogFile, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, logFile, err)
end

function helicsFederateLogErrorMessage(fed, logmessage, err)
    ccall((:helicsFederateLogErrorMessage, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, logmessage, err)
end

function helicsFederateLogWarningMessage(fed, logmessage, err)
    ccall((:helicsFederateLogWarningMessage, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, logmessage, err)
end

function helicsFederateLogInfoMessage(fed, logmessage, err)
    ccall((:helicsFederateLogInfoMessage, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, logmessage, err)
end

function helicsFederateLogDebugMessage(fed, logmessage, err)
    ccall((:helicsFederateLogDebugMessage, libhelicsSharedLib), Cvoid, (helics_federate, Cstring, Ptr{helics_error}), fed, logmessage, err)
end

function helicsFederateLogLevelMessage(fed, loglevel, logmessage, err)
    ccall((:helicsFederateLogLevelMessage, libhelicsSharedLib), Cvoid, (helics_federate, Cint, Cstring, Ptr{helics_error}), fed, loglevel, logmessage, err)
end

function helicsCoreSetGlobal(core, valueName, value, err)
    ccall((:helicsCoreSetGlobal, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Cstring, Ptr{helics_error}), core, valueName, value, err)
end

function helicsBrokerSetGlobal(broker, valueName, value, err)
    ccall((:helicsBrokerSetGlobal, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Cstring, Ptr{helics_error}), broker, valueName, value, err)
end

function helicsCoreSetLogFile(core, logFileName, err)
    ccall((:helicsCoreSetLogFile, libhelicsSharedLib), Cvoid, (helics_core, Cstring, Ptr{helics_error}), core, logFileName, err)
end

function helicsBrokerSetLogFile(broker, logFileName, err)
    ccall((:helicsBrokerSetLogFile, libhelicsSharedLib), Cvoid, (helics_broker, Cstring, Ptr{helics_error}), broker, logFileName, err)
end

function helicsCreateQuery(target, query)
    ccall((:helicsCreateQuery, libhelicsSharedLib), helics_query, (Cstring, Cstring), target, query)
end

function helicsQueryExecute(query, fed, err)
    ccall((:helicsQueryExecute, libhelicsSharedLib), Cstring, (helics_query, helics_federate, Ptr{helics_error}), query, fed, err)
end

function helicsQueryCoreExecute(query, core, err)
    ccall((:helicsQueryCoreExecute, libhelicsSharedLib), Cstring, (helics_query, helics_core, Ptr{helics_error}), query, core, err)
end

function helicsQueryBrokerExecute(query, broker, err)
    ccall((:helicsQueryBrokerExecute, libhelicsSharedLib), Cstring, (helics_query, helics_broker, Ptr{helics_error}), query, broker, err)
end

function helicsQueryExecuteAsync(query, fed, err)
    ccall((:helicsQueryExecuteAsync, libhelicsSharedLib), Cvoid, (helics_query, helics_federate, Ptr{helics_error}), query, fed, err)
end

function helicsQueryExecuteComplete(query, err)
    ccall((:helicsQueryExecuteComplete, libhelicsSharedLib), Cstring, (helics_query, Ptr{helics_error}), query, err)
end

function helicsQueryIsCompleted(query)
    ccall((:helicsQueryIsCompleted, libhelicsSharedLib), helics_bool, (helics_query,), query)
end

function helicsQuerySetTarget(query, target, err)
    ccall((:helicsQuerySetTarget, libhelicsSharedLib), Cvoid, (helics_query, Cstring, Ptr{helics_error}), query, target, err)
end

function helicsQuerySetQueryString(query, queryString, err)
    ccall((:helicsQuerySetQueryString, libhelicsSharedLib), Cvoid, (helics_query, Cstring, Ptr{helics_error}), query, queryString, err)
end

function helicsQueryFree(query)
    ccall((:helicsQueryFree, libhelicsSharedLib), Cvoid, (helics_query,), query)
end

function helicsCleanupLibrary()
    ccall((:helicsCleanupLibrary, libhelicsSharedLib), Cvoid, ())
end
# Julia wrapper for header: helicsCallbacks.h
# Automatically generated using Clang.jl

function helicsBrokerSetLoggingCallback(broker, logger, userdata, err)
    ccall((:helicsBrokerSetLoggingCallback, libhelicsSharedLib), Cvoid, (helics_broker, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{helics_error}), broker, logger, userdata, err)
end

function helicsCoreSetLoggingCallback(core, logger, userdata, err)
    ccall((:helicsCoreSetLoggingCallback, libhelicsSharedLib), Cvoid, (helics_core, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{helics_error}), core, logger, userdata, err)
end

function helicsFederateSetLoggingCallback(fed, logger, userdata, err)
    ccall((:helicsFederateSetLoggingCallback, libhelicsSharedLib), Cvoid, (helics_federate, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{helics_error}), fed, logger, userdata, err)
end

function helicsFilterSetCustomCallback(filter, filtCall, userdata, err)
    ccall((:helicsFilterSetCustomCallback, libhelicsSharedLib), Cvoid, (helics_filter, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{helics_error}), filter, filtCall, userdata, err)
end
# Julia wrapper for header: helics_export.h
# Automatically generated using Clang.jl

# Julia wrapper for header: chelics.h
# Automatically generated using Clang.jl

# Julia wrapper for header: helics_enums.h
# Automatically generated using Clang.jl


text:
const NodeContexts = Vector{NodeObject}()
@global_js_const _VM = "require('vm')"
@global_js_const _ASSIGN_DEFAULTS = """(() => {
    const keys = ['console']
    // Pass global functions
    for (const key of Object.keys(globalThis)) {
        if (key !== 'global' && !key.startsWith('_')) {
            keys.push(key)
        }
    }
    // Pass all the types (the global objects whose names start with a capital letter)
    for (const key of Object.getOwnPropertyNames(globalThis)) {
        if (key[0] === key[0].toUpperCase() && !key.startsWith('_')) {
            keys.push(key)
        }
    }
    return (ctx) => {
        const defaults = new Object()
        for (const key of keys) {
            defaults[key] = globalThis[key]
        }
        return Object.assign(defaults, ctx)
    }
})()"""

current_context() = let i = _GLOBAL_ENV.context_index
    i == 0 ? nothing : NodeContexts[i]
end

function get_context(index::Integer)
    @assert 1 ≤ index ≤ length(NodeContexts)
    NodeContexts[index]
end

function switch_context(index::Integer)
    context = get_context(index)
    _GLOBAL_ENV.context_index = index
    context
end
function switch_context(context)
    for i in 1:length(NodeContexts)
        if NodeContexts[i] == context
            return switch_context(i)
        end
    end
    push!(NodeContexts, context)
    switch_context(length(NodeContexts))
end

new_context(context_object=nothing; add_defaults=true, be_current=true) = @with_scope begin
    if isnothing(context_object)
        context_object = create_object()
    end
    if add_defaults
        context_object = _ASSIGN_DEFAULTS(context_object; result=RESULT_RAW)
    end
    context = _VM.createContext(
        context_object;
        result=RESULT_NODE
    )
    push!(NodeContexts, context)
    if be_current
        switch_context(length(NodeContexts))
    end
    context
end

function delete_context(index::Integer=_GLOBAL_ENV.context_index)
    if _GLOBAL_ENV.context_index == index
        _GLOBAL_ENV.context_index = length(NodeContexts) == 1 ? 0 : 1
    end
    deleteat!(NodeContexts, index)
    if length(NodeContexts) == 0
        new_context()
    end
    true
end
function delete_context(context)
    for i in 1:length(NodeContexts)
        if NodeContexts[i] == context
            return delete_context(i)
        end
    end
    false
end

function clear_context()
    _GLOBAL_ENV.context_index = 0
    resize!(NodeContexts, 0)
    new_context()
    nothing
end

list_contexts() = copy(NodeContexts)

ext: jl


text:
# The test sets in this file are mostly intended to test the "raw" form of function objects.
# Therefore we use directly the inner constructors and avoid the more convenient outer
# constructors which may potentially optimize out some of the complexity.

@testset "Argument" begin
    func = compile(fulltrans)

    val = ev(func, [0.5], lineelt)
    @test val == ((), ())

    val = ev(func, [0.5], Element(Simplex{1}(), 1; transform=(Shift([1.0]),)))
    @test val == ((), (Shift([1.0]),))

    val = ev(func, [0.5], Element(Simplex{1}(), 1; dimcorr=(Updim{1,1}(2.4),)))
    @test val == ((Updim{1,1}(2.4),), ())

    val = ev(func, [0.5], Element(Simplex{1}(), 1; dimcorr=(Updim{1,1}(2.4),), transform=(Shift([1.0]),)))
    @test val == ((Updim{1,1}(2.4),), (Shift([1.0]),))

    func = compile(dimtrans)

    val = ev(func, [0.5], lineelt)
    @test val == ()

    val = ev(func, [0.5], Element(Simplex{1}(), 1; transform=(Shift([1.0]),)))
    @test val == ()

    val = ev(func, [0.5], Element(Simplex{1}(), 1; dimcorr=(Updim{1,1}(2.4),)))
    @test val == (Updim{1,1}(2.4),)

    val = ev(func, [0.5], Element(Simplex{1}(), 1; dimcorr=(Updim{1,1}(2.4),), transform=(Shift([1.0]),)))
    @test val == (Updim{1,1}(2.4),)
end

@testset "ApplyTransform" begin
    func = compile(rootcoords(1))

    val = ev(func, [0.5], lineelt)
    @test val == [0.5]

    val = ev(func, [0.7], Element(Simplex{1}(), 1; transform=(Shift([-0.3]),)))
    @test val ≈ [0.4]
end

@testset "ApplyTransformGrad" begin
    func = compile(ApplyTransformGrad(fulltrans, Functions._point, 1))
    val = ev(func, [0.5], lineelt)
    @test val == fill(1.0, (1,1))
end

@testset "Constant" begin
    func = compile(Constant(1.0))
    val = ev(func, [0.5], lineelt)
    @test val == fill(1.0, ())

    func = compile(Constant([1.0]))
    val = ev(func, [0.5], lineelt)
    @test val == [1.0]

    func = compile(Constant([1.0, 2.0, 3.0]))
    val = ev(func, [0.2], lineelt)
    @test val == [1.0, 2.0, 3.0]

    func = Add((Constant([0.0]), Constant([0.0])))
    @test length(Functions.linearize(func)) == 2
end

@testset "Contract" begin
    Random.seed!(2018)
    lmx = rand(Float64, 3, 4)
    rmx = rand(Float64, 4, 2)

    pfunc = Contract(Constant(lmx), Constant(rmx))
    @test size(pfunc) == (3, 2)
    func = compile(pfunc)
    val = ev(func, [0.5], lineelt)
    @test val ≈ lmx * rmx
end

@testset "GetIndex" begin
    Random.seed!(201808041834)
    array = rand(Int, 4, 5, 6)

    # Indexing with ints and colons
    pfunc = getindex(Constant(array), 3, :, :)
    @test size(pfunc) == (5, 6)
    func = compile(pfunc)
    val = ev(func, [0.1], lineelt)
    @test size(val) == (5, 6)
    @test val == array[3, :, :]

    # Indexing with evaluables
    pfunc = getindex(Constant(array), Constant(1), :, Constant(4))
    @test size(pfunc) == (5,)
    func = compile(pfunc)
    val = ev(func, [0.1], lineelt)
    @test size(val) == (5,)
    @test val == array[1, :, 4]
end

@testset "Inflate" begin
    Random.seed!(201808031205)

    data = Constant([1.0, 2.0, 3.0, 4.0])
    index1 = Constant([1, 2, 3, 4])
    func = compile(Inflate(data, (4,), 1 => index1))
    val = ev(func, [0.1], lineelt)
    @test val == [1.0, 2.0, 3.0, 4.0]

    func = compile(Inflate(data, (7,), 1 => index1))
    val = ev(func, [0.1], lineelt)
    @test val == [1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0]
end

@testset "InsertAxis" begin
    Random.seed!(201808041356)
    data = rand(Float64, 4, 5, 6)

    pfunc = InsertAxis(Constant(data), [1])
    @test size(pfunc) == (1, 4, 5, 6)
    val = ev(compile(pfunc), [0.5], lineelt)
    @test val == reshape(data, 1, 4, 5, 6)

    pfunc = InsertAxis(Constant(data), [1, 1])
    @test size(pfunc) == (1, 1, 4, 5, 6)
    val = ev(compile(pfunc), [0.5], lineelt)
    @test val == reshape(data, 1, 1, 4, 5, 6)

    pfunc = InsertAxis(Constant(data), [2])
    @test size(pfunc) == (4, 1, 5, 6)
    val = ev(compile(pfunc), [0.5], lineelt)
    @test val == reshape(data, 4, 1, 5, 6)

    pfunc = InsertAxis(Constant(data), [1, 2])
    @test size(pfunc) == (1, 4, 1, 5, 6)
    val = ev(compile(pfunc), [0.5], lineelt)
    @test val == reshape(data, 1, 4, 1, 5, 6)

    pfunc = InsertAxis(Constant(data), [1, 2, 4])
    @test size(pfunc) == (1, 4, 1, 5, 6, 1)
    val = ev(compile(pfunc), [0.5], lineelt)
    @test val == reshape(data, 1, 4, 1, 5, 6, 1)
end

@testset "Inv" begin
    Random.seed!(201808071535)

    data = rand(Float64, 1, 1)
    func = compile(inv(Constant(data)))
    @test ev(func, [0.5], lineelt) ≈ inv(data)

    data = rand(Float64, 2, 2)
    func = compile(inv(Constant(data)))
    @test ev(func, [0.5], lineelt) ≈ inv(data)

    data = rand(Float64, 3, 3)
    func = compile(inv(Constant(data)))
    @test ev(func, [0.5], lineelt) ≈ inv(data)

    data = rand(Float64, 4, 4)
    func = compile(inv(Constant(data)))
    @test ev(func, [0.5], lineelt) ≈ inv(data)
end

@testset "Monomials" begin
    Random.seed!(2018)
    pts = rand(Float64, 2, 2)
    func = compile(Monomials(Constant(pts), 3, 1))
    val = ev(func, [0.5], lineelt)
    @test val[1,:,:] == fill(0.0, 2, 2)
    @test val[2,:,:] == fill(1.0, 2, 2)
    @test val[3,:,:] ≈ pts
    @test val[4,:,:] ≈ pts .^ 2
    @test val[5,:,:] ≈ pts .^ 3
end

@testset "Neg" begin
    Random.seed!(201808081346)
    data = rand(Float64, 3, 4, 5)
    func = compile(-Constant(data))
    val = ev(func, [0.5], lineelt)
    @test val == -data
end

@testset "Product" begin
    Random.seed!(2018)
    lmx = rand(Float64, 5)
    rmx = rand(Float64, 5, 9)
    func = compile(Product((Constant(lmx), Constant(rmx))))
    val = ev(func, [0.5], lineelt)
    @test val ≈ lmx .* rmx
end

@testset "Add" begin
    Random.seed!(2018)
    lmx = rand(Float64, 5)
    rmx = rand(Float64, 5, 9)
    func = compile(Add(Constant(lmx), Constant(rmx)))
    val = ev(func, [0.5], lineelt)
    @test val ≈ lmx .+ rmx
end

@testset "Tupl" begin
    func = compile(Tupl((Constant(1), Constant(2.0))))
    val = ev(func, [0.5], lineelt)
    @test val == (fill(1, ()), fill(2.0, ()))
end

@testset "Zeros" begin
    func = compile(Zeros(Float64, 3, 4, 5))
    val = ev(func, [0.5], lineelt)
    @test val == zeros(Float64, 3, 4, 5)
end

max_stars_repo_name: TheBB/Jutils

max_issues_repo_name: TheBB/Jutils

max_forks_repo_name: TheBB/Jutils


text:
# ---------------------------------------------------------------------------- #
#
#   basisFuncTetLag.jl
#
#   Get Legendre basis functions for Tetrahedron
#
#   λυτέος
#   Fall 2017
#
#   Max Opgenoord
#
# ---------------------------------------------------------------------------- #

# function basisFuncTetLeg( ::Type{Val{0}}, s::Array{Float64}, t::Array{Float64}, u::Array{Float64} )
#
#   dim = 3
#   nx  = length( s )
#
#   # Constant
#
#   nphi = 1
#   phi  = Array{Float64}(nx, nphi)
#   dphi = Array{Float64}(nx, nphi, dim)
#
#   # value
#   phi[:,1] = 1.0
#
#   # derivative in x
#   dphi[:,1,1] = 0.0
#   # derivative in y
#   dphi[:,1,2] = 0.0
#   # derivative in z
#   dphi[:,1,3] = 0.0
#
#   # transpose
#   phi   = phi'
#
#   dphi2 = fill( 0.0, size(dphi,2), size(dphi,1), 3 )
#   dphi2[:,:,1] = dphi[:,:,1]'
#   dphi2[:,:,2] = dphi[:,:,2]'
#   dphi2[:,:,3] = dphi[:,:,3]'
#
#   return phi, dphi2
#
# end

function basisFuncTetLeg( P::P1, s::Array{Float64}, t::Array{Float64}, u::Array{Float64} )

  dim = 3
  nx  = length( s )

  # Linear

  nphi = 4
  phi  = Array{Float64}(nx, nphi)
  dphi = Array{Float64}(nx, nphi, dim)

  # value
  phi[:,1] = 1
  phi[:,2] = (sqrt(5/3.)).*(-1+(4).*(s))
  phi[:,3] = (sqrt(10/3.)).*(-1+s+(3).*(t))
  phi[:,4] = (sqrt(10)).*(-1+s+t+(2).*(u))

  # derivative in x
  dphi[:,1,1] = 0
  dphi[:,2,1] = (4).*(sqrt(5/3.))
  dphi[:,3,1] = sqrt(10/3.)
  dphi[:,4,1] = sqrt(10)

  # derivative in y
  dphi[:,1,2] = 0
  dphi[:,2,2] = 0
  dphi[:,3,2] = sqrt(30)
  dphi[:,4,2] = sqrt(10)

  # derivative in z
  dphi[:,1,3] = 0
  dphi[:,2,3] = 0
  dphi[:,3,3] = 0
  dphi[:,4,3] = (2).*(sqrt(10))

  # transpose
  phi   = phi'

  dphi2 = fill( 0.0, size(dphi,2), size(dphi,1), 3 )
  dphi2[:,:,1] = dphi[:,:,1]'
  dphi2[:,:,2] = dphi[:,:,2]'
  dphi2[:,:,3] = dphi[:,:,3]'

  return phi, dphi2

end

function basisFuncTetLeg( P::P2, s::Array{Float64}, t::Array{Float64}, u::Array{Float64} )

  dim = 3
  nx  = length( s )

  # Quadratric
  nphi = 10
  phi  = Array{Float64}(nx, nphi)
  dphi = Array{Float64}(nx, nphi, dim)

  t2 = t .* t
  u2 = u .* u

  # value
  phi[:,1] = 1
  phi[:,2] = (sqrt(5/3.)).*(-1+(4).*(s))
  phi[:,3] = (sqrt(10/3.)).*(-1+s+(3).*(t))
  phi[:,4] = (sqrt(10)).*(-1+s+t+(2).*(u))
  phi[:,5] = (sqrt(7/3.)).*(1+(5).*((s).*(-2+(3).*(s))))
  phi[:,6] = (sqrt(14/3.)).*((-1+(6).*(s)).*(-1+s+(3).*(t)))
  phi[:,7] = (sqrt(14)).*((-1+(6).*(s)).*(-1+s+t+(2).*(u)))
  phi[:,8] = (sqrt(7)).*((-1+s).^2+(8).*((-1+s).*(t))+(10).*(t2))
  phi[:,9] = (sqrt(21)).*((-1+s+(5).*(t)).*(-1+s+t+(2).*(u)))
  phi[:,10] = (sqrt(35)).*((-1+s+t).^2+(6).*((-1+s+t).*(u))+(6).*(u2))

  # derivative in x
  dphi[:,1,1] = 0
  dphi[:,2,1] = (4).*(sqrt(5/3.))
  dphi[:,3,1] = sqrt(10/3.)
  dphi[:,4,1] = sqrt(10)
  dphi[:,5,1] = (10).*((sqrt(7/3.)).*(-1+(3).*(s)))
  dphi[:,6,1] = (sqrt(14/3.)).*(-7+(12).*(s)+(18).*(t))
  dphi[:,7,1] = (sqrt(14)).*(-7+(12).*(s)+(6).*(t)+(12).*(u))
  dphi[:,8,1] = (2).*((sqrt(7)).*(-1+s+(4).*(t)))
  dphi[:,9,1] = (2).*((sqrt(21)).*(-1+s+(3).*(t)+u))
  dphi[:,10,1] = (2).*((sqrt(35)).*(-1+s+t+(3).*(u)))

  # derivative in y
  dphi[:,1,2] = 0
  dphi[:,2,2] = 0
  dphi[:,3,2] = sqrt(30)
  dphi[:,4,2] = sqrt(10)
  dphi[:,5,2] = 0
  dphi[:,6,2] = (sqrt(42)).*(-1+(6).*(s))
  dphi[:,7,2] = (sqrt(14)).*(-1+(6).*(s))
  dphi[:,8,2] = (4).*((sqrt(7)).*(-2+(2).*(s)+(5).*(t)))
  dphi[:,9,2] = (2).*((sqrt(21)).*(-3+(3).*(s)+(5).*(t)+(5).*(u)))
  dphi[:,10,2] = (2).*((sqrt(35)).*(-1+s+t+(3).*(u)))

  # derivative in z
  dphi[:,1,3] = 0
  dphi[:,2,3] = 0
  dphi[:,3,3] = 0
  dphi[:,4,3] = (2).*(sqrt(10))
  dphi[:,5,3] = 0
  dphi[:,6,3] = 0
  dphi[:,7,3] = (2).*((sqrt(14)).*(-1+(6).*(s)))
  dphi[:,8,3] = 0
  dphi[:,9,3] = (2).*((sqrt(21)).*(-1+s+(5).*(t)))
  dphi[:,10,3] = (6).*((sqrt(35)).*(-1+s+t+(2).*(u)))

  # transpose
  phi   = phi'

  dphi2 = fill( 0.0, size(dphi,2), size(dphi,1), 3 )
  dphi2[:,:,1] = dphi[:,:,1]'
  dphi2[:,:,2] = dphi[:,:,2]'
  dphi2[:,:,3] = dphi[:,:,3]'

  return phi, dphi2

end

function basisFuncTetLeg( P::P3, s::Array{Float64}, t::Array{Float64}, u::Array{Float64} )

  dim = 3
  nx  = length( s )

  # Cubic
  nphi = 20
  phi  = Array{Float64}(nx, nphi)
  dphi = Array{Float64}(nx, nphi, dim)

  s2 = s  .* s
  t2 = t  .* t
  u2 = u  .* u
  s3 = s2 .* s
  t3 = t2 .* t
  u3 = u2 .* u

  # value
  phi[:,1] = 1
  phi[:,2] = (sqrt(5/3.)).*(-1+(4).*(s))
  phi[:,3] = (sqrt(10/3.)).*(-1+s+(3).*(t))
  phi[:,4] = (sqrt(10)).*(-1+s+t+(2).*(u))
  phi[:,5] = (sqrt(7/3.)).*(1+(5).*((s).*(-2+(3).*(s))))
  phi[:,6] = (sqrt(14/3.)).*((-1+(6).*(s)).*(-1+s+(3).*(t)))
  phi[:,7] = (sqrt(14)).*((-1+(6).*(s)).*(-1+s+t+(2).*(u)))
  phi[:,8] = (sqrt(7)).*((-1+s).^2+(8).*((-1+s).*(t))+(10).*(t2))
  phi[:,9] = (sqrt(21)).*((-1+s+(5).*(t)).*(-1+s+t+(2).*(u)))
  phi[:,10] = (sqrt(35)).*((-1+s+t).^2+(6).*((-1+s+t).*(u))+(6).*(u2))
  phi[:,11] = (sqrt(3)).*(-1+(s).*(18+(7).*((s).*(-9+(8).*(s)))))
  phi[:,12] = (sqrt(6)).*((1+(14).*((s).*(-1+(2).*(s)))).*(-1+s+(3).*(t)))
  phi[:,13] = (3).*((sqrt(2)).*((1+(14).*((s).*(-1+(2).*(s)))).*(-1+s+t+(2).*(u))))
  phi[:,14] = (3).*((-1+(8).*(s)).*((-1+s).^2+(8).*((-1+s).*(t))+(10).*(t2)))
  phi[:,15] = (3).*((sqrt(3)).*((-1+(8).*(s)).*((-1+s+(5).*(t)).*(-1+s+t+(2).*(u)))))
  phi[:,16] = (3).*((sqrt(5)).*((-1+(8).*(s)).*((-1+s+t).^2+(6).*((-1+s+t).*(u))+(6).*(u2))))
  phi[:,17] = (2).*((sqrt(3)).*((-1+s).^3+(15).*(((-1+s).^2).*(t))+(45).*((-1+s).*(t2))+(35).*(t3)))
  phi[:,18] = (6).*(((-1+s).^2+(12).*((-1+s).*(t))+(21).*(t2)).*(-1+s+t+(2).*(u)))
  phi[:,19] = (2).*((sqrt(15)).*((-1+s+(7).*(t)).*((-1+s+t).^2+(6).*((-1+s+t).*(u))+(6).*(u2))))
  phi[:,20] = (2).*((sqrt(21)).*((-1+s+t).^3+(12).*(((-1+s+t).^2).*(u))+(30).*((-1+s+t).*(u2))+(20).*(u3)))

  # derivative in x
  dphi[:,1,1] = 0
  dphi[:,2,1] = (4).*(sqrt(5/3.))
  dphi[:,3,1] = sqrt(10/3.)
  dphi[:,4,1] = sqrt(10)
  dphi[:,5,1] = (10).*((sqrt(7/3.)).*(-1+(3).*(s)))
  dphi[:,6,1] = (sqrt(14/3.)).*(-7+(12).*(s)+(18).*(t))
  dphi[:,7,1] = (sqrt(14)).*(-7+(12).*(s)+(6).*(t)+(12).*(u))
  dphi[:,8,1] = (2).*((sqrt(7)).*(-1+s+(4).*(t)))
  dphi[:,9,1] = (2).*((sqrt(21)).*(-1+s+(3).*(t)+u))
  dphi[:,10,1] = (2).*((sqrt(35)).*(-1+s+t+(3).*(u)))
  dphi[:,11,1] = (6).*((sqrt(3)).*(3+(7).*((s).*(-3+(4).*(s)))))
  dphi[:,12,1] = (3).*((sqrt(6)).*(5+(-14).*(t)+(28).*((s).*(-1+s+(2).*(t)))))
  dphi[:,13,1] = (3).*((sqrt(2)).*(15+(-14).*(t)+(-28).*(u)+(28).*((s).*(-3+(3).*(s)+(2).*(t)+(4).*(u)))))
  dphi[:,14,1] = (6).*(5+(12).*(s2)+(4).*((t).*(-9+(10).*(t)))+(s).*(-17+(64).*(t)))
  dphi[:,15,1] = (6).*((sqrt(3)).*(5+(12).*(s2)+(-9).*(u)+(s).*(-17+(48).*(t)+(16).*(u))+(t).*(-27+(20).*(t)+(40).*(u))))
  dphi[:,16,1] = (6).*((sqrt(5)).*(5+(12).*(s2)+(4).*(t2)+(3).*((u).*(-9+(8).*(u)))+(3).*((t).*(-3+(8).*(u)))+(s).*(-17+(16).*(t)+(48).*(u))))
  dphi[:,17,1] = (6).*((sqrt(3)).*((-1+s).^2+(10).*((-1+s).*(t))+(15).*(t2)))
  dphi[:,18,1] = (6).*(3+(3).*(s2)+(-4).*(u)+(s).*(-6+(26).*(t)+(4).*(u))+(t).*(-26+(33).*(t)+(24).*(u)))
  dphi[:,19,1] = (6).*((sqrt(15)).*(1+s2+(5).*(t2)+(2).*((-2+u).*(u))+(s).*(-2+(6).*(t)+(4).*(u))+(2).*((t).*(-3+(8).*(u)))))
  dphi[:,20,1] = (6).*((sqrt(21)).*((-1+s+t).^2+(8).*((-1+s+t).*(u))+(10).*(u2)))

  # derivative in y
  dphi[:,1,2] = 0
  dphi[:,2,2] = 0
  dphi[:,3,2] = sqrt(30)
  dphi[:,4,2] = sqrt(10)
  dphi[:,5,2] = 0
  dphi[:,6,2] = (sqrt(42)).*(-1+(6).*(s))
  dphi[:,7,2] = (sqrt(14)).*(-1+(6).*(s))
  dphi[:,8,2] = (4).*((sqrt(7)).*(-2+(2).*(s)+(5).*(t)))
  dphi[:,9,2] = (2).*((sqrt(21)).*(-3+(3).*(s)+(5).*(t)+(5).*(u)))
  dphi[:,10,2] = (2).*((sqrt(35)).*(-1+s+t+(3).*(u)))
  dphi[:,11,2] = 0
  dphi[:,12,2] = (3).*((sqrt(6)).*(1+(14).*((s).*(-1+(2).*(s)))))
  dphi[:,13,2] = (3).*((sqrt(2)).*(1+(14).*((s).*(-1+(2).*(s)))))
  dphi[:,14,2] = (12).*((-1+(8).*(s)).*(-2+(2).*(s)+(5).*(t)))
  dphi[:,15,2] = (6).*((sqrt(3)).*((-1+(8).*(s)).*(-3+(3).*(s)+(5).*(t)+(5).*(u))))
  dphi[:,16,2] = (6).*((sqrt(5)).*((-1+(8).*(s)).*(-1+s+t+(3).*(u))))
  dphi[:,17,2] = (30).*((sqrt(3)).*((-1+s).^2+(6).*((-1+s).*(t))+(7).*(t2)))
  dphi[:,18,2] = (6).*(13+(13).*(s2)+(-24).*(u)+(s).*(-26+(66).*(t)+(24).*(u))+(3).*((t).*(-22+(21).*(t)+(28).*(u))))
  dphi[:,19,2] = (6).*((sqrt(15)).*(3+(3).*(s2)+(7).*(t2)+(2).*((u).*(-8+(7).*(u)))+(2).*((s).*(-3+(5).*(t)+(8).*(u)))+(2).*((t).*(-5+(14).*(u)))))
  dphi[:,20,2] = (6).*((sqrt(21)).*((-1+s+t).^2+(8).*((-1+s+t).*(u))+(10).*(u2)))

  # derivative in z
  dphi[:,1,3] = 0
  dphi[:,2,3] = 0
  dphi[:,3,3] = 0
  dphi[:,4,3] = (2).*(sqrt(10))
  dphi[:,5,3] = 0
  dphi[:,6,3] = 0
  dphi[:,7,3] = (2).*((sqrt(14)).*(-1+(6).*(s)))
  dphi[:,8,3] = 0
  dphi[:,9,3] = (2).*((sqrt(21)).*(-1+s+(5).*(t)))
  dphi[:,10,3] = (6).*((sqrt(35)).*(-1+s+t+(2).*(u)))
  dphi[:,11,3] = 0
  dphi[:,12,3] = 0
  dphi[:,13,3] = (6).*((sqrt(2)).*(1+(14).*((s).*(-1+(2).*(s)))))
  dphi[:,14,3] = 0
  dphi[:,15,3] = (6).*((sqrt(3)).*((-1+(8).*(s)).*(-1+s+(5).*(t))))
  dphi[:,16,3] = (18).*((sqrt(5)).*((-1+(8).*(s)).*(-1+s+t+(2).*(u))))
  dphi[:,17,3] = 0
  dphi[:,18,3] = (12).*((-1+s).^2+(12).*((-1+s).*(t))+(21).*(t2))
  dphi[:,19,3] = (12).*((sqrt(15)).*((-1+s+(7).*(t)).*(-1+s+t+(2).*(u))))
  dphi[:,20,3] = (24).*((sqrt(21)).*((-1+s+t).^2+(5).*((-1+s+t).*(u))+(5).*(u2)))

  # transpose
  phi   = phi'

  dphi2 = fill( 0.0, size(dphi,2), size(dphi,1), 3 )
  dphi2[:,:,1] = dphi[:,:,1]'
  dphi2[:,:,2] = dphi[:,:,2]'
  dphi2[:,:,3] = dphi[:,:,3]'

  return phi, dphi2

end


text:
import DataFrames
import GLM
import StatsModels

function get_unique_symbol_name(
        v::AbstractVector{<:Symbol},
        new_symbol::Symbol = :x;
        append_string::String = "1"
        )::Symbol
    old_strings_set::Set{String} = Set(strip.(string.(v)))
    new_string::String = strip.(string.(new_symbol))
    _append_string::String = strip(append_string)
    while new_string in old_strings_set
        new_string = string(new_string, _append_string)
    end
    new_symbol::Symbol = Symbol(new_string)
    return new_symbol
end

function columns_are_linearly_independent(
        df::DataFrames.DataFrame,
        columns::AbstractVector{<:Symbol} = Symbol[],
        )::Bool
    df_copy = deepcopy(df)
    if length(columns) == 0
        columns_copy = deepcopy(DataFrames.names(df_copy))
    else
        columns_copy = deepcopy(columns)
    end
    temporary_dependent_variable::Symbol = get_unique_symbol_name(
        columns_copy,
        :y,
        )
    formula = generate_formula(
        temporary_dependent_variable,
        columns_copy;
        intercept = false,
        interactions = 1,
        )
    df_copy[temporary_dependent_variable] = randn(size(df_copy, 1))
    try_lm_result::Bool = try
        lm = GLM.lm(formula, df_copy, false)
        true
    catch ex
        @debug("caught exception: ", exception=ex,)
        false
    end
    cols_result = length(linearly_dependent_columns(df, columns)) == 0
    final_result::Bool = try_lm_result && cols_result
    return final_result
end

function linearly_dependent_columns(
        df::DataFrames.DataFrame,
        columns::AbstractVector{<:Symbol} = Symbol[])::Vector{Symbol}
    df_copy = deepcopy(df)
    if length(columns) == 0
        columns_copy = deepcopy(DataFrames.names(df_copy))
    else
        columns_copy = deepcopy(columns)
    end
    temporary_dependent_variable::Symbol = get_unique_symbol_name(
        columns_copy,
        :y,
        )
    formula = generate_formula(
        temporary_dependent_variable,
        columns_copy;
        intercept = false,
        interactions = 1,
        )
    df_copy[temporary_dependent_variable] = randn(size(df_copy, 1))
    lm = GLM.lm(formula, df_copy, true)
    coeftable = StatsModels.coeftable(lm)
    result_strings::Vector{String} = sort(
        unique(strip.(coeftable.rownms[isnan.(coeftable.cols[4])]))
        )
    result_symbols::Vector{Symbol} = Symbol.(result_strings)
    return result_symbols
end


text:
#-------------------------
# initializing receiver field
#-------------------------
function init_receiver(recgeom,nrec,dr,dz,nr,nz,nt)
    #vr,vz, and tii receivers
    #receivers are assigned at nearest grids

    if (minimum(recgeom[:,1])<0.) || (maximum(recgeom[:,1])>(nz-1)*dz)
       error("Check receiver geometry!")
    end
    if (minimum(recgeom[:,2])<0.) || (maximum(recgeom[:,2])>(nr-1)*dr)
       error("Check receiver geometry!")
    end

    #--Receiver indexes---
    index_allrec_vr=zeros(nrec,2) #z,r
    index_allrec_vz=zeros(nrec,2) #z,r
    index_allrec_tii=zeros(nrec,2) #z,r
    for irec=1:nrec
        tmpz=recgeom[irec,1]
        tmpr=recgeom[irec,2]

        iz=round((tmpz-dz/2)/dz)+1 #vz
        ir=round(tmpr/dr)+1 #vz
        index_allrec_vz[irec,1]=iz
        index_allrec_vz[irec,2]=ir

        iz=round(tmpz/dz)+1 #vr
        ir=round((tmpr-dr/2)/dr)+1 #vr
        index_allrec_vr[irec,1]=iz
        index_allrec_vr[irec,2]=ir

#        iz=round((tmpz-dz/2)/dz)+1 #tii
#        ir=round((tmpr-dr/2)/dr)+1 #tii
        iz=round(tmpz/dz)+1 #tii
        ir=round(tmpr/dr)+1 #tii
        index_allrec_tii[irec,1]=iz
        index_allrec_tii[irec,2]=ir

    end
    #---Initializing receiver data matrces
    rec_vr=zeros(nt,nrec)
    rec_vz=zeros(nt,nrec)
    rec_tii=zeros(nt,nrec)

    return rec_vr,rec_vz,rec_tii,ceil.(Int,index_allrec_vr),ceil.(Int,index_allrec_vz),ceil.(Int,index_allrec_tii)
end

#
function init_receiver_hydrophone(recgeom,nrec,dr,dz,nr,nz,nt)
    #tii(pressure) receivers
    #receivers are assigned at nearest grids

    if (minimum(recgeom[:,1])<0.) || (maximum(recgeom[:,1])>(nz-1)*dz)
       error("Check receiver geometry!")
    end
    if (minimum(recgeom[:,2])<0.) || (maximum(recgeom[:,2])>(nr-1)*dr)
       error("Check receiver geometry!")
    end

    #--Receiver indexes---
    index_allrec_tii=zeros(nrec,2) #z,r
    for irec=1:nrec
        tmpz=recgeom[irec,1]
        tmpr=recgeom[irec,2]

#        iz=round((tmpz-dz/2)/dz)+1 #tii
#        ir=round((tmpr-dr/2)/dr)+1 #tii
        iz=round(tmpz/dz)+1 #tii
        ir=round(tmpr/dr)+1 #tii
        index_allrec_tii[irec,1]=iz
        index_allrec_tii[irec,2]=ir

    end
    #---Initializing receiver data matrces
    rec_tii=zeros(nt,nrec)

    return rec_tii,ceil.(Int,index_allrec_tii)
end

function init_receiver_geophone(recgeom,nrec,dr,dz,nr,nz,nt)
    #vr,and vz receivers
    #receivers are assigned at nearest grids
    #borehole wall is not checked!

    if (minimum(recgeom[:,1])<0.) || (maximum(recgeom[:,1])>(nz-1)*dz)
       error("Check receiver geometry!")
    end
    if (minimum(recgeom[:,2])<0.) || (maximum(recgeom[:,2])>(nr-1)*dr)
       error("Check receiver geometry!")
    end

    #--Receiver indexes---
    index_allrec_vr=zeros(nrec,2) #z,r
    index_allrec_vz=zeros(nrec,2) #z,r
    index_allrec_tii=zeros(nrec,2) #z,r
    for irec=1:nrec
        tmpz=recgeom[irec,1]
        tmpr=recgeom[irec,2]

        iz=round((tmpz-dz/2)/dz)+1 #vz
        ir=round(tmpr/dr)+1 #vz
        index_allrec_vz[irec,1]=iz
        index_allrec_vz[irec,2]=ir

        iz=round(tmpz/dz)+1 #vr
        ir=round((tmpr-dr/2)/dr)+1 #vr
        index_allrec_vr[irec,1]=iz
        index_allrec_vr[irec,2]=ir

    end
    #---Initializing receiver data matrces
    rec_vr=zeros(nt,nrec)
    rec_vz=zeros(nt,nrec)

    return rec_vr,rec_vz,ceil.(Int,index_allrec_vr),ceil.(Int,index_allrec_vz)
end

#-------------------------
# obtaining values at receiver grid
#-------------------------
function getRecData_from_index!(paramarray,rec_data,rec_index,nrec,it)
    #receivers are assigned at nearest grids

    for irec=1:nrec
        iz=rec_index[irec,1]
        ir=rec_index[irec,2]
        rec_data[it,irec]=paramarray[iz,ir]
    end
end


text:
using PEPSAD, ITensors, AutoHOOT, Zygote

const itensorad = AutoHOOT.ITensorsAD

@testset "test monotonic loss decrease of optimization" begin
    Nx, Ny = 2, 3
    num_sweeps = 20
    sites = siteinds("S=1/2", Nx * Ny)
    sites = reshape(sites, Ny, Nx)
    peps = PEPS(sites; linkdims = 10)
    randomizePEPS!(peps)
    H_local = localham(Model("tfim"), sites; h = 1.0)
    losses_gd = gradient_descent(peps, H_local, stepsize = 0.005, num_sweeps = num_sweeps)
    losses_ls = optimize(peps, H_local; num_sweeps = num_sweeps, method = "GD")
    losses_lbfgs = optimize(peps, H_local; num_sweeps = num_sweeps, method = "LBFGS")
    losses_cg = optimize(peps, H_local; num_sweeps = num_sweeps, method = "CG")
    for i = 3:length(losses_gd)-1
        @test losses_gd[i] >= losses_gd[i+1]
        @test losses_ls[i] >= losses_ls[i+1]
        @test losses_lbfgs[i] >= losses_lbfgs[i+1]
        @test losses_cg[i] >= losses_cg[i+1]
    end
end

@testset "test inner product gradient" begin
    Nx = 2
    Ny = 2
    sites = siteinds("S=1/2", Nx * Ny)
    sites = reshape(sites, Ny, Nx)
    peps = PEPS(sites; linkdims = 2)
    randomizePEPS!(peps)
    function loss(peps::PEPS)
        peps_prime = PEPSAD.prime(peps; ham = false)
        peps_prime_ham = PEPSAD.prime(peps; ham = true)
        network_list = generate_inner_network(peps, peps_prime, peps_prime_ham, [])
        variables = extract_data([peps, peps_prime])
        inners = itensorad.batch_tensor_contraction(network_list, variables...)
        return itensorad.scalar(sum(inners))
    end
    g = gradient(loss, peps)
    inner = inner_network(peps, PEPSAD.prime(peps; ham = false))
    g_true_first_site = contract(inner[2:length(inner)])
    g_true_first_site = 2 * g_true_first_site
    @test isapprox(norm(g[1].data[1, 1]), norm(g_true_first_site))
end


text:
function update!(d::Stochastic{<:GeneralNode}, m::Model)
    d.distr = d.eval(m)
    d
end

function update!(d::Logical{<:GeneralNode}, m::Model)
    d.value = d.eval(m)
    d
end

function names(d::Stochastic{<:GeneralNode}, nodekey::Symbol)
    AbstractString["Tree_length["*string(nodekey)*"]"]
end

function names(d::Logical{<:GeneralNode}, nodekey::Symbol)
    AbstractString["Tree_length["*string(nodekey)*"]"]
end

function unlist(root::N) where N<:GeneralNode
    [tree_length(root)]
end

function unlist(d::T) where T <: TreeVariate
    unlist(d.value)
end

function unlist_tree(root::N) where N<:GeneralNode
    [tree_length(root)]
end

function unlist_tree(s::TreeVariate)
    unlist_tree(s.value)
end

function unlist(s::TreeVariate, x::N, transform::Bool=false)  where N <: GeneralNode
    transform ? link_sub(s.distr, s.value) : s.value
end

function link_sub(d::TreeDistribution, X::N) where N<:GeneralNode
    com = to_covariance(X)
    another_unlist(Bijectors.pd_link(com))
end

function relistlength_sub(d::TreeDistribution, s::Stochastic{<:AbstractArray{<:Real, N} where N}, X::AbstractArray{<:Real})
    another_relist(X)
end

function relistlength(d::TreeDistribution, s::Stochastic{<:AbstractArray{<:Real, N} where N}, X::AbstractArray{<:Real} )
    another_relist(X)
end

function relistlength(d::TreeDistribution, X::AbstractArray{<:GeneralNode})
    relistlength(d, X[1])
end

function relistlength(d::TreeDistribution, X::AbstractArray{<:Real})
    another_relist(X)
end

function invlink_sub(d::TreeDistribution, X::AbstractArray)
    Y = Bijectors.replace_diag(exp, X)
    Y = Bijectors.getpd(Y)
    #Y[Y .< 0] .= 0
    t = cov2tree(Y, string.(1:size(Y,1)),collect(1:size(Y,1)))
    set_binary!(t)
    number_nodes!(t)
    blv = get_branchlength_vector(t)
    set_branchlength_vector!(t, molifier.(blv, 0.003))
    t
end

function another_unlist(X::AbstractArray)
    n = size(X, 1)
    y = [X[i, j] for i = 1:n for j in 1:n if i >= j]
    y
end

function another_relist(X::AbstractArray)
    d = length(X)
    n = 0.5*(sqrt(8*d+1)-1)
    Y = [i >= j ? X[getix(i, j)] : X[getix(j, i)] for j = 1:n, i = 1:n]
    k = Int(n * (n + 1) / 2)
    (Y, k)
end

max_stars_repo_name: erathorn/MCPhylo

max_issues_repo_name: erathorn/MCPhylo

max_forks_repo_name: erathorn/MCPhylo


text:
"""
    dpclustering(y::Array{Real, 1}, N::Array{Real, 1}; <keyword arguments>)
Perform dirichlet clustering on the variant allele frequency distribution of cancer sequencing data and find the number of clusters that the data supports, y is a vector of the number of reads reporting each mutant, N is the total depth at each locus.

...
## Arguments
- `iterations = 1000`: number of iterations of the gibbs samples
- `C = 30`: Max number of clusters to consider
- `burninstart = round(Int64, iterations/2)`: Burn in of the gibbs samples
- `bw = 0.01`: Bandwidth of density estimation
- `maxxaxis = 0.7`:
- `cutoffweight = 0.05`: Minimum weight to be called a cluster
- `verbose = true`: Show progress of gibbs sampling with `ProgressMeter` package
- `A = 0.01`: Hyperparameter for α, see Nik-Zainal et al
- `B = 0.01`: Hyperparameter for α, see Nik-Zainal et al
...
"""
function dpclustering(y, N;
    iterations = 20000,
    C = 30, #max number of clusters
    burninstart = round(Int64, 5000),
    bw = 0.01, # bandwidth of density estimation
    maxxaxis = 0.7,
    cutoffweight = 0.05, #minimum weight to be called a cluster
    verbose = true,
    A = 0.01, # Hyperparameters for alpha
    B = 0.01 # Hyperparameters for alpha
    )

    sum(y .== 0) == 0 || error("Some mutations have VAF = 0.0, make sure these mutations are removed before clustering")

    nummuts = length(y)

    # Set up arrays and matrices for recording samples
    y = map(Float64, y) # make sure read counts and depth are floats
    N = map(Float64, N)
    VAF = y ./ N
    π = zeros(Float64, iterations, C)
    PrS = zeros(Float64, nummuts, C)
    α = zeros(Float64, iterations)
    mutburdens = zeros(Float64, iterations, C, nummuts)
    V = ones(Float64, iterations, C)
    clusterassignment = zeros(Int64, iterations, nummuts)

    #random initial clusters between 0 and 1
    π[1, :] = rand(Uniform(0.0, maximum(VAF)), C)
    for c in 1:C
        mutburdens[1, c, :] .= π[1, c]
    end

    α[1] = 1.0
    V[1, 1:(C - 1)] .= 0.5

    if verbose == true
      p = Progress(iterations, 1, "Gibbs sampling progress: ", 30)
    end

    for m in 2:iterations
        for k in 1:nummuts
            #Binomial log-likelihood
            PrS[k, 1] = log.(V[m .- 1, 1]) .+ (y[k] .* log.(mutburdens[m-1, 1, k])) .+
            (N[k] .- y[k]) .* log.(1 .- mutburdens[m - 1, 1, k])
            allocate!(PrS, V, mutburdens, y, N, k, C, m)
            takemax!(PrS, k, C)
            exp!(PrS, k, C)
            normalize!(PrS, k, C)
        end

        multinomsample!(clusterassignment, PrS, nummuts, m, C)

        # Update stick-breaking weights
        updatestick!(V, clusterassignment, α, C, m)

        V[m, [V[m, 1:(C-1)] .== 1.0; false]] .= 0.9999

        countsPerCopyNum = N

        mutburdens[m, :, :] = mutburdens[m - 1, :, :]
        @fastmath @inbounds for c in unique(clusterassignment[m, :])
          idx = findall((in)(c), clusterassignment[m, :])
          αp = sum(y[idx])
          βp = 1 ./ sum(countsPerCopyNum[idx])
          π[m, c] = minimum([rand(Gamma(αp, βp)), 0.999])
          mutburdens[m, c, :] .= π[m, c]
        end
        x1 = C .+ A .- 1

        x2 = sum(log.(1 .- V[m, 1:(C.-1)]))
        x3 = B .- x2

        α[m] = rand(Gamma(C .+ A .- 1, 1/(B .- sum(log.(1 .- V[m, 1:(C.-1)])))))
        #α[m] = rand(Gamma(x1, x3))

        if verbose == true
          next!(p)
        end

    end

    dp = DPout(clusterassignment, V, π, α)

    DF, wts =
    getdensity(dp, iterations; burninstart = burninstart, bw = bw, maxxaxis = maxxaxis)
    wtsout, clonefreq, allwts, allfreq =
    summariseoutput(dp, wts, iterations; burninstart = burninstart, cutoffweight = cutoffweight)

    sortind = sortperm(clonefreq)
    return DPresults(DF, wts, length(wtsout), wtsout[sortind],
    clonefreq[sortind], allwts, allfreq, dp, TargetData(y, N, VAF));
end

function multinomsample!(clusterassignment, PrS, nummuts, m, C)
  @fastmath @inbounds for k in 1:nummuts
    clusterassignment[m, k] = sum(rand(Multinomial(1, PrS[k, :])) .* collect(1:C))
  end
end

function takemax!(PrS, k, C)
  maxPrS = maximum(PrS[k, :])
  @fastmath @inbounds for i in 1:C
    PrS[k, i] = PrS[k, i] - maxPrS
  end
end

function exp!(PrS, k, C)
  @fastmath @inbounds for i in 1:C
    PrS[k, i] = exp(PrS[k, i])
  end
end

function normalize!(PrS, k, C)
  sumPrS = sum(PrS[k, :])
  @fastmath @inbounds for i in 1:C
    PrS[k, i] = PrS[k, i] / sumPrS
  end
end

function updatestick!(V, clusterassignment, α, C, m)
  @fastmath @inbounds for h in 1:(C-1)
    V[m, h] = rand(Beta(1+sum(clusterassignment[m, :] .== h), α[m - 1] + sum(clusterassignment[m, :] .> h)))
  end
end

function allocate!(PrS, V, mutburdens, obsy, obsN, k, C, m)
    @fastmath @inbounds for j in 2:C
        PrS[k, j] = log(V[m-1, j]) +
        sum(log.(1 .- view(V, m-1, 1:(j-1)))) +
        obsy[k] * log(mutburdens[m-1, j, k]) +
        (obsN[k] - obsy[k]) * log(1-mutburdens[m-1, j, k])
    end
end

function getdensity(dp, iterations; burninstart = 500, bw = 1.0, maxxaxis = 0.5)

    wts = zeros( size(dp.V)[1], size(dp.V)[2]);
    wts[:, 1] = dp.V[:, 1]
    wts[:, 2] = dp.V[:, 2] .* (1 .- dp.V[:, 1])

    for i in 3:size(wts)[2]
        wts[:, i] = dp.V[:, i] .* prod((1 .- dp.V[:, (1:i .- 1)]), dims = 2)
    end

    postints = zeros(512, iterations -  burninstart + 1)

    xx = kde(dp.π[burninstart - 1, :],
    weights = wts[burninstart, :]./(sum(wts[burninstart, :])),
                npoints = 512, boundary = (0, maxxaxis), bandwidth = bw).x

    for i in burninstart:iterations
        postints[:, i - burninstart + 1] = kde(dp.π[i - 1, :], weights = wts[i, :]./(sum(wts[i, :])),
        npoints = 512, boundary = (0, maxxaxis), bandwidth = bw).density
    end

    meanv = mean(postints, dims = 2)[:]
    lq = mapslices(x -> quantile(x, 0.025), postints, dims = 2)[:]
    uq = mapslices(x -> quantile(x, 0.975), postints, dims = 2)[:]

    DF = DataFrame(mean = meanv, lq = lq, uq = uq, x = collect(xx))

    return DF, wts
end

function summariseoutput(dp, wts, iterations; burninstart = 1000, cutoffweight = 0.05)

    postwts = wts[burninstart:iterations, :]
    meanwts = mean(postwts, dims = 1)
    clonewts = meanwts[meanwts.>cutoffweight]

    clonefrequency = mean(dp.π[burninstart:iterations, :], dims = 1)
    largeclonefrequency = clonefrequency[meanwts.>cutoffweight]

    clonefrequency = clonefrequency[:]
    meanwts = meanwts[:]

    sortind = sortperm(clonefrequency)

    return clonewts, largeclonefrequency, meanwts[sortind], clonefrequency[sortind]
end