Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Running a software from a Fortran code

h_amini
Beginner
1,628 Views

Hi there

I need to run a software (TNO DIANA) as a subroutine in an iterative procedure of my Fortran program.

The company says it is not possible, but the software has a command box which can be linked to Visual Fortran Compiler. The software can be run from the command box and with a .bat file.

So I can write a run file and ask DIANA to do several analyses but I cannot interrupt it to let my Fortran program generate the required data file for the next run.

I am just wondering if there is any command in FORTRAN can be used for running a software or is there any program can be used for this purpose?

Regards

Hamid

0 Kudos
15 Replies
Ron_Green
Moderator
1,628 Views
I am not entirely sure what you are asking. If you want to run an external program from within a Fortran program, perhaps you need to read up on SYSTEM

use ifport

integer :: result

result = SYSTEM("c:Programsmyprog.exe")

for example.

Other than that, you will have to check with TNO DIANA or hope that someone else on the Forum is a Diana user and has done what you are looking to do.

ron
0 Kudos
h_amini
Beginner
1,628 Views
I am not entirely sure what you are asking. If you want to run an external program from within a Fortran program, perhaps you need to read up on SYSTEM

use ifport

integer :: result

result = SYSTEM("c:Programsmyprog.exe")

for example.

Other than that, you will have to check with TNO DIANA or hope that someone else on the Forum is a Diana user and has done what you are looking to do.

ron

Many thanks Ronald.

Is it possible to run a .bat file from my program? In fact running the bat file, runs DIANA, then performs an analysis.

Hamid

0 Kudos
bmchenry
New Contributor II
1,628 Views

You might also try looking at the Windows API routine "Createprocess"

3rd party interfaces for Fortran like Winteracter simplify the use of CreateProcess with simple commands like:
Call IOsExecute(CommandChar)
whereCommandChar is a Character string with whatever you wish to pass to the operating system.

brian
0 Kudos
Ron_Green
Moderator
1,628 Views
Quoting - h.amini

Many thanks Ronald.

Is it possible to run a .bat file from my program? In fact running the bat file, runs DIANA, then performs an analysis.

Hamid


sure, modify the example to:

result = SYSTEM("c:mydirmybatch.bat")

but keep in mind that there is no data sharing between the external .bat or program run by SYSTEM and the main program. So in this case, you'd need to run the Diana program as above, then perhaps use OPEN statements to open the results file and read everything into the program.
0 Kudos
h_amini
Beginner
1,628 Views

sure, modify the example to:

result = SYSTEM("c:mydirmybatch.bat")

When I try to run the bat file with

result = SYSTEM("D:testf1.bat")

the command in the bat file (diana file1.dat file1.com) is read and shown, but my program says diana' is not recognized as an internal or external command, operable program or batch file.

In fact, the bat file must be run in the command box of DIANA. But how can I do that from within my code?

0 Kudos
h_amini
Beginner
1,628 Views
Quoting - bmchenry

You might also try looking at the Windows API routine "Createprocess"

3rd party interfaces for Fortran like Winteracter simplify the use of CreateProcess with simple commands like:
Call IOsExecute(CommandChar)
whereCommandChar is a Character string with whatever you wish to pass to the operating system.

brian

Many thanks Brian.

I don't know anything about that you said. Can it be used to run the bat filewith the command box?

Hamid

0 Kudos
TimP
Honored Contributor III
1,628 Views
There are (expensive) commercial utitlies to capture Windows GUI box keyboard entries and re-run them from a script.
0 Kudos
Ron_Green
Moderator
1,628 Views
Quoting - h.amini

Many thanks Brian.

I don't know anything about that you said. Can it be used to run the bat filewith the command box?

Hamid


I think the answer is 'no'.

You are asking, can Fortran launch this 'command box' - probably yes. You would have to know the name of the program that launches the 'command box'. You could go to TNO and ask "How do I start the command box from a command line window?" and they could give you the command needed to start your command box.

BUT you cannot start this command box AND have the program put the name of the batch file in the text box and click OK or ENTER or whatnot.

The only possible way is if the command box program accepts the batch file name as an argument.

This you'll have to work out with TNO, but I guess they have already said this is impossible.

ron
0 Kudos
h_amini
Beginner
1,628 Views
Quoting - tim18
There are (expensive) commercial utitlies to capture Windows GUI box keyboard entries and re-run them from a script.

Can they work in conjunction with my code? How much are they roughly? How can I get them?

0 Kudos
bmchenry
New Contributor II
1,628 Views
I think there may be an easier solution.

1) create one program called RUNDIANA. What this program will do is to call DIANA using the SYSTEM command to call the BAT file which call DIANA with the options required and then close.

2)create your second, main progrm which has the main loop:
2a)delete anyBAT file,
2b)create a new BAT file with the options you want for calling DIANA
2c)save/close the BAT file,
2d)call the program RUNDIANA to execute DIANA.

OnceRUNDIANA exits and returns control to your second, main program, you have code toevaluate the output files from DIANA. Once that is completed, then simplyloops to 2a) above

The 3rd party vendors have system calls/interfaces which can assist you with this. but you'll need to check their documentation/contact them. winteracter.com is one i use.

brian
0 Kudos
h_amini
Beginner
1,628 Views
Quoting - bmchenry
1) create one program called RUNDIANA. What this program will do is to call DIANA using the SYSTEM command to call the BAT file which call DIANA with the options required and then close.

Appreciated very much Brian. But how can I do step 1)? I can probably create a program which calls the command box of DIANA. But, how the BAT file can be called?

What I do by hand is to write the name of the BAT file in the command box and press enter. I need to do it automatically inthe loop of my program.

Hamid

0 Kudos
anthonyrichards
New Contributor III
1,628 Views
Quoting - h.amini

When I try to run the bat file with

result = SYSTEM("D:testf1.bat")

the command in the bat file (diana file1.dat file1.com) is read and shown, but my program says diana' is not recognized as an internal or external command, operable program or batch file.

In fact, the bat file must be run in the command box of DIANA. But how can I do that from within my code?


The system wil interpret the command "diana file1.dat file1.com" as meaning "diana.EXE file1.dat file1.com" and will look for the program diane.exe in the local directory. If it cannot find it there, or if it cannot find it somewhere in the path held in the PATH environment variable, then you will get the message shown.

Clearly, the system does not know where to find diane.exe, so you must tell it where to find it, either by supplying the full path to diane e.g.

d:mypathtodianadiana.exe file1.dat file1.com

or by modifying PATH before you try and execute "diana file1.dat file1.com" as follows:

PATH=d:mypathtodiana;%PATH%
diana file1.dat file1.com
0 Kudos
h_amini
Beginner
1,628 Views
Quoting - anthonyrichards

The system wil interpret the command "diana file1.dat file1.com" as meaning "diana.EXE file1.dat file1.com" and will look for the program diane.exe in the local directory. If it cannot find it there, or if it cannot find it somewhere in the path held in the PATH environment variable, then you will get the message shown.

Clearly, the system does not know where to find diane.exe, so you must tell it where to find it, either by supplying the full path to diane e.g.

d:mypathtodianadiana.exe file1.dat file1.com

or by modifying PATH before you try and execute "diana file1.dat file1.com" as follows:

PATH=d:mypathtodiana;%PATH%
diana file1.dat file1.com

Appreciated very much for your comment.

I could not find the executable file of the command box, but as you said adding the following line to the BAT file could solve the problem.

PATH=C:Program FilesDiana 9.3bin;%PATH%

The next thing I need is to delete a file, e.g. a DAT, from may program. I will probably ask it in a new discussion.

Many thanks
Hamid

0 Kudos
gib
New Contributor II
1,628 Views
Quoting - h.amini

Appreciated very much for your comment.

I could not find the executable file of the command box, but as you said adding the following line to the BAT file could solve the problem.

PATH=C:Program FilesDiana 9.3bin;%PATH%

The next thing I need is to delete a file, e.g. a DAT, from may program. I will probably ask it in a new discussion.

Many thanks
Hamid

A suggestion: get a book about Fortran, or find a Fortran user manual (if you are using IVF it has a very comprehensive manual). You will find the answers to many of your questions in such a document. It is very important to learn how to find information from the documentation.
0 Kudos
h_amini
Beginner
1,628 Views
Quoting - gib
A suggestion: get a book about Fortran, or find a Fortran user manual (if you are using IVF it has a very comprehensive manual). You will find the answers to many of your questions in such a document. It is very important to learn how to find information from the documentation.

Thank you for this. I've got the following three books in my office and usually check them before starting a new discussion.

1- FORTRAN 77 and Numerical Methods for Engineers, Borse, G. J., PWS-Kent, 1991.

2- Fortran 90 Programming,Ellis, T. M. R, Philips, I. R. and Lahey, T. M.. Addison-Wesley, 1994.

3- FORTRAN with Engineering Applications, Koffman, E. B. and Friedman F. L., Addison-Wesley, 1993.

If you know a more comprehensive reference, please kindly let me know.

Many thanks

Hamid

0 Kudos
Reply