From b783cbb981a6bcdcd8d830db01465bc94cebd50e Mon Sep 17 00:00:00 2001 From: Ying-Li Niu <64801511@qq.com> Date: Thu, 11 Jun 2026 19:11:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(fortran):=20=E4=BF=AE=E5=A4=8D=20read=5Fcoo?= =?UTF-8?q?rd=20=E4=B8=AD=20line(0:0)=20=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=B6=8A=E7=95=8C=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 错误码 3221225785 (0xC0000005 = STATUS_ACCESS_VIOLATION) 由 read_coord 中列数统计的双重条件导致: line(i:i) /= ' ' .and. (i == 1 .or. line(i-1:i-1) == ' ') Fortran 不保证 .or. 短路求值,当 i=1 时 line(0:0) 触发 内存越界。拆分为嵌套 if 块,确保只有在 i>1 时才访问 line(i-1:i-1)。 --- engines/fortran/main.f90 | 8 +++++++- examples/case06/input/input.txt | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/engines/fortran/main.f90 b/engines/fortran/main.f90 index 0dcaef4..c6c1f46 100644 --- a/engines/fortran/main.f90 +++ b/engines/fortran/main.f90 @@ -334,7 +334,13 @@ subroutine read_coord(input_dir, n_atoms, atom_ids, masses, radii, pos_0, vel_0, read(u, '(a)', iostat=ios) line ncols = 0 do i = 1, len_trim(line) - if (line(i:i) /= ' ' .and. (i == 1 .or. line(i-1:i-1) == ' ')) ncols = ncols + 1 + if (line(i:i) /= ' ') then + if (i == 1) then + ncols = ncols + 1 + else if (line(i-1:i-1) == ' ') then + ncols = ncols + 1 + end if + end if end do do diff --git a/examples/case06/input/input.txt b/examples/case06/input/input.txt index df99e09..a65582a 100644 --- a/examples/case06/input/input.txt +++ b/examples/case06/input/input.txt @@ -16,7 +16,7 @@ plot_wave_save_mp4: 1 # 输出波形 MP4(需 step_plot_wave=1) # ── 计算引擎 ────────────────────────────────── # 可选: python, c, cpp, fortran, java -engine: python # 默认使用 python 引擎 +engine: fortran # 默认使用 python 引擎 # ── 盒子 ────────────────────────────────────── box_a: 80.0 # 立方体半边长,粒子被限制在 [-box_a, box_a]³ 内 @@ -63,7 +63,7 @@ warmup_steps: 0 # 默认 0(立即开始记录) # 总模拟时间(秒),程序自动计算 NT = T_total / DT # 如果同时指定了 NT,以 NT 为准 -T_total: 4.0 +T_total: 10.0 # 抽帧间隔(每 NSTEP 步取一帧用于动画) NSTEP: 100