Jump to content

anybody know FORTRAN?

JewishBacon
Go to solution Solved by MrSuperb,

So I figured it out. F needs to be initialized in both the function AMD subfunction

 

you have to declare it, not initialize it ...

 

thats why I wrote :

DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F

so i have this code that i need to convert to fortran from c. yes i know this is useless because nobody uses fortran or c anymore.

here is the c code

 

#include <stdio.h>#include <math.h>double f(double t, double y){return y;}main(){double h=0.1, t, y, k1,k2,k3,k4;int i;/* initial value */t=0.0;y=1.0;for (i=0; i<=10; i++){printf("t= %lf rk= %lf exact=%lf\n", t, y, exp(t));k1=h*f(t,y);k2=h*f(t+h/2, y+k1/2.0);k3=h*f(t+h/2, y+k2/2.0);k4=h*f(t+h, y+k3);y= y+(k1+2.0*k2+2.0*k3+k4)/6.0;t=t+h;}return 0;}
attached is a screencap of what i think should work, but it does not seem to run. any ideas?

post-39732-0-28425300-1398734333_thumb.j

Edited by alpenwasser
code tags :)

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

No one uses C anymore? I must be living in some parallel universe then.

not the point

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Many people use C, but far fewer use fortran. Please put your code in code brackets (the icon in between the picture and quote icons) 

like this.

As for your actual problem, sorry, I can't help. Could you explain the output you are trying to get? It will make it easier for others to achieve that result, especially since your code apparently doesn't do what you want.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

IM literally just supposed to translate thec code to the fortran code

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Many people use C, but far fewer use fortran. Please put your code in code brackets (the icon in between the picture and quote icons) 

like this.
As for your actual problem, sorry, I can't help. Could you explain the output you are trying to get? It will make it easier for others to achieve that result, especially since your code apparently doesn't do what you want.

sorry about that im on my mobile and cant

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Shouldn't the function subprogram be:

function F(T, Y)     F=Yend

 

mainly because in the C code it takes two parameters and just returns Y. Which is a useless function though.

------------------------------------

     ~ Live Love Code ~

------------------------------------

Link to comment
Share on other sites

Link to post
Share on other sites

@RocK_lee2

this is what my code looks like right now

 
       FUNCTION F(T, Y)       DOUBLE PRECISION F, X,Y       F=Y       RETURN       END       PARAMETER (EPS=1.0E-6)       DOUBLE PRECISION H,K1,K2,K3,K4,T,Y       H=0.1       Y=1.0       T=0.0        DO 10 I=0,10,1        WRITE(*,*)"T=",T        WRITE(*,*)"RK=",Y        WRITE(*,*)"EXACT=",EXP(T)        K1=H*F(T,Y)        K2=H*F(T+H/2, Y+K1/2.0)        K3=H*F(T+H/2, Y+K2/2.0)        K4=H*F(T+H, Y+K3)        Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0        T=T+H        IF I=10 GOTO 11 10    CONTINUE 11    CONTINUE       STOP       END

and this is what i get when i type g77 fortrancode.f

fort.f: In program `MAIN__':fort.f:1:          FUNCTION F(T, Y)                   1fort.f:18: (continued):           K1=H*F(T,Y)                2Global name `f' at (2) has different type at (1) [info -f g77 M GLOBALS]fort.f:24:           IF I=10 GOTO 11           ^Invalid form for IF statement at (^) 

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

 

I know nothing about FORTRAN but ...

IF I=10 GOTO 11

should be ...

 IF (I .EQ. 10) GOTO 11

well it appears that you do! haha that fixed the for statement error, but not the other ones

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Ignore my previous comment. the whole loop should be different ...

 

instead of this ...

 DO 10 I=0,10,1...bla bla bla ...IF I=10 GOTO 11 10 CONTINUE 11 CONTINUE

do this ...

 DO 10 I=0,10...bla bla bla ...10 CONTINUE 

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

 

Ignore my previous comment. the whole loop should be different ...

 

instead of this ...

 DO 10 I=0,10,1...bla bla bla ...IF I=10 GOTO 11 10 CONTINUE 11 CONTINUE

do this ...

 DO 10 I=0,10...bla bla bla ...10 CONTINUE 

so this is what i did 

       FUNCTION F(T, Y)       DOUBLE PRECISION F, X,Y       F=Y       RETURN       END       PARAMETER (EPS=1.0E-6)       DOUBLE PRECISION H,K1,K2,K3,K4,T,Y       H=0.1       Y=1.0       T=0.0        DO 10 I=0,10        WRITE(*,*)"T=",T        WRITE(*,*)"RK=",Y        WRITE(*,*)"EXACT=",EXP(T)        K1=H*F(T,Y)        K2=H*F(T+H/2, Y+K1/2.0)        K3=H*F(T+H/2, Y+K2/2.0)        K4=H*F(T+H, Y+K3)        Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0        T=T+Hc        IF I=10 GOTO 11 10    CONTINUEc 11    CONTINUE       STOP       END

and this is the output, im not sure what its trying to tell me 

fort.f: In program `MAIN__':fort.f:1:          FUNCTION F(T, Y)                   1fort.f:18: (continued):           K1=H*F(T,Y)                2Global name `f' at (2) has different type at (1) [info -f g77 M GLOBALS]

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

FUNCTION F(T, Y)DOUBLE PRECISION F, X,YF=YRETURNEND

instead:

FUNCTION F(T, Y)F=YEND

