Gustav Ivanovic
2003-09-22 20:05:56 UTC
I would like to share my first experience of mixed language
programming using tcl/tk and fortran.
I have been working for sometime in an engineering dept in a big
company. Recently the IT policy of the company has changed and we have
now Windows XP without any administrator privilege therefore we do not
have anymore the possibility to install any GUI programming tool like
visual basic.
By chance, I stumbled on comp.lang.tcl and found that tcl and tk is
the solution to our difficulty to develop GUI without having
administrator privilege on our XP work station.
Until now our programs run on Unix servers and the GUI is built on PC
using MS visual basic. We are used to have our fortran program
input/output as files. input and output files are sent or fetched from
Unix computers using ftp or rcp. The programs on Unix servers are
triggered by rexec or rsh. Briefly, all communication between Unix and
XP is done via files (instead of sockets) to keep the architecture
simple.
We have now very fast PC and we started to migrate our fortran apps to
PC using Compaq Visual Fortran 6 compiler (CVF is the only development
tool officially "approved" by our bloody IT dept.). All fortran
programs run OK in this PC environment, now the problem is to build
the GUI because we have lost the possibility to write in VB.
Since all communication with our fortran programs is done by file, the
port to PC is quite straight forward. The last experiment we have done
is to build DLLs for our fortran and to plug it into GUI built in Tcl
and Tk with the help of ffidl. Tclkit allows us to work without any
installation whatsoever on our XP computers.
We have now left the old Unix server and work almost exclusively on
our XP workstation. Only the basic engineering database remains on
Unix servers (a kind of vault).
I put some examples here after to give an illustration of how we
transfer information from Tcl/Tk GUI to fortran dll. The only transfer
from fortran to Tcl/Tk we managed to do is by return of integer or
real function (see snippets).
FORTRAN PART (Compaq Visual Fortran)
=========================================
module tcl
contains
integer function integervar(n)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'integervar', STDCALL
::integervar
integervar = n * n
end function integervar
real function realvar(x)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'realvar', STDCALL ::realvar
realvar = x * x
end function realvar
subroutine stringvar(length,line)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'stringvar', STDCALL
::stringvar
!DEC$ ATTRIBUTES REFERENCE ::line
character(len=length) :: line
integer ::length,fileunit
fileunit=1
open(fileunit,file=line)
write(fileunit,'(A)') line
close(fileunit)
end subroutine stringvar
end module tcl
END OF FORTRAN
TCL/TK script (with ffidl05.dll)
=========================================
load ../ffidl05
ffidl::callout RunFortranint {int} int [ffidl::symbol testcvf.dll
integervar]
ffidl::callout RunFortranstr {int pointer-utf8} int [ffidl::symbol
testcvf.dll stringvar]
ffidl::callout RunFortranfloat {float} float [ffidl::symbol
testcvf.dll realvar]
set buffer ABCDE
puts $buffer
puts [RunFortranint 12]
puts [RunFortranstr [string length $buffer] $buffer]
puts [RunFortranfloat 2.5]
END OF TCL/TK script
Interesting links:
http://mini.net/tcl/ffidl
wiki.tcl.tk/ffidl
www.tcl.tk
wiki.tcl.tk/tclkit
http://mini.net/tcl/tclkit
programming using tcl/tk and fortran.
I have been working for sometime in an engineering dept in a big
company. Recently the IT policy of the company has changed and we have
now Windows XP without any administrator privilege therefore we do not
have anymore the possibility to install any GUI programming tool like
visual basic.
By chance, I stumbled on comp.lang.tcl and found that tcl and tk is
the solution to our difficulty to develop GUI without having
administrator privilege on our XP work station.
Until now our programs run on Unix servers and the GUI is built on PC
using MS visual basic. We are used to have our fortran program
input/output as files. input and output files are sent or fetched from
Unix computers using ftp or rcp. The programs on Unix servers are
triggered by rexec or rsh. Briefly, all communication between Unix and
XP is done via files (instead of sockets) to keep the architecture
simple.
We have now very fast PC and we started to migrate our fortran apps to
PC using Compaq Visual Fortran 6 compiler (CVF is the only development
tool officially "approved" by our bloody IT dept.). All fortran
programs run OK in this PC environment, now the problem is to build
the GUI because we have lost the possibility to write in VB.
Since all communication with our fortran programs is done by file, the
port to PC is quite straight forward. The last experiment we have done
is to build DLLs for our fortran and to plug it into GUI built in Tcl
and Tk with the help of ffidl. Tclkit allows us to work without any
installation whatsoever on our XP computers.
We have now left the old Unix server and work almost exclusively on
our XP workstation. Only the basic engineering database remains on
Unix servers (a kind of vault).
I put some examples here after to give an illustration of how we
transfer information from Tcl/Tk GUI to fortran dll. The only transfer
from fortran to Tcl/Tk we managed to do is by return of integer or
real function (see snippets).
FORTRAN PART (Compaq Visual Fortran)
=========================================
module tcl
contains
integer function integervar(n)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'integervar', STDCALL
::integervar
integervar = n * n
end function integervar
real function realvar(x)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'realvar', STDCALL ::realvar
realvar = x * x
end function realvar
subroutine stringvar(length,line)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'stringvar', STDCALL
::stringvar
!DEC$ ATTRIBUTES REFERENCE ::line
character(len=length) :: line
integer ::length,fileunit
fileunit=1
open(fileunit,file=line)
write(fileunit,'(A)') line
close(fileunit)
end subroutine stringvar
end module tcl
END OF FORTRAN
TCL/TK script (with ffidl05.dll)
=========================================
load ../ffidl05
ffidl::callout RunFortranint {int} int [ffidl::symbol testcvf.dll
integervar]
ffidl::callout RunFortranstr {int pointer-utf8} int [ffidl::symbol
testcvf.dll stringvar]
ffidl::callout RunFortranfloat {float} float [ffidl::symbol
testcvf.dll realvar]
set buffer ABCDE
puts $buffer
puts [RunFortranint 12]
puts [RunFortranstr [string length $buffer] $buffer]
puts [RunFortranfloat 2.5]
END OF TCL/TK script
Interesting links:
http://mini.net/tcl/ffidl
wiki.tcl.tk/ffidl
www.tcl.tk
wiki.tcl.tk/tclkit
http://mini.net/tcl/tclkit