forums.silverfrost.com
Welcome to the Silverfrost forums

 How do refresh a simplepot graph with new data? Goto page 1, 2  Next
Author Message
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

Posted: Tue Aug 11, 2015 12:29 pm    Post subject: How do refresh a simplepot graph with new data?

Hi all,
consider we create a x-y line plot with %pl and regularily new x and y values were available. The graph should refresh itself and show the latest data set.

When I code like this (I am not using %gr)

 Code: Do   sleep@ 5 ! wait for new data   read ... x,y   i=winio@(%pl ....) enddo

I'm getting a new plot aside the old one and the graphics window gets bigger and bigger. For me it would be ok if a new graph is plotted, however it must remain at the initial position. Must I use %gr and if, how?
Kenneth_Smith

Joined: 18 May 2012
Posts: 174
Location: Glasgow, Scotland.

Posted: Tue Aug 11, 2015 7:39 pm    Post subject:

This might help.

 Code: program test     integer n,winio@,i, j     parameter(n=50)     real x(n),y(n)             do j = 1, 3, 1        do i=1,n          if (j .eq. 1) then            x(i)=i-1            y(i)=x(i)**2          else if (j .eq. 2) then            y(i) = sqrt(x(i))          else            y(i) = x(i)          end if        enddo        call plot_poly (x,y,n)      end do            end program test            subroutine plot_poly (x,y,n)      implicit none      real,    intent(in), dimension(1:n) :: x      real,    intent(in), dimension(1:n) :: y      integer, intent(in) :: n      real*8,  allocatable::xr8(:)      real*8,  allocatable::yr8(:)      integer  i, winio@, alloc_stat        allocate(xr8(n),stat=alloc_stat)        if (alloc_stat.gt.0) stop 'failed to allocate xr8 in plot_poly'                allocate(yr8(n),stat=alloc_stat)        if (alloc_stat.gt.0) stop 'failed to allocate yr8 in plot_poly'        xr8 = x        yr8 = y              i=winio@('%ca[simpleplot]%bg[grey]&')        i=winio@('%pl[x_array,colour=blue,title="plot",x_axis=r,y_axis=x],&', 500,300,n,xr8,yr8)        i=winio@('%ff%nl%cn%tt[ok]')        deallocate(xr8,yr8)      end subroutine plot_poly
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

 Posted: Fri Aug 14, 2015 10:13 am    Post subject: Hi Kenneth, thanks for the code, but it didn't hit my question exactly: I do not want to press [ok] to see the next graphs. They should appear automatically as long there are new data. regards, johannes
LitusSaxonicum

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

 Posted: Fri Aug 14, 2015 10:24 am    Post subject: Hi Johannes, Then set a flag to say if there is new data, and put a timer on the window with %dl, and if there is new data waiting to be plotted, (which the callback to the timer can find from the flag) then replot everything. Don't forget to unset the flag after plotting! If you have a short enough interval, it will appear to be instant update. Eddie
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

 Posted: Fri Aug 14, 2015 4:04 pm    Post subject: post deletedLast edited by johannes on Fri Aug 14, 2015 7:15 pm; edited 1 time in total
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

Posted: Fri Aug 14, 2015 5:17 pm    Post subject:

This code is doing, but I don't know how to stop properly if finish==1
 Code: Module data      integer,parameter :: n=10      real*8 ::  x(n)=0., y(n)=0.      integer :: i, winio@, newdataflag,icall,finish end Module program test  USE data  external lookup  icall=1 ; finish=0     i=winio@('%dl', 0.1d0, lookup)     !HOW TO EXIT IF finish==1?    !- call plot_poly ()  end program test       subroutine plot_poly ()  USE data  i=winio@('%pl[x_array,colour=blue,title="plot",x_axis=r,y_axis=x]', 500,300,n,x,y) end subroutine plot_poly       integer function lookup()  USE data    ! alternatively read data from file  icall=icall+1  finish=0  do i=1,icall             if (icall>n) then      finish=1      RETURN    endif       x(i)=i-1         y(i) = sqrt(x(i))  enddo   i=winio@('%pl[x_array,colour=blue,title="plot",x_axis=r,y_axis=x]', 500,300,n,x,y) return end
