Skip to content

Commit

Permalink
Move from sprintf to snprintf.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetmatharu committed Dec 1, 2023
1 parent bc23614 commit 40d23aa
Show file tree
Hide file tree
Showing 415 changed files with 2,174 additions and 2,147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void SUPGAdvectionDiffusionProblem<ELEMENT>::doc_solution()

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution()

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
some_file.close();

// Output exact solution
//----------------------
sprintf(filename,"%s/exact_soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/exact_soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output_fct(some_file,npts,TanhSolnForAdvectionDiffusion::get_exact_u);
Expand All @@ -302,7 +302,7 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution()
// Doc error and return of the square of the L2 error
//---------------------------------------------------
double error,norm;
sprintf(filename,"%s/error%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/error%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->compute_error(some_file,TanhSolnForAdvectionDiffusion::get_exact_u,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution(

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ doc_solution(DocInfo& doc_info)

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output(some_file,npts);
some_file.close();

// Output exact solution
//----------------------
sprintf(filename,"%s/exact_soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/exact_soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output_fct(some_file,npts,TanhSolnForAdvectionDiffusion::get_exact_u);
Expand All @@ -371,7 +371,7 @@ doc_solution(DocInfo& doc_info)
// Doc error and return of the square of the L2 error
//---------------------------------------------------
double error,norm;
sprintf(filename,"%s/error%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/error%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->compute_error(some_file,TanhSolnForAdvectionDiffusion::get_exact_u,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution()

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
Expand All @@ -323,7 +323,7 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution()

// Output exact solution
//----------------------
sprintf(filename,"%s/exact_soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/exact_soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output_fct(some_file,npts,RachelsAdvectionDiffusion::get_exact_u);
Expand All @@ -333,7 +333,7 @@ void RefineableAdvectionDiffusionProblem<ELEMENT>::doc_solution()
// Doc error and return of the square of the L2 error
//---------------------------------------------------
double error,norm;
sprintf(filename,"%s/error%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/error%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->compute_error(some_file,RachelsAdvectionDiffusion::get_exact_u,
Expand Down
6 changes: 3 additions & 3 deletions demo_drivers/all_foeppl_von_karman/axisym_displ_based_fvk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,22 @@ void AxisymFvKProblem<ELEMENT>::doc_solution()
// Output solution with specified number of plot points per element
char filename[100];

sprintf(filename, "%s/soln%i.dat",
snprintf(filename, sizeof(filename), "%s/soln%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream solution_file(filename,ios::app);
mesh_pt()->output(solution_file,npts);
solution_file.close();


// Output exact solution
sprintf(filename, "%s/exactsol%i.dat",
snprintf(filename, sizeof(filename), "%s/exactsol%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream exact_file(filename,ios::app);
mesh_pt()->output_fct(exact_file,npts,AxisymFvKParameters::get_exact_u);
exact_file.close();

// Output solution at the centre (r=0) as function of the pressure
sprintf(filename, "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
snprintf(filename, sizeof(filename), "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
ofstream w_centre_file(filename,ios::app);
w_centre_file << AxisymFvKParameters::Pressure << " "
<< mesh_pt()->node_pt(0)->value(0) << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions demo_drivers/all_foeppl_von_karman/axisym_fvk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ void AxisymFvKProblem<ELEMENT>::doc_solution()

// Output solution with specified number of plot points per element
char filename[100];
sprintf(filename, "%s/sol_%i.dat",
snprintf(filename, sizeof(filename), "%s/sol_%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream solution_file(filename,ios::app);
mesh_pt()->output(solution_file,npts);
solution_file.close();


// Output exact solution
sprintf(filename, "%s/exact_sol_%i.dat",
snprintf(filename, sizeof(filename), "%s/exact_sol_%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream exact_file(filename,ios::app);
mesh_pt()->output_fct(exact_file,npts,AxisymFvKParameters::get_exact_u);
exact_file.close();


// Output solution at the centre (r=0) as function of the pressure
sprintf(filename, "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
snprintf(filename, sizeof(filename), "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
ofstream w_centre_file(filename,ios::app);
w_centre_file << AxisymFvKParameters::Pressure << " "
<< mesh_pt()->node_pt(0)->value(0) << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions demo_drivers/all_foeppl_von_karman/circular_disk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ UnstructuredFvKProblem<ELEMENT>::UnstructuredFvKProblem(double element_area)
build_global_mesh();

char filename[100];
sprintf(filename, "RESLT/trace.dat");
snprintf(filename, sizeof(filename), "RESLT/trace.dat");
Trace_file.open(filename);

oomph_info << "Number of equations: "
Expand Down Expand Up @@ -423,14 +423,14 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()
// Number of plot points
unsigned npts = 5;

sprintf(filename,"RESLT/soln%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/soln%i.dat",Doc_info.number());
some_file.open(filename);
this->My_mesh_pt->output(some_file,npts);
some_file.close();

// Output boundaries
//------------------
sprintf(filename,"RESLT/boundaries%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/boundaries%i.dat",Doc_info.number());
some_file.open(filename);
My_mesh_pt->output_boundaries(some_file);
some_file.close();
Expand All @@ -453,7 +453,7 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()
}

// Plot solution along radial line
sprintf(filename,"RESLT/soln_along_radial_line%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/soln_along_radial_line%i.dat",Doc_info.number());
some_file.open(filename);
Vector<double> x(2);
unsigned nplot=Radial_sample_point_pt.size();
Expand All @@ -473,7 +473,7 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()
// Doc error and return of the square of the L2 error
//---------------------------------------------------
double dummy_error,zero_norm;
sprintf(filename,"RESLT/norm%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/norm%i.dat",Doc_info.number());
some_file.open(filename);
My_mesh_pt->compute_error(some_file,GlobalParameters::zero,
dummy_error,zero_norm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ UnstructuredFvKProblem<ELEMENT>::UnstructuredFvKProblem(double element_area)
build_global_mesh();

char filename[100];
sprintf(filename, "RESLT/trace.dat");
snprintf(filename, sizeof(filename), "RESLT/trace.dat");
Trace_file.open(filename);

oomph_info << "Number of equations: "
Expand Down Expand Up @@ -485,14 +485,14 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()
// Number of plot points
unsigned npts = 5;

sprintf(filename,"RESLT/soln%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/soln%i.dat",Doc_info.number());
some_file.open(filename);
this->My_mesh_pt->output(some_file,npts);
some_file.close();

// Output boundaries
//------------------
sprintf(filename,"RESLT/boundaries%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/boundaries%i.dat",Doc_info.number());
some_file.open(filename);
My_mesh_pt->output_boundaries(some_file);
some_file.close();
Expand All @@ -516,7 +516,7 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()


// Plot solution along radial line
sprintf(filename,"RESLT/soln_along_radial_line%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/soln_along_radial_line%i.dat",Doc_info.number());
some_file.open(filename);
Vector<double> x(2);
unsigned nplot=Radial_sample_point_pt.size();
Expand All @@ -538,7 +538,7 @@ void UnstructuredFvKProblem<ELEMENT>::doc_solution()
// Doc error and return of the square of the L2 error
//---------------------------------------------------
double dummy_error,zero_norm;
sprintf(filename,"RESLT/norm%i.dat",Doc_info.number());
snprintf(filename, sizeof(filename), "RESLT/norm%i.dat",Doc_info.number());
some_file.open(filename);
My_mesh_pt->compute_error(some_file,GlobalParameters::zero,
dummy_error,zero_norm);
Expand Down
2 changes: 1 addition & 1 deletion demo_drivers/axisym_advection_diffusion/pipe/pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void RefineableAdvectionDiffusionPipeProblem<ELEMENT>::doc_solution()

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void RefineableAdvectionDiffusionPipeProblem<ELEMENT>::doc_solution()

// Output solution
//-----------------
sprintf(filename,"%s/soln%i.dat",Doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
Doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,22 @@ void AxisymFvKProblem<ELEMENT>::doc_solution()
// Output solution with specified number of plot points per element
char filename[100];

sprintf(filename, "%s/soln%i.dat",
snprintf(filename, sizeof(filename), "%s/soln%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream solution_file(filename,ios::app);
mesh_pt()->output(solution_file,npts);
solution_file.close();


// Output exact solution
sprintf(filename, "%s/exactsol%i.dat",
snprintf(filename, sizeof(filename), "%s/exactsol%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream exact_file(filename,ios::app);
mesh_pt()->output_fct(exact_file,npts,AxisymFvKParameters::get_exact_u);
exact_file.close();

// Output solution at the centre (r=0) as function of the pressure
sprintf(filename, "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
snprintf(filename, sizeof(filename), "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
ofstream w_centre_file(filename,ios::app);
w_centre_file << AxisymFvKParameters::Pressure << " "
<< mesh_pt()->node_pt(0)->value(0) << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions demo_drivers/axisym_foeppl_von_karman/axisym_fvk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ void AxisymFvKProblem<ELEMENT>::doc_solution()

// Output solution with specified number of plot points per element
char filename[100];
sprintf(filename, "%s/sol_%i.dat",
snprintf(filename, sizeof(filename), "%s/sol_%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream solution_file(filename,ios::app);
mesh_pt()->output(solution_file,npts);
solution_file.close();


// Output exact solution
sprintf(filename, "%s/exact_sol_%i.dat",
snprintf(filename, sizeof(filename), "%s/exact_sol_%i.dat",
AxisymFvKParameters::Directory.c_str(),Doc_info.number());
ofstream exact_file(filename,ios::app);
mesh_pt()->output_fct(exact_file,npts,AxisymFvKParameters::get_exact_u);
exact_file.close();


// Output solution at the centre (r=0) as function of the pressure
sprintf(filename, "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
snprintf(filename, sizeof(filename), "%s/w_centre.dat",AxisymFvKParameters::Directory.c_str());
ofstream w_centre_file(filename,ios::app);
w_centre_file << AxisymFvKParameters::Pressure << " "
<< mesh_pt()->node_pt(0)->value(0) << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions demo_drivers/axisym_linear_elasticity/cylinder/cylinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ AxisymmetricLinearElasticityProblem()

// for (unsigned it=0;it<ntime;it++)
// {
// sprintf(filename,"animation%i.dat",it);
// snprintf(filename, sizeof(filename), "animation%i.dat",it);
// Global_Parameters::Output_stream.open(filename);
// double t=(2*MathematicalConstants::Pi)*(double(it)/(ntime-1));
// std::cout << t << std::endl;
Expand Down Expand Up @@ -670,14 +670,14 @@ doc_solution(DocInfo& doc_info)
unsigned npts=10;

// Output solution
sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output(some_file,npts);
some_file.close();

// Output exact solution
sprintf(filename,"%s/exact_soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/exact_soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output_fct(some_file,npts,time_pt()->time(),
Expand All @@ -687,7 +687,7 @@ doc_solution(DocInfo& doc_info)
// Doc error
double error=0.0;
double norm=0.0;
sprintf(filename,"%s/error%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/error%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->compute_error(some_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void CapProblem<ELEMENT>::parameter_study(const string& dir_name)

// Open trace file
char filename[100];
sprintf(filename,"%s/trace.dat",doc_info.directory().c_str());
snprintf(filename, sizeof(filename), "%s/trace.dat",doc_info.directory().c_str());
Trace_file.open(filename);
Trace_file << "VARIABLES=\"<greek>a</greek><sub>prescribed</sub>\",";
Trace_file << "\"h<sub>left</sub>\",\"h<sub>right</sub>\",";
Expand Down Expand Up @@ -473,15 +473,15 @@ void CapProblem<ELEMENT>::doc_solution(DocInfo& doc_info)


//Output domain
sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output(some_file,npts);
Surface_mesh_pt->output(some_file,npts);
some_file.close();

//Output domain in paraview format
sprintf(filename,"%s/soln%i.vtu",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.vtu",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output_paraview(some_file,npts);
Expand Down Expand Up @@ -941,7 +941,7 @@ void PseudoSolidCapProblem<ELEMENT>::parameter_study(const string& dir_name)

// Open trace file
char filename[100];
sprintf(filename,"%s/trace.dat",doc_info.directory().c_str());
snprintf(filename, sizeof(filename), "%s/trace.dat",doc_info.directory().c_str());
Trace_file.open(filename);
Trace_file << "VARIABLES=\"<greek>a</greek><sub>prescribed</sub>\",";
Trace_file << "\"h<sub>left</sub>\",\"h<sub>right</sub>\",";
Expand Down Expand Up @@ -984,7 +984,7 @@ void PseudoSolidCapProblem<ELEMENT>::doc_solution(DocInfo& doc_info)
unsigned npts=5;

//Output domain
sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
snprintf(filename, sizeof(filename), "%s/soln%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
Bulk_mesh_pt->output(some_file,npts);
Expand Down
Loading

0 comments on commit 40d23aa

Please sign in to comment.