Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

waitonmouseevent

Robert
Beginner
863 Views
I am trying to understand the following sample code from the on-line documentation. When compiled as a Quick Win program it runs. Can someone please explain the code? INTEGER(4) mouseevent, keystate, x, y mouseevent = MOUSE$RBUTTONDOWN .OR. MOUSE$LBUTTONDOWN result = WAITONMOUSEEVENT (mouseevent, keystate, x , y) if ((MOUSE$KS_SHIFT .AND. keystate) == MOUSE$KS_SHIFT) then write (*,*) 'Shift key was down' endif if ((MOUSE$KS_CONTROL .AND. keystate) == MOUSE$KS_CONTROL) then write (*,*) 'Ctrl key was down' endif 1) Please explain: mouseevent = MOUSE$RBUTTONDOWN .OR. MOUSE$LBUTTONDOWN i.e. what does it mean to .OR. two symbolic constants and set that equal to mouseevent which is INTEGER(4). And how does that work? 2)How are the tests in the IF statements made? Thank you.
0 Kudos
5 Replies
Steven_L_Intel1
Employee
863 Views

This example has so much wrong with it I hardly know where to start. The misuse of logical operations on integers, which we support as an extension, is the least of it. There are numerous syntax errors as well. I will have it replaced.

Basically, the .OR. should be replaced with references to the IOR intrinsic and the .AND. replaced with IAND. 

0 Kudos
Steven_L_Intel1
Employee
863 Views

This is what it should be:

   USE IFQWIN
   INTEGER(4) mouseevent, keystate, x, y, result
   !...
   mouseevent = IOR(MOUSE$RBUTTONDOWN,MOUSE$LBUTTONDOWN)
   result = WAITONMOUSEEVENT (mouseevent, keystate, x , y)
 !
 ! Wait until right or left mouse button clicked, then check the keystate
 ! with the following:
 !
   if (IAND(MOUSE$KS_SHIFT,keystate) == MOUSE$KS_SHIFT)       &
  & write (*,*) 'Shift key was down'
   if (IAND(MOUSE$KS_CONTROL,keystate) == MOUSE$KS_CONTROL)   &
  & write (*,*) 'Ctrl key was down'
  end

 

0 Kudos
JVanB
Valued Contributor II
863 Views

When Fortran was the only language I knew, I remember that reading about logical and shift operations (in the machine language sense, not the high level language sense) was a revelation to me. Instead of thinking about an INTEGER variable as a number having a value, you can think of it as an array of BIT_SIZE(I) logical values, or flags. Same variables, just different way to think about them.

ORing two integer variables results in a variable whose set flags are the union of the set flags of the inputs. For two inputs IOR(A,B) achieves this. For any number of inputs, f2008 provides IANY([A,B,C,D]) (as an example with 4 inputs).

ANDing two integer variables results in a variable whose set flags are the intersection of the set flags of the inputs. For two inputs use IAND(A,B); for any number of inputs, IALL([A,B,C,D]).

There is also IEOR(A,B) to toggle bits, IPARITY for any number of inputs.

Thus in the above, MOUSE$RBUTTONDOWN and MOUSE$LBUTTONDOWN each have, I assume, 1 bit (flag) set in them so the WAITONMOUSEEVENT invocation ends up checking for both events because those are the two flags that are set in mouseevent. IAND(MOUSE$KS_SHIFT,keystate) will equal MOUSE$KS_SHIFT exactly when all the bits (flags) that are set in MOUSE$KS_SHIFT are also set in keystate.

So this way of thinking about integer variables is sort of a set of logical operations on a fixed size array. A Possible reference is http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CCwQFjAC&url=http%3A%2F%2Fwww.cs.uwm.edu%2Fclasses%2Fcs215%2Fslides%2F14%2520-%2520Arithmetic%2520%26%2520Logic%25201.ppt&ei=81TKVPS4MJe2yASYuIGgDA&usg=AFQjCNGOT8mICel1yne6WHk8aWDQRh-stQ&bvm=bv.84607526,d.aWw

0 Kudos
Robert
Beginner
863 Views

Steve and Repeat Offender:

Thank you for the replies. They are very helpful and fully explain everything.

By the way is there a document that gives tips on how to format posts to the forum?  I would like to know how Steve inserted his code snip into his post, and how to start a new line without inserting a blank line (like the blank line between the lines Regards and Bob below).

Regards,

Bob. 

0 Kudos
Steven_L_Intel1
Employee
863 Views

When you enter a post, there is a row of buttons for various formatting options. The second from the right is the Code button. Click that, select Fortran from the dropdown, and paste your code into that.

0 Kudos
Reply