Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executable program

Status
Not open for further replies.

j0zn

Programmer
Jul 19, 2013
36
0
0
BR
Is possible to create an execuble program from a fortran program?
If yes, how can I do it?
Thank you in advance
 
j0zn said:
If yes, how can I do it?
You have to compile it using a fortran compiler - for example: gfortran, g95, ...

 
wow, j0zn, where is that question coming from? Judging from all the threads that you have started, you have supposedly been writing Fortran programs for a few months now...I wouldn't expect this question from you at this time, unless...
 
I am sorry guys for this poorly made question. I wanted to know if is possible create a program like the windows programs from fortran, click-open-programs or something like this...
Is possible create a way of using a program without to use the terminal?
Is possible create a graphic interface to a program in fortran?
 
Yes - which compiler are you using?
 
j0zn said:
Is possible create a way of using a program without to use the terminal?
Is possible create a graphic interface to a program in fortran?
Yes it's possible with Fortran if you have a suitable library for it.

It's possible without Fortran too: You can create a wrapper program in other language, which creates the GUI, reads user input from it, sends it to the fortran program and after the calculation displays the output of the fortran program back in the GUI.
For simple case it's simple. I have this little example using Tcl/Tk:

Consider, we have this simplest Fortran program
fortcl.f95
Code:
[COLOR=#a020f0]program[/color] fortcl
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
 
[COLOR=#2e8b57][b]  real[/b][/color] :: val, [COLOR=#008080]sin[/color]
 
  [COLOR=#804040][b]read[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) val
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(A12,F6.3)'[/color]) [COLOR=#ff00ff]"Result = "[/color], [COLOR=#008080]sin[/color](val)  
[COLOR=#a020f0]end[/color]

Compile it (for example with gfortran or g95)
Code:
$ gfortran fortcl.f95 -o fortcl

Then create this Tcl/Tk script in the same directory where is your fortran executable:
fortcl.tcl
Code:
[COLOR=#0000ff]#!/usr/bin/wish[/color]

[COLOR=#0000ff]# window title[/color]
wm title . Sinus

[COLOR=#0000ff]# input field [/color]
[COLOR=#2e8b57][b]entry[/b][/color]  .e1

[COLOR=#0000ff]# button[/color]
[COLOR=#2e8b57][b]button[/b][/color] .b1 -[COLOR=#6a5acd]text[/color] [COLOR=#ff00ff]"Compute"[/color] -[COLOR=#6a5acd]command[/color] fcall

[COLOR=#0000ff]# text field[/color]
[COLOR=#2e8b57][b]label[/b][/color]  .l1 -bg green

[COLOR=#0000ff]# pack the widgets[/color]
[COLOR=#804040][b]pack[/b][/color] .e1 -[COLOR=#6a5acd]padx[/color] [COLOR=#ff00ff]10[/color] -[COLOR=#6a5acd]pady[/color] 5
[COLOR=#804040][b]pack[/b][/color] .b1 -[COLOR=#6a5acd]padx[/color] [COLOR=#ff00ff]10[/color] -[COLOR=#6a5acd]pady[/color] 5
[COLOR=#804040][b]pack[/b][/color] .l1 -[COLOR=#6a5acd]padx[/color] [COLOR=#ff00ff]10[/color] -[COLOR=#6a5acd]pady[/color] 5
 
[COLOR=#804040][b]proc[/b][/color] fcall { } { 
[COLOR=#0000ff]  # Communication with Fortran, printing the result [/color]

  [COLOR=#804040][b]set[/b][/color] val [.e1 get]

  [COLOR=#804040][b]if[/b][/color] {[[COLOR=#804040][b]string[/b][/color] is integer -strict [COLOR=#008080]$val[/color]] || [[COLOR=#804040][b]string[/b][/color] is double -strict [COLOR=#008080]$val[/color]]} {
[COLOR=#0000ff]    # fortcl.exe is compiled and linked Fortran program[/color]
    [COLOR=#804040][b]set[/b][/color] f [[COLOR=#804040][b]open[/b][/color] [COLOR=#ff00ff]"|./fortcl.exe"[/color] r+]

    [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$f[/color] [COLOR=#008080]$val[/color]
    [COLOR=#804040][b]flush[/b][/color] [COLOR=#008080]$f[/color]
 
    [COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$f[/color] wert
    [COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$f[/color]
  } [COLOR=#804040][b]else[/b][/color] {
[COLOR=#0000ff]    # if input was not a number, create error message [/color]
    [COLOR=#804040][b]set[/b][/color] wert [COLOR=#ff00ff]"Input ERROR !!!"[/color]
  }

  .l1 config -text [COLOR=#008080]$wert[/color]
}

Now if you run the Tcl script, you get a simplest GUI for the simple fortran program.
I saw more comprehensive examples on the web.
 
IVF has the MS windows interface

Silverfrost has a cryptic version of the MS windows interface
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top