1 (edited by JohnWasilewski 2013-06-02 19:48:16)

Topic: GUI I/O in FORTRAN programs

Here are the various alternative methods I have come across for developing FORTRAN software with a graphical user interface ('GUI'):

1.  Use FORTRAN for the main algorithm, and wrap it in a JAVA code for the GUI.
     Simply Fortran will presumably do this.
     I don't know how to do it.
     Does Simply Fortran support JAVA by any chance?
     Can anyone supply a fully-coded example, with instructions for how to build it
     into an executable which will run under Win Doze?

2.  Use FORTRAN for the main algorithm, and wrap it in a Python code for the GUI.
     Simply Fortran will presumably do this.
     I don't know how to do it.
     Does Simply Fortran support Python by any chance?
     Can anyone supply a fully-coded example, with instructions for how to build it
     into an executable which will run under Win Doze?

3.  Use Compaq Visual Fortran and its GUI tools, if you still use WinXP 32 bit.
     CVF6.6f is not installable/runnable under Win Doze 7 64 bit.

4.  Use the Intel FORTRAN derivative of CVF, with its GUI tools.
     If you can afford to spend several hundred quid on it.

5.  Use Salford university's product, 'Silverfrost' FORTRAN,
     with its 'ClearWin+' GUI tools.
     I'm not sure but I have a feeling that the free version has some kind
     of restriction, such as an advertising banner in all output.
     Does anyone know for sure what the score is with this?

6.  Use the commercial version of Salford university's 'Silverfrost'
     FORTRAN, with its 'ClearWin+' GUI tools.
     If you can afford to spend several hundred quid on it

7.  Use Simply Fortran with the DISLIN extension.
     This works brilliantly, and is not difficult.
     I taught myself to do it, after reading a paper by Clive Page.
     Easy to find on the web.
     I will post a complete example immediately after posting this message.

8.  Use Simply Fortran with the Gtk Fortran extension.
     I've not tried this but it looks do-able.
     I read somewhere that Gtk Fortran can be a bit tricky.
     Can anyone amplify, confirm or correct this?
     Can anyone supply a fully-coded example, with instructions for how to build it
     into an executable which will run under Win Doze?
----
John

2 (edited by JohnWasilewski 2013-06-02 16:35:55)

Re: GUI I/O in FORTRAN programs

Here's a complete example using Simply Fortran and the DISLIN extension:


      PROGRAM Roots
C     -------------
C     Example showing how to use DISLIN to greate a Fortran GUI
C     Jmw
C     30-03-2011
C     The concept is to display a window, with buttons, menus,
C     input (fields) and output panel(s), and simply wait for the user
C     to do stuff.  The user enters data in input fields
C     then activates various parts of the program by clicking buttons
C     or selecting actions from pull-down menus.
C     Each part of the program is executed in a subroutine, which always
C     returns control to the user in the main top window.
      USE dislin
      IMPLICIT NONE
      CHARACTER*8 aValu
      CHARACTER*5 Header
      INTEGER ipMain,ipTopM,ipTopL,ipTopR,ipBtmM,idMActs,idSqre,idSqRt,
     +        idIN, idOUT, CALL1,CALL2,CALL3,CALL4,CALL5,CALL6, i
      COMMON aValu, idIN, idOUT
     
      EXTERNAL Square, SqRoot, CuRoot
     
      aValu='        '
C-----------------------------------------------------------------------
C     DESIGN THE MAIN WINDOW LAYOUT
C     Size, position and title
      CALL SWGWTH(24)
      CALL SWGSIZ(408,420)
      CALL SWGPOS(425,225)
     
      Header='ROOTS'
      Print*, Header
      CALL SWGTIT(Header)
     
C     Define main window ipMain, stacked vertically
      CALL WGINI('VERT',ipmain)
     
C     Divide the top area of ipMain, ipTopM, horizontally
         CALL WGBAS(ipMain,'HORI',ipTopM)
         
C        Define the L and R vertical stacks in ipTopM
         CALL WGBAS(ipTopM,'VERT',ipTopL)
         CALL WGBAS(ipTopM,'VERT',ipTopR)
         
C        Repeatedly redefine ipMain's bottom area until far enough down
         DO i=1,12
           CALL WGBAS(ipmain,'HORI',ipBtmM)
           END DO
C-----------------------------------------------------------------------
C     Menus
C     New menu
      CALL WGPOP(ipmain,'Actions',idMActs)
     
C       Menu entries
        CALL WGAPP(idMActs,'Square',CALL1)
        CALL SWGCBK(CALL1, SQUARE)
       
        CALL WGAPP(idMActs,'SqRoot',CALL2)
        CALL SWGCBK(CALL2, SQROOT)
       
        CALL WGAPP(idMActs,'CuRoot',CALL3)
        CALL SWGCBK(CALL3, CUROOT)
       
