gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1....

20
gtk-fortran: a GTK / Fortran binding 1. Vincent MAGNIN, 2. James TAPPIN, 3. Jens HUNGER, 4. Jerry DELISLE 1. Lille University (France), 2. RAL Space (UK), 3. Technische Universität Dresden (Germany), 4. GFortran Team (USA) FortranCon 2020, Zurich, 2-4 July 2020 1 / 20

Transcript of gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1....

Page 1: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

gtk-fortran: a GTK / Fortran binding

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE

1. Lille University (France), 2. RAL Space (UK),3. Technische Universität Dresden (Germany), 4. GFortran Team (USA)

FortranCon 2020, Zurich, 2-4 July 2020

1 / 20

Page 2: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

2 / 20

Why gtk-fortran?Installing, building, runningWelcome to the machineTo Infinity and Beyond!

Plan

1 Why gtk-fortran?

2 Installing, building, running

3 Welcome to the machine

4 To Infinity and Beyond!

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE gtk-fortran: a GTK / Fortran binding

Page 3: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

The scientist and the unknown pleasures of visualization. . .

Do scientists dream of electric sheep being artists?Scientific visualization is essential and is an art (left).Nothing in the Fortran standard, except ASCII art? (right)

Figure: first discovered pulsar [1]. Figure: the Mandelbrot set in 1978.

3 / 20

Page 4: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

You can’t always get what you want

Visual Fortran (Digital, Compaq, Intel) has the Quickwin library(Windows).When migrating to Linux, I was looking for something:

to make bitmap (or vectorial) drawing,and scientific plotting.To build Graphical User Interfaces (GUI).Using only standard Fortran.Multi-platform: Linux, Windows, MacOS. . .Free software (as in free beer and freedom).A perennial solution.

There was/is a lot of great tools like pilib (GTK 2, but needing a Ccompiler), DISLIN, PLplot, gnuplot, interfacing with anotherlanguage (japi), etc.But I still hadn’t found what I was looking for. . .

4 / 20

Page 5: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

But if you try sometime you find: GTK

2nd May 2007 13:10Tobias BURNUS posted on the comp.lang.fortran newsgroup a democreating an empty GTK 2 window:

GTK is mainly written in C language,and Fortran 2003 introduced interoperability with C.

About GTKGNU LGPL license.Multi-platform.Who’s behind? The GNOME Foundation (RedHat. . . ).2002: GTK 2.02011: GTK 3.02020(?): GTK 4.0

5 / 20

Page 6: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

GTK is not a library. . .

It’s a collection of libraries !GLib: general-purpose utility library,GObject: the GLib Object System,GTK itself,GdkPixbuf: pixel drawing (even without GUI),Cairo: vectorial drawing,GIO : input/output,GDK, Pango, ATK. . .

6 / 20

Page 7: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

A GTK / Fortran binding

gtk-fortranProject launched with J. DELISLE, J. TAPPIN and J. HUNGER.First commit: 9 January 2011.Now ≈ 10 000 functions in gtk-fortran!Not only about GUI and graphics! But also strings, regex, date andtime, files, network utilities, lists, trees, hash tables, etc.Only 500 functions used in our tools and examples. . .

Figure: Commits in the GTK 3 branch.

7 / 20

Page 8: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

8 / 20

Why gtk-fortran?Installing, building, runningWelcome to the machineTo Infinity and Beyond!

Installing and building gtk-fortranDownload the zip fromhttps://github.com/vmagnin/gtk-fortran/wiki or git clone:$ git clone [email protected]:vmagnin/gtk−fortran.git

Install tools and dependencies (Debian/Ubuntu names):$ sudo apt install gfortran cmake libgtk−3−dev

libplplot−dev plplot−driver−cairo

Build the project and install the library:$ mkdir build && cd build$ cmake ..$ make$ sudo make install

Compile your own program:$ gfortran my_app.f90 $(pkg−config −−cflags −−libs

gtk−3−fortran)

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE gtk-fortran: a GTK / Fortran binding

Page 9: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

And I went down to the demonstration

Figure: hl_cairo_clock.f90 (Kubuntu)

