forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is it possible to get data points from a graph?
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Jul 31, 2009 5:48 pm    Post subject: Is it possible to get data points from a graph? Reply with quote

Im am plotting data using the simpleplot facilities of Clearwin+ and I want to
mark two points in a curve with a mouse click on the graph, take the data points between these limits and perform the fit of the data in the range marked in the plot. I have checked some subroutines of simpleplot but I do not find how to do this. Have anyone tried to pick up data points from a graph made using clearwin?

Thanks in advance!

Agustin
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Sat Aug 01, 2009 7:57 am    Post subject: Reply with quote

Here is a sample program that uses full_mouse_input...

Code:
      options(implicit_none)
      winapp
c-----------------------------------------------------------------
      include <clearwin.ins>
      include 'gr6.ins'
      integer i
      external gr_func

      cstat=' '
      mstat=0

      i=winio@('%ww[no_border]&')
      i=winio@('%ca[LINE SELECTION]&')
      i=winio@('%mn[E&xit]&','EXIT')
      i=winio@('%ob&')
      i=winio@('%^gr[black,line_selection,full_mouse_input]&',
     +         300,300,gr_func)
      i=winio@('%cb%ob[status]%20st%cb',cstat)
      end
c-----------------------------------------------------------
      integer function gr_func()
      include <windows.ins>
      include 'gr6.ins'
      integer x1,y1,x2,y2,nstat

      call get_mouse_info@(x1,y1,nstat)
      write(cstat(1:30),'(3I7)') x1,y1,nstat
      call window_update@(cstat)

      if(and(nstat,MK_LBUTTON).EQ.0.AND.and(mstat,MK_LBUTTON).NE.0)then
        call get_graphics_selected_area@(x1,y1,x2,y2)
        call set_graphics_selection@(0)
        call draw_line@(x1,y1,x2,y2,12)
        call set_graphics_selection@(2)
      endif
      mstat=nstat

      gr_func=1
      end



gr6.ins contains...

Code:
      integer mstat
      character*30 cstat
      common/control/ mstat,cstat
Back to top
View user's profile Send private message AIM Address
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Sat Aug 01, 2009 7:06 pm    Post subject: Reply with quote

Thank you Paul for your code, but it is not what I mean. I have no problems with mouse input, in fact with my program I can get windows coordinates with no problems. The point is how can I transform these "pixel" or "window" coordinates into "data" coordinates. i.e. if I have a graph about Temperature and Presure, when I click with the mouse and get x=200 and y=300 (window pixels) I get T=315 and P = 0.5 as a result. Do you follow what I mean?

Agustin
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Sat Aug 01, 2009 8:16 pm    Post subject: Reply with quote

Sorry, I don't know how I missed your reference to SimplePlot.

Off hand I don't know how to work out the transformation but %gp may be useful; also clearwin_info@('SCREEN_WIDTH') and clearwin_info@('SCREEN_DEPTH').

There is also get_window_location@ used together with %lc.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Aug 01, 2009 11:37 pm    Post subject: Reply with quote

Paul,
I don't think it registered with you that Agustin was using Simpleplot - I'm guessing that you read it that he was using “simple plot” routines! I read your first reply, and was amazed to imagine that the mouse worked the same in a Simpleplot window as a %gr window – and I guess that it doesn’t.

Agustin,
In the documentation area of the Silverfrost website you will find a range of documents on Simpleplot. In some of them, mention is made of a routine GETXY for interaction using the mouse in a Simpleplot window. This is a Simpleplot (i.e. BUSS) routine not a Silverfrost one, as it doesn't end with @. One of the difficult things to discover is precisely what is present in the “bundled” version, and what extra facilities were in the full version. Whether or not GETXY is included in the bundled mini version of Simpleplot that is supplied with FTN95 I don't know. You should probably start by downloading all the Simpleplot documentation and read it all. You may find the answer there - although if the routine is available only in the full Simpleplot then you continue to have a problem.

In the Simpleplot documentation, it talks about placing Simpleplot graphics into a conventional %dw window. This is in the document "Using Simpleplot with FTN95" in section 5.2.3. There is sample code there and a tutorial. I don't like %dw - it doesn't work properly with all the Silverfrost routines - so maybe it is worth trying with %gr instead. Then you can use the method Paul gave you for getting the mouse position.

When drawing any graphics, you always have to do a conversion from real world coordinates to pixels, both for scaling and for shifting the origin. To get back, reverse the process. Remember that the mouse position is given to 1 pixel accuracy, and this isn't very good (usually) in real world coordinates, so you may have to make an intelligent decision about what the real world equivalent should be and round (up or down) your mouse position accordingly.
I keep the conversions in “statement functions”, so, for example,
Code:
       IPOSX(XX) = (XX - X_CENTRE)/SCREEN_SCALE_X + IXRES/2
       IPOSY(YY) = IYRES/2 - (YY-Y_CENTRE)/SCREEN_SCALE_Y

