text:
function uhd_get_last_error(error_out, strbuffer_len)
    ccall((:uhd_get_last_error, libuhd), uhd_error, (Ptr{Cchar}, Csize_t), error_out, strbuffer_len)
end

function uhd_get_abi_string(abi_string_out, buffer_len)
    ccall((:uhd_get_abi_string, libuhd), uhd_error, (Ptr{Cchar}, Csize_t), abi_string_out, buffer_len)
end

function uhd_get_version_string(version_out, buffer_len)
    ccall((:uhd_get_version_string, libuhd), uhd_error, (Ptr{Cchar}, Csize_t), version_out, buffer_len)
end

function uhd_rx_metadata_make(handle)
    ccall((:uhd_rx_metadata_make, libuhd), uhd_error, (Ptr{uhd_rx_metadata_handle},), handle)
end

function uhd_rx_metadata_free(handle)
    ccall((:uhd_rx_metadata_free, libuhd), uhd_error, (Ptr{uhd_rx_metadata_handle},), handle)
end

function uhd_rx_metadata_has_time_spec(h, result_out)
    ccall((:uhd_rx_metadata_has_time_spec, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_rx_metadata_time_spec(h, full_secs_out, frac_secs_out)
    ccall((:uhd_rx_metadata_time_spec, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Int64}, Ptr{Cdouble}), h, full_secs_out, frac_secs_out)
end

function uhd_rx_metadata_more_fragments(h, result_out)
    ccall((:uhd_rx_metadata_more_fragments, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_rx_metadata_fragment_offset(h, fragment_offset_out)
    ccall((:uhd_rx_metadata_fragment_offset, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Csize_t}), h, fragment_offset_out)
end

function uhd_rx_metadata_start_of_burst(h, result_out)
    ccall((:uhd_rx_metadata_start_of_burst, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_rx_metadata_end_of_burst(h, result_out)
    ccall((:uhd_rx_metadata_end_of_burst, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_rx_metadata_out_of_sequence(h, result_out)
    ccall((:uhd_rx_metadata_out_of_sequence, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_rx_metadata_to_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_rx_metadata_to_pp_string, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_rx_metadata_error_code(h, error_code_out)
    ccall((:uhd_rx_metadata_error_code, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{uhd_rx_metadata_error_code_t}), h, error_code_out)
end

function uhd_rx_metadata_strerror(h, strerror_out, strbuffer_len)
    ccall((:uhd_rx_metadata_strerror, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Cchar}, Csize_t), h, strerror_out, strbuffer_len)
end

function uhd_rx_metadata_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_rx_metadata_last_error, libuhd), uhd_error, (uhd_rx_metadata_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_tx_metadata_make(handle, has_time_spec, full_secs, frac_secs, start_of_burst, end_of_burst)
    ccall((:uhd_tx_metadata_make, libuhd), uhd_error, (Ptr{uhd_tx_metadata_handle}, Bool, Int64, Cdouble, Bool, Bool), handle, has_time_spec, full_secs, frac_secs, start_of_burst, end_of_burst)
end

function uhd_tx_metadata_free(handle)
    ccall((:uhd_tx_metadata_free, libuhd), uhd_error, (Ptr{uhd_tx_metadata_handle},), handle)
end

function uhd_tx_metadata_has_time_spec(h, result_out)
    ccall((:uhd_tx_metadata_has_time_spec, libuhd), uhd_error, (uhd_tx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_tx_metadata_time_spec(h, full_secs_out, frac_secs_out)
    ccall((:uhd_tx_metadata_time_spec, libuhd), uhd_error, (uhd_tx_metadata_handle, Ptr{Int64}, Ptr{Cdouble}), h, full_secs_out, frac_secs_out)
end

function uhd_tx_metadata_start_of_burst(h, result_out)
    ccall((:uhd_tx_metadata_start_of_burst, libuhd), uhd_error, (uhd_tx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_tx_metadata_end_of_burst(h, result_out)
    ccall((:uhd_tx_metadata_end_of_burst, libuhd), uhd_error, (uhd_tx_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_tx_metadata_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_tx_metadata_last_error, libuhd), uhd_error, (uhd_tx_metadata_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_async_metadata_make(handle)
    ccall((:uhd_async_metadata_make, libuhd), uhd_error, (Ptr{uhd_async_metadata_handle},), handle)
end

function uhd_async_metadata_free(handle)
    ccall((:uhd_async_metadata_free, libuhd), uhd_error, (Ptr{uhd_async_metadata_handle},), handle)
end

function uhd_async_metadata_channel(h, channel_out)
    ccall((:uhd_async_metadata_channel, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{Csize_t}), h, channel_out)
end

function uhd_async_metadata_has_time_spec(h, result_out)
    ccall((:uhd_async_metadata_has_time_spec, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{Bool}), h, result_out)
end

function uhd_async_metadata_time_spec(h, full_secs_out, frac_secs_out)
    ccall((:uhd_async_metadata_time_spec, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{Int64}, Ptr{Cdouble}), h, full_secs_out, frac_secs_out)
end

function uhd_async_metadata_event_code(h, event_code_out)
    ccall((:uhd_async_metadata_event_code, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{uhd_async_metadata_event_code_t}), h, event_code_out)
end

function uhd_async_metadata_user_payload(h, user_payload_out)
    ccall((:uhd_async_metadata_user_payload, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{UInt32}), h, user_payload_out)
end

function uhd_async_metadata_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_async_metadata_last_error, libuhd), uhd_error, (uhd_async_metadata_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_range_to_pp_string(range, pp_string_out, strbuffer_len)
    ccall((:uhd_range_to_pp_string, libuhd), uhd_error, (Ptr{uhd_range_t}, Ptr{Cchar}, Csize_t), range, pp_string_out, strbuffer_len)
end

function uhd_meta_range_make(h)
    ccall((:uhd_meta_range_make, libuhd), uhd_error, (Ptr{uhd_meta_range_handle},), h)
end

function uhd_meta_range_free(h)
    ccall((:uhd_meta_range_free, libuhd), uhd_error, (Ptr{uhd_meta_range_handle},), h)
end

function uhd_meta_range_start(h, start_out)
    ccall((:uhd_meta_range_start, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Cdouble}), h, start_out)
end

function uhd_meta_range_stop(h, stop_out)
    ccall((:uhd_meta_range_stop, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Cdouble}), h, stop_out)
end

function uhd_meta_range_step(h, step_out)
    ccall((:uhd_meta_range_step, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Cdouble}), h, step_out)
end

function uhd_meta_range_clip(h, value, clip_step, result_out)
    ccall((:uhd_meta_range_clip, libuhd), uhd_error, (uhd_meta_range_handle, Cdouble, Bool, Ptr{Cdouble}), h, value, clip_step, result_out)
end

function uhd_meta_range_size(h, size_out)
    ccall((:uhd_meta_range_size, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Csize_t}), h, size_out)
end

function uhd_meta_range_push_back(h, range)
    ccall((:uhd_meta_range_push_back, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{uhd_range_t}), h, range)
end

function uhd_meta_range_at(h, num, range_out)
    ccall((:uhd_meta_range_at, libuhd), uhd_error, (uhd_meta_range_handle, Csize_t, Ptr{uhd_range_t}), h, num, range_out)
end

function uhd_meta_range_to_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_meta_range_to_pp_string, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_meta_range_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_meta_range_last_error, libuhd), uhd_error, (uhd_meta_range_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_sensor_value_make(h)
    ccall((:uhd_sensor_value_make, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle},), h)
end

function uhd_sensor_value_make_from_bool(h, name, value, utrue, ufalse)
    ccall((:uhd_sensor_value_make_from_bool, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle}, Ptr{Cchar}, Bool, Ptr{Cchar}, Ptr{Cchar}), h, name, value, utrue, ufalse)
end

function uhd_sensor_value_make_from_int(h, name, value, unit, formatter)
    ccall((:uhd_sensor_value_make_from_int, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle}, Ptr{Cchar}, Cint, Ptr{Cchar}, Ptr{Cchar}), h, name, value, unit, formatter)
end

function uhd_sensor_value_make_from_realnum(h, name, value, unit, formatter)
    ccall((:uhd_sensor_value_make_from_realnum, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle}, Ptr{Cchar}, Cdouble, Ptr{Cchar}, Ptr{Cchar}), h, name, value, unit, formatter)
end

function uhd_sensor_value_make_from_string(h, name, value, unit)
    ccall((:uhd_sensor_value_make_from_string, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle}, Ptr{Cchar}, Ptr{Cchar}, Ptr{Cchar}), h, name, value, unit)
end

function uhd_sensor_value_free(h)
    ccall((:uhd_sensor_value_free, libuhd), uhd_error, (Ptr{uhd_sensor_value_handle},), h)
end

function uhd_sensor_value_to_bool(h, value_out)
    ccall((:uhd_sensor_value_to_bool, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Bool}), h, value_out)
end

function uhd_sensor_value_to_int(h, value_out)
    ccall((:uhd_sensor_value_to_int, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cint}), h, value_out)
end

function uhd_sensor_value_to_realnum(h, value_out)
    ccall((:uhd_sensor_value_to_realnum, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cdouble}), h, value_out)
end

function uhd_sensor_value_name(h, name_out, strbuffer_len)
    ccall((:uhd_sensor_value_name, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cchar}, Csize_t), h, name_out, strbuffer_len)
end

function uhd_sensor_value_value(h, value_out, strbuffer_len)
    ccall((:uhd_sensor_value_value, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cchar}, Csize_t), h, value_out, strbuffer_len)
end

function uhd_sensor_value_unit(h, unit_out, strbuffer_len)
    ccall((:uhd_sensor_value_unit, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cchar}, Csize_t), h, unit_out, strbuffer_len)
end

function uhd_sensor_value_data_type(h, data_type_out)
    ccall((:uhd_sensor_value_data_type, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{uhd_sensor_value_data_type_t}), h, data_type_out)
end

function uhd_sensor_value_to_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_sensor_value_to_pp_string, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_sensor_value_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_sensor_value_last_error, libuhd), uhd_error, (uhd_sensor_value_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_string_vector_make(h)
    ccall((:uhd_string_vector_make, libuhd), uhd_error, (Ptr{uhd_string_vector_handle},), h)
end

function uhd_string_vector_free(h)
    ccall((:uhd_string_vector_free, libuhd), uhd_error, (Ptr{uhd_string_vector_handle},), h)
end

function uhd_string_vector_push_back(h, value)
    ccall((:uhd_string_vector_push_back, libuhd), uhd_error, (Ptr{uhd_string_vector_handle}, Ptr{Cchar}), h, value)
end

function uhd_string_vector_at(h, index, value_out, strbuffer_len)
    ccall((:uhd_string_vector_at, libuhd), uhd_error, (uhd_string_vector_handle, Csize_t, Ptr{Cchar}, Csize_t), h, index, value_out, strbuffer_len)
end

function uhd_string_vector_size(h, size_out)
    ccall((:uhd_string_vector_size, libuhd), uhd_error, (uhd_string_vector_handle, Ptr{Csize_t}), h, size_out)
end

function uhd_string_vector_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_string_vector_last_error, libuhd), uhd_error, (uhd_string_vector_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_tune_result_to_pp_string(tune_result, pp_string_out, strbuffer_len)
    ccall((:uhd_tune_result_to_pp_string, libuhd), Cvoid, (Ptr{uhd_tune_result_t}, Ptr{Cchar}, Csize_t), tune_result, pp_string_out, strbuffer_len)
end

function uhd_usrp_rx_info_free(rx_info)
    ccall((:uhd_usrp_rx_info_free, libuhd), uhd_error, (Ptr{uhd_usrp_rx_info_t},), rx_info)
end

function uhd_usrp_tx_info_free(tx_info)
    ccall((:uhd_usrp_tx_info_free, libuhd), uhd_error, (Ptr{uhd_usrp_tx_info_t},), tx_info)
end

function uhd_dboard_eeprom_make(h)
    ccall((:uhd_dboard_eeprom_make, libuhd), uhd_error, (Ptr{uhd_dboard_eeprom_handle},), h)
end

function uhd_dboard_eeprom_free(h)
    ccall((:uhd_dboard_eeprom_free, libuhd), uhd_error, (Ptr{uhd_dboard_eeprom_handle},), h)
end

function uhd_dboard_eeprom_get_id(h, id_out, strbuffer_len)
    ccall((:uhd_dboard_eeprom_get_id, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cchar}, Csize_t), h, id_out, strbuffer_len)
end

function uhd_dboard_eeprom_set_id(h, id)
    ccall((:uhd_dboard_eeprom_set_id, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cchar}), h, id)
end

function uhd_dboard_eeprom_get_serial(h, serial_out, strbuffer_len)
    ccall((:uhd_dboard_eeprom_get_serial, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cchar}, Csize_t), h, serial_out, strbuffer_len)
end

function uhd_dboard_eeprom_set_serial(h, serial)
    ccall((:uhd_dboard_eeprom_set_serial, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cchar}), h, serial)
end

function uhd_dboard_eeprom_get_revision(h, revision_out)
    ccall((:uhd_dboard_eeprom_get_revision, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cint}), h, revision_out)
end

function uhd_dboard_eeprom_set_revision(h, revision)
    ccall((:uhd_dboard_eeprom_set_revision, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Cint), h, revision)
end

