LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2009, 01:05 AM   #1
srunni
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Rep: Reputation: 15
Calling Fortran 95 code in C


Hi,

I'm trying to call some Fortran 95 code in C, but I'm having problems with integers not having the same value in C as in Fortran, and changing values upon each run of the program. I think it has to do with the integer type, but I don't know how to fix it. I'm running Gentoo x86.

Here are the files I've got:
foo.c:
Code:
#include <stdio.h>

extern int qux_();

main() {
    printf("%d\n", qux_());
    return 0;
}
bar.f:
Code:
      subroutine qux()
      integer qux = 0
      return
      end subroutine qux
compile.sh:
Code:
#!/bin/bash
gcc -c foo.c
gfortran -c bar.f
gcc -o baz foo.o bar.o
GCC information:
Code:
# gcc --version
gcc (Gentoo 4.3.2-r3 p1.6, pie-10.1.5) 4.3.2
Thanks in advance for the help!

Last edited by srunni; 04-15-2009 at 01:07 AM.
 
Old 04-15-2009, 01:14 AM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Shouldn't that be a fortran function rather than a subroutine? Your syntax is the syntax of a function.
 
Old 04-15-2009, 08:15 AM   #3
srunni
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Oh, that's right. I changed the function from a void to an int and forgot to fix it. I'm not too familiar with Fortran

Anyway, here's the working code for bar.f:
Code:
      function qux()
      integer qux
      qux = 0
      end function qux
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling C from fortran RudraB Programming 0 07-23-2008 12:52 AM
Using C Preprocessor on Fortran Code mkrems Programming 4 07-08-2008 10:14 PM
calling ranlux from fortran RudraB Programming 0 04-25-2008 08:23 AM
compile old fortran code in linux v2010 Linux - Software 2 12-13-2005 04:32 PM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration