Coverage for src / sdynpy / fileio / sdynpy_uff_datasets / sdynpy_uff_dataset_164.py: 21%

53 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 16:22 +0000

1# -*- coding: utf-8 -*- 

2""" 

3Units 

4 

5This dataset defines the unit system for the universal file 

6""" 

7""" 

8Copyright 2022 National Technology & Engineering Solutions of Sandia, 

9LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. 

10Government retains certain rights in this software. 

11 

12This program is free software: you can redistribute it and/or modify 

13it under the terms of the GNU General Public License as published by 

14the Free Software Foundation, either version 3 of the License, or 

15(at your option) any later version. 

16 

17This program is distributed in the hope that it will be useful, 

18but WITHOUT ANY WARRANTY; without even the implied warranty of 

19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

20GNU General Public License for more details. 

21 

22You should have received a copy of the GNU General Public License 

23along with this program. If not, see <https://www.gnu.org/licenses/>. 

24""" 

25 

26from ..sdynpy_uff import UFFReadError 

27 

28 

29class Sdynpy_UFF_Dataset_164: 

30 def __init__(self): 

31 self.units_code = 0 

32 self.units_description = '' 

33 self.temperature_mode = 1 

34 self.length_conv = 1 

35 self.force_conv = 1 

36 self.temp_conv = 1 

37 self.temp_offset = 1 

38 

39 @property 

40 def dataset_number(self): 

41 return 164 

42 

43 @classmethod 

44 def from_uff_data_array(cls, data): 

45 # Transform from binary to ascii 

46 data = [line.decode() for line in data] 

47 ds_164 = cls() 

48 # Record 1: FORMAT(I10,20A1,I10) 

49 # Field 1 -- units code 

50 # = 1 - SI: Meter (newton) 

51 # = 2 - BG: Foot (pound f) 

52 # = 3 - MG: Meter (kilogram f) 

53 # = 4 - BA: Foot (poundal) 

54 # = 5 - MM: mm (milli newton) 

55 # = 6 - CM: cm (centi newton) 

56 # = 7 - IN: Inch (pound f) 

57 # = 8 - GM: mm (kilogram f) 

58 # = 9 - US: USER_DEFINED 

59 # = 10- MN: mm (newton) 

60 try: 

61 ds_164.units_code = int(data[0][0:10]) 

62 except ValueError: 

63 return UFFReadError('Units Code (record 1 field 1) must be an integer!') 

64 # Field 2 -- units description (used for 

65 # documentation only) 

66 ds_164.units_description = data[0][10:30].strip() 

67 # Field 3 -- temperature mode 

68 # = 1 - absolute 

69 # = 2 - relative 

70 try: 

71 ds_164.temperature_mode = int(data[0][30:40]) 

72 except ValueError: 

73 return UFFReadError('Temperature Mode (record 1 field 3) must be an integer!') 

74 # Record 2: FORMAT(3D25.17) 

75 # Unit factors for converting universal file units to SI. 

76 # To convert from universal file units to SI divide by 

77 # the appropriate factor listed below. 

78 # Field 1 -- length 

79 try: 

80 ds_164.length_conv = float(data[1][0:25].replace('D','E')) 

81 except ValueError: 

82 return UFFReadError('Length Conversion Factor (record 2 field 1) must be a floating point number') 

83 # Field 2 -- force 

84 try: 

85 ds_164.force_conv = float(data[1][25:50].replace('D','E')) 

86 except ValueError: 

87 return UFFReadError('Force Conversion Factor (record 2 field 2) must be a floating point number') 

88 # Field 3 -- temperature 

89 try: 

90 ds_164.temp_conv = float(data[1][50:75].replace('D','E')) 

91 except ValueError: 

92 return UFFReadError('Temperature Conversion Factor (record 2 field 3) must be a floating point number') 

93 # Field 4 -- temperature offset <-- Actually Record 3 field 1! 

94 try: 

95 ds_164.temp_offset = float(data[2][0:25].replace('D','E')) 

96 except ValueError: 

97 return UFFReadError('Temperature offset (record 4 field 1) must be a floating point number') 

98 return ds_164 

99 

100 def __repr__(self): 

101 return 'Sdynpy_UFF_Dataset_164<{}>'.format(self.units_description) 

102 

103 def write_string(self): 

104 return ('{:<10}{:<20}{:<10}\n'.format(self.units_code, 

105 self.units_description, 

106 self.temperature_mode) + 

107 '{:>25.17E}{:>25.17E}{:>25.17E}\n{:>25.17E}\n'.format(self.length_conv, 

108 self.force_conv, 

109 self.temp_conv, 

110 self.temp_offset)) 

111 

112 def __str__(self): 

113 lines = self.write_string().split('\n') 

114 if len(lines) > 8: 

115 return 'Dataset 164: Units\n ' + '\n '.join(lines[0:5] + ['.', '.', '.']) 

116 else: 

117 return 'Dataset 164: Units\n ' + '\n '.join(lines) 

118 

119 

120def read(data): 

121 return Sdynpy_UFF_Dataset_164.from_uff_data_array(data)