program pipe2 implicit none integer(kind=4), parameter :: arglen = 132 integer(kind=4), parameter :: ne = 0 integer(kind=4), parameter :: ni = 11 integer(kind=4), parameter :: no = 12 logical :: verbose = .FALSE. character(len=*), parameter :: name = 'pipe2' real(kind=8) :: a, b, c character(len=arglen) :: fi, fo, p integer(kind=4) :: iarg iarg = command_argument_count() if (iarg < 2) error stop "require 2 stream names" call get_command_argument(1, value=fi) call get_command_argument(2, value=fo) if (iarg == 3) then call get_command_argument(3, value=p) if (trim(p) == 'verbose') then verbose=.TRUE. else error stop "unknown parameter " // trim(p) endif endif if (iarg > 3) error stop "too many parameters" if (verbose) write (ne, *) "["//name//"] Reading from ", trim(fi) if (verbose) write (ne, *) "["//name//"] Writing to ", trim(fo) open(file=trim(fi), unit=ni, access="stream",form="unformatted") open(file=trim(fo), unit=no, access="stream",form="unformatted") do while (.True.) if (verbose) write (ne, *) "["//name//"] Waiting for input ... " read(ni) a, b if (verbose) write (ne, *) "["//name//"] Obtained ", a, b if ((a <= 0.d0) .and. (b <= 0.d0)) exit if (verbose) write (ne, *) "["//name//"] Computing result ... " c = a**b if (verbose) write (ne, *) "["//name//"] Result is ", c if (verbose) write (ne, *) "["//name//"] Sending result ... " write (no) a**b flush (no) if (verbose) write (ne, *) "["//name//"] Result sent." end do if (verbose) write (ne, *) "["//name//"] Exiting, closing files ... " close(ni) close(no) if (verbose) write (ne, *) "["//name//"] Done. " end program pipe2