Silverfrost Forums

Welcome to our forums

V8.71 %pl

8 Apr 2021 3:18 #27449

I would be grateful if somebody who has installed the updated version could test the following code. When I select the 'half extents' button I see data points drawn in the left and right margins of the %pl region. I'm trying to decide if I've corrupted my FTN95 installation or not.

Thanks

Ken

module problem_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: npoints = 200 
real(kind=dp) x(1:npoints), y(1:npoints) 
  
contains

integer function gen_data()
integer i
  do i = 1, npoints
    x(i) = 2.d0*random@()-1.d0 ; y(i) = 2.d0*random@()-1.d0
  end do
  gen_data = 2
end function gen_data

integer function plot_data()
integer iw
  iw = winio@('%2.1ob&')
  call winop@('%pl[native, x_array, n_graphs=1, gridlines, link=none, symbol=6, frame, colour=blue, etched]')
  iw = winio@('%pl&',1000,800,npoints,x,y)
  iw = winio@('%cb&')
  iw = winio@('This button sets xmin=-1, xmax=1, ymin=-1, ymax=1 &')
  iw = winio@('%nl%^bt[Full extents]&', full_extents_cb)
  iw = winio@('%2nlThis button sets xmin=-0.5, xmax=0.5, ymin=-0.5, ymax=0.5 &')
  iw = winio@('%nlThis results in points being plotted in the left and right margins&')
  iw = winio@('%nl%^bt[Half extents]&', half_extents_cb)
  iw = winio@('%cb&')
  iw = winio@(' ')
  plot_data = 2
end function plot_data

integer function full_extents_cb()
integer i
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, -1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'x_max', 0,  1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, -1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'y_max', 0,  1.d0 )
  call simpleplot_redraw@()
  full_extents_cb = 2
end function full_extents_cb

integer function half_extents_cb()
integer i
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, -0.5d0 ) ; print*, i
  i = CHANGE_PLOT_DBL@(0, 'x_max', 0,  0.5d0 ) ; print*, i
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, -0.5d0 ) ; print*, i
  i = CHANGE_PLOT_DBL@(0, 'y_max', 0,  0.5d0 ) ; print*, i
  call simpleplot_redraw@()
  half_extents_cb = 2
end function half_extents_cb

end module problem_mod

program main
use problem_mod
implicit none
integer i
i = gen_data()
i = plot_data()
end program main
8 Apr 2021 3:46 #27450

Ken

Is it 32 bits or 64 bits and does it make a difference?

8 Apr 2021 4:08 #27453

Paul,

It makes no difference, both 32 and 64 bit versions give the same response.

What is interesting (or perhaps I mean frustrating) is that other code using this technique continues to run as expected, but I cannot see a reason why this simple example fails.

Here is a screenshot: https://www.dropbox.com/s/ecs6wzkjb02y5su/pl_pic2.jpg?dl=0

PS Putting my installation back to a clean copy of FTN95 version 8.70 the code runs as expected. When I then install the April 6 2021 DLLs (newDLLs 77) and Clearwin+ mod files etc, the code does not run correctly.

9 Apr 2021 12:47 #27455

Ken Yes, 'half' makes dots drawn on the border. I installed Apr 6 update

9 Apr 2021 8:16 #27457

Dan, Thanks for confirming this issue.

9 Apr 2021 9:38 #27458

This failure has now been fixed and I have provided a new download via the sticlky post.

9 Apr 2021 12:36 #27461

Paul,

Thanks for this. I can confirm that this works for the sample above.

Unfortunately I can still replicate the error in the more complex code I was looking at yesterday (under certain specific scenarios).

I will look again at the this code for errors. It's only 180 lines of code, but the logic is complex and I'm pushing the envelope a bit in terms of my previous %pl usage.

Ken

9 Apr 2021 1:10 #27462

Paul, This sample demonstrates the issue. If the first adjustment is only to the range of x values I still see points drawn in the left and right margins.

winapp
module problem_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: npoints = 200 
real(kind=dp) x(1:npoints), y(1:npoints) 
  
contains

integer function gen_data()
integer i
  do i = 1, npoints
    x(i) = 2.d0*random@()-1.d0 ; y(i) = 2.d0*random@()-1.d0
  end do
  gen_data = 2
end function gen_data

integer function plot_data()
integer iw
  iw = winio@('%2.1ob&')
  call winop@('%pl[native, x_array, n_graphs=1, gridlines, link=none, symbol=6, frame, colour=blue, etched]')
  iw = winio@('%pl&',1000,800,npoints,x,y)
  iw = winio@('%cb&')
  iw = winio@('This button sets xmin=-1, xmax=1, ymin=-1, ymax=1 &')
  iw = winio@('%nl%^bt[Full extents]&', full_extents_cb)
  iw = winio@('%2nlThis button sets xmin=-0.5, xmax=0.5 &')
  iw = winio@('%nl%^bt[Half x extents]&', half_x_extents_cb)
  iw = winio@('%2nlThis button sets ymin=-0.5, ymax=0.5 &')
  iw = winio@('%nl%^bt[Half y extents]&', half_y_extents_cb)
  iw = winio@('%bf%2nl After the window is initially displayed if&')
  iw = winio@('%nl the first user action is to select 'Half x extents'&')
  iw = winio@('%nl points are displayed in the left and right margins&')
  iw = winio@('%nl If 'Half x extents' is selected after another button&')
  iw = winio@('%nl the problem does not occur&')
  iw = winio@('%cb&')
  iw = winio@(' ')
  plot_data = 2
