Home > Archive > Fortran > May 2004 > How to declare my_reshape()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to declare my_reshape()
|
|
| Victor 2004-05-12, 9:09 pm |
| Question to all Fortran95 gurus:
I want to define a function that will return an array whose shape is not known
to at compile time. In the simplest example, I just want to wrap around
intrinsic reshape:
function my_reshape(x,y) result (z)
! declarations here ????
z = reshape(x,y)
end my_reshape
Is this possible in fortran 95?
Victor
| |
| James Van Buskirk 2004-05-12, 9:09 pm |
| "Victor" <me@privacy.org> wrote in message
news:c7sjmh$3ick$1@sp15en20.hursley.ibm.com...
> function my_reshape(x,y) result (z)
> ! declarations here ????
> z = reshape(x,y)
> end my_reshape
Fortran doesn't suffer the program to create arrays of
rank unknown at compile time. Thus your program can only
work if the size of y is known. You could, for example,
try:
function my_reshape(x,y) result (z)
! declarations here ????
integer, intent(in) :: y(3)
real, intent(in) :: x(product(y))
real z(size(y,1), size(y,2), size(y,3))
z = reshape(x,y) ! Returns a rank-3 result.
end my_reshape
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
| |
| Victor 2004-05-12, 9:09 pm |
| James Van Buskirk wrote:
> Fortran doesn't suffer the program to create arrays of
> rank unknown at compile time. Thus your program can only
> work if the size of y is known.
What a pity :-) Thanks!
Victor
| |
| jan van oosterwijk 2004-05-12, 9:09 pm |
| "James Van Buskirk" <not_valid@comcast.net> wrote in message news:<27loc.75908$Ik.5480812@attbi_s53>...
> "Victor" <me@privacy.org> wrote in message
> news:c7sjmh$3ick$1@sp15en20.hursley.ibm.com...
>
>
> Fortran doesn't suffer the program to create arrays of
> rank unknown at compile time. Thus your program can only
> work if the size of y is known. You could, for example,
> try:
James:
The following is undoubtedly improvised:
> function my_reshape(x,y) result (z)
> ! declarations here ????
> integer, intent(in) :: y(3)
> real, intent(in) :: x(product(y))
> real z(size(y,1), size(y,2), size(y,3))
> z = reshape(x,y) ! Returns a rank-3 result.
> end my_reshape
A version accepted by a compiler:
! Van:James Van Buskirk (not_valid@comcast.net)
! Onderwerp:Re: How to declare my_reshape()
! Discussies:comp.lang.fortran
! Datum:2004-05-12 01:20:14 PST
function my_reshape(x,y) result (z)
! declarations here ????
integer, intent(in) :: y(3)
! real, intent(in) :: x(product(y)) ! Product not allowed :-(
real, intent(in) :: x(y(1)*y(2)*y(3))
real :: z(y(1), y(2), y(3))
! real z(size(y,1), size(y,2), size(y,3)) ! Y has only one size
z = reshape(x,y) ! Returns a rank-3 result.
end function my_reshape
[JvO] transfer((/ 778985834, 1869504886, 1702130543, &
1785296754, 1635205227, 1868849518, 1819160175 /), (/'x'/) )
| |
| Victor 2004-05-13, 4:41 am |
| James, Jan, Matthew:
Thanks for your answers! Turns out f95 is not APL despite all efforts :-(
Victor
|
|
|
|
|