Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Counter

Help
Beginner
644 Views
Can anyone help me with the logic for counter?
I will explain the scenario first
I have a 2 dimensional array, PRICE(A,B) where array size A=1-10 and B=1-12 and another single dimensional array, RULE(A).
The value of B can only be 0 and 1.
Requirement: If the value of B was 0, then it should be 0 for Rule(A) times. Where A=1-12.
Let us assume that the value of B is {0,0,1,0,1,0,1,0,1,0,1,0} and Rule(A) =3
Expected result: B={0,0,0,0,1,0,0,0,1,0,0,0}
When the B value changes from 1 to 0, it should be locked for A=3 times except for the first time when it is 0, it should be locked for A=3 times.
Below is the current loop. How can I modify it?

IF(RULE(A).GT.1.AND.PRICE(A,B).EQ.0)THEN
DO B= B,RULE(A)
PRICE(A,B)=0
END DO
ENDIF

Thanks in advance
0 Kudos
4 Replies
eos_pengwern
Beginner
644 Views

Maybe it's just me, but I can't make out what it is that you're trying to do.

How can B be an array index if it's just a vector of zeros and ones?

What does it mean for the B value to be locked? And how can it be locked for A=3 times, except for when it is locked for A=3 times?

And what is being counted?

If the question is clearly stated, then we can try to help.
0 Kudos
Help
Beginner
644 Views
Quoting - eos pengwern

Maybe it's just me, but I can't make out what it is that you're trying to do.

How can B be an array index if it's just a vector of zeros and ones?

What does it mean for the B value to be locked? And how can it be locked for A=3 times, except for when it is locked for A=3 times?

And what is being counted?

If the question is clearly stated, then we can try to help.

I am soory, my mistake. B is still an array. I have corrected my statement
Can anyone help me with the logic for counter?
I will explain the scenario first
I have a 2 dimensional array, PRICE(A,B) where array size A=1-10 and B=1-12 and another single dimensional array, RULE(A).
The value of PRICE(A,B) can only be 0 and 1.
Requirement: If the value of PRICE(A,B) was 0, then it should be 0 for Rule(A) times. Where A=1-12.
Let us assume that the value of PRICE(A,B) is {0,0,1,0,1,0,1,0,1,0,1,0} and Rule(A) =3
Expected result: PRICE(A,B)={0,0,0,0,1,0,0,0,1,0,0,0}
When the PRICE(A,B) value changes from 1 to 0, it should be locked for A=3 times except for the first time when it is 0, it should be locked for A=3 times.
Below is the current loop. How can I modify it?

IF(RULE(A).GT.1.AND.PRICE(A,B).EQ.0)THEN
DO B= B,RULE(A)
PRICE(A,B)=0
END DO
ENDIF
0 Kudos
Help
Beginner
644 Views
Quoting - eos pengwern

Maybe it's just me, but I can't make out what it is that you're trying to do.

How can B be an array index if it's just a vector of zeros and ones?

What does it mean for the B value to be locked? And how can it be locked for A=3 times, except for when it is locked for A=3 times?

And what is being counted?

If the question is clearly stated, then we can try to help.

Another correction to Rule(A)
Can anyone help me with the logic for counter?
I will explain the scenario first
I have a 2 dimensional array, PRICE(A,B) where array size A=1-10 and B=1-12 and another single dimensional array, RULE(A).
The value of PRICE(A,B) can only be 0 and 1.
Requirement: If the value of PRICE(A,B) was 0, then it should be locked to 0 for Rule(A) times. Where Rule(A) =1-12.
Let us assume that the value of PRICE(A,B) is {0,0,1,0,1,0,1,0,1,0,1,0}(This is for A=1 and B=1-12) and Rule(A) =3
Expected result: PRICE(A,B)={0,0,0,0,1,0,0,0,1,0,0,0}
When the PRICE(A,B) value changes from 1 to 0, it should be lockedto 0for Rule(A) =3 times except for the first time when it is 0, it should be locked for Rule(A) =3 times.
Below is the current loop. How can I modify it?

IF(RULE(A).GT.1.AND.PRICE(A,B).EQ.0)THEN
DO B= B,RULE(A)
PRICE(A,B)=0
END DO
ENDIF
0 Kudos
eos_pengwern
Beginner
644 Views
Quoting - Help

Another correction to Rule(A)
Can anyone help me with the logic for counter?
I will explain the scenario first
I have a 2 dimensional array, PRICE(A,B) where array size A=1-10 and B=1-12 and another single dimensional array, RULE(A).
The value of PRICE(A,B) can only be 0 and 1.
Requirement: If the value of PRICE(A,B) was 0, then it should be 0 for Rule(A) times. Where Rule(A) =1-12.
Let us assume that the value of PRICE(A,B) is {0,0,1,0,1,0,1,0,1,0,1,0}(This is for A=1 and B=1-12) and Rule(A) =3
Expected result: PRICE(A,B)={0,0,0,0,1,0,0,0,1,0,0,0}
When the PRICE(A,B) value changes from 1 to 0, it should be locked for Rule(A) =3 times except for the first time when it is 0, it should be locked for Rule(A) =3 times.
Below is the current loop. How can I modify it?

IF(RULE(A).GT.1.AND.PRICE(A,B).EQ.0)THEN
DO B= B,RULE(A)
PRICE(A,B)=0
END DO
ENDIF

I'm still a little bit puzzled by the 'locking' part, but here is a first stab at what I think you may be looking for:

do b=1,12
do a=1,10
if (price(a,b).eq.1) then
do k=b,min(12, b+rule(a))
price(a,k)=0
end do
end if
end do
end do

This will make sure that, wherever a value of "price(a,b)=1" is encountered, the '1' will be replaced by a row of 'rule(a)' zeros, unless the row is too short to allow for this.

Is that what you wanted to do?

Stephen.
0 Kudos
Reply