replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - array constructor query
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

array constructor query

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
arctica



Joined: 10 Sep 2006
Posts: 146
Location: United Kingdom

PostPosted: Thu Jan 23, 2025 12:16 pm    Post subject: array constructor query Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8184
Location: Salford, UK

PostPosted: Thu Jan 23, 2025 12:37 pm    Post subject: Reply with quote

Google AI says square brackets were introduced in Fortran 2003.
Back to top
View user's profile Send private message AIM Address
arctica



Joined: 10 Sep 2006
Posts: 146
Location: United Kingdom

PostPosted: Thu Jan 23, 2025 12:44 pm    Post subject: Reply with quote

Good to know Paul
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group