Figure: mandelbrot_pixbuf.f90 (MacOS)

Figure: hl_plplot4e.f90 (Windows 7)

Figure: julia_pixbuf.f90 (Fedora)9 / 20

Page 10: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

Some projects using gtk-fortran

"The VCU nuclear reactor simulator, Richmond Pile 3, is aclassroom and research tool that emulates a large commercialpressurized water reactor (PWR)." [2]https://egr.vcu.edu/departments/mechanical/research/nuclear-simulator-lab/

Uncertradio [3]:https://www.thuenen.de/de/fi/arbeitsbereiche/meeresumwelt/

leitstelle-umweltradioaktivitaet-in-fisch/uncertradio/

10 / 20

Page 11: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

11 / 20

Why gtk-fortran?Installing, building, runningWelcome to the machineTo Infinity and Beyond!

Nobody said it was easy. . .

Event driven programmingBased on a main loop, idle most of the time.If something happens a signal is emitted,received by the concerned widget,which calls its corresponding callback function.

It’s all about C pointers and C typesC pointers toward functions, objects, data. . .C types: int, double, char. . .The GTK official documentation is totally C oriented: to be able toread C function prototypes is better. . .

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE gtk-fortran: a GTK / Fortran binding

Page 12: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

Example: the button widget

To create my "Bye" button, I need to call that C function whoseprototype is in /usr/include/gtk-3.0/gtk/gtkbutton.h:� �GtkWidget∗ gtk_button_new_with_labe l ( const gchar ∗ l a b e l ) ;� �The gtk-fortran interface for that function is in src/gtk-auto.f90:� �f u n c t i o n gtk_button_new_with_labe l ( l a b e l ) b ind ( c )

use i s o_c_b ind ing , on l y : c_ptr , c_chartype ( c_ptr ) : : gtk_button_new_with_labe lc h a r a c t e r ( k ind=c_char ) , dimens ion (∗ ) : : l a b e l

end f u n c t i o n� �In my Fortran program:� �

use i s o_c_b ind i nguse gtk , on l y : gtk_button_new_with_labe l , g_s i gna l_connec t

. . .my_button = gtk_button_new_with_labe l ( "Bye " // c_nu l l_cha r )

! I need a l s o to connect my button to a c a l l b a c k f u n c t i o n :c a l l g_s igna l_connec t (my_button , " c l i c k e d " // c_nu l l_char , c_ fun l oc (

my_ca l l back_func t i on ) )� �12 / 20

Page 13: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

How the Fortran interfaces are generated?Before each gtk-fortran release

