Home > Archive > Tcl > January 2006 > Mixed language programming with FORTRAN for tcl/tk extension
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Mixed language programming with FORTRAN for tcl/tk extension
|
|
| S-Y. Chen 2006-01-31, 7:59 am |
| I have been working on this for a while, and got a lot of help from
Arjen (thanks to Arjen). I am bumping into some compiling programming
problems now and probably some of you can help me. I have tried many
different approaches and decided this may be the best way for me. I
think the try itself maybe interesting, so I will describe it in
details
1. The objective
I have a lot of fortran subroutines, which has been used for more than
10 years. They are stable and I don't want to touch them or transfer
them into C either (at least not for now). Recently my customer need
GUI, scripting and such things upon my FORTRAN subroutines. After long
discussion with everyone, I decided the best way is to embed my fortran
codes into the original Tcl/tk source code as some extension command.
2. What I have tried
I have tried many different things (including Arjen's Ftcl, which is
successful and really neat). And finally I wrote C codes to wrap around
my FORTRAN, then I wrote extension in Tcl with these c wrapper.
The compiling is actually more different than coding (for me).
Originally I was coding under VC++. However the customers asked me to
port everything into visual studio. Finally I have to modify the
NMAKE.VC supplied with tcl.tk source distribution. I extend the .obj
files list in the file, and specify the souece for these obj (which are
used for the extension)
I tested simple C code first (without FORTRAN). It works.
3. The compilation problem
Now it comes the problems. In order to use VS we will have to use Intel
FORTRAN, which is embedded into VS. The document say the fortran has to
be separated into static library projects These are all fine. Compiling
fortran into static libraries is not a problem
But, I can never get the C main program of tcl/tk to "see" the FORTRAN.
First I just wrote a simple C program to call my fortran, and I tried
to put FOREAN project into the VC project. It never worked out
(actually I don't know what I am doing here). Anyway, it should be a
simple problem of how to use Visual Studio. However my customer has
never done this before so we were stocked here.
Even if this problem is solved, how can we embeded the FORTRAN project
into the Tcl source distribution ? (NMAKE,VC)
Any help will be greatly appreciated.
Regards
S-Y. Chen
| |
| Gerald W. Lester 2006-01-31, 7:59 am |
| S-Y. Chen wrote:
> I have been working on this for a while, and got a lot of help from
> Arjen (thanks to Arjen). I am bumping into some compiling programming
> problems now and probably some of you can help me. I have tried many
> different approaches and decided this may be the best way for me. I
> think the try itself maybe interesting, so I will describe it in
> details
>
> 1. The objective
> I have a lot of fortran subroutines, which has been used for more than
> 10 years. They are stable and I don't want to touch them or transfer
> them into C either (at least not for now). Recently my customer need
> GUI, scripting and such things upon my FORTRAN subroutines. After long
> discussion with everyone, I decided the best way is to embed my fortran
> codes into the original Tcl/tk source code as some extension command.
>
> 2. What I have tried
> I have tried many different things (including Arjen's Ftcl, which is
> successful and really neat). And finally I wrote C codes to wrap around
> my FORTRAN, then I wrote extension in Tcl with these c wrapper.
>
> The compiling is actually more different than coding (for me).
> Originally I was coding under VC++. However the customers asked me to
> port everything into visual studio. Finally I have to modify the
> NMAKE.VC supplied with tcl.tk source distribution. I extend the .obj
> files list in the file, and specify the souece for these obj (which are
> used for the extension)
>
> I tested simple C code first (without FORTRAN). It works.
>
> 3. The compilation problem
> Now it comes the problems. In order to use VS we will have to use Intel
> FORTRAN, which is embedded into VS. The document say the fortran has to
> be separated into static library projects These are all fine. Compiling
> fortran into static libraries is not a problem
>
> But, I can never get the C main program of tcl/tk to "see" the FORTRAN.
> First I just wrote a simple C program to call my fortran, and I tried
> to put FOREAN project into the VC project. It never worked out
> (actually I don't know what I am doing here). Anyway, it should be a
> simple problem of how to use Visual Studio. However my customer has
> never done this before so we were stocked here.
>
> Even if this problem is solved, how can we embeded the FORTRAN project
> into the Tcl source distribution ? (NMAKE,VC)
>
> Any help will be greatly appreciated.
>
> Regards
> S-Y. Chen
>
My suggestion is that it might be easier to have your fortran library as a
separte executable and invoke the functions via a pipe.
So, create a fortran main that has the following loop:
1) Read a line with an integer value
2) If the value is -1, exit
3) Otherwise use a computed goto
4) for each case of the computed goto:
4a) read the arguments for the function whose number you have decided that is
4b) call the function
4c) write the results to standeard output
4d) flush standard output
Write you tcl package to have an myPackage::init routine that does an
set ::myPackage::libFD [open {|myFortran.exe} {CREAT RDWRT}]
Have routines in the package that correspond to each fortran fucntion.
Those routines would look like:
proc ::myPackage::foo {a b} {
variable libFD
puts $libFD 1; ## put our particular function number
puts $libFD [format {%4.4d %5.5d} $a $b]; ## output formatted args
flush $libFD
gets $libFD answer
return $answer
}
It would also have a myPackage::close that is called when done with the
package that looks like:
proc ::myPackage::close {} {
variable libFD
puts $libFD -1
flush $libFD
catch {close $libFD}
set libFD {}
}
| |
| Arjen Markus 2006-01-31, 7:03 pm |
| Shen-Yeh,
if you could send me the project files, I can try and have a look.
(Visual Studio can be very frustrating at times and unfortunately I
have ample experience with it ;))
Regards,
Arjen
|
|
|
|
|