Calling a subroutine in Fortran 77

  • Fortran
  • Thread starter vjvaibhu
  • Start date
  • #1
vjvaibhu
2
0
I am calling a fortran 77 subroutine in a fortran 90 code and the results i am getting are wrong as confirmed from matlab. Can anybody please let me know where is the problem?

Fortran:
do isss=1,5
    do ig=1,10
        dat0=dat(:,ig,isss)
        do iss=1,5                 
                if ((ig>isss) .and. (ig>iss) .and. (iss>isss)) then
                    dat1=dat(:,ig,iss)
                    temp=dat1(10:1:-1)
                    call convolvef77(dat0, m, temp, m, xcorr)
                    vshot(:,isss,iss)=xcorr(10:19)+vshot(:,isss,iss)
                end if
        end do
    end do
end do
!
Fortran:
    subroutine convolvef77 (x, lx, y, ly, xy)
c
c A basic implementation of convolution algorithm for two vectors
c I use zero-based arrays here.
c
      integer lx, ly, i, j
      real x(0:lx-1), y(0:ly-1), xy(0:lx+ly-2)
 
      do 20 i = 0, (lx-1)
         do 15 j = 0, (ly-1)
            xy(i+j) = xy(i+j) + x(i) * y(j)
  15     continue
  20  continue

      end
 
Last edited by a moderator:

Answers and Replies

  • #2
DrClaude
Mentor
8,124
4,947
Your problem has nothing to do with F77 vs F90, but rather because array xy is not initialized to 0 in convolvef77.
 
  • #3
vjvaibhu
2
0
Your problem has nothing to do with F77 vs F90, but rather because array xy is not initialized to 0 in convolvef77.
Thank you for your quick reply. When i am initializing xy to 0, only first and last terms of the array are getting correct value because every time j iterates it makes xy(i+j)=0. How should I initialize it then?
 
  • #4
DrClaude
Mentor
8,124
4,947
Thank you for your quick reply. When i am initializing xy to 0, only first and last terms of the array are getting correct value because every time j iterates it makes xy(i+j)=0. How should I initialize it then?
You need to set xy to 0 before the main loop.
 
  • Like
Likes harborsparrow

Suggested for: Calling a subroutine in Fortran 77

Replies
8
Views
791
Replies
19
Views
910
  • Last Post
Replies
2
Views
1K
Replies
5
Views
1K
  • Last Post
Replies
12
Views
592
  • Last Post
Replies
2
Views
962
  • Last Post
Replies
8
Views
610
  • Last Post
Replies
4
Views
624
Replies
6
Views
5K
Top