Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message"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 hav
e
> a shell script that has to run a series of programs in sequence, but one o
f
> them uses mpi and there is a lengthy initialization each time it is run, s
o
> it would be quicker to only run this program once but call all of the othe
r
> 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.
Post Follow-up to this messageMartin White wrote: > Hi, > > Is there a way to call shell commands from within fortran? I currently hav e > a shell script that has to run a series of programs in sequence, but one o f > them uses mpi and there is a lengthy initialization each time it is run, s o > it would be quicker to only run this program once but call all of the othe r > 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
Post Follow-up to this messageHi,
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
of
so
other
shell
be
>
> 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.
Post Follow-up to this message"Martin White" <mjw63@cam.ac.uk> wrote in message news:<Wde3d.48$ka1.21@newsfe6-win.ntli.ne t>... > 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.