diff --git a/src/dump_atom.cpp b/src/dump_atom.cpp index 0dbd3b3278..dd2ea7ee13 100644 --- a/src/dump_atom.cpp +++ b/src/dump_atom.cpp @@ -289,19 +289,21 @@ void DumpAtom::header_item(bigint ndump) { if (unit_flag && !unit_count) { ++unit_count; - fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style); + fmt::print(fp,"ITEM: UNITS\n{}\n",update->unit_style); } - if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time()); + if (time_flag) fmt::print(fp,"ITEM: TIME\n{:.16}\n",compute_time()); - fprintf(fp,"ITEM: TIMESTEP\n"); - fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep); - fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,BIGINT_FORMAT "\n",ndump); - fprintf(fp,"ITEM: BOX BOUNDS %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e\n",boxxlo,boxxhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxylo,boxyhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxzlo,boxzhi); - fprintf(fp,"ITEM: ATOMS %s\n",columns); + fmt::print(fp,"ITEM: TIMESTEP\n{}\n" + "ITEM: NUMBER OF ATOMS\n{}\n", + update->ntimestep, ndump); + + fmt::print(fp,"ITEM: BOX BOUNDS {}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxylo,boxyhi,boxzlo,boxzhi); + + fmt::print(fp,"ITEM: ATOMS {}\n",columns); } /* ---------------------------------------------------------------------- */ @@ -310,19 +312,21 @@ void DumpAtom::header_item_triclinic(bigint ndump) { if (unit_flag && !unit_count) { ++unit_count; - fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style); + fmt::print(fp,"ITEM: UNITS\n{}\n",update->unit_style); } - if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time()); + if (time_flag) fmt::print(fp,"ITEM: TIME\n{:.16}\n",compute_time()); - fprintf(fp,"ITEM: TIMESTEP\n"); - fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep); - fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,BIGINT_FORMAT "\n",ndump); - fprintf(fp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz); - fprintf(fp,"ITEM: ATOMS %s\n",columns); + fmt::print(fp,"ITEM: TIMESTEP\n{}\n" + "ITEM: NUMBER OF ATOMS\n{}\n", + update->ntimestep, ndump); + + fmt::print(fp,"ITEM: BOX BOUNDS xy xz yz {}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxxy,boxylo,boxyhi,boxxz,boxzlo,boxzhi,boxyz); + + fmt::print(fp,"ITEM: ATOMS {}\n",columns); } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index d52dac745f..b1c9aed58b 100644 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -123,7 +123,7 @@ void DumpCFG::write_header(bigint n) if (atom->peri_flag) scale = atom->pdscale; else if (unwrapflag == 1) scale = UNWRAPEXPAND; - fprintf(fp,"Number of particles = " BIGINT_FORMAT "\n", n); + fmt::print(fp,"Number of particles = {}\n", n); fprintf(fp,"A = %g Angstrom (basic length-scale)\n",scale); fprintf(fp,"H0(1,1) = %g A\n",domain->xprd); fprintf(fp,"H0(1,2) = 0 A \n"); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 5d371d3145..e7371c1fe1 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -507,19 +507,21 @@ void DumpCustom::header_item(bigint ndump) { if (unit_flag && !unit_count) { ++unit_count; - fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style); + fmt::print(fp,"ITEM: UNITS\n{}\n",update->unit_style); } - if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time()); + if (time_flag) fmt::print(fp,"ITEM: TIME\n{:.16}\n",compute_time()); - fprintf(fp,"ITEM: TIMESTEP\n"); - fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep); - fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,BIGINT_FORMAT "\n",ndump); - fprintf(fp,"ITEM: BOX BOUNDS %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e\n",boxxlo,boxxhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxylo,boxyhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxzlo,boxzhi); - fprintf(fp,"ITEM: ATOMS %s\n",columns); + fmt::print(fp,"ITEM: TIMESTEP\n{}\n" + "ITEM: NUMBER OF ATOMS\n{}\n", + update->ntimestep, ndump); + + fmt::print(fp,"ITEM: BOX BOUNDS {}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxylo,boxyhi,boxzlo,boxzhi); + + fmt::print(fp,"ITEM: ATOMS {}\n",columns); } /* ---------------------------------------------------------------------- */ @@ -528,19 +530,21 @@ void DumpCustom::header_item_triclinic(bigint ndump) { if (unit_flag && !unit_count) { ++unit_count; - fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style); + fmt::print(fp,"ITEM: UNITS\n{}\n",update->unit_style); } - if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time()); + if (time_flag) fmt::print(fp,"ITEM: TIME\n{:.16}\n",compute_time()); - fprintf(fp,"ITEM: TIMESTEP\n"); - fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep); - fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,BIGINT_FORMAT "\n",ndump); - fprintf(fp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz); - fprintf(fp,"ITEM: ATOMS %s\n",columns); + fmt::print(fp,"ITEM: TIMESTEP\n{}\n" + "ITEM: NUMBER OF ATOMS\n{}\n", + update->ntimestep, ndump); + + fmt::print(fp,"ITEM: BOX BOUNDS xy xz yz {}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxxy,boxylo,boxyhi,boxxz,boxzlo,boxzhi,boxyz); + + fmt::print(fp,"ITEM: ATOMS {}\n",columns); } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_local.cpp b/src/dump_local.cpp index 67586c625a..a5bc99d939 100644 --- a/src/dump_local.cpp +++ b/src/dump_local.cpp @@ -242,8 +242,7 @@ int DumpLocal::modify_param(int narg, char **arg) // use of &str[1] removes leading '%' from BIGINT_FORMAT string char *ptr = strchr(format_int_user,'d'); if (ptr == nullptr) - error->all(FLERR, - "Dump_modify int format does not contain d character"); + error->all(FLERR, "Dump_modify int format does not contain d character"); char str[8]; sprintf(str,"%s",BIGINT_FORMAT); *ptr = '\0'; @@ -273,26 +272,29 @@ void DumpLocal::write_header(bigint ndump) if (me == 0) { if (unit_flag && !unit_count) { ++unit_count; - fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style); + fmt::print(fp,"ITEM: UNITS\n{}\n",update->unit_style); } - if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time()); + if (time_flag) fmt::print(fp,"ITEM: TIME\n{:.16}\n",compute_time()); + + fmt::print(fp,"ITEM: TIMESTEP\n{}\n" + "ITEM: NUMBER OF {}\n{}\n", + update->ntimestep, label, ndump); - fprintf(fp,"ITEM: TIMESTEP\n"); - fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep); - fprintf(fp,"ITEM: NUMBER OF %s\n",label); - fprintf(fp,BIGINT_FORMAT "\n",ndump); if (domain->triclinic) { - fprintf(fp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz); - fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz); + fmt::print(fp,"ITEM: BOX BOUNDS xy xz yz {}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxxy,boxylo,boxyhi,boxxz,boxzlo,boxzhi,boxyz); } else { - fprintf(fp,"ITEM: BOX BOUNDS %s\n",boundstr); - fprintf(fp,"%-1.16e %-1.16e\n",boxxlo,boxxhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxylo,boxyhi); - fprintf(fp,"%-1.16e %-1.16e\n",boxzlo,boxzhi); + fmt::print(fp,"ITEM: BOX BOUNDS {}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n" + "{:>1.16e} {:>1.16e}\n", + boundstr,boxxlo,boxxhi,boxylo,boxyhi,boxzlo,boxzhi); } - fprintf(fp,"ITEM: %s %s\n",label,columns); + + fmt::print(fp,"ITEM: {} {}\n", label, columns); } } diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index b6cb17b8c9..efe1bd9fdc 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -941,7 +941,7 @@ void FixAveChunk::end_of_step() if (overwrite) platform::fseek(fp,filepos); double count = 0.0; for (m = 0; m < nchunk; m++) count += count_total[m]; - fprintf(fp,BIGINT_FORMAT " %d %g\n",ntimestep,nchunk,count); + fmt::print(fp,"{} {} {}\n",ntimestep,nchunk,count); int compress = cchunk->compress; int *chunkID = cchunk->chunkID; diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index 486b991b77..17182c8667 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -487,7 +487,7 @@ void FixAveCorrelate::end_of_step() if (fp && me == 0) { clearerr(fp); if (overwrite) platform::fseek(fp,filepos); - fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrepeat); + fmt::print(fp,"{} {}\n",ntimestep,nrepeat); for (i = 0; i < nrepeat; i++) { fprintf(fp,"%d %d %d",i+1,i*nevery,count[i]); if (count[i]) diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index 5a7c6d4ccb..c2acd652ad 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -815,7 +815,7 @@ void FixAveHisto::end_of_step() if (fp && me == 0) { clearerr(fp); if (overwrite) platform::fseek(fp,filepos); - fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins, + fmt::print(fp,"{} {} {} {} {} {}\n",ntimestep,nbins, stats_total[0],stats_total[1],stats_total[2],stats_total[3]); if (stats_total[0] != 0.0) for (i = 0; i < nbins; i++) diff --git a/src/fix_ave_histo_weight.cpp b/src/fix_ave_histo_weight.cpp index 16a64e093e..f90551b52f 100644 --- a/src/fix_ave_histo_weight.cpp +++ b/src/fix_ave_histo_weight.cpp @@ -468,7 +468,7 @@ void FixAveHistoWeight::end_of_step() if (fp && me == 0) { clearerr(fp); if (overwrite) platform::fseek(fp,filepos); - fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins, + fmt::print(fp,"{} {} {} {} {} {}\n",ntimestep,nbins, stats_total[0],stats_total[1],stats_total[2],stats_total[3]); if (stats_total[0] != 0.0) for (i = 0; i < nbins; i++) diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 98b066ef0b..ee08c859f4 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -669,11 +669,10 @@ void FixAveTime::invoke_scalar(bigint ntimestep) if (fp && me == 0) { clearerr(fp); if (overwrite) platform::fseek(fp,filepos); - fprintf(fp,BIGINT_FORMAT,ntimestep); + fmt::print(fp,"{}",ntimestep); for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm); fprintf(fp,"\n"); - if (ferror(fp)) - error->one(FLERR,"Error writing out time averaged data"); + if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data"); fflush(fp); @@ -881,7 +880,7 @@ void FixAveTime::invoke_vector(bigint ntimestep) if (fp && me == 0) { if (overwrite) platform::fseek(fp,filepos); - fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrows); + fmt::print(fp,"{} {}\n",ntimestep,nrows); for (i = 0; i < nrows; i++) { fprintf(fp,"%d",i+1); for (j = 0; j < nvalues; j++) fprintf(fp,format,array_total[i][j]/norm); diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index f7b9662c24..0e91a5f3fb 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -445,34 +445,35 @@ void FixPropertyAtom::write_data_section(int /*mth*/, FILE *fp, int n, double **buf, int /*index*/) { int k,icol,ncol,nv; + std::string line; for (int i = 0; i < n; i++) { - fprintf(fp,TAGINT_FORMAT,(tagint) ubuf(buf[i][0]).i); + line = fmt::format("{}",(tagint) ubuf(buf[i][0]).i); icol = 1; for (nv = 0; nv < nvalue; nv++) { if (styles[nv] == MOLECULE) - fprintf(fp," " TAGINT_FORMAT,(tagint) ubuf(buf[i][icol++]).i); + line += fmt::format(" {}",(tagint) ubuf(buf[i][icol++]).i); else if (styles[nv] == CHARGE) - fprintf(fp," %g",buf[i][icol++]); + line += fmt::format(" {}",buf[i][icol++]); else if (styles[nv] == RMASS) - fprintf(fp," %g",buf[i][icol++]); + line += fmt::format(" {}",buf[i][icol++]); else if (styles[nv] == IVEC) - fprintf(fp," %d",(int) ubuf(buf[i][icol++]).i); + line += fmt::format(" {}",(int) ubuf(buf[i][icol++]).i); else if (styles[nv] == DVEC) - fprintf(fp," %g",buf[i][icol++]); + line += fmt::format(" {}",buf[i][icol++]); else if (styles[nv] == IARRAY) { ncol = cols[nv]; for (k = 0; k < ncol; k++) - fprintf(fp," %d",(int) ubuf(buf[i][icol+k]).i); + line += fmt::format(" {}",(int) ubuf(buf[i][icol+k]).i); icol += ncol; } else if (styles[nv] == DARRAY) { ncol = cols[nv]; for (k = 0; k < ncol; k++) - fprintf(fp," %g",buf[i][icol+k]); + line += fmt::format(" {}",buf[i][icol+k]); icol += ncol; } } - fprintf(fp,"\n"); + fmt::print(fp,line+"\n"); } }