io.harwell_boeing._fortran_format_parser

Preliminary module to handle fortran formats for IO. Does not use this outside scipy.sparse io for now, until the API is deemed reasonable.

The *Format classes handle conversion between fortran and python format, and FortranFormatParser can create *Format instances from raw fortran format strings (e.g. ‘(3I4)’, ‘(10I3)’, etc…)

Module Contents

Classes

BadFortranFormat()
IntFormat(self,width,min=None,repeat=None)
ExpFormat(self,width,significand,min=None,repeat=None)
Token(self,type,value,pos)
Tokenizer(self)
FortranFormatParser(self) Parser for fortran format strings. The parse method returns a *Format

Functions

number_digits(n)
class BadFortranFormat
number_digits(n)
class IntFormat(width, min=None, repeat=None)
from_number(n, min=None)

Given an integer, returns a “reasonable” IntFormat instance to represent any number between 0 and n if n > 0, -n and n if n < 0

n : int
max number one wants to be able to represent
min : int
minimum number of characters to use for the format
res : IntFormat
IntFormat instance with reasonable (see Notes) computed width

Reasonable should be understood as the minimal string length necessary without losing precision. For example, IntFormat.from_number(1) will return an IntFormat instance of width 2, so that any 0 and 1 may be represented as 1-character strings without loss of information.

__init__(width, min=None, repeat=None)
__repr__()
fortran_format()
python_format()
class ExpFormat(width, significand, min=None, repeat=None)
from_number(n, min=None)

Given a float number, returns a “reasonable” ExpFormat instance to represent any number between -n and n.

n : float
max number one wants to be able to represent
min : int
minimum number of characters to use for the format
res : ExpFormat
ExpFormat instance with reasonable (see Notes) computed width

Reasonable should be understood as the minimal string length necessary to avoid losing precision.

__init__(width, significand, min=None, repeat=None)

Parameters ———- width : int

number of characters taken by the string (includes space).
__repr__()
fortran_format()
python_format()
class Token(type, value, pos)
__init__(type, value, pos)
__str__()
__repr__()
class Tokenizer
__init__()
input(s)
next_token()
class FortranFormatParser

Parser for fortran format strings. The parse method returns a *Format instance.

Only ExpFormat (exponential format for floating values) and IntFormat (integer format) for now.

__init__()
parse(s)
_get_min(tokens)
_expect(token, tp)
_parse_format(tokens)
_next(tokens, tp)