function uhd_dboard_eeprom_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_dboard_eeprom_last_error, libuhd), uhd_error, (uhd_dboard_eeprom_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_mboard_eeprom_make(h)
    ccall((:uhd_mboard_eeprom_make, libuhd), uhd_error, (Ptr{uhd_mboard_eeprom_handle},), h)
end

function uhd_mboard_eeprom_free(h)
    ccall((:uhd_mboard_eeprom_free, libuhd), uhd_error, (Ptr{uhd_mboard_eeprom_handle},), h)
end

function uhd_mboard_eeprom_get_value(h, key, value_out, strbuffer_len)
    ccall((:uhd_mboard_eeprom_get_value, libuhd), uhd_error, (uhd_mboard_eeprom_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t), h, key, value_out, strbuffer_len)
end

function uhd_mboard_eeprom_set_value(h, key, value)
    ccall((:uhd_mboard_eeprom_set_value, libuhd), uhd_error, (uhd_mboard_eeprom_handle, Ptr{Cchar}, Ptr{Cchar}), h, key, value)
end

function uhd_mboard_eeprom_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_mboard_eeprom_last_error, libuhd), uhd_error, (uhd_mboard_eeprom_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_subdev_spec_pair_free(subdev_spec_pair)
    ccall((:uhd_subdev_spec_pair_free, libuhd), uhd_error, (Ptr{uhd_subdev_spec_pair_t},), subdev_spec_pair)
end

function uhd_subdev_spec_pairs_equal(first, second, result_out)
    ccall((:uhd_subdev_spec_pairs_equal, libuhd), uhd_error, (Ptr{uhd_subdev_spec_pair_t}, Ptr{uhd_subdev_spec_pair_t}, Ptr{Bool}), first, second, result_out)
end

function uhd_subdev_spec_make(h, markup)
    ccall((:uhd_subdev_spec_make, libuhd), uhd_error, (Ptr{uhd_subdev_spec_handle}, Ptr{Cchar}), h, markup)
end

function uhd_subdev_spec_free(h)
    ccall((:uhd_subdev_spec_free, libuhd), uhd_error, (Ptr{uhd_subdev_spec_handle},), h)
end

function uhd_subdev_spec_size(h, size_out)
    ccall((:uhd_subdev_spec_size, libuhd), uhd_error, (uhd_subdev_spec_handle, Ptr{Csize_t}), h, size_out)
end

function uhd_subdev_spec_push_back(h, markup)
    ccall((:uhd_subdev_spec_push_back, libuhd), uhd_error, (uhd_subdev_spec_handle, Ptr{Cchar}), h, markup)
end

function uhd_subdev_spec_at(h, num, subdev_spec_pair_out)
    ccall((:uhd_subdev_spec_at, libuhd), uhd_error, (uhd_subdev_spec_handle, Csize_t, Ptr{uhd_subdev_spec_pair_t}), h, num, subdev_spec_pair_out)
end

function uhd_subdev_spec_to_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_subdev_spec_to_pp_string, libuhd), uhd_error, (uhd_subdev_spec_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_subdev_spec_to_string(h, string_out, strbuffer_len)
    ccall((:uhd_subdev_spec_to_string, libuhd), uhd_error, (uhd_subdev_spec_handle, Ptr{Cchar}, Csize_t), h, string_out, strbuffer_len)
end

function uhd_subdev_spec_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_subdev_spec_last_error, libuhd), uhd_error, (uhd_subdev_spec_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_rx_streamer_make(h)
    ccall((:uhd_rx_streamer_make, libuhd), uhd_error, (Ptr{uhd_rx_streamer_handle},), h)
end

function uhd_rx_streamer_free(h)
    ccall((:uhd_rx_streamer_free, libuhd), uhd_error, (Ptr{uhd_rx_streamer_handle},), h)
end

function uhd_rx_streamer_num_channels(h, num_channels_out)
    ccall((:uhd_rx_streamer_num_channels, libuhd), uhd_error, (uhd_rx_streamer_handle, Ptr{Csize_t}), h, num_channels_out)
end

function uhd_rx_streamer_max_num_samps(h, max_num_samps_out)
    ccall((:uhd_rx_streamer_max_num_samps, libuhd), uhd_error, (uhd_rx_streamer_handle, Ptr{Csize_t}), h, max_num_samps_out)
end

function uhd_rx_streamer_recv(h, buffs, samps_per_buff, md, timeout, one_packet, items_recvd)
    ccall((:uhd_rx_streamer_recv, libuhd), uhd_error, (uhd_rx_streamer_handle, Ptr{Ptr{Cvoid}}, Csize_t, Ptr{uhd_rx_metadata_handle}, Cdouble, Bool, Ptr{Csize_t}), h, buffs, samps_per_buff, md, timeout, one_packet, items_recvd)
end

function uhd_rx_streamer_issue_stream_cmd(h, stream_cmd)
    ccall((:uhd_rx_streamer_issue_stream_cmd, libuhd), uhd_error, (uhd_rx_streamer_handle, Ptr{uhd_stream_cmd_t}), h, stream_cmd)
end

function uhd_rx_streamer_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_rx_streamer_last_error, libuhd), uhd_error, (uhd_rx_streamer_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_tx_streamer_make(h)
    ccall((:uhd_tx_streamer_make, libuhd), uhd_error, (Ptr{uhd_tx_streamer_handle},), h)
end

function uhd_tx_streamer_free(h)
    ccall((:uhd_tx_streamer_free, libuhd), uhd_error, (Ptr{uhd_tx_streamer_handle},), h)
end

function uhd_tx_streamer_num_channels(h, num_channels_out)
    ccall((:uhd_tx_streamer_num_channels, libuhd), uhd_error, (uhd_tx_streamer_handle, Ptr{Csize_t}), h, num_channels_out)
end

function uhd_tx_streamer_max_num_samps(h, max_num_samps_out)
    ccall((:uhd_tx_streamer_max_num_samps, libuhd), uhd_error, (uhd_tx_streamer_handle, Ptr{Csize_t}), h, max_num_samps_out)
end

function uhd_tx_streamer_send(h, buffs, samps_per_buff, md, timeout, items_sent)
    ccall((:uhd_tx_streamer_send, libuhd), uhd_error, (uhd_tx_streamer_handle, Ptr{Ptr{Cvoid}}, Csize_t, Ptr{uhd_tx_metadata_handle}, Cdouble, Ptr{Csize_t}), h, buffs, samps_per_buff, md, timeout, items_sent)
end

function uhd_tx_streamer_recv_async_msg(h, md, timeout, valid)
    ccall((:uhd_tx_streamer_recv_async_msg, libuhd), uhd_error, (uhd_tx_streamer_handle, Ptr{uhd_async_metadata_handle}, Cdouble, Ptr{Bool}), h, md, timeout, valid)
end

function uhd_tx_streamer_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_tx_streamer_last_error, libuhd), uhd_error, (uhd_tx_streamer_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_usrp_find(args, strings_out)
    ccall((:uhd_usrp_find, libuhd), uhd_error, (Ptr{Cchar}, Ptr{uhd_string_vector_handle}), args, strings_out)
end

function uhd_usrp_make(h, args)
    ccall((:uhd_usrp_make, libuhd), uhd_error, (Ptr{uhd_usrp_handle}, Ptr{Cchar}), h, args)
end

function uhd_usrp_free(h)
    ccall((:uhd_usrp_free, libuhd), uhd_error, (Ptr{uhd_usrp_handle},), h)
end

function uhd_usrp_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_usrp_last_error, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_usrp_get_rx_stream(h, stream_args, h_out)
    ccall((:uhd_usrp_get_rx_stream, libuhd), uhd_error, (uhd_usrp_handle, Ptr{uhd_stream_args_t}, uhd_rx_streamer_handle), h, stream_args, h_out)
end

function uhd_usrp_get_tx_stream(h, stream_args, h_out)
    ccall((:uhd_usrp_get_tx_stream, libuhd), uhd_error, (uhd_usrp_handle, Ptr{uhd_stream_args_t}, uhd_tx_streamer_handle), h, stream_args, h_out)
end

function uhd_usrp_get_rx_info(h, chan, info_out)
    ccall((:uhd_usrp_get_rx_info, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_usrp_rx_info_t}), h, chan, info_out)
end

function uhd_usrp_get_tx_info(h, chan, info_out)
    ccall((:uhd_usrp_get_tx_info, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_usrp_tx_info_t}), h, chan, info_out)
end

function uhd_usrp_set_master_clock_rate(h, rate, mboard)
    ccall((:uhd_usrp_set_master_clock_rate, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, rate, mboard)
end

function uhd_usrp_get_master_clock_rate(h, mboard, clock_rate_out)
    ccall((:uhd_usrp_get_master_clock_rate, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, mboard, clock_rate_out)
end

function uhd_usrp_get_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_usrp_get_pp_string, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_usrp_get_mboard_name(h, mboard, mboard_name_out, strbuffer_len)
    ccall((:uhd_usrp_get_mboard_name, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, mboard, mboard_name_out, strbuffer_len)
end

function uhd_usrp_get_time_now(h, mboard, full_secs_out, frac_secs_out)
    ccall((:uhd_usrp_get_time_now, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Int64}, Ptr{Cdouble}), h, mboard, full_secs_out, frac_secs_out)
end

function uhd_usrp_get_time_last_pps(h, mboard, full_secs_out, frac_secs_out)
    ccall((:uhd_usrp_get_time_last_pps, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Int64}, Ptr{Cdouble}), h, mboard, full_secs_out, frac_secs_out)
end

function uhd_usrp_set_time_now(h, full_secs, frac_secs, mboard)
    ccall((:uhd_usrp_set_time_now, libuhd), uhd_error, (uhd_usrp_handle, Int64, Cdouble, Csize_t), h, full_secs, frac_secs, mboard)
end

function uhd_usrp_set_time_next_pps(h, full_secs, frac_secs, mboard)
    ccall((:uhd_usrp_set_time_next_pps, libuhd), uhd_error, (uhd_usrp_handle, Int64, Cdouble, Csize_t), h, full_secs, frac_secs, mboard)
end

function uhd_usrp_set_time_unknown_pps(h, full_secs, frac_secs)
    ccall((:uhd_usrp_set_time_unknown_pps, libuhd), uhd_error, (uhd_usrp_handle, Int64, Cdouble), h, full_secs, frac_secs)
end

function uhd_usrp_get_time_synchronized(h, result_out)
    ccall((:uhd_usrp_get_time_synchronized, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Bool}), h, result_out)
end

function uhd_usrp_set_command_time(h, full_secs, frac_secs, mboard)
    ccall((:uhd_usrp_set_command_time, libuhd), uhd_error, (uhd_usrp_handle, Int64, Cdouble, Csize_t), h, full_secs, frac_secs, mboard)
end

function uhd_usrp_clear_command_time(h, mboard)
    ccall((:uhd_usrp_clear_command_time, libuhd), uhd_error, (uhd_usrp_handle, Csize_t), h, mboard)
end

function uhd_usrp_set_time_source(h, time_source, mboard)
    ccall((:uhd_usrp_set_time_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, time_source, mboard)
end

function uhd_usrp_get_time_source(h, mboard, time_source_out, strbuffer_len)
    ccall((:uhd_usrp_get_time_source, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, mboard, time_source_out, strbuffer_len)
end

function uhd_usrp_get_time_sources(h, mboard, time_sources_out)
    ccall((:uhd_usrp_get_time_sources, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, mboard, time_sources_out)
end

function uhd_usrp_set_clock_source(h, clock_source, mboard)
    ccall((:uhd_usrp_set_clock_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, clock_source, mboard)
end

function uhd_usrp_get_clock_source(h, mboard, clock_source_out, strbuffer_len)
    ccall((:uhd_usrp_get_clock_source, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, mboard, clock_source_out, strbuffer_len)
end

function uhd_usrp_get_clock_sources(h, mboard, clock_sources_out)
    ccall((:uhd_usrp_get_clock_sources, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, mboard, clock_sources_out)
end

function uhd_usrp_set_clock_source_out(h, enb, mboard)
    ccall((:uhd_usrp_set_clock_source_out, libuhd), uhd_error, (uhd_usrp_handle, Bool, Csize_t), h, enb, mboard)
end

function uhd_usrp_set_time_source_out(h, enb, mboard)
    ccall((:uhd_usrp_set_time_source_out, libuhd), uhd_error, (uhd_usrp_handle, Bool, Csize_t), h, enb, mboard)
end

function uhd_usrp_get_num_mboards(h, num_mboards_out)
    ccall((:uhd_usrp_get_num_mboards, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Csize_t}), h, num_mboards_out)
end

function uhd_usrp_get_mboard_sensor(h, name, mboard, sensor_value_out)
    ccall((:uhd_usrp_get_mboard_sensor, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_sensor_value_handle}), h, name, mboard, sensor_value_out)
end

function uhd_usrp_get_mboard_sensor_names(h, mboard, mboard_sensor_names_out)
    ccall((:uhd_usrp_get_mboard_sensor_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, mboard, mboard_sensor_names_out)
end

function uhd_usrp_set_user_register(h, addr, data, mboard)
    ccall((:uhd_usrp_set_user_register, libuhd), uhd_error, (uhd_usrp_handle, UInt8, UInt32, Csize_t), h, addr, data, mboard)
end

function uhd_usrp_get_mboard_eeprom(h, mb_eeprom, mboard)
    ccall((:uhd_usrp_get_mboard_eeprom, libuhd), uhd_error, (uhd_usrp_handle, uhd_mboard_eeprom_handle, Csize_t), h, mb_eeprom, mboard)
end

function uhd_usrp_set_mboard_eeprom(h, mb_eeprom, mboard)
    ccall((:uhd_usrp_set_mboard_eeprom, libuhd), uhd_error, (uhd_usrp_handle, uhd_mboard_eeprom_handle, Csize_t), h, mb_eeprom, mboard)
end

function uhd_usrp_get_dboard_eeprom(h, db_eeprom, unit, slot, mboard)
    ccall((:uhd_usrp_get_dboard_eeprom, libuhd), uhd_error, (uhd_usrp_handle, uhd_dboard_eeprom_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t), h, db_eeprom, unit, slot, mboard)
end

function uhd_usrp_set_dboard_eeprom(h, db_eeprom, unit, slot, mboard)
    ccall((:uhd_usrp_set_dboard_eeprom, libuhd), uhd_error, (uhd_usrp_handle, uhd_dboard_eeprom_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t), h, db_eeprom, unit, slot, mboard)
end

function uhd_usrp_set_rx_subdev_spec(h, subdev_spec, mboard)
    ccall((:uhd_usrp_set_rx_subdev_spec, libuhd), uhd_error, (uhd_usrp_handle, uhd_subdev_spec_handle, Csize_t), h, subdev_spec, mboard)
end

function uhd_usrp_get_rx_subdev_spec(h, mboard, subdev_spec_out)
    ccall((:uhd_usrp_get_rx_subdev_spec, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_subdev_spec_handle), h, mboard, subdev_spec_out)
end

function uhd_usrp_get_rx_num_channels(h, num_channels_out)
    ccall((:uhd_usrp_get_rx_num_channels, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Csize_t}), h, num_channels_out)
end

function uhd_usrp_get_rx_subdev_name(h, chan, rx_subdev_name_out, strbuffer_len)
    ccall((:uhd_usrp_get_rx_subdev_name, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, chan, rx_subdev_name_out, strbuffer_len)
end

function uhd_usrp_set_rx_rate(h, rate, chan)
    ccall((:uhd_usrp_set_rx_rate, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, rate, chan)
end

function uhd_usrp_get_rx_rate(h, chan, rate_out)
    ccall((:uhd_usrp_get_rx_rate, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, rate_out)
end

function uhd_usrp_get_rx_rates(h, chan, rates_out)
    ccall((:uhd_usrp_get_rx_rates, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, rates_out)
end

function uhd_usrp_set_rx_freq(h, tune_request, chan, tune_result)
    ccall((:uhd_usrp_set_rx_freq, libuhd), uhd_error, (uhd_usrp_handle, Ptr{uhd_tune_request_t}, Csize_t, Ptr{uhd_tune_result_t}), h, tune_request, chan, tune_result)
end

function uhd_usrp_get_rx_freq(h, chan, freq_out)
    ccall((:uhd_usrp_get_rx_freq, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, freq_out)
end

function uhd_usrp_get_rx_freq_range(h, chan, freq_range_out)
    ccall((:uhd_usrp_get_rx_freq_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, freq_range_out)
end

function uhd_usrp_get_fe_rx_freq_range(h, chan, freq_range_out)
    ccall((:uhd_usrp_get_fe_rx_freq_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, freq_range_out)
end

function uhd_usrp_get_rx_lo_names(h, chan, rx_lo_names_out)
    ccall((:uhd_usrp_get_rx_lo_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, rx_lo_names_out)
end

function uhd_usrp_set_rx_lo_source(h, src, name, chan)
    ccall((:uhd_usrp_set_rx_lo_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t), h, src, name, chan)
end

function uhd_usrp_get_rx_lo_source(h, name, chan, rx_lo_source_out, strbuffer_len)
    ccall((:uhd_usrp_get_rx_lo_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Cchar}, Csize_t), h, name, chan, rx_lo_source_out, strbuffer_len)
end

function uhd_usrp_get_rx_lo_sources(h, name, chan, rx_lo_sources_out)
    ccall((:uhd_usrp_get_rx_lo_sources, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_string_vector_handle}), h, name, chan, rx_lo_sources_out)
end

function uhd_usrp_set_rx_lo_export_enabled(h, enabled, name, chan)
    ccall((:uhd_usrp_set_rx_lo_export_enabled, libuhd), uhd_error, (uhd_usrp_handle, Bool, Ptr{Cchar}, Csize_t), h, enabled, name, chan)
end

function uhd_usrp_get_rx_lo_export_enabled(h, name, chan, result_out)
    ccall((:uhd_usrp_get_rx_lo_export_enabled, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Bool}), h, name, chan, result_out)
end

function uhd_usrp_set_rx_lo_freq(h, freq, name, chan, coerced_freq_out)
    ccall((:uhd_usrp_set_rx_lo_freq, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Ptr{Cchar}, Csize_t, Ptr{Cdouble}), h, freq, name, chan, coerced_freq_out)
end

function uhd_usrp_get_rx_lo_freq(h, name, chan, rx_lo_freq_out)
    ccall((:uhd_usrp_get_rx_lo_freq, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Cdouble}), h, name, chan, rx_lo_freq_out)
end

function uhd_usrp_set_rx_gain(h, gain, chan, gain_name)
    ccall((:uhd_usrp_set_rx_gain, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t, Ptr{Cchar}), h, gain, chan, gain_name)
end

function uhd_usrp_set_normalized_rx_gain(h, gain, chan)
    ccall((:uhd_usrp_set_normalized_rx_gain, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, gain, chan)
end

function uhd_usrp_set_rx_agc(h, enable, chan)
    ccall((:uhd_usrp_set_rx_agc, libuhd), uhd_error, (uhd_usrp_handle, Bool, Csize_t), h, enable, chan)
end

function uhd_usrp_get_rx_gain(h, chan, gain_name, gain_out)
    ccall((:uhd_usrp_get_rx_gain, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Ptr{Cdouble}), h, chan, gain_name, gain_out)
end

function uhd_usrp_get_normalized_rx_gain(h, chan, gain_out)
    ccall((:uhd_usrp_get_normalized_rx_gain, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, gain_out)
end

function uhd_usrp_get_rx_gain_range(h, name, chan, gain_range_out)
    ccall((:uhd_usrp_get_rx_gain_range, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, uhd_meta_range_handle), h, name, chan, gain_range_out)
end

function uhd_usrp_get_rx_gain_names(h, chan, gain_names_out)
    ccall((:uhd_usrp_get_rx_gain_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, gain_names_out)
end

function uhd_usrp_set_rx_antenna(h, ant, chan)
    ccall((:uhd_usrp_set_rx_antenna, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, ant, chan)
end

function uhd_usrp_get_rx_antenna(h, chan, ant_out, strbuffer_len)
    ccall((:uhd_usrp_get_rx_antenna, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, chan, ant_out, strbuffer_len)
end

function uhd_usrp_get_rx_antennas(h, chan, antennas_out)
    ccall((:uhd_usrp_get_rx_antennas, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, antennas_out)
end

function uhd_usrp_get_rx_sensor_names(h, chan, sensor_names_out)
    ccall((:uhd_usrp_get_rx_sensor_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, sensor_names_out)
end

function uhd_usrp_set_rx_bandwidth(h, bandwidth, chan)
    ccall((:uhd_usrp_set_rx_bandwidth, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, bandwidth, chan)
end

function uhd_usrp_get_rx_bandwidth(h, chan, bandwidth_out)
    ccall((:uhd_usrp_get_rx_bandwidth, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, bandwidth_out)
end

function uhd_usrp_get_rx_bandwidth_range(h, chan, bandwidth_range_out)
    ccall((:uhd_usrp_get_rx_bandwidth_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, bandwidth_range_out)
end

function uhd_usrp_get_rx_sensor(h, name, chan, sensor_value_out)
    ccall((:uhd_usrp_get_rx_sensor, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_sensor_value_handle}), h, name, chan, sensor_value_out)
end

function uhd_usrp_set_rx_dc_offset_enabled(h, enb, chan)
    ccall((:uhd_usrp_set_rx_dc_offset_enabled, libuhd), uhd_error, (uhd_usrp_handle, Bool, Csize_t), h, enb, chan)
end

function uhd_usrp_set_rx_iq_balance_enabled(h, enb, chan)
    ccall((:uhd_usrp_set_rx_iq_balance_enabled, libuhd), uhd_error, (uhd_usrp_handle, Bool, Csize_t), h, enb, chan)
end

function uhd_usrp_set_tx_subdev_spec(h, subdev_spec, mboard)
    ccall((:uhd_usrp_set_tx_subdev_spec, libuhd), uhd_error, (uhd_usrp_handle, uhd_subdev_spec_handle, Csize_t), h, subdev_spec, mboard)
end

function uhd_usrp_get_tx_subdev_spec(h, mboard, subdev_spec_out)
    ccall((:uhd_usrp_get_tx_subdev_spec, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_subdev_spec_handle), h, mboard, subdev_spec_out)
end

function uhd_usrp_get_tx_num_channels(h, num_channels_out)
    ccall((:uhd_usrp_get_tx_num_channels, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Csize_t}), h, num_channels_out)
end

function uhd_usrp_get_tx_subdev_name(h, chan, tx_subdev_name_out, strbuffer_len)
    ccall((:uhd_usrp_get_tx_subdev_name, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, chan, tx_subdev_name_out, strbuffer_len)
end

function uhd_usrp_set_tx_rate(h, rate, chan)
    ccall((:uhd_usrp_set_tx_rate, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, rate, chan)
end

function uhd_usrp_get_tx_rate(h, chan, rate_out)
    ccall((:uhd_usrp_get_tx_rate, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, rate_out)
end

function uhd_usrp_get_tx_rates(h, chan, rates_out)
    ccall((:uhd_usrp_get_tx_rates, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, rates_out)
end

function uhd_usrp_set_tx_freq(h, tune_request, chan, tune_result)
    ccall((:uhd_usrp_set_tx_freq, libuhd), uhd_error, (uhd_usrp_handle, Ptr{uhd_tune_request_t}, Csize_t, Ptr{uhd_tune_result_t}), h, tune_request, chan, tune_result)
end

function uhd_usrp_get_tx_freq(h, chan, freq_out)
    ccall((:uhd_usrp_get_tx_freq, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, freq_out)
end

function uhd_usrp_get_tx_freq_range(h, chan, freq_range_out)
    ccall((:uhd_usrp_get_tx_freq_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, freq_range_out)
end

function uhd_usrp_get_fe_tx_freq_range(h, chan, freq_range_out)
    ccall((:uhd_usrp_get_fe_tx_freq_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, freq_range_out)
end

function uhd_usrp_get_tx_lo_names(h, chan, tx_lo_names_out)
    ccall((:uhd_usrp_get_tx_lo_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, tx_lo_names_out)
end

function uhd_usrp_set_tx_lo_source(h, src, name, chan)
    ccall((:uhd_usrp_set_tx_lo_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t), h, src, name, chan)
end

function uhd_usrp_get_tx_lo_source(h, name, chan, tx_lo_source_out, strbuffer_len)
    ccall((:uhd_usrp_get_tx_lo_source, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Cchar}, Csize_t), h, name, chan, tx_lo_source_out, strbuffer_len)
end

function uhd_usrp_get_tx_lo_sources(h, name, chan, tx_lo_sources_out)
    ccall((:uhd_usrp_get_tx_lo_sources, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_string_vector_handle}), h, name, chan, tx_lo_sources_out)
end

function uhd_usrp_set_tx_lo_export_enabled(h, enabled, name, chan)
    ccall((:uhd_usrp_set_tx_lo_export_enabled, libuhd), uhd_error, (uhd_usrp_handle, Bool, Ptr{Cchar}, Csize_t), h, enabled, name, chan)
end

function uhd_usrp_get_tx_lo_export_enabled(h, name, chan, result_out)
    ccall((:uhd_usrp_get_tx_lo_export_enabled, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Bool}), h, name, chan, result_out)
end

function uhd_usrp_set_tx_lo_freq(h, freq, name, chan, coerced_freq_out)
    ccall((:uhd_usrp_set_tx_lo_freq, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Ptr{Cchar}, Csize_t, Ptr{Cdouble}), h, freq, name, chan, coerced_freq_out)
end

function uhd_usrp_get_tx_lo_freq(h, name, chan, tx_lo_freq_out)
    ccall((:uhd_usrp_get_tx_lo_freq, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{Cdouble}), h, name, chan, tx_lo_freq_out)
end

function uhd_usrp_set_tx_gain(h, gain, chan, gain_name)
    ccall((:uhd_usrp_set_tx_gain, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t, Ptr{Cchar}), h, gain, chan, gain_name)
end

function uhd_usrp_set_normalized_tx_gain(h, gain, chan)
    ccall((:uhd_usrp_set_normalized_tx_gain, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, gain, chan)
end

function uhd_usrp_get_tx_gain_range(h, name, chan, gain_range_out)
    ccall((:uhd_usrp_get_tx_gain_range, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, uhd_meta_range_handle), h, name, chan, gain_range_out)
end

function uhd_usrp_get_tx_gain(h, chan, gain_name, gain_out)
    ccall((:uhd_usrp_get_tx_gain, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Ptr{Cdouble}), h, chan, gain_name, gain_out)
end

function uhd_usrp_get_normalized_tx_gain(h, chan, gain_out)
    ccall((:uhd_usrp_get_normalized_tx_gain, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, gain_out)
end

function uhd_usrp_get_tx_gain_names(h, chan, gain_names_out)
    ccall((:uhd_usrp_get_tx_gain_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, gain_names_out)
end

function uhd_usrp_set_tx_antenna(h, ant, chan)
    ccall((:uhd_usrp_set_tx_antenna, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t), h, ant, chan)
end

function uhd_usrp_get_tx_antenna(h, chan, ant_out, strbuffer_len)
    ccall((:uhd_usrp_get_tx_antenna, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cchar}, Csize_t), h, chan, ant_out, strbuffer_len)
end

function uhd_usrp_get_tx_antennas(h, chan, antennas_out)
    ccall((:uhd_usrp_get_tx_antennas, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, antennas_out)
end

function uhd_usrp_set_tx_bandwidth(h, bandwidth, chan)
    ccall((:uhd_usrp_set_tx_bandwidth, libuhd), uhd_error, (uhd_usrp_handle, Cdouble, Csize_t), h, bandwidth, chan)
end

function uhd_usrp_get_tx_bandwidth(h, chan, bandwidth_out)
    ccall((:uhd_usrp_get_tx_bandwidth, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{Cdouble}), h, chan, bandwidth_out)
end

function uhd_usrp_get_tx_bandwidth_range(h, chan, bandwidth_range_out)
    ccall((:uhd_usrp_get_tx_bandwidth_range, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, uhd_meta_range_handle), h, chan, bandwidth_range_out)
end

function uhd_usrp_get_tx_sensor(h, name, chan, sensor_value_out)
    ccall((:uhd_usrp_get_tx_sensor, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_sensor_value_handle}), h, name, chan, sensor_value_out)
end

function uhd_usrp_get_tx_sensor_names(h, chan, sensor_names_out)
    ccall((:uhd_usrp_get_tx_sensor_names, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, chan, sensor_names_out)
end

function uhd_usrp_get_gpio_banks(h, mboard, gpio_banks_out)
    ccall((:uhd_usrp_get_gpio_banks, libuhd), uhd_error, (uhd_usrp_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, mboard, gpio_banks_out)
end

function uhd_usrp_set_gpio_attr(h, bank, attr, value, mask, mboard)
    ccall((:uhd_usrp_set_gpio_attr, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Ptr{Cchar}, UInt32, UInt32, Csize_t), h, bank, attr, value, mask, mboard)
end

function uhd_usrp_get_gpio_attr(h, bank, attr, mboard, attr_out)
    ccall((:uhd_usrp_get_gpio_attr, libuhd), uhd_error, (uhd_usrp_handle, Ptr{Cchar}, Ptr{Cchar}, Csize_t, Ptr{UInt32}), h, bank, attr, mboard, attr_out)
end

function uhd_usrp_clock_find(args, devices_out)
    ccall((:uhd_usrp_clock_find, libuhd), uhd_error, (Ptr{Cchar}, Ptr{uhd_string_vector_t}), args, devices_out)
end

function uhd_usrp_clock_make(h, args)
    ccall((:uhd_usrp_clock_make, libuhd), uhd_error, (Ptr{uhd_usrp_clock_handle}, Ptr{Cchar}), h, args)
end

function uhd_usrp_clock_free(h)
    ccall((:uhd_usrp_clock_free, libuhd), uhd_error, (Ptr{uhd_usrp_clock_handle},), h)
end

function uhd_usrp_clock_last_error(h, error_out, strbuffer_len)
    ccall((:uhd_usrp_clock_last_error, libuhd), uhd_error, (uhd_usrp_clock_handle, Ptr{Cchar}, Csize_t), h, error_out, strbuffer_len)
end

function uhd_usrp_clock_get_pp_string(h, pp_string_out, strbuffer_len)
    ccall((:uhd_usrp_clock_get_pp_string, libuhd), uhd_error, (uhd_usrp_clock_handle, Ptr{Cchar}, Csize_t), h, pp_string_out, strbuffer_len)
end

function uhd_usrp_clock_get_num_boards(h, num_boards_out)
    ccall((:uhd_usrp_clock_get_num_boards, libuhd), uhd_error, (uhd_usrp_clock_handle, Ptr{Csize_t}), h, num_boards_out)
end

function uhd_usrp_clock_get_time(h, board, clock_time_out)
    ccall((:uhd_usrp_clock_get_time, libuhd), uhd_error, (uhd_usrp_clock_handle, Csize_t, Ptr{UInt32}), h, board, clock_time_out)
end

function uhd_usrp_clock_get_sensor(h, name, board, sensor_value_out)
    ccall((:uhd_usrp_clock_get_sensor, libuhd), uhd_error, (uhd_usrp_clock_handle, Ptr{Cchar}, Csize_t, Ptr{uhd_sensor_value_handle}), h, name, board, sensor_value_out)
end

function uhd_usrp_clock_get_sensor_names(h, board, sensor_names_out)
    ccall((:uhd_usrp_clock_get_sensor_names, libuhd), uhd_error, (uhd_usrp_clock_handle, Csize_t, Ptr{uhd_string_vector_handle}), h, board, sensor_names_out)
end

function uhd_set_thread_priority(priority, realtime)
    ccall((:uhd_set_thread_priority, libuhd), uhd_error, (Cfloat, Bool), priority, realtime)
end

max_stars_repo_name: RGerzaguet/UHDBindings

max_issues_repo_name: RGerzaguet/UHDBindings


text:
using Test
using MPI
using ClimateMachine
ClimateMachine.init()
using ClimateMachine.Mesh.Topologies
using ClimateMachine.Mesh.Grids
using ClimateMachine.MPIStateArrays
using ClimateMachine.Mesh.DSS
using KernelAbstractions

DA = ClimateMachine.array_type()

function test_dss_stacked_3d()
    FT = Float64
    comm = MPI.COMM_WORLD
    crank = MPI.Comm_rank(comm)
    csize = MPI.Comm_size(comm)

    @assert csize == 3

    N = (4, 4, 5)
    brickrange = (0:4, 5:9, 0:3)
    periodicity = (false, false, false)
    nvars = 3

    topl = StackedBrickTopology(
        comm,
        brickrange,
        periodicity = periodicity,
        boundary = ((1, 2), (3, 4), (5, 6)),
        connectivity = :full,
    )
    grid = DiscontinuousSpectralElementGrid(
        topl,
        FloatType = FT,
        DeviceArray = DA,
        polynomialorder = N,
    )

    Nq = N .+ 1
    Np = prod(Nq)
    Q = MPIStateArray{FT}(
        comm,
        DA,
        Np,
        nvars,
        length(topl.elems),
        realelems = topl.realelems,
        ghostelems = topl.ghostelems,
        vmaprecv = grid.vmaprecv,
        vmapsend = grid.vmapsend,
        nabrtorank = topl.nabrtorank,
        nabrtovmaprecv = grid.nabrtovmaprecv,
        nabrtovmapsend = grid.nabrtovmapsend,
    )
    realelems = Q.realelems
    ghostelems = Q.ghostelems

    Q.data[:, :, realelems] .= FT(1)
    Q.data[:, :, ghostelems] .= FT(0)

    dss!(Q, grid)
    #---------Tests-------------------------
    nodes = reshape(1:Np, Nq)
    interior = nodes[2:(Nq[1] - 1), 2:(Nq[2] - 1), 2:(Nq[3] - 1)][:]
    vertmap = Array(grid.vertmap)
    edgemap = Array(grid.edgemap)
    facemap = Array(grid.facemap)
    data = Array(Q.data)
    compare(data, ivar, iel, efmap) =
        unique(data[setdiff(efmap, [-1]), ivar, lel])
    lel = 1 # local element number for each process

    if crank == 0
        for ivar in 1:nvars
            # local element #1, global elememt # 1
            # interior dof should not be affected
            idof = unique(data[interior, ivar, lel])
            @test idof == [FT(1)]
            # vertex dof check
            @test data[vertmap, ivar, lel] == FT.([1, 2, 2, 4, 2, 4, 4, 8])
            # edge dof check
            @test compare(data, ivar, lel, edgemap[:, 1, 1]) == [FT(1)] # edge #  1
            @test compare(data, ivar, lel, edgemap[:, 2, 1]) == [FT(2)] # edge #  2
            @test compare(data, ivar, lel, edgemap[:, 3, 1]) == [FT(2)] # edge #  3
            @test compare(data, ivar, lel, edgemap[:, 4, 1]) == [FT(4)] # edge #  4
            @test compare(data, ivar, lel, edgemap[:, 5, 1]) == [FT(1)] # edge #  5
            @test compare(data, ivar, lel, edgemap[:, 6, 1]) == [FT(2)] # edge #  6
            @test compare(data, ivar, lel, edgemap[:, 7, 1]) == [FT(2)] # edge #  7
            @test compare(data, ivar, lel, edgemap[:, 8, 1]) == [FT(4)] # edge #  8
            @test compare(data, ivar, lel, edgemap[:, 9, 1]) == [FT(1)] # edge #  9
            @test compare(data, ivar, lel, edgemap[:, 10, 1]) == [FT(2)] # edge # 10
            @test compare(data, ivar, lel, edgemap[:, 11, 1]) == [FT(2)] # edge # 11
            @test compare(data, ivar, lel, edgemap[:, 12, 1]) == [FT(4)] # edge # 12

            # face dof check
            @test compare(data, ivar, lel, facemap[:, 1, 1]) == [FT(1)] # face # 1
            @test compare(data, ivar, lel, facemap[:, 2, 1]) == [FT(2)] # face # 2
            @test compare(data, ivar, lel, facemap[:, 3, 1]) == [FT(1)] # face # 3
            @test compare(data, ivar, lel, facemap[:, 4, 1]) == [FT(2)] # face # 4
            @test compare(data, ivar, lel, facemap[:, 5, 1]) == [FT(1)] # face # 5
            @test compare(data, ivar, lel, facemap[:, 6, 1]) == [FT(2)] # face # 6
        end

    elseif crank == 1
        for ivar in 1:nvars
            # local element #1, global elememt # 6 (in 2D)
            # interior dof should not be affected
            idof = unique(data[interior, ivar, lel])
            @test idof == [FT(1)]
            # vertex dof check
            @test data[vertmap, ivar, lel] == FT.([2, 4, 1, 2, 4, 8, 2, 4])
            # edge dof check
            @test compare(data, ivar, lel, edgemap[:, 1, 1]) == [FT(2)] # edge #  1
            @test compare(data, ivar, lel, edgemap[:, 2, 1]) == [FT(1)] # edge #  2
            @test compare(data, ivar, lel, edgemap[:, 3, 1]) == [FT(4)] # edge #  3
            @test compare(data, ivar, lel, edgemap[:, 4, 1]) == [FT(2)] # edge #  4
            @test compare(data, ivar, lel, edgemap[:, 5, 1]) == [FT(1)] # edge #  5
            @test compare(data, ivar, lel, edgemap[:, 6, 1]) == [FT(2)] # edge #  6
            @test compare(data, ivar, lel, edgemap[:, 7, 1]) == [FT(2)] # edge #  7
            @test compare(data, ivar, lel, edgemap[:, 8, 1]) == [FT(4)] # edge #  8
            @test compare(data, ivar, lel, edgemap[:, 9, 1]) == [FT(2)] # edge #  9
            @test compare(data, ivar, lel, edgemap[:, 10, 1]) == [FT(4)] # edge # 10
            @test compare(data, ivar, lel, edgemap[:, 11, 1]) == [FT(1)] # edge # 11
            @test compare(data, ivar, lel, edgemap[:, 12, 1]) == [FT(2)] # edge # 12

            # face dof check
            @test compare(data, ivar, lel, facemap[:, 1, 1]) == [FT(1)] # face # 1
            @test compare(data, ivar, lel, facemap[:, 2, 1]) == [FT(2)] # face # 2
            @test compare(data, ivar, lel, facemap[:, 3, 1]) == [FT(2)] # face # 3
            @test compare(data, ivar, lel, facemap[:, 4, 1]) == [FT(1)] # face # 4
            @test compare(data, ivar, lel, facemap[:, 5, 1]) == [FT(1)] # face # 5
            @test compare(data, ivar, lel, facemap[:, 6, 1]) == [FT(2)] # face # 6
        end
    else # crank == 2
        for ivar in 1:nvars
            # local element #1, global elememt # 11 (in 2D)
            # interior dof should not be affected
            idof = unique(data[interior, ivar, lel])
            @test idof == [FT(1)]
            # vertex dof check
            @test data[vertmap, ivar, lel] == FT.([4, 2, 2, 1, 8, 4, 4, 2])
            # edge dof check
            @test compare(data, ivar, lel, edgemap[:, 1, 1]) == [FT(2)] # edge #  1
            @test compare(data, ivar, lel, edgemap[:, 2, 1]) == [FT(1)] # edge #  2
            @test compare(data, ivar, lel, edgemap[:, 3, 1]) == [FT(4)] # edge #  3
            @test compare(data, ivar, lel, edgemap[:, 4, 1]) == [FT(2)] # edge #  4
            @test compare(data, ivar, lel, edgemap[:, 5, 1]) == [FT(2)] # edge #  5
            @test compare(data, ivar, lel, edgemap[:, 6, 1]) == [FT(1)] # edge #  6
            @test compare(data, ivar, lel, edgemap[:, 7, 1]) == [FT(4)] # edge #  7
            @test compare(data, ivar, lel, edgemap[:, 8, 1]) == [FT(2)] # edge #  8
            @test compare(data, ivar, lel, edgemap[:, 9, 1]) == [FT(4)] # edge #  9
            @test compare(data, ivar, lel, edgemap[:, 10, 1]) == [FT(2)] # edge # 10
            @test compare(data, ivar, lel, edgemap[:, 11, 1]) == [FT(2)] # edge # 11
            @test compare(data, ivar, lel, edgemap[:, 12, 1]) == [FT(1)] # edge # 12
            # face dof check
            @test compare(data, ivar, lel, facemap[:, 1, 1]) == [FT(2)] # face # 1
            @test compare(data, ivar, lel, facemap[:, 2, 1]) == [FT(1)] # face # 2
            @test compare(data, ivar, lel, facemap[:, 3, 1]) == [FT(2)] # face # 3
            @test compare(data, ivar, lel, facemap[:, 4, 1]) == [FT(1)] # face # 4
            @test compare(data, ivar, lel, facemap[:, 5, 1]) == [FT(1)] # face # 5
            @test compare(data, ivar, lel, facemap[:, 6, 1]) == [FT(2)] # face # 6
        end
    end
end

test_dss_stacked_3d()

ext: jl


text:
abstract type AbstractDataset end
abstract type AbstractDataPoint end

const default_root = normpath(@__DIR__, "../../datasets/")

function download_and_verify(url, path, hash)
    tmppath = tempname()
    download(url, tmppath)
    hash_download = open(tmppath) do f
        bytes2hex(SHA.sha256(f))
    end
    if hash_download !== hash
        msg = "Hash Mismatch!\n"
        msg *= "  Expected sha256:   $hash\n"
        msg *= "  Calculated sha256: $hash_download"
        error(msg)
    end
    mv(tmppath, path; force = true)
end

struct DataPoint <: AbstractDataPoint
    idx::Int
    data::Flux3D.AbstractObject
    ground_truth::UInt8
    category_name::String
end

function Base.show(io::IO, d::DataPoint)
    print(
        io,
        "DataPoint:",
        "\n    idx: ",
        d.idx,
        "\n    data: ",
        typeof(d.data),
        "\n    ground_truth: ",
        d.ground_truth,
        "\n    category_name: ",
        d.category_name,
    )
end

Base.size(d::AbstractDataset) = error("define Base.size of dataset type: $(typeof(d)).")
Base.length(d::AbstractDataset) = error("define Base.length of dataset type: $(typeof(d)).")

Base.show(io::IO, p::AbstractDataPoint) =
    print(io, "idx: $(p.idx), data: $(typeof(p.data))")

function Base.show(io::IO, dset::AbstractDataset)
    print(io, "Dataset(")
    print("root = $(dset.root), ")
    print("train = $(dset.train), ")
    print("length = $(dset.length))")
end


text:
using Distributed

dt = 0.1
exit_time = 1

n_formulations = 2

max_iterations = max_cycle_length
iteration = 0
results = nothing
finished = nothing
wids = nothing

function clean_results()
    global results
    global finished
    results = Vector{Any}(nothing, n_formulations)
    finished = Array{Bool,1}(undef, n_formulations)
end

function create_procs()
    extra_procs = max(max_iterations*n_formulations+1-nprocs(), 0)
    addprocs(extra_procs)
    proc_min = 2+iteration*n_formulations
    proc_max = proc_min+n_formulations-1
    global wids
    wids = collect(proc_min:proc_max)
    @everywhere include("includes.jl")
end

clean_results()
create_procs()

struct Parallel
    args::Any

    function Parallel(args...)
        new(args)
    end
end

@everywhere function solve_basic(index, args)
    println("Basic started")
    instance = Basic(args...)
    result = solve(instance)
    println("Basic finished")
    @spawnat 1 begin
        results[index] = result
        finished[index] = true
    end
end

@everywhere function solve_intermediate(index, args)
    println("Intermediate started")
    instance = Intermediate(args...)
    result = solve(instance)
    println("Intermediate finished")
    @spawnat 1 begin
        results[index] = result
        finished[index] = true
    end
end

function get_first(args)
    implementations = [solve_basic, solve_intermediate]

    clean_results()
    create_procs()
    n = n_formulations
    for i in 1:n
        wid = wids[i]
        f = Future(wid)
        @spawnat wid implementations[i](i, args)
    end
    first_finished = false
    result = nothing
    while !first_finished
        first_finished = all_finished()
        for i in 1:n
            if !isnothing(results[i])
                result = results[i]
                first_finished = true
                break
            end
        end
        sleep(dt)
    end
    exit_processes()
    global iteration
    iteration += 1
    return result
end

function all_finished()
    return all(finished)
end

function exit_processes()
    for i in wids
        @async interrupt(i)
    end
    sleep(exit_time)
end

function solve(problem::Parallel)
    return get_first(problem.args)
end


text:
@testsection "Tens" begin
    sq2 = √Sym(2)
    v = Sym[0 1 1; 1 0 1; 1 1 0]
    b = Basis(v)
    bn = normalize(b)
    for i ∈ 1:3
        @eval $(Symbol("v$i")) = symbols($"v$i", real = true)
    end
    V = Tens(Tensor{1,3}(i -> eval(Symbol("v$i"))))
    @test simplify(components(V, b, (:cont,))) ==
          [(-v1 + v2 + v3) / 2, (v1 - v2 + v3) / 2, (v1 + v2 - v3) / 2]
    @test simplify(components(V, b, (:cov,))) == [v2 + v3, v1 + v3, v1 + v2]
    @test simplify(components(V, bn, (:cov,))) ==
          [sq2 * (v2 + v3) / 2, sq2 * (v1 + v3) / 2, sq2 * (v1 + v2) / 2]

    for i ∈ 1:3, j ∈ 1:3
        @eval $(Symbol("t$i$j")) = symbols($"t$i$j", real = true)
    end
    T = Tens(Tensor{2,3}((i, j) -> eval(Symbol("t$i$j"))))
    @test simplify(components(T, b, (:cov, :cov))) == [
        t22+t23+t32+t33 t21+t23+t31+t33 t21+t22+t31+t32
        t12+t13+t32+t33 t11+t13+t31+t33 t11+t12+t31+t32
        t12+t13+t22+t23 t11+t13+t21+t23 t11+t12+t21+t22
    ]
    @test simplify(components(T, b, (:cont, :cov))) ==
          [
        -t12-t13+t22+t23+t32+t33 -t11-t13+t21+t23+t31+t33 -t11-t12+t21+t22+t31+t32
        t12+t13-t22-t23+t32+t33 t11+t13-t21-t23+t31+t33 t11+t12-t21-t22+t31+t32
        t12+t13+t22+t23-t32-t33 t11+t13+t21+t23-t31-t33 t11+t12+t21+t22-t31-t32
    ] / 2

    for i ∈ 1:3
        @eval $(Symbol("a$i")) = symbols($"a$i", real = true)
        @eval $(Symbol("b$i")) = symbols($"b$i", real = true)
    end
    a = Tens(Vec{3}((i,) -> eval(Symbol("a$i"))))
    b = Tens(Vec{3}((i,) -> eval(Symbol("b$i"))))
    @test a ⊗ b == Sym[a1*b1 a1*b2 a1*b3; a2*b1 a2*b2 a2*b3; a3*b1 a3*b2 a3*b3]
    @test a ⊗ˢ b == Sym[
        a1*b1 a1*b2/2+a2*b1/2 a1*b3/2+a3*b1/2
        a1*b2/2+a2*b1/2 a2*b2 a2*b3/2+a3*b2/2
        a1*b3/2+a3*b1/2 a2*b3/2+a3*b2/2 a3*b3
    ]

    θ, ϕ, ψ = symbols("θ, ϕ, ψ", real = true)
    R = rot3(θ, ϕ, ψ)
    Λ = [symbols("λ$i", positive = true) for i ∈ 1:3]
    bg = Basis(R .* Λ')
    bo = Basis(R)
    𝕀, 𝕁, 𝕂 = ISO()
    α, β = symbols("α β", real = true)
    𝕋 = α * 𝕁 + β * 𝕂
    @test change_tens(𝕋, bg) == 𝕋
    @test change_tens(𝕋, bo) == 𝕋
    A = components(𝕋, bg)
    𝕋₂ = Tens(A, bg)
    @test 𝕋₂ == 𝕋

end


text:
using Documenter, Weave

makedocs(
    modules = [Weave],
    format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
    sitename = "Weave.jl",
    pages = [
        "index.md",
        "getting_started.md",
        "usage.md",
        "publish.md",
        "chunk_options.md",
        "notebooks.md",
        "function_index.md",
    ],
)

include("make_examples.jl")

deploydocs(
    repo = "github.com/mpastell/Weave.jl.git",
    push_preview = true,
)


text:
"""
code adapted from https://discourse.julialang.org/t/custom-subject-in-rocket-jl-for-mouse-events-from-glfw/65133/3
module coordinating response to the  keyboard input - mainly shortcuts that  helps controlling  active/visible texture2D
"""
#@doc ReactOnKeyboardSTR
module ReactOnKeyboard
using ModernGL, ..DisplayWords, ..StructsManag, Setfield, ..PrepareWindow,   ..DataStructs , Rocket, GLFW,Dictionaries,  ..ForDisplayStructs, ..TextureManag,  ..OpenGLDisplayUtils,  ..Uniforms, Match, Parameters,DataTypesBasic
using ..KeyboardMouseHelper,..MaskDiffrence, ..KeyboardVisibility, ..OtherKeyboardActions, ..WindowControll, ..ChangePlane
export reactToKeyboard , registerKeyboardFunctions,processKeysInfo

"""
will "tell" what functions should be invoked in order to process keyboard input
"""
function Rocket.on_subscribe!(handler::KeyboardCallbackSubscribable, actor::SyncActor{Any, ActorWithOpenGlObjects})
    return subscribe!(handler.subject, actor)
end

"""
given pressed keys lik 1-9 and all letters resulting key is encoded as string and will be passed here
handler object responsible for capturing action
str - name of key lik 1,5 f,.j ... but not ctrl shift etc
action - for example key press or release
scancode - if key do not have short name like ctrl ... it has scancode
"""
function (handler::KeyboardCallbackSubscribable)(str::String, action::GLFW.Action)

    if( (action==instances(GLFW.Action)[2])  )
        push!(handler.lastKeysPressed ,str)
   end#if
end #handler

GLFW.PRESS

function (handler::KeyboardCallbackSubscribable)(scancode ::GLFW.Key, action::GLFW.Action)
    #1 pressed , 2 released -1 sth else
    act =  @match action begin
        instances(GLFW.Action)[2] => 1
        instances(GLFW.Action)[1] => 2
        _ => -1
    end

   if(act>0)# so we have press or relese

         scCode = @match scancode begin
            GLFW.KEY_RIGHT_CONTROL=> (handler.isCtrlPressed= (act==1); "ctrl" )
            GLFW.KEY_LEFT_CONTROL => (handler.isCtrlPressed= (act==1); "ctrl")
            GLFW.KEY_LEFT_SHIFT =>( handler.isShiftPressed= (act==1); "shift")
            GLFW.KEY_RIGHT_SHIFT =>( handler.isShiftPressed=( act==1); "shift")
            GLFW.KEY_RIGHT_ALT =>( handler.isAltPressed= (act==1); "alt")
            GLFW.KEY_LEFT_ALT => (handler.isAltPressed= (act==1); "alt")
            GLFW.KEY_SPACE => (handler.isSpacePressed= (act==1); "space")
            GLFW.KEY_TAB => (handler.isTAbPressed= (act==1); "tab")
            GLFW.KEY_ENTER =>( handler.isEnterPressed= (act==1); "enter")
            GLFW.KEY_F1 =>( handler.isEnterPressed= (act==1); "f1")
            GLFW.KEY_F2 =>( handler.isEnterPressed= (act==1); "f2")
            GLFW.KEY_F3 =>( handler.isEnterPressed= (act==1); "f3")
            GLFW.KEY_F4 =>( handler.isF4Pressed= (act==1); "f4")
            GLFW.KEY_F5 =>( handler.isF5Pressed= (act==1); "f5")
            GLFW.KEY_F6 =>( handler.isF6Pressed= (act==1); "f6")
            GLFW.KEY_Z =>( handler.isZPressed= (act==1); "z")

            GLFW.KEY_F =>( handler.isFPressed= (act==1); "f")
            GLFW.KEY_S =>( handler.isSPressed= (act==1); "s")

            GLFW.KEY_KP_ADD =>( handler.isPlusPressed= (act==1); "+")
            GLFW.KEY_EQUAL =>( handler.isPlusPressed= (act==1); "+")

            GLFW.KEY_KP_SUBTRACT =>( handler.isMinusPressed= (act==1); "-")
            GLFW.KEY_MINUS =>( handler.isMinusPressed= (act==1); "-")
            _ => "notImp" # not Important

         end
            res = KeyboardStruct(isCtrlPressed=handler.isCtrlPressed || scCode=="ctrl"
                    , isShiftPressed= handler.isShiftPressed ||scCode=="shift"
                    ,isAltPressed= handler.isAltPressed ||scCode=="alt"
                    ,isSpacePressed= handler.isSpacePressed ||scCode=="space"
                    ,isTAbPressed= handler.isTAbPressed ||scCode=="tab"
                    ,isF1Pressed= handler.isF1Pressed ||scCode=="f1"
                    ,isF2Pressed= handler.isF2Pressed ||scCode=="f2"
                    ,isF3Pressed= handler.isF3Pressed ||scCode=="f3"
                    ,isF4Pressed= handler.isF4Pressed ||scCode=="f4"
                    ,isF5Pressed= handler.isF5Pressed ||scCode=="f5"
                    ,isF6Pressed= handler.isF6Pressed ||scCode=="f6"

                    ,isZPressed= handler.isZPressed ||scCode=="z"
                    ,isFPressed= handler.isFPressed ||scCode=="f"
                    ,isSPressed= handler.isSPressed ||scCode=="s"

                    ,isPlusPressed= handler.isPlusPressed ||scCode=="+"
                    ,isMinusPressed= handler.isMinusPressed ||scCode=="-"

                    ,isEnterPressed= handler.isEnterPressed
                    ,lastKeysPressed= handler.lastKeysPressed
                    ,mostRecentScanCode = scancode
                    ,mostRecentKeyName = "" # just marking it as empty
                    ,mostRecentAction = action)

            if(shouldBeExecuted(res,act))
                next!(handler.subject, res )
                handler.lastKeysPressed=[]

            end#if

    end#if

end #second handler

"""
registering functions to the GLFW
window - GLFW window with Visualization
stopListening - atomic boolean enabling unlocking GLFW context
"""
function registerKeyboardFunctions(window::GLFW.Window,stopListening::Base.Threads.Atomic{Bool}    )

    stopListening[]=true # stoping event listening loop to free the GLFW context

    keyboardSubs = KeyboardCallbackSubscribable()

    GLFW.SetKeyCallback(window, (_, key, scancode, action, mods) -> begin
        name = GLFW.GetKeyName(key, scancode)
        if name === nothing || name =="+" || name =="-" || name =="z"  || name =="f"  || name =="s"
            keyboardSubs(key,action)
        else
            keyboardSubs(name,action)
        end
        end)

   stopListening[]=false # reactivate event listening loop

return keyboardSubs

end #registerKeyboardFunctions

#multiple dispatch controls what will be invoked
processKeysInfo(a::Const{Nothing},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) = "" # just doing nothing in case of empty option
processKeysInfo(a::Identity{Tuple{Const{Nothing}, Identity{TextureSpec{T}}}},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) where T = "" # just doing nothing in case of empty option
processKeysInfo(a::Identity{Tuple{Const{Nothing}, Const{Nothing}}},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) = "" # just doing nothing in case of empty option
processKeysInfo(a::Identity{Tuple{ Identity{TextureSpec{T}}, Const{Nothing}}},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) where T = "" # just doing nothing in case of empty option
#just passing definitions from submodules
processKeysInfo(textSpecObs::Identity{TextureSpec{T}},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) where T = KeyboardVisibility.processKeysInfo(textSpecObs,actor,keyInfo)
processKeysInfo(toScrollDatPrim::Identity{DataToScrollDims},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct,toBeSavedForBack::Bool = true ) where T = ChangePlane.processKeysInfo(toScrollDatPrim,actor, keyInfo, toBeSavedForBack )
processKeysInfo(maskNumbs::Identity{Tuple{Identity{TextureSpec{T}}, Identity{TextureSpec{G}}}},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) where {T,G} = MaskDiffrence.processKeysInfo(maskNumbs,actor,keyInfo)
processKeysInfo(numbb::Identity{Int64}     ,actor::SyncActor{Any, ActorWithOpenGlObjects}  ,keyInfo::KeyboardStruct    ,toBeSavedForBack::Bool = true) where T = OtherKeyboardActions.processKeysInfo(numbb,actor,keyInfo,toBeSavedForBack   )
processKeysInfo(numbb::Identity{Bool},actor::SyncActor{Any, ActorWithOpenGlObjects},keyInfo::KeyboardStruct ) where T = OtherKeyboardActions.processKeysInfoUndo( numbb, actor,keyInfo  )
processKeysInfo(annot::Identity{AnnotationStruct}  ,actor::SyncActor{Any, ActorWithOpenGlObjects} ,keyInfo::KeyboardStruct ,toBeSavedForBack::Bool = true) where T = OtherKeyboardActions.processKeysInfo(annot,actor,keyInfo,toBeSavedForBack  )

processKeysInfo(isTobeFast::Identity{Tuple{Bool,Bool}}  ,actor::SyncActor{Any, ActorWithOpenGlObjects} ,keyInfo::KeyboardStruct ,toBeSavedForBack::Bool = true) where T = KeyboardMouseHelper.processKeysInfo(isTobeFast,actor,keyInfo,toBeSavedForBack  )

processKeysInfo(wind::Identity{WindowControlStruct} ,actor::SyncActor{Any, ActorWithOpenGlObjects}  ,keyInfo::KeyboardStruct  ,toBeSavedForBack::Bool = true) where T = WindowControll.processKeysInfo(wind,actor,keyInfo,toBeSavedForBack)

"""
Given keyInfo struct wit information about pressed keys it can process them to make some actions  - generally activating keyboard shortcuts
shift + number - make mask associated with given number visible
ctrl + number -  make mask associated with given number invisible
alt + number -  make mask associated with given number active for mouse interaction
tab + number - sets the number that will be  used as an input to masks modified by mouse
shift + numberA + "m" +numberB  - display diffrence between masks associated with numberA and numberB - also it makes automaticall mask A and B invisible
ctrl + numberA + "m" +numberB  - stops displaying diffrence between masks associated with numberA and numberB - also it makes automaticall mask A and B visible
space + 1 or 2 or 3 - change the plane of view (transverse, coronal, sagittal)
ctrl + z - undo last action
tab +/- increase or decrease stroke width
F1, F2 ... - switch between defined window display characteristics - like min shown white and mx shown black ...
"""
function reactToKeyboard(keyInfo::KeyboardStruct
                        , actor::SyncActor{Any, ActorWithOpenGlObjects})

    #we got this only when ctrl/shift/als is released or enter is pressed
    obj = actor.actor.mainForDisplayObjects
    obj.stopListening[]=true #free GLFW context
    # processing here on is based on multiple dispatch mainly
    processKeysInfo(parseString(keyInfo.lastKeysPressed,actor,keyInfo),actor,keyInfo)

    obj.stopListening[]=false # reactivete event listening loop

end#reactToKeyboard

"""
return true in case the combination of keys should invoke some action
"""
function shouldBeExecuted(keyInfo::KeyboardStruct, act::Int64)::Bool
    if(act>0)# so we have press or relese
        res =  @match keyInfo.mostRecentScanCode begin
      GLFW.KEY_RIGHT_CONTROL => return act==2 # returning true if we relese key
      GLFW.KEY_LEFT_CONTROL => return act==2
      GLFW.KEY_LEFT_SHIFT => return act==2
      GLFW.KEY_RIGHT_SHIFT=> return act==2
      GLFW.KEY_RIGHT_ALT => return act==2
      GLFW.KEY_LEFT_ALT => return act==2
      GLFW.KEY_SPACE => return act==2
      GLFW.KEY_TAB => return act==2
      GLFW.KEY_ENTER  => return act==1 # returning true if pressed pressed
      GLFW.KEY_F1  => return act==1
      GLFW.KEY_F2  => return act==1
      GLFW.KEY_F3  => return act==1
      GLFW.KEY_F4  => return act==2
      GLFW.KEY_F5  => return act==2
      GLFW.KEY_F6  => return act==2

      GLFW.KEY_KP_ADD =>return act==1
      GLFW.KEY_EQUAL =>return act==1

      GLFW.KEY_KP_SUBTRACT =>return act==1
      GLFW.KEY_MINUS =>return act==1
      GLFW.KEY_Z =>return act==1
      GLFW.KEY_F =>return act==1
      GLFW.KEY_S =>return act==1

            _ => false # not Important
         end#match

         return res

        end#if
   # if we got here we did not found anything intresting
return false

end#shouldBeExecuted

"""
given number from keyboard input it return array With texture that holds the texture specification we are looking for
listOfTextSpecifications - list with all registered Texture specifications
numb - string that may represent number - if it does not function will return empty option
return Option - either Texture specification or empty Option
"""
function findTextureBasedOnNumb(listOfTextSpecifications::Vector{TextureSpec}
                                ,numb::Int32
                                ,dict::Dictionary{Int32, Int64})::Option
    if(haskey(dict, numb))
        return Option(listOfTextSpecifications[dict[numb]])
    end#if
    #if we are here it mean no such texture was found
     @info "no texture associated with this number" numb
    return Option()

end #findTextureBasedOnNumb

"""
Given string it parser it to given object on the basis of with and multiple dispatch futher actions will be done
it checks each character weather is numeric - gets substring of all numeric characters and parses it into integer
listOfTextSpecifications - list with all registered Texture specifications
return option of diffrent type depending on input
"""
function parseString(str::Vector{String},actor::SyncActor{Any, ActorWithOpenGlObjects} ,keyInfo::KeyboardStruct)::Option{}
    joined = join(str)
	filtered =  filter(x->isnumeric(x) , joined )
    listOfTextSpecs = actor.actor.mainForDisplayObjects.listOfTextSpecifications
    searchDict = actor.actor.mainForDisplayObjects.numIndexes
    # for controlling window
    if(keyInfo.isF1Pressed)
        return Option(WindowControlStruct(letterCode="F1"))
    elseif(keyInfo.isF2Pressed)
        return Option(WindowControlStruct(letterCode="F2"))
    elseif(keyInfo.isF3Pressed)
        return Option(WindowControlStruct(letterCode="F3"))
    elseif(keyInfo.isF4Pressed)
        return Option(WindowControlStruct(letterCode="F4"))
    elseif(keyInfo.isF5Pressed)
        return Option(WindowControlStruct(letterCode="F5"))
    elseif(keyInfo.isF6Pressed)
        return Option(WindowControlStruct(letterCode="F6"))
    # for undoing actions
    elseif(keyInfo.isZPressed )
        return Option(true)
    elseif(keyInfo.isFPressed )
        return Option((true,false))
    elseif(keyInfo.isSPressed )
        return Option((false,true))
    # for control of stroke width
    elseif(keyInfo.isTAbPressed &&  keyInfo.isPlusPressed)
        return  Option(AnnotationStruct(1))
    elseif(keyInfo.isTAbPressed && keyInfo.isMinusPressed )
        return  Option(AnnotationStruct(-1))
    elseif(isempty(filtered))#nothing to be done
        return Option()
    # when we want to set new value for manual mask change
    elseif(keyInfo.isTAbPressed && !isempty(filtered))
        return Option(parse(Int64,filtered))
    #in case we want to change the dimension of plane for slicing data
    elseif(keyInfo.isSpacePressed && !isempty(filtered)  &&  parse(Int64,filtered)<4)
        return Option(setproperties(actor.actor.onScrollData.dataToScrollDims ,  (dimensionToScroll= parse(Int64,filtered)) )    )
     # in case we want to display diffrence of two masks
    elseif(occursin("m" , joined))

     mapped = map(splitted-> filter(x->isnumeric(x) , splitted) ,split(joined,"m")) |>
      (filtered)-> filter(it-> it!="", filtered) |>
      (filtered)->map(it->parse(Int32,it)  ,filtered)
        if(length(mapped)==2)
            textSpectOptions = map(it->findTextureBasedOnNumb(listOfTextSpecs,it, searchDict )  ,mapped )
            return Option( (textSpectOptions[1],textSpectOptions[2])  )

        end#if
        return Option()
    # in case we want to undo last action
    end#if
        #in case we have single number
	return   findTextureBasedOnNumb(listOfTextSpecs,parse(Int32,filtered), searchDict )
end#strToNumber

end #..ReactOnMouseClickAndDrag


text:
# DOCOPT faster than argparse, but a little sensitive to spacing
doc = """We use this to train Policy Gradients. UW CSE Motion Control Lab.

Usage:
   PGTrain.jl [(<experiment> <name>)]
   PGTrain.jl -h | --help

Options:
   -h --help   Show this screen.

"""

using DocOpt
opt = docopt(doc, ARGS)

@everywhere push!(LOAD_PATH, "./")

using Common

prefix="/tmp/"
modeldir="$(pwd())/models"
meshfile = "$(modeldir)/meshes/" # hack for now...

expfile=opt["<experiment>"]
expname=opt["<name>"]

myseed = 12345

@eval @everywhere const SEED = $myseed
@everywhere push!(LOAD_PATH, "$(pwd())")

println("Experiment called $(expname)")
println("Loading experiment parameters from $(expfile)")

################################################### start work by loading files
using Policy
using PolicyGradient
using ExpFunctions
using LearningStrategies

const METHOD = :NPG
include("$(pwd())/$(expfile)") # LOADING TASK FILE with PARAMETERS
@assert isdefined(:pgmodel)
@assert isdefined(:pg_specs)
@assert isdefined(:myfuncs)

# PG specific rollouts
policyrollout = PolicyRollout(myfuncs) # in setup! this makes the stochastic and mean functions

# plot stoc & mean every other iter
# TODO Generall strategies; put somewhere else?
evaluatepolicy = IterFunction((model,i)->push!(model.trace[:evalscore], myfuncs.evaluate(model.mjsys, model.meansamples)))

const NITER = 4
plotR = IterFunction(NITER, (model,i)->Common.plotlines(i,"Reward",
                                                        (model.trace[:stocR],"Stoc"),
                                                        (model.trace[:meanR],"Mean")))

plotEval = IterFunction(NITER, (model,i)->Common.plotlines(i,"Evaluation",
                                                           (model.trace[:evalscore],"")))

plotCTRL = IterFunction(NITER, (model,i)->
                        begin
                           _, idx = findmax(sum(model.meansamples.reward, 1))
                           Common.plotlines(i,"Ctrl", model.meansamples.ctrl[:,:,idx])
                        end )
#plotCTRL2 = IterFunction(NITER, (model,i)->Common.plotlines(i,"Ctrl Stoc", model.samples.ctrl[:,:,1]))

# meta strategies: order matters!!
pg_strat = strategy(PolicyExp(prefix, expfile,
                              expname, meshfile), # setup some things, hook for save

                    policyrollout,           # stochastic and mean rollouts
                    pg_specs,              # main loop for NPG
                    evaluatepolicy,          # hooks
                    plotR,
                    plotEval,
                    plotCTRL,
                    #plotCTRL2,
                    Verbose(MaxIter(pgmodel.niter)))

@time learn!(pgmodel, pg_strat)

########################## done


text:
struct NewPackage end
struct NewVersion end

abstract type AutoMergeException <: Exception
end

struct AutoMergeAuthorNotAuthorized <: AutoMergeException
    msg::String
end

struct AutoMergeCronJobError <: AutoMergeException
    msg::String
end

struct AutoMergeGuidelinesNotMet <: AutoMergeException
    msg::String
end

struct AutoMergeNeitherNewPackageNorNewVersion <: AutoMergeException
    msg::String
end

struct AutoMergePullRequestNotOpen <: AutoMergeException
    msg::String
end

struct AutoMergeShaMismatch <: AutoMergeException
    msg::String
end

struct AutoMergeWrongBuildType <: AutoMergeException
    msg::String
end


text:
# Autogenerated wrapper script for libevent_jll for x86_64-apple-darwin
export libevent

using OpenSSL_jll
JLLWrappers.@generate_wrapper_header("libevent")
JLLWrappers.@declare_library_product(libevent, "@rpath/libevent-2.1.7.dylib")
function __init__()
    JLLWrappers.@generate_init_header(OpenSSL_jll)
    JLLWrappers.@init_library_product(
        libevent,
        "lib/libevent.dylib",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@generate_init_footer()
end  # __init__()


text:
include("even_sampling.jl")

"""
Returns a matrix of convex coefficients to construct points contained within
a `dim`-dimensional simplex. Coefficients can either be random (generated
according to a uniform distribution) or be constructed such that the resulting
points are uniformly distributed within the simplex (generated by shape-preserving
splitting a generic simplex). The `sample_randomly` argument controls this
behaviour.

The default is to not sample randomly (`sample_randomly = false`). In this case,
you won't get the exact number of convex coefficient sets you want, but the
smallest number of set of coefficients such that you have *at least* `n_pts`
convex coefficient sets.

If `sample_randomly = true`, you get as many convex coefficient combinations as
`n_pts`.
"""
function subsample_coeffs(dim::Int, n_randpts::Int, sample_randomly::Bool)
    # Create a set of convex coefficients to be used for all simplices
    if sample_randomly
        convex_coeffs = rand(Distributions.Uniform(0, 1), n_randpts, dim + 1)
        convex_coeffs .= convex_coeffs ./ sum(convex_coeffs, dims=2)
    else
        minimum_split_factor = ceil(Int, n_randpts^(1 / dim))[1]
        convex_coeffs = copy(transpose(even_sampling_rules(dim, minimum_split_factor)))
    end
     copy(transpose(convex_coeffs))
end

"""
    childpoint(parentsimplex::AbstractArray{Float64, 2})

Generates a random simplex which is entirely contained within `parentsimplex`,
which is a (dim+1)-by-dim array.
"""
function childpoint(parentsimplex::AbstractArray{Float64, 2})
    dim = size(parentsimplex, 2)
    # Random linear combination coefficients
    R = rand(Float64, 1, dim + 1)

    # Normalise the coefficients so that they sum to one. We can then create
	# the new point as a convex linear combination of the vertices of the parent
	# simplex.
    R = (1 ./ sum(R, dims=2)) .* R

    R * parentsimplex
end

"""
    childpoint(parentsimplex::AbstractArray{Float64, 2})

Generates a random simplex which is entirely contained within `parentsimplex`,
which is a (dim+1)-by-dim array.
"""
function childpoint(parentsimplex::AbstractArray{Float64, 2}, dim::Int)
    # Random linear combination coefficients
    R = rand(Float64, 1, dim + 1)

    # Normalise the coefficients so that they sum to one. We can then create
	# the new point as a convex linear combination of the vertices of the parent
	# simplex.
    R = (1 ./ sum(R, dims=2)) .* R

    R * parentsimplex
end

"""
Create `n` (default: n = 100) points that lies inside `parent_simplex`,
which is a (dim+1)-by-dim array.
"""
function childpoints(parent_simplex::AbstractArray{Float64, 2}, n::Int)
    dim = size(parent_simplex, 2)

    # Random linear combination coefficients
    R = rand(Float64, n, dim + 1)

    # Normalise the coefficients so that they sum to one. We can then create
    # the new point
    # as a convex linear combination of the vertices of the parent simplex.
    normalised_coeffs = (1 ./ sum(R, dims=2)) .* R

    normalised_coeffs * parent_simplex
end

"""
Create a point that lies inside `parent_simplex`, which is a (dim+1)-by-dim
array.
"""
function outsidepoint(parentsimplex::AbstractArray{Float64, 2})
    dim = size(parentsimplex, 2)
    # Random linear combination coefficients
    R = rand(Float64, 1, dim + 1)

    # Normalise the coefficients so that they sum to one. We can then create the new point
    # as a convex linear combination of the vertices of the parent simplex.
    normalised_coeffs = (1 ./ sum(R, dims=2)) .* R
    normalised_coeffs[1] += 1

    normalised_coeffs * parentsimplex
end


text:
# Deprecated use of positional argument mem
@deprecate LBFGSOperator(T::DataType, n::Int, mem::Int; kwargs...) LBFGSOperator(
  T,
  n;
  mem = mem,
  kwargs...,
) false
@deprecate LBFGSOperator(n::Int, mem::Int; kwargs...) LBFGSOperator(n; mem = mem, kwargs...) false
@deprecate InverseLBFGSOperator(T::DataType, n::Int, mem::Int; kwargs...) InverseLBFGSOperator(
  T,
  n;
  mem = mem,
  kwargs...,
) false
@deprecate InverseLBFGSOperator(n::Int, mem::Int; kwargs...) InverseLBFGSOperator(
  n;
  mem = mem,
  kwargs...,
) false
@deprecate LSR1Operator(T::DataType, n::Int, mem::Int; kwargs...) LSR1Operator(
  T,
  n;
  mem = mem,
  kwargs...,
) false
@deprecate LSR1Operator(n::Int, mem::Int; kwargs...) LSR1Operator(n; mem = mem, kwargs...) false


text:
# Julia is Base 1 - but the CPU sets are index zero.
#
# This `IndexZero` type provides explicit description when we are in a base zero realm.

"""
    IndexZero

Specify that the value contained should be interpreted as starting at zero (0).

For example,
```julia
convert(CounterTools.IndexZero, 1) == CounterTools.IndexZero(0)
```
"""
struct IndexZero{T <: Integer}
    val::T
end

IndexZero(x::IndexZero) = x

"""
    value(x::IndexZero)

Return the Integer value of `x`.
"""
value(B::IndexZero) = B.val

Base.convert(::Type{<:IndexZero}, x::Integer) = indexzero(x)

indexzero(i::T) where {T <: Integer} = IndexZero(i - one(T))
indexzero(i::IndexZero) = i

Base.getindex(A::AbstractArray, i::IndexZero) = A[value(i) + 1]
Base.getindex(A::Tuple, i::IndexZero) = A[value(i) + 1]
Base.getindex(A::Record, i::IndexZero) = A[value(i) + 1]

# Implement the Iterator Interface
Base.iterate(x::IndexZero) = (x, nothing)
Base.iterate(x::IndexZero, ::Nothing) = nothing
Base.length(::IndexZero) = 1

const INDEX_TYPES = Union{Integer, IndexZero}


text:
"""
    prep_pass(project, pass_num)

 - Remove `pass(pass_num)/`
 - Copy files from `pass(pass_num-1)/` into `pass(pass_num)`
 - Returns files from pass_num
"""
function prep_pass(project, pass_num)
    pass_num <= 1 && error("prep_pass only valid for pass_num>1")
    rm(joinpath(project.paths[:example_root], "pass$pass_num", "src");recursive=true,force=true)
    files = [joinpath(root, f) for
            (root, dirs, files) in
            Base.Filesystem.walkdir(
            joinpath(project.paths[:example_root],
            "pass$(pass_num-1)", "src"))
            for f in files]

    mkpath(joinpath(project.paths[:example_root], "pass$pass_num", "src"))

    cd(joinpath(project.paths[:example_root], "pass$pass_num", "src")) do
        for file in files
            file_new = basename(file)
            cp(file, file_new;force=true)
        end
    end
    files = [joinpath(root, f) for
            (root, dirs, files) in
            Base.Filesystem.walkdir(
            joinpath(project.paths[:example_root],
            "pass$pass_num", "src"))
            for f in files]
    return files
end


text:
using UAParser, YAML, Test

# a helper macro for creating tests
macro testparseval(obj::Symbol, valname::String, outputname::Symbol)
    valsymb = Symbol(valname)
    esc(quote
        if $obj[$valname] == nothing
            ismissing($outputname.$valsymb)
        else
            $obj[$valname] == $outputname.$valsymb
        end
    end)
end

#Since parser is known not to be 100% compatible with source Python parser (see README), testing accuracy
#Accuracy stats derived from test files for v0.6 of package
#Any future changes to parsing code will be evaluated against this standard

@testset "parse_device" begin
    #Test 1: Validation of parsedevice
    test_device = YAML.load(open(joinpath(dirname(@__FILE__), "data", "test_device.yaml")))

    pass = 0
    fail = 0
    for test_case in test_device["test_cases"]
        test_case["family"] == parsedevice(test_case["user_agent_string"]).family ? pass += 1 : fail += 1
    end

    @test pass/(pass + fail) >= .945

end

@testset "parse_os" begin
    #Test 2: Validation of parseos
    test_os = YAML.load(open(joinpath(dirname(@__FILE__), "data", "test_os.yaml")))

    pass = 0
    fail = 0

    for value in test_os["test_cases"]
        os = parseos(value["user_agent_string"])
        value["family"] == os.family ? pass += 1 : fail += 1
        (@testparseval value "major" os) ? pass += 1 : fail += 1
        (@testparseval value "minor" os) ? pass += 1 : fail += 1
        (@testparseval value "patch_minor" os) ? pass += 1 : fail += 1
    end

    @test pass/(pass + fail) >= .992

end

@testset "parse_ua" begin
    #Test 4: Validation of parseuseragent
    test_ua = YAML.load(open(joinpath(dirname(@__FILE__), "data", "test_ua.yaml")))

    pass = 0
    fail = 0

    for value in test_ua["test_cases"]
        ua = parseuseragent(value["user_agent_string"])
        value["family"] == ua.family ? pass += 1 : fail += 1
        (@testparseval value "major" ua) ? pass += 1 : fail += 1
        (@testparseval value "minor" ua) ? pass += 1 : fail += 1
        (@testparseval value "patch" ua) ? pass += 1 : fail += 1
    end

    @test pass/(pass + fail) >= .992

end


text:
abstract type AbstractPAR end

struct PAR <: AbstractPAR
    value::Rational{UInt32}
end

struct PAR1 <: AbstractPAR
end

AbstractPAR(x) = isone(x) ? PAR1() : PAR(x)

par(x::PAR) = x.value
par(_::PAR1) = 1//1

const Image = Matrix{RGB{N0f8}}#PermutedDimsArray{RGB{Normed{UInt8,8}},2,(2, 1),(2, 1),Array{RGB{Normed{UInt8,8}},2}} #{RGB{Normed{UInt8,8}}}

abstract type AbstractPhotage end

struct Snapshot{P <: AbstractPAR} <: AbstractPhotage
    img::Image
    par::P
end

struct TimeLapse{P <: AbstractPAR} <: AbstractPhotage
    imgs::Vector{Image}
    par::P
end

par(x::AbstractPhotage) = par(x.par)

const STEP = Millisecond(60)

timestamps(t::Temporal{WholeVideo, Instantaneous}) = (t.video.file.name, start(t.time))

function timestamps(t::Temporal{FragmentedVideo, Instantaneous})
    t = start(t.time)
    for vf in files(t.video)
        d = duration(vf)
        if t ≤ d
            return (vf.name, t)
        end
        t -= d
    end
end

timestamps(t::Temporal{WholeVideo, Prolonged}) = (t.video.file.name, start(t.time):STEP:stop(t.time))

function timestamps(t::Temporal{FragmentedVideo, Prolonged})
    ranges = Dict{String, StepRange{Millisecond,Millisecond}}()
    t1 = start(t.time)
    t2 = stop(t.time)
    files = Iterators.Stateful(t.video.files)
    for vf in files
        if t1 ≤ vf.duration
            if t2 ≤ vf.duration
                ranges[vf.name] = t1:STEP:t2
                return ranges
            else
                ranges[vf.name] = t1:STEP:vf.duration
                t2 -= vf.duration
                for _vf in files
                    if t2 ≤ _vf.duration
                        ranges[_vf.name] = Millisecond(0):STEP:t2
                        return ranges
                    end
                    ranges[_vf.name] = Millisecond(0):STEP:_vf.duration
                    t2 -= _vf.duration
                end
            end
        end
        t1 -= vf.duration
        t2 -= vf.duration
    end
end

ms2s(t::Millisecond) = t/Millisecond(1000)

function seekread(f, s::Float64)
    seek(f, s)
    full = read(f)
    full[1:2:end, :]
end

fetchimages(_::Missing) = missing

function fetchimages(t::Temporal{V, Instantaneous}) where V
    file, time = timestamps(t)
    f = VideoIO.openvideo(joinpath(Databula.coffeesource, file))
    img = seekread(f, ms2s(time))
    sar = 2VideoIO.aspect_ratio(f)
    Snapshot(img, AbstractPAR(sar))
end

function fetchimages(t::Temporal{WholeVideo, Prolonged})
    file, times = timestamps(t)
    f = VideoIO.openvideo(joinpath(Databula.coffeesource, file))
    imgs = [seekread(f, ms2s(t)) for t in times]
    sar = 2VideoIO.aspect_ratio(f)
    TimeLapse(imgs, AbstractPAR(sar))
end

function fetchimages(t::Temporal{FragmentedVideo, Prolonged})
    ft = timestamps(t)
    imgs = Vector{TimeLapse}(undef, length(ft))
    for (i, (file, times)) in enumerate(ft)
        f = VideoIO.openvideo(joinpath(Databula.coffeesource, file))
        _imgs = [seekread(f, ms2s(t)) for t in times]
        sar = 2VideoIO.aspect_ratio(f)
        imgs[i] = TimeLapse(_imgs, AbstractPAR(sar))
    end
    imgs
end


text:
# Sample postprocessing script for wave-like structure spatial-temporal distribution
# searching.
#
# Usage:
#   julia -t 4 demo_wave_search.jl
# or
#   JULIA_NUM_THREADS=4 julia demo_wave_search.jl
#
# Procedures:
# 1. Extract variables in all cells from all snapshots.
# 2. For each cell and time interval, count time-series local peaks.
# 3. Plot the peak occurrence frequencies across the whole domain as an indicator for waves.
#
# Note:
# 1. When dealing with multiple variables, it is recommended to handle one variable at a
# time through the whole process due to memory considerations.
# 2. It assumes uniform sampling in time.
# 3. Peak-finding is threaded, but plotting is still serial.
#
# Hongyang Zhou, hyzhou@umich.edu

using Glob, Vlasiator, PyPlot, LaTeXStrings

"Extract time series variable"
function extract_var(files, ncells, varname, component=0)
   nfiles = length(files)
   var = zeros(Float32, ncells[1], ncells[2], nfiles)

   # Extract data from each frame
   if component == 0 # scalar
      Threads.@threads for i = eachindex(files)
         meta = load(files[i])
         var[:,:,i] = meta[varname]
      end
   else # vector component
      Threads.@threads for i = eachindex(files)
         meta = load(files[i])
         var[:,:,i] = meta[varname][component,:]
      end
   end

   return var
end

"Count local maxima of vector `y` with moving box length `n`."
function countpeaks(y, n)
   maxs = Int[]
   for i in 2:length(y)-1
      if y[i+1] < y[i] > y[i-1]
         push!(maxs, i)
      end
   end
   nCounts = zeros(Int, length(y)-n+1)
   nCounts[1] = count(i->(1 ≤ i ≤ n), maxs)
   for i in 1:length(y)-n
      nCounts[i+1] = nCounts[i]
      if i ∈ maxs
         nCounts[i+1] -= 1
      end
      if i+n-1 ∈ maxs
         nCounts[i+1] += 1
      end
   end
   nCounts
end

"Check wave-like occurrence frequencies within box length `n` of output interval `dt`."
function checkwaves_sma(var, dt=0.5, n::Int=size(var,3))
   nPeaks = zeros(Int, size(var,3)-n+1, size(var,1), size(var,2))

   Threads.@threads for j in axes(var, 2)
      for i in axes(var, 1)
         var_series = @view var[i,j,:]
         nPeaks[:,i,j] = countpeaks(var_series, n)
      end
   end
   nPeaks ./ (n*dt)
end

function plot_dist(files, varnames, varnames_print, components, Δt, nboxlength)
   @assert nboxlength ≥ 3 && isodd(nboxlength) "Expect odd box length ≥ 3!"
   if (local nfiles = length(files)) < nboxlength
      @warn "Set moving box length to the number of files..."
      nboxlength = nfiles
   end
   local x, y, tStart, tEnd, ncells
   let Re = Vlasiator.Re
      meta = load(files[1])
      tStart = meta.time
      ncells = meta.ncells
      x = LinRange{Float32}(meta.coordmin[1]/Re, meta.coordmax[1]/Re, meta.ncells[1])
      y = LinRange{Float32}(meta.coordmin[2]/Re, meta.coordmax[2]/Re, meta.ncells[2])
      meta = load(files[end])
      tEnd = meta.time
   end

   fig, ax = plt.subplots(figsize=(16,9))
   fontsize = 14
   vmin, vmax = 0.0, 0.5
   levels = matplotlib.ticker.MaxNLocator(nbins=255).tick_values(vmin, vmax)
   norm = matplotlib.colors.BoundaryNorm(levels, ncolors=256, clip=true)
   ticks = range(vmin, vmax, length=11)

   fakedata = zeros(Float32, length(x), length(y))
   im = ax.pcolormesh(y, x, fakedata; norm, shading="nearest")

   ax.set_aspect("equal")
   ax.set_xlabel(L"y [$R_E$]"; fontsize, weight="black")
   ax.set_ylabel(L"x [$R_E$]"; fontsize, weight="black")
   ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
   ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
   ax.grid(true, color="grey", linestyle="-")

   cb = fig.colorbar(im; ax, ticks, pad=0.02)
   cb.ax.set_ylabel("Frequency of local maxima occurrence, [#/s]"; fontsize)

   for i in eachindex(varnames)
      outdir = "../out/$(lowercase(varnames_print[i]))"
      !isdir(outdir) && mkdir(outdir)
      length(glob("spatial*.png", outdir)) == length(files) - nboxlength + 1 && continue

      # Obtain time series data
      var = extract_var(files, ncells, varnames[i], components[i])
      # Count local peak occuring frequencies at each location
      fPeaks = checkwaves_sma(var, Δt, nboxlength)

      for it in axes(fPeaks,1) # Iterate over time
         outname = joinpath(outdir,
            "spatial_perturbation_distribution_$(lpad(it, 3, '0')).png")
         isfile(outname) && continue
         # Update plot
         im.set_array(fPeaks[it,:,:])
         ax.set_title("$(varnames_print[i]) Perturbation Detection, "*
            "t = $(round(tStart+(it-1)*Δt, digits=1)) ~ "*
            "$(round(tStart+(it+nboxlength-1)*Δt, digits=1))s";
            fontsize, fontweight="bold")

         savefig(outname, bbox_inches="tight")
      end
   end
end

##### Main

varnames = ["proton/vg_rho", "vg_pressure", "proton/vg_v", "proton/vg_v", "vg_b_vol",
   "vg_e_vol", "vg_e_vol"]
varnames_print = ["Density", "Thermal Pressure", "Vx", "Vy", "Bz", "Ex", "Ey"]
components = [0, 0, 1, 2, 3, 1, 2] # 0: scalar; 1: x, 2: y, 3: z
Δt = 0.5                           # output time interval [s]
nboxlength = 101                   # moving box average length
dir = "../run_rho2_bz-5_timevarying_startfrom300s" # data directory

files = glob("bulk*.vlsv", dir)

println("Total number of snapshots: $(length(files))")
println("Running with $(Threads.nthreads()) threads...")

@time plot_dist(files, varnames, varnames_print, components, Δt, nboxlength)

println("Virtual satellite extraction done!")


text:
module test_suite_applications

using BasisFunctions, DomainSets, FrameFun, LinearAlgebra
using Test

@testset "FourierExtensionPlatform: DiscreteGramStyle" begin
    F = FourierExtensionPlatform(0.0..0.5)
    opts = (samplingstyle=FrameFun.DiscreteGramStyle(),)
    P = dictionary(F, 4)
    D = azdual_dict(F,4;opts...)
    M = measure(F,4;opts...)
    A = SynthesisOperator(P, M)
    Z = SynthesisOperator(D, M)
    Zt = Z'
    G1 = Zt*A
    G2 = BasisFunctions.default_mixedgram(D, P, M;warnslow=false)
    G3 = BasisFunctions.mixedgram(D, P, M)
    @test Matrix(G1) ≈ Matrix(G2)
    @test Matrix(G2) ≈ Matrix(G3)
end

@testset "FourierExtensionPlatform: GramStyle" begin
    F = FourierExtensionPlatform(0.0..0.5)
    opts = (samplingstyle=FrameFun.GramStyle(),)
    P = dictionary(F, 4)
    D = azdual_dict(F,4;opts...)
    M = measure(F,4;opts...)
    A = SynthesisOperator(P, M)
    Z = SynthesisOperator(D, M)
    @info "Two `Slow computation of Gram matrix entrywise.` warnings follow."
    Zt = Z'
    G1 = Zt*A
    G2 = BasisFunctions.default_mixedgram(D, P, M;warnslow=false)
    G3 = BasisFunctions.mixedgram(D, P, M)
    @test Matrix(G1) ≈ Matrix(G2)
    @test Matrix(G2) ≈ Matrix(G3)

    n = 101
    F = FourierExtensionPlatform(0.0..0.5)
    opts = (samplingstyle=FrameFun.GramStyle(),warnslow=false)
    A = AZ_A(F, n; opts...)
    Z = AZ_Z(F, n; opts...)
    MG = Z'*A
    @test sum(.0001 .< svdvals(MG) .< .9999) == 9
end

@testset "FourierExtensionPlatform: GenericOperatorStyle" begin
    F = FourierExtensionPlatform(0.0..0.5)
    opts = (samplingstyle=FrameFun.GramStyle(),
            problemstyle=FrameFun.GenericOperatorStyle(), atol=1e-4,rtol=1e-4,warnslow=false)
    n = 11
    f = Fun(exp, F, n; opts...)
    x = .1923
    @test abs(f(x) - exp(x)) < 1e-3

    opts = (samplingstyle=FrameFun.DiscreteGramStyle(),
            problemstyle=FrameFun.GenericOperatorStyle(), atol=1e-4,rtol=1e-4,warnslow=false)
    f = Fun(exp, F, n; opts...)
    @test abs(f(x) - exp(x)) < 1e-3
end

@testset "WeightedSumPlatform" begin
    # Simple platform construction test
    n = 12
    domain = 0.0..0.5
    P = FourierExtensionPlatform(domain)
    WP = WeightedSumPlatform(P,x->sqrt(x),x->1)
    f = x->sqrt(x)*(1-x)-exp(x)
    F = Fun(f, WP, (n,n), solverstyle=AZStyle())
    rgrid = randomgrid(domain, 200)
    abserror = sum(abs.(F.(rgrid)-f.(rgrid)))/length(rgrid)
    @test abserror<2e-7
end

end # module


text:
# This file is a part of SimilaritySearch.jl
# License is Apache 2.0: https://www.apache.org/licenses/LICENSE-2.0.txt

using SimilaritySearch
using Test

@testset "bit ops" begin
    u = zero(UInt128)
    v = setbit(u, 0)
    w = setbit(u, 1)
    @test v == 1 && w == 2
    v = setbit(v, 1)
    @test v == 3
    v = resetbit(v, 1)
    @test v == 1
end


text:
"""
    may(mutate!, args...)

Call `mutate!(args...)` if possible; fallback to the out-of-place version if not.
"""
may
Base.@propagate_inbounds may(mutate, args...) =
    if possible(mutate, args...)
        mutate(args...)
    else
        pure(mutate)(args...)
    end

_maybb(mutate) = something(_asbb(mutate), mutate)
_asbb(::Any) = nothing

const MaybeMutableContainer = Union{
    AbstractArray,
    AbstractDict,
    AbstractSet,
}
const ShapeFrozenContainer = Union{
    NoBang.ImmutableContainer,
    NoBang.Empty,
    NoBang.SingletonVector,
    NoBang.SingletonDict,
}
const Mutator = Union{typeof(push!), typeof(setindex!)}

"""
    implements(f!, x) :: Bool

`true` if in-place function `f!` can mutate `x`.

# Examples
```jldoctest
julia> using BangBang: implements

julia> implements(push!, Vector)
true

julia> implements(push!, [])  # works with instances, too
true

julia> implements(push!, Tuple)
false

julia> using StaticArrays

julia> implements(push!, SVector)
false

julia> implements(setindex!, SVector)
false

julia> implements(push!, MVector)
false

julia> implements(setindex!, MVector)
true
```
"""
implements
implements(f!, x) = implements(f!, typeof(x))
implements(::Any, ::Type) = false

implements(::Mutator, ::Type{<:ShapeFrozenContainer}) = false
implements(::Mutator, ::Type{<:MaybeMutableContainer}) = true
implements(::Mutator, ::Type{<:AbstractString}) = false

implements(::typeof(resize!), ::Type{<:AbstractVector}) = true
implements(
    ::typeof(resize!),
    ::Type{<:Union{SubArray{<:Any,1},Base.ReshapedArray{<:Any,1}}},
) = false

Base.@pure ismutablestruct(T::DataType) = T.mutable
implements(::typeof(setproperty!), T::DataType) = ismutablestruct(T)
implements(::typeof(setproperty!), ::Type{<:NamedTuple}) = false

# trymutate(::typeof(push!)) = push!!
# trymutate(::typeof(append!)) = append!!

struct Undefined end
implements(::Mutator, ::Undefined) = false

"""
    possible(f!, args...) :: Bool

Check if `f!(args...)` is possible.

# Examples
```jldoctest
julia> using BangBang: possible

julia> possible(push!, Int[], 1)
true

julia> possible(push!, Int[], 0.5)
false
```
"""
possible


text:
# Interface requirements:
# * columns(tbl)::Vector{Any}
# * Base.getindex(tbl, field)
# * Base.setindex!(tbl, col, field)

# TODO: Include discussion of null storage patterns
"""
    columns(tbl::AbstractTable)::Vector{Any}

Produce a list of columns of `tbl` in canonical order.

This is a requisite method of the AbstractTable column-indexable interface. The
contents of `columns(tbl)[i]` must be iterable. The orderings of columns(tbl)
and fields(tbl) must be consistent -- that is, fields(tbl)[i] must be the field
name of columns(tbl)[i]. The mapping in `index(tbl)` must respect the ordering
of columns and fields in `columns(tbl)` and `fields(tbl)`. This ordering is
assumed to be the canonical column ordering for `tbl`.
"""
function columns end

function columns(tbl::AbstractTable)
    msg = @sprintf("Objects of type %s are not column-indexable", typeof(tbl))
    throw(ArgumentError(msg))
end

# Base.copy
# Should this be a part of the column-indexable interface or the query
# sub-interface?