- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
I am new to fortran.. I am facing difficulty in calling subroutine and module from main program. When I run the program , its gives error about line 95 d.
sometimes it gives error SALFORD RUN TIME ERROR-STACK OVER FLOW
Please check any mistake in the following code:
Regards,
Ali
- Module variables_m
- integer lon,lonmax,xx,yy ! longitude
- integer lat,latmax ! latitude
- integer yr,yrmax ! year
- integer mon,monmax ! month
- integer num ! arbitral number
- integer i,j,k
- parameter (lonmax=320) ! num of grids (longitude)
- parameter (latmax=160) ! num of grids (latitude)
- parameter (yrmax=101) ! num of years totally
- parameter (monmax=12) ! num of months per year
- real:: idata(lonmax,latmax*monmax*yrmax)
- real data(lonmax,latmax,monmax,yrmax)
- real, dimension(1:10)::ave
- integer count,tt,sy,ey
- real:: summ
- end module variables_m
- module readbinaryfile_m
- use variables_m
- contains
- subroutine readbinaryfile()
- open(8,file='monthly_temperature_1900to2000.bin',access='direct',recl=lonmax*1)
- do num=1,latmax*monmax*yrmax
- do lon=1,lonmax
- read(8,rec=num) idata(lon,num)
- end do
- enddo
- close(8)
- end subroutine readbinaryfile
- end module readbinaryfile_m
- module printallvalues_m
- use variables_m
- use readbinaryfile_m
- implicit none
- contains
- subroutine printallvalues()
- integer lon,lonmax,xx,yy ! longitude
- integer lat,latmax ! latitude
- integer yr,yrmax ! year
- integer mon,monmax ! month
- integer num ! arbitral number
- integer i,j,k
- parameter (lonmax=320) ! num of grids (longitude)
- parameter (latmax=160) ! num of grids (latitude)
- parameter (yrmax=101) ! num of years totally
- parameter (monmax=12) ! num of months per year
- real:: idata(lonmax,latmax*monmax*yrmax)
- real data(lonmax,latmax,monmax,yrmax)
- real, dimension(1:10)::ave
- integer count,tt,sy,ey
- real:: summ
- open(9,file='all_values.csv',status='replace')
- num=1
- do yr=1,yrmax
- do mon=1,monmax
- do lat=1,latmax
- do lon=1,lonmax
- data(lon,lat,mon,yr)=idata(lon,num)
- write(9,*) data(lon,lat,mon,yr)
- end do
- num=num+1
- end do
- end do
- end do
- close(9)
- end subroutine printallvalues
- end module printallvalues_m
- module decadalmeantemperature_m
- use variables_m
- use readbinaryfile_m
- use printallvalues_m
- implicit none
- contains
- subroutine decadalmeantemperature()
- integer lon,lonmax,xx,yy ! longitude
- integer lat,latmax ! latitude
- integer yr,yrmax ! year
- integer mon,monmax ! month
- integer num ! arbitral number
- integer i,j,k
- parameter (lonmax=320) ! num of grids (longitude)
- parameter (latmax=160) ! num of grids (latitude)
- parameter (yrmax=101) ! num of years totally
- parameter (monmax=12) ! num of months per year
- real:: idata(lonmax,latmax*monmax*yrmax)
- real data(lonmax,latmax,monmax,yrmax)
- real, dimension(1:10)::ave
- integer count,tt,sy,ey
- real:: summ
- open(10,file='10 Years average.csv',status='replace')
- write(10,*) 'Interval',',','Average Decadel Temp'
- sy=1
- ey=10
- do k=1,10
- summ=0.0
- count=0
- do yr= sy,ey
- ave=0.0
.yy=1899+sy
- xx=1899+ey
- do mon=1, 12
- do lat=1,160
- do lon=1,320
- summ =summ+ data(lon,lat,mon,yr)
- count=count+1
- end do
- end do
- end do
- end do
- sy=ey+1
- ey=ey+10
- if (ey==100) then
- ey=101
- end if
- ave(k) =summ/count
- write(10,*) yy,'-',xx,',', ave(k)
- end do
- close(10)
- end subroutine decadalmeantemperature
- end module decadalmeantemperature_m
- program envfluidmechanics
- use variables_m
- use readbinaryfile_m
- use printallvalues_m
- use decadalmeantemperature_m
- call decadalmeantemperature
- end program envfluidmechanics
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It helps if you can specify what the problems you encounter with this code are. Since we do not know what it is supposed to do, we can only guess at the intended functionality.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Arjen,
Thank you for your quick reply.
I made changes in my question.
Please check know
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay, stack overflows are caused by for instance large local arrays, because these exist only during the time the subroutine is active. Stack memory is limited and while you can enlarge it when linking the program, this is not the solution in this case.
Have a look at the module printallvalues_m and its subroutine printallvalues. The module uses the variables_m module, so that the variables defined by that module are known to the using module and its contents, but you define local variables in the subroutine printallvalues of the same name. I think you mean to use the variables from variables_m. To do that: leave out the declarations. Because of these local declarations you hide the module variables.
And the stack overflow is (most probably) coming from the local declaration of the arrays data and idata.
Regards,
Arjen

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page