Skip to content

Commit 81d5f5a

Browse files
authored
Merge pull request #108 from ladisk/double_uneven
BUG: corrected bug in handling left-over samples in uneven double data
2 parents e517508 + 7acb007 commit 81d5f5a

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

pyuff/datasets/dataset_58.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def _write58(fh, dset, mode='add', _filename=None, force_double=True):
993993
fh.write(n4_blocks * '%13.5e%20.11e%13.5e%20.11e\n' % tuple(data[:4 * n4_blocks]))
994994
if rem_vals > 0:
995995
fmt = ['%13.5e', '%20.11e', '%13.5e', '%20.11e']
996-
fh.write((''.join(fmt[rem_vals]) + '\n') % tuple(data[4 * n4_blocks:]))
996+
fh.write((''.join(fmt[:rem_vals]) + '\n') % tuple(data[4 * n4_blocks:]))
997997
else:
998998
if is_even:
999999
fh.write(n4_blocks * '%20.11e%20.11e%20.11e%20.11e\n' % tuple(data[:4 * n4_blocks]))

tests/test_58.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,56 @@ def test_write_read_func_type_0():
286286
np.testing.assert_array_equal(read_dataset['data'], test_data)
287287
np.testing.assert_array_equal(read_dataset['x'], test_x)
288288

289+
def test_double_uneven():
290+
test_double_uneven_base()
291+
test_double_uneven_base(test_data=[1.0,2.0,2.0,4.0], test_x=[20.0,100,300,500])
292+
293+
294+
def test_double_uneven_base(test_data=[1.0,2.0,2.0,4.0,1.0], test_x=[20.0,100,300,500,2000]):
295+
save_to_file = './data/temp.uff'
296+
if os.path.exists(save_to_file):
297+
os.remove(save_to_file)
298+
299+
uffwrite = pyuff.UFF(save_to_file)
300+
my_set = pyuff.prepare_58(binary=None, id1='my_test',
301+
func_type=9, ver_num=0, load_case_id=0,
302+
rsp_ent_name='CH1', rsp_node=0, rsp_dir=1,
303+
ord_data_type=4, num_pts=5, abscissa_spacing=0,
304+
abscissa_spec_data_type=18,
305+
ordinate_spec_data_type=12,
306+
data = test_data,
307+
x = test_x,
308+
return_full_dict=True)
309+
310+
for key,value in my_set.items():
311+
if value is None:
312+
my_set[key] = 0
313+
314+
uffwrite._write_set(my_set,'add')
315+
316+
uffread = pyuff.UFF(save_to_file)
317+
read_data = uffread.read_sets()
318+
319+
# Clean up the file
320+
if os.path.exists(save_to_file):
321+
os.remove(save_to_file)
322+
323+
# Validate the content
324+
assert read_data, "Expected one dataset to be read."
325+
# No need to index; use read_data directly
326+
read_dataset = read_data
327+
328+
# Check basic metadata
329+
np.testing.assert_equal(read_dataset['func_type'], 9)
330+
np.testing.assert_string_equal(read_dataset['id1'], 'my_test')
331+
np.testing.assert_string_equal(read_dataset['rsp_ent_name'], 'CH1')
332+
# Validate data content
333+
np.testing.assert_array_equal(read_dataset['data'], test_data)
334+
np.testing.assert_array_equal(read_dataset['x'], test_x)
289335

290336
if __name__ == '__main__':
291-
test_fix_58b()
337+
test_double_uneven(test_data=[1.0,2.0,2.0,4.0,1.0], test_x=[20.0,100,300,500,2000])
338+
test_double_uneven(test_data=[1.0,2.0,2.0,4.0], test_x=[20.0,100,300,500])
292339

293340
if __name__ == '__mains__':
294341
np.testing.run_module_suite()

0 commit comments

Comments
 (0)