Calling an interactive FORTRAN program 
Author Message
 Calling an interactive FORTRAN program

Hi,

I'm in the process of writing a perl script in which I need to run a fortran
program to do some number crunching.
Unfortunately, the FORTRAN program (which I cannot change) was written to be
run interactively, and hence requires input from STDIN, rather than from the
command line, which is proving to be a problem when trying to run it from
perl.

I have succeeded in running the program via the following (not very
satisfactory) method:

  system <<'EndOfShellScript';
  name_of_fortran_program <<EOF
  datafile.dat
  /scratch/Directory1/
  23
  EOF
  EndOfShellScript

My problem now, however, lies in that the input passed to
"name_of_fortran_program" above is stored in variables provided at run-time by
another part of the perl script.

So, I would like to write something like

  $data = 'datafile.dat';
  $dir  = '/scratch/Directory1/';
  $num  = 23;

  system <<'EndOfShellScript';
  name_of_fortran_program <<EOF
  $data
  $dir
  $num
  EOF
  EndOfShellScript

which, of course, is not correct.

Can anyone suggest how to pass variables to an external program via a system
call, or alternatively, a better way to call the FORTRAN program in the first
place ?

Any assistance would be greatly appreciated.
Cheers,

Nuria.
-------------------------------



Tue, 11 Jan 2000 03:00:00 GMT  
 Calling an interactive FORTRAN program

Quote:

> So, I would like to write something like

>   $data = 'datafile.dat';
>   $dir  = '/scratch/Directory1/';
>   $num  = 23;

>   system <<'EndOfShellScript';
>   name_of_fortran_program <<EOF
>   $data
>   $dir
>   $num
>   EOF
>   EndOfShellScript

You want to either use "" around the EndOfShellScript delimiter, or
the more perlish solution:

        open(PIPE,"|name_of_fortran_program")||die($!);
        print PIPE $data, "\n";
        print PIPE $dir, "\n";
        print PIPE $num, "\n";
        close PIPE;

Error-checking can happen on the close and the prints.

                        -AJS



Tue, 11 Jan 2000 03:00:00 GMT  
 Calling an interactive FORTRAN program


Quote:

>   $data = 'datafile.dat';
>   $dir  = '/scratch/Directory1/';
>   $num  = 23;

>   system <<'EndOfShellScript';
>   name_of_fortran_program <<EOF
>   $data
>   $dir
>   $num
>   EOF
>   EndOfShellScript

> which, of course, is not correct.

Just replace single quotes in your outermost here-doc tag with
doublequotes, like so:

$data = 'datafile.dat';
$dir  = '/scratch/Directory1/';
$num  = 23;

#Note the DOUBLE quotes around EndOfShellScript in the next line
system <<"EndOfShellScript";
name_of_fortran_program <<EOF
$data
$dir
$num
EOF
EndOfShellScript

This will cause Perl to do the appropriate variable interpolations
before sending it to the shell.  Look up 'here document' in the index
of the Camel book for more details.

Hope this helps!
--------

As of 29 Jul 1997, only 885 days until Y2K....
Any person with a phone line can become a town crier with a voice
that resonates farther than it could from any soapbox.
--The US Supreme Court, overturning the Communications Decency Act



Sun, 16 Jan 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Perl call from Fortran possible?

2. Running a Fortran program using Perl

3. how to compile a fortran program from web page

4. how to call one program through another program and capture the out put of another program

5. Perl or shell for interactive questioning program?

6. passing argvs to interactive program (perl wrapper)

7. test for (non-)interactive program run

8. Apropos for Interactive Programs?

9. automatic feed of inputs to interactive program

10. Interactive program with command line history/vi mode--help needed

11. Interactive Programs and Perl

12. input to interactive programs

 

 
Powered by phpBB® Forum Software