From 6e37818bbbc9d83ede8692442e38269caabb7ae2 Mon Sep 17 00:00:00 2001 From: wenxiannnn <4bar1p@gmail.com> Date: Thu, 19 Mar 2026 21:14:29 +0800 Subject: [PATCH] Add if(!file.is_open()) check in write_restart --- source/source_md/md_base.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/source_md/md_base.cpp b/source/source_md/md_base.cpp index 390e1c2b08..258e4494e6 100644 --- a/source/source_md/md_base.cpp +++ b/source/source_md/md_base.cpp @@ -235,6 +235,13 @@ void MD_base::write_restart(const std::string& global_out_dir) std::stringstream ssc; ssc << global_out_dir << "Restart_md.txt"; std::ofstream file(ssc.str().c_str()); + + if (!file.is_open()) + { + std::cerr << "Fatal Error in MD_base::write_restart: " << std::endl; + std::cerr << "Cannot open file " << ssc.str() << " for writing." << std::endl; + std::cerr << "Please check if the directory exists and has write permissions." << std::endl; + } file << step_ + step_rst_ << std::endl; file << md_tfirst << std::endl;