! Procedure gag__demo:demo-adjust
!
! An example of ADJUST usage
if pro%narg.le.3 then
  SAY "Usage:"
  SAY " @ gag_demo:demo-emcee  Amp Pos Width Noise"
  SAY " "
  return error
endif
! For simplicity, let us define the GAUSSIAN function
if (function(gauss)) delete /function gauss
define function gauss(x,a,b,c) a*exp(-0.5*((x-b)/c)^2)
!
! The Gaussian parameters, Amplitude, Position and Width
if .not.exist(my__data) then
  define double amp pos width /global
  ! Now the data...
  define integer nx
  let nx 512
  define double xx[nx] my__data[nx] /global
  ! Define the Measurement points XX
  let xx[i] 10*(i-nx/2)/nx
endif
!
! Fill the data with some noisy values. In reality, this may come from
! an experiment or observation
let my__data gauss(xx,&1,&2,&3)
let my__data[i] my__data+&4*noise(i/i)
!
! This is the key script for ADJUST
begin procedure my__difference
  let ADJ%res my__data-gauss(xx,amp,pos,width)
end procedure my__difference
!
! Minimize
adjust my__data "@ my__difference" /start 3 2 1 /par amp pos width /root ADJ
exa ADJ%PAR
exa ADJ%ERRORS

