Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

formatted output further??? Thanks.

yingwu
Beginner
380 Views
Hi everyone, I submitted a thread here about the formatted output. At that time, I wanted to display the array, A, in a defined format. Could I make this further? Actually, this is a question I have been looking for for a long long time, so thank ou if you have any idea.

What I want to do is to display any real-type array dynamiclly. I want to develop a subroutine, where I pass the name of a real-type array to the subroutine, then the subroutine can display this array in the format similar with matlab.

I guess the code is something like this

program average
real A(5,2), B(3,4)
call displayArray(A)
call displayArray(B)
end

subroutine displayArray(X)
real X

! the subroutine needs to know the number of rows and columns of X firstly
... ....
! here display the array in the format similar Matlab
... ....

end

I have two difficulties.

1. How to pass the array to the subroutine. Remember the dimensions of the array passed to the subroutine is not fixed, so the subroutine must know its demensions dynamicly.

2. Liz has given me a idea to display the array by using "print '(f6.4,2x,f6.4)', A". However, this is mainly for an array with two columns. In the subroutine, again the number of rows and columns of one array is not fixed. How to do?

Thanks very much.
0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
380 Views

program average
interface
subroutine displayArray(X)
real :: X(:,:)
end subroutine displayArray
end interface
real A(5,2), B(3,4)
call displayArray(A)
call displayArray(B)
end

subroutine displayArray(X)
real :: X(:,:)
integer :: rows, cols, r, c
rows = size(A,1)
cols = size(A,2)
do r=1,rows
do c=1,cols
...
end do
end do
end subroutine displayArray

There are functions to obtain the rank of an array

Jim Demspey


0 Kudos
Reply