Silverfrost Forums

Welcome to our forums

%pl + optimise + win32 + minimal %pl call back

24 Jul 2020 3:53 #26093

The following code uses the native %pl to plot a simple two cycle sine wave.

It includes the options(optimise) flag at the beginning to the file. (This is a cut down version of a 1000 line program which would benefit from optimisation).

When compiled with the 64 bit compiler everything is as expected. But when complied with 32 bit the program fails. “The function supplied as argument 7 is corrupt”.

This appears to be related to the %pl call back. If there is no %pl call back everything runs as expected.

In this program, the %pl call back does nothing apart from return the value 2. If the pl call back does something else e.g. there is a print statement added then the program runs as expected.

I stumbled on this one by accident, as the %pl was in the code as a placeholder and I was intending to come back to add to it later. So it’s not really a bug, but it is a bit unexpected. The reference to “argument 7” is a bit unhelpful as there are no functions with 7 arguments.

options(optimise)
module problem_mod
use clrwin
implicit none
integer, parameter :: dp = kind(1.d0)
integer, parameter :: n=360*2+1
real(kind=dp), parameter :: pi = 4.d0*atan(1.d0)
real(kind=dp), parameter :: deg2rad = pi/180.d0
real(kind=dp) x1(1:n), y1(1:n)
contains
  integer function build_gui()
  integer winio@, i
  integer, save :: iw
    x1 = (/(deg2rad*i,i=1,n,1)/) ; y1 = (/(sin(deg2rad*i),i=1,n,1)/)
    iw = winio@('%mn[Exit]&','exit')
    call winop@('%pl[native, independent, x_array, n_graphs=1,gridlines,framed,y_min=-1,y_max=1, dy=0.5]')
    iw = winio@('%^pl&',600,400,n,x1,y1,pl_cb)
    iw = winio@(' ')
    build_gui =1
  end function build_gui

  integer function pl_cb()
  pl_cb = 2
  end function pl_cb
  
end module problem_mod

program main
use problem_mod
implicit none
integer i
  i = build_gui()
end program main
24 Jul 2020 4:27 #26094

Ken

I have added this to the list of things to investigate.

25 Jul 2020 4:46 #26095

Ken, Compiler calls winio@('%^pl&',600,400,n,x1,y1,pl_cb) a function with 7 arguments. Ideally it better also display the name of the erroneous argument as i for example often gather 10 controls in one long line. Or show it using arrow like some compilers sometimes do for convenience

25 Jul 2020 6:58 #26096

Dan

As soon as you switch on the optimiser you won't get detailed information about runtime failures (with any compiler).

25 Jul 2020 9:29 #26097

You are correct Dan. I was looking at this as %pl with 6 arguments, rather than winio@ with 7 arguments.

While it's easy to pick out the offending line in this sample program this is not the case in the longer program.

Easy to fix in this particular example, but the observed behaviour is not correct, so I thought it best to share this example with Silverfrost as whatever is causing the failure in this case may cause other problems with more complex codes in less obvious ways.

25 Jul 2020 11:16 #26098

This has now been fixed for the next release of FTN95.

Please login to reply.