Calling a subroutine in Fortran 77

In summary: This can be done using the F90 intrinsic function 'fill'. In summary, The conversation discusses a problem with a Fortran code where the results are incorrect even after using a subroutine from Fortran 77. It is discovered that the issue is with the array not being initialized to 0 in the subroutine. To fix this, the array should be set to 0 before the main loop using the 'fill' function.
  • #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:
Technology news on Phys.org
  • #2
Your problem has nothing to do with F77 vs F90, but rather because array xy is not initialized to 0 in convolvef77.
 
  • #3
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?
 
  • #4
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

Related to Calling a subroutine in Fortran 77

1. What is a subroutine in Fortran 77?

A subroutine in Fortran 77 is a section of code that performs a specific task and can be called by other parts of the program. It allows for code reusability and helps to organize complex programs.

2. How do I call a subroutine in Fortran 77?

To call a subroutine in Fortran 77, you first need to declare it in your program using the "SUBROUTINE" keyword followed by the name of the subroutine. Then, you can use the "CALL" keyword followed by the subroutine name to execute it.

3. Can a subroutine in Fortran 77 have arguments?

Yes, a subroutine in Fortran 77 can have arguments, also known as parameters. These are variables that are passed into the subroutine and can be used in the code to perform specific tasks. This allows for more flexibility and customization in the subroutine.

4. How many arguments can a subroutine in Fortran 77 have?

A subroutine in Fortran 77 can have a maximum of seven arguments. If you need to pass in more variables, you can use the "COMMON" statement to create a shared area of memory between the subroutine and the main program.

5. Can a subroutine in Fortran 77 return a value?

No, unlike functions in other programming languages, subroutines in Fortran 77 cannot return a value. They are solely used to perform a specific task and cannot be used in an expression. If you need to return a value, you can use a function instead.

Similar threads

  • Programming and Computer Science
Replies
4
Views
706
  • Programming and Computer Science
Replies
1
Views
960
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Atomic and Condensed Matter
Replies
3
Views
981
  • Programming and Computer Science
Replies
5
Views
7K
  • Programming and Computer Science
Replies
10
Views
9K
Back
Top