subroutine myfcn(npar, g, f, x, iflag, futil) C implicit none integer npar, iflag, i, ndat integer SYSIN/1/, SYSRD/5/, SYSWR/6/, SYSPU/7/ parameter (ndat=5) C real*8 f, g(*), x(*), xdat(ndat), ydat(ndat), edat(ndat), func, > answer/15.7/, rms, avg, diff C C Save all data that must be preserved between calls! C save xdat, ydat, edat C external futil C if (iflag .eq. 1) then C C Initialization mode C do i=1,ndat xdat(i) = i ydat(i) = answer + i - float(ndat + 1) / 2. edat(i) = 1. end do end if C C compute LSQ C f = 0 do i = 1, ndat f = f + (ydat(i) - func(xdat(i), x(1)))**2 / edat(i) end do if (iflag .eq. 3) then C C print mode C avg = 0 rms = 0 write(SYSWR, '('' X Y dY func pull'')') do i = 1, ndat diff = (ydat(i) - func(xdat(i), x(1))) / sqrt(edat(i)) avg = avg + diff rms = rms + diff**2 write(SYSWR, '(10f8.3)') xdat(i), ydat(i), edat(i), > func(xdat(i), x), diff end do avg = avg / ndat rms = rms / ndat - avg**2 write(SYSWR, '('' mean pull'', f10.3, '' rms of pulls :'', > 2f10.4)') avg, rms write(SYSWR, *) ' ' end if end