fix(c): read_bonds 中 rewind 后未跳过表头行导致成键数据全为空

rewind(f) 将文件指针拉回开头(含表头 'n1 n2 bond_name'),
后续 fscanf 试图将 'n1' 解析为 %d 全部失败,导致:
- bond_pairs 直接用未初始化的栈垃圾 → 随机索引
- bond_stiffness/rest_lengths 保持默认值 1.0/2.0
- 弹簧力无法正确传播 → 第一个原子动后后面全不动

修复:rewind 后加 fgets(line, ...) 再次跳过表头。
This commit is contained in:
2026-06-11 19:38:10 +08:00
parent e353e04133
commit 9d5997afec
3 changed files with 60009 additions and 60008 deletions
+1
View File
@@ -389,6 +389,7 @@ static BondData read_bonds(const char *input_dir, const AtomData *atoms) {
char bond_name[256];
while (fscanf(f, "%d %d %s", &tmp_a, &tmp_b, bond_name) == 3) n_lines++;
rewind(f);
fgets(line, sizeof(line), f); // 再次跳过表头
if (n_lines == 0) { fclose(f); return b; }