matcal.core.input_file_writer
Classes
|
Create an input file block to be added to a file or input file block as a subblock. |
|
Create an input file line to be added to a file or input file block. |
|
Stores a table of values for input blocks/files. |
- class matcal.core.input_file_writer.InputFileLine(leading_statement, *args, name=None)[source]
Create an input file line to be added to a file or input file block.
- Parameters:
leading_statement (str) – first word in the line that is always printed.
args (list(str, float, int)) – list of values to be added to the line after the leading statement.
name (str) – optional name for the line. It is used only for accessing the line as part of a block or input file and is not printed. Default is the leading statement if one is not passed.
- write(f, indent=0)[source]
Write the line to a file handle object.
- Parameters:
f (TextIOWrapper) – the file object that line will be written to.
indent (int) – The number of indents to be applied to the line. The default indent is four spaces.
- get_string(indent=0)[source]
Return the line string with a specified indent.
- Parameters:
indent (int) – the number of indents to be applied to the line. The default indent is four spaces.
- suppress_symbol()[source]
Do not output a symbol between the line leading statement and the following values.
- set_at_end(value)[source]
Set the line’s last value.
- Parameters:
value (float or str) – the last value the line will contain.
- set(value, index=1)[source]
Set the line’s value. By default it sets the lines value after the leading statement (default index of 1). If an index greater than the current length is chosen, empty entries are added until the line reaches the correct number of entries
- warning :: a non-string or float can be added. It must be able to be
converted to a string using the str function to be printed correctly.
- Parameters:
value (float or str) – the value to be added to the line.
index (int) – the location of the value place in the line list.
- class matcal.core.input_file_writer.InputFileBlock(title, name=None, begin_end=False)[source]
Create an input file block to be added to a file or input file block as a subblock.
- Parameters:
title (str) – The block title. This is printed by default and all lines in the subblock are printed as indented lines.
name (str) – An optional name. Set to title by default. The name is how to access the subblock from any parent container object.
name – optional name for the line. It is used for accessing the subblock as part of a block or input file and is not printed by default. The name can be printed in place of the title if one is used.
begin_end – Prepend “Begin “ to the block title and close the block with an “End {title}” line.
- property title
Returns the subblock title.
- Return type:
str
- property name
Returns the subblock name.
- Return type:
str
- property lines
Returns a list of all block lines.
- Return type:
list(
InputFileLine)
- property subblocks
Returns a list of all block subblocks.
- Return type:
list(
InputFileBlock)
- property tables
Returns a list of all block tables.
- Return type:
list(
InputFileTable)
- add_line(line, replace=False)[source]
Add a line to the input file block.
- Parameters:
line (
InputFileLine) – the line to be added.replace (bool) – replace existing value if the line is in the block lines when sen to True
- add_lines(*lines, replace=False)[source]
Add a set or list of lines to the input file block.
- Parameters:
lines (list(
InputFileLine)) – the lines to be added.replace (bool) – replace existing value if the line is in the block lines when sen to True
- add_lines_from_dictionary(dictionary, replace=False)[source]
Use a dictionary to add several keyword, value pairs to the block as lines. The keywords will end up being the lines’ leading statements and the values will be the values.
- Parameters:
dictionary (dict(str or float or tuple(float, str) or list(float, str))) – the dictionary containing the line information to be added to the block.
replace (bool) – replace lines if already existing in the subblock
- add_subblock(subblock, replace=False, set_begin_end_to_parent=False)[source]
Add a subblock to the input file block or input file.
- Parameters:
subblock (
matcal.core.input_file_writer.InputFileBlock) – the subblock to be added. Can be unpopulated.replace (bool) – the subblock will replace an existing one if found.
- remove_subblock(subblock)[source]
Remove and return the passed subblock or subblock name.
- Parameters:
subblock (str or
matcal.core.input_file_writer.InputFileBlock) – the subblock to be removed from the input file block.
- get_line(line_name)[source]
Returns a line with the passed line name.
- Parameters:
line_name (str) – the name of the line desired.
- Return type:
- get_line_value(key, index=1)[source]
Return the value from the line values at a specified index. By default it returns the second value, which is the value after the line keyword.
- Parameters:
key (str) – the name of the line. Usually the keyword.
index (int) – an optional parameter to set a different index for the returned value from the line
- get_subblock(key)[source]
Get a subblock by name from the block.
- Parameters:
key (str) – the name of the desired subblock.
- get_table(name)[source]
Returns a table for a given table name if it is in the input file/block.
- Parameters:
name (str) – name of the desired table.
- write(f)[source]
Write the subblock to a file handle object.
- Parameters:
f (TextIOWrapper) – the file object that line will be written to.
- set_print_name(print_name=True, print_title=False)[source]
Controls whether to print the name of the subblock. By default, it prints the name and not the title.
- Parameters:
print_name (bool) – print the name if True or do not if False.
- set_print_title(print_title=True)[source]
Controls how to print the title of the subblock. By default, it prints the name and not the title. If the title is printed, it is printed before the name.
- Parameters:
print_title (bool) – print the title with the name or as the name
- suppress_symbols_for_lines()[source]
Suppress the symbol for all lines in the block. Does not apply to subblocks.
- set_symbol_for_lines(symbol)[source]
Set the symbol for all lines in the block. Does not apply to subblocks.
- Parameters:
symbol (None or str) – symbol to be used for all block lines. If none, the symbol will be suppressed.