Calling a simple FORTRAN subroutine from my simple C program 
Author Message
 Calling a simple FORTRAN subroutine from my simple C program

I can not find any reference examples for a very simple C program that
calls a simple fortran subroutine.  I am using Visual C++ Standard
Edition 4.0 and FORTRAN PowerStation 4.0 (Console Applications).  My
FORTRAN subtoutine is just a WRITE statement (in .obj file).  I want to
be able to get this to work and then pass variables (int, float, string,
matrix) back and forth.  I am a very very simple programer so I need
very simple and clear examples to understand.  I write very simple
Windows C programs, and in the future I will need to call a FORTRAN
subroutine from a Windows C program. I have had no luck from any books.
Any help would be greatly appreciated.
Thank You  


fax 216-433-2184



Tue, 14 Mar 2000 03:00:00 GMT  
 Calling a simple FORTRAN subroutine from my simple C program

Quote:
> Actually, Microsoft has licenced Digital to use Developer Studio for its
> FORTRAN compiler. Provided you use version 5.0 of Digital's Visual
FORTRAN
> with VC++ 5.0 you can mix the two seemlesy. I know, because I have a
mixed
> language project in C++, C and FORTRAN that I have recompiled (from
version
> MS VC++ 4.0 and MS PowerStation 4.0) in Visual C++ 5.0 and Digital Visual
> FORTRAN 5.0 without changing a single line of code on both Intel and DEC
> Alpha platforms. The only snag with the latter was that VC++ on RISC
> removes leading underscores from symbol names and the calling convention

Oops! I meant naming convention rather than calling convention, of
course...

Rajesh Khan



Fri, 17 Mar 2000 03:00:00 GMT  
 Calling a simple FORTRAN subroutine from my simple C program

Quote:
> It is quite easy to do what you are trying to do.

> On my first pass, I spent quite a bit of time creating a single mixed
language, C++ &
> FORTRAN, application. It was very difficult to get the libraries to link
properly. In
> the end I was able to get this to work, but decided on another solution.
Another reason
> not to use this approach is that VC++ dropped FORTRAN support with Rev 5.
So one would
> be forever wedded to Rev 4.

Actually, Microsoft has licenced Digital to use Developer Studio for its
FORTRAN compiler. Provided you use version 5.0 of Digital's Visual FORTRAN
with VC++ 5.0 you can mix the two seemlesy. I know, because I have a mixed
language project in C++, C and FORTRAN that I have recompiled (from version
MS VC++ 4.0 and MS PowerStation 4.0) in Visual C++ 5.0 and Digital Visual
FORTRAN 5.0 without changing a single line of code on both Intel and DEC
Alpha platforms. The only snag with the latter was that VC++ on RISC
removes leading underscores from symbol names and the calling convention
had to be modified (can be implemented with preprocessor directives).

I think the trick to get the libraries to link together properly is to make
sure that the library settings under both the FORTRAN tab and C/C++ tab
(under project settings) agree. That is, if you are using multithreaded
DLLs for the C++ part of the project, you should do the same for the
FORTRAN part and vice versa.

Quote:

> The solution I gravitated to was to create a DLL with the FORTRAN code
which was
> accessed from the C++ code. This way the FORTRAN & C are separate modules
which work
> together. There is a description of how to do this in the FPS

Programmer's Guide CH 22,

Quote:
> Programming with Mixed Languages.

> Good luck, Jeremy Wise

Rajesh Khan



Fri, 17 Mar 2000 03:00:00 GMT  
 Calling a simple FORTRAN subroutine from my simple C program

Quote:

> I can not find any reference examples for a very simple C program that
> calls a simple FORTRAN subroutine.  I am using Visual C++ Standard
> Edition 4.0 and FORTRAN PowerStation 4.0 (Console Applications).  My
> FORTRAN subtoutine is just a WRITE statement (in .obj file).  I want to
> be able to get this to work and then pass variables (int, float, string,
> matrix) back and forth.  I am a very very simple programer so I need
> very simple and clear examples to understand.  I write very simple
> Windows C programs, and in the future I will need to call a FORTRAN
> subroutine from a Windows C program. I have had no luck from any books.
> Any help would be greatly appreciated.
> Thank You


> fax 216-433-2184

It is quite easy to do what you are trying to do.

On my first pass, I spent quite a bit of time creating a single mixed language, C++ &
FORTRAN, application. It was very difficult to get the libraries to link properly. In
the end I was able to get this to work, but decided on another solution. Another reason
not to use this approach is that VC++ dropped FORTRAN support with Rev 5. So one would
be forever wedded to Rev 4.

The solution I gravitated to was to create a DLL with the FORTRAN code which was
accessed from the C++ code. This way the FORTRAN & C are separate modules which work
together. There is a description of how to do this in the FPS Programmer's Guide CH 22,
Programming with Mixed Languages.

Good luck, Jeremy Wise



Fri, 17 Mar 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Calling Fortran 90 subroutine from C program

2. calling a Fortran subroutine from a C program

3. Calling a subroutine of IMSL Fortran library in c program

4. HELP: call FORTRAN subroutines from C?

5. Calling Fortran subroutines in C

6. Calling C subroutine from FORTRAN

7. Calling FORTRAN library functions/subroutines

8. C calls to Fortran subroutines on HP9000/300

9. HELP: call FORTRAN subroutines from C?

10. How to call C subroutine in Fortran

11. Call C subroutine in Fortran

12. Call Fortran subroutine in VC++

 

 
Powered by phpBB® Forum Software