- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page