LitusSaxonicum

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

 Posted: Fri Aug 14, 2015 6:09 pm    Post subject: Johannes, That depends what you mean by 'stop properly'. I've just upgraded this laptop to Windows 10 from 8.1, and your program gives me an odd message 'Simpleplot: incompatible device driver' so to have a proper look I'll have to wait until I'm in the office again. It may mean that Windows 10 sounds the end of Simpleplot :( Eddie
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

Posted: Fri Aug 14, 2015 7:31 pm    Post subject:

1. After I submitted the post I realized that I had to say what I mean by 'stop': at any time I want to be able to close the window and to abort the updating process.
I tried to add some more statements, which at the end shows a [Close] button very shortly, but no graphat all, unfortunately:
 Code: Module data      integer,parameter :: n=10      real*8 ::  x(n)=0., y(n)=0.      integer :: i, winio@, newdataflag,icall,finish end Module program test  USE data  external lookup,abbruch  icall=1 ; finish=0     i=winio@('%dl&', 0.1d0, lookup)     !HOW TO STOP IF finish=01?        i=winio@('%^tt[Close]',abort) end program test       integer function lookup()  USE data    ! alternatively read data from file  icall=icall+1  finish=0  do i=1,icall             if (icall>n) then      finish=1      RETURN    endif       x(i)=i-1         y(i) = sqrt(x(i))  enddo   i=winio@('%pl[x_array,colour=blue,title="plot",x_axis=r,y_axis=x]&', 500,300,n,x,y) return end integer function abort() return end[quote][/quote]

2. Another lack of my posted code from 5:17pm is, that it created 10 independent windows one over the other, which have to be closed one by one manually. That invalidates this solution.
3. Compatibility with Win10 is a good point. Is your Windows10 problem a Simpleplot problem or a general Clearwin problem? Is FTN prepared for Windows10?
johannes
LitusSaxonicum

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

 Posted: Sat Aug 15, 2015 3:20 pm    Post subject: Hi Johannes, Couple of things. Firstly I think what you are looking for to get the plots redrawn in the same space is CALL SIMPLEPLOT_REDRAW@. I'm getting in a tangle with simpleplot (which I don't use) but will post the demonstrator when I've done it. As far as Win 10 is concerned, my small laptop came with Windows 8.1. I don't like all that much, so I thought that I'd let it update to Windows 10. It is certainly nastier in the visual department as Windows have no frames, there was that glitch with simpleplot, and Edge, the replacement for Internet Explorer is so different as to be (as yet) unusable by me. Caption bars are not differentiated from menu bars by colour or anything. I may scrub the lot and revert to my small Windows 7 laptop or install Windows 7 on the new one. Eddie
johannes

Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

 Posted: Sat Aug 15, 2015 5:43 pm    Post subject: Hi Eddie, of course I don't know where to precisely place simpleplot_redraw@ but any compliation gives: WARNING the following symbols are missing: SIMPLEPLOT_REDRAW# Did I forget to link a special library? johannes
LitusSaxonicum

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

Posted: Sun Aug 16, 2015 10:36 am    Post subject:

Hi Johannes,

Simpleplot defeats me, and I gave up yesterday. I am an old dog and use Fortran 77 tricks, not all the new stuff, so I get access to Clearwin+ tricks with

 Code: INCLUDE

This goes in every routine that uses any windows or clearwin subprograms. If you use USE then the modules are given in the include folder of Silverfrost/FTN95

The CALL SIMPLEPLOT_REDRAW@ goes immediately after you have changed x and y, and want to update the plot. It's a bit like perform_graphics_update@.

Eddie
LitusSaxonicum

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

Posted: Sun Aug 16, 2015 11:18 am    Post subject:

