Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Mixed language programming with FORTRAN for tcl/tk extension
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 11th August 14:28
s-y. chen
External User
 
Posts: 1
Default Mixed language programming with FORTRAN for tcl/tk extension



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

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
  Reply With Quote


 


2 2nd September 00:49
gerald w. lester
External User
 
Posts: 1
Default Mixed language programming with FORTRAN for tcl/tk extension



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 {}
}
  Reply With Quote


 


3 2nd September 00:49
arjen markus
External User
 
Posts: 1
Default Mixed language programming with FORTRAN for tcl/tk extension


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
  Reply With Quote
Reply


Thread Tools
Display Modes




666