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