0
#!/bin/bash
for tracelength in 50 100 150 200 250 300 350 400 450 500 ; do
    step=0.2
    short=0
    long=1
    for i in {1..4}; do
    ratio=0
        for j in {1..4}; do
                declare -a listofresults
                echo "$tracelength $short $long $ratio" >> results.csv
                python3 main.py "$tracelength" "$short" "$long" "$ratio">file.smt2
                chmod 775 file.smt2
                declare total=0
                declare m=0
                for repeat in {1..10}; do
                    executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat < file.smt2 2>&1 >/dev/null)
                    echo "$executiontime"
                    total=$(echo "scale=2; ($total) + ($executiontime)" | bc) #echo $(bc <<< "scale=2; $total/100")
                    echo "$total"
                    let "m=m+1"
                    echo "m=$m"
                done
                echo $(bc <<< "scale=2; ($total)/10") >> results.csv
                ratio=$(echo "scale=10; ($ratio) + ($step)" | bc) #float points arithmetics are different
            done
            short=$(echo "scale=10; ($short) + ($step)" | bc)
            long=$(echo "scale=10; ($long) - ($step)" | bc)
        done
    done

I am basically just running an experiment where I run a file with variant inputs. The code works for some values and for some it just gives me:

(standard_in) 1: parse error

In my results file this is the output I have:

50 0 1 0
21.82
50 0 1 .2
27.08
50 0 1 .4
40.89
50 0 1 .6

The experiment I am running always stops at the same input values(the last one printed in the output file) and then from there it's all parser errors! why does it do that? and how do I fixe it? I have tried multiple solution I found for similar questions(related to bc) here but none worked.

Patrick Trentin
  • 7,126
  • 3
  • 23
  • 40
basel117
  • 189
  • 1
  • 10
  • So which values does it fail for and what's the input to `bc` in those cases? – that other guy Apr 28 '19 at 19:12
  • it's there! the last value in the input file: 50 0 1 0.6 it produces parser error and from there it's all parser errors – basel117 Apr 28 '19 at 19:23
  • I meant to say *output file – basel117 Apr 28 '19 at 20:14
  • I'm not sure I understand. You have five commands like `echo "something" | bc` and of course they work by building and expression and passing it to `bc`. Can you find which particular line produces this error, and what the string you write to bc is? `bash -x yourscript` is one verbose way to find out – that other guy Apr 28 '19 at 21:26

1 Answers1

1

I suspect it's related to the following line:


executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat &1 >/dev/null)

When I change your code with

executiontime="ISSUE"

I get this as output (notice how I S S U E is being printed line by line)


m=3
ISSUE
(standard_in) 1: parse error (standard_in) 1: illegal character: I (standard_in) 1: illegal character: S (standard_in) 1: illegal character: S (standard_in) 1: illegal character: U
kalou.net
  • 446
  • 1
  • 4
  • 16
  • do you get the expected format at echo "$executiontime" ? – kalou.net Apr 28 '19 at 21:37
  • The following line must be corrected .. `executiontime=$(timeout 500 gtime -f "%U" /Users/ouafaelachhab/Desktop/SemanticLocality/optimathsat-1.6.2-macos-64-bit/bin/optimathsat < file.smt2 2>&1 >/dev/null)` as it roughtly equivalent to `executiontime=$(something 2>&1 > /dev/null)` – kalou.net Jul 18 '19 at 14:53
  • I don't understand what you mean? – basel117 Jul 20 '19 at 18:04
  • executiontime=$(something 2>&1 /dev/null) will always give executiontime="" ... as stderr (file descriptor 2) and stdin (file descriptor 1) are bound together using "2>&1" and then their output is sent to /dev/null, which mean "discarded" by the kernel. – kalou.net Jul 21 '19 at 08:29