Home > Archive > Fortran > September 2004 > Re: Running shell commands in a fortran program
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Running shell commands in a fortran program
|
|
| Martin White 2004-09-18, 8:56 am |
| Hi,
Is there a way to call shell commands from within fortran? I currently have
a shell script that has to run a series of programs in sequence, but one of
them uses mpi and there is a lengthy initialization each time it is run, so
it would be quicker to only run this program once but call all of the other
programs from within the fortran program. This would require calling shell
commands from within fortran though- I vaguely remember that this might be
possible, but can't remember how it is done!
Thanks for your help,
Martin
| |
| beliavsky@aol.com 2004-09-18, 3:58 pm |
| "Martin White" <mjw63@cam.ac.uk> wrote in message news:<STU2d.670$%g5.541@newsfe5-gui.ntli.net>...
> Hi,
>
> Is there a way to call shell commands from within fortran? I currently have
> a shell script that has to run a series of programs in sequence, but one of
> them uses mpi and there is a lengthy initialization each time it is run, so
> it would be quicker to only run this program once but call all of the other
> programs from within the fortran program. This would require calling shell
> commands from within fortran though- I vaguely remember that this might be
> possible, but can't remember how it is done!
There is no standard way, but most compilers have this functionality,
usually through a procedure called 'system' or something similar
('systemqq' for Compaq Visual Fortran on Windows) -- consult your
documentation. To get a more detailed answer, please specify your
compiler and operating system.
| |
| kamaraju kusumanchi 2004-09-18, 8:56 pm |
| Martin White wrote:
> Hi,
>
> Is there a way to call shell commands from within fortran? I currently have
> a shell script that has to run a series of programs in sequence, but one of
> them uses mpi and there is a lengthy initialization each time it is run, so
> it would be quicker to only run this program once but call all of the other
> programs from within the fortran program. This would require calling shell
> commands from within fortran though- I vaguely remember that this might be
> possible, but can't remember how it is done!
>
> Thanks for your help,
>
> Martin
There are two possibilities. From your problem description, it sounds
like it could be accomplished in the makefile. If I got it wrong then
you can use the system command. Works with intel compilers atleast.
program callsystem
implicit none
!to examine the behaviour of the system command
character (len=100)::cmd
cmd="echo Wake up Neo"
!if u are using ifc compiler use -Vaxlib during compilation
call system(cmd//achar(0))
end program callsystem
$ifc -Vaxlib system.f90
program CALLSYSTEM
8 Lines Compiled
$./a.out
Wake up Neo
$ifc -V
Intel(R) Fortran Compiler for 32-bit applications, Version 7.1 Build
20040309Z
Copyright (C) 1985-2004 Intel Corporation. All rights reserved.
FOR NON-COMMERCIAL USE ONLY
GNU ld version 2.15
Supported emulations:
elf_i386
i386linux
elf_x86_64
/usr/lib/crt1.o(.text+0x18): In function `_start':
.../sysdeps/i386/elf/start.S:98: undefined reference to `main'
hth
raju
| |
| Martin White 2004-09-19, 9:01 am |
| Hi,
Thank you both for your replies. I'm using a Sun machine running Solaris 9
(I think!). The compiler is the standard Sun one, but I know little more
than that. I'll give your suggestions a try and see if there is an
equivalent of the system command.
Cheers,
Martin
<beliavsky@aol.com> wrote in message
news:3064b51d.0409181026.a476c48@posting.google.com...
> "Martin White" <mjw63@cam.ac.uk> wrote in message
news:<STU2d.670$%g5.541@newsfe5-gui.ntli.net>...
have[color=darkred]
of[color=darkred]
so[color=darkred]
other[color=darkred]
shell[color=darkred]
be[color=darkred]
>
> There is no standard way, but most compilers have this functionality,
> usually through a procedure called 'system' or something similar
> ('systemqq' for Compaq Visual Fortran on Windows) -- consult your
> documentation. To get a more detailed answer, please specify your
> compiler and operating system.
| |
| Robert Corbett 2004-09-20, 4:01 am |
| "Martin White" <mjw63@cam.ac.uk> wrote in message news:<Wde3d.48$ka1.21@newsfe6-win.ntli.net>...
> Hi,
>
> Thank you both for your replies. I'm using a Sun machine running Solaris 9
> (I think!). The compiler is the standard Sun one, but I know little more
> than that. I'll give your suggestions a try and see if there is an
> equivalent of the system command.
Sun f95 provides SYSTEM, but for most uses, SH is the better choice.
Sincerely,
Bob Corbett
|
|
|
|
|