How to answer interactive prompt that includes multiple answers per line - list

Dear Stack Overflow community,
I am having trouble with a FORTRAN executable ("build" from Perple_X_6.8.5 in case anybody knows that) that requires input via prompts which I have to automate. For the prompts that only require one line as an answer I found the following solution:
./build << EOF
test `# Problem name deifnition`
hp02ver.dat `# Declaration of the data base to be used`
perplex_option.dat `# Declaration of the computational option file (default)`
N `# Tranform the data base components? (No)`
N `# Saturated fluids? (No)`
N `# Saturated components? (No)`
N `# chem. pot., activities, fugacities indipendet? (No)`
EOF
However, the next prompt gives me a list of components from which I have to chose:
Select thermodynamic components from the set:
NA2O MGO AL2O3 SIO2 K2O CAO TIO2 MNO FEO O2 H2O CO2
Enter names, 1 per line, press <enter> to finish:
That is where the problem arises. How would I, following my initial solution for "simple" prompts, answer this prompt that requires one component per line a an "enter" in order to jump to the next prompt?
I tried the following:
./build << EOF
test `# Problem name deifnition`
hp02ver.dat `# Declaration of the data base to be used`
perplex_option.dat `# Declaration of the computational option file (default)`
N `# Tranform the data base components? (No)`
N `# Saturated fluids? (No)`
N `# Saturated components? (No)`
N `# chem. pot., activities, fugacities indipendet? (No)`
SIO2 `# List of components`
TIO2
AL2O3
FEO
MNO
MGO
CAO
NA2O
K2O
H2O
EOF
which returned this error:
Fortran runtime error: Sequential READ or WRITE not allowed after EOF marker, possibly use REWIND or BACKSPACE
Please note that this is not the last prompt in the whole chain of prompts. More "simple" and more "list" prompts follow suit.

(First posted as a comment, but others think it is the answer)
The program asks for Enter names, 1 per line, press <enter> to finish.
Each line is finished with an <enter>, so here the program wants an additional <enter>.
Insert an empty line after the last thermodynamic component (before EOF or other input).

Related

gdb run program in a loop until a breakpoint is reached then display stacktrace

I am trying to debug a very sporadic issue in my application. If ran ~1000 times my application surely hits a certain line it shouldn't and I would like to view the stack.
I tried using a gdb script cmd.gdb for this:
set logging overwrite on
set pagination off
set $n = 1000
break file.c:496
while $n-- > 0
ignore 1 9
condition 1 global_var == 10
run
end
How should I modify this script in order to print the stack when the breakpoint is reached?
I tried adding this after "run":
if $_siginfo
bt
loop_break
end
but it doesn't seem to work.
Actually, I have a Github repo with a Python-GDB extension, which does exactly the same thing as You have described, but with some more functionality.
You can just clone the repo:
git clone https://github.com/Viaceslavus/gdb-debug-until.git
and feed the python script to GDB with the following command inside GDB:
source <python script path>
Then, according to your example, you should run the next command:
debug-until file.c:496 --args="" --var-eq="global_var:10" -r=1000
*some remarks:
file.c:496 here is a starting breakpoint
"--args" parameter contains the arguments for your program
"--var-eq" is a debugging event, where 'global_var' is a variable name and '10' is a value
and finally the "-r" option specifies the number of times the program will be ran.
So all together this command will run your program 1000 times and will immediately notify You when the 'global_var' will be equal to 10.
Any additional information about the project could be found here:
https://github.com/Viaceslavus/gdb-debug-until.git in the README file.

How to define tolerance level in CBC solver using pyomo's solverfactory?

I am trying to solve a MIP with CBC using pyomo's solver factory, however running into some infeasibility issues. I wanted to first try configuring the tolerance level and see if that works before diving deep into the data points that could cause the infeasibility.
However when I use this command, the cbc solver outputs an error:
options = {
'tol': 0.0001
}
solver = SolverFactory(solver_type)
solver.options.update(options)
Can anyone help me with the understanding how to define tolerance level in cbc? Thanks!
So, it depends a bit. Assuming you are looking for the tolerance for a mixed integer program, the keyword for CBC is 'ratio'.
Here is a setup that runs 6 threads, max 20 seconds, ratio of 0.02 (2% gap)
### SOLVE
solver = pyo.SolverFactory('cbc')
solver.options = {'sec': 20, 'threads': 6, 'ratio': 0.02}
results = solver.solve(mdl)
print(results)
There are several different types of syntax that are acceptable here... You can pass the options in to the SolverFactory, etc... but this works fine for me.
As another trick, I always get hung up on the correct keywords for these solvers.... If you have CBC installed properly, you can just go to the terminal, open CBC with the command cbc, which should give you the 'coin' prompt and type "?" to see the commands. Then you can use the command and double '??' to get details. This also works for glpk which is super helpful.
For instance:
% cbc
Welcome to the CBC MILP Solver
Version: 2.10.5
Build Date: Dec 5 2021
CoinSolver takes input from arguments ( - switches to stdin)
Enter ? for list of commands or help
Coin:?
In argument list keywords have leading - , -stdin or just - switches to stdin
One command per line (and no -)
abcd? gives list of possibilities, if only one + explanation
abcd?? adds explanation, if only one fuller help
abcd without value (where expected) gives current value
abcd value sets value
Commands are:
Double parameters:
dualB(ound) dualT(olerance) primalT(olerance) primalW(eight) psi
zeroT(olerance)
Branch and Cut double parameters:
allow(ableGap) cuto(ff) inc(rement) integerT(olerance) preT(olerance)
pumpC(utoff) ratio(Gap) sec(onds)
Integer parameters:
force(Solution) idiot(Crash) maxF(actor) maxIt(erations) output(Format)
randomS(eed) slog(Level) sprint(Crash)
Branch and Cut integer parameters:
cutD(epth) cutL(ength) depth(MiniBab) hot(StartMaxIts) log(Level) maxN(odes)
maxSaved(Solutions) maxSo(lutions) passC(uts) passF(easibilityPump)
passT(reeCuts) pumpT(une) randomC(bcSeed) slow(cutpasses) strat(egy)
strong(Branching) trust(PseudoCosts)
Keyword parameters:
allC(ommands) chol(esky) crash cross(over) direction error(sAllowed)
fact(orization) keepN(ames) mess(ages) perturb(ation) presolve
printi(ngOptions) scal(ing) timeM(ode)

