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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array declaration

Status
Not open for further replies.

ahad29

Technical User
Jul 24, 2005
2
US
Hi, I am new to Fortran and using Compaq visual fortran. I tried looking up on google but couldn't resolve ths problem.

I need to declare a matrix but the dimensions of this will not be knwon till the program gets to the executable part of the code. From the executable part i get a value for say j and my matrix needs to be F(1,j). These lines in the executable part of the code
==============================
REAL, dimension(1,j):: FN
FN(1,:)=0
==============================
create the following error: "Error: A specification statement cannot appear in the executable section."

Is there a way to define a matrix in the beginning with the help of variables whose value is established in the executable part of the program. Please help.Thanks

ahad
 
Looks like compaq visual fortran is either Fortran 90 or Fortran 95. If it is Fortran 90, you cannot have dynamic arrays. If it is fortran 95, have a look at the keyword ALLOCATE and TARGET. Basically what you need to do is

1) Declare it in the program as allocatable
2) Allocate it when you know what dimensions you want

Note that all declarations have to be at the top: you cannot declare stuff when you want to use it like in C++.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top