Solved

Fortran 90 to C

Posted on 2003-10-31
6
1,633 Views
Last Modified: 2013-11-08
I was perusing the web and found - in effect - source code to convert fortran code to C.  Unfortunately i'm having difficulties  compiling source.

The question.  Does anyone have an f90 to C or f2C (basically a fortran to C converter - preferably fortran 90 to C/C++?) converter that works in a PC enviornment (Unsure how much difference it make, nonetheless, I'm ruinning XP) that I could obtain?  I've got lots of fortran code to convert.

My 'outside' email would be forums_mp@hotmail.com

Thanks in advance
0
Comment
Question by:forums_mp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 9657929
0
 

Author Comment

by:forums_mp
ID: 9658426

Consider the example referenced in the manual for f2c

------------------------------------
FUNCTION DOT(N,X,Y)
INTEGER N
REAL X(N),Y(N)
DOT = 0
DOT 10 I = 1, N
10  DOT = DOT + X(I)*Y(I)
END

using f2c per the above
Error on line 1 of test2.F: illegal continuation card (starts "FUNCTI")
Error on line 2 of test2.F: illegal continuation card (starts "INTEGE")
Error on line 3 of test2.F: illegal continuation card (starts "REAL X")
Error on line 4 of test2.F: nondigit in statement label field "DOT ="
Error on line 5 of test2.F: nondigit in statement label field "DOT 1"
Error on line 4 of test2.F: unclassifiable statement (starts "0")
Error on line 6 of test2.F: labeled continuation line (starts "10  DO")
Error on line 7 of test2.F: nondigit in statement label field "END  "
   MAIN:
Error on line 5 of test2.F: syntax error
Warning on line 7: missing final end statement
------------------------------------------------------------------------
What all this means is beyond me and cant find anything per the documentation highlighting a fix.
Any ideas?

0
 
LVL 32

Accepted Solution

by:
jhance earned 150 total points
ID: 9658938
My how we've forgotten our FORTRAN!!

1) You must start FORTRAN statements in COLUMN 7!  FORTRAN considers column 1 as "special" and you're not following the rules.

2) You must have a final END since you start with a FUNCTION.  This is not really a valid FORTRAN program but it's still translatable.

Starting with the following LEGAL FORTRAN:

      FUNCTION DOT(N,X,Y)
      INTEGER N
      REAL X(N),Y(N)
      DOT = 0
      DO 10 I = 1, N
   10 DOT = DOT + X(I)*Y(I)
      END
      END

I issued the following:

F2C <TEST.F

And the expected response:

/*  -- translated by f2c (version 19970805).
   You must link the resulting object file with the libraries:
      -lf2c -lm   (in that order)
*/

#include "f2c.h"

doublereal dot_(n, x, y)
integer *n;
real *x, *y;
{
    /* System generated locals */
    integer i__1;
    real ret_val;

    /* Local variables */
    static integer i__;

    /* Parameter adjustments */
    --y;
    --x;

    /* Function Body */
    ret_val = (float)0.;
    i__1 = *n;
    for (i__ = 1; i__ <= i__1; ++i__) {
/* L10: */
      ret_val += x[i__] * y[i__];
    }
    return ret_val;
} /* dot_ */
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:jhance
ID: 9658941
3) This line:

DOT 10 I = 1, N

is ILLEGAL.  It should be (I assume):

DO 10 I = 1, N
0
 

Author Comment

by:forums_mp
ID: 9660855

Truly appreaciate the timely responses.  I have to apologize, I now have a fotran book.  Simply put i've never used fortran in the past.   with some general clean ups,  I sense this function should look like.

integer *n;
// real *x, *y;
float *x, *y;

float dot_(int *n, float* x, float* y)
{
    /* System generated locals */
    integer i__1;
    // real ret_val;
    float ret_val;

    /* Local variables */
    static integer i__;

    /* Parameter adjustments */
    --y;
    --x;

    /* Function Body */
   //  ret_val = (float)0.;
    ret_val = 0.0;

    i__1 = *n;
    for (i__ = 1; i__ <= i__1; ++i__) {
/* L10: */
     ret_val += x[i__] * y[i__];
    }
    return ret_val;
} /* dot_ */
0
 
LVL 32

Expert Comment

by:jhance
ID: 9661620
BTW, f2c does make C from FORTRAN but the C it makes is NOT very good C.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add values of each row in an array 3 81
C# code editing and collaboration 3 167
Not needed 13 134
Reccomended programming language for client-server applications 12 196
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question