Fortran: Pilib

Aus Wikibooks
<< zur Fortran-Startseite
< japi BLAS und ATLAS >




Allgemeines[Bearbeiten]

Auch pilib ist ein Open-Source-Ansatz für die Erstellung von GUIs mittels Fortran. Anders als japi verwendet pilib zu diesem Zweck die GTK+-Bibliothek. Momentan befindet sich dieses Projekt in einer frühen Entwicklungsphase (Alpha-Status, Stand: Anfang 2006).

Für nähere Informationen hinsichtlich der GTK+-Bibliothek wird auf die GTK+-Homepage verwiesen.

pilib-Installation[Bearbeiten]

  1. Download des pilib-Softwarepakets von der im Abschnitt Weblinks angegebenen pilib-Internetadresse.
  2. Entpacken (gunzip, tar).
  3. Installation der Bibliotheksbestandteile für Linux mit dem üblichen ./configure, make, make install.

Für eine detailliertere Installationsanleitung wird auf die im Softwarepaket enthaltene INSTALL- und README-Datei, sowie das pilib-Manual im HTML-Format verwiesen.

Beispiel[Bearbeiten]

Fortran 90/95-Code (free source form)
module bspmod
  implicit none
  save
 
  integer :: myedit1, myedit2, myedit3
end module bspmod
 
 
program bsp
  use pimod
  use bspmod
  implicit none
 
  integer :: mywin, mycontainer, mybutton, mytext, myclose, myclick	
 
  call piinit
 
  call gkwindow(c("Addition"), 1, 0, mywin, myclose)
 
  ! Container (in diesem Fall eine Table)
  call gkcontain(3, 2, 4, 5, mycontainer)
  call gkput(0, 0, -1, -1, mywin, mycontainer)
 
  ! Label
  call gktext(c("Zahl 1: "), mytext)              
  call gkputtable(0, 0, 0, 0, 4, 4, 5, 5, -1, -1, mycontainer, mytext)                
 
  ! Einzeiliges Eingabefeld mit einer Breite von 10 Zeichen
  call gkxedt(10, myedit1)
  call gkputtable(1, 0, 1, 0, 4, 4, 5, 5, -1, -1, mycontainer, myedit1)                
 
  ! Label
  call gktext(c("+"), mytext)              
  call gkputtable(0, 1, 1, 1, 4, 4, 5, 5, -1, -1, mycontainer, mytext)                
 
  ! Label
  call gktext(c("Zahl 2: "), mytext)              
  call gkputtable(0, 2, 0, 2, 4, 4, 5, 5, -1, -1, mycontainer, mytext)                
 
  ! Einzeiliges Eingabefeld mit einer Breite von 10 Zeichen
  call gkxedt(10, myedit2)
  call gkputtable(1, 2, 1, 2, 4, 4, 5, 5, -1, -1, mycontainer, myedit2)                
 
  ! Schaltfläche
  call gkbutton(c("="), mybutton, myclick)
  call gkputtable(0, 3, 2, 3, 4, 4, 5, 5, -1, -1, mycontainer, mybutton)                
 
  ! Label
  call gktext(c("Ergebnis: "), mytext)              
  call gkputtable(0, 4, 0, 4, 4, 4, 5, 5, -1, -1, mycontainer, mytext)                
 
  !  Einzeiliges Eingabefeld mit einer Breite von 10 Zeichen
  call gkxedt(10, myedit3)              
  call gkputtable(1, 4, 1, 4, 4, 4, 5, 5, -1, -1, mycontainer, myedit3)                
 
  call gkshow(mywin)      
 
  do while(myclose == 0)                              
    call gkproc
 	
    if(myclick /= 0) then
      call calculate
      myclick = 0
    end if
  end do
 
  call gkdestroy(mywin) 
end program bsp
 
 
subroutine calculate
  use pimod
  use bspmod
  implicit none
 
  real          :: k1, k2, string2real 
  character(30) :: cstr
 
  k1 = string2real(myedit1) 
  k2 = string2real(myedit2) 
  			
  write(cstr, *) k1+k2
  	
  call gksetstring (c(cstr), myedit3) 	
end subroutine calculate
 
 
function string2real(widget)
  use pimod
  implicit none
 
  real                :: string2real, zahl
  integer, intent(in) :: widget
  character(30)       :: cstr
  type(string)        :: str
 
  call gkgetstring(str, widget) 
  cstr = f_str2char(str)
  read(cstr, *) zahl   ! Umwandlung eines character-Wertes in eine real-Zahl
                       ! unter Zuhilfenahme des internal-file-Mechanismus
  string2real = zahl
end function string2real


Kompilieren, Linken:

g95 bsp.f95 -lpilib -lpilibf -I/usr/local/include

Bei der pilib-Installation werden mod-Dateien in ein Standard-Include-Verzeichnis geschrieben. Der Optionsschalter "-I" weist den Compiler an, im gegebenem Verzeichnis nach Include-Dateien zu suchen, in diesem Fall nach mod-Dateien. Das Format der mod-Dateien ist compilerabhängig.


Dieses Beispiel soll nur einen ersten Eindruck von pilib geben. Eine genauere Beschreibung der verwendeten pilib-Unterprogramme und Subroutinenparameter, sowie eine Auflistung weiterer Möglichkeiten der pilib-Bibliothek wird hier mit Hinweis auf die dem pilib-Softwarepaket beiliegenden Dokumentationsdateien nicht getätigt.

Weblinks[Bearbeiten]


<< zur Fortran-Startseite
< japi BLAS und ATLAS >