Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forgot Fortran

Status
Not open for further replies.

daveask

Programmer
Aug 11, 2004
108
GB
Hi,

I knew Fortran long time ago but forgot all now. Can you correct the folloing program for me?

Thank you in advance.

PROGRAM Hello

REAL a(2,2)
a = (/1.0,2.0,3.0,4.0/)
CALL Test(a)
print*,a(1,1)

CONTAINS
SUBROUTINE Test(a)
REAL a(2,2)
a(1,1)=a(1,1)+9.0
END SUBROUTINE Test

END PROGRAM Hello
 
Why we need to put subroutine inside the "main" program?
 
C ThePROGRAM Hello
REAL a(2,2)
C a = (/1.0,2.0,3.0,4.0/) instead try :
DATA A /1.0,2.0,3.0,4.0/
CALL Test(a)
print*,a(1,1)
C CONTAINS
END
SUBROUTINE Test(a)
REAL a(2,2)
a(1,1)=a(1,1)+9.0
RETURN
END

The subroutine can be compiled as a separate program and linked to the main program before execution.
 
PAndersen,

Thank you for your help.
>C a = (/1.0,2.0,3.0,4.0/) instead try :
> DATA A /1.0,2.0,3.0,4.0/
Why not use a = (/1.0,2.0,3.0,4.0/)? I forget DATA already.....but are you talking Fortran77 ?



 
If a = (/1.0,2.0,3.0,4.0/) gives no compilation error, use it. The DATA statement is for FTN77 and older.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top