How to run fortran77 program with inputs from file?

I run fortran77 program in terminal


and the program ask for input and output file. What should I write to terminal when I have the names of input and output files in a file – in two columns? I would like to run the program for all rows in the file with names.

Or – how to run a program with input information like parameters?

Or how to write the name of file direct in script? Instead of

READ(+,'(A)') OUT
Asked By: Arrara


If you are lucky then maybe

<infile ./program  >outfile

will work. Redirection to give a filedescriptor. Options/arguments???

While we earthlings write something like…

$ <77in cat >77.out
$ cat 77in >77.out

(This copies just 77in to 77.out)

…this Fortran77 program/command wanted it’s operands linewise in one input file/stream:

$  < cat

Now if cat was something else it would parse first line as input file (containing “hellonworld” eg.) and the second as file to create.

And that is just the newer, easy way it seems…

Instead of a long argument list like cp -a dir1 dir2 dest it is <in_list cpa77.

But then you need an additional file…just like modern cpio does:

<filelist cpio -o >files.cpio. Of course cpio just needs STDIN linewise:

find . | cpio -o >files.cpio

(cpio has this special call syntax because of its functioning, working with many files. It is one command and a half. Same for tar, in a different way)

If anything is typical of unix, then it is this flexibility in feeding control and data to commands in the shell. As I commented: good Q after all! (Thx to accepted answer!)

Answered By: user373503

I made the following program file prog.f

       program test

       character IN*30,OUT*30,line*80

       PRINT *,'Input file '
       READ(*,'(A)') IN
       PRINT *,'Output file?'
       READ(*,'(A)') OUT

       read (1,'(a80)') line
       write (2,*) "I read ", line

compiled & linked it with

gfortran prog.f -o prog

I put a text string into an input file

echo "Hello World" > in

Then I sent the names of the input file in and output file out to the program

$ <<< 'in
out' ./prog
 Input file 
 Output file?

and checked the output file

$ cat out
 I read Hello World                                                                     

<<< works in bash. You may prefer piping from echo which is more portable,

$ rm out
rm: remove normal file 'out'? y

$ echo 'in
out' | ./prog
 Input file 
 Output file?
$ cat out
 I read Hello World                                                                     
Answered By: sudodus
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.