Trouble with visualizer.pl

I'm trying to use visualizer.pl to visualize the dynamics of multi-state system
my function file:
f1 := x2
f2 := x1+x2*x3
f3 := x3^2+x1+x2+1
I used the following command as mentioned in "readme.txt" 
perl visualizer.pl -p 1.txt 3 3
since prime := 3 and num_nodes :=3
but I got this error
educ#educ-VirtualBox:~/Desktop/visualizer$ perl visualizer.pl -p 1.txt 3 3
Errors found in the input file. See below for description:
ERROR: Incorrect start of function declaration in function 1.
Errors with input file..ending program at visualizer.pl line 162, > line 1.
State Space Visualizer
Version 1.0 beta
-------------------------------------
The State Space Visualizer is a tool for the visualization of the dynamics of multi-state, discrete models of biological networks.
More information about package:
https://web.archive.org/web/20110815084457/http://dvd.vbi.vt.edu/tutorial.html
https://web.archive.org/web/20120320172453if_/http://dvd.vbi.vt.edu/visualizer.zip
Use = to separate your functions, and remove spaces around the =. Your input file should thus be:
f1=x2
f2=x1+x2*x3
f3=x3^2+x1+x2+1
I know that it's not consistent with the readme, but it's consistent with the content of visualizer.pl, and it works.
If, once that's done, the script visualizer.pl fails with:
sh: 1: kghostview: not found
You can fix it by installing ghostview (sudo apt install gv on Debian), and replacing the line system("kghostview out.ps &"); by system("gv out.ps &"); at the end of visualizer.pl.

C++ SunOS ofstream error

Folks,
we collect large amounts of data and create error, status, info log files to let us know what's
going on. We use ofstreams to write to these files. After some period of time (days), we get a
file error (indicated by .good() call) on one of the ofstreams. In the affected log file, it
appears that the write of a single line begins but is interrupted by a write of the exact same
line. For example,
### Random Line of Text 1 ###
### Random Line of Text 2 ###
### Random Line of Text 3### Random Line of Text 3 ###
Each file/ofstream has a single thread that does the actual writing. We don't flush for performance
reasons and shouldn't have to.
Its always the same type of error.
It does only happen on one of three machines running the same code but we don't see any I/O errors
but maybe not looking in the right place.
Thanks for you time.

Pre-assign parameter in script

Actually I have trouble naming the title of this post. Because I don't know how to summarize my meaning in a professional way. But I'll explain my question as below:
I'm running a program written by C++, command is:
./VariationHunter_SC
Then it'll let you type in many parameters:
Please enter the minimum paired-end insert size:
Please enter the maximum paired-end insert size:
Please enter the pre-processing mapping prune probability:
Please enter the name of the input file:
Please enter the minimum support for a cluster:
Obviously I need to type in such parameters one by one to run the program; But I have thousands of such jobs, and need to pre-assign such parameters in script, and submit script to computer.
So how can I do that?
thx
Edit
so how can I make parameter-list?
Just like below?:
140
160
0
mrfast.vh
1
Seems the program cannot recognize these numbers, and distribute numbers..
This depends on how the program actually reads the data that you type in - it's likely that its reading stdin, so you could use separate files with the parameters and pass them in via redirection: ./VariationHunter_SC < parameter-file
It's also possible that the program will accept parameters on the command line, but there's no way of really knowing that (or how) except by whatever documentation the program might come with (or by reading the source code, if it's available and there is no other accurate docs).
Simply use the piping character to pipe the contents of a file to your program
example, in a windows command shell:
echo "asdf" | pause
This will pass "asdf" to the pause program. As a result, pause will print a "Press any key to continue" message, then imediately continue because it will receive the "asdf" string as a response.
So, overall, write or use a program that outputs the contents of your file. Call it, then pipe its output to the program that needs the input.
The unix cat command is such a command that writes the contents of a file to output, or to the input of another executable if you are piping the output.