Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change specific array elements from an array column 1

Status
Not open for further replies.

Mechaero2006

Aerospace
Jan 26, 2014
29
The following question is a repost to this FORTRAN dedicated forum (sorry about that)

Hello all,

although it might sound trivial to more experienced users, I am trying to create a code in FORTRAN (preferably f90 or higher) of a n series x 2 columns matrix, where a condition on some elements of column 1, will change the corresponding elements of column 2 (i.e. only those that have the same "i" with the elements affected by the condition). So far I have managed to do this by creating two (2) column arrays containing the elements and by using a simple "where" command I did what I wanted. Could someone please try to inform me how to perform the same job but without spliting the array into two sub-arrays?

Working example code of what I did follows:

Code:
program test
    implicit none
    integer::elem
    real,dimension(:),allocatable::A
    real,dimension(:),allocatable::B
    integer::i,j                    

    elem = 10      

    allocate(A(elem))
    allocate(B(elem))

    do i=1,10
        A(i)=i
        end do

    do j=1,10
        B(j)=0
        end do

where (A>=3 .and. A<=6) B = 1

    deallocate(A,B)            

end program test

Thank you in advance for your kind assistance.
 
Replies continue below

Recommended for you

Code:
program q
    integer :: c(10,2), i, j 
    c(:,1) = (/(i,i=1,10)/)    ;    c(:,2) = 0    
    write(*,'(I2,2x,I2)') ( (c(i,j),j=1,2), i=1,10 )
    where ( c(:,1) >=3 .and. c(:,1) <=6 )  c(:,2) = 1
    write(*,'(I2,2x,I2)') ( (c(i,j),j=1,2), i=1,10 )
end program q
 
Hi gsal! I found it myself and posted my reply to the other thread. Just when I was thinking to join this thread and delete my post, I came across your reply. Nice coding there mate! Thank you very much for your effort!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor