Repository navigation
Read and write records in .wfdb archives - #35
Closed
tompollard wants to merge 3 commits into
Closed
tompollard wants to merge 3 commits into
tompollard wants to merge 3 commits into
Conversation
A .wfdb archive is a ZIP file that holds the files of a single record:
its header file, the signal files listed in the header, and optionally
annotation and other files. This is the same format that the WFDB
Python package reads and writes.
A record in an archive is opened by giving its name with the '.wfdb'
extension (for example, 'rdsamp -r 100.wfdb'). wfdb_open then builds
a file name such as '100.wfdb.hea', which wfdb_fopen recognizes as the
file '100.hea' within the archive '100.wfdb'. The archive is found by
searching the WFDB path, like any other file.
Reading:
- The header is the file named after the archive ('100.hea' in
'100.wfdb'), or the only header in the archive. Headers larger than
1 MB are rejected.
- Signal files are read from the same archive as the header, by the
names given in the header. A missing signal file is an error.
- Files must be stored without compression, so that a range of samples
can be read without reading the whole signal file, and so that no
compression library is needed. ZIP64 archives are supported.
Writing:
- Output files named 'RECORD.wfdb.EXT' (as produced by applications
such as xform and wrsamp for an output record named 'RECORD.wfdb')
are stored in the archive as 'RECORD.EXT'. setheader requires the
signal files of a record in an archive to be in the same archive, and
writes their names within the archive to the header.
- Files are kept in temporary files until wfdbquit is called (or the
program exits). The new archive is then written to a temporary file
next to the old one and moved into place, so an existing archive is
either fully replaced or left unchanged. Other files already in the
archive are kept, so that (for example) 'sqrs -r 100.wfdb' adds
100.qrs to the archive. A replaced archive keeps its permissions.
Archives on remote servers and multi-segment records in archives are
not supported, and give an error.
lcheck now copies record 100y into the archive 100x.wfdb (including its info strings, written with setinfo and putinfo), then copies 100x.wfdb to 100z. 100z.dat and 100z.hea must still match the expected files. appcheck copies record 100s and its annotations into an archive with xform, adds annotations made by sqrs to the archive, and checks the signals and both annotation files read from the archive.
Owner
|
Is this AI-generated?
|
Author
|
Yes this is an AI port of the python implementation |
Owner
|
Thanks, but I am not accepting any AI-generated contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for reading and writing records stored in
.wfdbarchives: a ZIP file that holds the header, signal and annotation files of a single record. It is the C counterpart of MIT-LCP/wfdb-python#541 (see also wfdb/wfdb-spec#21), and uses the same format, so archives written by either package can be read by the other.Usage
Records in archives are opened by giving the record name with the
.wfdbextension. All applications built with the library can then read and write archives:The archive is found by searching the WFDB path, like any other file.
Implementation
The archive code is in
lib/wfdbio.c, behind the existingWFDB_FILEfunctions, with no new dependencies. There are three commits:wfdb_openbuilds file names such as100.wfdb.hea.wfdb_fopenrecognizes these as the file100.heawithin the archive100.wfdb.100.heain100.wfdb), or the only header in the archive. Signal files are read from the same archive, by the names in the header, and a missing signal file is an error. Headers larger than 1 MB are rejected, as in the Python package. ZIP64 archives are supported.RECORD.wfdb.EXTare stored asRECORD.EXT. This is the name applications such asxformandwrsampalready give signal files of an output record namedRECORD.wfdb.setheaderrequires the signal files of a record in an archive to be in the same archive, and writes their names within the archive to the header.wfdbquit()is called (or the program exits). The new archive is then written to a temporary file next to the old one and moved into place, so an existing archive is either fully replaced or left unchanged. A replaced archive keeps its permissions.sqrs -r 100.wfdbadd100.qrsto an archive, and letssetinfo/putinfoadd info strings. This differs fromwrsamp(wfdb_archive=...)in Python, which always writes a new archive.lchecknow copies record100yinto the archive100x.wfdb(including info strings), then copies100x.wfdbto100z.100z.datand100z.heamust still match the expected files.appcheckcopies100sand its annotations into an archive withxform, adds annotations made bysqrs, and checks the signals and both annotation files read back from the archive.Not supported yet
These give a clear error:
zipwithout-0). Reading these would need zlib, which could be added as an optional dependency later, like libFLAC.Testing
make checkpasses with and without NETFILES (libcheck 8/8 and appcheck 57/57 with NETFILES, usingWFDB_NO_NET_CHECK).xform, and the C library reads archives written by Python'swrsampandcreate_archive. This covered several signal files, formats 16/212/80, annotations and sample ranges.