Skip to content

Commit 50b02c2

Browse files
committed
multiheader wr_header_file formatting fixes
1 parent a629039 commit 50b02c2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

wfdb/io/_header.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,25 @@ def wr_header_file(self, write_fields, write_dir):
756756
for field in RECORD_SPECS.index:
757757
# If the field is being used, add it with its delimiter
758758
if field in write_fields:
759-
record_line += RECORD_SPECS.loc[field, "delimiter"] + str(
760-
getattr(self, field)
759+
string_field = str(getattr(self, field))
760+
761+
# Certain fields need extra processing
762+
if field == "fs" and isinstance(self.fs, float):
763+
if round(self.fs, 8) == float(int(self.fs)):
764+
string_field = str(int(self.fs))
765+
elif field == "base_time" and "." in string_field:
766+
string_field = string_field.rstrip("0")
767+
elif field == "base_date":
768+
string_field = "/".join(
769+
(string_field[8:], string_field[5:7], string_field[:4])
770+
)
771+
772+
record_line += (
773+
RECORD_SPECS.loc[field, "delimiter"] + string_field
761774
)
775+
# The 'base_counter' field needs to be closed with ')'
776+
if field == "base_counter":
777+
record_line += ")"
762778

763779
header_lines = [record_line]
764780

0 commit comments

Comments
 (0)