Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Duplicate certain values of an array and increase second counter

Status
Not open for further replies.

G2M2

Technical User
Oct 8, 2009
2
US
Hi
I have one array "A" with N values and another one "B" with also N values. The values in "B" are a flag (let's say YES or NO) to decide if a certain position n, 1<n<N has to be written twice in a third array "C" of dimension M>N
Something like this:
DO n=1,N m=1,M
IF B(n) = NO then
C(m) = A(n)
IF B(n) = YES then
C(m) = A(n)
C(m+1) = A(n)

My problem is that i don't know where to include the counter "m" and how to make it advance "1" when "n" advances to the next iteration in the first IF case and "2" in the second IF case.

Probably there is a better way to do this, but i am not being able of figuring it out.

Any advise?

Thank you very much

 
I think this could help you
Code:
m = 1
do n=1,N
  if B(n) = NO then   
    C(m) = A(n)
    m = m+1
  if B(n) = YES then   
    C(m) = A(n) 
    C(m+1) = A(n)
    m = m+2
end do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top