!> 输出 module output_m use types_m, only: region_t use config_m, only: in_path, out_path, form use swift_file_m, only: is_exist use stdlib_logger, only: stdlog => global_logger contains !> 输出域,支持输出 ASCII 和二进制文件 subroutine output(region) type(region_t), intent(in) :: region logical :: exist(2) exist(1) = is_exist(in_path//'/ini_xv.dat') exist(2) = is_exist(in_path//'/ini_state.dat') if (all(exist)) then write (*, '(a)', advance='no') 'Outputted data already exists, overwrite? (T/F): ' read (*, '(l1)') exist(1) if (.not. exist(1)) return end if if (form == 'unformatted') then open (1, file=in_path//'/ini_xv.dat', status='replace', access='stream', & form='unformatted') open (2, file=in_path//'/ini_state.dat', status='replace', access='stream', & form='unformatted') write (1) region%n, region%m, region%hsml do i = 1, region%n + region%m write (1) region%loc(:, i), region%vel(:, i) write (2) region%mass(i), region%rho(i), region%p(i), region%u(i), & region%itype(i) end do else open (1, file=in_path//'/ini_xv.dat', status='replace', access='stream', & form='formatted') open (2, file=in_path//'/ini_state.dat', status='replace', access='stream', & form='formatted') ! 文本注释 write (1, '(a)') '# n, m, hsml; loc, vel' write (2, '(a)') '# mass, rho, p, u, itype' write (1, '(2(i0,2x),es14.7)') region%n, region%m, region%hsml do i = 1, region%n + region%m write (1, '(*(es14.7,2x))') region%loc(:, i), region%vel(:, i) write (2, '(4(es14.7,2x),i3)') region%mass(i), region%rho(i), region%p(i), & region%u(i), region%itype(i) end do end if close(1); close(2) call stdlog%log_information('Outputted data to '//in_path//'/ini_xv.dat and '//in_path & //'/ini_state.dat') end subroutine output end module output_m