give me the pixel coordinates of a point with real life coordinates (XX,YY) in a window of size (IXRES , IYRES). The scales for X and Y are possibly different (hence SCREEN_SCALE_X and _Y) and these have to be worked out from the range of X and Y coordinates, and whether the aspect ratio is fixed or not. My statement functions centre my plottable object in the window, and take account of the fact that my Y coordinates increase upwards, although the screen y-coordinates increase downwards. (I forget about whether or not the coordinates start at 1 or 0 !)

Reversing things is a matter of getting the pixel coordinates, and then getting the real life coordinates. In one of my programs this is done with
Code:
       IXP = CLEARWIN_INFO@ ('GRAPHICS_MOUSE_X')
       IYP = CLEARWIN_INFO@ ('GRAPHICS_MOUSE_Y')
       RX = (IXP-ixres/2)*SCREEN_SCALE + X_CENTRE
       RY = Y_CENTRE - (IYP-iyres/2)*SCREEN_SCALE

As I understand Simpleplot, the actual graph is plotted in (say) 60% of the available window pixels, so you need to take that into account as well when back-calculating the real world coordinates.

You may find this rather easier if you program the graphing yourself (in a %gr region) rather than using Simpleplot! (or try using SIMDEM).

Regards
Eddie

PS. It is always useful to download the FTN77 documentation as well. There are facilities still in FTN95 that come from the past, and which aren't always documented in FTN95.CHM.

E
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Tue Aug 04, 2009 2:34 pm    Post subject: Reply with quote

Thank you Ed for your comments. I will probably try your suggestion after finishing my tries with Simpleplot. I know the getxy subrooutine that should be used along with kxyxy to obtain the mouse position coordinates (getxy) and convert to user defined coordinates (kxyxy) but...it seems that, at least with clearwin windows such as %gr and %pl, does not work. I will give a look to %dw although you think it is not the best way to work with graphics windows. For your information, the Simpleplot library that comes with FTN95 is, as far as I know, complete, i.e. it is the same that BUSS used to provide to their users. I bougth Simpleplot long time ago (1993?) and the last version I got was 2.15, which is not very different from the last version BUSS produced after they closed. Although I have the full documentation of Simpleplot, the manuals were not the best ones for understanding how every subroutine worked. However, I think that graphics are done easier with Simpleplot than with FTN95 facilities. Am I wrong?

Agustin
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Aug 04, 2009 6:39 pm    Post subject: Reply with quote

Agustin,

If you are just drawing a graph, then Simpleplot has to be easier than doing it yourself. However, if you want to interact with the graph, then in my view doing it yourself is best.

A quick fix might be to ask the user to input the values for redrawing the graph rather than picking them up with the mouse. Best of luck.

Eddie
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Tue Aug 04, 2009 9:00 pm    Post subject: Reply with quote

well, in fact I was thinking precisely about that, i.e. see the graph and input the upper and lower values that one like to fit (for instance). Thanks for your comments.

Agustin
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2815
Location: South Pole, Antarctica

PostPosted: Sat Sep 05, 2009 5:26 am    Post subject: Re: Reply with quote

PaulLaidler wrote:

include <clearwin.ins>
include 'gr6.ins'


Where is gr6.ins - compilation failed ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Sat Sep 05, 2009 6:57 am    Post subject: Reply with quote

The include file is also listed in my post.
Back to top
View user's profile Send private message AIM Address
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Oct 02, 2009 11:32 pm    Post subject: Reply with quote

Well, well, I eventually found how to get the x,y values of a point in a plot using Clearwin and Simpleplot! Just in case someone find it useful....

Agustin

module clearwin_sp
!Contains definition of values to pass to DDDATA
INTEGER SIMPLE_WINDOWS_SET_WINDOWNAME
PARAMETER(SIMPLE_WINDOWS_SET_WINDOWNAME = 6)
INTEGER SIMPLE_WINDOWS_SET_HDC_DIM
PARAMETER(SIMPLE_WINDOWS_SET_HDC_DIM = 7)
INTEGER SIMPLE_WINDOWS_END_LIST
PARAMETER(SIMPLE_WINDOWS_END_LIST = 0)
! Useful definition of data structure to hold BitmapDC to pass to SIMPLEPLOT
INTEGER*4 iBitmapDC, iWidth, iHeight
contains
subroutine ini_bitmap
use mswin
iWidth=GetSystemMetrics(SM_CXSCREEN)*0.75
iHeight=GetSystemMetrics(SM_CYSCREEN)*0.75
ibitmapdc=GET_BITMAP_DC@(INTS(iWidth),INTS(iHeight))
end subroutine ini_bitmap
! ******************* SP_SupplyBitmap ***********************
! Set up a Static (SAVEd) parameter block consisting of an array of pairs of
! integers. Each pair of integers consists of a function number followed by an
! optional address of a data structure.
! The parameter block address is passed to SIMPLEPLOT by SUBROUTINE DDDATA.
!
! In this example:
! SIMPLE_WINDOWS_SET_HDC_DIM specifies that the next integer is the address
! of a data structure consisting of a Bitmap DC followed by its dimensions
! SIMPLE_WINDOWS_END_LIST is the mandatory end of list item which does not
! require the address of a structure
SUBROUTINE SP_SupplyBitmap ! Pass Bitmap to SIMPLEPLOT
INTEGER*4 iParams(4)
SAVE iParams
iParams(1) = SIMPLE_WINDOWS_SET_HDC_DIM ! hDC + dimensions
iParams(2) = LOC(iBitmapDC) ! Address of PARAMETER block
iParams(3) = SIMPLE_WINDOWS_END_LIST! End of list
CALL DDDATA(LOC(iParams(1)))! Notify SIMPLEPLOT
CALL DEVNAM('WINDOW') ! Select Window
CALL OWNNEW(.TRUE.) ! Inhibit 'Continue' button
END subroutine sp_supplybitmap
! ********************* Update Window **********************
! This subroutine is called whenever the bitmap is to be copied to the screen.
! Until this is called, none of the graphics produced by SIMPLEPLOT is visible
SUBROUTINE UpdateWin
CALL OUTBUF ! Flush buffers
CALL WINDOW_UPDATE@(iBitmapDC) ! Copy Bitmap to window
END subroutine updatewin
end module clearwin_sp

