diff --git a/bin/sps.py b/bin/legacy_fwr.py similarity index 66% rename from bin/sps.py rename to bin/legacy_fwr.py index e0c33e3..c7346ee 100644 --- a/bin/sps.py +++ b/bin/legacy_fwr.py @@ -1,13 +1,30 @@ #!/usr/bin/python3 """ -SPS importing functions. - -And by SPS, we mean more or less any line-delimited, fixed-width record format. +Legacy fixed width record importing functions. """ import builtins -from parse_fwr import parse_fwr + +def parse_fwr (string, widths, start=0): + """Parse a fixed-width record. + + string: the string to parse. + widths: a list of record widths. A negative width denotes a field to be skipped. + start: optional start index. + + Returns a list of strings. + """ + results = [] + current_index = start + for width in widths: + if width > 0: + results.append(string[current_index : current_index + width]) + current_index += width + else: + current_index -= width + + return results def int (v): return builtins.int(float(v)) diff --git a/bin/parse_fwr.py b/bin/parse_fwr.py deleted file mode 100644 index 77d3b4e..0000000 --- a/bin/parse_fwr.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python3 - -def parse_fwr (string, widths, start=0): - """Parse a fixed-width record. - - string: the string to parse. - widths: a list of record widths. A negative width denotes a field to be skipped. - start: optional start index. - - Returns a list of strings. - """ - results = [] - current_index = start - for width in widths: - if width > 0: - results.append(string[current_index : current_index + width]) - current_index += width - else: - current_index -= width - - return results diff --git a/bin/preplots.py b/bin/preplots.py index 58be431..6b8bcbd 100644 --- a/bin/preplots.py +++ b/bin/preplots.py @@ -1,4 +1,4 @@ -import sps +import legacy_fwr """ Preplot importing functions. @@ -7,7 +7,7 @@ Preplot importing functions. def from_file (file, realpath = None): filepath = realpath or file["path"] if not "type" in file or file["type"] == "sps": - records = sps.from_file(filepath, file["format"] if "format" in file else None ) + records = legacy_fwr.from_file(filepath, file["format"] if "format" in file else None ) else: return "Not an SPS file"