Commit 95f04889 authored by Alberto Ramos's avatar Alberto Ramos

Corrected length of haders

parent 56d3dd70
...@@ -23,4 +23,15 @@ export BDIOstream, BDIO_open, BDIO_start_record!, BDIO_write_hash!, ...@@ -23,4 +23,15 @@ export BDIOstream, BDIO_open, BDIO_start_record!, BDIO_write_hash!,
BDIO_write!, BDIO_seek!, BDIO_get_len, BDIO_get_fmt, BDIO_write!, BDIO_seek!, BDIO_get_len, BDIO_get_fmt,
BDIO_get_uinfo, BDIO_read, BDIO_set_user, BDIO_set_host, BDIO_close! BDIO_get_uinfo, BDIO_read, BDIO_set_user, BDIO_set_host, BDIO_close!
function Base.show(io::IO, fb::BDIOstream)
if (fb.imode == BDIO_R_MODE)
print("BDIOstream in read mode")
else
print("BDIOstream in write mode")
end
end
end # module end # module
""" """
Set user name globally for writing BDIO files.
BDIO_set_user(us::String) BDIO_set_user(us::String)
Set user name globally for writing BDIO files.
### Arguments ### Arguments
- us: Set `us` as the user name when writing BDIO files. - us: Set `us` as the user name when writing BDIO files.
...@@ -12,15 +12,15 @@ julia> BDIO_set_user("alberto") ...@@ -12,15 +12,15 @@ julia> BDIO_set_user("alberto")
``` ```
""" """
function BDIO_set_user(us::String) function BDIO_set_user(us::String)
global user = SubString(us*user, 1, 255) global user = us
return true return true
end end
""" """
Set host machine globally for writing BDIO files.
BDIO_set_host(us::String) BDIO_set_host(us::String)
Set host machine globally for writing BDIO files.
### Arguments ### Arguments
- us: Set `us` as the host when writing BDIO files. - us: Set `us` as the host when writing BDIO files.
...@@ -30,26 +30,26 @@ julia> BDIO_set_host("HLRN") ...@@ -30,26 +30,26 @@ julia> BDIO_set_host("HLRN")
``` ```
""" """
function BDIO_set_host(us::String) function BDIO_set_host(us::String)
global host = SubString(us*host, 1, 255) global host = us
return true return true
end end
""" """
Opens a BDIO file and returns the BDIO handle.
BDIO_open(fname::String, mode::String, protocol_info::String="") BDIO_open(fname::String, mode::String, protocol_info::String="")
Opens a BDIO file and returns the BDIO handle.
The file can be opened in several modes: The file can be opened in several modes:
- Write mode ("w"): The file is created and a header written. If the file exists an error is printed. - Write mode ("w"): The file is created and a header written. If the file exists an error is printed.
- Write mode ("d"): The file is created and a header written. If the file exists it is overwritten. - Delete mode ("d"): The file is created and a header written. If the file exists it is overwritten.
- Write mode ("a"): The file is created if it does not exist, or opened for appending if the file exists. - Append mode ("a"): The file is created if it does not exist, or opened for appending if the file exists.
- Write mode ("r"): The file is opened for reading. - Read mode ("r"): The file is opened for reading.
## Arguments ## Arguments
- `fname`: File name - `fname`: File name
- `mode`: The mode in which the file is opened. See above. - `mode`: The mode in which the file is opened. See above.
- `protocol_info`: Only used when the file is created (i.e. "w" mode) and labels the file. - `protocol_info`: Only used when the file is created (i.e. "w" or "d" modes) and labels the file.
## Examples ## Examples
```julia-repl ```julia-repl
...@@ -60,10 +60,9 @@ julia> fb = BDIO_open("new_file.bdio", "w", "Test file") ...@@ -60,10 +60,9 @@ julia> fb = BDIO_open("new_file.bdio", "w", "Test file")
A BDIOstream type. A BDIOstream type.
""" """
function BDIO_open(fname::String, mode::String, protocol_info::String="") function BDIO_open(fname::String, mode::String, protocol_info::String="\0")
fb = BDIOstream(fname,mode) fb = BDIOstream(fname,mode, protocol_info)
fb.info = protocol_info
fb.user = user fb.user = user
fb.host = host fb.host = host
...@@ -78,8 +77,9 @@ function BDIO_open(fname::String, mode::String, protocol_info::String="") ...@@ -78,8 +77,9 @@ function BDIO_open(fname::String, mode::String, protocol_info::String="")
BDIO_parse!(fb) BDIO_parse!(fb)
fb.ipt = length(fb.records) fb.ipt = length(fb.records)
elseif (mode == "d") elseif (mode == "d")
BDIO_parse!(fb) fb.created = floor(Int32, time())
fb.ipt = length(fb.records) fb.modified = floor(Int32, time())
BDIO_write_header!(fb)
else else
error("Incorrect mode") error("Incorrect mode")
end end
...@@ -88,10 +88,10 @@ function BDIO_open(fname::String, mode::String, protocol_info::String="") ...@@ -88,10 +88,10 @@ function BDIO_open(fname::String, mode::String, protocol_info::String="")
end end
""" """
Closes the file associated with fb and clears the record database
BDIO_close!(fb::BDIOstream) BDIO_close!(fb::BDIOstream)
Closes the file associated with fb and clears the record database
## Arguments ## Arguments
- `fb`: A BDIOstream type. It must be associated with a file. - `fb`: A BDIOstream type. It must be associated with a file.
...@@ -106,10 +106,10 @@ function BDIO_close!(fb::BDIOstream) ...@@ -106,10 +106,10 @@ function BDIO_close!(fb::BDIOstream)
end end
""" """
Start a new BDIO record at the end of the file.
BDIO_start_record!(fb::BDIOstream, ifmt, iuinfo, long::Bool = false) BDIO_start_record!(fb::BDIOstream, ifmt, iuinfo, long::Bool = false)
Start a new BDIO record at the end of the file.
## Arguments ## Arguments
- `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode - `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode
- `ifmt`: Format. Currently the supported formats are - `ifmt`: Format. Currently the supported formats are
...@@ -170,10 +170,10 @@ function BDIO_start_record!(fb::BDIOstream, ifmt, iuinfo, long::Bool = false) ...@@ -170,10 +170,10 @@ function BDIO_start_record!(fb::BDIOstream, ifmt, iuinfo, long::Bool = false)
end end
""" """
Write `data` to BDIO file to the end of the last record.
BDIO_write!(fb::BDIOstream,data,hash::Bool=true) BDIO_write!(fb::BDIOstream,data,hash::Bool=true)
Write `data` to BDIO file to the end of the last record.
## Arguments ## Arguments
- `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode. - `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode.
- `data`: Data to write to file. - `data`: Data to write to file.
...@@ -210,10 +210,10 @@ function BDIO_write!(fb::BDIOstream,data,hash::Bool=true) ...@@ -210,10 +210,10 @@ function BDIO_write!(fb::BDIOstream,data,hash::Bool=true)
end end
""" """
Write the `MD5` checksum of the actual record as a new record.
BDIO_write_hash!(fb::BDIOstream) BDIO_write_hash!(fb::BDIOstream)
Write the `MD5` checksum of the actual record as a new record.
## Arguments ## Arguments
- `fb`: A `BDIOstream` type. It must be associated with a file in either `w` or `a` mode. - `fb`: A `BDIOstream` type. It must be associated with a file in either `w` or `a` mode.
...@@ -241,10 +241,10 @@ function BDIO_write_hash!(fb) ...@@ -241,10 +241,10 @@ function BDIO_write_hash!(fb)
end end
""" """
Move the read position backward/forward `icnt` records
BDIO_seek!(fb::BDIOstream, icnt::Int = 1) BDIO_seek!(fb::BDIOstream, icnt::Int = 1)
Move the read position backward/forward `icnt` records
## Arguments ## Arguments
- `fb`: A BDIOstream type. It must be associated with a file. - `fb`: A BDIOstream type. It must be associated with a file.
- `icnt` (optional): number of records to move forward (if `icnt>0`) or backwards (`icnt<0`). If `icnt=0` move to the first record. The default value is `+1`. - `icnt` (optional): number of records to move forward (if `icnt>0`) or backwards (`icnt<0`). If `icnt=0` move to the first record. The default value is `+1`.
...@@ -254,7 +254,7 @@ Move the read position backward/forward `icnt` records ...@@ -254,7 +254,7 @@ Move the read position backward/forward `icnt` records
julia> # count number of records in a file. julia> # count number of records in a file.
julia> fb = BDIO_open("randoms.bdio", "r") julia> fb = BDIO_open("randoms.bdio", "r")
julia> count = 0 julia> count = 0
julia> while BDIO_seek(fb) julia> while BDIO_seek!(fb)
julia> count += 1 julia> count += 1
julia> end julia> end
``` ```
...@@ -277,10 +277,10 @@ function BDIO_seek!(fb::BDIOstream, icnt::Int = 1) ...@@ -277,10 +277,10 @@ function BDIO_seek!(fb::BDIOstream, icnt::Int = 1)
end end
""" """
Read `data` from BDIO file.
BDIO_read(fb::BDIOstream, vdata::Vector, n::Int64 = 0) BDIO_read(fb::BDIOstream, vdata::Vector, n::Int64 = 0)
Read `data` from BDIO file.
## Arguments ## Arguments
- `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode. - `fb`: A BDIOstream type. It must be associated with a file in either `w` or `a` mode.
- `data[:]`: A `Vector` of data to read. - `data[:]`: A `Vector` of data to read.
...@@ -317,10 +317,10 @@ function BDIO_read(fb::BDIOstream, vdata::Vector, n::Int64 = 0) ...@@ -317,10 +317,10 @@ function BDIO_read(fb::BDIOstream, vdata::Vector, n::Int64 = 0)
end end
""" """
Returns the len (in bytes) of the current record
BDIO_get_len(fb::BDIOstream) BDIO_get_len(fb::BDIOstream)
Returns the len (in bytes) of the current record
## Arguments ## Arguments
- `fb`: A `BDIOstream` type. It must be associated with a file. - `fb`: A `BDIOstream` type. It must be associated with a file.
...@@ -328,7 +328,7 @@ Returns the len (in bytes) of the current record ...@@ -328,7 +328,7 @@ Returns the len (in bytes) of the current record
```julia-repl ```julia-repl
julia> # Write length of all records julia> # Write length of all records
julia> fb = BDIO_open("randoms.bdio", "r") julia> fb = BDIO_open("randoms.bdio", "r")
julia> while BDIO_seek(fb) julia> while BDIO_seek!(fb)
julia> count += 1 julia> count += 1
julia> println("Record: ", count, " length: ", BDIO_get_len(fb), " bytes") julia> println("Record: ", count, " length: ", BDIO_get_len(fb), " bytes")
julia> end julia> end
...@@ -337,10 +337,10 @@ julia> end ...@@ -337,10 +337,10 @@ julia> end
BDIO_get_len(fb::BDIOstream) = fb.records[fb.ipt].rlen BDIO_get_len(fb::BDIOstream) = fb.records[fb.ipt].rlen
""" """
Returns the format of the current record
BDIO_get_fmt(fb::BDIOstream) BDIO_get_fmt(fb::BDIOstream)
Returns the format of the current record
## Arguments ## Arguments
- `fb`: A `BDIOstream` type. It must be associated with a file. - `fb`: A `BDIOstream` type. It must be associated with a file.
...@@ -348,7 +348,7 @@ Returns the format of the current record ...@@ -348,7 +348,7 @@ Returns the format of the current record
```julia-repl ```julia-repl
julia> # Print all BDIO_BIN_GENERIC records julia> # Print all BDIO_BIN_GENERIC records
julia> fb = BDIO_open("randoms.bdio", "r") julia> fb = BDIO_open("randoms.bdio", "r")
julia> while BDIO_seek(fb) julia> while BDIO_seek!(fb)
julia> count += 1 julia> count += 1
julia> if (BDIO_get_fmt(fb) == BDIO_BIN_GENERIC) julia> if (BDIO_get_fmt(fb) == BDIO_BIN_GENERIC)
julia> println("Record: ", count, " is BIN_GENERIC") julia> println("Record: ", count, " is BIN_GENERIC")
...@@ -359,10 +359,10 @@ julia> end ...@@ -359,10 +359,10 @@ julia> end
BDIO_get_fmt(fb::BDIOstream) = fb.records[fb.ipt].rfmt BDIO_get_fmt(fb::BDIOstream) = fb.records[fb.ipt].rfmt
""" """
Returns the user provided info of each record
BDIO_get_uinfo(fb::BDIOstream) BDIO_get_uinfo(fb::BDIOstream)
Returns the user provided info of each record
## Arguments ## Arguments
- `fb`: A `BDIOstream type`. It must be associated with a file. - `fb`: A `BDIOstream type`. It must be associated with a file.
...@@ -370,7 +370,7 @@ Returns the user provided info of each record ...@@ -370,7 +370,7 @@ Returns the user provided info of each record
```julia-repl ```julia-repl
julia> # Write length of all records julia> # Write length of all records
julia> fb = BDIO_open("randoms.bdio", "r") julia> fb = BDIO_open("randoms.bdio", "r")
julia> while BDIO_seek(fb) julia> while BDIO_seek!(fb)
julia> count += 1 julia> count += 1
julia> println("Record: ", count, " user info: ", BDIO_get_uinfo(fb)) julia> println("Record: ", count, " user info: ", BDIO_get_uinfo(fb))
julia> end julia> end
...@@ -485,7 +485,7 @@ function BDIO_write_header!(fb::BDIOstream) ...@@ -485,7 +485,7 @@ function BDIO_write_header!(fb::BDIOstream)
if (fb.imode == BDIO_R_MODE) if (fb.imode == BDIO_R_MODE)
error("Attemp to write in READ mode") error("Attemp to write in READ mode")
end end
ihdr::Int32 = BDIO_MAGIC ihdr::Int32 = BDIO_MAGIC
write(fb.io, ihdr) write(fb.io, ihdr)
...@@ -514,7 +514,7 @@ function BDIO_write_header!(fb::BDIOstream) ...@@ -514,7 +514,7 @@ function BDIO_write_header!(fb::BDIOstream)
write(fb.io, fb.info*"\0") write(fb.io, fb.info*"\0")
ind::Int64 = position(fb.io) ind::Int64 = position(fb.io)
ill = Int16(ind-ist) ill = Int16(ind-ist)
reset(fb.io) reset(fb.io)
write(fb.io, ill) write(fb.io, ill)
...@@ -544,7 +544,7 @@ function BDIOstream(fname::String, mode::String, protocol_info::String="\0") ...@@ -544,7 +544,7 @@ function BDIOstream(fname::String, mode::String, protocol_info::String="\0")
io = open(fname, "a+") io = open(fname, "a+")
md = BDIO_A_MODE md = BDIO_A_MODE
elseif (mode == "d") elseif (mode == "d")
rm(fnme, force=true) rm(fname, force=true)
io = open(fname, "w+") io = open(fname, "w+")
md = BDIO_D_MODE md = BDIO_D_MODE
else else
......
...@@ -31,6 +31,6 @@ const BDIO_BIN_F64 = 243 ...@@ -31,6 +31,6 @@ const BDIO_BIN_F64 = 243
const BDIO_HASH_MAGIC_S = 1515784845 const BDIO_HASH_MAGIC_S = 1515784845
user = " " user = " "
host = " " host = " "
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment