Silverfrost Forums

Welcome to our forums

Trouble with Shape

1 Dec 2011 4:40 #9332

This website has an example of how to use the reshape function.

http://www.nsc.liu.se/~boein/f77to90/a5.html#section17

! PROGRAM TO TEST THE OPTIONAL ARGUMENTS TO RESHAPE
  INTERFACE
     SUBROUTINE WRITE_MATRIX(A)
         REAL, DIMENSION(:,:) :: A
     END SUBROUTINE  WRITE_MATRIX
  END INTERFACE

  REAL, DIMENSION (1:9) :: B = (/ 11, 12, 13, 14, 15, 16, 17, 18, 19 /)
  REAL, DIMENSION (1:3, 1:3) :: C, D, E
  REAL, DIMENSION (1:4, 1:4) :: F, G, H

  INTEGER, DIMENSION (1:2) :: ORDER1 = (/ 1, 2 /)
  INTEGER, DIMENSION (1:2) :: ORDER2 = (/ 2, 1 /)
  REAL, DIMENSION (1:16)   :: PAD1 = (/ -1, -2, -3, -4, -5, -6, -7, -8, &
                                 &   -9, -10, -11, -12, -13, -14, -15, -16 /)

  C = RESHAPE( B, (/ 3, 3 /) )
  CALL WRITE_MATRIX(C)

  D = RESHAPE( B, (/ 3, 3 /), ORDER = ORDER1)
  CALL WRITE_MATRIX(D)

  E = RESHAPE( B, (/ 3, 3 /), ORDER = ORDER2)
  CALL WRITE_MATRIX(E)

  F = RESHAPE( B, (/ 4, 4 /), PAD = PAD1)
  CALL WRITE_MATRIX(F)

  G = RESHAPE( B, (/ 4, 4 /), PAD = PAD1, ORDER = ORDER1)
  CALL WRITE_MATRIX(G)

  H = RESHAPE( B, (/ 4, 4 /), PAD = PAD1, ORDER = ORDER2)
  CALL WRITE_MATRIX(H)

  END

  SUBROUTINE WRITE_MATRIX(A)
  REAL, DIMENSION(:,:) :: A
  WRITE(*,*)
  DO I = LBOUND(A,1), UBOUND(A,1)
     WRITE(*,*) (A(I,J), J = LBOUND(A,2), UBOUND(A,2))
  END DO
  END SUBROUTINE WRITE_MATRIX

The expected result is:

  11.0000000  14.0000000  17.0000000
  12.0000000  15.0000000  18.0000000
  13.0000000  16.0000000  19.0000000

  11.0000000  14.0000000  17.0000000
  12.0000000  15.0000000  18.0000000
  13.0000000  16.0000000  19.0000000

  11.0000000  12.0000000  13.0000000
  14.0000000  15.0000000  16.0000000
  17.0000000  18.0000000  19.0000000

  11.0000000  15.0000000  19.0000000  -4.0000000
  12.0000000  16.0000000  -1.0000000  -5.0000000
  13.0000000  17.0000000  -2.0000000  -6.0000000
  14.0000000  18.0000000  -3.0000000  -7.0000000

  11.0000000  15.0000000  19.0000000  -4.0000000
  12.0000000  16.0000000  -1.0000000  -5.0000000
  13.0000000  17.0000000  -2.0000000  -6.0000000
  14.0000000  18.0000000  -3.0000000  -7.0000000

  11.0000000  12.0000000  13.0000000  14.0000000
  15.0000000  16.0000000  17.0000000  18.0000000
  19.0000000  -1.0000000  -2.0000000  -3.0000000
  -4.0000000  -5.0000000  -6.0000000  -7.0000000

Silverfrost doesn't give the same result as the website.

      11.0000         14.0000         17.0000
      12.0000         15.0000         18.0000
      13.0000         16.0000         19.0000

      11.0000         14.0000         17.0000
      12.0000         15.0000         18.0000
      13.0000         16.0000         19.0000

      11.0000         12.0000         13.0000
      14.0000         15.0000         16.0000
      17.0000         18.0000         19.0000

      11.0000         15.0000         19.0000         0.00000
      12.0000         16.0000        -1.00000         0.00000
      13.0000         17.0000        6.611734E-37    6.611657E-37
      14.0000         18.0000         0.00000         0.00000

      11.0000         15.0000         19.0000         0.00000
      12.0000         16.0000        -1.00000         0.00000
      13.0000         17.0000        6.611763E-37    3.098880E-29
      14.0000         18.0000         0.00000         0.00000

      11.0000         12.0000         13.0000         14.0000
      15.0000         16.0000         17.0000         18.0000
      19.0000        -1.00000        6.611792E-37     0.00000
      0.00000         0.00000         0.00000         0.00000

What is the correct answer?

1 Dec 2011 4:48 #9333

My previous post is being truncated.

Here are the Silverfrost results.

      11.0000         14.0000         17.0000
      12.0000         15.0000         18.0000
      13.0000         16.0000         19.0000

      11.0000         14.0000         17.0000
      12.0000         15.0000         18.0000
      13.0000         16.0000         19.0000

      11.0000         12.0000         13.0000
      14.0000         15.0000         16.0000
      17.0000         18.0000         19.0000

      11.0000         15.0000         19.0000         0.00000
      12.0000         16.0000        -1.00000         0.00000
      13.0000         17.0000        6.611734E-37    6.611657E-37
      14.0000         18.0000         0.00000         0.00000

      11.0000         15.0000         19.0000         0.00000
      12.0000         16.0000        -1.00000         0.00000
      13.0000         17.0000        6.611763E-37    3.098880E-29
      14.0000         18.0000         0.00000         0.00000

      11.0000         12.0000         13.0000         14.0000
      15.0000         16.0000         17.0000         18.0000
      19.0000        -1.00000        6.611792E-37     0.00000
      0.00000         0.00000         0.00000         0.00000

What is the correct answer?

1 Dec 2011 8:22 #9334

The 'expected' result looks good. The padding is clearly not working in FTN95. I will log this as a bug to fix.

24 Feb 2012 3:39 #9680

I have fixed this bug for the next release. Took me a while to find it but in the end the fix was to remove one character from a character string.

24 Feb 2012 4:01 #9681

Thanks Paul,

When will the fix be available?

Glen

24 Feb 2012 4:51 #9682

The last release was in December 2011. The Announcements section of this Forum gives an indication of how often releases are made. The interval varies but it is usually from 6 to 12 months from the last release.

Please login to reply.