Skip to content

Commit

Permalink
ENH: Add command line processing in the generated dde_solver demo pro…
Browse files Browse the repository at this point in the history
…gram.

abserr, relerr, stoptime and the parameter values may be given
as command line arguments to the demo program.

[test dde_solver]
  • Loading branch information
WarrenWeckesser committed Sep 28, 2024
1 parent 0418726 commit 2503e33
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/vf_dde_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ void VectorField::PrintDDE_SOLVER(map<string,string> options)
Declare(fout, "", "double precision ::", conname_list, "");
}
fout << endl;
fout << "character(len=100) :: name_arg\n";
fout << "character(len=100) :: value_arg\n";
fout << "integer :: readstatus\n";
fout << "double precision :: value\n";
fout << endl;

if (HasPi) {
fout << "Pi = 3.1415926535897932385D0\n";
Expand All @@ -367,6 +372,50 @@ void VectorField::PrintDDE_SOLVER(map<string,string> options)
fout << "relerr = 1D-7\n";
fout << "abserr = 1D-9\n";
fout << "stoptime = 10.0\n";
fout << endl;
fout << "! - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
fout << "! Handle command line arguments.\n";
fout << "! abserr, relerr, stoptime, and the parameter values\n";
fout << "! may be given on the command line.\n";
fout << "! - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
fout << "i = 1\n";
fout << "do\n";
fout << " call get_command_argument(i, name_arg)\n";
fout << " if (len(trim(name_arg)) == 0) then\n";
fout << " exit\n";
fout << " end if\n";
fout << " i = i + 1\n";
fout << " call get_command_argument(i, value_arg)\n";
fout << " if (len(trim(value_arg)) == 0) then\n";
fout << " write(*, *) \"ERROR: Missing command line value for \", name_arg\n";
fout << " stop -1\n";
fout << " end if\n";
fout << " i = i + 1\n";
fout << " read(value_arg, *, iostat=readstatus) value\n";
fout << " if (readstatus .ne. 0) then\n";
fout << " write(*, *) \"ERROR: Unable to read the numerical value given for parameter \", name_arg\n";
fout << " write(*, *) \" The value given was \", value_arg\n";
fout << " stop -1\n";
fout << " end if\n";
fout << " if (name_arg .eq. \"abserr\") then\n";
fout << " abserr = value\n";
fout << " else if (name_arg .eq. \"relerr\") then\n";
fout << " relerr = value\n";
fout << " else if (name_arg .eq. \"stoptime\") then\n";
fout << " stoptime = value\n";
for (unsigned k = 0; k < parname_list.nops(); ++k) {
fout << " else if (name_arg .eq. \"" << parname_list[k] << "\") then\n";
fout << " " << parname_list[k] << " = value\n";
}
fout << " else\n";
fout << " write(*, *) \"ERROR: Unknown parameter given on the command line: \", name_arg\n";
fout << " stop -1\n";
fout << " end if\n";
fout << "end do\n";
fout << "! - - - - - - - - - - - - - - - - - - - - - - - -\n";
fout << "! Finished handling command line arguments.\n";
fout << "! - - - - - - - - - - - - - - - - - - - - - - - -\n";
fout << endl;
for (unsigned k = 0; k < parname_list.nops(); ++k) {
fout << "p_(" << k+1 << ") = " << parname_list[k] << "\n";
}
Expand Down

0 comments on commit 2503e33

Please sign in to comment.