2

In my program subroutine stlstp passing work(2,1) as parameter to stlfts(...) subroutine. work(2,1) will be double value at that index, but how subroutine converting it as single dimension array x(n)?

When I print x value in stlfts(...) subroutine, it is printing elements of n size, example:

 STLFTS....X,,,   0.0000000000000000        1.4964418382246345E-317   1.48978578
58438612E-317   1.4964339331743010E-317   1.4964418382246345E-317   4.3367611401 ....

My understanding is, except 1st value, all other values in this x are garbage, but not sure how this assignment will will effect original reference? can someone please help me with this?

subroutine stlstp(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,nljump,ni,userw,rw,season,trend,work)

!     implicit none
! Arg
      integer n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,nljump,ni
      logical userw
      double precision y(n),rw(n),season(n),trend(n),work(20,5)
! Var
      integer i,j

     do 80 j = 1,1
         do 1 i = 1,n
              work(i,1) = y(i)-trend(i)
 1       continue
         call stlss(y,n,np,ns,isdeg,nsjump,userw,rw,season)

         PRINT *, 'WORK 1,2 ....',work(1,2)
         PRINT *, 'WORK ....',work
         call stlfts(work(1,2),n+2*np,np,work(1,3),work(1,1))

Now stlfts subroutine code is:

  subroutine stlfts(x,n,np,trend,work)
    integer n, np
    double precision x(n), trend(n), work(n)
    PRINT *, 'STLFTS....X,,,',x 
    call stlma(x,    n,      np, trend)
  end

1 Answer 1

3

Thanks, to IanH for the direction to the standard (Fortran 2008 12.5.2.11(1)), the answer was wrong in the statement about the standard conformance:

An actual argument represents an element sequence if it is an array expression, an array element designator, a default character scalar, or a scalar of type character with the C character kind (15.2.2). If the actual argument is an array expression, the element sequence consists of the elements in array element order. If the actual argument is an array element designator, the element sequence consists of that array element and each element that follows it in array element order.

This means this praxis is standard conforming and this is a legal way how to pass a part of an array starting from some element.

The situation can be explained to C programmers as the subroutine stlstp passing the address of the actual point in the original array.

The subroutine stlfts then interprets the address as an address of a part of the original array of length n. It will be the first n elements in the column major order starting from the element (1,2). This way it gets access to other elements of the original array WORK and the result will not be garbage.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks! Yes it is pretty old code, I am trying to reverse engineer it.Can you point me to some example on internet to understand more about "It will be the first n elements in the column major order starting from the element (1,2)"? An example in action will help me to quickly understand the concept.
en.wikipedia.org/wiki/Row-major_order#Column-major_order Otherwise just understand it as passing &work[2][1] and expecting double x[n] or double *x in C (provided work is contiguous as old Fortran arrays are).
Thank you! I think I am little bit clear on this topic. I am writing a quick small example to validate my understanding.
I am assuming same principle applies to "single dimension arrays" too. Am I correct?
Sure, it is even simpler for them.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.