×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

#### Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!
• Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

# FORTRAN: condition on array elements in one column changes corresponding elements in other column

 Forum Search FAQs Links MVPs

## FORTRAN: condition on array elements in one column changes corresponding elements in other column

(OP)
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 --> fortran

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.

### RE: FORTRAN: condition on array elements in one column changes corresponding elements in other column

probably something like this in psuedocode:

do blah
A=i
if A>=3 .and. A<=6 then
B=1
else
B=0
end if
end do

FWIW there is a Fortran forum: forum545: Fortran

TTFN
I can do absolutely anything. I'm an expert!
homework forum: //www.engineering.com/AskForum/aff/32.aspx
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers

### RE: FORTRAN: condition on array elements in one column changes corresponding elements in other column

(OP)
Thanks for your reply. I'll try your suggestion and repost my question to the forum dedicated to FORTRAN programming.

### RE: FORTRAN: condition on array elements in one column changes corresponding elements in other column

(OP)
Found it:

#### CODE --> f95

program test
implicit none
integer::elem,i
real,dimension(:,:),allocatable::A
elem = 10
allocate(A(elem,2))
FORALL(I = 1:elem) A(I, 1) = i
FORALL(I = 1:elem) A(I, 2) = 0
print*,A
where (A(:,1)>=3 .and. A(:,1)<=6) A(:,2) = 1
print*,A
deallocate(A)
end program test 

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

### Reply To This Thread

#### Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.