Fortran Calling a subroutine in Fortran 77

AI Thread Summary
The discussion centers around issues encountered when calling a Fortran 77 subroutine from a Fortran 90 code, specifically regarding incorrect results confirmed by MATLAB. The user provided a code snippet involving nested loops and a convolution subroutine, convolvef77. The main problem identified is that the array xy in the subroutine is not initialized to zero, leading to incorrect results. It was suggested that xy should be initialized to zero before entering the main computation loop. The user expressed confusion about initializing xy correctly, as they observed that only the first and last terms were receiving correct values. The resolution emphasizes the need to ensure that xy is reset to zero prior to the convolution calculations to avoid accumulation of incorrect values during iterations.
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 harborsparrow
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Replies
59
Views
11K
Replies
8
Views
4K
Replies
2
Views
2K
Replies
5
Views
8K
Replies
5
Views
3K
Replies
10
Views
10K
Replies
7
Views
2K
Back
Top