Fortran to  C (Translation)   by  PK Mohanty, SINP, Kolkata-107
Statements
Fortran (77)
       C
Remarks
Structure (1)
Col. 1    :  c or * for comments
Col. 2-5 : Statement label (optional)
Col. 6 : Continua of prev. line (optional)
Col. 7-72 : Statements
Col. 73-80: Sequence number
Structure  Free
Statement ends with ;
Case sensitive

Variable types
integer, real,double, character 
complex,logical
int,float, double, char 
(C does not have logical or complex var)
true and false are integer 1 and 0.
  
Var Declaration
integer a,b,c
real x,y
int a,b,c;
real x,y ;

Innitialization
real x,y
integer a,b
data x/1.2/, a/12/
float x=1.2,y
 int a=12,b;


Oporators (mathematical)
+,-, *, /, **
+,-,*, /, %, ++,--
+=, -= ,*= ,/=

Oporators (logical) .ge. , .gt. , .eq. , .or. , .and., .ne, .not.
>, >= , ==, ||, &&, !=, !





Control  transfer

do 10  i, 1, 100, 2
         DO-WHATEVER
  10    end do
     while (i.lt. 100) do
DO-WHATEVER
enddo
f(i.lt. 100) then
 DO-WHATEVER
else
DO-otherwise
enddo
    goto 40
 
 40 x= x+1


for(i=1;i<=100,i+=2)
{DO-WHATEVER ;}

while( i<100 )
{DO-WHATEVER ;}

if( i<100) {DO-WHATEVER ;}
else {DO-othrwise}
goto   there
label  there : x++

goto is  usually not  used in C.

The label there can be anything
Array
 real a(5), b(5,10)
 int c(2), k
data  k/1/, c/19,45/
 float a[5], b[5][5]
int c[]={19,45}, k
Array Index
F : 1 to N   
C: 0 to N-1
Function
      real function add(m,t)
integer m
real t
mult= t*m
return
end
float mult(int m, float t)
{ return(t*m);}

Subroutine
      subroutine iswap (a, b)
integer a, b,t
t = a
a = b
b = t
return
end
void iswap(a,b)
{int a,b,t; t=a;a=b;b=t}
Subroutine is a void function in C.
A complete program
c ----- Butterfly diagram-----
c ----------Logistic Map------
real x, a,f
integer i
do 10 a=0,4,.02
x= .15
do 20 i=0,1000
x= f(x,a)
20 enddo
do 30 i=0,100
x= a*x*(1-x)
write(*,*) a,x
30 enddo
10 enddo
stop
end

real function f(y,b)
real y,b
f= b* y*(1-y)
return
end

#include<stdio.h>
/*----- Butterfly diagram-----
----------Logistic Map------*/
main()
{
float x,a,f(float,float);
int i;

for(a=0;a<4;a+=.02)
{
x=.15;
for(i=0;i<1000;i++)x= f(x,a);
for(i=0;i<100;i++)
{x= f(x,a); printf("%lf %lf\n",a, x);}
}
}

float f( float y, float b)
{return( b* y*(1-y));}

Files


I will add more to it  in few days. PK.