Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Modules and subroutines

Malik_Ahmad_A_
Beginner
695 Views

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

  1. Module variables_m

 

  1. integer lon,lonmax,xx,yy     ! longitude
  1. integer lat,latmax     ! latitude
  2. integer yr,yrmax       ! year
  3. integer mon,monmax     ! month
  4. integer num            ! arbitral number
  5. integer i,j,k
  6. parameter (lonmax=320) ! num of grids (longitude)
  7. parameter (latmax=160) ! num of grids (latitude)
  8. parameter (yrmax=101)  ! num of years totally
  9. parameter (monmax=12)  ! num of months per year
  10. real:: idata(lonmax,latmax*monmax*yrmax)
  11. real data(lonmax,latmax,monmax,yrmax)
  1. real, dimension(1:10)::ave
  2. integer count,tt,sy,ey
  3. real:: summ

 

  1. end module variables_m
  1. module readbinaryfile_m
  2. use variables_m
  3. contains
  4. subroutine readbinaryfile()

 

 

 

 

 

  1. open(8,file='monthly_temperature_1900to2000.bin',access='direct',recl=lonmax*1)
  1. do num=1,latmax*monmax*yrmax
  1. do           lon=1,lonmax
  2. read(8,rec=num) idata(lon,num)
  3. end do
  4. enddo    
  5. close(8)
  6. end subroutine readbinaryfile    
  1. end module readbinaryfile_m
  1. module printallvalues_m
  2. use variables_m
  3. use readbinaryfile_m
  1. implicit none
  1. contains
  2. subroutine printallvalues()
  1. integer lon,lonmax,xx,yy     ! longitude
  2. integer lat,latmax     ! latitude
  3. integer yr,yrmax       ! year
  4. integer mon,monmax     ! month
  5. integer num            ! arbitral number
  6. integer i,j,k
  7. parameter (lonmax=320) ! num of grids (longitude)
  8. parameter (latmax=160) ! num of grids (latitude)
  9. parameter (yrmax=101)  ! num of years totally
  10. parameter (monmax=12)  ! num of months per year
  11. real:: idata(lonmax,latmax*monmax*yrmax)
  12. real data(lonmax,latmax,monmax,yrmax)
  1. real, dimension(1:10)::ave
  2. integer count,tt,sy,ey
  3. real:: summ
  1. open(9,file='all_values.csv',status='replace')
  2. num=1
  1. do yr=1,yrmax
  1. do mon=1,monmax
  2. do lat=1,latmax
  3. do lon=1,lonmax
  4. data(lon,lat,mon,yr)=idata(lon,num)
  5. write(9,*) data(lon,lat,mon,yr)
  6. end do
  7. num=num+1
  8. end do
  1. end do
  2. end do
  1. close(9)
  1. end subroutine printallvalues
  1. end module printallvalues_m
  1. module decadalmeantemperature_m
  2. use variables_m
  3. use readbinaryfile_m
  4. use printallvalues_m
  5. implicit none
  6. contains
  1. subroutine decadalmeantemperature()
  1. integer lon,lonmax,xx,yy     ! longitude
  2. integer lat,latmax     ! latitude
  3. integer yr,yrmax       ! year
  4. integer mon,monmax     ! month
  5. integer num            ! arbitral number
  6. integer i,j,k
  7. parameter (lonmax=320) ! num of grids (longitude)
  8. parameter (latmax=160) ! num of grids (latitude)
  9. parameter (yrmax=101)  ! num of years totally
  10. parameter (monmax=12)  ! num of months per year
  11. real:: idata(lonmax,latmax*monmax*yrmax)
  12. real data(lonmax,latmax,monmax,yrmax)
  1. real, dimension(1:10)::ave
  2. integer count,tt,sy,ey
  3. real:: summ
  1. open(10,file='10 Years average.csv',status='replace')
  2. write(10,*) 'Interval',',','Average Decadel Temp'
  1. sy=1
  2. ey=10  
  1. do k=1,10
    1. summ=0.0
    2. count=0
  2. do yr= sy,ey
  1. ave=0.0

.yy=1899+sy

  1. xx=1899+ey
  1. do           mon=1, 12
  2. do           lat=1,160
  3. do           lon=1,320
  4. summ =summ+ data(lon,lat,mon,yr)
  5. count=count+1
  1. end do
  2. end do
  3. end do
  4. end do
  1. sy=ey+1
  1. ey=ey+10
  2. if (ey==100) then
  3. ey=101
  4. end if
    1. ave(k) =summ/count
  5. write(10,*) yy,'-',xx,',', ave(k)
  1. end do
  1. close(10)
  1. end subroutine decadalmeantemperature
  2. end module decadalmeantemperature_m
  1. program envfluidmechanics
  1. use variables_m
  2. use readbinaryfile_m
  3. use printallvalues_m
  1. use decadalmeantemperature_m
  2. call decadalmeantemperature

 

 

  1. end program envfluidmechanics

 

0 Kudos
3 Replies
Arjen_Markus
Honored Contributor II
695 Views

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

0 Kudos
Malik_Ahmad_A_
Beginner
695 Views

Dear Arjen,

Thank you for your quick reply.

 

I made changes in my question.

Please check know

Regards

0 Kudos
Arjen_Markus
Honored Contributor II
695 Views

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

0 Kudos
Reply