0

I am NOT looking for an answer to this problem. I am having trouble understanding what I should be trying to accomplish in this assignment. I welcome Pseudo code or hints if you would like. but what I really need is an explanation to what I need to be making, and what the output should be/look like. please do not write out a lot of code though I would like to try that on my own.

(()) = notes from me

The assignment is:

a program (prog.exe) ((we are given this program)) that reads 2 integers (m, n) and 1 double (a) from an input data file named input.in. For example, the sample input.in given file contains the values

5 7 1.23456789012345

when you run ./prog.exe the output is a long column of floating-point numbers

in additions to the program, there is a file called ain.in that contains a long column of double precision values.

copy prog.exe and ain.in to working directory

Write a bash script that does that following:

-Runs ./prog.exe for all combonations of

--m=0,1,...,10

--n=0,1,...,5

--a=every value in the file ain.in

-this is essentially a triple nested loop over m,n and the ain.in values

-for each combination of m,n and ain.in value above:

-- generate the appropriate input file input.in

-- run the program and redirect the output to some temporary output file.

--extract the 37th and 51st values from this temporary output file and store these in a file called average.in

-when the 3 nested loops terminate the average.in file should contain a long list of floating point values.

-your script should return the average of the values contained in average.in

HINTS: seq , awk , output direction, will be useful here


thank you to whoever took the time to even read through this. This is my second bash coding assignment and im still trying to get a grasp on it and a better explanation would be very helpful. thanks again!

3 Answers3

2

this is one way of generating all input combinations without explicit loops

join -j9 <(join -j9 <(seq 0 10) <(seq 0 5)) ain.in | cut -d' ' -f2-
karakfa
  • 66,216
  • 7
  • 41
  • 56
0

The idea is to write a bash script that will test prog.exe with a variety of input conditions. This means recreating input.in and running prog.exe many times. Each time you run prog.exe, input.in should contain a different three numbers, e.g.,

First run:

0 0 <first line of ain.in>

Second run:

0 0 <second line of ain.in>

. . . last run:

10 5 <last line of ain.in>

You can use seq and for loops to accomplish this.

Then, you need to systematically save the output of each run, e.g.,

./prog.exe > tmp.out
# extract line 37 and 51 and append to average.ln
sed -n '37p; 51p; 51q' tmp.out >> average.ln

Finally, after testing all the combinations, use awk to compute the average of all the lines in average.in.

Community
  • 1
  • 1
webb
  • 4,180
  • 1
  • 17
  • 26
0

One-liner inspired by @karakfa:

join -j9 <(join -j9 <(seq 0 10) <(seq 0 5)) ain.in | cut -d' ' -f2- |
    sed "s/.*/echo & >input.in;./prog.exe>tmp.out; sed -n '37p;51p;51q' tmp.out/" |
    sh | awk '{sum+=$1; n++} END {print sum/n}'
webb
  • 4,180
  • 1
  • 17
  • 26