Re: Argument of subroutine is an array of unfixed length.
- From: "David Frank" <dave_frank@xxxxxxxxxxx>
- Date: Tue, 28 Jun 2005 11:04:06 GMT
<kurdayon@xxxxxxxxx> wrote in message
news:1119948286.305629.177110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> I would like to write subroutine which takes an one dimensional array
> and gives another where elements are of initial array are ordered in in
> inverse order.
>
> For example:
> (1,2,3,4,4,2)-> (2,4,4,3,2,1).
>
> And I would like my subroutine can perform this action for array of any
> length. Moreover I do not want gives lengths of input array explicitly
> (I would like it is determined automaticaly). How do I need to declare
> variables in this case? Something like this?
>
> subroutine reorder(input_array, output_array)
> implicit none
> input_array, allocatable?, dimension(:)?
> ???
> allocate(input_array(?))
> end subroutine reorder
>
You dont need a subroutine to do this,
below reverse array statement works no matter what array sizes are as long
as they are equal and 1-based.
! ---------------------
program test
integer :: b(6), a(6) = [1,2,3,4,4,2]
b = [a(size(a):1:-1)]
write (*,*) b ! outputs 2 4 4 3 2 1
end program
.
- Follow-Ups:
- Re: Argument of subroutine is an array of unfixed length.
- From: Herman D . Knoble
- Re: Argument of subroutine is an array of unfixed length.
- References:
- Argument of subroutine is an array of unfixed length.
- From: kurdayon
- Argument of subroutine is an array of unfixed length.
- Prev by Date: Re: Announcing Intel Fortran Compilers 9.0
- Next by Date: Re: Efficient Programming
- Previous by thread: Argument of subroutine is an array of unfixed length.
- Next by thread: Re: Argument of subroutine is an array of unfixed length.
- Index(es):
Relevant Pages
|