mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:37:08 +00:00
Rename "SPS" preplots import to "legacy fixed width"
This commit is contained in:
@@ -1,13 +1,30 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SPS importing functions.
|
Legacy fixed width record importing functions.
|
||||||
|
|
||||||
And by SPS, we mean more or less any line-delimited, fixed-width record format.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import builtins
|
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):
|
def int (v):
|
||||||
return builtins.int(float(v))
|
return builtins.int(float(v))
|
||||||
@@ -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
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import sps
|
import legacy_fwr
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Preplot importing functions.
|
Preplot importing functions.
|
||||||
@@ -7,7 +7,7 @@ Preplot importing functions.
|
|||||||
def from_file (file, realpath = None):
|
def from_file (file, realpath = None):
|
||||||
filepath = realpath or file["path"]
|
filepath = realpath or file["path"]
|
||||||
if not "type" in file or file["type"] == "sps":
|
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:
|
else:
|
||||||
return "Not an SPS file"
|
return "Not an SPS file"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user