The python program cfwrapper.py parses the GTK .h header files,generates the src/*-auto.f90,using especially regular expressions.

$ ./cfwrapper.py −g 3Pass 1: looking for enumerators, funptr and derived types...Pass 2: looking for C functions...

/usr/include/atk−1.0 => atk−auto.f9085781 bytes

/usr/include/cairo => cairo−auto.f90133740 bytes

/usr/include/gdk−pixbuf−2.0 => gdk−pixbuf−auto.f9058223 bytes

/usr/include/glib−2.0 => glib−auto.f901299171 bytes

/usr/include/gtk−3.0/gdk => gdk−auto.f90208504 bytes

/usr/include/gtk−3.0/gtk => gtk−auto.f901319554 bytes

/usr/include/gtk−3.0/unix−print => unix−print−auto.f9024488 bytes

/usr/include/pango−1.0 => pango−auto.f90171656 bytes

=== Statistics (ready to paste in the Status wiki page) ===

## GTK 3.24.12, GLib 2.62.4, Ubuntu 19.10 x86_64, Python 3.7.5vmagnin, Tue, 30 Jun 2020 15:12:24 +0000

* nb_files scanned = 759

* nb_generated_interfaces = 10335

* nb_deprecated_functions = 1118

* nb_type_errors = 61

* nb_errors (others) = 348

* nb_lines treated = 33888

* nb_variadic functions = 136

* nb_enumerators = 376

* nb_win32_utf8 = 4

* Number of types = 78

* Computing time: 12.69 s

* SHA1: a4542484b3a002678f983d936482f244ad5222c2>>>>>> SHA 1 HAS BEEN MODIFIED ! It was 1

cfa7b5cf0c2d36a8962109c8da6d3b6f758398a <<<<<<

Used types: [’c_ptr’, ’c_int’, ’c_char’, ’c_double’, ’c_funptr’, ’c_int64_t’, ’c_size_t’, ’c_long’, ’c_int32_t’, ’c_float’, ’c_int8_t’, ’?’, ’c_int16_t’, ’c_long_double’]

13 / 20

Page 14: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

Tools to ease the pain

A High Level library (J. Tappin)Offers a simplified interface for most useful GUI functions.Can be mixed with direct GTK calls.

gtkf-sketcher (J. Hunger)Complicated GUI can be graphically designed with Glade,saved in an XML file,used by gtkf-sketcher to generate a gtk-fortran program.

Other toolsusemodules.pl: to generate your "USE, ONLY:" statementsSome shell scripts.

14 / 20

Page 15: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

15 / 20

Why gtk-fortran?Installing, building, runningWelcome to the machineTo Infinity and Beyond!

How to contribute?

Build and test with various systems and compilers:use the gtk3 stable branch,or the gtk4 branch if you are already familiar with GTK.

Report issues on GitHub.Help improve the documentation.Write tutorials.Write new examples (only 500 functions tested).. . .

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE gtk-fortran: a GTK / Fortran binding

Page 16: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

SWOT matrix of the project

StrengthsStandard Fortran.GTK is perenial and multi-platform.gtk-fortran maintained since 2011.Includes a High Level library.Many commented examples.

OpportunitiesFortranCon 2020.Fortran-lang Community and tools.New compilers: Flang, LFortran. . .GTK 4 soon released (Fall 2020?).Use GObject Introspection?

WeaknessesFew contributors.No GTK programming tutorial.The cfwrapper.py needs refactoring.The binding is not 100 % complete.

ThreatsFortran is losing users.

16 / 20

Page 17: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

17 / 20

Appendices

Thank you for listening!

I will be pleased to answer yourquestions now

or later on Slack, GitHub,Fortran-lang Discourse. . .

1. Vincent MAGNIN, 2. James TAPPIN,3. Jens HUNGER, 4. Jerry DELISLE gtk-fortran: a GTK / Fortran binding

Page 18: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

Acknowledgments

Tobias BURNUS who posted on the comp.lang.fortrannewsgroup (2nd May 2007 13:10) an example of a program creatingan empty GTK+ 2 window.Contributors and users who are not in the authors: MehdiCHINOUNE (CMake parallelisation), Ian HARVEY. . .

18 / 20

Page 19: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

Useful links

The gtk-fortran home [4]:https://github.com/vmagnin/gtk-fortran/wiki

The GTK home:https://www.gtk.org/

Where to find its official documentation:https://developer.gnome.org/

The GTK developers blog:https://blog.gtk.org/

The GNOME Discourse:https://discourse.gnome.org/c/platform

Fresh GTK News:https://gitlab.gnome.org/GNOME/gtk/-/blob/master/NEWS

19 / 20

Page 20: gtk-fortran: a GTK / Fortran binding · 2020. 7. 2. · gtk-fortran: aGTK/Fortranbinding 1. VincentMAGNIN,2. JamesTAPPIN, 3. JensHUNGER,4. JerryDELISLE 1. LilleUniversity(France),2.

References

Harold Dumont Craft.Radio observations of the pulse profiles and dispersion measures oftwelve pulsars.Ithaca, N.Y., 1970.Ph.D. Thesis, OCLC: 741854775.D. Tincher, S. Bilbao y León, and J. Miller.Progress on real-time, interactive modeling and simulation of nuclearpower plants.volume 2017-September, 2017.

Günter Kanisch.Generalized evaluation of environmental radioactivity measurementswith uncertradio. part i: Methods without linear unfolding.Applied Radiation and Isotopes, 110:28 – 41, 2016.

V. MAGNIN, J. TAPPIN, J. HUNGER, and J. DELISLE.gtk-fortran: a GTK+ binding to build Graphical User Interfaces inFortran.The Journal of Open Source Software, 5(34), February 2019.

20 / 20