LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-26-2006, 12:35 AM   #1
swerdna
Member
 
Registered: Jun 2006
Location: Oz
Distribution: openSUSE 10.x
Posts: 80

Rep: Reputation: 16
How to issue system call from running fortran program


Hi, I'm using gfortran 4.1 on Suse 10.1 to compile/run a fortran 90/95 program. The program loops iteratively towards the solution to a model. I need to display graphs at each iteration to make sure it's not calculating junk. I figure I can display these if the program can issue a sytem call to invoke one of the plotting apps that come with Suse (e.g. gnuplot, xmgrace). Google tells me to use the fortran intrinsic "system(command)" where "command" is a character variable containing the desired command.

My problem is that gfortran doesn't recognise "call system(command)" as a valid statement.

Here's the extracted lines of code:
Code:
character :: command
command = "xmgrace data/reconstituted.out"
call system(command)
and here's the compile-time dialogue showing the rejection of the code
Code:
john@suse101:~/Desktop/model> gfortran -std=gnu -W -Wall -pedantic model.f90
 In file model.f90:97

call system(command)
                   1
Warning: Intrinsic 'system' at (1) is not included in the selected standard
john@suse101:~/Desktop/model>
If I change the standard from gnu to f95 I still get a rejection as follows:
Code:
john@suse101:~/Desktop/model> gfortran -std=f95 -W -Wall -pedantic model.f90
/tmp/ccIk3JRP.o: In function `MAIN__':
model.f90:(.text+0xebc): undefined reference to `system_'
collect2: ld returned 1 exit status
I believe that "system(command)" used to work in fortran77, but I'm not keen to go back to that to get system calls.

Any advice on what I'm doing wrong, or on alternate methods to invoke graphics, would be much appreciated.

Thanks
Swerdna
 
Old 12-26-2006, 08:51 AM   #2
swerdna
Member
 
Registered: Jun 2006
Location: Oz
Distribution: openSUSE 10.x
Posts: 80

Original Poster
Rep: Reputation: 16
Hi folks, I got it solved:
Code:
john@suse101:~/Desktop/model> gfortran -std=f95 -W -Wall -pedantic model.f90
is no good because std=f95 forces compliance with f95, but calling "system" isn't supported [or just won't work for me] via the gfortran/f95 variant.

On the other hand using -std=gnu instead of -std=f95 does allow calling "system" because it was recently implemented in gfortran [and so you'll need ver 4.1+ of gfortran]. But you'll still get the warning message because of including "-pedantic" in the options. Despite this warning the executable works fine.

Thanks
Swerdna
 
Old 12-26-2006, 09:42 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
If the code that uses this non-standard feature can be isolated, it is my understanding that code compiled to different standards can still be linked into the same executable... you are still using the same compiler.

In other words, if the standards-level "matters" to your code, I believe that you can spin-off those routines into separate compile-units so that the majority of the code is enforced to the higher standard. If that matters to your project.
 
Old 12-27-2006, 07:44 AM   #4
swerdna
Member
 
Registered: Jun 2006
Location: Oz
Distribution: openSUSE 10.x
Posts: 80

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by sundialsvcs
If the code that uses this non-standard feature can be isolated, it is my understanding that code compiled to different standards can still be linked into the same executable... you are still using the same compiler.

In other words, if the standards-level "matters" to your code, I believe that you can spin-off those routines into separate compile-units so that the majority of the code is enforced to the higher standard. If that matters to your project.
Thanks Sundialsvcs. It makes sense to separate the system-calls part of the work because that's tied up with a plotting package and is really a separate utility to generate plots from within programs generally. So I can and I will relocate that as a general-purpose utility.
Cheers
Swerdna
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use "mail" program from System() call in C? minhsangniit Programming 2 08-19-2006 12:08 AM
Gnome System Tray Show Program Running in Memory help nedson Linux - Newbie 1 04-20-2006 08:21 PM
how to call C function in FORTRAN program bigapple Programming 5 08-24-2005 12:30 AM
C++: running system() without stopping program kamel Programming 3 05-31-2004 04:42 PM
Running a Fortran program after make on Red Hat 9 evo Linux - Software 3 06-30-2003 01:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration