VMS IO

The classes in the vms module make reading binary input files exported from a VAX/VMS system more expressive and easier to debug without affecting the clarity of real-time processing code. In normal usage you should only need read_vms_profiles() and write_vms_profiles().

medsrtqc.vms.read_vms_profiles(src, ver='vms')

Read a binary VMS file into a list() of VMSProfile objects.

Parameters:

src – A filename or file-like object

>>> from medsrtqc.vms import read_vms_profiles
>>> from medsrtqc.resources import resource_path
>>> profiles = read_vms_profiles(resource_path('BINARY_VMS.DAT'))
>>> profiles[0]['TEMP'].value
masked_array(data=[3.49900007, 3.45300007, 3.45799994, 3.48900008,
                3.46799994, 3.49099994, 3.4690001 , 3.50999999,
                3.45799994, 3.4849999 , 3.49699998, 3.42199993,
                3.45700002, 3.48900008, 3.48900008, 3.46700001,
                3.51699996],
            mask=False,
    fill_value=1e+20)
medsrtqc.vms.write_vms_profiles(profiles, dest, ver='vms')

Write a binary VMS file from a list() of VMSProfile objects.

Parameters:
  • profiles – A list() of VMSProfile objects.

  • dest – A filename or file-like object

>>> from medsrtqc.vms import write_vms_profiles, read_vms_profiles
>>> from medsrtqc.resources import resource_path
>>> import tempfile
>>> profiles = read_vms_profiles(resource_path('BINARY_VMS.DAT'))
>>> with tempfile.TemporaryFile() as f:
...     write_vms_profiles(profiles, f)
class medsrtqc.vms.VMSProfile(data)

An implementation of the core.Profile type backed by data read from the MEDS internal VMS data structure. These objects are usually created by read_vms_profiles().

Low-level VMS IO

The classes in the vms.enc module are the basis on which the high-level structure definitions are based and are normally not used interactively; however, they may be used to discover the format or debug the reading of files. The built-in types mostly use the Python struct module to encode and decode values.

>>> from io import BytesIO
>>> medsrtqc.vms.enc import *
>>> buf = BytesIO()
>>> encoding = StructEncoding(('f1', Character(4)), ('f2': Integer2()))
>>> encoding.encode(buf, {'f1': 'abc', 'f2': 0})
>>> buf.getvalue()
b'abc \x00\x00'
>>> buf.seek(0)
0
>>> encoding.decode(buf)
OrderedDict([('f1', 'abc'), ('f2', 0)])
class medsrtqc.vms.enc.Encoding

A base class for binary encoding and decoding values

decode(file: BinaryIO, value=None)

Read from a file object and return a Python object

encode(file: BinaryIO, value)

Encode a Python object and send it to a file object

sizeof(value=None)

The number of bytes that decode() will write to file when called

class medsrtqc.vms.enc.Integer2

A 16-bit signed little-endian integer encoding

class medsrtqc.vms.enc.Integer4

A 32-bit signed little-endian integer encoding

class medsrtqc.vms.enc.Real4

A 32-bit middle-endian VAX/-encoded float value

class medsrtqc.vms.enc.Character(length, encoding='utf-8', pad=b' ')

A fixed-length character encoding. A fixed length is enforced by adding a padding character to the right of the string.

class medsrtqc.vms.enc.StructEncoding(*encodings)

A struct containing named values of other encodings

class medsrtqc.vms.enc.ArrayOf(Encoding: Encoding, max_length=None)

An array of some other encoding