that still outputs the same errors

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

    DOUBLE PRECISION FUNCTION F(T, Y) <----------------------    DOUBLE PRECISION F, X,Y    F=Y    END         PARAMETER (EPS=1.0E-6)    DOUBLE PRECISION H,K1,K2,K3,K4,T,Y    DOUBLE PRECISION F <----------------------------------         H=0.1    Y=1.0    T=0.0         DO 10 I=0,10    WRITE(*,*)"T=",T    WRITE(*,*)"RK=",Y    WRITE(*,*)"EXACT=",EXP(T)    K1=H*F(T,Y)    K2=H*F(T+H/2, Y+K1/2.0)    K3=H*F(T+H/2, Y+K2/2.0)    K4=H*F(T+H, Y+K3)    Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0    T=T+H    c IF I=10 GOTO 11         10 CONTINUE         c 11 CONTINUE         STOP    END     

try this

 

edit: without my nice arrows :P

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

    DOUBLE PRECISION FUNCTION F(T, Y) <----------------------    DOUBLE PRECISION F, X,Y    F=Y    END         PARAMETER (EPS=1.0E-6)    DOUBLE PRECISION H,K1,K2,K3,K4,T,Y    DOUBLE PRECISION F <----------------------------------         H=0.1    Y=1.0    T=0.0         DO 10 I=0,10    WRITE(*,*)"T=",T    WRITE(*,*)"RK=",Y    WRITE(*,*)"EXACT=",EXP(T)    K1=H*F(T,Y)    K2=H*F(T+H/2, Y+K1/2.0)    K3=H*F(T+H/2, Y+K2/2.0)    K4=H*F(T+H, Y+K3)    Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0    T=T+H    c IF I=10 GOTO 11         10 CONTINUE         c 11 CONTINUE         STOP    END     

try this

 

edit: without my nice arrows :P

 

that gives way more errors than what was there before

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

does this compile ? with errors?

PROGRAM LTTPARAMETER (EPS=1.0E-6)DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, FH=0.1Y=1.0T=0.0DO 10 I=0,10WRITE(*,*)"T=",TWRITE(*,*)"RK=",YWRITE(*,*)"EXACT=",EXP(T)K1=H*F(T,Y)K2=H*F(T+H/2, Y+K1/2.0)K3=H*F(T+H/2, Y+K2/2.0)K4=H*F(T+H, Y+K3)Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0T=T+H10 CONTINUESTOPENDDOUBLE PRECISION FUNCTION F(T, Y)DOUBLE PRECISION F,T,YF=YEND

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

 

does this compile ? with errors?

PROGRAM LTTPARAMETER (EPS=1.0E-6)DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, FH=0.1Y=1.0T=0.0DO 10 I=0,10WRITE(*,*)"T=",TWRITE(*,*)"RK=",YWRITE(*,*)"EXACT=",EXP(T)K1=H*F(T,Y)K2=H*F(T+H/2, Y+K1/2.0)K3=H*F(T+H/2, Y+K2/2.0)K4=H*F(T+H, Y+K3)Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0T=T+H10 CONTINUESTOPENDDOUBLE PRECISION FUNCTION F(T, Y)DOUBLE PRECISION F,T,YF=YEND

oh yea. loads of em :)

test.f:7:         DO 10 I=0,10         1test.f:19: (continued):         END         2Statement at (2) invalid in context established by statement at (1)test.f:7:         DO 10 I=0,10         1test.f:20: (continued):         DOUBLE PRECISION FUNCTION F(T, Y)         2Statement at (2) invalid in context established by statement at (1)test.f:3:         DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F                                             1test.f:20: (continued):         DOUBLE PRECISION FUNCTION F(T, Y)                                     2Invalid declaration of or reference to symbol `t' at (2) [initially seen at (1)]test.f:3:         DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F                                                1test.f:20: (continued):         DOUBLE PRECISION FUNCTION F(T, Y)                                        2Invalid declaration of or reference to symbol `y' at (2) [initially seen at (1)]test.f:7:         DO 10 I=0,10         1test.f:21: (continued):         DOUBLE PRECISION F,T,Y         2Statement at (2) invalid in context established by statement at (1)test.f:3:         DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F                                                   1test.f:22: (continued):         F=Y         2Invalid declaration of or reference to symbol `f' at (2) [initially seen at (1)]test.f:7:         DO 10 I=0,10         1test.f:23: (continued):         END         2Statement at (2) invalid in context established by statement at (1)test.f:7:         DO 10 I=0,10         ^

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

No one uses C anymore? I must be living in some parallel universe then.

Twas exactly what I was about to say.

Link to comment
Share on other sites

Link to post
Share on other sites

some slight changes ...

(maybe someone actually knows fortran here :D )

 

    PROGRAM LTT    PARAMETER (EPS=1.0E-6)    DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F    H=0.1    Y=1.0    T=0.0    DO 10 I=0,10    WRITE(*,*)'T=',T    WRITE(*,*)'RK=',Y    WRITE(*,*)'EXACT=',EXP(T)    K1=H*F(T,Y)    K2=H*F(T+H/2, Y+K1/2.0)    K3=H*F(T+H/2, Y+K2/2.0)    K4=H*F(T+H, Y+K3)    Y= Y+(K1+2.0*K2+2.0*K3+K4)/6.0    T=T+H    10 CONTINUE    STOP    END    DOUBLE PRECISION FUNCTION F(T, Y)    DOUBLE PRECISION T,Y    F=Y    END

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

So I figured it out. F needs to be initialized in both the function AMD subfunction

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

So I figured it out. F needs to be initialized in both the function AMD subfunction

 

you have to declare it, not initialize it ...

 

thats why I wrote :

DOUBLE PRECISION H, K1, K2, K3, K4, T, Y, F

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

A lot of people use C, you'd actually be surprised. If you want to be any type of programmer, you should learn C, you can make algorithms with it and stuff.

 

My math teacher and uncle (professor of Computer Science and EE) knows Fortran, COBOL, Pascal and those really old languages that all the modern banks use today.

There are 10 types of people in this world, those who understand binary, and those who don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×