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!

memory get less and less

Status
Not open for further replies.

momphy

Programmer
Jul 16, 2012
14
US
hi guys
sorry for post problem .i reattach my code . and problem is when i run my code , the memory get less and less ,and finally run out . i use one variable in loop ,overwrite different data file to this variable,then write txt to disk . it should not take that much memory .thanks a lot for helping .here is my code :
*****************code*****************
program rfcor

character*32,dimension(20,160)::synfile
character*32 syn,synname,obspath,filepath
character*64 outpath
character*32,dimension(3329)::eek:bsfile
character*32,dimension(300)::filename
* real,dimension(3500)::syndata,obsdata
real,allocatable,dimension:))::syndata,obsdata
integer ni,nj,filenum,num
integer,dimension(20,160)::corr





syn='syndata/data.txt'
open(300,file=syn)
do i=1,20
do j=1,160
read(300,*,end=600)synfile(i,j)
end do
end do
600 continue

open(400,file='list.txt')
read(400,*)obsfile
*******************************************************
*up read station name
********************************************************
do ni=1,3329
obspath=trim(obsfile(ni))//'/data.txt'
* print*,obspath

open(401,file=obspath)
num=0
filename=''
do while(.true.)
num=num+1
read(401,*,end=500)filename(num)
end do
500 continue
print*,num
filenum=num-1
* print*,filenum
******************************************************
*read event name
******************************************************
do nj=1,filenum
filepath=trim(obsfile(ni))//'/'//trim(filename(nj))
print*,filepath
allocate(obsdata(3500))
obsdata=0
print*,obsdata
open(402,file=filepath)
read(402,*)(obsdata(nk),nk=1,3500)
* print*,size(obsdata)
***********************************************************
*read syn data
************************************************************
do i =1,20
do j=1,160
synname='syndata/'//synfile(i,j)
* print*,synname

allocate(syndata(3500))
syndata=0
open(301,file=synname)
read(301,*)(syndata(k),k=1,3500)
* print*,'syndata'
* print*,size(syndata)
corr(i,j)=sum(obsdata*syndata)
deallocate(syndata)
end do
end do
deallocate(obsdata)
************************************************************
*write result in to txt file
***********************************************************
outpath=filepath//'rfcor.txt'
print*,outpath
open(700,file=outpath,action='write')
do i=1,20
write(700,*)(corr(i,j),j=1,160)
end do
end do
end do
end program rfcor
 
Since syndata and obsdata are always the same size, why allocate and deallocate? Why not just declare them up front (as in your commeted out line) and get rid of the allocate/deallocate statements.
 
Seems we have the same thread twice.

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