module data_mod
implicit none
integer, parameter :: dp = kind(1.d0), npts_max = 10000
integer :: npts = 2000, npts_now(2) = 0
real(kind=dp) :: x(npts_max) = 0.d0, y(npts_max) = 0.d0
integer, save :: internal_id = 1, plot_id = 2
end module data_mod
module calc_mod
use data_mod
implicit none
contains
integer function build_gui()
include<windows.ins>
integer i
! Draw first 2 points to a pl in memory
npts_now = 2
x(1) = 0.d0 ; y(1) = 0.d0 ; x(2) = 1.d0 ; y(2) = 1.d0
i = create_graphics_region@(internal_id,650,600)
i = select_graphics_object@(internal_id)
call winop@('%pl[native,smoothing=4,width=1,x_array,independent,N_GRAPHS=1, gridlines,y_sigfigs=2]')
call winop@('%pl[link=lines,colour=blue,symbol=0,pen_style=0]')
i = winio@('%`bg[white]&')
i = winio@('%pl[external]',npts_now,x,y)
! Comment out above four lines and remove comment from line below. This demonstrates that the COPY_GRAPHICS_REGION@ call works.
!$$$$$$ call draw_filled_rectangle@(0,0,650,600,rgb@(0,255,0))
i = winio@('%mn[Exit]&','exit')
i = winio@('%bg[grey]&')
i = winio@('%3.1ob%ws%cb&','Number of points')
i = winio@('%il&', 0, npts_max)
i = winio@('%rd%cb&',npts)
i = winio@('%^tt[Plot]%cb&',plot)
i = winio@('%ff&')
i = winio@('%`gr[black]&',650,600,plot_id) ! Initially black so that we can see image copied over
! Following lines are same as %pl above (except for graphics size), to see embedded plot being updated live as calculation proceeds
!
!$$$$$$ call winop@('%pl[native,smoothing=4,width=1,x_array,independent,N_GRAPHS=1, gridlines,y_sigfigs=2]')
!$$$$$$ call winop@('%pl[link=lines,colour=blue,symbol=0,pen_style=0]')
!$$$$$$ i = winio@('%`bg[white]&')
!$$$$$$ i = winio@('%ta%pl&',650,600,npts_now,x,y)
i = winio@('%ff')
build_gui = 1
end function build_gui
integer function plot()
include<windows.ins>
integer i, icopy, counter
real(kind=dp) ang_last
integer COPY_GRAPHICS_REGION@
ang_last = 0.d0 ; counter = 0
do i = 3, npts, 1
x(i) = x(i-1) + 1.d0 ; y(i) = y(i-1) + 1.d0 ; npts_now = i ; counter = counter + 1
if (counter .eq. 10 )then
call YIELD_PROGRAM_CONTROL@(Y_TEMPORARILY)
! Here the call to simpleplot_redraw@ does not update the image in memory ##############
! We can see this since the image copied back to the screen never changes.
! The image that is always copied back is the %pl with the first two points as defined in function build_gui()
call simpleplot_redraw@()
! call PLOT_REDRAW@() ! John's suggestion
icopy = COPY_GRAPHICS_REGION@(plot_id, 1, 1, 650, 600, &
internal_id, 1, 1, 650, 600, 13369376 )
if (icopy .eq. 1) write(6,*) 'Success for COPY_GRAPHICS_REGION@'
counter = 0
end if
end do
plot = 1
end function plot
end module calc_mod
program main
use calc_mod
implicit none
integer i
i = build_gui()
end program main