Calling a subroutine in Fortran 77

  • Context: Fortran 
  • Thread starter Thread starter vjvaibhu
  • Start date Start date
  • Tags Tags
    Fortran Subroutine
Click For Summary

Discussion Overview

The discussion revolves around issues encountered when calling a Fortran 77 subroutine from a Fortran 90 code, specifically regarding incorrect results in a convolution operation. Participants explore potential causes and solutions related to array initialization and the handling of zero-based arrays.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports incorrect results when calling the Fortran 77 subroutine from Fortran 90, suggesting a potential issue with the implementation.
  • Another participant asserts that the problem is related to the array 'xy' not being initialized to zero in the 'convolvef77' subroutine.
  • A participant expresses confusion about initializing 'xy' to zero, noting that only the first and last terms of the array receive correct values, and seeks clarification on proper initialization.
  • Further clarification is provided that 'xy' should be set to zero before entering the main loop of the convolution algorithm.

Areas of Agreement / Disagreement

Participants generally agree that the issue is related to the initialization of the 'xy' array, but there is some uncertainty regarding the correct method of initialization and its impact on the results.

Contextual Notes

The discussion highlights the importance of array initialization in Fortran subroutines, particularly when transitioning between Fortran 77 and Fortran 90, but does not resolve the specific implementation details or the underlying cause of the incorrect results.

vjvaibhu
Messages
2
Reaction score
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:
Technology news on Phys.org
Your problem has nothing to do with F77 vs F90, but rather because array xy is not initialized to 0 in convolvef77.
 
DrClaude said:
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?
 
vjvaibhu said:
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   Reactions: harborsparrow

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
1
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 10 ·
Replies
10
Views
10K
  • · Replies 7 ·
Replies
7
Views
2K