FWFTables.jl

Documentation for FWFTables.jl

FWFTables.VarspecType
Varspec

Struct to hold all relevant information for one variable. Fields are

  • name: name of the variable
  • datatype: Julia type of variable
  • startpos: starting position of variabele in record
  • length: length in bytes of variable
  • decimals: for float-type the number of decimals

Predefined usable types are FixedSizeString{N} for string variables, Union{Missing,Int64} and IntXX for integer variables, FloatXX for real numbers and Nothing for variables that must be skipped. If you want to use another type for input, then you must define fw_convert to convert the byte-string to the given type.

To write to a fixed width file, generator functions for the used types must be available. Predefined function are defined for FixedSizeString{N}, Union{Missing,Int64}, Float64 and Nothing. For other functions the function makewrite must be defined.

source
FWFTables.FileMethod
File(filename::String, specs::Vector{Varspec})

Read a fixed width file.

source
FWFTables.FileMethod
File(filename::String, blafilename::String)

Read a fixed width file, using the specs from blafile. Returns an object implementing the Tables interface.

If the file starts with the 3 byte BOM for utf-8, it will be skipped. The line-ending is determined based on the first line. If the file uses a mixed line ending, the data will not be read correctly.

Examples

julia> using DataFrames, FWFTables
julia> df = DataFrame(FWFTables.File("data.asc", "spec.bla"))
source
FWFTables.readblaMethod
readbla(filename)

Read a Blaise specification file for a fixed width ascii file. Returns a vector of 'Varspec' objects.

A simple example of a Blaise specification file looks like

datamodel testbla
 Fields
    var1        : integer[9]
    var2        : string[8]
    dummy[2]
    var3        : Real[8, 2]
    vars        : Array[2010..2050] of STRING[4]
endmodel
source
FWFTables.writeMethod
write(io::IO, specs::Vector{Varspec}, table)

Write the table to a fixed width ascii file

source
FWFTables.writeMethod
write(filename::String, specs::Vector{Varspec}, table)

Write the table to a fixed width ascii file

source
FWFTables.writeMethod
write(filename::String, blafilename::String, table)

Write the table to a fixed width ascii file. The blafile contains the specifications of the file in the Blaise format.

Using the datatype, length and if relevant the decimals from the specification a conversion function is generated to write a single value using the required width. For String, Integer, Real and Dummy there are conversion-functions generated by makewrite. For other datatypes, the required generator must be created. The signature is (T::Type, spec::Varspec), and the return value must be a function that accepts (io::IO, value::T) and writes the ascii-representation of the value to io.

source