Rename "SPS" preplots import to "legacy fixed width"

This commit is contained in:
D. Berge
2023-11-15 21:36:12 +01:00
parent 6fa0f8e659
commit 8ec918bc7c
3 changed files with 23 additions and 27 deletions

View File

@@ -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))

View File

@@ -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

View File

@@ -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"