Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using C variables in a FORTRAN NAMELIST

Status
Not open for further replies.

kfsii

Programmer
Apr 8, 1999
1
0
0
US
I have a C program but want to use the FORTRAN NAMELIST feature to <br>
read in initial variable values. I need to know how to declare the <br>
variables in FORTRAN so the linker knows the variables are the same as those used in the C code.
 
<br>
You might mention the platform you are working on (PC, VAX, WorkStation?) and operating system and type linker.
 
I am giving a program below which can help you. <br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br>The C main program uses the __stdcall keyword to call the Fortran routines with the correct calling convention. The C source must use all-uppercase names for the routines, because this Fortran code does not use the C, STDCALL, or ALIAS attributes. Finally, pass by value and pass by reference are specified explicitly, though pass by reference would have been assumed by default for Fortran.<br><br>/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File CMAIN.C&nbsp;&nbsp;&nbsp;*/<br><br>#include &lt;stdio.h&gt;<br><br>extern int __stdcall FACT (int n);<br>extern void __stdcall PYTHAGORAS (float a, float b, float *c);<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;float c;<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Factorial of 7 is: %d\n&quot;, FACT(7));<br>&nbsp;&nbsp;&nbsp;&nbsp;PYTHAGORAS (30, 40, &c);<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Hypotenuse if sides 30, 40 is: %f\n&quot;, c);<br>}<br><br>C&nbsp;&nbsp;&nbsp;&nbsp;File FORSUBS.FOR<br>C<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INTEGER*4 FUNCTION Fact (n)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INTEGER*4 n [VALUE]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INTEGER*4 i, amt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amt = 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DO i = 1, n<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amt = amt * i<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END DO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fact = amt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SUBROUTINE Pythagoras (a, b, c)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;REAL*4 a [VALUE]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;REAL*4 b [VALUE]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;REAL*4 c [REFERENCE]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c = SQRT (a * a + b * b)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top