LinuxQuestions.org
Help answer threads with 0 replies.
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 06-08-2012, 04:19 AM   #1
mushi_aph
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
Question Fortran alternative to Matlab 'system' command


Hi All,

I have been trying to run a linux executable (written in fortran77) into my another code (also in fortran77). In Matlab, I did it with "system('./<filename>')". But I am not able to do it in fortran script as './' is not simply working for me.

I will really appreciate if anyone could tell me what alternative command I can use to execute and executable file into fortran code. A quick response will be extremely helpful and highly appreacited.

Thanks in advance.

Mushi
 
Old 06-08-2012, 07:30 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
You may want to replace the ./ with an absolute path name and see whether that works for you.

If you're using GNU FORTRAN, the SYSTEM call is implemented
Code:
call system(command [, status])
status = system(command)
See the manual at http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gfortran.pdf, section 6.193 (page 142).

Hope this helps some.
 
Old 06-08-2012, 08:05 AM   #3
mushi_aph
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Question

Thanks tronayne for the help.

Actually I am bit new to Fortran and the comment you pasted is a bit confusing for me. Can you please elaborate more what those code lines mean? For emample, I want to run an executable called 'file1'. Where shall I put this file name? What does status mean?

I will be grateful for your help.
Thanks anyways.

Mushi
 
Old 06-08-2012, 08:16 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
command is what you want to execute, so in your case it is file1. status is the return code of the command, used to evaluate the execution.
 
Old 06-08-2012, 03:07 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I would add that system is not a good choice for portability due to the (slightly) different implementation in different compilers. For example Intel fortran doesn't accept the call system variation and some compilers act differently on windows and Linux machines, since some windows libraries inherited the DEC's systemqq call. Not to mention the system function is not part of the Fortran standard.

On the other hand, the Fortran 2008 introduces the subroutine execute_command_line and it is the statement advised for future compatibility. Example:
Code:
PROGRAM test_system_call
  IMPLICIT NONE
  INTEGER :: status
  CALL execute_command_line('file1', exitstat = status)
  WRITE(*,*) 'exit status of the command is', status
END PROGRAM test_system_call
This code assumes that the operating system is aware of the file1 command, that is it resides in one of the directories listed in the PATH environment variable. On the contrary, put the full path, as previously suggested:
Code:
  CALL execute_command_line('/path/to/file1', exitstat = status)
Nevertheless, the Fortran 2008 standard is not fully accepted by all the fortran compilers, therefore we have to wait some more time before they align.

Instead, my suggestion is to recompile the source code of file1 after having transformed it in a fortran MODULE containing FUNCTIONS and/or SUBROUTINES. In this way, the calling program can use it and its functions by means of a USE statement at the beginning of your code and nothing else. For example, suppose you have a MODULE named my_utilities and a FUNCTION inside it named file_one; the calling program will be:
Code:
PROGRAM test_module
  USE my_utilities
  IMPLICIT NONE
  INTEGER :: result
  result = file_one(list of arguments)
  WRITE(*,*) result
END PROGRAM test_module
This topic is too far extensive to be covered here, but if you follow a good Fortran reference, MODULES are the way to go (and the chapter to read). Just my

Last edited by colucix; 06-08-2012 at 03:10 PM. Reason: typo
 
  


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
[SOLVED] Installed MATLAB in /home/c/Desktop/MATLAB But Cannot ACCESS it hitmen Linux - Newbie 10 09-25-2011 12:11 PM
system call to know the files and directories in pwd ( alternative to ls command ) vlrk Linux - Newbie 1 03-03-2010 06:30 PM
alternative for MATLAB in Linux mansoor323 Linux - Software 3 02-15-2010 07:47 AM
Matlab Distributed Computing Server: Connecting to Matlab client fails OEP Linux - Server 0 12-21-2009 02:18 PM
linux intel fortran problem: ifort command does not execute terrence Programming 1 09-01-2005 09:03 PM

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

All times are GMT -5. The time now is 07:30 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