C     Help menu
      CALL SWGHLP('Enter a numeric value then|'//
     +            'click an action button, or|'//
     +            'select a menu action.')
C-----------------------------------------------------------------------
C     Prompt, messages and data entry field - in the top area, LH stack
      CALL WGLAB(ipTopL,'Simple JMW Fortran GUI example',i)
      CALL WGLTXT(ipTopL,'Enter a value',aValu,48,idIN)
C-----------------------------------------------------------------------
C     Buttons - in the top area, RH stack
      CALL WGPBUT(ipTopR,'SQUARE',CALL4)
      CALL SWGCBK(CALL4, SQUARE)
     
      CALL WGPBUT(ipTopR,'SQROOT',CALL5)
      CALL SWGCBK(CALL5, SQROOT)
     
      CALL WGPBUT(ipTopR,'CuROOT',CALL6)
      CALL SWGCBK(CALL6, CUROOT)
C-----------------------------------------------------------------------
C     Output panel - in the bottom area
      CALL SWGWTH(52)   
      CALL WGSTXT(ipBtmM,14,999,idOUT)
C-----------------------------------------------------------------------
C     Activate
      CALL WGFIN
C-----------------------------------------------------------------------
      STOP
      END
C-----------------------------------------------------------------------     
   
   
      SUBROUTINE SQUARE
      USE dislin
      IMPLICIT NONE
      CHARACTER*8 aValu
      CHARACTER*20 StringR
      INTEGER idIN, idOUT
      REAL Value
      COMMON aValu, idIN, idOUT
     
C     Read the keyboard input value from idIN
      CALL GWGTXT(idIN,aValu)
      CALL GWGFLT(idIN,Value)
     
C     Run this part of the program
C     (It would normally contain a lot more than this)
      CALL SWGTXT(idOUT,
     +            TRIM(aVALU)//' (squared) = '//
     +            STRINGR(Value**2,'(F8.3)'))
      RETURN
      END
C-----------------------------------------------------------------------


      SUBROUTINE SQROOT
      USE dislin
      IMPLICIT NONE
      CHARACTER*8 aValu
      CHARACTER*20 StringR
      INTEGER idIN, idOUT
      REAL Value
      COMMON aValu, idIN, idOUT
     
C     Read the keyboard input value from idIN
      CALL GWGTXT(idIN,aValu)
      CALL GWGFLT(idIN,Value)
     
C     Run this part of the program
C     (It would normally contain a lot more than this)
      CALL SWGTXT(idOUT,
     +     'Square root ('//TRIM(aVALU)//') = '//
     +      STRINGR(SQRT(Value),'(F8.3)'))
      RETURN
      END
C-----------------------------------------------------------------------


      SUBROUTINE CUROOT
      USE dislin
      IMPLICIT NONE
      CHARACTER*8 aValu
      CHARACTER*20 StringR
      INTEGER idIN, idOUT
      REAL Value
      COMMON aValu, idIN, idOUT
     
C     Read the keyboard input value from idIN
      CALL GWGTXT(idIN,aValu)
      CALL GWGFLT(idIN,Value)
     
C     Run this part of the program
C     (It would normally contain a lot more than this)
      CALL SWGTXT(idOUT,
     +     'Cube root ('//TRIM(aVALU)//') = '//
     +      STRINGR(10**(LOG10(Value)/3),'(F8.3)'))
      RETURN
      END
C-----------------------------------------------------------------------


      FUNCTION STRINGR(RValu,F)
C     Returns real RValu as a string
C     F is the format specification, such as '(F8.3)'
      Character STRINGR*20, F*80
      REAL RValu
      WRITE(STRINGR,F) RValu
      RETURN
      END
C-----------------------------------------------------------------------

Re: GUI I/O in FORTRAN programs

DISLIN is very easy to implement and works rather well, but the licensing is very restrictive.

QuickWin (Intel's GUI with their Parallel Studio product) is really only for bare-minimum getting a non-command prompt GUI.  It'll display text in a window, for the most part.

gtk-fortran and the highlevel container for it that is also available is pretty good.  Implements GTK+.  Harder than DISLIN but the license is GNU v3.

I've actually started on a framework uses gtk-fortran and (hopefully) makes it really easy to create a GUI.  Also has a bit of OpenMP in it, too.  Here's a link:  https://sourceforge.net/projects/fortran-forge/

Its only at v0.1, so its not that great yet, but I'm probably going to upload v0.2 tonight which will make it a little easier to use.

If you just want an example, use the Simply Fortran Package Manager to download the gtk-fortran package and then when you go to create a new project, choose the pre-made "Gtk-Fortran Examples" project.  That will have a lot of examples for all the different ways to create a GUI.

John