C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 7th, 2008, 02:15 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
Fortran to C

Hi,
does any one knows how to convert a Fortran IV codes in to C.
I have a Fortran IV program (some 20 lines) and i need to convert to C, since i dont know any thing about Fortran...or can i post those Fortran codes here!!!!
thanks
kumar

Reply With Quote
  #2  
Old May 7th, 2008, 02:40 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,833 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 4 h 11 m 7 sec
Reputation Power: 446
I'd say, give it a try.

Basically think of it as a translation exercise. Read the original, understand what it's saying, and then express that in the target language. Of course, the original might say something that you can't express in the target (eg, call a library function that doesn't exist), so success is not always assured.

Reply With Quote
  #3  
Old May 7th, 2008, 03:00 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
Quote:
Originally Posted by dwise1_aol
I'd say, give it a try.

Basically think of it as a translation exercise. Read the original, understand what it's saying, and then express that in the target language. Of course, the original might say something that you can't express in the target (eg, call a library function that doesn't exist), so success is not always assured.


Will try....i am bit confused with numbering..also everything are in CAPS...also just some minutes ago got to know Fortran always starts from 6th Column
kumar

Reply With Quote
  #4  
Old May 7th, 2008, 03:13 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,833 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 4 h 11 m 7 sec
Reputation Power: 446
I thought that was column 7 -- column 6 marked continuation lines as I recall. Of course, that was 30 years ago.

FORTRAN didn't care whether you used upper or lower-case letters; it was just common practice to use all capitals. Also, it used line numbers (as did BASIC, though Visual Basic no longer does), which is what the first 5 columns were for.

Just post it as it is.

Reply With Quote
  #5  
Old May 7th, 2008, 03:33 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
fortran codes:-
Its somewhat okay..i can understand a bit..since i know some maths in it..otherwise...difficult
Code:
C CONVOLUTION INTEGRATION BY CRANSHAW'S METHOD
      IMPLICIT REAL*8 (A-H, O-Z)
      DIMENSION F(301),T(1001),V(10),A(10),S(1001)
      VELR=30.
      XL=30.
      API=3.1415926
      GAMS=2.
      GAMA=2.
      NJ=3
      VEL=VELR/2.
      X=-VEL
      NP=200
      DELTE=VELR/NP
      A(1)=.5
      A(2)=.3
      A(3)=.1
      V(1)=3.
      V(2)=0
      V(3)=-4.
      NP1=NP+1
      L=(XL+VEL)*2.*NP/VELR+1.1
      EN=-VEL-XL-DELTE
      DO 100 I=1,L
      EN=EN+DELTE
100   S(I)=GAMS/2/API/(EN**2+GAMS**2/4.)
      X=-XL-DELTE
      L=L-200
      DO 102 I=1,L
      T(I)=0.
      X=X+DELTE
      DO 101 J=1,NJ
101   T(I)=T(I)+A(J)/((X-V(J))**2+(GAMA/2.)**2)
102   T(I)=DEXP(-T(I))
      EN=-VEL-DELTE
      LL=L-1
      DO 400 I=1,NP1
      EN=EN+DELTE
      COR=1./API*(API-DATAN(2.*(XL+EN)/GAMS)
     1-DATAN(2.*(XL-EN)/GAMS))
      F(I)=(S(202-I)*T(1)+S(201+L-I)*T(L))/2.
      DO 401 J=2, LL
401   F(I)=F(I)+S(201+J-1)*T(J)
      F(I)=F(I)*DELTE+COR
400   PRINT 3, EN, F(I)
  3   FORMAT (4(1X, F14.8))
      END

Reply With Quote
  #6  
Old May 7th, 2008, 04:04 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,504 Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 20 h 56 m 52 sec
Reputation Power: 865
Here's a loose translation. It compiles but I won't guarantee that it works
Code:
#include <stdio.h>
#include <math.h>

#define PI 3.1415926

int main(void)
{
    double f[301], t[1001], v[10], a[10], s[1001];
    int    i, j;
    for (i = 0; i < 301; i++)
        f[i] = 0.0;
    for (i = 0; i < 1001; i++) 
        t[i] = s[i] = 0.0;
    for (i = 0; i < 10; i++) 
        v[i] = a[i] = 0.0;    

    double velr = 30;
    double xl   = 30;
    double gams = 2;
    double gama = 2;
    int    nj   = 3;
    double vel  = velr / 2.0;
    double x    = -vel;
    int    np   = 200;
    double delte = velr / np;
    a[1] = 0.5; a[2] = 0.3; a[3] = .1;
    v[1] = 3.0; v[2] = 0.0; v[3] = -1;
    int    np1  = np + 1;
    int l       = (xl + vel) * 2.0 * np / velr + 1.1;
    double en   = -vel -xl -delte;

    for (i = 1; i <= l; i++) {
        en += delte;
        s[i] = gams / 2 / PI / (pow(en, 2.0) + pow(gams, 2.0) / 4.0);
    }

    x = -xl - delte;
    l -= 200;
    for (i = 1; i <= l; i++) {
        t[i] = 0;
        x += delte;
        for (j = 1; j <= nj; j++) {
            t[i] += a[j] / ( pow(x - v[j], 2.0) + pow(gama/2.0, 2.0) );
        }
        t[i] = (double)(-t[i]);
    }
    en = -vel - delte;
    int ll = l - 1;
    for (i = 1; i <= np1; i++) {
        en += delte;
        double cor = 1.0 / PI * (PI - atan(2.0 * (xl + en) / gams) 
                                 - atan(2.0 * (xl - en) / gams));
        for (j = 2; j <= ll; j++) {
            f[i] += f[i] + s[201 + j - 1] * t[j];
        }
        f[i] = f[i] * delte + cor;
        printf("%14.8f %14.8f\n", en, f[i]);
    }
    
    
    return 0;
}
Comments on this post
sizablegrin agrees!
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month

Reply With Quote
  #7  
Old May 7th, 2008, 04:10 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
hi

Hi now in my home...so cant test it...anyways i will try to read and will understand ur new C codes...with the result of ur c codes i will compare with the original fortran program (this program is already published...so should be correct)
Actually i want to make some small changes to the fortran codes..and i dont like to play with fortran codes...if it is in C..then i can do it...
thanks

Reply With Quote
  #8  
Old May 13th, 2008, 11:09 AM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
hi

Hi,
Now i am trying to convert to C lang...with ur c codes...now i need one small help...
If u see the fortran program, u will notice the following line...
T(I)=DEXP(-T(I))..
after googling i got to know dexp is exponential function
But how to write it in C....
if i am correct can i write in the following format..
t[i]=exp(-t[i])...is this correct!!!
kumar

Reply With Quote
  #9  
Old May 13th, 2008, 11:25 AM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,178 sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 9th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 4 Days 4 h 46 m 28 sec
Reputation Power: 1549
Yes. Include math.h.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
  #10  
Old May 13th, 2008, 01:36 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
Hi again,,,
API is PI
In that fortran code u will see this formula:-
Code:
COR=1./API*(API-DATAN(2.*(XL+EN)/GAMS)
     1-DATAN(2.*(XL-EN)/GAMS))

the equal C code is:-
double cor = (1.0 / PI) * (PI - atan(2.0 * (xl + en) / gams)-atan(2.0*(xl-en)/gams));

Is that okay...if not kindly give me the correct math formula (not in program language!!)
PS: there is '1' (???) in fortran code...and also the formula is correct...actually i dont know why that '1' in that formula!
thanks kumaar
Comments on this post
sizablegrin disagrees: You're wearing very thin. We are here to help you, not to do your thinking for you.
Scorpions4ever agrees: Well, he did ask a reasonable question

Reply With Quote
  #11  
Old May 13th, 2008, 02:28 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,833 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 4 h 11 m 7 sec
Reputation Power: 446
Quote:
Originally Posted by kumaaar
PS: there is '1' (???) in fortran code...and also the formula is correct...actually i dont know why that '1' in that formula!


That 1 is undoubtedly in column 6, which is the continuation column. I assume that COR= had started in column 7, which is where the code is to begin -- columns 1 through 5 were for the line number and columns 73 through 80 for sequencing.

You see, FORTRAN coding was tied very closely to punch cards, an IBM method for encoding, storing, and processing data that started decades before electronic computers (ie, computers started in the 1940's whereas punch cards for data processing started in 1890 with Herman Hollerith -- http://en.wikipedia.org/wiki/Hollerith -- , whose company became IBM; the punch code that we learned was still called "Hollerith code"). I've seen a photo from the 1920's of a bank office filled with rows and rows of large desks, all covered with decks of punch cards stacked up to about a meter high. When IBM finally entered the new computer industry, one of their big selling points was that their computer could interface with the IBM data processing equipment the customer already owned.

Punch cards (http://en.wikipedia.org/wiki/Punched_card) normally had 80 columns, so you'd code up your FORTRAN program on 80-column coding sheets. As already noted, columns 1-5 were for the line number, columns 7-72 for the line of code, and 73-80 for the sequence number (the reason for which will be given below).

In C, we can have one code statement occupy several lines, with the semicolon telling the compiler that it has reached the end of the statement. In FORTRAN, the end of the code statement was marked by the end of the line, so basically each code statement had to fit on one line; ie, on one single punch card. If you needed to continue the statement onto the next line, then you would write something in the continuation column, column 6. As I recall, we always wrote a 'C', but it could be anything, such as the 1 that you find.


Now about that sequence number. In a public TV series chronicling the history of computers, they showed an old student film from the 1960's. A graduate student is working on a massive project using a card deck that's about 4 feet long. We see him carrying it back and forth, resubmitting it and then changing it based on the printout. Until he trips and drops the deck, shuffling it completely out of order. There's nothing left for him to do but to hang himself.

That's where the sequence number field comes in. In that field, you put the order in which the cards belong in the deck -- in BASIC, you would do that with the line numbers, but in FORTRAN it was with the sequence field. That way, if your card deck ever got shuffled, you'd just run it through a card sorter that would place all the cards in their proper order, based on their sequence fields. And you could run a computer job that would copy your existing deck and punch a new deck for you, adding the sequence numbers for you.

Last edited by dwise1_aol : May 13th, 2008 at 02:37 PM.

Reply With Quote
  #12  
Old May 13th, 2008, 03:06 PM
kumaaar kumaaar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 45 kumaaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 39 m 19 sec
Reputation Power: 1
hi

Hi Dewis
yes i have seen those punch card..some guys here like gold preserve it...
btw...i am happy to inform finally i succeeded in making my own program..(off course with ur, siza and scorpion help)..I really befitted a lot.....that scorpion's transulation in to C is good enough for me to understand...now i am trying to modify it a bit...
now will go for a beer
kumar

Reply With Quote
  #13  
Old May 13th, 2008, 03:24 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,833 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 4 h 11 m 7 sec
Reputation Power: 446
Oh yes, the beer. And Obstler ... I had to wait 30 years, but they've finally started importing it to the US.

When I started studying computer science in 1977, for the first two years we had to use punch cards and then in the last two years were allowed to use terminals, of which there were only about five -- the computer was an IBM S/370 mainframe; the IBM PC didn't even exist until 3 years later. Then in 1982, the university started installing lots more terminals in rooms all over the campus in order for students in other departments to use.

In a graduate class at another university in the late 80's, we did a top-level design of an operating system. The professor defined only two I/O devices: a line printer and a card reader. Half the students in that class had come directly from the undergraduate program (ie, had only been at it for four years and hadn't gone out to work in industry yet) and that half immediately raised their hands: "What's a card reader?" "It's used to read punch cards." Same half of the class again: "What's a punch card? We've never seen one!" And indeed, they hadn't, because they had spent their entire college career at a terminal and never had to work a keypunch.

Now, the Navy continued to use them for several years (I worked in the warehouses as a reservist). Mainly to label pallets and to write notes on.

Reply With Quote
  #14  
Old May 13th, 2008, 03:56 PM