README.md 2.14 KB
Newer Older
Alberto Ramos's avatar
Alberto Ramos committed
1 2 3 4 5 6

# BDIO.jl

BDIO.jl is a package to write/read [BDIO](http://bdio.org) (**B**inary
**D**ata **I**nput/**O**utput) files. 

7
The full documentation of the package is available via the usual
Alberto Ramos's avatar
Alberto Ramos committed
8 9 10
[Julia `REPL` help
mode](https://docs.julialang.org/en/v1/stdlib/REPL/#Help-mode-1) and
online in [HTML format](https://ific.uv.es/~alramos/docs/BDIO/).
11

12 13
## Install

14
The package in not in the general registry. Still one can use the package manager
15 16 17 18 19
```julia
julia> import Pkg
(v1.1) pkg> add https://gitlab.ift.uam-csic.es/alberto/bdio.jl
```

20 21 22 23 24 25
## Configuration

The package does not require much configuration, but it is recommended
that the variables `user` and `host` contain reasonable values. Since
`BDIO` is a light package, probably the easiest is to add to your
`~/.julia/config/startup.jl` something like
Alberto Ramos's avatar
Alberto Ramos committed
26
```julia
27 28 29 30 31
using BDIO
BDIO_set_user("username")
BDIO_set_host("laptop")
```

32 33
## Example

Alberto Ramos's avatar
Alberto Ramos committed
34 35 36
The test1.jl file in the `tests` directory gives a simple example on
the usage of the package
```julia
37 38
julia> using BDIO

Alberto Ramos's avatar
Alberto Ramos committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
julia> BDIO_set_user("alberto")
julia> BDIO_set_host("laptop")
julia> fb  = BDIO_open("foo.bdio", "w", "Test file")

julia> BDIO_start_record!(fb, BDIO_BIN_INT64LE, 1, true)
julia> BDIO_write!(fb, collect(1:1000))
julia> BDIO_write_hash!(fb)

julia> BDIO_start_record!(fb, BDIO_BIN_F64LE, 2, true)
julia> vec1  = randn(1000)

julia> vec2  = similar(vec1)
julia> vec2 .= .- vec1

julia> BDIO_write!(fb, vec1)
julia> BDIO_write!(fb, vec2)
julia> BDIO_write_hash!(fb)

julia> BDIO_close!(fb)

julia> fb2 = BDIO_open("foo.bdio", "r")

julia> global isum = 0
julia> global fsum = 0.0

julia> while BDIO_seek!(fb2)
julia>     if BDIO_get_uinfo(fb2) == 1
julia>         idt = similar(Array{Int64,   1}, 100)
julia>         for i = 1:10
julia>             BDIO_read(fb2, idt)
julia>             global isum += sum(idt)
julia>         end
julia>     elseif BDIO_get_uinfo(fb2) == 2
julia>         fdt = similar(Array{Float64, 1}, 100)
julia>         for i = 1:20
julia>             BDIO_read(fb2, fdt)
julia>             global fsum += sum(fdt)
julia>         end
julia>     end
julia> end

julia> rm("foo.bdio", force=true)
julia> ( (abs(fsum) < 1.0E-10) && ((2*isum - 1000*(1001)) == 0) )
```