end function plot_data

integer function half_x_extents_cb()
integer i
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, -0.5d0 )
  i = CHANGE_PLOT_DBL@(0, 'x_max', 0,  0.5d0 )
  call simpleplot_redraw@()
  half_x_extents_cb =1
end function half_x_extents_cb


integer function half_y_extents_cb()
integer i
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, -0.5d0 )
  i = CHANGE_PLOT_DBL@(0, 'y_max', 0,  0.5d0 )
  call simpleplot_redraw@()
  half_y_extents_cb =1
end function half_y_extents_cb


integer function full_extents_cb()
integer i
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, -1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'x_max', 0,  1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, -1.d0 )
  i = CHANGE_PLOT_DBL@(0, 'y_max', 0,  1.d0 )
  call simpleplot_redraw@()
  full_extents_cb = 1
end function full_extents_cb

end module problem_mod

program main
use problem_mod
implicit none
integer i
i = gen_data()
i = plot_data()
end program main
9 Apr 2021 10:22 #27469

Paul,

I did a little more digging into this issue this evening. The second example I posted also fails with V8.70

The difference between the second example and earlier applications I have coded is that in the earlier codes there are always four calls to CHANGE_PLOT_DBL@ before the call to simpleplot_redraw@, i.e. I updated all four extent limits even when only two actually required to be changed. As a consequence, this issue was undetected until I deliberately started to avoid unnecessary calls to CHANGE_PLOT_DBL@ in the code I am presently working with.

Below is a slightly modified version of my second example. If you remove the two lines commented out in the function half_extents_cb, then the problem when the user first clicks on the 'half_extents' button does not occur.

9 Apr 2021 10:48 #27470
winapp
module problem_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: npoints = 200
real(kind=dp) x(1:npoints), y(1:npoints)
real(kind=dp) :: x_min = -1.d0, x_max = 1.d0, y_min = -1.d0, y_max = 1.d0
contains
integer function gen_data()
integer i
  do i = 1, npoints
    x(i) = 2.d0*random@()-1.d0 ; y(i) = 2.d0*random@()-1.d0
  end do
  gen_data = 2
end function gen_data
integer function plot_data()
integer iw
  iw = winio@('%2.1ob&')
  call winop@('%pl[native, x_array, n_graphs=1, gridlines, link=none, symbol=6, frame, colour=blue, etched]')
  iw = winio@('%pl&',1000,800,npoints,x,y)
  iw = winio@('%cb&')
  iw = winio@('This button sets xmin=-1, xmax=1, ymin=-1, ymax=1 &')
  iw = winio@('%nl%^bt[Full extents]&', full_extents_cb)
  iw = winio@('%2nlThis button sets xmin=-0.5, xmax=0.5 &')
  iw = winio@('%nl%^bt[Half x extents]&', half_x_extents_cb)
  iw = winio@('%2nlThis button sets ymin=-0.5, ymax=0.5 &')
  iw = winio@('%nl%^bt[Half y extents]&', half_y_extents_cb)
  iw = winio@('%bf%2nl After the window is initially displayed if&')
  iw = winio@('%nl the first user action is to select 'Half x extents'&')
  iw = winio@('%nl points are displayed in the left and right margins&')
  iw = winio@('%nl If 'Half x extents' is selected after another button&')
  iw = winio@('%nl the problem does not occur&')
  iw = winio@('%cb&')
  iw = winio@(' ')
  plot_data = 2
end function plot_data
integer function half_x_extents_cb()
integer i
  x_min = -0.5d0
  x_max =  0.5d0
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min ) ;   i = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max )
!  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min )        !Uncomment these two lines and there is no issue
!  i = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max )
  call simpleplot_redraw@()
  half_x_extents_cb =1
end function half_x_extents_cb
integer function half_y_extents_cb()
integer i
  y_min = -0.5d0 ;   y_max =  0.5d0
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min ) ;   i = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max)
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min ) ;   i = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max)
  call simpleplot_redraw@()
  half_y_extents_cb =1
end function half_y_extents_cb
integer function full_extents_cb()
integer i
  x_min = -1.d0 ;   x_max =  1.d0 ;   y_min = -1.d0 ;   y_max =  1.d0
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min ) ;   i = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max )
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min ) ;   i = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max )
  call simpleplot_redraw@()
  full_extents_cb = 1
end function full_extents_cb
end module problem_mod

program main
use problem_mod
implicit none
integer i
i = gen_data() ; i = plot_data()
end program main
10 Apr 2021 8:05 #27471