And then again, Johannes, maybe it doesn't! Apologies for this scruffy program, but it illustrates SIMPLEPLOT_REDRAW:
 Code: WINAPP       OPTIONS (INTL)       program test       IMPLICIT DOUBLE PRECISION(A-H, O-Z)       INCLUDE       COMMON /VALUES/ X(10), Y(10)       COMMON /COUNT/  N,     IA,    M       COMMON /REPEAT/ Keep_code(3), New_data_ready       INTEGER, EXTERNAL :: PLOT_FN, REDRAW_FN       N = 10;   M = 1       DO 10 I=1, 10       x(i)=i-1            y(i)=x(i) ** 2 + M * x(I) - M       write(*,*) x(i), y(i)   10  CONTINUE       I=WINIO@('%ca[Main window]%lw&', Keep_code(1))       i=winio@('%dl&', 5.0d0, REDRAW_FN)       I=WINIO@('%sc&', PLOT_FN)       I=WINIO@('%fr', 600, 400) ! positioning       end program test               integer function PLOT_FN()       IMPLICIT DOUBLE PRECISION(A-H, O-Z)       INCLUDE       COMMON /VALUES/ X(10), Y(10)       COMMON /COUNT/  N,     IA,    M       COMMON /REPEAT/ Keep_code(3), New_data_ready       IA=WINIO@('%aw&', Keep_code(1))       iA=winio@('%pl[x_array,colour=blue,title="plot",      &          x_axis=r,y_axis=x]', 500, 300, n, x, y)       PLOT_FN = 1       RETURN       END       INTEGER FUNCTION REDRAW_FN ()       IMPLICIT DOUBLE PRECISION(A-H, O-Z)       INCLUDE       COMMON /VALUES/ X(10), Y(10)       COMMON /COUNT/  N,     IA,    M       COMMON /REPEAT/ Keep_code(3), New_data_ready       DO 10 I=1, 10       x(i)=i-1            y(i)=x(i) ** 2 + M * x(I) - M       write(*,*) x(i), y(i)   10  CONTINUE       M = M+1       CALL SIMPLEPLOT_REDRAW@       REDRAW_FN = 1       IF (M .EQ. 11) REDRAW_FN = 0       RETURN       END

(I didn't use Keep_code 2 or 3, or New_data_ready). I put the plot in a child window, but the timer is in the main window.

Eddie
DanRRight

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

 Posted: Mon Aug 17, 2015 1:58 am    Post subject: Eddie, The Simpleplot Win10 incompatibility is a bad news, i was trying to update to Windows 10 too but some bug stopped me. I hope Silverfrost will fix that but may be we can temporally fix themselves too: can you make the EXE file compatible with Windows 8.1 changing its Properties ? Right click on EXE file, chose Properties/Compatibility / select radiobutton "Run this program in compatibility mode" and chose older Windows version As to autoupdate here is one more trick to consider. I use FILES@ for that which we discussed here last month in the thread in "General" called "Attributes of file". The code permanently scans for the data file (which contains your plotting data) attributes change with 0.1 second interval and as soon as it finds date/time stamps changed it reads this file and plots the data. Also John Campbell made the code (also in this thread) where all the DOS attributes are decrypted in human-readable format.
LitusSaxonicum

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

 Posted: Mon Aug 17, 2015 9:28 am    Post subject: Dan, The next two days I got really big 'updates' and I haven't tried it since on this little laptop. I will when time permits. For example Cortana didn't run on day 1, but did on day 2, and better on day 3! Meanwhile, I used my desktop computer (Win 7) to demo how SIMPLEPLOT_REDRAW@ works for Johannes. That idea of using the datestamp is great - I was thinking of a independently running plot program and another that creates the data. The date and time stamp is the flag that data has changed.
LitusSaxonicum

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

 Posted: Mon Aug 17, 2015 10:35 am    Post subject: Dan, Good news so far: now my program above works on Win 10 without that 'device driver' bit. I was expecting some issues at first. Eddie
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 HourGoto page 1, 2  Next Page 1 of 2