diff --git a/src/angle_write.cpp b/src/angle_write.cpp index 863183995b..9a33722250 100644 --- a/src/angle_write.cpp +++ b/src/angle_write.cpp @@ -26,6 +26,7 @@ #include "force.h" #include "input.h" #include "math_const.h" +#include "safe_pointers.h" #include "update.h" #include @@ -79,13 +80,13 @@ void AngleWrite::command(int narg, char **arg) // otherwise make certain that units are consistent // print header in format used by angle_style table - FILE *fp = nullptr; + SafeFilePtr fp; std::string coeffs_file = table_file + ".tmp.coeffs"; if (comm->me == 0) { - fp = fopen(coeffs_file.c_str(), "w"); - force->angle->write_data(fp); - fclose(fp); + FILE *coeffs = fopen(coeffs_file.c_str(), "w"); + force->angle->write_data(coeffs); + fclose(coeffs); // units sanity check: // - if this is the first time we write to this potential file, @@ -221,7 +222,6 @@ void AngleWrite::command(int narg, char **arg) // clean up delete writer; - fclose(fp); } MPI_Comm_free(&singlecomm); } diff --git a/src/bond.cpp b/src/bond.cpp index f5af30062e..d42dd6fd24 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -20,6 +20,7 @@ #include "force.h" #include "memory.h" #include "neighbor.h" +#include "safe_pointers.h" #include "suffix.h" #include "update.h" @@ -365,7 +366,7 @@ void Bond::write_file(int narg, char **arg) // add line with DATE: and UNITS: tag when creating new file // print header in format used by bond_style table - FILE *fp = nullptr; + SafeFilePtr fp; if (comm->me == 0) { std::string table_file = arg[4]; @@ -419,7 +420,6 @@ void Bond::write_file(int narg, char **arg) e = single(btype, r * r, itype, jtype, f); fprintf(fp, "%8d %- 22.15g %- 22.15g %- 22.15g\n", i + 1, r, e, f * r); } - fclose(fp); } }