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!

Allocate syntax error 1

Status
Not open for further replies.

venik

Technical User
Sep 29, 2006
3
US
I am trying to use Dynamic arrays in F95 with gfortran (F95) under Ubuntu 6.10.
What is wrong with this code? I am getting a message:
Syntax error in ALLOCATE statment.
I tried to put the ALLOCATE and DEALLOCATE in the main program, and that prevented the error message, but it still did not work. I got a message:
Segmentation failure: Core Dumped.
Thanks for any help.
----------------------------------------
program CountSpikes
c Opens a text file (of spike times) and counts how many lines it has
REAL*8, ALLOCATABLE :: rgsp:)) !rank 1

c
open(unit=55,status='old',file='retu160_4.dat')
nspikes=0
do
read(55, *, end=999) rgsp(nspikes)
C print *,rgsp, nspikes
nspikes=nspikes+1
end do
999 print *, nspikes
call testDynamicArray(nspikes, rgsp)

end


subroutine testDynamicArray(nspikes,rgsp)
allocate (rgsp (nspikes) )

do i=1,nspikes
print *,rgsp(i)
end do
deallocate(rgsp)
return
end

 
Unusual mix of fixed/free form source lines...
Allocate ALLOCATABLE array in one and only one ALLOCATE statement when the required shape becomes known:
Code:
allocate(rgsp(nspiles))
So simply calculate numbers in the 1st loop (read a number in dummy variable - REAL*8::junk, for example), then allocate array then REWIND(UNIT=55) file (place logical read cursor at the beginning) then READ a file again into this (now allocated) array. All done.

See your language reference: array parameter declarations. In your snippet rgsp parameter is treated contextually as a function name but not an array name.
 
Thanks. Your comments pointed me in the right direction, and the program works fine now. Although I had only one ALLOCATE statment in the snippet, it did include an unintentional error, which I have now fixed.
Thanks again for your quick help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top