program getxy
use clearwin_sp
LIBRARY 'C:\simple.dll'
integer ans
external get_xy
call ini_bitmap
call sp_supplybitmap
ans=winio@('%ww%ca[My program GetXY]&')
ans=winio@('%^dw&',ibitmapdc,get_xy)
ans=winio@('%ff%cn%bt[OK]')
end program getxy

integer function get_xy()
use mswin
use clearwin_sp
real*4,dimension(50) ::dat_x,dat_y
real ::minx,maxx,miny,maxy
character*6 ::xt,yt
integer f
do i=1,50
dat_x(i)=i+20
dat_y(i)=i*3+52
end do
f=50
minx=MINVAL(dat_x)
maxx=MAXVAL(dat_x)
miny=MINVAL(dat_y)
maxy=MAXVAL(dat_y)
CALL INITSP
call axsbtk('XC','I')
call axsbtk('YC','I')
call axlbjs('X','C')
call textmg(1.5)
CALL CHSET(0)
call textmg(2.0)
CALL SCALES(minx,maxx,1,miny,maxy,1)
CALL NEWPIC
CALL AXIS7('XC','x')
CALL AXIS7('YC','y')
call pen(2)
CALL MARKCV(real(dat_x,1),real(dat_y,1),f,5,1)
CALL TITLE7('O','C','Test of Get_XY')
call updatewin
ibutton=and(clearwin_info@('graphics_mouse_flags'),31)
!click on the mouse right button to show the picture on screen
if(ibutton.ne.1) return
!click on the left button to pick the points on the plot
ix=clearwin_info@('graphics_mouse_x')
iy=iheight-clearwin_info@('graphics_mouse_y')
call kxyxy(1,real(ix),real(iy),5,rx,ry)
print*,rx,ry
call markpt(rx,ry,5)
CALL KREAL(RX,XT)
CALL KREAL(RY,YT)
xl=len(xt)
yl=len(yt)
total=xl+yl+1
call caplbm(rx,ry-4,15,xt//','//yt,total)
call updatewin
get_xy=1
end function get_xy
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2815
Location: South Pole, Antarctica

PostPosted: Sun Oct 04, 2009 10:35 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
The include file is also listed in my post.

Oops...

But why the code does not work if substutute "include <clearwin.ins>" to "use clrwin" (undefined variables)?
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Mon Oct 05, 2009 12:50 am    Post subject: Reply with quote

You should set "use mswin" and not "use clrwin" as the module with the clearwin+ code is called mswin. Clearwin.ins was part of FTN77 (when modules did not exist) not FTN95 (or FTN90 in the very early days....).

Agustin
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2815
Location: South Pole, Antarctica

PostPosted: Fri Oct 09, 2009 4:05 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
Here is a sample program that uses full_mouse_input...

Code:
      options(implicit_none)
      winapp
c-----------------------------------------------------------------
      include <clearwin.ins>
      include 'gr6.ins'
      integer i
      external gr_func

      cstat=' '
      mstat=0

      i=winio@('%ww[no_border]&')
      i=winio@('%ca[LINE SELECTION]&')
      i=winio@('%mn[E&xit]&','EXIT')
      i=winio@('%ob&')
      i=winio@('%^gr[black,line_selection,full_mouse_input]&',
     +         300,300,gr_func)
.........................
.........................


How best way to get program react also on keyboard input when full_mouse_input is used?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Fri Oct 09, 2009 4:31 pm    Post subject: Reply with quote

In the same window use %mg with WM_KEYDOWN and/or WM_SYSKEYDOWN.

Look these up in MSDN and find out what the wparam and lparam in the message are. Then in your callback for %mg, get the wparam and lparam from clearwin_info@("MESSAGE_WPARAM") etc.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group