Ken

I am not sure that there is anything for me to fix here.

The ClearWin+ code does not always handle the case where the min and max values are not set initially but are then changed dynamically.

It may be possible to get ClearWin+ to handle this case but the logic does get more and more complex.

Try initialising these values to see if that works for you....

  call winop_flt@('%pl[x_min]', x_min)
  call winop_flt@('%pl[x_max]', x_max)
  call winop_flt@('%pl[y_min]', y_min)
  call winop_flt@('%pl[y_max]', y_max)
10 Apr 2021 11:21 #27473

As ever, thanks Paul,

You have provided the missing link i.e. 'The ClearWin+ code does not always handle the case where the min and max values are not set initially but are then changed dynamically.'

What I am trying to achieve is an auxiliary Fortran module with data and routes which when used in conjunction with %pl allow the application of %pv, %hx, %hv and a zoom function without any further processing of the raw input x, y data. This has the potential to simplify the writing of future code requiring these features.

My idea was to let %pl choose the initial limits, then once the %pl region is formed as you know the %pl initial graphics width and graphics height (or can now deduce them following a resize), and have specified the margins, all the coordinate data required for a scroll or zoom operation can be deduced via calls to GET_PLOT_DATA@. This requires two callbacks to be attached to the %pl via '+'; one to process the scrollbar movements and one to annotate the plot via 'PLOT_ADJUST' if required.

At the moment the have %pv and %hv working correctly, with only %hv causing a problem if it is the first action of the user is to select the x-axis scroll bar.

I think I have enough information now to complete the task, based on what you have told me and my observations. I will share the code if I am successful.

14 Apr 2021 8:34 #27528

As promised, here is an example that demonstrates the idea I was thinking about. It works as described above. Note this example requires the latest version of FTN95 V8.71.

https://www.dropbox.com/s/hk63wpmol2nt0it/scrollpluszoom.f95?dl=0

Paul,

Please take a look at Examples 2 and 3 in the code.

In Example 2 with [link=columns], when the vertical scroll bar is moved upwards, each column disappears when the data point associated with it moves beyond the current %pl y_max value.

In Example 3, with [link=bars], a horizontal scroll bar movement which causes the data point to move beyond the current %pl x limits does not cause the bar to disappear.

This difference between [link=columns] and [link=bars] seems a little odd to me.

15 Apr 2021 1:58 #27540

Ken

I have made a note of this.

16 Apr 2021 11:48 #27552

Paul,

Here is a much simpler code that demonstrates the difference between [link=columns] and [link=bars] when changing the %pl limits.

module demo
use clrwin
implicit none 
integer, parameter :: dp = kind(1.d0), npoints=21
real(kind=dp) x(1:npoints), y(1:npoints)
real(kind=dp) :: x_min, x_max, y_min, y_max
contains
integer function gen_data()
integer i, j
  j = -10
  do i = 1, npoints
    x(i) = j ; y(i) = j
    j = j + 1
  end do
  gen_data = 2
end function gen_data

integer function plot3()
integer iw
  y_min=-10; y_max=10; x_min=-10; x_max=10
  call winop@('%pl[native,x_array,frame,gridlines, width=5,link=columns,symbol=0,colour=blue]')  
  iw = winio@('%pl&',800,800,npoints,x,y)
  iw = winio@('%^4bt[UP]%^4bt[DOWN]&',up_cb,down_cb)
  iw = winio@('%ff%cn%bt[OK]')
  plot3 = 2
end function plot3

integer function plot4()
integer iw
  y_min=-10; y_max=10; x_min=-10; x_max=10
  call winop@('%pl[native,x_array,frame,gridlines, width=5,link=bars,symbol=0,  colour=blue]') 
  iw = winio@('%pl&',800,800,npoints,x,y)
  iw = winio@('%^5bt[Left]%^5bt[Right]&',left_cb,right_cb)
  iw = winio@('%ff%cn%bt[OK]')
  plot4 = 2
end function plot4

integer function up_cb()
  y_min = y_min - 1.0d0 ; y_max = y_max - 1.0d0 ; call update ; up_cb = 2
end function up_cb

integer function down_cb()
  y_min = y_min + 1.d0 ; y_max = y_max + 1.d0 ; call update ; down_cb = 2
end function down_cb

integer function left_cb()
  x_min = x_min + 1.d0 ; x_max = x_max + 1.d0 ; call update ; left_cb = 2
end function left_cb

integer function right_cb()
  x_min = x_min - 1.d0 ; x_max = x_max - 1.d0 ; call update ; right_cb = 2
end function right_cb

subroutine update
integer i
  i = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min ) ; i = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max )
  i = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min ) ; i = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max )
  call simpleplot_redraw@()
end subroutine update
end module demo

program main
use demo
i = gen_data() ; i = plot3() ; i = plot4()
end program main
19 Apr 2021 7:23 #27575

Ken

This failure has now been fixed for the next release of ClearWin+.

19 Apr 2021 8:20 #27577

Paul,

Thanks for this fix.

Please login to reply.