Skip to content

Commit 87be67d

Browse files
author
Bright-yaw
committed
Adding files and editing readme aand project.toml file
1 parent 00ea4e1 commit 87be67d

11 files changed

+797
-5
lines changed

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ReadDBC"
22
uuid = "79d50320-df92-4ae6-9b90-d461b5bc1756"
33
authors = ["Bright-yaw <[email protected]> and contributors"]
4-
version = "1.0.0-DEV"
4+
version = "1.0.0"
55

66
[deps]
77
DBFTables = "75c7ada1-017a-5fb6-b8c7-2125ff2d6c93"
@@ -12,6 +12,8 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1212

1313
[compat]
1414
julia = "1.10.4"
15+
DBFTables = "1.2.6"
16+
DataFrames = "1.6.1"
1517

1618
[extras]
1719
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,68 @@
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://lego-yaw.github.io/ReadDBC.jl/dev/)
55
[![Build Status](https://github.com/lego-yaw/ReadDBC.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/lego-yaw/ReadDBC.jl/actions/workflows/CI.yml?query=branch%3Amain)
66
[![Coverage](https://codecov.io/gh/lego-yaw/ReadDBC.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/lego-yaw/ReadDBC.jl)
7+
8+
9+
10+
### ReadDBC.jl
11+
+ A simple package for converting *.dbc* (compressed DBC) files from Datasus into *.dbf* (DBF) and *data frames* tables.
12+
13+
+ DATASUS plays a critical role in ensuring the efficient operation of Brazil's public health system. DATASUS is the name of the Departement of informatics of Brazil's health system (Sistema Unico de Saúde-SUS). They are responsible for maintaining and publishing Brazilian public health data. Aside this, the Brazilian National Agency for supplementary Health data (ANS), also use the same file format for storing public health data.
14+
15+
+ *Please note* that, this package only handles *.dbc* format used by DATASUS and is not in any way related to handling Microsoft Foxpro or CANdb DBC files.
16+
17+
## Installation
18+
+ Package can be installed like any other julia package
19+
20+
```Julia-repl
21+
>>> ]
22+
>>> add ReadDBC
23+
```
24+
or
25+
26+
```
27+
>>> using Pkg
28+
>>> Pkg.add("ReadDBC")
29+
```
30+
# Usage
31+
+ ReadDBC is simple to use
32+
33+
```
34+
# converting dbc to dbf format
35+
>>> using ReadDBC
36+
>>> dbctodbc("path/to/file.dbc, path/to/file.dbf) # input file is .dbc file and output file is .dbf
37+
38+
# converting dbc into dataframe Table
39+
>>> using readdbc
40+
>>> df = dbcTable("path/to/file.dbc)" # input file is .dbc file and output file is in table format
41+
>>> head(df)
42+
43+
# Example
44+
>>> using Download, using ReadDBC
45+
>>> download("ftp://ftp.datasus.gov.br/dissemin/publicos/SIASUS/200801_/Dados/ABOAC1909.dbc", "ABOAC1909.dbc") # this link downlaods the ABOAC1909.dbc file from Datasus database.
46+
47+
# run fucntion
48+
>>> df = dbcTable("ABOAC1909.dbc") ## read into dataframe Table
49+
>>> display(df)
50+
51+
or
52+
53+
>>> using ReadDBC
54+
>>> dbctodbc("ABOAC1909.dbc", "ABOAC1909.dbf") # conversion into DBF format
55+
56+
```
57+
58+
# Format description references
59+
60+
* https://en.wikipedia.org/wiki/.dbf
61+
* https://www.clicketyclick.dk/databases/xbase/format/dbf.html
62+
* http://www.independent-software.com/dbase-dbf-dbt-file-format.html
63+
64+
# Contact information
65+
+ if you have any questions or suggestions, feel free to contact at [email protected]
66+
67+
# Citation
68+
+ This project is based on the work of https://github.com/madler/zlib/tree/master/contrib/blast and https:// github.com/eaglebh/blast-dbf and the R version developed by danicat(https://github.com/danicat/read.dbc).
69+
Also this package wouldn't have been possible without DBFTable (https://github.com/JuliaData/DBFTables.jl)
70+
71+
+ Neither this project, nor its author, is related in any way to the Brazilian government.

src/ABOAC1909.dbc

3 KB
Binary file not shown.

src/ReadDBC.jl

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
module ReadDBC
22

3-
# Write your package code here.
3+
# Export functions
4+
export dbcTable, dbctodbf
45

6+
# Importing packages
7+
using DBFTables
8+
using DataFrames
9+
using Logging
10+
using Libdl
11+
12+
13+
# Defining function dbctodbf
14+
function dbctodbf(input_file::String, output_file::String)
15+
# Load the shared library
16+
lib = dlopen("src/libdbc2dbf.dll")
17+
18+
# Ensure the library is properly loaded
19+
if lib === C_NULL
20+
error("Failed to load the library.")
21+
end
22+
23+
# Create a pointer to the C function in the library
24+
func = dlsym(lib, :dbc2dbf)
25+
26+
# Ensure the function pointer is valid
27+
if func === C_NULL
28+
dlclose(lib)
29+
error("Failed to find the function dbc2dbf in the library.")
30+
end
31+
32+
# Call the C function directly with string parameters
33+
result = ccall(func, Cvoid, (Cstring, Cstring), input_file, output_file)
34+
35+
# Close the library after the function call
36+
dlclose(lib)
37+
38+
return result
39+
end
40+
41+
# Defining function readdbc
42+
function dbcTable(input_file::String)
43+
output_file = replace(input_file, ".dbc" => ".dbf")
44+
try
45+
# Convert the DBC file to a DBF file
46+
dbctodbf(input_file, output_file)
47+
48+
# Read the DBF file into a DataFrame
49+
df = DBFTables.Table(output_file)
50+
return DataFrame(df)
51+
52+
catch e
53+
@error "Failed to convert or read DBC file: $input_file"
54+
@error "$e"
55+
return nothing
56+
end
557
end
58+
59+
end # module readdbc

0 commit comments

Comments
 (0)