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!

Arrays

Status
Not open for further replies.

joseph89

Programmer
Apr 9, 2012
1
GB
I want to declare an array of size N, although N is assigned by the user, so when I declare my variables N doesn't have a value, which seems to be a problem when I define the array.
 
use allocatable arrays then (which requires Fortran 90/95 or later)

Code:
real, allocatable, dimension (:) :: rValue   ! declare your variables like this
.
.
read (*,*) N    ! user input
allocate (rValue(N), stat = irslt)    ! allocate memory for your array
if (irslt .ne. 0) then
    write (*,*) 'cannot allocate memory'    ! errormessage
!   continue as appropriate in your prog
endif
rValue = 0.0     ! initalize your new array some way or other
.
(use array)
.
deallocate (rValue)   ! deallocate if no longer needed to free memory

deallocation is done automatically, when your program ends execution so you might skip the last statement.
Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top