# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. include include "icfit.h" include "names.h" # IC_FERRORS -- Compute error diagnositic information. procedure ic_ferrors$t (ic, cv, x, y, wts, npts, fd) pointer ic # ICFIT pointer pointer cv # Curfit pointer PIXEL x[ARB] # Ordinates PIXEL y[ARB] # Abscissas PIXEL wts[ARB] # Weights int npts # Number of data points int fd # Output file descriptor int i, n, deleted, ncoeffs PIXEL chisqr, rms pointer sp, fit, wts1, coeffs, errors int $tcvstati() PIXEL ic_rms$t() begin # Determine the number of coefficients and allocate memory. ncoeffs = $tcvstati (cv, CVNCOEFF) call smark (sp) call salloc (coeffs, ncoeffs, TY_PIXEL) call salloc (errors, ncoeffs, TY_PIXEL) if (npts == IC_NFIT(ic)) { # Allocate memory for the fit. n = npts call salloc (fit, n, TY_PIXEL) call salloc (wts1, n, TY_PIXEL) # Eliminate rejected points and count deleted points. call amov$t (wts, Mem$t[wts1], n) if (IC_NREJECT(ic) > 0) { do i = 1, npts { if (Memi[IC_REJPTS(ic)+i-1] == YES) Mem$t[wts1+i-1] = 0. } } deleted = 0 do i = 1, n { if (wts[i] == 0.) deleted = deleted + 1 } # Get the coefficients and compute the errors. call $tcvvector (cv, x, Mem$t[fit], n) call $tcvcoeff (cv, Mem$t[coeffs], ncoeffs) call $tcverrors (cv, y, Mem$t[wts1], Mem$t[fit], n, chisqr, Mem$t[errors]) rms = ic_rms$t (x, y, Mem$t[fit], Mem$t[wts1], n) } else { # Allocate memory for the fit. n = IC_NFIT(ic) call salloc (fit, n, TY_PIXEL) call salloc (wts1, n, TY_PIXEL) # Eliminate rejected points and count deleted points. call amov$t (Mem$t[IC_WTSFIT(ic)], Mem$t[wts1], n) if (IC_NREJECT(ic) > 0) { do i = 1, npts { if (Memi[IC_REJPTS(ic)+i-1] == YES) Mem$t[wts1+i-1] = 0. } } deleted = 0 do i = 1, n { if (wts[i] == 0.) deleted = deleted + 1 } # Get the coefficients and compute the errors. call $tcvvector (cv, Mem$t[IC_XFIT(ic)], Mem$t[fit], n) rms = ic_rms$t (Mem$t[IC_XFIT(ic)], Mem$t[IC_YFIT(ic)], Mem$t[fit], Mem$t[wts1], n) call $tcvcoeff (cv, Mem$t[coeffs], ncoeffs) call $tcverrors (cv, Mem$t[IC_YFIT(ic)], Mem$t[wts1], Mem$t[fit], n, chisqr, Mem$t[errors]) } # Print the error analysis. call fprintf (fd, "# total points = %d\nsample points = %d\n") call pargi (npts) call pargi (n) call fprintf (fd, "# nrejected = %d\ndeleted = %d\n") call pargi (IC_NREJECT(ic)) call pargi (deleted) call fprintf (fd, "# RMS = %7.4g\n") call parg$t (rms) call fprintf (fd, "# square root of reduced chi square = %7.4g\n") call parg$t (sqrt (chisqr)) # Free allocated memory. call sfree (sp) end # IC_RMS -- Compute RMS of points which have not been deleted. PIXEL procedure ic_rms$t (x, y, fit, wts, npts) PIXEL x[ARB] # Ordinates PIXEL y[ARB] # Abscissas PIXEL fit[ARB] # Fit PIXEL wts[ARB] # Weights int npts # Number of data points int i, n PIXEL resid, rms begin rms = 0. n = 0 do i = 1, npts { if (wts[i] == 0.) next resid = y[i] - fit[i] rms = rms + resid * resid n = n + 1 } if (n > 0) rms = sqrt (rms / n) return (rms) end