Source code for pyNastran.bdf.field_writer_8

"""Defines functions for single precision 8 character field writing."""
import sys
import warnings
from typing import List, Union, Any
from numpy import float32, float64, isnan


[docs]def set_string8_blank_if_default(value: Any, default: Any) -> str: """helper method for writing BDFs""" val = set_blank_if_default(value, default) if val is None: return ' ' return '%8s' % val
[docs]def is_same(value1: Any, value2: Any) -> bool: """ Checks to see if 2 values are the same .. note:: this method is used by almost every card when printing """ if isinstance(value1, str) or value1 is None: return value1 == value2 if value1 == value2: return True return False
[docs]def set_blank_if_default(value: Any, default: Any) -> Union[int, float, str, None]: """ Used when setting the output data of a card to clear default values Parameters ---------- value : int/float/str the field value the may be set to None (blank) if value=default, the default value for the field default : int/float/str the default value .. note:: this method is used by almost every card when printing """ if isinstance(value, (float, float32, float64)) and isnan(value): return None return None if is_same(value, default) else value
[docs]def set_default_if_blank(value: Any, default: Any) -> Union[int, float, str]: """ Used when initializing a card and the default value isn't set Used on PBARL""" return default if value is None or value == '' else value
#def print_float_or_int_8(value: Union[int, float]) - str: #""" #Prints a 8-character width field #Parameters #---------- #value : int/float #the value to print #Returns #------- #field : str #an 8-character string #""" #if isinstance(value, (float, float32, float64)): #field = print_float_8(value) #elif isinstance(value, int): #field = "%8i" % value #else: #msg = 'Invalid Type: value=%r type=%s' % (value, type(value)) #raise TypeError(msg) #return field