ansys.dyna.core.lib.kwd_line_formatter#
Keyword line formatter.
Attributes#
Classes#
Immutable, hashable specification for parsing fixed-width data lines. |
Functions#
|
Read and return the line, and a flag on whether to stop reading. |
|
Return whether the buffer is at the end of the keyword |
|
Read from the buffer into a list of string. |
|
Returns the text block from the line at the given position and width. |
|
Given a text block - determine if a keyword value exists. |
|
Loads a keyword card line from string, auto-detecting fixed-width or comma-delimited format. |
|
Like load_dataline, but also returns the detected format. |
Module Contents#
- ansys.dyna.core.lib.kwd_line_formatter.read_line(buf: TextIO, skip_comment=True) Tuple[str, bool][source]#
Read and return the line, and a flag on whether to stop reading.
- ansys.dyna.core.lib.kwd_line_formatter.at_end_of_keyword(buf: TextIO) bool[source]#
Return whether the buffer is at the end of the keyword
- ansys.dyna.core.lib.kwd_line_formatter.buffer_to_lines(buf: TextIO, max_num_lines: int = -1) List[str][source]#
Read from the buffer into a list of string. buf: buffer to read from max_num_lines: number of lines to read. -1 means no limit
- ansys.dyna.core.lib.kwd_line_formatter.seek_text_block(line_data: str, position: int, width: int) Tuple[int, str][source]#
Returns the text block from the line at the given position and width.
If the position is past the end, it will return an empty string.
- ansys.dyna.core.lib.kwd_line_formatter.has_value(text_block: str) bool[source]#
Given a text block - determine if a keyword value exists.
If its an empty string (i.e. the seek_text_block returned an empty string) then there is no value. If its just whitespace, then the keyword file did not include data for that field.
- ansys.dyna.core.lib.kwd_line_formatter.load_dataline(spec: List[tuple], line_data: str, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet = None) List[source]#
Loads a keyword card line from string, auto-detecting fixed-width or comma-delimited format.
LS-DYNA supports both fixed-width format and comma-delimited (free) format. This function automatically detects which format is used based on the presence of commas in the line. Per the LS-DYNA manual, formats can be mixed within a deck but not within a single card.
- Parameters:
- Returns:
listParsed values from the keyword card line.
Examples
>>> load_dataline([(0,10, int),(10,10, str)], ' 1 hello') (1, 'hello') >>> load_dataline([(0,10, int),(10,10, str)], '1,hello') (1, 'hello')
- ansys.dyna.core.lib.kwd_line_formatter.load_dataline_with_format(spec: List[tuple], line_data: str, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet = None) Tuple[List, str][source]#
Like load_dataline, but also returns the detected format.
- Returns:
tupleA tuple of (values, format) where format is ‘csv’ or ‘fixed’.