arctica
Joined: 10 Sep 2006 Posts: 146 Location: United Kingdom
|
Posted: Thu Jan 23, 2025 12:16 pm Post subject: array constructor query |
|
|
Hello
Can I just check if this array constructor , using square brackets is valid. Both methods work. Could not see documentation in the ftn95 help, is this part of 2003?
Code: | module array_flipping
implicit none
contains
! Function to flip an array up-down
function flipud(array) result(flipped)
implicit none
real, intent(in) :: array(:,:)
real :: flipped(size(array,1), size(array,2))
integer :: i, j, rows, cols
rows = size(array, 1)
cols = size(array, 2)
do i = 1, rows
do j = 1, cols
flipped(i, j) = array(rows - i + 1, j)
end do
end do
end function flipud
! Function to flip an array left-right
function fliplr(array) result(flipped)
implicit none
real, intent(in) :: array(:,:)
real :: flipped(size(array,1), size(array,2))
integer :: i, j, rows, cols
rows = size(array, 1)
cols = size(array, 2)
do i = 1, rows
do j = 1, cols
flipped(i, j) = array(i, cols - j + 1)
end do
end do
end function fliplr
end module array_flipping
program test_flipping
use array_flipping
implicit none
real :: array(3,3)
real :: flipped_ud(3, 3), flipped_lr(3, 3)
integer :: i
array=reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
!array=reshape((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
! For a 3x3 array dim1 = dim2
print *, "Original Array:"
do i = 1, size(array,1)
write(*, '(3F10.5)') array(i, :)
end do
flipped_ud = flipud(array)
print *, "Flipped Up-Down:"
do i = 1, size(array,1)
write(*, '(3F10.5)') flipped_ud(i, :)
end do
flipped_lr = fliplr(array)
print *, "Flipped Left-Right:"
do i = 1, size(array,1)
write(*, '(3F10.5)') flipped_lr(i, :)
end do
end program test_flipping
|
Testing functions to replicate the Matlab/Scilab style flipup/fliplr.
Lester
Last edited by arctica on Thu Jan 30, 2025 1:35 pm; edited 1 time in total |
|