diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /pkg/xtools/icfit | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/xtools/icfit')
76 files changed, 9728 insertions, 0 deletions
diff --git a/pkg/xtools/icfit/Revisions b/pkg/xtools/icfit/Revisions new file mode 100644 index 00000000..0117042e --- /dev/null +++ b/pkg/xtools/icfit/Revisions @@ -0,0 +1,405 @@ +.help revisions Jun88 pkg.xtools.icfit +.nf +icdeviant.gx + There were two bugs related to growing. First, the logic was wrong. + Second, in one place the grow parameter was treated as being in pixels + and in another as being in user coordinate units. + (6/28/10, Valdes) + +icdosetup.gx + When there is only one sample range that is binned to a single point + this would result in the fitting limits (introduced 8/11/00) being + equal. This causes cvinit to return an error and the cv pointer + is invald. The change is if the number of binned fitting points + is 1 then the full range of the unbinned data is used. Note that + a change was also made on this date to have cvinit return a null + pointer rather than a partially initialized pointer. (11/18/02, Valdes) + +======= +V2.12.1 +======= + +===== +V2.12 +===== + +icdosetup.gx + The change made previously is now restricted to the polynomial functions + which make sense to extrapolate. The spline functions define the + fitting region to be the region set by the calling program. + (11/21/00, Valdes) + +icfshow.gx + Will now work if the GT pointer is NULL. (8/19/00, Valdes) + +icdosetup.gx + When using sample ranges the fitting region is now limited to the + minimum and maximum of the fitted region. (8/11/00, Valdes) + +========= +V2.11.3p1 +========= +======= +V2.11.3 +======= + +icgui.x + Eliminated gmsg calls when there is no GUI. (2/1/99, Valdes) + +icshow.x +icvshow.gx + The gt pointer was not being used when called by CURFIT noninteractively. + The IC_GT structure is now set in these routines. (9/14/99, Valdes) + +======= +V2.11.2 +======= + +icggraph.gx + Moved smark to after an initial return. (7/11/99, Valdes) + +icgfit.x + This routine is called with a graphics descriptor for interactive + fitting. The descriptor is set in an internal structure. Other + procedures, which may be called both for interactive and + non-interactive fitting, check if the descriptor is not NULL + before sending GUI messages. The problem occurs if this procedure is + first called interactively and then the non-interactive fitting + routine is called later (maybe after a deactivate workstation or + closing the descriptor) resulting in GUI messages being sent + when not in interactive mode. The solution is to return the + internal descriptor value to NULL after finishing the interactive + fitting and returning from this procedure. (7/22/99, Valdes) + +icgui.x + Fixed bug in behavior when there is no gui. (4/2/99, Valdes) + +icfit.h +names.h +icgfit.gx +icparams.x +icggraph.gx +icgcolon.gx +icgui.x +icferrors.gx +icshow.x +icerrors.gx +icvshow.gx +icguishow.gx +icfvshow.gx +mkpkg + Added support for GUIs. (12/7/98, Valdes) + +======= +V2.11.1 +======= + +======= +V2.11.0 +======= + +pkg$xtools/icfit/icfit.hlp + Changed the order of the task name and version number in the revisions + section. (4/22/97, Valdes) + +pkg$xtools/icgcolon.gx +pkg$xtools/icfit/icfit.hlp + Changed the "fitvalue" colon command to "evaluate" to avoid abbreviation + conflict with "function". (4/16/97, Valdes) + +pkg$xtools/icfit/icshow.x + The commenting of the title string needed to be modified since the + title string could include new lines and we want each line to be + commented. (3/27/97, Valdes) + +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icfit.hlp + Added a "fitvalue" colon command to evaluate the fit at an arbitrary value. + (1/28/97, Valdes) + +pkg$xtools/icfit/icvshow.gx +pkg$xtools/icfit/icshow.x +pkg$xtools/icfit/icerrors.gx + All output except the tabular part of :xyshow now begins with + the comment character. Comment column labels were added back. + (2/29/96, Valdes) + +pkg$xtools/icfit/icvshow.gx +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icfit.help + Enhanced the :xyshow command to include the weights and not print + column labels. (11/20/95, Valdes) + +pkg$xtools/icfit/icparams.x + Added an ic_geti paramter "nmin" to return the minimum number of + points that can be fit. (9/8/95, Valdes) + +pkg$xtools/icfit/icgfit.h + The prototype capability of adding points was supposed to return to + the calling program as if only the original data was used however + the structure element giving the number of points fit was the number + after adding the points. This causes other routines to think the + data was sampled in some way which then leads to attempting to + reference a NULL array. The routine now sets the number of points + fit back to the input value upon completion. (7/12/95, Valdes) + +pkg$xtools/icfit/icfit.h +pkg$xtools/icfit/icparams.x +pkg$xtools/icfit/icggraph.gx +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icfit.hlp + Added a color option for the fit. Users may set it with :color and + applications with ic_puti. (6/30/95, Valdes) + +======= +V2.10.4 +======= + +pkg$xtools/icfit/icdosetup.gx + Fixed two type mismatches in min/max calls. (12/30/94, Valdes) + +pkg$xtools/icfit/icgfit.gx +pkg$xtools/icfit/icfit.hlp + Added 'v' key to change fitting weight. (12/29/94, Valdes) + +pkg$xtools/icparams.gx + Make it legal to call ic_closed with a null pointer. (8/11/93, Valdes) + +============ +V2.10.3 beta +============ + +pkg$xtools/icfit.gx + This procedure now sets the IC_FITERROR structure element so that + a program using only the noninteractive ic_fit will have this element + defined. The procedure will still return with an error condition + if an error occurs as was true previously. (6/29/93, Valdes) + +pkg$xtools/icdosetup.gx + The fitting min and max given to cvinit is now calculated from the data + avoiding errors in setting it by calling programs. This was especially + dangerous because fitting data outside this range can cause memory + corruption errors by the CURFIT routines. (7/29/92, Valdes) + +======= +V2.10.1 +======= + +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icggraph.gx +pkg$xtools/icfit/icparams.x +pkg$xtools/icfit/icfit.h +pkg$xtools/icfit/icfit.hlp +noao$lib/src/icgfit.key +noao$lib/src/idicgfit.key + Added a new user parameter called "markrej" to toggle whether to mark + rejected points or not. (1/21/92, Valdes) + +pkg$xtools/icfit/icfit.hlp +pkg$xtools/icfit/icgsample.gx +pkg$xtools/icfit/icgfit.gx +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icparams.x +pkg$xtools/icfit/icfit.h +pkg$xtools/icfit/icfit.hlp + 1. Added 'z' key to delete individual sample regions. + 2. Increased the internal sample string to 1024 characters. + (9/4/91, Valdes) + +pkg$xtools/icfit/icfit.hlp +pkg$xtools/icfit/icgfit.gx +pkg$xtools/icfit/icgadd.gx +pkg$xtools/icfit/ mkpkg + Added 'a' key to allow adding points for constraining the fit. + (9/3/91, Valdes) + +pkg$xtools/icfit/icfit.hlp + Fixed typo for :errors description. (11/20/90, Valdes) + +pkg$xtools/icfit/icgcolon.gx + 1. Unrecognized or ambiguous colon commands are now noted. + (10/2/90, Valdes) + +pkg$xtools/icfit/icvshow.gx +pkg$xtools/icfit/icgcolon.gx +pkg$xtools/icfit/icfit.hlp +noaolib$scr/icgfit.key + 1. The :vshow command now does not print the (x, y fit, y) values. + 2. A new user command, :xyshow, prints the (x, y fit, y) values. + (5/16/90, Valdes) + +==== +V2.9 +==== + +pkg$xtools/icfit/icparams.x +pkg$xtools/icfit/icgcolon.x + 1. ic_puti uses max (1, order) for setting the order. + 2. icg_colon prints error if attempting to set order < 1. + (3/6/90, Valdes) + +pkg$xtools/icfit/icparams.x + Added ability to get information about the number of fit points and the + rejected points to the ic_geti procedure. (5/4/89, Valdes) + +pkg$xtools/icfit/icggraph.gx + Scaled the symbol used for marking average points to the appropriate + coordinate system. This is still only approximately correct. + Based on a report by Ivo Busko. (3/1/89, Valdes) + +pkg$xtools/icfit/icvshow.gx + + Changed output format of 3 values so 7 digits of precision are printed. + This was in response to a user request for the utilities.curfit task, + but all programs calling icvshow will be affected. (ShJ 3-NOV-88) + +< call fprintf (fd, "RMS = %10.7g\n") +> call fprintf (fd, "RMS = %7.4g\n") + +< call fprintf (fd, "square root of reduced chi square = %10.7g\n") +> call fprintf (fd, "square root of reduced chi square = %7.4g\n") + +< call fprintf (fd, "\t%14.7e\t%14.7e\n") +> call fprintf (fd, "\t%10.4e\t%10.4e\n") + +pkg$xtools/icfit/icgfit.gx +pkg$xtools/icfit/icgaddfit.gx +noao$lib/scr/icgfit.key + Added 'I' interrupt key. (4/20/88 Valdes) + +pkg$xtools/icfit/icgfit.gx +pkg$xtools/icfit/icgparams.gx + Valdes, Jan. 5, 1988 + Added checks for an error in fitting the curve. + +pkg$xtools/icfit/icgfit.gx + Valdes, Oct. 2, 1987 + 1. When doing sample regions there was a round off problem with + negative numbers. Replaced int(x+.5) with nint(x). + +pkg$xtools/icfit/icfit.h +pkg$xtools/icfit/icparams.x +pkg$xtools/icfit/icguaxes.gx + Valdes, February 20,1987 + 1. Made the cursor help file a setable parameter since the graph + keys are definable by the application. + 2. Added the radial velocity axis type explicitly to the package + to remove the need for onedspec.identify to have it's own copy + of the package. + +pkg$xtools/icfit/*x + Valdes, February 17, 1987 + 1. Required GIO changes. + +pkg$xtools/icfit/icgcolon.gx + Valdes, January 16, 1987 + 1. Colon command dictionary and switch modified to use macro definitions. + +pkg$xtools/icfit/icgfit.gx +noao$lib/scr/icgfit.key +noao$lib/scr/icgaxes.key - + Valdes, January 13, 1987 + 1. When setting sample ranges with the cursor the range limits are now + rounded to the nearest integer only if the x values are integers. + Previously it always rounded even if the data were not integers. + 2. Modified to use system page procedure for printing help. + 3. Revised the help file and included the graph axes help in the same + file since it is now paged. The separate axes help file was deleted. + +pkg$xtools/icfit/icgcolon.gx + Valdes, October 7, 1986 + 1. It is no longer possible to set naverage to 0 which causes ICFIT + to crash. A message is now printed telling the user that 0 is + not a legal value. This error is present in V2.3 and earlier. + +pkg$xtools/icfit/icgdelete.gx +pkg$xtools/icfit/icgundelete.gx + Valdes, September 8, 1986 + 1. Procedures were defined as function but used as subroutines. The + function declarations were removed. Found during the Alliant port. + +pkg$xtools/icfit/icgfit.gx +noao$onedspec/identify/icfit/icgfit.gx + Valdes, August 21, 1986 + 1. When defining sample ranges interactively with the cursor the + new sample string was appended to the previous string without + a leading space and with a trailing space. This was fine if + the sample was defined only interactively or only explicitly + as a string. However, appending an interactive sample to one + the user types in (without a trailing blank) is an error. + Changed the interactive appending to put a leading blank and + no trailing blank. + +noao$lib/src/icgfit.key + Valdes, August 20, 1986 + 1. The key file listed :lowreject and :highreject instead of the + correct :low_reject and :high_reject. The key file was fixed. + +==================================== +Version 2.3 Release, August 18, 1986 +==================================== + +icfit$: Valdes, August 11, 1986 + 1. Reorganized package to have separate objects for each procedure. + This allows loading only the procedures of the desired datatype. + +icfit$icgfit.gx: Valdes, August 7, 1986 + 1. The 'c' key was using a fixed format inappropriate for some types + of data. The formats where changed to general %g format. + +icfit$icgfit.gx: Valdes, August 7, 1986 + 1. A bug in the generic code was causing a double to be + passed to gt_setr which caused the windowing to be wrong. + This bug appeared only in the SUN. + 2. A bug in writing the current key definition with the 'g' key was + fixed. This bug appeared only in the SUN. + +icfit: Valdes, July 3, 1986 + 1. New ICFIT package. + +icfit$icggraph.gx: Valdes, April 28, 1986 + 1. Fixed bug in icggraph.gx: + real $tcveval ---> PIXEL $tcveval + +icfit$icgfit.gx,icgfit2.x,icgcolon.x: Valdes, April 7, 1986 + 1. Fixed use of STRIDX with a character constant to STRIDXS. + 2. Fixed problem with colon usage for ":sample" and ":function" + +icfit: Valdes, Mar 13, 1986: + 1. ICFIT package converted to generic form. The package now has entries + for both single precision and double precision data. It uses the new + curfit math library which now has double precision entries as well. + The external names of the single precision procedures are unchanged. +====== +Release 2.2 +====== +From Valdes Dec 30 , 1985 + +1. Setting of sample ranges by cursor was integer truncating giving the +funny result that if the cursor was set at 4.99 the sample limit was 4. +This has been changed so that the sample limit is rounded to the nearest +integer. +------ +From Valdes Nov 20 , 1985 + +1. New procedure ICG_FIT2 added. This procedure does all graphics +open and closes and has cl parameters "graphics", "plots", and "cursor". +This will eventually phase out ICG_FIT. + +2. Procedures modified to use an array of GTOOLS pointers instead of +keeping them in separate variables. This allows easy expansion to add +additional graph formats. +------ +From Valdes Oct 17 , 1985 + +1. Graphing the zero line was removed from icggraph.x because the line +interfered with fitting data near zero. +------ +From Valdes Oct 4, 1985 + +1. The package was modified to add high and low rejection and to iterate +the rejection algorithm. + +2. Procedure icg_params was add to label the graphs with the fitting +parameters. +.endhelp diff --git a/pkg/xtools/icfit/icclean.gx b/pkg/xtools/icfit/icclean.gx new file mode 100644 index 00000000..0d5dd08a --- /dev/null +++ b/pkg/xtools/icfit/icclean.gx @@ -0,0 +1,92 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/rg.h> +include "icfit.h" +include "names.h" + +# IC_CLEAN -- Replace rejected points by the fitted values. + +procedure ic_clean$t (ic, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +PIXEL x[npts] # Ordinates +PIXEL y[npts] # Abscissas +PIXEL w[npts] # Weights +int npts # Number of points + +int i, nclean, newreject +pointer sp, xclean, yclean, wclean + +PIXEL $tcveval() + +begin + if ((IC_LOW(ic) == 0.) && (IC_HIGH(ic) == 0.)) + return + + # If there has been no subsampling and no sample averaging then the + # IC_REJPTS(ic) array already contains the rejected points. + + if (npts == IC_NFIT(ic)) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = $tcveval (cv, x[i]) + } + } + + # If there has been no sample averaging then the rejpts array already + # contains indices into the subsampled array. + + } else if (abs(IC_NAVERAGE(ic)) < 2) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Mem$t[IC_YFIT(ic)+i-1] = + $tcveval (cv, Mem$t[IC_XFIT(ic)+i-1]) + } + } + call rg_unpack$t (IC_RG(ic), Mem$t[IC_YFIT(ic)], y) + + # Because ic_fit rejects points from the fitting data which + # has been sample averaged the rejpts array refers to the wrong data. + # Do the cleaning using ic_deviant to find the points to reject. + + } else if (RG_NPTS(IC_RG(ic)) == npts) { + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviant$t (cv, x, y, w, Memi[IC_REJPTS(ic)], npts, + IC_LOW(ic), IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), + newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = $tcveval (cv, x[i]) + } + } + + # If there is subsampling then allocate temporary arrays for the + # subsample points. + + } else { + call smark (sp) + nclean = RG_NPTS(IC_RG(ic)) + call salloc (xclean, nclean, TY_PIXEL) + call salloc (yclean, nclean, TY_PIXEL) + call salloc (wclean, nclean, TY_PIXEL) + call rg_pack$t (IC_RG(ic), x, Mem$t[xclean]) + call rg_pack$t (IC_RG(ic), y, Mem$t[yclean]) + call rg_pack$t (IC_RG(ic), w, Mem$t[wclean]) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviant$t (cv, Mem$t[xclean], Mem$t[yclean], + Mem$t[wclean], Memi[IC_REJPTS(ic)], nclean, IC_LOW(ic), + IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Mem$t[yclean+i-1] = $tcveval (cv, Mem$t[xclean+i-1]) + } + } + call rg_unpack$t (IC_RG(ic), Mem$t[yclean], y) + call sfree (sp) + } +end diff --git a/pkg/xtools/icfit/iccleand.x b/pkg/xtools/icfit/iccleand.x new file mode 100644 index 00000000..97c88a19 --- /dev/null +++ b/pkg/xtools/icfit/iccleand.x @@ -0,0 +1,92 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/rg.h> +include "icfit.h" +include "names.h" + +# IC_CLEAN -- Replace rejected points by the fitted values. + +procedure ic_cleand (ic, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[npts] # Ordinates +double y[npts] # Abscissas +double w[npts] # Weights +int npts # Number of points + +int i, nclean, newreject +pointer sp, xclean, yclean, wclean + +double dcveval() + +begin + if ((IC_LOW(ic) == 0.) && (IC_HIGH(ic) == 0.)) + return + + # If there has been no subsampling and no sample averaging then the + # IC_REJPTS(ic) array already contains the rejected points. + + if (npts == IC_NFIT(ic)) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = dcveval (cv, x[i]) + } + } + + # If there has been no sample averaging then the rejpts array already + # contains indices into the subsampled array. + + } else if (abs(IC_NAVERAGE(ic)) < 2) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[IC_YFIT(ic)+i-1] = + dcveval (cv, Memd[IC_XFIT(ic)+i-1]) + } + } + call rg_unpackd (IC_RG(ic), Memd[IC_YFIT(ic)], y) + + # Because ic_fit rejects points from the fitting data which + # has been sample averaged the rejpts array refers to the wrong data. + # Do the cleaning using ic_deviant to find the points to reject. + + } else if (RG_NPTS(IC_RG(ic)) == npts) { + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviantd (cv, x, y, w, Memi[IC_REJPTS(ic)], npts, + IC_LOW(ic), IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), + newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = dcveval (cv, x[i]) + } + } + + # If there is subsampling then allocate temporary arrays for the + # subsample points. + + } else { + call smark (sp) + nclean = RG_NPTS(IC_RG(ic)) + call salloc (xclean, nclean, TY_DOUBLE) + call salloc (yclean, nclean, TY_DOUBLE) + call salloc (wclean, nclean, TY_DOUBLE) + call rg_packd (IC_RG(ic), x, Memd[xclean]) + call rg_packd (IC_RG(ic), y, Memd[yclean]) + call rg_packd (IC_RG(ic), w, Memd[wclean]) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviantd (cv, Memd[xclean], Memd[yclean], + Memd[wclean], Memi[IC_REJPTS(ic)], nclean, IC_LOW(ic), + IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[yclean+i-1] = dcveval (cv, Memd[xclean+i-1]) + } + } + call rg_unpackd (IC_RG(ic), Memd[yclean], y) + call sfree (sp) + } +end diff --git a/pkg/xtools/icfit/iccleanr.x b/pkg/xtools/icfit/iccleanr.x new file mode 100644 index 00000000..cbcff319 --- /dev/null +++ b/pkg/xtools/icfit/iccleanr.x @@ -0,0 +1,92 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/rg.h> +include "icfit.h" +include "names.h" + +# IC_CLEAN -- Replace rejected points by the fitted values. + +procedure ic_cleanr (ic, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[npts] # Ordinates +real y[npts] # Abscissas +real w[npts] # Weights +int npts # Number of points + +int i, nclean, newreject +pointer sp, xclean, yclean, wclean + +real rcveval() + +begin + if ((IC_LOW(ic) == 0.) && (IC_HIGH(ic) == 0.)) + return + + # If there has been no subsampling and no sample averaging then the + # IC_REJPTS(ic) array already contains the rejected points. + + if (npts == IC_NFIT(ic)) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = rcveval (cv, x[i]) + } + } + + # If there has been no sample averaging then the rejpts array already + # contains indices into the subsampled array. + + } else if (abs(IC_NAVERAGE(ic)) < 2) { + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[IC_YFIT(ic)+i-1] = + rcveval (cv, Memr[IC_XFIT(ic)+i-1]) + } + } + call rg_unpackr (IC_RG(ic), Memr[IC_YFIT(ic)], y) + + # Because ic_fit rejects points from the fitting data which + # has been sample averaged the rejpts array refers to the wrong data. + # Do the cleaning using ic_deviant to find the points to reject. + + } else if (RG_NPTS(IC_RG(ic)) == npts) { + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviantr (cv, x, y, w, Memi[IC_REJPTS(ic)], npts, + IC_LOW(ic), IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), + newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + y[i] = rcveval (cv, x[i]) + } + } + + # If there is subsampling then allocate temporary arrays for the + # subsample points. + + } else { + call smark (sp) + nclean = RG_NPTS(IC_RG(ic)) + call salloc (xclean, nclean, TY_REAL) + call salloc (yclean, nclean, TY_REAL) + call salloc (wclean, nclean, TY_REAL) + call rg_packr (IC_RG(ic), x, Memr[xclean]) + call rg_packr (IC_RG(ic), y, Memr[yclean]) + call rg_packr (IC_RG(ic), w, Memr[wclean]) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + call ic_deviantr (cv, Memr[xclean], Memr[yclean], + Memr[wclean], Memi[IC_REJPTS(ic)], nclean, IC_LOW(ic), + IC_HIGH(ic), IC_GROW(ic), NO, IC_NREJECT(ic), newreject) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[yclean+i-1] = rcveval (cv, Memr[xclean+i-1]) + } + } + call rg_unpackr (IC_RG(ic), Memr[yclean], y) + call sfree (sp) + } +end diff --git a/pkg/xtools/icfit/icdeviant.gx b/pkg/xtools/icfit/icdeviant.gx new file mode 100644 index 00000000..e4e2cff3 --- /dev/null +++ b/pkg/xtools/icfit/icdeviant.gx @@ -0,0 +1,134 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <math/curfit.h> +include "names.h" + +# IC_DEVIANT -- Find deviant points with large residuals from the fit +# and reject from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at +-reject*sigma. Points outside the rejection threshold are +# recorded in the reject array. + +procedure ic_deviant$t (cv, x, y, w, rejpts, npts, low_reject, high_reject, + grow, refit, nreject, newreject) + +pointer cv # Curve descriptor +PIXEL x[npts] # Input ordinates +PIXEL y[npts] # Input data values +PIXEL w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection thresholds +real grow # Rejection radius +int refit # Refit the curve? +int nreject # Number of points rejected +int newreject # Number of new points rejected + +int i, j, i_min, i_max, pixgrow +PIXEL sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin + # If low_reject and high_reject are zero then simply return. + + if ((low_reject == 0.) && (high_reject == 0.)) + return + + # Allocate memory for the residuals. + + call smark (sp) + call salloc (residuals, npts, TY_PIXEL) + + # Compute the residuals. + + call $tcvvector (cv, x, Mem$t[residuals], npts) + call asub$t (y, Mem$t[residuals], Mem$t[residuals], npts) + + # Compute the sigma of the residuals. If there are less than + # 5 points return. + + j = 0 + nreject = 0 + sigma = 0. + + do i = 1, npts { + if ((w[i] != 0.) && (rejpts[i] == NO)) { + sigma = sigma + Mem$t[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + if (low_reject > 0.) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > 0.) + high_cut = high_reject * sigma + else + high_cut = MAX_REAL + + # Reject the residuals exceeding the rejection limits. + # A for loop is used instead of do because with region growing we + # want to modify the loop index. + + pixgrow = 0 + if (grow > 0.) { + do i = 1, npts-1 { + if (abs (x[i+1] - x[i]) < 0.0001) + next + if (i == 1) + pixgrow = grow / abs (x[i+1] - x[i]) + else + pixgrow = max (grow / abs (x[i+1] - x[i]), pixgrow) + } + } + + newreject = 0 + for (i = 1; i <= npts; i = i + 1) { + if (w[i] == 0. || rejpts[i] == YES) + next + + residual = Mem$t[residuals + i - 1] + if (residual < high_cut && residual > low_cut) + next + + i_min = max (1, i - pixgrow) + i_max = min (npts, i + pixgrow) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != 0.) && + (rejpts[j] == NO)) { + if (refit == YES) + call $tcvrject (cv, x[j], y[j], w[j]) + rejpts[j] = 2 + newreject = newreject + 1 + } + } + } + do i = 1, npts + if (rejpts[i] != NO) + rejpts[i] = YES + + nreject = nreject + newreject + call sfree (sp) + + if ((refit == YES) && (newreject > 0)) { + call $tcvsolve (cv, i) + switch (i) { + case SINGULAR: + call error (1, "ic_reject: Singular solution") + case NO_DEG_FREEDOM: + call error (2, "ic_reject: No degrees of freedom") + } + } +end diff --git a/pkg/xtools/icfit/icdeviantd.x b/pkg/xtools/icfit/icdeviantd.x new file mode 100644 index 00000000..ab16b3d5 --- /dev/null +++ b/pkg/xtools/icfit/icdeviantd.x @@ -0,0 +1,134 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <math/curfit.h> +include "names.h" + +# IC_DEVIANT -- Find deviant points with large residuals from the fit +# and reject from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at +-reject*sigma. Points outside the rejection threshold are +# recorded in the reject array. + +procedure ic_deviantd (cv, x, y, w, rejpts, npts, low_reject, high_reject, + grow, refit, nreject, newreject) + +pointer cv # Curve descriptor +double x[npts] # Input ordinates +double y[npts] # Input data values +double w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection thresholds +real grow # Rejection radius +int refit # Refit the curve? +int nreject # Number of points rejected +int newreject # Number of new points rejected + +int i, j, i_min, i_max, pixgrow +double sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin + # If low_reject and high_reject are zero then simply return. + + if ((low_reject == 0.) && (high_reject == 0.)) + return + + # Allocate memory for the residuals. + + call smark (sp) + call salloc (residuals, npts, TY_DOUBLE) + + # Compute the residuals. + + call dcvvector (cv, x, Memd[residuals], npts) + call asubd (y, Memd[residuals], Memd[residuals], npts) + + # Compute the sigma of the residuals. If there are less than + # 5 points return. + + j = 0 + nreject = 0 + sigma = 0. + + do i = 1, npts { + if ((w[i] != 0.) && (rejpts[i] == NO)) { + sigma = sigma + Memd[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + if (low_reject > 0.) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > 0.) + high_cut = high_reject * sigma + else + high_cut = MAX_REAL + + # Reject the residuals exceeding the rejection limits. + # A for loop is used instead of do because with region growing we + # want to modify the loop index. + + pixgrow = 0 + if (grow > 0.) { + do i = 1, npts-1 { + if (abs (x[i+1] - x[i]) < 0.0001) + next + if (i == 1) + pixgrow = grow / abs (x[i+1] - x[i]) + else + pixgrow = max (grow / abs (x[i+1] - x[i]), pixgrow) + } + } + + newreject = 0 + for (i = 1; i <= npts; i = i + 1) { + if (w[i] == 0. || rejpts[i] == YES) + next + + residual = Memd[residuals + i - 1] + if (residual < high_cut && residual > low_cut) + next + + i_min = max (1, i - pixgrow) + i_max = min (npts, i + pixgrow) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != 0.) && + (rejpts[j] == NO)) { + if (refit == YES) + call dcvrject (cv, x[j], y[j], w[j]) + rejpts[j] = 2 + newreject = newreject + 1 + } + } + } + do i = 1, npts + if (rejpts[i] != NO) + rejpts[i] = YES + + nreject = nreject + newreject + call sfree (sp) + + if ((refit == YES) && (newreject > 0)) { + call dcvsolve (cv, i) + switch (i) { + case SINGULAR: + call error (1, "ic_reject: Singular solution") + case NO_DEG_FREEDOM: + call error (2, "ic_reject: No degrees of freedom") + } + } +end diff --git a/pkg/xtools/icfit/icdeviantr.x b/pkg/xtools/icfit/icdeviantr.x new file mode 100644 index 00000000..5d584377 --- /dev/null +++ b/pkg/xtools/icfit/icdeviantr.x @@ -0,0 +1,134 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <math/curfit.h> +include "names.h" + +# IC_DEVIANT -- Find deviant points with large residuals from the fit +# and reject from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at +-reject*sigma. Points outside the rejection threshold are +# recorded in the reject array. + +procedure ic_deviantr (cv, x, y, w, rejpts, npts, low_reject, high_reject, + grow, refit, nreject, newreject) + +pointer cv # Curve descriptor +real x[npts] # Input ordinates +real y[npts] # Input data values +real w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection thresholds +real grow # Rejection radius +int refit # Refit the curve? +int nreject # Number of points rejected +int newreject # Number of new points rejected + +int i, j, i_min, i_max, pixgrow +real sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin + # If low_reject and high_reject are zero then simply return. + + if ((low_reject == 0.) && (high_reject == 0.)) + return + + # Allocate memory for the residuals. + + call smark (sp) + call salloc (residuals, npts, TY_REAL) + + # Compute the residuals. + + call rcvvector (cv, x, Memr[residuals], npts) + call asubr (y, Memr[residuals], Memr[residuals], npts) + + # Compute the sigma of the residuals. If there are less than + # 5 points return. + + j = 0 + nreject = 0 + sigma = 0. + + do i = 1, npts { + if ((w[i] != 0.) && (rejpts[i] == NO)) { + sigma = sigma + Memr[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + if (low_reject > 0.) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > 0.) + high_cut = high_reject * sigma + else + high_cut = MAX_REAL + + # Reject the residuals exceeding the rejection limits. + # A for loop is used instead of do because with region growing we + # want to modify the loop index. + + pixgrow = 0 + if (grow > 0.) { + do i = 1, npts-1 { + if (abs (x[i+1] - x[i]) < 0.0001) + next + if (i == 1) + pixgrow = grow / abs (x[i+1] - x[i]) + else + pixgrow = max (grow / abs (x[i+1] - x[i]), pixgrow) + } + } + + newreject = 0 + for (i = 1; i <= npts; i = i + 1) { + if (w[i] == 0. || rejpts[i] == YES) + next + + residual = Memr[residuals + i - 1] + if (residual < high_cut && residual > low_cut) + next + + i_min = max (1, i - pixgrow) + i_max = min (npts, i + pixgrow) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != 0.) && + (rejpts[j] == NO)) { + if (refit == YES) + call rcvrject (cv, x[j], y[j], w[j]) + rejpts[j] = 2 + newreject = newreject + 1 + } + } + } + do i = 1, npts + if (rejpts[i] != NO) + rejpts[i] = YES + + nreject = nreject + newreject + call sfree (sp) + + if ((refit == YES) && (newreject > 0)) { + call rcvsolve (cv, i) + switch (i) { + case SINGULAR: + call error (1, "ic_reject: Singular solution") + case NO_DEG_FREEDOM: + call error (2, "ic_reject: No degrees of freedom") + } + } +end diff --git a/pkg/xtools/icfit/icdosetup.gx b/pkg/xtools/icfit/icdosetup.gx new file mode 100644 index 00000000..b4ec4c55 --- /dev/null +++ b/pkg/xtools/icfit/icdosetup.gx @@ -0,0 +1,121 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_DOSETUP -- Setup the fit. This is called at the start of each call +# to ic_fit to update the fitting parameters if necessary. + +procedure ic_dosetup$t (ic, cv, x, wts, npts, newx, newwts, newfunction, refit) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +PIXEL x[npts] # Ordinates of data +PIXEL wts[npts] # Weights +int npts # Number of points in data +int newx # New x points? +int newwts # New weights? +int newfunction # New function? +int refit # Use cvrefit? + +int ord +PIXEL xmin, xmax + +pointer rg_xranges$t() +#extern hd_power$t() +errchk rg_xranges$t + +begin + # Set sample points. + if ((newx == YES) || (newwts == YES)) { + if (npts == 0) + call error (0, "No data points for fit") + + call mfree (IC_XFIT(ic), TY_PIXEL) + call mfree (IC_YFIT(ic), TY_PIXEL) + call malloc (IC_XFIT(ic), npts, TY_PIXEL) + + call mfree (IC_WTSFIT(ic), TY_PIXEL) + call malloc (IC_WTSFIT(ic), npts, TY_PIXEL) + + call mfree (IC_REJPTS(ic), TY_INT) + call malloc (IC_REJPTS(ic), npts, TY_INT) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + IC_NREJECT(ic) = 0 + + # Set sample points. + + call rg_free (IC_RG(ic)) + IC_RG(ic) = rg_xranges$t (Memc[IC_SAMPLE(ic)], x, npts) + call rg_order (IC_RG(ic)) + call rg_merge (IC_RG(ic)) + call rg_wtbin$t (IC_RG(ic), max (1, abs (IC_NAVERAGE(ic))), x, wts, + npts, Mem$t[IC_XFIT(ic)], Mem$t[IC_WTSFIT(ic)], IC_NFIT(ic)) + + if (IC_NFIT(ic) == 0) + call error (0, "No sample points for fit") + + if (IC_NFIT(ic) == npts) { + call rg_free (IC_RG(ic)) + call mfree (IC_XFIT(ic), TY_PIXEL) + call mfree (IC_WTSFIT(ic), TY_PIXEL) + IC_YFIT(ic) = NULL + IC_WTSFIT(ic) = NULL + call alim$t (x, npts, xmin, xmax) + } else { + call malloc (IC_YFIT(ic), IC_NFIT(ic), TY_PIXEL) + if (IC_NFIT(ic) == 1) + call alim$t (x, npts, xmin, xmax) + else + call alim$t (Mem$t[IC_XFIT(ic)], IC_NFIT(ic), xmin, xmax) + } + + IC_XMIN(ic) = min (IC_XMIN(ic), real(xmin)) + IC_XMAX(ic) = max (IC_XMAX(ic), real(xmax)) + refit = NO + } + + # Set curve fitting parameters. + # For polynomials define fitting range over range of data in fit + # and assume extrpolation is ok. For spline functions define + # fitting range to be range of evaluation set by the caller + # since extrapolation will not make sense. + + if ((newx == YES) || (newfunction == YES)) { + if (cv != NULL) + call $tcvfree (cv) + + switch (IC_FUNCTION(ic)) { + case LEGENDRE, CHEBYSHEV: + ord = min (IC_ORDER(ic), IC_NFIT(ic)) + call $tcvinit (cv, IC_FUNCTION(ic), ord, PIXEL (xmin), + PIXEL (xmax)) + case SPLINE1: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 1) + if (ord > 0) + call $tcvinit (cv, SPLINE1, ord, PIXEL (IC_XMIN(ic)), + PIXEL (IC_XMAX(ic))) + else + call $tcvinit (cv, LEGENDRE, IC_NFIT(ic), + PIXEL (IC_XMIN(ic)), PIXEL (IC_XMAX(ic))) + case SPLINE3: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 3) + if (ord > 0) + call $tcvinit (cv, SPLINE3, ord, PIXEL (IC_XMIN(ic)), + PIXEL (IC_XMAX(ic))) + else + call $tcvinit (cv, LEGENDRE, IC_NFIT(ic), + PIXEL (IC_XMIN(ic)), PIXEL (IC_XMAX(ic))) +# case USERFNC: +# ord = min (IC_ORDER(ic), IC_NFIT(ic)) +# call $tcvinit (cv, USERFNC, ord, PIXEL (IC_XMIN(ic)), +# PIXEL (IC_XMAX(ic))) +# call $tcvuserfnc (cv, hd_power$t) + default: + call error (0, "Unknown fitting function") + } + + refit = NO + } +end diff --git a/pkg/xtools/icfit/icdosetupd.x b/pkg/xtools/icfit/icdosetupd.x new file mode 100644 index 00000000..98b64939 --- /dev/null +++ b/pkg/xtools/icfit/icdosetupd.x @@ -0,0 +1,121 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_DOSETUP -- Setup the fit. This is called at the start of each call +# to ic_fit to update the fitting parameters if necessary. + +procedure ic_dosetupd (ic, cv, x, wts, npts, newx, newwts, newfunction, refit) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[npts] # Ordinates of data +double wts[npts] # Weights +int npts # Number of points in data +int newx # New x points? +int newwts # New weights? +int newfunction # New function? +int refit # Use cvrefit? + +int ord +double xmin, xmax + +pointer rg_xrangesd() +#extern hd_power$t() +errchk rg_xrangesd + +begin + # Set sample points. + if ((newx == YES) || (newwts == YES)) { + if (npts == 0) + call error (0, "No data points for fit") + + call mfree (IC_XFIT(ic), TY_DOUBLE) + call mfree (IC_YFIT(ic), TY_DOUBLE) + call malloc (IC_XFIT(ic), npts, TY_DOUBLE) + + call mfree (IC_WTSFIT(ic), TY_DOUBLE) + call malloc (IC_WTSFIT(ic), npts, TY_DOUBLE) + + call mfree (IC_REJPTS(ic), TY_INT) + call malloc (IC_REJPTS(ic), npts, TY_INT) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + IC_NREJECT(ic) = 0 + + # Set sample points. + + call rg_free (IC_RG(ic)) + IC_RG(ic) = rg_xrangesd (Memc[IC_SAMPLE(ic)], x, npts) + call rg_order (IC_RG(ic)) + call rg_merge (IC_RG(ic)) + call rg_wtbind (IC_RG(ic), max (1, abs (IC_NAVERAGE(ic))), x, wts, + npts, Memd[IC_XFIT(ic)], Memd[IC_WTSFIT(ic)], IC_NFIT(ic)) + + if (IC_NFIT(ic) == 0) + call error (0, "No sample points for fit") + + if (IC_NFIT(ic) == npts) { + call rg_free (IC_RG(ic)) + call mfree (IC_XFIT(ic), TY_DOUBLE) + call mfree (IC_WTSFIT(ic), TY_DOUBLE) + IC_YFIT(ic) = NULL + IC_WTSFIT(ic) = NULL + call alimd (x, npts, xmin, xmax) + } else { + call malloc (IC_YFIT(ic), IC_NFIT(ic), TY_DOUBLE) + if (IC_NFIT(ic) == 1) + call alimd (x, npts, xmin, xmax) + else + call alimd (Memd[IC_XFIT(ic)], IC_NFIT(ic), xmin, xmax) + } + + IC_XMIN(ic) = min (IC_XMIN(ic), real(xmin)) + IC_XMAX(ic) = max (IC_XMAX(ic), real(xmax)) + refit = NO + } + + # Set curve fitting parameters. + # For polynomials define fitting range over range of data in fit + # and assume extrpolation is ok. For spline functions define + # fitting range to be range of evaluation set by the caller + # since extrapolation will not make sense. + + if ((newx == YES) || (newfunction == YES)) { + if (cv != NULL) + call dcvfree (cv) + + switch (IC_FUNCTION(ic)) { + case LEGENDRE, CHEBYSHEV: + ord = min (IC_ORDER(ic), IC_NFIT(ic)) + call dcvinit (cv, IC_FUNCTION(ic), ord, double (xmin), + double (xmax)) + case SPLINE1: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 1) + if (ord > 0) + call dcvinit (cv, SPLINE1, ord, double (IC_XMIN(ic)), + double (IC_XMAX(ic))) + else + call dcvinit (cv, LEGENDRE, IC_NFIT(ic), + double (IC_XMIN(ic)), double (IC_XMAX(ic))) + case SPLINE3: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 3) + if (ord > 0) + call dcvinit (cv, SPLINE3, ord, double (IC_XMIN(ic)), + double (IC_XMAX(ic))) + else + call dcvinit (cv, LEGENDRE, IC_NFIT(ic), + double (IC_XMIN(ic)), double (IC_XMAX(ic))) +# case USERFNC: +# ord = min (IC_ORDER(ic), IC_NFIT(ic)) +# call $tcvinit (cv, USERFNC, ord, PIXEL (IC_XMIN(ic)), +# PIXEL (IC_XMAX(ic))) +# call $tcvuserfnc (cv, hd_power$t) + default: + call error (0, "Unknown fitting function") + } + + refit = NO + } +end diff --git a/pkg/xtools/icfit/icdosetupr.x b/pkg/xtools/icfit/icdosetupr.x new file mode 100644 index 00000000..2039560d --- /dev/null +++ b/pkg/xtools/icfit/icdosetupr.x @@ -0,0 +1,121 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_DOSETUP -- Setup the fit. This is called at the start of each call +# to ic_fit to update the fitting parameters if necessary. + +procedure ic_dosetupr (ic, cv, x, wts, npts, newx, newwts, newfunction, refit) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[npts] # Ordinates of data +real wts[npts] # Weights +int npts # Number of points in data +int newx # New x points? +int newwts # New weights? +int newfunction # New function? +int refit # Use cvrefit? + +int ord +real xmin, xmax + +pointer rg_xrangesr() +#extern hd_power$t() +errchk rg_xrangesr + +begin + # Set sample points. + if ((newx == YES) || (newwts == YES)) { + if (npts == 0) + call error (0, "No data points for fit") + + call mfree (IC_XFIT(ic), TY_REAL) + call mfree (IC_YFIT(ic), TY_REAL) + call malloc (IC_XFIT(ic), npts, TY_REAL) + + call mfree (IC_WTSFIT(ic), TY_REAL) + call malloc (IC_WTSFIT(ic), npts, TY_REAL) + + call mfree (IC_REJPTS(ic), TY_INT) + call malloc (IC_REJPTS(ic), npts, TY_INT) + call amovki (NO, Memi[IC_REJPTS(ic)], npts) + IC_NREJECT(ic) = 0 + + # Set sample points. + + call rg_free (IC_RG(ic)) + IC_RG(ic) = rg_xrangesr (Memc[IC_SAMPLE(ic)], x, npts) + call rg_order (IC_RG(ic)) + call rg_merge (IC_RG(ic)) + call rg_wtbinr (IC_RG(ic), max (1, abs (IC_NAVERAGE(ic))), x, wts, + npts, Memr[IC_XFIT(ic)], Memr[IC_WTSFIT(ic)], IC_NFIT(ic)) + + if (IC_NFIT(ic) == 0) + call error (0, "No sample points for fit") + + if (IC_NFIT(ic) == npts) { + call rg_free (IC_RG(ic)) + call mfree (IC_XFIT(ic), TY_REAL) + call mfree (IC_WTSFIT(ic), TY_REAL) + IC_YFIT(ic) = NULL + IC_WTSFIT(ic) = NULL + call alimr (x, npts, xmin, xmax) + } else { + call malloc (IC_YFIT(ic), IC_NFIT(ic), TY_REAL) + if (IC_NFIT(ic) == 1) + call alimr (x, npts, xmin, xmax) + else + call alimr (Memr[IC_XFIT(ic)], IC_NFIT(ic), xmin, xmax) + } + + IC_XMIN(ic) = min (IC_XMIN(ic), real(xmin)) + IC_XMAX(ic) = max (IC_XMAX(ic), real(xmax)) + refit = NO + } + + # Set curve fitting parameters. + # For polynomials define fitting range over range of data in fit + # and assume extrpolation is ok. For spline functions define + # fitting range to be range of evaluation set by the caller + # since extrapolation will not make sense. + + if ((newx == YES) || (newfunction == YES)) { + if (cv != NULL) + call rcvfree (cv) + + switch (IC_FUNCTION(ic)) { + case LEGENDRE, CHEBYSHEV: + ord = min (IC_ORDER(ic), IC_NFIT(ic)) + call rcvinit (cv, IC_FUNCTION(ic), ord, real (xmin), + real (xmax)) + case SPLINE1: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 1) + if (ord > 0) + call rcvinit (cv, SPLINE1, ord, real (IC_XMIN(ic)), + real (IC_XMAX(ic))) + else + call rcvinit (cv, LEGENDRE, IC_NFIT(ic), + real (IC_XMIN(ic)), real (IC_XMAX(ic))) + case SPLINE3: + ord = min (IC_ORDER(ic), IC_NFIT(ic) - 3) + if (ord > 0) + call rcvinit (cv, SPLINE3, ord, real (IC_XMIN(ic)), + real (IC_XMAX(ic))) + else + call rcvinit (cv, LEGENDRE, IC_NFIT(ic), + real (IC_XMIN(ic)), real (IC_XMAX(ic))) +# case USERFNC: +# ord = min (IC_ORDER(ic), IC_NFIT(ic)) +# call $tcvinit (cv, USERFNC, ord, PIXEL (IC_XMIN(ic)), +# PIXEL (IC_XMAX(ic))) +# call $tcvuserfnc (cv, hd_power$t) + default: + call error (0, "Unknown fitting function") + } + + refit = NO + } +end diff --git a/pkg/xtools/icfit/icerrors.gx b/pkg/xtools/icfit/icerrors.gx new file mode 100644 index 00000000..114349e3 --- /dev/null +++ b/pkg/xtools/icfit/icerrors.gx @@ -0,0 +1,24 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "names.h" + +# IC_ERRORS -- Compute and error diagnositic information. + +procedure ic_errors$t (ic, file, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +PIXEL x[ARB] # Ordinates +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +int npts # Number of data points + +int fd, open() +errchk open, ic_ferrors$t + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_ferrors$t (ic, cv, x, y, wts, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icerrorsd.x b/pkg/xtools/icfit/icerrorsd.x new file mode 100644 index 00000000..763c7c4d --- /dev/null +++ b/pkg/xtools/icfit/icerrorsd.x @@ -0,0 +1,24 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "names.h" + +# IC_ERRORS -- Compute and error diagnositic information. + +procedure ic_errorsd (ic, file, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points + +int fd, open() +errchk open, ic_ferrorsd + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_ferrorsd (ic, cv, x, y, wts, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icerrorsr.x b/pkg/xtools/icfit/icerrorsr.x new file mode 100644 index 00000000..def6f603 --- /dev/null +++ b/pkg/xtools/icfit/icerrorsr.x @@ -0,0 +1,24 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "names.h" + +# IC_ERRORS -- Compute and error diagnositic information. + +procedure ic_errorsr (ic, file, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points + +int fd, open() +errchk open, ic_ferrorsr + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_ferrorsr (ic, cv, x, y, wts, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icferrors.gx b/pkg/xtools/icfit/icferrors.gx new file mode 100644 index 00000000..4c7ef109 --- /dev/null +++ b/pkg/xtools/icfit/icferrors.gx @@ -0,0 +1,141 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +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 diff --git a/pkg/xtools/icfit/icferrorsd.x b/pkg/xtools/icfit/icferrorsd.x new file mode 100644 index 00000000..03a5523c --- /dev/null +++ b/pkg/xtools/icfit/icferrorsd.x @@ -0,0 +1,141 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FERRORS -- Compute error diagnositic information. + +procedure ic_ferrorsd (ic, cv, x, y, wts, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +int fd # Output file descriptor + +int i, n, deleted, ncoeffs +double chisqr, rms +pointer sp, fit, wts1, coeffs, errors + +int dcvstati() +double ic_rmsd() + +begin + # Determine the number of coefficients and allocate memory. + + ncoeffs = dcvstati (cv, CVNCOEFF) + call smark (sp) + call salloc (coeffs, ncoeffs, TY_DOUBLE) + call salloc (errors, ncoeffs, TY_DOUBLE) + + if (npts == IC_NFIT(ic)) { + # Allocate memory for the fit. + + n = npts + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (wts, Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[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 dcvvector (cv, x, Memd[fit], n) + call dcvcoeff (cv, Memd[coeffs], ncoeffs) + call dcverrors (cv, y, Memd[wts1], Memd[fit], n, chisqr, + Memd[errors]) + rms = ic_rmsd (x, y, Memd[fit], Memd[wts1], n) + } else { + # Allocate memory for the fit. + + n = IC_NFIT(ic) + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (Memd[IC_WTSFIT(ic)], Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[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 dcvvector (cv, Memd[IC_XFIT(ic)], Memd[fit], n) + rms = ic_rmsd (Memd[IC_XFIT(ic)], Memd[IC_YFIT(ic)], + Memd[fit], Memd[wts1], n) + call dcvcoeff (cv, Memd[coeffs], ncoeffs) + call dcverrors (cv, Memd[IC_YFIT(ic)], Memd[wts1], Memd[fit], + n, chisqr, Memd[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 pargd (rms) + call fprintf (fd, "# square root of reduced chi square = %7.4g\n") + call pargd (sqrt (chisqr)) + + # Free allocated memory. + + call sfree (sp) +end + +# IC_RMS -- Compute RMS of points which have not been deleted. + +double procedure ic_rmsd (x, y, fit, wts, npts) + +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double fit[ARB] # Fit +double wts[ARB] # Weights +int npts # Number of data points + +int i, n +double 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 diff --git a/pkg/xtools/icfit/icferrorsr.x b/pkg/xtools/icfit/icferrorsr.x new file mode 100644 index 00000000..61cf0d52 --- /dev/null +++ b/pkg/xtools/icfit/icferrorsr.x @@ -0,0 +1,141 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FERRORS -- Compute error diagnositic information. + +procedure ic_ferrorsr (ic, cv, x, y, wts, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +int fd # Output file descriptor + +int i, n, deleted, ncoeffs +real chisqr, rms +pointer sp, fit, wts1, coeffs, errors + +int rcvstati() +real ic_rmsr() + +begin + # Determine the number of coefficients and allocate memory. + + ncoeffs = rcvstati (cv, CVNCOEFF) + call smark (sp) + call salloc (coeffs, ncoeffs, TY_REAL) + call salloc (errors, ncoeffs, TY_REAL) + + if (npts == IC_NFIT(ic)) { + # Allocate memory for the fit. + + n = npts + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (wts, Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[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 rcvvector (cv, x, Memr[fit], n) + call rcvcoeff (cv, Memr[coeffs], ncoeffs) + call rcverrors (cv, y, Memr[wts1], Memr[fit], n, chisqr, + Memr[errors]) + rms = ic_rmsr (x, y, Memr[fit], Memr[wts1], n) + } else { + # Allocate memory for the fit. + + n = IC_NFIT(ic) + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (Memr[IC_WTSFIT(ic)], Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[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 rcvvector (cv, Memr[IC_XFIT(ic)], Memr[fit], n) + rms = ic_rmsr (Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)], + Memr[fit], Memr[wts1], n) + call rcvcoeff (cv, Memr[coeffs], ncoeffs) + call rcverrors (cv, Memr[IC_YFIT(ic)], Memr[wts1], Memr[fit], + n, chisqr, Memr[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 pargr (rms) + call fprintf (fd, "# square root of reduced chi square = %7.4g\n") + call pargr (sqrt (chisqr)) + + # Free allocated memory. + + call sfree (sp) +end + +# IC_RMS -- Compute RMS of points which have not been deleted. + +real procedure ic_rmsr (x, y, fit, wts, npts) + +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real fit[ARB] # Fit +real wts[ARB] # Weights +int npts # Number of data points + +int i, n +real 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 diff --git a/pkg/xtools/icfit/icfit.gx b/pkg/xtools/icfit/icfit.gx new file mode 100644 index 00000000..2c301360 --- /dev/null +++ b/pkg/xtools/icfit/icfit.gx @@ -0,0 +1,99 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + + +include <error.h> +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FIT -- Fit a function. This is the main fitting task. It uses +# flags to define changes since the last fit. This allows the most +# efficient use of the curfit and ranges packages. + +procedure ic_fit$t (ic, cv, x, y, wts, npts, newx, newy, newwts, newfunction) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +PIXEL x[npts] # Ordinates +PIXEL y[npts] # Data to be fit +PIXEL wts[npts] # Weights +int npts # Number of points +int newx # New x points? +int newy # New y points? +int newwts # New weights? +int newfunction # New function? + +int ier, refit + +errchk ic_dosetup$t, $tcvfit, $tcvrefit, rg_wtbin$t, ic_reject$t + +begin + IC_FITERROR(ic) = NO + + iferr { + # Setup the new parameters. + + call ic_dosetup$t (ic, cv, x, wts, npts, newx, newwts, newfunction, + refit) + + # If not sampling use the data array directly. + + if (npts == IC_NFIT(ic)) { + if (refit == NO) { + call $tcvfit (cv, x, y, wts, npts, WTS_USER, ier) + } else if (newy == YES) + call $tcvrefit (cv, x, y, wts, ier) + + # If sampling first form the sample y values. + + } else { + if ((newx == YES) || (newy == YES) || (newwts == YES)) + call rg_wtbin$t (IC_RG(ic), IC_NAVERAGE(ic), y, wts, npts, + Mem$t[IC_YFIT(ic)], Mem$t[IC_WTSFIT(ic)], IC_NFIT(ic)) + if (refit == NO) { + call $tcvfit (cv, Mem$t[IC_XFIT(ic)], Mem$t[IC_YFIT(ic)], + Mem$t[IC_WTSFIT(ic)], IC_NFIT(ic), WTS_USER, ier) + } else if (newy == YES) + call $tcvrefit (cv, Mem$t[IC_XFIT(ic)], Mem$t[IC_YFIT(ic)], + Mem$t[IC_WTSFIT(ic)], ier) + } + + # Check for an error in the fit. + + switch (ier) { + case SINGULAR: + call printf ("Singular solution\n") + call flush (STDOUT) + case NO_DEG_FREEDOM: + call printf ("No degrees of freedom\n") + call flush (STDOUT) + IC_FITERROR(ic) = YES + } + + if (IC_FITERROR(ic) == NO) { + refit = YES + + # Do pixel rejection if desired. + + if ((IC_LOW(ic) > 0.) || (IC_HIGH(ic) > 0.)) { + if (npts == IC_NFIT(ic)) + call ic_reject$t (cv, x, y, wts, Memi[IC_REJPTS(ic)], + IC_NFIT(ic), IC_LOW(ic), IC_HIGH(ic), + IC_NITERATE(ic), IC_GROW(ic), IC_NREJECT(ic)) + else + call ic_reject$t (cv, Mem$t[IC_XFIT(ic)], + Mem$t[IC_YFIT(ic)], Mem$t[IC_WTSFIT(ic)], + Memi[IC_REJPTS(ic)], IC_NFIT(ic), IC_LOW(ic), + IC_HIGH(ic), IC_NITERATE(ic), IC_GROW(ic), + IC_NREJECT(ic)) + + if (IC_NREJECT(ic) > 0) + refit = NO + } else + IC_NREJECT(ic) = 0 + } + } then { + IC_FITERROR(ic) = YES + call erract (EA_ERROR) + } +end diff --git a/pkg/xtools/icfit/icfit.h b/pkg/xtools/icfit/icfit.h new file mode 100644 index 00000000..3ea9023c --- /dev/null +++ b/pkg/xtools/icfit/icfit.h @@ -0,0 +1,50 @@ +# The ICFIT data structure + +define IC_NGKEYS 5 # Number of graph keys +define IC_LENSTRUCT 44 # Length of ICFIT structure +define IC_SZSAMPLE 1024 # Size of sample string + +# User fitting parameters +define IC_FUNCTION Memi[$1] # Function type +define IC_ORDER Memi[$1+1] # Order of function +define IC_SAMPLE Memi[$1+2] # Pointer to sample string +define IC_NAVERAGE Memi[$1+3] # Sampling averaging bin +define IC_NITERATE Memi[$1+4] # Number of rejection interation +define IC_XMIN Memr[P2R($1+5)] # Minimum value for curve +define IC_XMAX Memr[P2R($1+6)] # Maximum value for curve +define IC_LOW Memr[P2R($1+7)] # Low rejection value +define IC_HIGH Memr[P2R($1+8)] # Low rejection value +define IC_GROW Memr[P2R($1+9)] # Rejection growing radius + +# ICFIT parameters used for fitting +define IC_NFIT Memi[$1+10] # Number of fit points +define IC_NREJECT Memi[$1+11] # Number of rejected points +define IC_RG Memi[$1+12] # Pointer for ranges +define IC_XFIT Memi[$1+13] # Pointer to ordinates of fit points +define IC_YFIT Memi[$1+14] # Pointer to abscissas of fit points +define IC_WTSFIT Memi[$1+15] # Pointer to weights of fit points +define IC_REJPTS Memi[$1+16] # Pointer to rejected points + +# ICFIT parameters used for interactive graphics +define IC_NEWX Memi[$1+17] # New x fit points? +define IC_NEWY Memi[$1+18] # New y points? +define IC_NEWWTS Memi[$1+19] # New weights? +define IC_NEWFUNCTION Memi[$1+20] # New fitting function? +define IC_COLOR Memi[$1+21] # Fit color +define IC_OVERPLOT Memi[$1+22] # Overplot next plot? +define IC_FITERROR Memi[$1+23] # Error in fit +define IC_MARKREJ Memi[$1+24] # Mark rejected points? +define IC_LABELS Memi[$1+25+$2-1]# Graph axis labels +define IC_UNITS Memi[$1+27+$2-1]# Graph axis units +define IC_HELP Memi[$1+29] # Pointer to help file name +define IC_GP Memi[$1+30] # GIO pointer +define IC_GT Memi[$1+31] # GTOOLS pointer + +# ICFIT key definitions +define IC_GKEY Memi[$1+32] # Graph key +define IC_AXES Memi[$1+33+($2-1)*2+$3-1] # Graph axis codes + +# Default help file and prompt +define IC_DEFHELP "noao$lib/scr/icgfit.key" +define IC_DEFHTML "noao$lib/scr/icgfit.html" +define IC_PROMPT "icfit cursor options" diff --git a/pkg/xtools/icfit/icfit.hlp b/pkg/xtools/icfit/icfit.hlp new file mode 100644 index 00000000..3461c9ff --- /dev/null +++ b/pkg/xtools/icfit/icfit.hlp @@ -0,0 +1,229 @@ +.help icfit Sep91 xtools.icfit +.ih +NAME +icfit -- Interactive curve fitting +.ih +SYNOPSIS +A number of application tasks use the interactive curve fitting tools based +on the \fBcurfit\fR package for fitting curves to data. Interactive graphical +curve fitting begins by graphing the data points and the current fit in one of +five formats. When the cursor appears the user may modify the graphs and the +fit in a number of ways with cursor mode keystrokes and colon commands. +These are described below. +.ih +CURSOR MODE +.ls ? +The terminal is cleared and a menu of cursor keys and colon commands is printed. +.le +.ls a +Add points to contrain the fit. When adding points a query is made to set +the weights. A large weight will force the fit to go near the added point. +The added points are internal to the fitting routine and are not returned +or otherwise available to the particular task using the ICFIT capability. +.le +.ls c +The coordinates of the data point nearest the cursor and the fitted value +are printed on the status line. +.le +.ls d +The data point nearest the cursor and not previously deleted is marked with an +X. It will not be used in futher fits unless it is undeleted. +.le +.ls f +A curve is fit to the data and the fit is graphed in the current format. +.le +.ls g +Redefine the graph keys "h-l" from their defaults. A prompt is given for the +graph key which is to be redefined and then for the graph desired. +A '?' to either prompt prints help information. A graph +is given by a pair of comma separated data types. The first data type defines +the horizontal axis and the second defines the vertical axis. Any of the +data types may be graphed along either axis. The data types are +.nf + x Independent variable y Dependent variable + f Fitted value r Residual (y - f) + d Ratio (y / f) n Nonlinear part of y +.fi +.le +.ls h, i, j, k, l +Each key produces a different graph. The graphs are described by the data +which is graphed along each axis as defined above. The default graph keys +(which may be redefined with the 'g' key) are h=(x,y), i=(y,x), j=(x,r), +k=(x,d), l=(x,n). +.le +.ls o +Overplot the next fit provided the graph format is not changed. +.le +.ls q +Exit from the interactive curve fitting. Two consecutive carriage returns +(cursor end-of-file) may also be used. +.le +.ls r +Redraw the current graph. +.le +.ls s +Select a sample range. Set the cursor at one end point of the sample before +typing 's' and then set the cursor to the other endpoint and type any key +in response to the prompt "again:". Sample ranges are intersected unless +the sample ranges have been initialized to all the points with the key 't'. +.le +.ls t +Initialize the sample to include all data points. +.le +.ls u +Undelete the data point nearest the cursor which was previously deleted. +.le +.ls v +Change the fitting weight of the point nearest the cursor. +.le +.ls w +Set the graph window (range along each axis to be graphed). This is a +\fBgtools\fR option which prints the prompt "window:". The set of cursor +keys is printed with '?' and help is available under the keyword \fBgtools\fR. +.le +.ls x +Change the x value of the point nearest the cursor. +.le +.ls y +Change the y value of the point nearest the cursor. +.le +.ls z +Delete the nearest sample region to the cursor. +.le +.ih +COLON COMMANDS +Colon commands are show or set the values of parameters. The parameter names +may be abbreviated as may the function type. + +.ls :show [file] +Show the current values of all the fitting parameters. The default output +is the terminal (STDOUT) and the screen is cleared before the information +is output. If a file is specified then the information is appended to the +named file. +.le +.ls :vshow [file] +A verbose version of "show" which includes the fitted coefficients and their +errors. +.le +.ls :evaluate <value> +Evaluate the fit at the specified value and print the result on the status +line. +.le +.ls :xyshow [file] +List the independent (X), dependent (y), fitted (Y fit), and weight values. +The output may be listed on the screen or to a file. Note that if the +original input is combined into composit points (\fInaverage\fR not 1) +then the values are for the composite points. Deleted points will have +a weight of zero. +.le +.ls :errors [file] +Show the fitted function and square root of the chi square of the fit. +The default output +is the terminal (STDOUT) and the screen is cleared before the information +is output. If a file is specified then the information is appended to the +named file. +.le +.ls :function [value] +Show the current value or set the function type. The functions types are +"chebyshev", "legendre", "spline1", or "spline3" for chebyshev or legendre +polynomial or linear or cubic spline. +.le +.ls :grow [value] +Show the current value or set the rejection growing radius. Any points within +this distance of rejected points are also rejected. +.le +.ls :color [value=0-9] +Color of fit where 0=background (invisible), 1=foreground, and higher +numbers depend on the graphics device. Note that this applies to the +fit and to change the color of the data use ":/color". +.le +.ls :markrej [value] +Mark rejected points? If there are many rejected points then it might be +desired not to mark the points. +.le +.ls :naverage [value] +Show the current value or set the number of points to average or median to form +fitting points. A positive value select an mean and negative values select +a median. The averaged points are also shown in the graphs. +.le +.ls :order [value] +Show the current value or set the order of the function. For legendre or +chebyshev polynomials the order is the number of terms (i.e. an order of 2 +has two terms and is a linear function). For the splines the order is the +number of spline pieces. +.le +.ls :low_reject [value], :high_reject [value] +Show the current values or set the rejection limits. When a fit is made +if the rejection threshold is greater than zero then the sigma of the +residuals about the fit is computed. Points with residuals more than +this number of times the sigma are removed from the final fit. These +points are marked on the graphs with diamonds. +.le +.ls :niterate [value] +Show the current value or set a new value for the number of rejection +iterations. +.le +.ls :sample [value] +Show the current value or set the sample points to use in the fits. This +parameter is a string consisting of single points, colon separated ranges, +or "*" to indicate all points. A file containing sample strings may also +be specified by prefixing the file name with the character '@'. +Note that sample ranges may also be set with the cursor mode key 's'. +.le +.ih +DESCRIPTION +A one dimensional function is fit to a set of x and y data points. +The function may be a legendre polynomial, chebyshev polynomial, +linear spline, or cubic spline of a given order or number of spline pieces. + +The points fit are determined by selecting a sample of data specified by +the parameter \fIsample\fR and taking either the average or median of +the number of points specified by the parameter \fInaverage\fR. +The type of averaging is selected by the sign of the parameter and the number +of points is selected by the absolute value of the parameter. + +If \fIniterate\fR is greater than zero the sigma +of the residuals between the fitted points and the fitted function is computed +and those points whose residuals are less than \fI-low_reject\fR * sigma +or \fIhigh_reject\fR * sigma value are excluded from the fit. Points within +a distance of \fIgrow\fR pixels of a rejected pixel are also excluded from +the fit. The function is then refit without the rejected points. +The rejection can be iterated the number of times specified by the parameter +\fIniterate\fR. Note a rejection value of zero is the same as no rejection. +The rejected points may be marked with diamonds. The marking of rejected +points is controlled by the :markrej command. + +There are five types or formats of graphs selected by the keys 'h', 'i', 'j', +'k', and 'l'. The graphs are defined by what is plotted on each axis of the +graph. There are six data types, any of which may be plotted on either axis. +These data types are the independent data points (x), the dependent data +points (y), the fitted values (f), the residuals (r=y-f), the +ratio of the data to the fit (d=y/f), and the data with the linear term +of the fit (determined by the endpoints of the fit) subtracted. The +default graph keys are shown in the cursor key section though the definitions +may be modified by the application. The user may also redefine the graph +keys using the 'g' key. This gives a choice of 36 different graph types. + +It is important to remember that changing the value of a fitting +parameter does not change the fit until 'f' is typed. +.ih +NOTES +The sample region is stored internally as a string of length 1024 characters. +This is greatly increased over versions prior to V2.10. However, due +to the fixed default size of string parameters in parameter files (160 +characters), initial sample regions input with a CL parameter are limited +to this smaller length string. The limitation may be escaped by using +the new capability of specifying a file containing ranges. Also sample +regions initialize by a task parameter may be extended interactively. +.ih +REVISIONS +.ls ICFIT V2.11 +The :xyshow output was modified to 1) not include colon labels, +2) print (X, Y, Y fit, Weight) instead of (X, Y fit, Y), and 3) +the printed values are those actually used in the fit when using +composite points (naverage not 1). +.le +.ih +SEE ALSO +gtools +.endhelp diff --git a/pkg/xtools/icfit/icfitd.x b/pkg/xtools/icfit/icfitd.x new file mode 100644 index 00000000..88a0e66f --- /dev/null +++ b/pkg/xtools/icfit/icfitd.x @@ -0,0 +1,99 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + + +include <error.h> +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FIT -- Fit a function. This is the main fitting task. It uses +# flags to define changes since the last fit. This allows the most +# efficient use of the curfit and ranges packages. + +procedure ic_fitd (ic, cv, x, y, wts, npts, newx, newy, newwts, newfunction) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[npts] # Ordinates +double y[npts] # Data to be fit +double wts[npts] # Weights +int npts # Number of points +int newx # New x points? +int newy # New y points? +int newwts # New weights? +int newfunction # New function? + +int ier, refit + +errchk ic_dosetupd, dcvfit, dcvrefit, rg_wtbind, ic_rejectd + +begin + IC_FITERROR(ic) = NO + + iferr { + # Setup the new parameters. + + call ic_dosetupd (ic, cv, x, wts, npts, newx, newwts, newfunction, + refit) + + # If not sampling use the data array directly. + + if (npts == IC_NFIT(ic)) { + if (refit == NO) { + call dcvfit (cv, x, y, wts, npts, WTS_USER, ier) + } else if (newy == YES) + call dcvrefit (cv, x, y, wts, ier) + + # If sampling first form the sample y values. + + } else { + if ((newx == YES) || (newy == YES) || (newwts == YES)) + call rg_wtbind (IC_RG(ic), IC_NAVERAGE(ic), y, wts, npts, + Memd[IC_YFIT(ic)], Memd[IC_WTSFIT(ic)], IC_NFIT(ic)) + if (refit == NO) { + call dcvfit (cv, Memd[IC_XFIT(ic)], Memd[IC_YFIT(ic)], + Memd[IC_WTSFIT(ic)], IC_NFIT(ic), WTS_USER, ier) + } else if (newy == YES) + call dcvrefit (cv, Memd[IC_XFIT(ic)], Memd[IC_YFIT(ic)], + Memd[IC_WTSFIT(ic)], ier) + } + + # Check for an error in the fit. + + switch (ier) { + case SINGULAR: + call printf ("Singular solution\n") + call flush (STDOUT) + case NO_DEG_FREEDOM: + call printf ("No degrees of freedom\n") + call flush (STDOUT) + IC_FITERROR(ic) = YES + } + + if (IC_FITERROR(ic) == NO) { + refit = YES + + # Do pixel rejection if desired. + + if ((IC_LOW(ic) > 0.) || (IC_HIGH(ic) > 0.)) { + if (npts == IC_NFIT(ic)) + call ic_rejectd (cv, x, y, wts, Memi[IC_REJPTS(ic)], + IC_NFIT(ic), IC_LOW(ic), IC_HIGH(ic), + IC_NITERATE(ic), IC_GROW(ic), IC_NREJECT(ic)) + else + call ic_rejectd (cv, Memd[IC_XFIT(ic)], + Memd[IC_YFIT(ic)], Memd[IC_WTSFIT(ic)], + Memi[IC_REJPTS(ic)], IC_NFIT(ic), IC_LOW(ic), + IC_HIGH(ic), IC_NITERATE(ic), IC_GROW(ic), + IC_NREJECT(ic)) + + if (IC_NREJECT(ic) > 0) + refit = NO + } else + IC_NREJECT(ic) = 0 + } + } then { + IC_FITERROR(ic) = YES + call erract (EA_ERROR) + } +end diff --git a/pkg/xtools/icfit/icfitr.x b/pkg/xtools/icfit/icfitr.x new file mode 100644 index 00000000..96344ffd --- /dev/null +++ b/pkg/xtools/icfit/icfitr.x @@ -0,0 +1,99 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + + +include <error.h> +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FIT -- Fit a function. This is the main fitting task. It uses +# flags to define changes since the last fit. This allows the most +# efficient use of the curfit and ranges packages. + +procedure ic_fitr (ic, cv, x, y, wts, npts, newx, newy, newwts, newfunction) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[npts] # Ordinates +real y[npts] # Data to be fit +real wts[npts] # Weights +int npts # Number of points +int newx # New x points? +int newy # New y points? +int newwts # New weights? +int newfunction # New function? + +int ier, refit + +errchk ic_dosetupr, rcvfit, rcvrefit, rg_wtbinr, ic_rejectr + +begin + IC_FITERROR(ic) = NO + + iferr { + # Setup the new parameters. + + call ic_dosetupr (ic, cv, x, wts, npts, newx, newwts, newfunction, + refit) + + # If not sampling use the data array directly. + + if (npts == IC_NFIT(ic)) { + if (refit == NO) { + call rcvfit (cv, x, y, wts, npts, WTS_USER, ier) + } else if (newy == YES) + call rcvrefit (cv, x, y, wts, ier) + + # If sampling first form the sample y values. + + } else { + if ((newx == YES) || (newy == YES) || (newwts == YES)) + call rg_wtbinr (IC_RG(ic), IC_NAVERAGE(ic), y, wts, npts, + Memr[IC_YFIT(ic)], Memr[IC_WTSFIT(ic)], IC_NFIT(ic)) + if (refit == NO) { + call rcvfit (cv, Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)], + Memr[IC_WTSFIT(ic)], IC_NFIT(ic), WTS_USER, ier) + } else if (newy == YES) + call rcvrefit (cv, Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)], + Memr[IC_WTSFIT(ic)], ier) + } + + # Check for an error in the fit. + + switch (ier) { + case SINGULAR: + call printf ("Singular solution\n") + call flush (STDOUT) + case NO_DEG_FREEDOM: + call printf ("No degrees of freedom\n") + call flush (STDOUT) + IC_FITERROR(ic) = YES + } + + if (IC_FITERROR(ic) == NO) { + refit = YES + + # Do pixel rejection if desired. + + if ((IC_LOW(ic) > 0.) || (IC_HIGH(ic) > 0.)) { + if (npts == IC_NFIT(ic)) + call ic_rejectr (cv, x, y, wts, Memi[IC_REJPTS(ic)], + IC_NFIT(ic), IC_LOW(ic), IC_HIGH(ic), + IC_NITERATE(ic), IC_GROW(ic), IC_NREJECT(ic)) + else + call ic_rejectr (cv, Memr[IC_XFIT(ic)], + Memr[IC_YFIT(ic)], Memr[IC_WTSFIT(ic)], + Memi[IC_REJPTS(ic)], IC_NFIT(ic), IC_LOW(ic), + IC_HIGH(ic), IC_NITERATE(ic), IC_GROW(ic), + IC_NREJECT(ic)) + + if (IC_NREJECT(ic) > 0) + refit = NO + } else + IC_NREJECT(ic) = 0 + } + } then { + IC_FITERROR(ic) = YES + call erract (EA_ERROR) + } +end diff --git a/pkg/xtools/icfit/icfshow.x b/pkg/xtools/icfit/icfshow.x new file mode 100644 index 00000000..ced7bdaf --- /dev/null +++ b/pkg/xtools/icfit/icfshow.x @@ -0,0 +1,62 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" + +# IC_FSHOW -- Show the values of the parameters. + +procedure ic_fshow (ic, fd) + +pointer ic # ICFIT pointer +int fd # Output file + +pointer str, ptr +long clktime() + +begin + call malloc (str, SZ_LINE, TY_CHAR) + + call cnvtime (clktime(0), Memc[str], SZ_LINE) + call fprintf (fd, "\n# %s\n") + call pargstr (Memc[str]) + + if (IC_GT(ic) != NULL) { + # The title may contain new lines so we have to put comments + # in front of each line. + call gt_gets (IC_GT(ic), GTTITLE, Memc[str], SZ_LINE) + call putline (fd, "# ") + for (ptr=str; Memc[ptr]!=EOS; ptr=ptr+1) { + call putc (fd, Memc[ptr]) + if (Memc[ptr] == '\n') { + call putline (fd, "# ") + } + } + call putline (fd, "\n") + + call gt_gets (IC_GT(ic), GTYUNITS, Memc[str], SZ_LINE) + if (Memc[str] != EOS) { + call fprintf (fd, "# fit units = %s\n") + call pargstr (Memc[str]) + } + } + + call ic_gstr (ic, "function", Memc[str], SZ_LINE) + call fprintf (fd, "# function = %s\n") + call pargstr (Memc[str]) + call fprintf (fd, "# grow = %g\n") + call pargr (IC_GROW(ic)) + call fprintf (fd, "# naverage = %d\n") + call pargi (IC_NAVERAGE(ic)) + call fprintf (fd, "# order = %d\n") + call pargi (IC_ORDER(ic)) + call fprintf (fd, "# low_reject = %g\n") + call pargr (IC_LOW(ic)) + call fprintf (fd, "# high_reject = %g\n") + call pargr (IC_HIGH(ic)) + call fprintf (fd, "# niterate = %d\n") + call pargi (IC_NITERATE(ic)) + call fprintf (fd, "# sample = %s\n") + call pargstr (Memc[IC_SAMPLE(ic)]) + + call mfree (str, TY_CHAR) +end diff --git a/pkg/xtools/icfit/icfvshow.gx b/pkg/xtools/icfit/icfvshow.gx new file mode 100644 index 00000000..458c0664 --- /dev/null +++ b/pkg/xtools/icfit/icfvshow.gx @@ -0,0 +1,164 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FVSHOW -- Show fit parameters in verbose mode. + +procedure ic_fvshow$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 descriptor + +int i, n, deleted, ncoeffs +PIXEL chisqr, rms +pointer sp, fit, wts1, coeffs, errors + +int $tcvstati() +PIXEL ic_rms$t() + +begin + # Do the standard ic_show option, then add on the verbose part. + call ic_fshow (ic, fd) + + if (npts == 0) { + call eprintf ("# Incomplete output - no data points for fit\n") + return + } + + # 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\n# sample points = %d\n") + call pargi (npts) + call pargi (n) + call fprintf (fd, "# nrejected = %d\n# deleted = %d\n") + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call fprintf (fd, "# RMS = %10.7g\n") + call parg$t (rms) + call fprintf (fd, "# square root of reduced chi square = %10.7g\n") + call parg$t (sqrt (chisqr)) + + call fprintf (fd, "# \t coefficent\t error\n") + do i = 1, ncoeffs { + call fprintf (fd, "# \t%14.7e\t%14.7e\n") + call parg$t (Mem$t[coeffs+i-1]) + call parg$t (Mem$t[errors+i-1]) + } + + # Free allocated memory. + + call sfree (sp) +end + + +# IC_FXYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_fxyshow$t (ic, cv, x, y, w, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Pointer to curfit structure +PIXEL x[npts] # Array of x data values +PIXEL y[npts] # Array of y data values +PIXEL w[npts] # Array of weight data values +int npts # Number of data values +int fd # Output file descriptor + +int i +PIXEL $tcveval() + +begin + # List the data being fit (not necessarily the input data). + call fprintf (fd, "# X Y Y FIT WEIGHT\n") + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call parg$t (x[i]) + call parg$t (y[i]) + call parg$t ($tcveval (cv, x[i])) + call parg$t (w[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call parg$t (Mem$t[IC_XFIT(ic)+i-1]) + call parg$t (Mem$t[IC_YFIT(ic)+i-1]) + call parg$t ($tcveval (cv, Mem$t[IC_XFIT(ic)+i-1])) + call parg$t (Mem$t[IC_WTSFIT(ic)+i-1]) + } + } +end diff --git a/pkg/xtools/icfit/icfvshowd.x b/pkg/xtools/icfit/icfvshowd.x new file mode 100644 index 00000000..a26e0530 --- /dev/null +++ b/pkg/xtools/icfit/icfvshowd.x @@ -0,0 +1,164 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FVSHOW -- Show fit parameters in verbose mode. + +procedure ic_fvshowd (ic, cv, x, y, wts, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +int fd # Output descriptor + +int i, n, deleted, ncoeffs +double chisqr, rms +pointer sp, fit, wts1, coeffs, errors + +int dcvstati() +double ic_rmsd() + +begin + # Do the standard ic_show option, then add on the verbose part. + call ic_fshow (ic, fd) + + if (npts == 0) { + call eprintf ("# Incomplete output - no data points for fit\n") + return + } + + # Determine the number of coefficients and allocate memory. + + ncoeffs = dcvstati (cv, CVNCOEFF) + call smark (sp) + call salloc (coeffs, ncoeffs, TY_DOUBLE) + call salloc (errors, ncoeffs, TY_DOUBLE) + + if (npts == IC_NFIT(ic)) { + # Allocate memory for the fit. + + n = npts + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (wts, Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[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 dcvvector (cv, x, Memd[fit], n) + call dcvcoeff (cv, Memd[coeffs], ncoeffs) + call dcverrors (cv, y, Memd[wts1], Memd[fit], n, chisqr, + Memd[errors]) + rms = ic_rmsd (x, y, Memd[fit], Memd[wts1], n) + } else { + # Allocate memory for the fit. + + n = IC_NFIT(ic) + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (Memd[IC_WTSFIT(ic)], Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[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 dcvvector (cv, Memd[IC_XFIT(ic)], Memd[fit], n) + rms = ic_rmsd (Memd[IC_XFIT(ic)], Memd[IC_YFIT(ic)], + Memd[fit], Memd[wts1], n) + call dcvcoeff (cv, Memd[coeffs], ncoeffs) + call dcverrors (cv, Memd[IC_YFIT(ic)], Memd[wts1], Memd[fit], + n, chisqr, Memd[errors]) + } + + # Print the error analysis. + + call fprintf (fd, "# total points = %d\n# sample points = %d\n") + call pargi (npts) + call pargi (n) + call fprintf (fd, "# nrejected = %d\n# deleted = %d\n") + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call fprintf (fd, "# RMS = %10.7g\n") + call pargd (rms) + call fprintf (fd, "# square root of reduced chi square = %10.7g\n") + call pargd (sqrt (chisqr)) + + call fprintf (fd, "# \t coefficent\t error\n") + do i = 1, ncoeffs { + call fprintf (fd, "# \t%14.7e\t%14.7e\n") + call pargd (Memd[coeffs+i-1]) + call pargd (Memd[errors+i-1]) + } + + # Free allocated memory. + + call sfree (sp) +end + + +# IC_FXYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_fxyshowd (ic, cv, x, y, w, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Pointer to curfit structure +double x[npts] # Array of x data values +double y[npts] # Array of y data values +double w[npts] # Array of weight data values +int npts # Number of data values +int fd # Output file descriptor + +int i +double dcveval() + +begin + # List the data being fit (not necessarily the input data). + call fprintf (fd, "# X Y Y FIT WEIGHT\n") + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargd (x[i]) + call pargd (y[i]) + call pargd (dcveval (cv, x[i])) + call pargd (w[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargd (Memd[IC_XFIT(ic)+i-1]) + call pargd (Memd[IC_YFIT(ic)+i-1]) + call pargd (dcveval (cv, Memd[IC_XFIT(ic)+i-1])) + call pargd (Memd[IC_WTSFIT(ic)+i-1]) + } + } +end diff --git a/pkg/xtools/icfit/icfvshowr.x b/pkg/xtools/icfit/icfvshowr.x new file mode 100644 index 00000000..2d50020f --- /dev/null +++ b/pkg/xtools/icfit/icfvshowr.x @@ -0,0 +1,164 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "icfit.h" +include "names.h" + +# IC_FVSHOW -- Show fit parameters in verbose mode. + +procedure ic_fvshowr (ic, cv, x, y, wts, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +int fd # Output descriptor + +int i, n, deleted, ncoeffs +real chisqr, rms +pointer sp, fit, wts1, coeffs, errors + +int rcvstati() +real ic_rmsr() + +begin + # Do the standard ic_show option, then add on the verbose part. + call ic_fshow (ic, fd) + + if (npts == 0) { + call eprintf ("# Incomplete output - no data points for fit\n") + return + } + + # Determine the number of coefficients and allocate memory. + + ncoeffs = rcvstati (cv, CVNCOEFF) + call smark (sp) + call salloc (coeffs, ncoeffs, TY_REAL) + call salloc (errors, ncoeffs, TY_REAL) + + if (npts == IC_NFIT(ic)) { + # Allocate memory for the fit. + + n = npts + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (wts, Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[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 rcvvector (cv, x, Memr[fit], n) + call rcvcoeff (cv, Memr[coeffs], ncoeffs) + call rcverrors (cv, y, Memr[wts1], Memr[fit], n, chisqr, + Memr[errors]) + rms = ic_rmsr (x, y, Memr[fit], Memr[wts1], n) + } else { + # Allocate memory for the fit. + + n = IC_NFIT(ic) + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (Memr[IC_WTSFIT(ic)], Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[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 rcvvector (cv, Memr[IC_XFIT(ic)], Memr[fit], n) + rms = ic_rmsr (Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)], + Memr[fit], Memr[wts1], n) + call rcvcoeff (cv, Memr[coeffs], ncoeffs) + call rcverrors (cv, Memr[IC_YFIT(ic)], Memr[wts1], Memr[fit], + n, chisqr, Memr[errors]) + } + + # Print the error analysis. + + call fprintf (fd, "# total points = %d\n# sample points = %d\n") + call pargi (npts) + call pargi (n) + call fprintf (fd, "# nrejected = %d\n# deleted = %d\n") + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call fprintf (fd, "# RMS = %10.7g\n") + call pargr (rms) + call fprintf (fd, "# square root of reduced chi square = %10.7g\n") + call pargr (sqrt (chisqr)) + + call fprintf (fd, "# \t coefficent\t error\n") + do i = 1, ncoeffs { + call fprintf (fd, "# \t%14.7e\t%14.7e\n") + call pargr (Memr[coeffs+i-1]) + call pargr (Memr[errors+i-1]) + } + + # Free allocated memory. + + call sfree (sp) +end + + +# IC_FXYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_fxyshowr (ic, cv, x, y, w, npts, fd) + +pointer ic # ICFIT pointer +pointer cv # Pointer to curfit structure +real x[npts] # Array of x data values +real y[npts] # Array of y data values +real w[npts] # Array of weight data values +int npts # Number of data values +int fd # Output file descriptor + +int i +real rcveval() + +begin + # List the data being fit (not necessarily the input data). + call fprintf (fd, "# X Y Y FIT WEIGHT\n") + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargr (x[i]) + call pargr (y[i]) + call pargr (rcveval (cv, x[i])) + call pargr (w[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargr (Memr[IC_XFIT(ic)+i-1]) + call pargr (Memr[IC_YFIT(ic)+i-1]) + call pargr (rcveval (cv, Memr[IC_XFIT(ic)+i-1])) + call pargr (Memr[IC_WTSFIT(ic)+i-1]) + } + } +end diff --git a/pkg/xtools/icfit/icgadd.gx b/pkg/xtools/icfit/icgadd.gx new file mode 100644 index 00000000..aa0b45d5 --- /dev/null +++ b/pkg/xtools/icfit/icgadd.gx @@ -0,0 +1,50 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> + +define MSIZE 2. # Mark size + +# ICG_ADD -- Add a point. + +procedure icg_add$t (gp, wx, wy, wt, x, y, w1, w2, npts) + +pointer gp # GIO pointer +real wx # X point to insert +real wy # Y point to insert +real wt # Weight of point to add +PIXEL x[npts] # Independent variable +PIXEL y[npts] # Dependent variable +PIXEL w1[npts] # Current weights +PIXEL w2[npts] # Initial weights +int npts # Number of points + +int i, j + +begin + # Find the place to insert the new point. + if (x[1] < x[npts]) + for (i = npts; (i > 0) && (wx < x[i]); i = i - 1) + ; + else + for (i = npts; (i > 0) && (wx > x[i]); i = i - 1) + ; + + # Shift the data to insert the new point. + for (j = npts; j > i; j = j - 1) { + x[j+1] = x[j] + y[j+1] = y[j] + w1[j+1] = w1[j] + w2[j+1] = w2[j] + } + + # Add the new point and increment the number of points. + i = i + 1 + x[i] = wx + y[i] = wy + w1[i] = wt + w2[i] = wt + npts = npts + 1 + + # Mark the point + call gmark (gp, real (x[i]), real (y[i]), GM_PLUS, MSIZE, MSIZE) +end diff --git a/pkg/xtools/icfit/icgaddd.x b/pkg/xtools/icfit/icgaddd.x new file mode 100644 index 00000000..b32c6b5a --- /dev/null +++ b/pkg/xtools/icfit/icgaddd.x @@ -0,0 +1,50 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> + +define MSIZE 2. # Mark size + +# ICG_ADD -- Add a point. + +procedure icg_addd (gp, wx, wy, wt, x, y, w1, w2, npts) + +pointer gp # GIO pointer +real wx # X point to insert +real wy # Y point to insert +real wt # Weight of point to add +double x[npts] # Independent variable +double y[npts] # Dependent variable +double w1[npts] # Current weights +double w2[npts] # Initial weights +int npts # Number of points + +int i, j + +begin + # Find the place to insert the new point. + if (x[1] < x[npts]) + for (i = npts; (i > 0) && (wx < x[i]); i = i - 1) + ; + else + for (i = npts; (i > 0) && (wx > x[i]); i = i - 1) + ; + + # Shift the data to insert the new point. + for (j = npts; j > i; j = j - 1) { + x[j+1] = x[j] + y[j+1] = y[j] + w1[j+1] = w1[j] + w2[j+1] = w2[j] + } + + # Add the new point and increment the number of points. + i = i + 1 + x[i] = wx + y[i] = wy + w1[i] = wt + w2[i] = wt + npts = npts + 1 + + # Mark the point + call gmark (gp, real (x[i]), real (y[i]), GM_PLUS, MSIZE, MSIZE) +end diff --git a/pkg/xtools/icfit/icgaddr.x b/pkg/xtools/icfit/icgaddr.x new file mode 100644 index 00000000..4e09be1b --- /dev/null +++ b/pkg/xtools/icfit/icgaddr.x @@ -0,0 +1,50 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> + +define MSIZE 2. # Mark size + +# ICG_ADD -- Add a point. + +procedure icg_addr (gp, wx, wy, wt, x, y, w1, w2, npts) + +pointer gp # GIO pointer +real wx # X point to insert +real wy # Y point to insert +real wt # Weight of point to add +real x[npts] # Independent variable +real y[npts] # Dependent variable +real w1[npts] # Current weights +real w2[npts] # Initial weights +int npts # Number of points + +int i, j + +begin + # Find the place to insert the new point. + if (x[1] < x[npts]) + for (i = npts; (i > 0) && (wx < x[i]); i = i - 1) + ; + else + for (i = npts; (i > 0) && (wx > x[i]); i = i - 1) + ; + + # Shift the data to insert the new point. + for (j = npts; j > i; j = j - 1) { + x[j+1] = x[j] + y[j+1] = y[j] + w1[j+1] = w1[j] + w2[j+1] = w2[j] + } + + # Add the new point and increment the number of points. + i = i + 1 + x[i] = wx + y[i] = wy + w1[i] = wt + w2[i] = wt + npts = npts + 1 + + # Mark the point + call gmark (gp, real (x[i]), real (y[i]), GM_PLUS, MSIZE, MSIZE) +end diff --git a/pkg/xtools/icfit/icgaxes.gx b/pkg/xtools/icfit/icgaxes.gx new file mode 100644 index 00000000..0e3f6a55 --- /dev/null +++ b/pkg/xtools/icfit/icgaxes.gx @@ -0,0 +1,103 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_AXES -- Set axes data. +# The applications program may set additional axes types. + +procedure icg_axes$t (ic, gt, cv, axis, x, y, z, npts) + +pointer ic # ICFIT pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +int axis # Output axis +PIXEL x[npts] # Independent variable +PIXEL y[npts] # Dependent variable +PIXEL z[npts] # Output values +int npts # Number of points + +int i, axistype, gtlabel[2], gtunits[2] +PIXEL a, b, xmin, xmax +pointer label, units + +PIXEL $tcveval(), icg_dvz$t() +errchk adiv$t() +extern icg_dvz$t() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +begin + axistype = IC_AXES(ic, IC_GKEY(ic), axis) + switch (axistype) { + case 'x': # Independent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,1)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,1)]) + call amov$t (x, z, npts) + case 'y': # Dependent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,2)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call amov$t (y, z, npts) + case 'f': # Fitted values + call gt_sets (gt, gtlabel[axis], "fit") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call $tcvvector (cv, x, z, npts) + case 'r': # Residuals + call gt_sets (gt, gtlabel[axis], "residuals") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call $tcvvector (cv, x, z, npts) + call asub$t (y, z, z, npts) + case 'd': # Ratio + call gt_sets (gt, gtlabel[axis], "ratio") + call gt_sets (gt, gtunits[axis], "") + call $tcvvector (cv, x, z, npts) +# iferr (call adiv$t (y, z, z, npts)) + call advz$t (y, z, z, npts, icg_dvz$t) + case 'n': # Linear component removed + call gt_sets (gt, gtlabel[axis], "non-linear component") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + xmin = IC_XMIN(ic) + xmax = IC_XMAX(ic) + a = $tcveval (cv, PIXEL (xmin)) + b = ($tcveval (cv, PIXEL (xmax)) - a) / (xmax - xmin) + do i = 1, npts + z[i] = y[i] - a - b * (x[i] - xmin) + case 'v': + call gt_sets (gt, gtlabel[axis], "Velocity") + call gt_sets (gt, gtunits[axis], "km/s") + call $tcvvector (cv, x, z, npts) + do i = 1, npts + z[i] = (z[i] - y[i]) / y[i] * 300000. + default: # User axes types. + call malloc (label, SZ_LINE, TY_CHAR) + call malloc (units, SZ_LINE, TY_CHAR) + if (axis == 1) { + call strcpy (Memc[IC_LABELS(ic,1)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,1)], Memc[units], SZ_LINE) + call amov$t (x, z, npts) + } else { + call strcpy (Memc[IC_LABELS(ic,2)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,2)], Memc[units], SZ_LINE) + call amov$t (y, z, npts) + } + call icg_uaxes$t (axistype, cv, x, y, z, npts, Memc[label], + Memc[units], SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + call mfree (label, TY_CHAR) + call mfree (units, TY_CHAR) + } +end + + +# ICG_DVZ -- Error action to take on zero division. + +PIXEL procedure icg_dvz$t (x) + +PIXEL x # Numerator + +begin + return (1.) +end diff --git a/pkg/xtools/icfit/icgaxesd.x b/pkg/xtools/icfit/icgaxesd.x new file mode 100644 index 00000000..9505c4c8 --- /dev/null +++ b/pkg/xtools/icfit/icgaxesd.x @@ -0,0 +1,103 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_AXES -- Set axes data. +# The applications program may set additional axes types. + +procedure icg_axesd (ic, gt, cv, axis, x, y, z, npts) + +pointer ic # ICFIT pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +int axis # Output axis +double x[npts] # Independent variable +double y[npts] # Dependent variable +double z[npts] # Output values +int npts # Number of points + +int i, axistype, gtlabel[2], gtunits[2] +double a, b, xmin, xmax +pointer label, units + +double dcveval(), icg_dvzd() +errchk adivd() +extern icg_dvzd() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +begin + axistype = IC_AXES(ic, IC_GKEY(ic), axis) + switch (axistype) { + case 'x': # Independent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,1)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,1)]) + call amovd (x, z, npts) + case 'y': # Dependent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,2)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call amovd (y, z, npts) + case 'f': # Fitted values + call gt_sets (gt, gtlabel[axis], "fit") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call dcvvector (cv, x, z, npts) + case 'r': # Residuals + call gt_sets (gt, gtlabel[axis], "residuals") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call dcvvector (cv, x, z, npts) + call asubd (y, z, z, npts) + case 'd': # Ratio + call gt_sets (gt, gtlabel[axis], "ratio") + call gt_sets (gt, gtunits[axis], "") + call dcvvector (cv, x, z, npts) +# iferr (call adiv$t (y, z, z, npts)) + call advzd (y, z, z, npts, icg_dvzd) + case 'n': # Linear component removed + call gt_sets (gt, gtlabel[axis], "non-linear component") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + xmin = IC_XMIN(ic) + xmax = IC_XMAX(ic) + a = dcveval (cv, double (xmin)) + b = (dcveval (cv, double (xmax)) - a) / (xmax - xmin) + do i = 1, npts + z[i] = y[i] - a - b * (x[i] - xmin) + case 'v': + call gt_sets (gt, gtlabel[axis], "Velocity") + call gt_sets (gt, gtunits[axis], "km/s") + call dcvvector (cv, x, z, npts) + do i = 1, npts + z[i] = (z[i] - y[i]) / y[i] * 300000. + default: # User axes types. + call malloc (label, SZ_LINE, TY_CHAR) + call malloc (units, SZ_LINE, TY_CHAR) + if (axis == 1) { + call strcpy (Memc[IC_LABELS(ic,1)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,1)], Memc[units], SZ_LINE) + call amovd (x, z, npts) + } else { + call strcpy (Memc[IC_LABELS(ic,2)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,2)], Memc[units], SZ_LINE) + call amovd (y, z, npts) + } + call icg_uaxesd (axistype, cv, x, y, z, npts, Memc[label], + Memc[units], SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + call mfree (label, TY_CHAR) + call mfree (units, TY_CHAR) + } +end + + +# ICG_DVZ -- Error action to take on zero division. + +double procedure icg_dvzd (x) + +double x # Numerator + +begin + return (1.) +end diff --git a/pkg/xtools/icfit/icgaxesr.x b/pkg/xtools/icfit/icgaxesr.x new file mode 100644 index 00000000..dcd4d686 --- /dev/null +++ b/pkg/xtools/icfit/icgaxesr.x @@ -0,0 +1,103 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_AXES -- Set axes data. +# The applications program may set additional axes types. + +procedure icg_axesr (ic, gt, cv, axis, x, y, z, npts) + +pointer ic # ICFIT pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +int axis # Output axis +real x[npts] # Independent variable +real y[npts] # Dependent variable +real z[npts] # Output values +int npts # Number of points + +int i, axistype, gtlabel[2], gtunits[2] +real a, b, xmin, xmax +pointer label, units + +real rcveval(), icg_dvzr() +errchk adivr() +extern icg_dvzr() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +begin + axistype = IC_AXES(ic, IC_GKEY(ic), axis) + switch (axistype) { + case 'x': # Independent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,1)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,1)]) + call amovr (x, z, npts) + case 'y': # Dependent variable + call gt_sets (gt, gtlabel[axis], Memc[IC_LABELS(ic,2)]) + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call amovr (y, z, npts) + case 'f': # Fitted values + call gt_sets (gt, gtlabel[axis], "fit") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call rcvvector (cv, x, z, npts) + case 'r': # Residuals + call gt_sets (gt, gtlabel[axis], "residuals") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + call rcvvector (cv, x, z, npts) + call asubr (y, z, z, npts) + case 'd': # Ratio + call gt_sets (gt, gtlabel[axis], "ratio") + call gt_sets (gt, gtunits[axis], "") + call rcvvector (cv, x, z, npts) +# iferr (call adiv$t (y, z, z, npts)) + call advzr (y, z, z, npts, icg_dvzr) + case 'n': # Linear component removed + call gt_sets (gt, gtlabel[axis], "non-linear component") + call gt_sets (gt, gtunits[axis], Memc[IC_UNITS(ic,2)]) + xmin = IC_XMIN(ic) + xmax = IC_XMAX(ic) + a = rcveval (cv, real (xmin)) + b = (rcveval (cv, real (xmax)) - a) / (xmax - xmin) + do i = 1, npts + z[i] = y[i] - a - b * (x[i] - xmin) + case 'v': + call gt_sets (gt, gtlabel[axis], "Velocity") + call gt_sets (gt, gtunits[axis], "km/s") + call rcvvector (cv, x, z, npts) + do i = 1, npts + z[i] = (z[i] - y[i]) / y[i] * 300000. + default: # User axes types. + call malloc (label, SZ_LINE, TY_CHAR) + call malloc (units, SZ_LINE, TY_CHAR) + if (axis == 1) { + call strcpy (Memc[IC_LABELS(ic,1)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,1)], Memc[units], SZ_LINE) + call amovr (x, z, npts) + } else { + call strcpy (Memc[IC_LABELS(ic,2)], Memc[label], SZ_LINE) + call strcpy (Memc[IC_UNITS(ic,2)], Memc[units], SZ_LINE) + call amovr (y, z, npts) + } + call icg_uaxesr (axistype, cv, x, y, z, npts, Memc[label], + Memc[units], SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + call mfree (label, TY_CHAR) + call mfree (units, TY_CHAR) + } +end + + +# ICG_DVZ -- Error action to take on zero division. + +real procedure icg_dvzr (x) + +real x # Numerator + +begin + return (1.) +end diff --git a/pkg/xtools/icfit/icgcolon.gx b/pkg/xtools/icfit/icgcolon.gx new file mode 100644 index 00000000..14329164 --- /dev/null +++ b/pkg/xtools/icfit/icgcolon.gx @@ -0,0 +1,218 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# List of colon commands. +define CMDS "|function|order|sample|naverage|niterate|low_reject|high_reject\ + |grow|markrej|color|show|vshow|xyshow|errors|evaluate\ + |graph|help|gui|" + +define FUNCTION 1 # Set or show function type +define ORDER 2 # Set or show function order +define SAMPLE 3 # Set or show sample ranges +define NAVERAGE 4 # Set or show sample averaging or medianing +define NITERATE 5 # Set or show rejection iterations +define LOW_REJECT 6 # Set or show lower rejection factor +define HIGH_REJECT 7 # Set or show upper rejection factor +define GROW 8 # Set or show rejection growing radius +define MARKREJ 9 # Mark rejected points +define COLOR 10 # Fit color +define SHOW 11 # Show values of parameters +define VSHOW 12 # Show verbose information +define XYSHOW 13 # Show x-y-fit-wts values +define ERRORS 14 # Show errors of fit +define EVALUATE 15 # Evaluate fit at specified value +define GRAPH 16 # Define graph +define HELP 17 # Set help file +define GUI 18 # Send GUI command + +# ICG_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure icg_colon$t (ic, cmdstr, newgraph, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char cmdstr[ARB] # Command string +int newgraph # New graph? +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer for error listing +PIXEL x[npts], y[npts], wts[npts] # Data arrays for error listing +int npts # Number of data points + +PIXEL val, $tcveval() +char key, xtype, ytype +bool bval +int ncmd, ival +real rval +pointer sp, cmd + +int nscan(), strdic(), btoi() + +string funcs "|chebyshev|legendre|spline1|spline3|power|" + +begin + # Check for GTOOLS command. + if (cmdstr[1] == '/') { + call gt_colon (cmdstr, gp, gt, newgraph) + return + } + + # Use formated scan to parse the command string. + # The first word is the command and it may be minimum match + # abbreviated with the list of commands. + + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], IC_SZSAMPLE) + ncmd = strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, CMDS) + + switch (ncmd) { + case FUNCTION: # :function - List or set the fitting function. + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (nscan() == 1) { + call printf ("function = %s\n") + call ic_gstr (ic, "function", Memc[cmd], IC_SZSAMPLE) + call pargstr (Memc[cmd]) + } else { + if (strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, funcs) > 0) { + call ic_pstr (ic, "function", Memc[cmd]) + IC_NEWFUNCTION(ic) = YES + } else + call printf ("Unknown or ambiguous function\n") + } + + case ORDER: # :order - List or set the function order. + call gargi (ival) + if (nscan() == 1) { + call printf ("order = %d\n") + call pargi (IC_ORDER(ic)) + } else if (ival < 1) { + call printf ("Order must be greater than zero\n") + } else { + call ic_puti (ic, "order", ival) + IC_NEWFUNCTION(ic) = YES + } + + case SAMPLE: # :sample - List or set the sample points. + call gargstr (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("sample = %s\n") + call pargstr (Memc[IC_SAMPLE(ic)]) + } else { + call ic_pstr (ic, "sample", Memc[cmd]) + IC_NEWX(ic) = YES + } + + case NAVERAGE: # :naverage - List or set the sample averging. + call gargi (ival) + if (nscan() == 1) { + call printf ("naverage = %d\n") + call pargi (IC_NAVERAGE(ic)) + } else { + call ic_puti (ic, "naverage", ival) + IC_NEWX(ic) = YES + } + + case NITERATE: # :niterate - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("niterate = %d\n") + call pargi (IC_NITERATE(ic)) + } else + call ic_puti (ic, "niterate", ival) + + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call pargr (IC_LOW(ic)) + } else + call ic_putr (ic, "low", rval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call pargr (IC_HIGH(ic)) + } else + call ic_putr (ic, "high", rval) + + case GROW: # :grow - List or set the rejection growing. + call gargr (rval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call pargr (IC_GROW(ic)) + } else + call ic_putr (ic, "grow", rval) + + case MARKREJ: # :markrej - Mark rejected points + call gargb (bval) + if (nscan() == 1) { + call printf ("markrej = %b\n") + call pargi (IC_MARKREJ(ic)) + } else + call ic_puti (ic, "markrej", btoi (bval)) + + case COLOR: # :color - List or set the fit color. + call gargi (ival) + if (nscan() == 1) { + call printf ("color = %d\n") + call pargi (IC_COLOR(ic)) + } else + call ic_puti (ic, "color", ival) + + case SHOW, VSHOW, XYSHOW, ERRORS: + call ic_guishow$t (ic, cmdstr, cv, x, y, wts, npts) + + case EVALUATE: # :evaluate x - evaluate fit at x. + call garg$t (val) + if (nscan() == 1) + call printf ("evaluate requires a value to evaluate\n") + else { + call printf ("fit(%g) = %g\n") + call parg$t (val) + call parg$t ($tcveval (cv, val)) + } + + case GRAPH: # :graph key xtype ytpe + call gargc (key) + call gargc (xtype) + call gargc (ytype) + if (nscan() != 4) { + ival = IC_GKEY(ic) + call printf ("graph %c %c %c\n") + call pargi ('h'+ival-1) + call pargi (IC_AXES(ic,ival,1)) + call pargi (IC_AXES(ic,ival,2)) + } else { + ival = key - 'h' + 1 + IC_GKEY(ic) = ival + call ic_pkey (ic, ival, int(xtype), int(ytype)) + newgraph = YES + } + + case HELP: # :help file + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("help = %s\n") + call pargstr (Memc[IC_HELP(ic)]) + } else + call ic_pstr (ic, "help", Memc[cmd]) + + case GUI: # :gui command - Update, unlearn or set the options. + call gargstr (Memc[cmd], IC_SZSAMPLE) + call ic_gui (ic, Memc[cmd]) + + default: # Unrecognized command. + call printf ("Unrecognized command or ambiguous abbreviation\007") + } + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgcolond.x b/pkg/xtools/icfit/icgcolond.x new file mode 100644 index 00000000..00c92a0d --- /dev/null +++ b/pkg/xtools/icfit/icgcolond.x @@ -0,0 +1,218 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# List of colon commands. +define CMDS "|function|order|sample|naverage|niterate|low_reject|high_reject\ + |grow|markrej|color|show|vshow|xyshow|errors|evaluate\ + |graph|help|gui|" + +define FUNCTION 1 # Set or show function type +define ORDER 2 # Set or show function order +define SAMPLE 3 # Set or show sample ranges +define NAVERAGE 4 # Set or show sample averaging or medianing +define NITERATE 5 # Set or show rejection iterations +define LOW_REJECT 6 # Set or show lower rejection factor +define HIGH_REJECT 7 # Set or show upper rejection factor +define GROW 8 # Set or show rejection growing radius +define MARKREJ 9 # Mark rejected points +define COLOR 10 # Fit color +define SHOW 11 # Show values of parameters +define VSHOW 12 # Show verbose information +define XYSHOW 13 # Show x-y-fit-wts values +define ERRORS 14 # Show errors of fit +define EVALUATE 15 # Evaluate fit at specified value +define GRAPH 16 # Define graph +define HELP 17 # Set help file +define GUI 18 # Send GUI command + +# ICG_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure icg_colond (ic, cmdstr, newgraph, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char cmdstr[ARB] # Command string +int newgraph # New graph? +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer for error listing +double x[npts], y[npts], wts[npts] # Data arrays for error listing +int npts # Number of data points + +double val, dcveval() +char key, xtype, ytype +bool bval +int ncmd, ival +real rval +pointer sp, cmd + +int nscan(), strdic(), btoi() + +string funcs "|chebyshev|legendre|spline1|spline3|power|" + +begin + # Check for GTOOLS command. + if (cmdstr[1] == '/') { + call gt_colon (cmdstr, gp, gt, newgraph) + return + } + + # Use formated scan to parse the command string. + # The first word is the command and it may be minimum match + # abbreviated with the list of commands. + + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], IC_SZSAMPLE) + ncmd = strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, CMDS) + + switch (ncmd) { + case FUNCTION: # :function - List or set the fitting function. + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (nscan() == 1) { + call printf ("function = %s\n") + call ic_gstr (ic, "function", Memc[cmd], IC_SZSAMPLE) + call pargstr (Memc[cmd]) + } else { + if (strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, funcs) > 0) { + call ic_pstr (ic, "function", Memc[cmd]) + IC_NEWFUNCTION(ic) = YES + } else + call printf ("Unknown or ambiguous function\n") + } + + case ORDER: # :order - List or set the function order. + call gargi (ival) + if (nscan() == 1) { + call printf ("order = %d\n") + call pargi (IC_ORDER(ic)) + } else if (ival < 1) { + call printf ("Order must be greater than zero\n") + } else { + call ic_puti (ic, "order", ival) + IC_NEWFUNCTION(ic) = YES + } + + case SAMPLE: # :sample - List or set the sample points. + call gargstr (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("sample = %s\n") + call pargstr (Memc[IC_SAMPLE(ic)]) + } else { + call ic_pstr (ic, "sample", Memc[cmd]) + IC_NEWX(ic) = YES + } + + case NAVERAGE: # :naverage - List or set the sample averging. + call gargi (ival) + if (nscan() == 1) { + call printf ("naverage = %d\n") + call pargi (IC_NAVERAGE(ic)) + } else { + call ic_puti (ic, "naverage", ival) + IC_NEWX(ic) = YES + } + + case NITERATE: # :niterate - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("niterate = %d\n") + call pargi (IC_NITERATE(ic)) + } else + call ic_puti (ic, "niterate", ival) + + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call pargr (IC_LOW(ic)) + } else + call ic_putr (ic, "low", rval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call pargr (IC_HIGH(ic)) + } else + call ic_putr (ic, "high", rval) + + case GROW: # :grow - List or set the rejection growing. + call gargr (rval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call pargr (IC_GROW(ic)) + } else + call ic_putr (ic, "grow", rval) + + case MARKREJ: # :markrej - Mark rejected points + call gargb (bval) + if (nscan() == 1) { + call printf ("markrej = %b\n") + call pargi (IC_MARKREJ(ic)) + } else + call ic_puti (ic, "markrej", btoi (bval)) + + case COLOR: # :color - List or set the fit color. + call gargi (ival) + if (nscan() == 1) { + call printf ("color = %d\n") + call pargi (IC_COLOR(ic)) + } else + call ic_puti (ic, "color", ival) + + case SHOW, VSHOW, XYSHOW, ERRORS: + call ic_guishowd (ic, cmdstr, cv, x, y, wts, npts) + + case EVALUATE: # :evaluate x - evaluate fit at x. + call gargd (val) + if (nscan() == 1) + call printf ("evaluate requires a value to evaluate\n") + else { + call printf ("fit(%g) = %g\n") + call pargd (val) + call pargd (dcveval (cv, val)) + } + + case GRAPH: # :graph key xtype ytpe + call gargc (key) + call gargc (xtype) + call gargc (ytype) + if (nscan() != 4) { + ival = IC_GKEY(ic) + call printf ("graph %c %c %c\n") + call pargi ('h'+ival-1) + call pargi (IC_AXES(ic,ival,1)) + call pargi (IC_AXES(ic,ival,2)) + } else { + ival = key - 'h' + 1 + IC_GKEY(ic) = ival + call ic_pkey (ic, ival, int(xtype), int(ytype)) + newgraph = YES + } + + case HELP: # :help file + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("help = %s\n") + call pargstr (Memc[IC_HELP(ic)]) + } else + call ic_pstr (ic, "help", Memc[cmd]) + + case GUI: # :gui command - Update, unlearn or set the options. + call gargstr (Memc[cmd], IC_SZSAMPLE) + call ic_gui (ic, Memc[cmd]) + + default: # Unrecognized command. + call printf ("Unrecognized command or ambiguous abbreviation\007") + } + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgcolonr.x b/pkg/xtools/icfit/icgcolonr.x new file mode 100644 index 00000000..dc320c2b --- /dev/null +++ b/pkg/xtools/icfit/icgcolonr.x @@ -0,0 +1,218 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# List of colon commands. +define CMDS "|function|order|sample|naverage|niterate|low_reject|high_reject\ + |grow|markrej|color|show|vshow|xyshow|errors|evaluate\ + |graph|help|gui|" + +define FUNCTION 1 # Set or show function type +define ORDER 2 # Set or show function order +define SAMPLE 3 # Set or show sample ranges +define NAVERAGE 4 # Set or show sample averaging or medianing +define NITERATE 5 # Set or show rejection iterations +define LOW_REJECT 6 # Set or show lower rejection factor +define HIGH_REJECT 7 # Set or show upper rejection factor +define GROW 8 # Set or show rejection growing radius +define MARKREJ 9 # Mark rejected points +define COLOR 10 # Fit color +define SHOW 11 # Show values of parameters +define VSHOW 12 # Show verbose information +define XYSHOW 13 # Show x-y-fit-wts values +define ERRORS 14 # Show errors of fit +define EVALUATE 15 # Evaluate fit at specified value +define GRAPH 16 # Define graph +define HELP 17 # Set help file +define GUI 18 # Send GUI command + +# ICG_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure icg_colonr (ic, cmdstr, newgraph, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +char cmdstr[ARB] # Command string +int newgraph # New graph? +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer for error listing +real x[npts], y[npts], wts[npts] # Data arrays for error listing +int npts # Number of data points + +real val, rcveval() +char key, xtype, ytype +bool bval +int ncmd, ival +real rval +pointer sp, cmd + +int nscan(), strdic(), btoi() + +string funcs "|chebyshev|legendre|spline1|spline3|power|" + +begin + # Check for GTOOLS command. + if (cmdstr[1] == '/') { + call gt_colon (cmdstr, gp, gt, newgraph) + return + } + + # Use formated scan to parse the command string. + # The first word is the command and it may be minimum match + # abbreviated with the list of commands. + + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], IC_SZSAMPLE) + ncmd = strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, CMDS) + + switch (ncmd) { + case FUNCTION: # :function - List or set the fitting function. + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (nscan() == 1) { + call printf ("function = %s\n") + call ic_gstr (ic, "function", Memc[cmd], IC_SZSAMPLE) + call pargstr (Memc[cmd]) + } else { + if (strdic (Memc[cmd], Memc[cmd], IC_SZSAMPLE, funcs) > 0) { + call ic_pstr (ic, "function", Memc[cmd]) + IC_NEWFUNCTION(ic) = YES + } else + call printf ("Unknown or ambiguous function\n") + } + + case ORDER: # :order - List or set the function order. + call gargi (ival) + if (nscan() == 1) { + call printf ("order = %d\n") + call pargi (IC_ORDER(ic)) + } else if (ival < 1) { + call printf ("Order must be greater than zero\n") + } else { + call ic_puti (ic, "order", ival) + IC_NEWFUNCTION(ic) = YES + } + + case SAMPLE: # :sample - List or set the sample points. + call gargstr (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("sample = %s\n") + call pargstr (Memc[IC_SAMPLE(ic)]) + } else { + call ic_pstr (ic, "sample", Memc[cmd]) + IC_NEWX(ic) = YES + } + + case NAVERAGE: # :naverage - List or set the sample averging. + call gargi (ival) + if (nscan() == 1) { + call printf ("naverage = %d\n") + call pargi (IC_NAVERAGE(ic)) + } else { + call ic_puti (ic, "naverage", ival) + IC_NEWX(ic) = YES + } + + case NITERATE: # :niterate - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("niterate = %d\n") + call pargi (IC_NITERATE(ic)) + } else + call ic_puti (ic, "niterate", ival) + + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call pargr (IC_LOW(ic)) + } else + call ic_putr (ic, "low", rval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call gargr (rval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call pargr (IC_HIGH(ic)) + } else + call ic_putr (ic, "high", rval) + + case GROW: # :grow - List or set the rejection growing. + call gargr (rval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call pargr (IC_GROW(ic)) + } else + call ic_putr (ic, "grow", rval) + + case MARKREJ: # :markrej - Mark rejected points + call gargb (bval) + if (nscan() == 1) { + call printf ("markrej = %b\n") + call pargi (IC_MARKREJ(ic)) + } else + call ic_puti (ic, "markrej", btoi (bval)) + + case COLOR: # :color - List or set the fit color. + call gargi (ival) + if (nscan() == 1) { + call printf ("color = %d\n") + call pargi (IC_COLOR(ic)) + } else + call ic_puti (ic, "color", ival) + + case SHOW, VSHOW, XYSHOW, ERRORS: + call ic_guishowr (ic, cmdstr, cv, x, y, wts, npts) + + case EVALUATE: # :evaluate x - evaluate fit at x. + call gargr (val) + if (nscan() == 1) + call printf ("evaluate requires a value to evaluate\n") + else { + call printf ("fit(%g) = %g\n") + call pargr (val) + call pargr (rcveval (cv, val)) + } + + case GRAPH: # :graph key xtype ytpe + call gargc (key) + call gargc (xtype) + call gargc (ytype) + if (nscan() != 4) { + ival = IC_GKEY(ic) + call printf ("graph %c %c %c\n") + call pargi ('h'+ival-1) + call pargi (IC_AXES(ic,ival,1)) + call pargi (IC_AXES(ic,ival,2)) + } else { + ival = key - 'h' + 1 + IC_GKEY(ic) = ival + call ic_pkey (ic, ival, int(xtype), int(ytype)) + newgraph = YES + } + + case HELP: # :help file + call gargwrd (Memc[cmd], IC_SZSAMPLE) + if (Memc[cmd] == EOS) { + call printf ("help = %s\n") + call pargstr (Memc[IC_HELP(ic)]) + } else + call ic_pstr (ic, "help", Memc[cmd]) + + case GUI: # :gui command - Update, unlearn or set the options. + call gargstr (Memc[cmd], IC_SZSAMPLE) + call ic_gui (ic, Memc[cmd]) + + default: # Unrecognized command. + call printf ("Unrecognized command or ambiguous abbreviation\007") + } + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgdelete.gx b/pkg/xtools/icfit/icgdelete.gx new file mode 100644 index 00000000..1c2a6fd6 --- /dev/null +++ b/pkg/xtools/icfit/icgdelete.gx @@ -0,0 +1,89 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_delete$t (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +PIXEL x[npts], y[npts] # Data points +PIXEL wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + call icg_axes$t (ic, gt, cv, 1, x, y, Mem$t[xout], npts) + call icg_axes$t (ic, gt, cv, 2, x, y, Mem$t[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_d1$t (ic, gp, Mem$t[xout], Mem$t[yout], wts, userwts, + npts, wx, wy) + else + call icg_d1$t (ic, gp, Mem$t[yout], Mem$t[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_D1 -- Do the actual delete. + +procedure icg_d1$t (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +PIXEL x[npts], y[npts] # Data points +PIXEL wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with non-zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] == 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Mark the deleted point with a cross and set the weight to zero. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + wts[j] = 0. + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icgdeleted.x b/pkg/xtools/icfit/icgdeleted.x new file mode 100644 index 00000000..60027998 --- /dev/null +++ b/pkg/xtools/icfit/icgdeleted.x @@ -0,0 +1,89 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_deleted (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +double x[npts], y[npts] # Data points +double wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + call icg_axesd (ic, gt, cv, 1, x, y, Memd[xout], npts) + call icg_axesd (ic, gt, cv, 2, x, y, Memd[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_d1d (ic, gp, Memd[xout], Memd[yout], wts, userwts, + npts, wx, wy) + else + call icg_d1d (ic, gp, Memd[yout], Memd[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_D1 -- Do the actual delete. + +procedure icg_d1d (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +double x[npts], y[npts] # Data points +double wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with non-zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] == 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Mark the deleted point with a cross and set the weight to zero. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + wts[j] = 0. + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icgdeleter.x b/pkg/xtools/icfit/icgdeleter.x new file mode 100644 index 00000000..86edd93b --- /dev/null +++ b/pkg/xtools/icfit/icgdeleter.x @@ -0,0 +1,89 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_deleter (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +real x[npts], y[npts] # Data points +real wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + call icg_axesr (ic, gt, cv, 1, x, y, Memr[xout], npts) + call icg_axesr (ic, gt, cv, 2, x, y, Memr[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_d1r (ic, gp, Memr[xout], Memr[yout], wts, userwts, + npts, wx, wy) + else + call icg_d1r (ic, gp, Memr[yout], Memr[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_D1 -- Do the actual delete. + +procedure icg_d1r (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +real x[npts], y[npts] # Data points +real wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with non-zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] == 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Mark the deleted point with a cross and set the weight to zero. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + wts[j] = 0. + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icgfit.gx b/pkg/xtools/icfit/icgfit.gx new file mode 100644 index 00000000..767daa3e --- /dev/null +++ b/pkg/xtools/icfit/icgfit.gx @@ -0,0 +1,544 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +# ICG_FIT -- Interactive curve fitting with graphics. This is the main +# entry point for the interactive graphics part of the icfit package. + +procedure icg_fit$t (ic, gp, cursor, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +PIXEL x[npts] # Ordinates +PIXEL y[npts] # Abscissas +PIXEL wts[npts] # Weights +int npts # Number of points + +real wx, wy +int wcs, key + +int i, j, newgraph, axes[2], xtype +PIXEL px1 +real rx1, rx2, ry1, ry2 +pointer sp, cmd, userwts, x1, y1, w1, n + +int gt_gcur1(), stridxs(), scan(), nscan() +int icg_nearest$t() +PIXEL $tcveval() +errchk ic_fit$t() + +begin + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + # Allocate memory for the fit and a copy of the weights. + # The weights are copied because they are changed when points are + # deleted. + + n = npts + x1 = NULL + y1 = NULL + w1 = NULL + call malloc (userwts, n, TY_PIXEL) + call amov$t (wts, Mem$t[userwts], n) + + # Initialize + IC_GP(ic) = gp + IC_GT(ic) = gt + IC_OVERPLOT(ic) = NO + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + IC_NEWFUNCTION(ic) = YES + + # Send the GUI the current task values. + call ic_gui (ic, "open") + call ic_gui (ic, "graph") + + # Read cursor commands. + + key = 'f' + newgraph = YES + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + xtype = 0 + + repeat { + switch (key) { + case '?': # Print help text. + call ic_gui (ic, "help") + + case ':': # List or set parameters + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call icg_colon$t (ic, Memc[cmd], newgraph, gp, gt, cv, + x, y, wts, n) + + case 'a': # Add points + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'y')) + ; + else if ((IC_AXES(ic,IC_GKEY(ic),1) == 'y') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + rx1 = wx + wx = wy + wy = rx1 + } else { + call printf ("Graph must be x vs. y or y vs. x\07\n") + next + } + + rx1 = 1. + call printf ("weight = (%g) ") + call pargr (rx1) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (rx2) + if (nscan() == 1) + if (!IS_INDEFR (rx2)) + rx1 = rx2 + } + + if (x1 == NULL) { + call malloc (x1, n+1, TY_PIXEL) + call malloc (y1, n+1, TY_PIXEL) + call malloc (w1, n+1, TY_PIXEL) + call amov$t (x, Mem$t[x1], n) + call amov$t (y, Mem$t[y1], n) + call amov$t (wts, Mem$t[w1], n) + } else { + call realloc (x1, n+1, TY_PIXEL) + call realloc (y1, n+1, TY_PIXEL) + call realloc (w1, n+1, TY_PIXEL) + } + call realloc (userwts, n+1, TY_PIXEL) + + call icg_add$t (gp, wx, wy, rx1, Mem$t[x1], Mem$t[y1], + Mem$t[w1], Mem$t[userwts], n) + + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + + case 'c': # Print the positions of data points. + if (x1 == NULL) { + i = icg_nearest$t (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call parg$t (x[i]) + call parg$t (y[i]) + call parg$t ($tcveval (cv, x[i])) + } + } else { + i = icg_nearest$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], + n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call parg$t (Mem$t[x1+i-1]) + call parg$t (Mem$t[y1+i-1]) + call parg$t ($tcveval (cv, Mem$t[x1+i-1])) + } + } + + case 'd': # Delete data points. + if (x1 == NULL) + call icg_delete$t (ic, gp, gt, cv, x, y, wts, + Mem$t[userwts], n, wx, wy) + else + call icg_delete$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], + Mem$t[w1], Mem$t[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'f': # Fit the function and reset the flags. + iferr { + if (x1 == NULL) + call ic_fit$t (ic, cv, x, y, wts, n, IC_NEWX(ic), + IC_NEWY(ic), IC_NEWWTS(ic), IC_NEWFUNCTION(ic)) + else + call ic_fit$t (ic, cv, Mem$t[x1], Mem$t[y1], Mem$t[w1], + n, IC_NEWX(ic), IC_NEWY(ic), IC_NEWWTS(ic), + IC_NEWFUNCTION(ic)) + + IC_NEWX(ic) = NO + IC_NEWY(ic) = NO + IC_NEWWTS(ic) = NO + IC_NEWFUNCTION(ic) = NO + IC_FITERROR(ic) = NO + newgraph = YES + + call ic_gui (ic, "refit NO") + } then { + IC_FITERROR(ic) = YES + call erract (EA_WARN) + } + + case 'g': # Set graph axes types. + call printf ("Graph key to be defined: ") + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + case 'h', 'i', 'j', 'k', 'l': + switch (Memc[cmd]) { + case 'h': + key = 1 + case 'i': + key = 2 + case 'j': + key = 3 + case 'k': + key = 4 + case 'l': + key = 5 + } + + call printf ("Set graph axes types (%c, %c): ") + call pargi (IC_AXES(ic, key, 1)) + call pargi (IC_AXES(ic, key, 2)) + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + default: + call gargc (Memc[cmd+1]) + call gargc (Memc[cmd+1]) + if (Memc[cmd+1] != '\n') { + IC_AXES(ic, key, 1) = Memc[cmd] + IC_AXES(ic, key, 2) = Memc[cmd+1] + if (IC_GKEY(ic) == key) + newgraph = YES + } + } + default: + call printf ("Not a graph key\n") + } + + case 'h': + if (IC_GKEY(ic) != 1) { + IC_GKEY(ic) = 1 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'i': + if (IC_GKEY(ic) != 2) { + IC_GKEY(ic) = 2 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'j': + if (IC_GKEY(ic) != 3) { + IC_GKEY(ic) = 3 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'k': + if (IC_GKEY(ic) != 4) { + IC_GKEY(ic) = 4 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'l': + if (IC_GKEY(ic) != 5) { + IC_GKEY(ic) = 5 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 't': # Initialize the sample string and erase from the graph. + if (x1 == NULL) + call icg_sample$t (ic, gp, gt, x, n, 0) + else + call icg_sample$t (ic, gp, gt, Mem$t[x1], n, 0) + call ic_pstr (ic, "sample", "*") + IC_NEWX(ic) = YES + + case 'o': # Set overplot flag + IC_OVERPLOT(ic) = YES + + case 'r': # Redraw the graph + newgraph = YES + + case 's': # Set sample regions with the cursor. + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') || + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + Memc[IC_SAMPLE(ic)] = EOS + + rx1 = wx + ry1 = wy + call printf ("again:\n") + if (gt_gcur1(gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + break + call printf ("\n") + rx2 = wx + ry2 = wy + + # Determine if the x vector is integer. + if (xtype == 0) { + xtype = TY_INT + if (x1 == NULL) { + do i = 1, n + if (x[i] != int (x[i])) { + xtype = TY_REAL + break + } + } else { + do i = 1, n + if (Mem$t[x1+i-1] != int (Mem$t[x1+i-1])) { + xtype = TY_REAL + break + } + } + } + + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (rx1)) + call pargi (nint (rx2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (rx1) + call pargr (rx2) + } + } else { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (ry1)) + call pargi (nint (ry2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (ry1) + call pargr (ry2) + } + } + call strcat (Memc[cmd], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + if (x1 == NULL) + call icg_sample$t (ic, gp, gt, x, n, 1) + else + call icg_sample$t (ic, gp, gt, Mem$t[x1], n, 1) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + IC_NEWX(ic) = YES + } + + case 'u': # Undelete data points. + if (x1 == NULL) + call icg_undelete$t (ic, gp, gt, cv, x, y, wts, + Mem$t[userwts], n, wx, wy) + else + call icg_undelete$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], + Mem$t[w1], Mem$t[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'w': # Window graph + call gt_window (gt, gp, cursor, newgraph) + + case 'v': # Reset the value of the weight. + if (x1 == NULL) { + i = icg_nearest$t (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call parg$t (wts[i]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + wts[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } else { + i = icg_nearest$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], n, + wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call parg$t (Mem$t[w1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + j = icg_nearest$t (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Mem$t[x1+i-1] && + y[j] == Mem$t[y1+i-1]) + wts[j] = px1 + Mem$t[w1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } + + case 'x': # Reset the value of the x point. + if (x1 == NULL) { + i = icg_nearest$t (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call parg$t (x[i]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + x[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } else { + i = icg_nearest$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], n, + wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call parg$t (Mem$t[x1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + j = icg_nearest$t (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Mem$t[x1+i-1] && + y[j] == Mem$t[y1+i-1]) + x[j] = px1 + Mem$t[x1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } + + case 'y': # Reset the value of the y point. + if (x1 == NULL) { + i = icg_nearest$t (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call parg$t (y[i]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + y[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } else { + i = icg_nearest$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], n, + wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call parg$t (Mem$t[y1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call garg$t (px1) + if (nscan() == 1) { + if (!IS_$INDEF (px1)) { + j = icg_nearest$t (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Mem$t[x1+i-1] && + y[j] == Mem$t[y1+i-1]) + y[j] = px1 + Mem$t[y1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } + + case 'z': # Delete sample region + if (x1 == NULL) + call icg_dsample$t (wx, wy, ic, gp, gt, x, n) + else + call icg_dsample$t (wx, wy, ic, gp, gt, Mem$t[x1], n) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + + case 'I': # Interrupt + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call icg_user (ic, gp, gt, cv, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. +10 if (newgraph == YES) { + if (IC_AXES(ic, IC_GKEY(ic), 1) != axes[1]) { + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + if (IC_AXES(ic, IC_GKEY(ic), 2) != axes[2]) { + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + if (x1 == NULL) + call icg_graph$t (ic, gp, gt, cv, x, y, wts, n) + else + call icg_graph$t (ic, gp, gt, cv, Mem$t[x1], Mem$t[y1], + Mem$t[w1], n) + newgraph = NO + } + if (cursor[1] == EOS) + break + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + + call ic_gui (ic, "close") + IC_GP(ic) = NULL + + if (x1 != NULL) { + call mfree (x1, TY_PIXEL) + call mfree (y1, TY_PIXEL) + call mfree (w1, TY_PIXEL) + if (IC_WTSFIT(ic) == NULL) + IC_NFIT(ic) = npts + } + call mfree (userwts, TY_PIXEL) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgfitd.x b/pkg/xtools/icfit/icgfitd.x new file mode 100644 index 00000000..ee66e9b3 --- /dev/null +++ b/pkg/xtools/icfit/icgfitd.x @@ -0,0 +1,544 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +# ICG_FIT -- Interactive curve fitting with graphics. This is the main +# entry point for the interactive graphics part of the icfit package. + +procedure icg_fitd (ic, gp, cursor, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +double x[npts] # Ordinates +double y[npts] # Abscissas +double wts[npts] # Weights +int npts # Number of points + +real wx, wy +int wcs, key + +int i, j, newgraph, axes[2], xtype +double px1 +real rx1, rx2, ry1, ry2 +pointer sp, cmd, userwts, x1, y1, w1, n + +int gt_gcur1(), stridxs(), scan(), nscan() +int icg_nearestd() +double dcveval() +errchk ic_fitd() + +begin + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + # Allocate memory for the fit and a copy of the weights. + # The weights are copied because they are changed when points are + # deleted. + + n = npts + x1 = NULL + y1 = NULL + w1 = NULL + call malloc (userwts, n, TY_DOUBLE) + call amovd (wts, Memd[userwts], n) + + # Initialize + IC_GP(ic) = gp + IC_GT(ic) = gt + IC_OVERPLOT(ic) = NO + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + IC_NEWFUNCTION(ic) = YES + + # Send the GUI the current task values. + call ic_gui (ic, "open") + call ic_gui (ic, "graph") + + # Read cursor commands. + + key = 'f' + newgraph = YES + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + xtype = 0 + + repeat { + switch (key) { + case '?': # Print help text. + call ic_gui (ic, "help") + + case ':': # List or set parameters + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call icg_colond (ic, Memc[cmd], newgraph, gp, gt, cv, + x, y, wts, n) + + case 'a': # Add points + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'y')) + ; + else if ((IC_AXES(ic,IC_GKEY(ic),1) == 'y') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + rx1 = wx + wx = wy + wy = rx1 + } else { + call printf ("Graph must be x vs. y or y vs. x\07\n") + next + } + + rx1 = 1. + call printf ("weight = (%g) ") + call pargr (rx1) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (rx2) + if (nscan() == 1) + if (!IS_INDEFR (rx2)) + rx1 = rx2 + } + + if (x1 == NULL) { + call malloc (x1, n+1, TY_DOUBLE) + call malloc (y1, n+1, TY_DOUBLE) + call malloc (w1, n+1, TY_DOUBLE) + call amovd (x, Memd[x1], n) + call amovd (y, Memd[y1], n) + call amovd (wts, Memd[w1], n) + } else { + call realloc (x1, n+1, TY_DOUBLE) + call realloc (y1, n+1, TY_DOUBLE) + call realloc (w1, n+1, TY_DOUBLE) + } + call realloc (userwts, n+1, TY_DOUBLE) + + call icg_addd (gp, wx, wy, rx1, Memd[x1], Memd[y1], + Memd[w1], Memd[userwts], n) + + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + + case 'c': # Print the positions of data points. + if (x1 == NULL) { + i = icg_nearestd (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call pargd (x[i]) + call pargd (y[i]) + call pargd (dcveval (cv, x[i])) + } + } else { + i = icg_nearestd (ic, gp, gt, cv, Memd[x1], Memd[y1], + n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call pargd (Memd[x1+i-1]) + call pargd (Memd[y1+i-1]) + call pargd (dcveval (cv, Memd[x1+i-1])) + } + } + + case 'd': # Delete data points. + if (x1 == NULL) + call icg_deleted (ic, gp, gt, cv, x, y, wts, + Memd[userwts], n, wx, wy) + else + call icg_deleted (ic, gp, gt, cv, Memd[x1], Memd[y1], + Memd[w1], Memd[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'f': # Fit the function and reset the flags. + iferr { + if (x1 == NULL) + call ic_fitd (ic, cv, x, y, wts, n, IC_NEWX(ic), + IC_NEWY(ic), IC_NEWWTS(ic), IC_NEWFUNCTION(ic)) + else + call ic_fitd (ic, cv, Memd[x1], Memd[y1], Memd[w1], + n, IC_NEWX(ic), IC_NEWY(ic), IC_NEWWTS(ic), + IC_NEWFUNCTION(ic)) + + IC_NEWX(ic) = NO + IC_NEWY(ic) = NO + IC_NEWWTS(ic) = NO + IC_NEWFUNCTION(ic) = NO + IC_FITERROR(ic) = NO + newgraph = YES + + call ic_gui (ic, "refit NO") + } then { + IC_FITERROR(ic) = YES + call erract (EA_WARN) + } + + case 'g': # Set graph axes types. + call printf ("Graph key to be defined: ") + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + case 'h', 'i', 'j', 'k', 'l': + switch (Memc[cmd]) { + case 'h': + key = 1 + case 'i': + key = 2 + case 'j': + key = 3 + case 'k': + key = 4 + case 'l': + key = 5 + } + + call printf ("Set graph axes types (%c, %c): ") + call pargi (IC_AXES(ic, key, 1)) + call pargi (IC_AXES(ic, key, 2)) + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + default: + call gargc (Memc[cmd+1]) + call gargc (Memc[cmd+1]) + if (Memc[cmd+1] != '\n') { + IC_AXES(ic, key, 1) = Memc[cmd] + IC_AXES(ic, key, 2) = Memc[cmd+1] + if (IC_GKEY(ic) == key) + newgraph = YES + } + } + default: + call printf ("Not a graph key\n") + } + + case 'h': + if (IC_GKEY(ic) != 1) { + IC_GKEY(ic) = 1 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'i': + if (IC_GKEY(ic) != 2) { + IC_GKEY(ic) = 2 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'j': + if (IC_GKEY(ic) != 3) { + IC_GKEY(ic) = 3 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'k': + if (IC_GKEY(ic) != 4) { + IC_GKEY(ic) = 4 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'l': + if (IC_GKEY(ic) != 5) { + IC_GKEY(ic) = 5 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 't': # Initialize the sample string and erase from the graph. + if (x1 == NULL) + call icg_sampled (ic, gp, gt, x, n, 0) + else + call icg_sampled (ic, gp, gt, Memd[x1], n, 0) + call ic_pstr (ic, "sample", "*") + IC_NEWX(ic) = YES + + case 'o': # Set overplot flag + IC_OVERPLOT(ic) = YES + + case 'r': # Redraw the graph + newgraph = YES + + case 's': # Set sample regions with the cursor. + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') || + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + Memc[IC_SAMPLE(ic)] = EOS + + rx1 = wx + ry1 = wy + call printf ("again:\n") + if (gt_gcur1(gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + break + call printf ("\n") + rx2 = wx + ry2 = wy + + # Determine if the x vector is integer. + if (xtype == 0) { + xtype = TY_INT + if (x1 == NULL) { + do i = 1, n + if (x[i] != int (x[i])) { + xtype = TY_REAL + break + } + } else { + do i = 1, n + if (Memd[x1+i-1] != int (Memd[x1+i-1])) { + xtype = TY_REAL + break + } + } + } + + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (rx1)) + call pargi (nint (rx2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (rx1) + call pargr (rx2) + } + } else { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (ry1)) + call pargi (nint (ry2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (ry1) + call pargr (ry2) + } + } + call strcat (Memc[cmd], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + if (x1 == NULL) + call icg_sampled (ic, gp, gt, x, n, 1) + else + call icg_sampled (ic, gp, gt, Memd[x1], n, 1) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + IC_NEWX(ic) = YES + } + + case 'u': # Undelete data points. + if (x1 == NULL) + call icg_undeleted (ic, gp, gt, cv, x, y, wts, + Memd[userwts], n, wx, wy) + else + call icg_undeleted (ic, gp, gt, cv, Memd[x1], Memd[y1], + Memd[w1], Memd[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'w': # Window graph + call gt_window (gt, gp, cursor, newgraph) + + case 'v': # Reset the value of the weight. + if (x1 == NULL) { + i = icg_nearestd (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call pargd (wts[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + wts[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } else { + i = icg_nearestd (ic, gp, gt, cv, Memd[x1], Memd[y1], n, + wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call pargd (Memd[w1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestd (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memd[x1+i-1] && + y[j] == Memd[y1+i-1]) + wts[j] = px1 + Memd[w1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } + + case 'x': # Reset the value of the x point. + if (x1 == NULL) { + i = icg_nearestd (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call pargd (x[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + x[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } else { + i = icg_nearestd (ic, gp, gt, cv, Memd[x1], Memd[y1], n, + wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call pargd (Memd[x1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestd (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memd[x1+i-1] && + y[j] == Memd[y1+i-1]) + x[j] = px1 + Memd[x1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } + + case 'y': # Reset the value of the y point. + if (x1 == NULL) { + i = icg_nearestd (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call pargd (y[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + y[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } else { + i = icg_nearestd (ic, gp, gt, cv, Memd[x1], Memd[y1], n, + wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call pargd (Memd[y1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargd (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestd (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memd[x1+i-1] && + y[j] == Memd[y1+i-1]) + y[j] = px1 + Memd[y1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } + + case 'z': # Delete sample region + if (x1 == NULL) + call icg_dsampled (wx, wy, ic, gp, gt, x, n) + else + call icg_dsampled (wx, wy, ic, gp, gt, Memd[x1], n) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + + case 'I': # Interrupt + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call icg_user (ic, gp, gt, cv, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. +10 if (newgraph == YES) { + if (IC_AXES(ic, IC_GKEY(ic), 1) != axes[1]) { + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + if (IC_AXES(ic, IC_GKEY(ic), 2) != axes[2]) { + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + if (x1 == NULL) + call icg_graphd (ic, gp, gt, cv, x, y, wts, n) + else + call icg_graphd (ic, gp, gt, cv, Memd[x1], Memd[y1], + Memd[w1], n) + newgraph = NO + } + if (cursor[1] == EOS) + break + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + + call ic_gui (ic, "close") + IC_GP(ic) = NULL + + if (x1 != NULL) { + call mfree (x1, TY_DOUBLE) + call mfree (y1, TY_DOUBLE) + call mfree (w1, TY_DOUBLE) + if (IC_WTSFIT(ic) == NULL) + IC_NFIT(ic) = npts + } + call mfree (userwts, TY_DOUBLE) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgfitr.x b/pkg/xtools/icfit/icgfitr.x new file mode 100644 index 00000000..d10c1607 --- /dev/null +++ b/pkg/xtools/icfit/icgfitr.x @@ -0,0 +1,544 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +# ICG_FIT -- Interactive curve fitting with graphics. This is the main +# entry point for the interactive graphics part of the icfit package. + +procedure icg_fitr (ic, gp, cursor, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +real x[npts] # Ordinates +real y[npts] # Abscissas +real wts[npts] # Weights +int npts # Number of points + +real wx, wy +int wcs, key + +int i, j, newgraph, axes[2], xtype +real px1 +real rx1, rx2, ry1, ry2 +pointer sp, cmd, userwts, x1, y1, w1, n + +int gt_gcur1(), stridxs(), scan(), nscan() +int icg_nearestr() +real rcveval() +errchk ic_fitr() + +begin + call smark (sp) + call salloc (cmd, IC_SZSAMPLE, TY_CHAR) + + # Allocate memory for the fit and a copy of the weights. + # The weights are copied because they are changed when points are + # deleted. + + n = npts + x1 = NULL + y1 = NULL + w1 = NULL + call malloc (userwts, n, TY_REAL) + call amovr (wts, Memr[userwts], n) + + # Initialize + IC_GP(ic) = gp + IC_GT(ic) = gt + IC_OVERPLOT(ic) = NO + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + IC_NEWFUNCTION(ic) = YES + + # Send the GUI the current task values. + call ic_gui (ic, "open") + call ic_gui (ic, "graph") + + # Read cursor commands. + + key = 'f' + newgraph = YES + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + xtype = 0 + + repeat { + switch (key) { + case '?': # Print help text. + call ic_gui (ic, "help") + + case ':': # List or set parameters + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call icg_colonr (ic, Memc[cmd], newgraph, gp, gt, cv, + x, y, wts, n) + + case 'a': # Add points + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'y')) + ; + else if ((IC_AXES(ic,IC_GKEY(ic),1) == 'y') && + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + rx1 = wx + wx = wy + wy = rx1 + } else { + call printf ("Graph must be x vs. y or y vs. x\07\n") + next + } + + rx1 = 1. + call printf ("weight = (%g) ") + call pargr (rx1) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (rx2) + if (nscan() == 1) + if (!IS_INDEFR (rx2)) + rx1 = rx2 + } + + if (x1 == NULL) { + call malloc (x1, n+1, TY_REAL) + call malloc (y1, n+1, TY_REAL) + call malloc (w1, n+1, TY_REAL) + call amovr (x, Memr[x1], n) + call amovr (y, Memr[y1], n) + call amovr (wts, Memr[w1], n) + } else { + call realloc (x1, n+1, TY_REAL) + call realloc (y1, n+1, TY_REAL) + call realloc (w1, n+1, TY_REAL) + } + call realloc (userwts, n+1, TY_REAL) + + call icg_addr (gp, wx, wy, rx1, Memr[x1], Memr[y1], + Memr[w1], Memr[userwts], n) + + IC_NEWX(ic) = YES + IC_NEWY(ic) = YES + IC_NEWWTS(ic) = YES + + case 'c': # Print the positions of data points. + if (x1 == NULL) { + i = icg_nearestr (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call pargr (x[i]) + call pargr (y[i]) + call pargr (rcveval (cv, x[i])) + } + } else { + i = icg_nearestr (ic, gp, gt, cv, Memr[x1], Memr[y1], + n, wx, wy) + + if (i != 0) { + call printf ("x = %g y = %g fit = %g\n") + call pargr (Memr[x1+i-1]) + call pargr (Memr[y1+i-1]) + call pargr (rcveval (cv, Memr[x1+i-1])) + } + } + + case 'd': # Delete data points. + if (x1 == NULL) + call icg_deleter (ic, gp, gt, cv, x, y, wts, + Memr[userwts], n, wx, wy) + else + call icg_deleter (ic, gp, gt, cv, Memr[x1], Memr[y1], + Memr[w1], Memr[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'f': # Fit the function and reset the flags. + iferr { + if (x1 == NULL) + call ic_fitr (ic, cv, x, y, wts, n, IC_NEWX(ic), + IC_NEWY(ic), IC_NEWWTS(ic), IC_NEWFUNCTION(ic)) + else + call ic_fitr (ic, cv, Memr[x1], Memr[y1], Memr[w1], + n, IC_NEWX(ic), IC_NEWY(ic), IC_NEWWTS(ic), + IC_NEWFUNCTION(ic)) + + IC_NEWX(ic) = NO + IC_NEWY(ic) = NO + IC_NEWWTS(ic) = NO + IC_NEWFUNCTION(ic) = NO + IC_FITERROR(ic) = NO + newgraph = YES + + call ic_gui (ic, "refit NO") + } then { + IC_FITERROR(ic) = YES + call erract (EA_WARN) + } + + case 'g': # Set graph axes types. + call printf ("Graph key to be defined: ") + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + case 'h', 'i', 'j', 'k', 'l': + switch (Memc[cmd]) { + case 'h': + key = 1 + case 'i': + key = 2 + case 'j': + key = 3 + case 'k': + key = 4 + case 'l': + key = 5 + } + + call printf ("Set graph axes types (%c, %c): ") + call pargi (IC_AXES(ic, key, 1)) + call pargi (IC_AXES(ic, key, 2)) + call flush (STDOUT) + if (scan() == EOF) + goto 10 + call gargc (Memc[cmd]) + + switch (Memc[cmd]) { + case '\n': + default: + call gargc (Memc[cmd+1]) + call gargc (Memc[cmd+1]) + if (Memc[cmd+1] != '\n') { + IC_AXES(ic, key, 1) = Memc[cmd] + IC_AXES(ic, key, 2) = Memc[cmd+1] + if (IC_GKEY(ic) == key) + newgraph = YES + } + } + default: + call printf ("Not a graph key\n") + } + + case 'h': + if (IC_GKEY(ic) != 1) { + IC_GKEY(ic) = 1 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'i': + if (IC_GKEY(ic) != 2) { + IC_GKEY(ic) = 2 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'j': + if (IC_GKEY(ic) != 3) { + IC_GKEY(ic) = 3 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'k': + if (IC_GKEY(ic) != 4) { + IC_GKEY(ic) = 4 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 'l': + if (IC_GKEY(ic) != 5) { + IC_GKEY(ic) = 5 + newgraph = YES + call ic_gui (ic, "graph") + } + + case 't': # Initialize the sample string and erase from the graph. + if (x1 == NULL) + call icg_sampler (ic, gp, gt, x, n, 0) + else + call icg_sampler (ic, gp, gt, Memr[x1], n, 0) + call ic_pstr (ic, "sample", "*") + IC_NEWX(ic) = YES + + case 'o': # Set overplot flag + IC_OVERPLOT(ic) = YES + + case 'r': # Redraw the graph + newgraph = YES + + case 's': # Set sample regions with the cursor. + if ((IC_AXES(ic,IC_GKEY(ic),1) == 'x') || + (IC_AXES(ic,IC_GKEY(ic),2) == 'x')) { + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + Memc[IC_SAMPLE(ic)] = EOS + + rx1 = wx + ry1 = wy + call printf ("again:\n") + if (gt_gcur1(gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + break + call printf ("\n") + rx2 = wx + ry2 = wy + + # Determine if the x vector is integer. + if (xtype == 0) { + xtype = TY_INT + if (x1 == NULL) { + do i = 1, n + if (x[i] != int (x[i])) { + xtype = TY_REAL + break + } + } else { + do i = 1, n + if (Memr[x1+i-1] != int (Memr[x1+i-1])) { + xtype = TY_REAL + break + } + } + } + + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (rx1)) + call pargi (nint (rx2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (rx1) + call pargr (rx2) + } + } else { + if (xtype == TY_INT) { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %d:%d") + call pargi (nint (ry1)) + call pargi (nint (ry2)) + } else { + call sprintf (Memc[cmd], IC_SZSAMPLE, " %g:%g") + call pargr (ry1) + call pargr (ry2) + } + } + call strcat (Memc[cmd], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + if (x1 == NULL) + call icg_sampler (ic, gp, gt, x, n, 1) + else + call icg_sampler (ic, gp, gt, Memr[x1], n, 1) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + IC_NEWX(ic) = YES + } + + case 'u': # Undelete data points. + if (x1 == NULL) + call icg_undeleter (ic, gp, gt, cv, x, y, wts, + Memr[userwts], n, wx, wy) + else + call icg_undeleter (ic, gp, gt, cv, Memr[x1], Memr[y1], + Memr[w1], Memr[userwts], n, wx, wy) + call ic_gui (ic, "refit YES") + + case 'w': # Window graph + call gt_window (gt, gp, cursor, newgraph) + + case 'v': # Reset the value of the weight. + if (x1 == NULL) { + i = icg_nearestr (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call pargr (wts[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + wts[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } else { + i = icg_nearestr (ic, gp, gt, cv, Memr[x1], Memr[y1], n, + wx, wy) + + if (i != 0) { + call printf ("weight = (%g) ") + call pargr (Memr[w1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestr (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memr[x1+i-1] && + y[j] == Memr[y1+i-1]) + wts[j] = px1 + Memr[w1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWWTS(ic) = YES + } + } + } + } + } + + case 'x': # Reset the value of the x point. + if (x1 == NULL) { + i = icg_nearestr (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call pargr (x[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + x[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } else { + i = icg_nearestr (ic, gp, gt, cv, Memr[x1], Memr[y1], n, + wx, wy) + + if (i != 0) { + call printf ("x = (%g) ") + call pargr (Memr[x1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestr (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memr[x1+i-1] && + y[j] == Memr[y1+i-1]) + x[j] = px1 + Memr[x1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWX(ic) = YES + } + } + } + } + } + + case 'y': # Reset the value of the y point. + if (x1 == NULL) { + i = icg_nearestr (ic, gp, gt, cv, x, y, n, wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call pargr (y[i]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + y[i] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } else { + i = icg_nearestr (ic, gp, gt, cv, Memr[x1], Memr[y1], n, + wx, wy) + + if (i != 0) { + call printf ("y = (%g) ") + call pargr (Memr[y1+i-1]) + call flush (STDOUT) + if (scan() != EOF) { + call gargr (px1) + if (nscan() == 1) { + if (!IS_INDEF (px1)) { + j = icg_nearestr (ic, gp, gt, cv, x, y, n, + wx, wy) + if (j != 0) + if (x[j] == Memr[x1+i-1] && + y[j] == Memr[y1+i-1]) + y[j] = px1 + Memr[y1+i-1] = px1 + call ic_gui (ic, "refit YES") + IC_NEWY(ic) = YES + } + } + } + } + } + + case 'z': # Delete sample region + if (x1 == NULL) + call icg_dsampler (wx, wy, ic, gp, gt, x, n) + else + call icg_dsampler (wx, wy, ic, gp, gt, Memr[x1], n) + call ic_pstr (ic, "sample", Memc[IC_SAMPLE(ic)]) + + case 'I': # Interrupt + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call icg_user (ic, gp, gt, cv, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. +10 if (newgraph == YES) { + if (IC_AXES(ic, IC_GKEY(ic), 1) != axes[1]) { + axes[1] = IC_AXES(ic, IC_GKEY(ic), 1) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + if (IC_AXES(ic, IC_GKEY(ic), 2) != axes[2]) { + axes[2] = IC_AXES(ic, IC_GKEY(ic), 2) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + if (x1 == NULL) + call icg_graphr (ic, gp, gt, cv, x, y, wts, n) + else + call icg_graphr (ic, gp, gt, cv, Memr[x1], Memr[y1], + Memr[w1], n) + newgraph = NO + } + if (cursor[1] == EOS) + break + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + IC_SZSAMPLE) == EOF) + + call ic_gui (ic, "close") + IC_GP(ic) = NULL + + if (x1 != NULL) { + call mfree (x1, TY_REAL) + call mfree (y1, TY_REAL) + call mfree (w1, TY_REAL) + if (IC_WTSFIT(ic) == NULL) + IC_NFIT(ic) = npts + } + call mfree (userwts, TY_REAL) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icggraph.gx b/pkg/xtools/icfit/icggraph.gx new file mode 100644 index 00000000..393582db --- /dev/null +++ b/pkg/xtools/icfit/icggraph.gx @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 2. # Mark size + +# ICG_GRAPH -- Graph data and fit. + +procedure icg_graph$t (ic, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer cv # Curfit pointer +PIXEL x[npts] # Independent variable +PIXEL y[npts] # Dependent variable +PIXEL wts[npts] # Weights +int npts # Number of points + +pointer xout, yout +real size + +begin + call malloc (xout, npts, TY_PIXEL) + call malloc (yout, npts, TY_PIXEL) + call icg_axes$t (ic, gt, cv, 1, x, y, Mem$t[xout], npts) + call icg_axes$t (ic, gt, cv, 2, x, y, Mem$t[yout], npts) + call icg_params$t (ic, cv, x, y, wts, npts, gt) + + call icg_g1$t (ic, gp, gt, Mem$t[xout], Mem$t[yout], wts, npts) + + # Symbol size for averaged ranges. + size = abs(IC_NAVERAGE(ic) * (Mem$t[xout+npts-1] - Mem$t[xout]) / + float(npts)) + + if (npts != IC_NFIT(ic)) { + if ((abs (IC_NAVERAGE(ic)) > 1) || (IC_NREJECT(ic) > 0)) { + call realloc (xout, IC_NFIT(ic), TY_PIXEL) + call realloc (yout, IC_NFIT(ic), TY_PIXEL) + call icg_axes$t (ic, gt, cv, 1, Mem$t[IC_XFIT(ic)], + Mem$t[IC_YFIT(ic)], Mem$t[xout], IC_NFIT(ic)) + call icg_axes$t (ic, gt, cv, 2, Mem$t[IC_XFIT(ic)], + Mem$t[IC_YFIT(ic)], Mem$t[yout], IC_NFIT(ic)) + call icg_g2$t (ic, gp, gt, Mem$t[xout], Mem$t[yout], + IC_NFIT(ic), size) + } + + } else if (IC_NREJECT(ic) > 0) + call icg_g2$t (ic, gp, gt, Mem$t[xout], Mem$t[yout], npts, size) + + call icg_gf$t (ic, gp, gt, cv, max (npts, NGRAPH)) + + # Mark the the sample regions. + + call icg_sample$t (ic, gp, gt, x, npts, 1) + + # Send the wcs to the gui. + call ic_gui (ic, "wcs") + + call mfree (xout, TY_PIXEL) + call mfree (yout, TY_PIXEL) +end + +procedure icg_g1$t (ic, gp, gt, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +PIXEL x[npts] # Ordinates +PIXEL y[npts] # Abscissas +PIXEL wts[npts] # Weights +int npts # Number of points + +int i +pointer sp, xr, yr, xr1, yr1, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (xr1, 2, TY_REAL) + call salloc (yr1, 2, TY_REAL) + call acht$tr (x, Memr[xr], npts) + call acht$tr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + if (IC_OVERPLOT(ic) == NO) { + # Start a new plot. + + call gclear (gp) + + # Set the graph scale and axes. + + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + if (IC_OVERPLOT(ic) == NO) { + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == 0.) { + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } else { + Memr[xr1+1] = Memr[xr+i-1] + Memr[yr1+1] = Memr[yr+i-1] + call gt_plot (gp, gt, Memr[xr1], Memr[yr1], 2) + Memr[xr1] = Memr[xr1+1] + Memr[yr1] = Memr[yr1+1] + } + } + } + + # Reset status flags. + + IC_OVERPLOT(ic) = NO + + call sfree (sp) + call gt_free (gt1) +end + +procedure icg_g2$t (ic, gp, gt, x, y, npts, size) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +PIXEL x[npts], y[npts] # Data points +int npts # Number of data points +real size # Symbol size + +int i +pointer sp, xr, yr, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call acht$tr (x, Memr[xr], npts) + call acht$tr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + + # Mark the sample points. + + if (abs (IC_NAVERAGE(ic)) > 1) { + call gt_sets (gt1, GTMARK, "plus") + call gt_setr (gt1, GTXSIZE, -size) + call gt_setr (gt1, GTYSIZE, 1.) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + } + + # Mark the rejected points. + + if (IC_NREJECT(ic) > 0 && IC_MARKREJ(ic) == YES) { + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + call gt_free (gt1) + call sfree (sp) +end + +procedure icg_gf$t (ic, gp, gt, cv, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer cv # CURFIT pointer +int npts # Number of points to plot + +pointer sp, xr, yr, x, y, xo, yo, gt1 +int i +PIXEL dx + +begin + if (IC_FITERROR(ic) == YES) + return + + call smark (sp) + + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts, TY_PIXEL) + call salloc (y, npts, TY_PIXEL) + call salloc (xo, npts, TY_PIXEL) + call salloc (yo, npts, TY_PIXEL) + + # Generate vector of independent variable values + dx = (IC_XMAX(ic) - IC_XMIN(ic)) / (npts - 1) + do i = 1, npts + Mem$t[x+i-1] = IC_XMIN(ic) + (i-1) * dx + + # Calculate vector of fit values. + call $tcvvector (cv, Mem$t[x], Mem$t[y], npts) + + # Convert to user function or transpose axes. Change type to reals + # for plotting. + call icg_axes$t (ic, gt, cv, 1, Mem$t[x], Mem$t[y], Mem$t[xo], npts) + call icg_axes$t (ic, gt, cv, 2, Mem$t[x], Mem$t[y], Mem$t[yo], npts) + call acht$tr (Mem$t[xo], Memr[xr], npts) + call acht$tr (Mem$t[yo], Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "line") + call gt_seti (gt1, GTLINE, GL_DASHED) + call gt_seti (gt1, GTCOLOR, max (0, min (9, IC_COLOR(ic)))) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + call gt_free (gt1) + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icggraphd.x b/pkg/xtools/icfit/icggraphd.x new file mode 100644 index 00000000..03994a14 --- /dev/null +++ b/pkg/xtools/icfit/icggraphd.x @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 2. # Mark size + +# ICG_GRAPH -- Graph data and fit. + +procedure icg_graphd (ic, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer cv # Curfit pointer +double x[npts] # Independent variable +double y[npts] # Dependent variable +double wts[npts] # Weights +int npts # Number of points + +pointer xout, yout +real size + +begin + call malloc (xout, npts, TY_DOUBLE) + call malloc (yout, npts, TY_DOUBLE) + call icg_axesd (ic, gt, cv, 1, x, y, Memd[xout], npts) + call icg_axesd (ic, gt, cv, 2, x, y, Memd[yout], npts) + call icg_paramsd (ic, cv, x, y, wts, npts, gt) + + call icg_g1d (ic, gp, gt, Memd[xout], Memd[yout], wts, npts) + + # Symbol size for averaged ranges. + size = abs(IC_NAVERAGE(ic) * (Memd[xout+npts-1] - Memd[xout]) / + float(npts)) + + if (npts != IC_NFIT(ic)) { + if ((abs (IC_NAVERAGE(ic)) > 1) || (IC_NREJECT(ic) > 0)) { + call realloc (xout, IC_NFIT(ic), TY_DOUBLE) + call realloc (yout, IC_NFIT(ic), TY_DOUBLE) + call icg_axesd (ic, gt, cv, 1, Memd[IC_XFIT(ic)], + Memd[IC_YFIT(ic)], Memd[xout], IC_NFIT(ic)) + call icg_axesd (ic, gt, cv, 2, Memd[IC_XFIT(ic)], + Memd[IC_YFIT(ic)], Memd[yout], IC_NFIT(ic)) + call icg_g2d (ic, gp, gt, Memd[xout], Memd[yout], + IC_NFIT(ic), size) + } + + } else if (IC_NREJECT(ic) > 0) + call icg_g2d (ic, gp, gt, Memd[xout], Memd[yout], npts, size) + + call icg_gfd (ic, gp, gt, cv, max (npts, NGRAPH)) + + # Mark the the sample regions. + + call icg_sampled (ic, gp, gt, x, npts, 1) + + # Send the wcs to the gui. + call ic_gui (ic, "wcs") + + call mfree (xout, TY_DOUBLE) + call mfree (yout, TY_DOUBLE) +end + +procedure icg_g1d (ic, gp, gt, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +double x[npts] # Ordinates +double y[npts] # Abscissas +double wts[npts] # Weights +int npts # Number of points + +int i +pointer sp, xr, yr, xr1, yr1, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (xr1, 2, TY_REAL) + call salloc (yr1, 2, TY_REAL) + call achtdr (x, Memr[xr], npts) + call achtdr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + if (IC_OVERPLOT(ic) == NO) { + # Start a new plot. + + call gclear (gp) + + # Set the graph scale and axes. + + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + if (IC_OVERPLOT(ic) == NO) { + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == 0.) { + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } else { + Memr[xr1+1] = Memr[xr+i-1] + Memr[yr1+1] = Memr[yr+i-1] + call gt_plot (gp, gt, Memr[xr1], Memr[yr1], 2) + Memr[xr1] = Memr[xr1+1] + Memr[yr1] = Memr[yr1+1] + } + } + } + + # Reset status flags. + + IC_OVERPLOT(ic) = NO + + call sfree (sp) + call gt_free (gt1) +end + +procedure icg_g2d (ic, gp, gt, x, y, npts, size) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +double x[npts], y[npts] # Data points +int npts # Number of data points +real size # Symbol size + +int i +pointer sp, xr, yr, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call achtdr (x, Memr[xr], npts) + call achtdr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + + # Mark the sample points. + + if (abs (IC_NAVERAGE(ic)) > 1) { + call gt_sets (gt1, GTMARK, "plus") + call gt_setr (gt1, GTXSIZE, -size) + call gt_setr (gt1, GTYSIZE, 1.) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + } + + # Mark the rejected points. + + if (IC_NREJECT(ic) > 0 && IC_MARKREJ(ic) == YES) { + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + call gt_free (gt1) + call sfree (sp) +end + +procedure icg_gfd (ic, gp, gt, cv, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer cv # CURFIT pointer +int npts # Number of points to plot + +pointer sp, xr, yr, x, y, xo, yo, gt1 +int i +double dx + +begin + if (IC_FITERROR(ic) == YES) + return + + call smark (sp) + + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts, TY_DOUBLE) + call salloc (y, npts, TY_DOUBLE) + call salloc (xo, npts, TY_DOUBLE) + call salloc (yo, npts, TY_DOUBLE) + + # Generate vector of independent variable values + dx = (IC_XMAX(ic) - IC_XMIN(ic)) / (npts - 1) + do i = 1, npts + Memd[x+i-1] = IC_XMIN(ic) + (i-1) * dx + + # Calculate vector of fit values. + call dcvvector (cv, Memd[x], Memd[y], npts) + + # Convert to user function or transpose axes. Change type to reals + # for plotting. + call icg_axesd (ic, gt, cv, 1, Memd[x], Memd[y], Memd[xo], npts) + call icg_axesd (ic, gt, cv, 2, Memd[x], Memd[y], Memd[yo], npts) + call achtdr (Memd[xo], Memr[xr], npts) + call achtdr (Memd[yo], Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "line") + call gt_seti (gt1, GTLINE, GL_DASHED) + call gt_seti (gt1, GTCOLOR, max (0, min (9, IC_COLOR(ic)))) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + call gt_free (gt1) + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icggraphr.x b/pkg/xtools/icfit/icggraphr.x new file mode 100644 index 00000000..ac2a3f2c --- /dev/null +++ b/pkg/xtools/icfit/icggraphr.x @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <pkg/gtools.h> +include "names.h" +include "icfit.h" + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 2. # Mark size + +# ICG_GRAPH -- Graph data and fit. + +procedure icg_graphr (ic, gp, gt, cv, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer cv # Curfit pointer +real x[npts] # Independent variable +real y[npts] # Dependent variable +real wts[npts] # Weights +int npts # Number of points + +pointer xout, yout +real size + +begin + call malloc (xout, npts, TY_REAL) + call malloc (yout, npts, TY_REAL) + call icg_axesr (ic, gt, cv, 1, x, y, Memr[xout], npts) + call icg_axesr (ic, gt, cv, 2, x, y, Memr[yout], npts) + call icg_paramsr (ic, cv, x, y, wts, npts, gt) + + call icg_g1r (ic, gp, gt, Memr[xout], Memr[yout], wts, npts) + + # Symbol size for averaged ranges. + size = abs(IC_NAVERAGE(ic) * (Memr[xout+npts-1] - Memr[xout]) / + float(npts)) + + if (npts != IC_NFIT(ic)) { + if ((abs (IC_NAVERAGE(ic)) > 1) || (IC_NREJECT(ic) > 0)) { + call realloc (xout, IC_NFIT(ic), TY_REAL) + call realloc (yout, IC_NFIT(ic), TY_REAL) + call icg_axesr (ic, gt, cv, 1, Memr[IC_XFIT(ic)], + Memr[IC_YFIT(ic)], Memr[xout], IC_NFIT(ic)) + call icg_axesr (ic, gt, cv, 2, Memr[IC_XFIT(ic)], + Memr[IC_YFIT(ic)], Memr[yout], IC_NFIT(ic)) + call icg_g2r (ic, gp, gt, Memr[xout], Memr[yout], + IC_NFIT(ic), size) + } + + } else if (IC_NREJECT(ic) > 0) + call icg_g2r (ic, gp, gt, Memr[xout], Memr[yout], npts, size) + + call icg_gfr (ic, gp, gt, cv, max (npts, NGRAPH)) + + # Mark the the sample regions. + + call icg_sampler (ic, gp, gt, x, npts, 1) + + # Send the wcs to the gui. + call ic_gui (ic, "wcs") + + call mfree (xout, TY_REAL) + call mfree (yout, TY_REAL) +end + +procedure icg_g1r (ic, gp, gt, x, y, wts, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +real x[npts] # Ordinates +real y[npts] # Abscissas +real wts[npts] # Weights +int npts # Number of points + +int i +pointer sp, xr, yr, xr1, yr1, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (xr1, 2, TY_REAL) + call salloc (yr1, 2, TY_REAL) + call achtrr (x, Memr[xr], npts) + call achtrr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + if (IC_OVERPLOT(ic) == NO) { + # Start a new plot. + + call gclear (gp) + + # Set the graph scale and axes. + + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + if (IC_OVERPLOT(ic) == NO) { + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == 0.) { + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } else { + Memr[xr1+1] = Memr[xr+i-1] + Memr[yr1+1] = Memr[yr+i-1] + call gt_plot (gp, gt, Memr[xr1], Memr[yr1], 2) + Memr[xr1] = Memr[xr1+1] + Memr[yr1] = Memr[yr1+1] + } + } + } + + # Reset status flags. + + IC_OVERPLOT(ic) = NO + + call sfree (sp) + call gt_free (gt1) +end + +procedure icg_g2r (ic, gp, gt, x, y, npts, size) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +real x[npts], y[npts] # Data points +int npts # Number of data points +real size # Symbol size + +int i +pointer sp, xr, yr, gt1 + +begin + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call achtrr (x, Memr[xr], npts) + call achtrr (y, Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + + # Mark the sample points. + + if (abs (IC_NAVERAGE(ic)) > 1) { + call gt_sets (gt1, GTMARK, "plus") + call gt_setr (gt1, GTXSIZE, -size) + call gt_setr (gt1, GTYSIZE, 1.) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + } + + # Mark the rejected points. + + if (IC_NREJECT(ic) > 0 && IC_MARKREJ(ic) == YES) { + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + call gt_free (gt1) + call sfree (sp) +end + +procedure icg_gfr (ic, gp, gt, cv, npts) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer cv # CURFIT pointer +int npts # Number of points to plot + +pointer sp, xr, yr, x, y, xo, yo, gt1 +int i +real dx + +begin + if (IC_FITERROR(ic) == YES) + return + + call smark (sp) + + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts, TY_REAL) + call salloc (y, npts, TY_REAL) + call salloc (xo, npts, TY_REAL) + call salloc (yo, npts, TY_REAL) + + # Generate vector of independent variable values + dx = (IC_XMAX(ic) - IC_XMIN(ic)) / (npts - 1) + do i = 1, npts + Memr[x+i-1] = IC_XMIN(ic) + (i-1) * dx + + # Calculate vector of fit values. + call rcvvector (cv, Memr[x], Memr[y], npts) + + # Convert to user function or transpose axes. Change type to reals + # for plotting. + call icg_axesr (ic, gt, cv, 1, Memr[x], Memr[y], Memr[xo], npts) + call icg_axesr (ic, gt, cv, 2, Memr[x], Memr[y], Memr[yo], npts) + call achtrr (Memr[xo], Memr[xr], npts) + call achtrr (Memr[yo], Memr[yr], npts) + + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "line") + call gt_seti (gt1, GTLINE, GL_DASHED) + call gt_seti (gt1, GTCOLOR, max (0, min (9, IC_COLOR(ic)))) + call gt_plot (gp, gt1, Memr[xr], Memr[yr], npts) + call gt_free (gt1) + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgnearest.gx b/pkg/xtools/icfit/icgnearest.gx new file mode 100644 index 00000000..d3165940 --- /dev/null +++ b/pkg/xtools/icfit/icgnearest.gx @@ -0,0 +1,74 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_NEAREST -- Find the nearest point to the cursor and return the index. +# The nearest point to the cursor in NDC coordinates is determined. +# The cursor is moved to the nearest point selected. + +int procedure icg_nearest$t (ic, gp, gt, cv, x, y, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +PIXEL x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int icg_n$t(), gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + call icg_axes$t (ic, gt, cv, 1, x, y, Mem$t[xout], npts) + call icg_axes$t (ic, gt, cv, 2, x, y, Mem$t[yout], npts) + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = icg_n$t (gp, Mem$t[xout], Mem$t[yout], npts, wx, wy) + else + pt = icg_n$t (gp, Mem$t[yout], Mem$t[xout], npts, wy, wx) + call sfree (sp) + + return (pt) +end + +int procedure icg_n$t (gp, x, y, npts, wx, wy) + +pointer gp # GIO pointer +PIXEL x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point. + + r2min = MAX_REAL + do i = 1, npts { + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Move the cursor to the selected point and return the index. + + if (j != 0) + call gscur (gp, real (x[j]), real (y[j])) + + return (j) +end diff --git a/pkg/xtools/icfit/icgnearestd.x b/pkg/xtools/icfit/icgnearestd.x new file mode 100644 index 00000000..4011f95c --- /dev/null +++ b/pkg/xtools/icfit/icgnearestd.x @@ -0,0 +1,74 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_NEAREST -- Find the nearest point to the cursor and return the index. +# The nearest point to the cursor in NDC coordinates is determined. +# The cursor is moved to the nearest point selected. + +int procedure icg_nearestd (ic, gp, gt, cv, x, y, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +double x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int icg_nd(), gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + call icg_axesd (ic, gt, cv, 1, x, y, Memd[xout], npts) + call icg_axesd (ic, gt, cv, 2, x, y, Memd[yout], npts) + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = icg_nd (gp, Memd[xout], Memd[yout], npts, wx, wy) + else + pt = icg_nd (gp, Memd[yout], Memd[xout], npts, wy, wx) + call sfree (sp) + + return (pt) +end + +int procedure icg_nd (gp, x, y, npts, wx, wy) + +pointer gp # GIO pointer +double x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point. + + r2min = MAX_REAL + do i = 1, npts { + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Move the cursor to the selected point and return the index. + + if (j != 0) + call gscur (gp, real (x[j]), real (y[j])) + + return (j) +end diff --git a/pkg/xtools/icfit/icgnearestr.x b/pkg/xtools/icfit/icgnearestr.x new file mode 100644 index 00000000..41363103 --- /dev/null +++ b/pkg/xtools/icfit/icgnearestr.x @@ -0,0 +1,74 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_NEAREST -- Find the nearest point to the cursor and return the index. +# The nearest point to the cursor in NDC coordinates is determined. +# The cursor is moved to the nearest point selected. + +int procedure icg_nearestr (ic, gp, gt, cv, x, y, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +real x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int icg_nr(), gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + call icg_axesr (ic, gt, cv, 1, x, y, Memr[xout], npts) + call icg_axesr (ic, gt, cv, 2, x, y, Memr[yout], npts) + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = icg_nr (gp, Memr[xout], Memr[yout], npts, wx, wy) + else + pt = icg_nr (gp, Memr[yout], Memr[xout], npts, wy, wx) + call sfree (sp) + + return (pt) +end + +int procedure icg_nr (gp, x, y, npts, wx, wy) + +pointer gp # GIO pointer +real x[npts], y[npts] # Data points +int npts # Number of points +real wx, wy # Cursor position + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point. + + r2min = MAX_REAL + do i = 1, npts { + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Move the cursor to the selected point and return the index. + + if (j != 0) + call gscur (gp, real (x[j]), real (y[j])) + + return (j) +end diff --git a/pkg/xtools/icfit/icgparams.gx b/pkg/xtools/icfit/icgparams.gx new file mode 100644 index 00000000..c63657e3 --- /dev/null +++ b/pkg/xtools/icfit/icgparams.gx @@ -0,0 +1,118 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_PARAMS -- Set parameter string. + +procedure icg_params$t (ic, cv, x, y, wts, npts, gt) + +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 +pointer gt # GTOOLS pointer + +int i, n, deleted +PIXEL rms +pointer sp, fit, wts1, str, params + +PIXEL ic_rms$t() + +begin + call smark (sp) + + n = IC_NFIT(ic) + deleted = 0 + rms = INDEF + + if (n == npts) { + # Allocate memory for the fit. + + 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 + } + + # Set the fit and compute the RMS error. + + if (IC_FITERROR(ic) == NO) { + call $tcvvector (cv, x, Mem$t[fit], n) + rms = ic_rms$t (x, y, Mem$t[fit], Mem$t[wts1], n) + } else + rms = INDEF + } else if (n > 0) { + # Allocate memory for the fit. + + 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 + } + + # Set the fit and compute the rms error. + + if (IC_FITERROR(ic) == NO) { + 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) + } else + rms = INDEF + } + + # Print the parameters and errors. + + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (params, 2*SZ_LINE, TY_CHAR) + + call sprintf (Memc[str], SZ_LINE, + "func=%s, order=%d, low_rej=%r, high_rej=%r, niterate=%d, grow=%r") + call ic_gstr (ic, "function", Memc[params], 2*SZ_LINE) + call pargstr (Memc[params]) + call pargi (IC_ORDER(ic)) + call pargr (IC_LOW(ic)) + call pargr (IC_HIGH(ic)) + call pargi (IC_NITERATE(ic)) + call pargr (IC_GROW(ic)) + call sprintf (Memc[params], 2*SZ_LINE, + "%s\ntotal=%d, sample=%d, rejected=%d, deleted=%d, RMS=%7.4g") + call pargstr (Memc[str]) + call pargi (npts) + call pargi (n) + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call parg$t (rms) + call gt_sets (gt, GTPARAMS, Memc[params]) + + # Free allocated memory. + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgparamsd.x b/pkg/xtools/icfit/icgparamsd.x new file mode 100644 index 00000000..de9397ab --- /dev/null +++ b/pkg/xtools/icfit/icgparamsd.x @@ -0,0 +1,118 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_PARAMS -- Set parameter string. + +procedure icg_paramsd (ic, cv, x, y, wts, npts, gt) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +pointer gt # GTOOLS pointer + +int i, n, deleted +double rms +pointer sp, fit, wts1, str, params + +double ic_rmsd() + +begin + call smark (sp) + + n = IC_NFIT(ic) + deleted = 0 + rms = INDEFD + + if (n == npts) { + # Allocate memory for the fit. + + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (wts, Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[wts1+i-1] = 0. + } + } + deleted = 0 + do i = 1, n { + if (wts[i] == 0.) + deleted = deleted + 1 + } + + # Set the fit and compute the RMS error. + + if (IC_FITERROR(ic) == NO) { + call dcvvector (cv, x, Memd[fit], n) + rms = ic_rmsd (x, y, Memd[fit], Memd[wts1], n) + } else + rms = INDEFD + } else if (n > 0) { + # Allocate memory for the fit. + + call salloc (fit, n, TY_DOUBLE) + call salloc (wts1, n, TY_DOUBLE) + + # Eliminate rejected points and count deleted points. + + call amovd (Memd[IC_WTSFIT(ic)], Memd[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memd[wts1+i-1] = 0. + } + } + deleted = 0 + do i = 1, n { + if (wts[i] == 0.) + deleted = deleted + 1 + } + + # Set the fit and compute the rms error. + + if (IC_FITERROR(ic) == NO) { + call dcvvector (cv, Memd[IC_XFIT(ic)], Memd[fit], n) + rms = ic_rmsd (Memd[IC_XFIT(ic)], Memd[IC_YFIT(ic)], + Memd[fit], Memd[wts1], n) + } else + rms = INDEFD + } + + # Print the parameters and errors. + + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (params, 2*SZ_LINE, TY_CHAR) + + call sprintf (Memc[str], SZ_LINE, + "func=%s, order=%d, low_rej=%r, high_rej=%r, niterate=%d, grow=%r") + call ic_gstr (ic, "function", Memc[params], 2*SZ_LINE) + call pargstr (Memc[params]) + call pargi (IC_ORDER(ic)) + call pargr (IC_LOW(ic)) + call pargr (IC_HIGH(ic)) + call pargi (IC_NITERATE(ic)) + call pargr (IC_GROW(ic)) + call sprintf (Memc[params], 2*SZ_LINE, + "%s\ntotal=%d, sample=%d, rejected=%d, deleted=%d, RMS=%7.4g") + call pargstr (Memc[str]) + call pargi (npts) + call pargi (n) + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call pargd (rms) + call gt_sets (gt, GTPARAMS, Memc[params]) + + # Free allocated memory. + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgparamsr.x b/pkg/xtools/icfit/icgparamsr.x new file mode 100644 index 00000000..a1c898de --- /dev/null +++ b/pkg/xtools/icfit/icgparamsr.x @@ -0,0 +1,118 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <pkg/gtools.h> +include "icfit.h" +include "names.h" + +# ICG_PARAMS -- Set parameter string. + +procedure icg_paramsr (ic, cv, x, y, wts, npts, gt) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +pointer gt # GTOOLS pointer + +int i, n, deleted +real rms +pointer sp, fit, wts1, str, params + +real ic_rmsr() + +begin + call smark (sp) + + n = IC_NFIT(ic) + deleted = 0 + rms = INDEFR + + if (n == npts) { + # Allocate memory for the fit. + + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (wts, Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[wts1+i-1] = 0. + } + } + deleted = 0 + do i = 1, n { + if (wts[i] == 0.) + deleted = deleted + 1 + } + + # Set the fit and compute the RMS error. + + if (IC_FITERROR(ic) == NO) { + call rcvvector (cv, x, Memr[fit], n) + rms = ic_rmsr (x, y, Memr[fit], Memr[wts1], n) + } else + rms = INDEFR + } else if (n > 0) { + # Allocate memory for the fit. + + call salloc (fit, n, TY_REAL) + call salloc (wts1, n, TY_REAL) + + # Eliminate rejected points and count deleted points. + + call amovr (Memr[IC_WTSFIT(ic)], Memr[wts1], n) + if (IC_NREJECT(ic) > 0) { + do i = 1, npts { + if (Memi[IC_REJPTS(ic)+i-1] == YES) + Memr[wts1+i-1] = 0. + } + } + deleted = 0 + do i = 1, n { + if (wts[i] == 0.) + deleted = deleted + 1 + } + + # Set the fit and compute the rms error. + + if (IC_FITERROR(ic) == NO) { + call rcvvector (cv, Memr[IC_XFIT(ic)], Memr[fit], n) + rms = ic_rmsr (Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)], + Memr[fit], Memr[wts1], n) + } else + rms = INDEFR + } + + # Print the parameters and errors. + + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (params, 2*SZ_LINE, TY_CHAR) + + call sprintf (Memc[str], SZ_LINE, + "func=%s, order=%d, low_rej=%r, high_rej=%r, niterate=%d, grow=%r") + call ic_gstr (ic, "function", Memc[params], 2*SZ_LINE) + call pargstr (Memc[params]) + call pargi (IC_ORDER(ic)) + call pargr (IC_LOW(ic)) + call pargr (IC_HIGH(ic)) + call pargi (IC_NITERATE(ic)) + call pargr (IC_GROW(ic)) + call sprintf (Memc[params], 2*SZ_LINE, + "%s\ntotal=%d, sample=%d, rejected=%d, deleted=%d, RMS=%7.4g") + call pargstr (Memc[str]) + call pargi (npts) + call pargi (n) + call pargi (IC_NREJECT(ic)) + call pargi (deleted) + call pargr (rms) + call gt_sets (gt, GTPARAMS, Memc[params]) + + # Free allocated memory. + + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgsample.gx b/pkg/xtools/icfit/icgsample.gx new file mode 100644 index 00000000..84d5216a --- /dev/null +++ b/pkg/xtools/icfit/icgsample.gx @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/rg.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_SAMPLE -- Mark sample. + +procedure icg_sample$t (ic, gp, gt, x, npts, pltype) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +PIXEL x[npts] # Ordinates of graph +int npts # Number of data points +int pltype # Plot line type + +pointer rg +int i, axis, pltype1 +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xranges$t() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, pltype) + rg = rg_xranges$t (Memc[IC_SAMPLE(ic)], x, npts) + + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + } + } + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) +end + + +# ICG_DSAMPLE -- Delete sample region. + +procedure icg_dsample$t (wx, wy, ic, gp, gt, x, npts) + +real wx, wy # Region to be deleted +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +PIXEL x[npts] # Ordinates of graph +int npts # Number of data points + +pointer sp, str, rg +int i, j, axis, pltype1 +real w, diff +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xranges$t() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + # Initialize + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, 0) + rg = rg_xranges$t (Memc[IC_SAMPLE(ic)], x, npts) + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + Memc[IC_SAMPLE(ic)] = EOS + + # Find nearest sample region + if (axis == 1) + w = wx + else + w = wy + + j = 1 + diff = MAX_REAL + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (w < x1) { + if (x1 - w < diff) { + diff = x1 - wx + j = i + } + } else if (wx > x2) { + if (wx - x2 < diff) { + diff = x1 - wx + j = i + } + } else { + diff = 0. + j = i + } + } + + # Erase sample region and reset sample string + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + IC_NEWX(ic) = YES + } + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + IC_NEWX(ic) = YES + } + } + } + + if (Memc[IC_SAMPLE(ic)] == EOS) + call strcat ("*", Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgsampled.x b/pkg/xtools/icfit/icgsampled.x new file mode 100644 index 00000000..314dfc33 --- /dev/null +++ b/pkg/xtools/icfit/icgsampled.x @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/rg.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_SAMPLE -- Mark sample. + +procedure icg_sampled (ic, gp, gt, x, npts, pltype) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +double x[npts] # Ordinates of graph +int npts # Number of data points +int pltype # Plot line type + +pointer rg +int i, axis, pltype1 +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xrangesd() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, pltype) + rg = rg_xrangesd (Memc[IC_SAMPLE(ic)], x, npts) + + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + } + } + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) +end + + +# ICG_DSAMPLE -- Delete sample region. + +procedure icg_dsampled (wx, wy, ic, gp, gt, x, npts) + +real wx, wy # Region to be deleted +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +double x[npts] # Ordinates of graph +int npts # Number of data points + +pointer sp, str, rg +int i, j, axis, pltype1 +real w, diff +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xrangesd() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + # Initialize + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, 0) + rg = rg_xrangesd (Memc[IC_SAMPLE(ic)], x, npts) + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + Memc[IC_SAMPLE(ic)] = EOS + + # Find nearest sample region + if (axis == 1) + w = wx + else + w = wy + + j = 1 + diff = MAX_REAL + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (w < x1) { + if (x1 - w < diff) { + diff = x1 - wx + j = i + } + } else if (wx > x2) { + if (wx - x2 < diff) { + diff = x1 - wx + j = i + } + } else { + diff = 0. + j = i + } + } + + # Erase sample region and reset sample string + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + IC_NEWX(ic) = YES + } + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + IC_NEWX(ic) = YES + } + } + } + + if (Memc[IC_SAMPLE(ic)] == EOS) + call strcat ("*", Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgsampler.x b/pkg/xtools/icfit/icgsampler.x new file mode 100644 index 00000000..2310cbb8 --- /dev/null +++ b/pkg/xtools/icfit/icgsampler.x @@ -0,0 +1,226 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/rg.h> +include <pkg/gtools.h> +include "icfit.h" + +# ICG_SAMPLE -- Mark sample. + +procedure icg_sampler (ic, gp, gt, x, npts, pltype) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +real x[npts] # Ordinates of graph +int npts # Number of data points +int pltype # Plot line type + +pointer rg +int i, axis, pltype1 +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xrangesr() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, pltype) + rg = rg_xrangesr (Memc[IC_SAMPLE(ic)], x, npts) + + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + } + } + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) +end + + +# ICG_DSAMPLE -- Delete sample region. + +procedure icg_dsampler (wx, wy, ic, gp, gt, x, npts) + +real wx, wy # Region to be deleted +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +real x[npts] # Ordinates of graph +int npts # Number of data points + +pointer sp, str, rg +int i, j, axis, pltype1 +real w, diff +real xl, xr, yb, yt, dy +real x1, x2, y1, y2, y3 + +int gstati(), stridxs(), gt_geti() +pointer rg_xrangesr() + +begin + if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0) + return + + # Find axis along which the independent data is plotted. + if (IC_AXES(ic,IC_GKEY(ic),1) == 'x') + axis = 1 + else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x') + axis = 2 + else + return + + if (gt_geti (gt, GTTRANSPOSE) == YES) + axis = mod (axis, 2) + 1 + + # Initialize + pltype1 = gstati (gp, G_PLTYPE) + call gseti (gp, G_PLTYPE, 0) + rg = rg_xrangesr (Memc[IC_SAMPLE(ic)], x, npts) + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + Memc[IC_SAMPLE(ic)] = EOS + + # Find nearest sample region + if (axis == 1) + w = wx + else + w = wy + + j = 1 + diff = MAX_REAL + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (w < x1) { + if (x1 - w < diff) { + diff = x1 - wx + j = i + } + } else if (wx > x2) { + if (wx - x2 < diff) { + diff = x1 - wx + j = i + } + } else { + diff = 0. + j = i + } + } + + # Erase sample region and reset sample string + switch (axis) { + case 1: + call ggwind (gp, xl, xr, yb, yt) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, x1, y1, x1, y2) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, x2, y1, x2, y2) + call gline (gp, x1, y3, x2, y3) + IC_NEWX(ic) = YES + } + } + case 2: + call ggwind (gp, yb, yt, xl, xr) + + dy = yt - yb + y1 = yb + dy / 100 + y2 = y1 + dy / 20 + y3 = (y1 + y2) / 2 + + do i = 1, RG_NRGS(rg) { + x1 = x[RG_X1(rg, i)] + x2 = x[RG_X2(rg, i)] + if (i != j) { + if (x1 == int(x1) && x2 == int(x2)) + call sprintf (Memc[str], SZ_FNAME, " %d:%d") + else + call sprintf (Memc[str], SZ_FNAME, " %g:%g") + call pargr (x1) + call pargr (x2) + call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + } else { + if ((x1 > xl) && (x1 < xr)) + call gline (gp, y1, x1, y2, x1) + if ((x2 > xl) && (x2 < xr)) + call gline (gp, y1, x2, y2, x2) + call gline (gp, y3, x1, y3, x2) + IC_NEWX(ic) = YES + } + } + } + + if (Memc[IC_SAMPLE(ic)] == EOS) + call strcat ("*", Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + + call gseti (gp, G_PLTYPE, pltype1) + call rg_free (rg) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icguaxes.gx b/pkg/xtools/icfit/icguaxes.gx new file mode 100644 index 00000000..1527a10e --- /dev/null +++ b/pkg/xtools/icfit/icguaxes.gx @@ -0,0 +1,18 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# ICG_UAXES -- Set user axis + +procedure icg_uaxes$t (key, cv, x, y, z, npts, label, units, maxchars) + +int key # Key for axes +pointer cv # CURFIT pointer +PIXEL x[npts] # Independent variable +PIXEL y[npts] # Dependent variable +PIXEL z[npts] # Output values +int npts # Number of points +char label[maxchars] # Axis label +char units[maxchars] # Axis units +int maxchars # Maximum chars in label + +begin +end diff --git a/pkg/xtools/icfit/icguaxesd.x b/pkg/xtools/icfit/icguaxesd.x new file mode 100644 index 00000000..b787d211 --- /dev/null +++ b/pkg/xtools/icfit/icguaxesd.x @@ -0,0 +1,18 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# ICG_UAXES -- Set user axis + +procedure icg_uaxesd (key, cv, x, y, z, npts, label, units, maxchars) + +int key # Key for axes +pointer cv # CURFIT pointer +double x[npts] # Independent variable +double y[npts] # Dependent variable +double z[npts] # Output values +int npts # Number of points +char label[maxchars] # Axis label +char units[maxchars] # Axis units +int maxchars # Maximum chars in label + +begin +end diff --git a/pkg/xtools/icfit/icguaxesr.x b/pkg/xtools/icfit/icguaxesr.x new file mode 100644 index 00000000..deeac3c7 --- /dev/null +++ b/pkg/xtools/icfit/icguaxesr.x @@ -0,0 +1,18 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# ICG_UAXES -- Set user axis + +procedure icg_uaxesr (key, cv, x, y, z, npts, label, units, maxchars) + +int key # Key for axes +pointer cv # CURFIT pointer +real x[npts] # Independent variable +real y[npts] # Dependent variable +real z[npts] # Output values +int npts # Number of points +char label[maxchars] # Axis label +char units[maxchars] # Axis units +int maxchars # Maximum chars in label + +begin +end diff --git a/pkg/xtools/icfit/icgui.x b/pkg/xtools/icfit/icgui.x new file mode 100644 index 00000000..9e0fd6e0 --- /dev/null +++ b/pkg/xtools/icfit/icgui.x @@ -0,0 +1,138 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <gio.h> +include "icfit.h" + +define CMDS "|open|close|params|graph|wcs|refit|help|" + +define OPEN 1 # Open GUI and send initial parameters +define CLOSE 2 # Close GUI and send final parameters +define PARAMS 3 # Send new parameters +define GRAPH 4 # Send graph type parameters +define WCS 5 # Send graph wcs parameters +define REFIT 6 # Send refit flag +define HELP 7 # Send help + +# IC_GUI -- GUI interaction. +# +# Note there is currently an interface violation to determine if the graphics +# stream is connected to a GUI. + +procedure ic_gui (ic, cmd) + +pointer ic #I ICFIT pointer +char cmd[ARB] #I Command + +int ncmd, strdic() +real vx1, vx2, vy1, vy2, wx1, wx2, wy1, wy2 +pointer sp, str, msg +bool streq() +errchk ic_help + +begin + if (IC_GP(ic) == NULL) + return + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Scan the command and switch on the first word. + call sscan (cmd) + call gargwrd (Memc[str], SZ_LINE) + ncmd = strdic (Memc[str], Memc[str], SZ_LINE, CMDS) + switch (ncmd) { + case OPEN, CLOSE, PARAMS: + call salloc (msg, SZ_LINE+IC_SZSAMPLE, TY_CHAR) + call ic_gstr (ic, "function", Memc[str], SZ_LINE) + call sprintf (Memc[msg], SZ_LINE+IC_SZSAMPLE, + "%s %s %d \"%s\" %d %d %g %g %g %b") + call pargstr (cmd) + call pargstr (Memc[str]) + call pargi (IC_ORDER(ic)) + call pargstr (Memc[IC_SAMPLE(ic)]) + call pargi (IC_NAVERAGE(ic)) + call pargi (IC_NITERATE(ic)) + call pargr (IC_LOW(ic)) + call pargr (IC_HIGH(ic)) + call pargr (IC_GROW(ic)) + call pargi (IC_MARKREJ(ic)) + if (GP_UIFNAME(IC_GP(ic)) != EOS) + call gmsg (IC_GP(ic), "icfit", Memc[msg]) + + if (GP_UIFNAME(IC_GP(ic)) != EOS) { + if (streq (Memc[IC_HELP(ic)], IC_DEFHELP)) + call strcpy (IC_DEFHTML, Memc[IC_HELP(ic)], SZ_LINE) + } + + case GRAPH: + call sprintf (Memc[str], SZ_LINE, "graph %c %c %c") + call pargi ('h'+IC_GKEY(ic)-1) + call pargi (IC_AXES(ic,IC_GKEY(ic),1)) + call pargi (IC_AXES(ic,IC_GKEY(ic),2)) + if (GP_UIFNAME(IC_GP(ic)) != EOS) + call gmsg (IC_GP(ic), "icfit", Memc[str]) + + case WCS: + call ggview (IC_GP(ic), vx1, vx2, vy1, vy2) + call ggwind (IC_GP(ic), wx1, wx2, wy1, wy2) + call sprintf (Memc[str], SZ_LINE, "wcs %g %g %g %g %g %g %g %g") + call pargr (vx1) + call pargr (vx2) + call pargr (vy1) + call pargr (vy2) + call pargr (wx1) + call pargr (wx2) + call pargr (wy1) + call pargr (wy2) + if (GP_UIFNAME(IC_GP(ic)) != EOS) + call gmsg (IC_GP(ic), "icfit", Memc[str]) + + case REFIT: + if (GP_UIFNAME(IC_GP(ic)) != EOS) + call gmsg (IC_GP(ic), "icrefit", cmd) + + case HELP: + if (GP_UIFNAME(IC_GP(ic)) != EOS) + call ic_help (ic) + else + call gpagefile (IC_GP(ic), Memc[IC_HELP(ic)], IC_PROMPT) + } + + call sfree (sp) +end + + +# IC_HELP - Send help to GUI + +procedure ic_help (ic) + +pointer ic #I ICFIT pointer + +int i, fd, len_str, open(), getline() +pointer line, help +errchk open() + +begin + len_str = 10 * SZ_LINE + call calloc (help, len_str, TY_CHAR) + line = help + + fd = open (Memc[IC_HELP(ic)], READ_ONLY, TEXT_FILE) + while (getline (fd, Memc[line]) != EOF) { + for (; Memc[line]!=EOS; line=line+1) + ; + i = line - help + if (i + SZ_LINE > len_str) { + len_str = len_str + 10 * SZ_LINE + call realloc (help, len_str, TY_CHAR) + line = help + i + } + } + call close (fd) + + # Send results to GUI. + call gmsg (IC_GP(ic), "ichelp", Memc[help]) + + call mfree (help, TY_CHAR) +end diff --git a/pkg/xtools/icfit/icguishow.gx b/pkg/xtools/icfit/icguishow.gx new file mode 100644 index 00000000..30df5f4d --- /dev/null +++ b/pkg/xtools/icfit/icguishow.gx @@ -0,0 +1,86 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <gset.h> +include <gio.h> +include "icfit.h" +include "names.h" + +define CMDS "|show|vshow|xyshow|errors|" + +define SHOW 1 # Show information +define VSHOW 2 # Show verbose information +define XYSHOW 3 # Show points +define ERRORS 4 # Show errors + +# IC_GUISHOW -- GUI show. +# +# Note there is currently an interface violation to determine if the graphics +# stream is connected to a GUI. + +procedure ic_guishow$t (ic, cmd, cv, x, y, wts, npts) + +pointer ic #I ICFIT pointer +char cmd[ARB] #I Command +pointer cv #I CURFIT pointer for error listing +PIXEL x[npts], y[npts], wts[npts] #I Data arrays +int npts #I Number of data points + +int ncmd, deact, fd +pointer sp, str, msg +int strdic(), nscan(), stropen(), open() +errchk stropen, open, ic_fshow, ic_fvshow$t, ic_fxyshow$t, ic_ferrors$t + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Scan the command. + call sscan (cmd) + call gargwrd (Memc[str], SZ_LINE) + ncmd = strdic (Memc[str], Memc[str], SZ_LINE, CMDS) + call gargwrd (Memc[str], SZ_LINE) + + iferr { + # Setup the output. + deact = NO + msg = NULL + + if (nscan() == 1) { + if (GP_UIFNAME(IC_GP(ic)) != EOS) { + call malloc (msg, 100000, TY_CHAR) + fd = stropen (Memc[msg], 100000, WRITE_ONLY) + } else { + fd = open ("STDOUT", APPEND, TEXT_FILE) + call gdeactivate (IC_GP(ic), AW_CLEAR) + deact = YES + } + } else + fd = open (Memc[str], APPEND, TEXT_FILE) + + # Write the results to the output. + switch (ncmd) { + case SHOW: + call ic_fshow (ic, fd) + case VSHOW: + call ic_fvshow$t (ic, cv, x, y, wts, npts, fd) + case XYSHOW: + call ic_fxyshow$t (ic, cv, x, y, wts, npts, fd) + case ERRORS: + call ic_fshow (ic, fd) + call ic_ferrors$t (ic, cv, x, y, wts, npts, fd) + } + + # Flush the output. + call close (fd) + if (msg != NULL) + call gmsg (IC_GP(ic), "icshow", Memc[msg]) + } then + call erract (EA_WARN) + + if (msg != NULL) + call mfree (msg, TY_CHAR) + if (deact == YES) + call greactivate (IC_GP(ic), AW_PAUSE) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icguishowd.x b/pkg/xtools/icfit/icguishowd.x new file mode 100644 index 00000000..dee7401d --- /dev/null +++ b/pkg/xtools/icfit/icguishowd.x @@ -0,0 +1,86 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <gset.h> +include <gio.h> +include "icfit.h" +include "names.h" + +define CMDS "|show|vshow|xyshow|errors|" + +define SHOW 1 # Show information +define VSHOW 2 # Show verbose information +define XYSHOW 3 # Show points +define ERRORS 4 # Show errors + +# IC_GUISHOW -- GUI show. +# +# Note there is currently an interface violation to determine if the graphics +# stream is connected to a GUI. + +procedure ic_guishowd (ic, cmd, cv, x, y, wts, npts) + +pointer ic #I ICFIT pointer +char cmd[ARB] #I Command +pointer cv #I CURFIT pointer for error listing +double x[npts], y[npts], wts[npts] #I Data arrays +int npts #I Number of data points + +int ncmd, deact, fd +pointer sp, str, msg +int strdic(), nscan(), stropen(), open() +errchk stropen, open, ic_fshow, ic_fvshowd, ic_fxyshowd, ic_ferrorsd + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Scan the command. + call sscan (cmd) + call gargwrd (Memc[str], SZ_LINE) + ncmd = strdic (Memc[str], Memc[str], SZ_LINE, CMDS) + call gargwrd (Memc[str], SZ_LINE) + + iferr { + # Setup the output. + deact = NO + msg = NULL + + if (nscan() == 1) { + if (GP_UIFNAME(IC_GP(ic)) != EOS) { + call malloc (msg, 100000, TY_CHAR) + fd = stropen (Memc[msg], 100000, WRITE_ONLY) + } else { + fd = open ("STDOUT", APPEND, TEXT_FILE) + call gdeactivate (IC_GP(ic), AW_CLEAR) + deact = YES + } + } else + fd = open (Memc[str], APPEND, TEXT_FILE) + + # Write the results to the output. + switch (ncmd) { + case SHOW: + call ic_fshow (ic, fd) + case VSHOW: + call ic_fvshowd (ic, cv, x, y, wts, npts, fd) + case XYSHOW: + call ic_fxyshowd (ic, cv, x, y, wts, npts, fd) + case ERRORS: + call ic_fshow (ic, fd) + call ic_ferrorsd (ic, cv, x, y, wts, npts, fd) + } + + # Flush the output. + call close (fd) + if (msg != NULL) + call gmsg (IC_GP(ic), "icshow", Memc[msg]) + } then + call erract (EA_WARN) + + if (msg != NULL) + call mfree (msg, TY_CHAR) + if (deact == YES) + call greactivate (IC_GP(ic), AW_PAUSE) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icguishowr.x b/pkg/xtools/icfit/icguishowr.x new file mode 100644 index 00000000..f16a957e --- /dev/null +++ b/pkg/xtools/icfit/icguishowr.x @@ -0,0 +1,86 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <gset.h> +include <gio.h> +include "icfit.h" +include "names.h" + +define CMDS "|show|vshow|xyshow|errors|" + +define SHOW 1 # Show information +define VSHOW 2 # Show verbose information +define XYSHOW 3 # Show points +define ERRORS 4 # Show errors + +# IC_GUISHOW -- GUI show. +# +# Note there is currently an interface violation to determine if the graphics +# stream is connected to a GUI. + +procedure ic_guishowr (ic, cmd, cv, x, y, wts, npts) + +pointer ic #I ICFIT pointer +char cmd[ARB] #I Command +pointer cv #I CURFIT pointer for error listing +real x[npts], y[npts], wts[npts] #I Data arrays +int npts #I Number of data points + +int ncmd, deact, fd +pointer sp, str, msg +int strdic(), nscan(), stropen(), open() +errchk stropen, open, ic_fshow, ic_fvshowr, ic_fxyshowr, ic_ferrorsr + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Scan the command. + call sscan (cmd) + call gargwrd (Memc[str], SZ_LINE) + ncmd = strdic (Memc[str], Memc[str], SZ_LINE, CMDS) + call gargwrd (Memc[str], SZ_LINE) + + iferr { + # Setup the output. + deact = NO + msg = NULL + + if (nscan() == 1) { + if (GP_UIFNAME(IC_GP(ic)) != EOS) { + call malloc (msg, 100000, TY_CHAR) + fd = stropen (Memc[msg], 100000, WRITE_ONLY) + } else { + fd = open ("STDOUT", APPEND, TEXT_FILE) + call gdeactivate (IC_GP(ic), AW_CLEAR) + deact = YES + } + } else + fd = open (Memc[str], APPEND, TEXT_FILE) + + # Write the results to the output. + switch (ncmd) { + case SHOW: + call ic_fshow (ic, fd) + case VSHOW: + call ic_fvshowr (ic, cv, x, y, wts, npts, fd) + case XYSHOW: + call ic_fxyshowr (ic, cv, x, y, wts, npts, fd) + case ERRORS: + call ic_fshow (ic, fd) + call ic_ferrorsr (ic, cv, x, y, wts, npts, fd) + } + + # Flush the output. + call close (fd) + if (msg != NULL) + call gmsg (IC_GP(ic), "icshow", Memc[msg]) + } then + call erract (EA_WARN) + + if (msg != NULL) + call mfree (msg, TY_CHAR) + if (deact == YES) + call greactivate (IC_GP(ic), AW_PAUSE) + call sfree (sp) +end diff --git a/pkg/xtools/icfit/icgundelete.gx b/pkg/xtools/icfit/icgundelete.gx new file mode 100644 index 00000000..c997ccd0 --- /dev/null +++ b/pkg/xtools/icfit/icgundelete.gx @@ -0,0 +1,93 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_UNDELETE -- Undelete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_undelete$t (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +PIXEL x[npts], y[npts] # Data points +PIXEL wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +pointer sp, xout, yout + +int gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + call icg_axes$t (ic, gt, cv, 1, x, y, Mem$t[xout], npts) + call icg_axes$t (ic, gt, cv, 2, x, y, Mem$t[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_u1$t (ic, gp, Mem$t[xout], Mem$t[yout], wts, userwts, + npts, wx, wy) + else + call icg_u1$t (ic, gp, Mem$t[yout], Mem$t[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_U1 -- Do the actual undelete. + +procedure icg_u1$t (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +PIXEL x[npts], y[npts] # Data points +PIXEL wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] != 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Unmark the deleted point and reset the weight. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gseti (gp, G_PMLTYPE, GL_CLEAR) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + call gseti (gp, G_PMLTYPE, GL_SOLID) + call gline (gp, real (x[j]), real (y[j]), real (x[j]), real (y[j])) + wts[j] = userwts[j] + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icgundeleted.x b/pkg/xtools/icfit/icgundeleted.x new file mode 100644 index 00000000..df295a92 --- /dev/null +++ b/pkg/xtools/icfit/icgundeleted.x @@ -0,0 +1,93 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_UNDELETE -- Undelete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_undeleted (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +double x[npts], y[npts] # Data points +double wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +pointer sp, xout, yout + +int gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + call icg_axesd (ic, gt, cv, 1, x, y, Memd[xout], npts) + call icg_axesd (ic, gt, cv, 2, x, y, Memd[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_u1d (ic, gp, Memd[xout], Memd[yout], wts, userwts, + npts, wx, wy) + else + call icg_u1d (ic, gp, Memd[yout], Memd[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_U1 -- Do the actual undelete. + +procedure icg_u1d (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +double x[npts], y[npts] # Data points +double wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] != 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Unmark the deleted point and reset the weight. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gseti (gp, G_PMLTYPE, GL_CLEAR) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + call gseti (gp, G_PMLTYPE, GL_SOLID) + call gline (gp, real (x[j]), real (y[j]), real (x[j]), real (y[j])) + wts[j] = userwts[j] + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icgundeleter.x b/pkg/xtools/icfit/icgundeleter.x new file mode 100644 index 00000000..a1db4dca --- /dev/null +++ b/pkg/xtools/icfit/icgundeleter.x @@ -0,0 +1,93 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <gset.h> +include <mach.h> +include <pkg/gtools.h> +include "icfit.h" + +define MSIZE 2. # Mark size + +# ICG_UNDELETE -- Undelete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure icg_undeleter (ic, gp, gt, cv, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +real x[npts], y[npts] # Data points +real wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +pointer sp, xout, yout + +int gt_geti() + +begin + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + call icg_axesr (ic, gt, cv, 1, x, y, Memr[xout], npts) + call icg_axesr (ic, gt, cv, 2, x, y, Memr[yout], npts) + + if (gt_geti (gt, GTTRANSPOSE) == NO) + call icg_u1r (ic, gp, Memr[xout], Memr[yout], wts, userwts, + npts, wx, wy) + else + call icg_u1r (ic, gp, Memr[yout], Memr[xout], wts, userwts, + npts, wy, wx) + + call sfree (sp) +end + + +# ICG_U1 -- Do the actual undelete. + +procedure icg_u1r (ic, gp, x, y, wts, userwts, npts, wx, wy) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +real x[npts], y[npts] # Data points +real wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +real wx, wy # Position to be nearest + +int i, j +real x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + + call gctran (gp, wx, wy, wx, wy, 1, 0) + + # Search for nearest point to a point with zero weight. + + r2min = MAX_REAL + do i = 1, npts { + if (wts[i] != 0.) + next + + call gctran (gp, real (x[i]), real (y[i]), x0, y0, 1, 0) + + r2 = (x0 - wx) ** 2 + (y0 - wy) ** 2 + if (r2 < r2min) { + r2min = r2 + j = i + } + } + + # Unmark the deleted point and reset the weight. + + if (j != 0) { + call gscur (gp, real (x[j]), real (y[j])) + call gseti (gp, G_PMLTYPE, GL_CLEAR) + call gmark (gp, real (x[j]), real (y[j]), GM_CROSS, MSIZE, MSIZE) + call gseti (gp, G_PMLTYPE, GL_SOLID) + call gline (gp, real (x[j]), real (y[j]), real (x[j]), real (y[j])) + wts[j] = userwts[j] + IC_NEWWTS(ic) = YES + } +end diff --git a/pkg/xtools/icfit/icguser.x b/pkg/xtools/icfit/icguser.x new file mode 100644 index 00000000..58727343 --- /dev/null +++ b/pkg/xtools/icfit/icguser.x @@ -0,0 +1,19 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# ICG_USER -- User default action + +procedure icg_user (ic, gp, gt, cv, wx, wy, wcs, key, cmd) + +pointer ic # ICFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer cv # CURFIT pointer +real wx, wy # Cursor positions +int wcs # GIO WCS +int key # Cursor key +char cmd[ARB] # Cursor command + +begin + # Ring bell + call printf ("\07\n") +end diff --git a/pkg/xtools/icfit/iclist.gx b/pkg/xtools/icfit/iclist.gx new file mode 100644 index 00000000..73af2f4e --- /dev/null +++ b/pkg/xtools/icfit/iclist.gx @@ -0,0 +1,45 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" +include "names.h" + +# IC_LIST -- List X, Y, FIT, W. + +procedure ic_list$t (ic, cv, x, y, wts, npts, file) + +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 +char file[ARB] # Output file + +int i, fd, open() +PIXEL $tcveval() +errchk open() + +begin + # Open the output file. + fd = open (file, APPEND, TEXT_FILE) + + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call parg$t (x[i]) + call parg$t (y[i]) + call parg$t ($tcveval (cv, x[i])) + call parg$t (wts[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call parg$t (Mem$t[IC_XFIT(ic)+i-1]) + call parg$t (Mem$t[IC_YFIT(ic)+i-1]) + call parg$t ($tcveval (cv, Mem$t[IC_XFIT(ic)+i-1])) + call parg$t (Mem$t[IC_WTSFIT(ic)+i-1]) + } + } + + call close (fd) +end diff --git a/pkg/xtools/icfit/iclistd.x b/pkg/xtools/icfit/iclistd.x new file mode 100644 index 00000000..78eb6058 --- /dev/null +++ b/pkg/xtools/icfit/iclistd.x @@ -0,0 +1,45 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" +include "names.h" + +# IC_LIST -- List X, Y, FIT, W. + +procedure ic_listd (ic, cv, x, y, wts, npts, file) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +char file[ARB] # Output file + +int i, fd, open() +double dcveval() +errchk open() + +begin + # Open the output file. + fd = open (file, APPEND, TEXT_FILE) + + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargd (x[i]) + call pargd (y[i]) + call pargd (dcveval (cv, x[i])) + call pargd (wts[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargd (Memd[IC_XFIT(ic)+i-1]) + call pargd (Memd[IC_YFIT(ic)+i-1]) + call pargd (dcveval (cv, Memd[IC_XFIT(ic)+i-1])) + call pargd (Memd[IC_WTSFIT(ic)+i-1]) + } + } + + call close (fd) +end diff --git a/pkg/xtools/icfit/iclistr.x b/pkg/xtools/icfit/iclistr.x new file mode 100644 index 00000000..4e2b2c14 --- /dev/null +++ b/pkg/xtools/icfit/iclistr.x @@ -0,0 +1,45 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" +include "names.h" + +# IC_LIST -- List X, Y, FIT, W. + +procedure ic_listr (ic, cv, x, y, wts, npts, file) + +pointer ic # ICFIT pointer +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +char file[ARB] # Output file + +int i, fd, open() +real rcveval() +errchk open() + +begin + # Open the output file. + fd = open (file, APPEND, TEXT_FILE) + + if (npts == IC_NFIT(ic)) { + do i = 1, npts { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargr (x[i]) + call pargr (y[i]) + call pargr (rcveval (cv, x[i])) + call pargr (wts[i]) + } + } else { + do i = 1, IC_NFIT(ic) { + call fprintf (fd, "%8g %8g %8g %8g\n") + call pargr (Memr[IC_XFIT(ic)+i-1]) + call pargr (Memr[IC_YFIT(ic)+i-1]) + call pargr (rcveval (cv, Memr[IC_XFIT(ic)+i-1])) + call pargr (Memr[IC_WTSFIT(ic)+i-1]) + } + } + + call close (fd) +end diff --git a/pkg/xtools/icfit/icparams.x b/pkg/xtools/icfit/icparams.x new file mode 100644 index 00000000..da829ce0 --- /dev/null +++ b/pkg/xtools/icfit/icparams.x @@ -0,0 +1,388 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" + +define FUNCTIONS "|chebyshev|legendre|spline3|spline1|user|" + +# IC_OPEN -- Open ICFIT parameter structure. + +procedure ic_open (ic) + +pointer ic # ICFIT pointer + +begin + # Allocate memory for the package parameter structure. + call malloc (ic, IC_LENSTRUCT, TY_STRUCT) + call malloc (IC_SAMPLE(ic), IC_SZSAMPLE, TY_CHAR) + call malloc (IC_LABELS(ic,1), SZ_LINE, TY_CHAR) + call malloc (IC_LABELS(ic,2), SZ_LINE, TY_CHAR) + call malloc (IC_UNITS(ic,1), SZ_LINE, TY_CHAR) + call malloc (IC_UNITS(ic,2), SZ_LINE, TY_CHAR) + call malloc (IC_HELP(ic), SZ_FNAME, TY_CHAR) + + # Initialize parameters + IC_OVERPLOT(ic) = NO + IC_RG(ic) = NULL + IC_XFIT(ic) = NULL + IC_YFIT(ic) = NULL + IC_WTSFIT(ic) = NULL + IC_REJPTS(ic) = NULL + IC_GP(ic) = NULL + IC_GT(ic) = NULL + + # Set defaults + call ic_pstr (ic, "function", "spline3") + call ic_puti (ic, "order", 1) + call ic_pstr (ic, "sample", "*") + call ic_puti (ic, "naverage", 1) + call ic_puti (ic, "niterate", 0) + call ic_putr (ic, "low", 3.) + call ic_putr (ic, "high", 3.) + call ic_putr (ic, "grow", 0.) + call ic_puti (ic, "markrej", YES) + call ic_pstr (ic, "xlabel", "X") + call ic_pstr (ic, "ylabel", "Y") + call ic_pstr (ic, "xunits", "") + call ic_pstr (ic, "yunits", "") + call ic_puti (ic, "color", 1) + call ic_pstr (ic, "help", IC_DEFHELP) + call ic_puti (ic, "key", 1) + call ic_pkey (ic, 1, 'x', 'y') + call ic_pkey (ic, 2, 'y', 'x') + call ic_pkey (ic, 3, 'x', 'r') + call ic_pkey (ic, 4, 'x', 'd') + call ic_pkey (ic, 5, 'x', 'n') +end + + +# IC_COPY -- Copy an ICFIT structure. +# The output pointer must be allocated already. + +procedure ic_copy (icin, icout) + +pointer icin # Input ICFIT pointer to copy +pointer icout # Ouput ICFIT pointer + +begin + IC_FUNCTION(icout) = IC_FUNCTION(icin) + IC_ORDER(icout) = IC_ORDER(icin) + IC_NAVERAGE(icout) = IC_NAVERAGE(icin) + IC_NITERATE(icout) = IC_NITERATE(icin) + IC_XMIN(icout) = IC_XMIN(icin) + IC_XMAX(icout) = IC_XMAX(icin) + IC_LOW(icout) = IC_LOW(icin) + IC_HIGH(icout) = IC_HIGH(icin) + IC_GROW(icout) = IC_GROW(icin) + IC_COLOR(icout) = IC_COLOR(icin) + IC_MARKREJ(icout) = IC_MARKREJ(icin) + IC_GKEY(icout) = IC_GKEY(icin) + + call strcpy (Memc[IC_SAMPLE(icin)], Memc[IC_SAMPLE(icout)], IC_SZSAMPLE) + call strcpy (Memc[IC_LABELS(icin,1)], Memc[IC_LABELS(icout,1)], SZ_LINE) + call strcpy (Memc[IC_LABELS(icin,2)], Memc[IC_LABELS(icout,2)], SZ_LINE) + call strcpy (Memc[IC_UNITS(icin,1)], Memc[IC_UNITS(icout,1)], SZ_LINE) + call strcpy (Memc[IC_UNITS(icin,2)], Memc[IC_UNITS(icout,2)], SZ_LINE) + call strcpy (Memc[IC_HELP(icin)], Memc[IC_HELP(icout)], SZ_LINE) + + call amovi (IC_AXES(icin,1,1), IC_AXES(icout,1,1), 10) + + IC_RG(icout) = NULL + IC_XFIT(icout) = NULL + IC_YFIT(icout) = NULL + IC_WTSFIT(icout) = NULL + IC_REJPTS(icout) = NULL +end + + +# IC_CLOSER -- Close ICFIT parameter structure. + +procedure ic_closer (ic) + +pointer ic # ICFIT pointer + +begin + if (ic != NULL) { + # Free memory for the package parameter structure. + call rg_free (IC_RG(ic)) + call mfree (IC_XFIT(ic), TY_REAL) + call mfree (IC_YFIT(ic), TY_REAL) + call mfree (IC_WTSFIT(ic), TY_REAL) + call mfree (IC_REJPTS(ic), TY_INT) + call mfree (IC_SAMPLE(ic), TY_CHAR) + call mfree (IC_LABELS(ic,1), TY_CHAR) + call mfree (IC_LABELS(ic,2), TY_CHAR) + call mfree (IC_UNITS(ic,1), TY_CHAR) + call mfree (IC_UNITS(ic,2), TY_CHAR) + call mfree (IC_HELP(ic), TY_CHAR) + call mfree (ic, TY_STRUCT) + } +end + + +# IC_CLOSED -- Close ICFIT parameter structure. + +procedure ic_closed (ic) + +pointer ic # ICFIT pointer + +begin + if (ic != NULL) { + # Free memory for the package parameter structure. + call rg_free (IC_RG(ic)) + call mfree (IC_XFIT(ic), TY_DOUBLE) + call mfree (IC_YFIT(ic), TY_DOUBLE) + call mfree (IC_WTSFIT(ic), TY_DOUBLE) + call mfree (IC_REJPTS(ic), TY_INT) + call mfree (IC_SAMPLE(ic), TY_CHAR) + call mfree (IC_LABELS(ic,1), TY_CHAR) + call mfree (IC_LABELS(ic,2), TY_CHAR) + call mfree (IC_UNITS(ic,1), TY_CHAR) + call mfree (IC_UNITS(ic,2), TY_CHAR) + call mfree (IC_HELP(ic), TY_CHAR) + call mfree (ic, TY_STRUCT) + } +end + + +# IC_PSTR -- Put string valued parameters. + +procedure ic_pstr (ic, param, str) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be put +char str[ARB] # String value + +int i +pointer ptr + +int strdic() +bool streq() + +begin + if (streq (param, "sample")) + call strcpy (str, Memc[IC_SAMPLE(ic)], IC_SZSAMPLE) + else if (streq (param, "function")) { + call malloc (ptr, SZ_LINE, TY_CHAR) + i = strdic (str, Memc[ptr], SZ_LINE, FUNCTIONS) + if (i > 0) + IC_FUNCTION(ic) = i + call mfree (ptr, TY_CHAR) + } else if (streq (param, "xlabel")) + call strcpy (str, Memc[IC_LABELS(ic,1)], SZ_LINE) + else if (streq (param, "ylabel")) + call strcpy (str, Memc[IC_LABELS(ic,2)], SZ_LINE) + else if (streq (param, "xunits")) + call strcpy (str, Memc[IC_UNITS(ic,1)], SZ_LINE) + else if (streq (param, "yunits")) + call strcpy (str, Memc[IC_UNITS(ic,2)], SZ_LINE) + else if (streq (param, "help")) + call strcpy (str, Memc[IC_HELP(ic)], SZ_LINE) + else + call error (0, "ICFIT: Unknown parameter") + + call ic_gui (ic, "params") +end + + +# IC_PUTI -- Put integer valued parameters. + +procedure ic_puti (ic, param, ival) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be put +int ival # Integer value + +bool streq() + +begin + if (streq (param, "naverage")) + IC_NAVERAGE(ic) = ival + else if (streq (param, "order")) + IC_ORDER(ic) = max (1, ival) + else if (streq (param, "niterate")) + IC_NITERATE(ic) = ival + else if (streq (param, "key")) + IC_GKEY(ic) = ival + else if (streq (param, "color")) + IC_COLOR(ic) = ival + else if (streq (param, "markrej")) + IC_MARKREJ(ic) = ival + else + call error (0, "ICFIT: Unknown parameter") + + call ic_gui (ic, "params") +end + + +# IC_PKEY -- Put key parameters. +# Note the key types must be integers not characters. + +procedure ic_pkey (ic, key, xaxis, yaxis) + +pointer ic # ICFIT pointer +int key # Key to be defined +int xaxis # X axis type +int yaxis # Y axis type + +begin + if (key >= 1 && key <= 5) { + IC_AXES(ic, key, 1) = xaxis + IC_AXES(ic, key, 2) = yaxis + + if (key == IC_GKEY(ic)) + call ic_gui (ic, "graph") + } +end + + +# IC_GKEY -- Get key parameters. + +procedure ic_gkey (ic, key, xaxis, yaxis) + +pointer ic # ICFIT pointer +int key # Key to be gotten +int xaxis # X axis type +int yaxis # Y axis type + +begin + xaxis = IC_AXES(ic, key, 1) + yaxis = IC_AXES(ic, key, 2) +end + + +# IC_PUTR -- Put real valued parameters. + +procedure ic_putr (ic, param, rval) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be put +real rval # Real value + +bool streq() + +begin + if (streq (param, "xmin")) + IC_XMIN(ic) = rval + else if (streq (param, "xmax")) + IC_XMAX(ic) = rval + else if (streq (param, "low")) + IC_LOW(ic) = rval + else if (streq (param, "high")) + IC_HIGH(ic) = rval + else if (streq (param, "grow")) + IC_GROW(ic) = rval + else + call error (0, "ICFIT: Unknown parameter") + + call ic_gui (ic, "params") +end + + +# IC_GSTR -- Get string valued parameters. + +procedure ic_gstr (ic, param, str, maxchars) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be put +char str[maxchars] # String value +int maxchars # Maximum number of characters + +bool streq() + +begin + if (streq (param, "sample")) + call strcpy (Memc[IC_SAMPLE(ic)], str, maxchars) + else if (streq (param, "xlabel")) + call strcpy (Memc[IC_LABELS(ic,1)], str, maxchars) + else if (streq (param, "ylabel")) + call strcpy (Memc[IC_LABELS(ic,2)], str, maxchars) + else if (streq (param, "xunits")) + call strcpy (Memc[IC_UNITS(ic,1)], str, maxchars) + else if (streq (param, "yunits")) + call strcpy (Memc[IC_UNITS(ic,2)], str, maxchars) + else if (streq (param, "help")) + call strcpy (Memc[IC_HELP(ic)], str, maxchars) + else if (streq (param, "function")) { + switch (IC_FUNCTION(ic)) { + case 1: + call strcpy ("chebyshev", str, maxchars) + case 2: + call strcpy ("legendre", str, maxchars) + case 3: + call strcpy ("spline3", str, maxchars) + case 4: + call strcpy ("spline1", str, maxchars) + case 5: + call strcpy ("user", str, maxchars) + } + } else + call error (0, "ICFIT: Unknown parameter") +end + + +# IC_GETI -- Get integer valued parameters. + +int procedure ic_geti (ic, param) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be gotten + +bool streq() + +begin + if (streq (param, "naverage")) + return (IC_NAVERAGE(ic)) + else if (streq (param, "order")) + return (IC_ORDER(ic)) + else if (streq (param, "niterate")) + return (IC_NITERATE(ic)) + else if (streq (param, "key")) + return (IC_GKEY(ic)) + else if (streq (param, "nfit")) + return (IC_NFIT(ic)) + else if (streq (param, "nreject")) + return (IC_NREJECT(ic)) + else if (streq (param, "rejpts")) + return (IC_REJPTS(ic)) + else if (streq (param, "color")) + return (IC_COLOR(ic)) + else if (streq (param, "markrej")) + return (IC_MARKREJ(ic)) + else if (streq (param, "nmin")) { + switch (IC_FUNCTION(ic)) { + case 3: + return (IC_ORDER(ic) + 3) + case 4: + return (IC_ORDER(ic) + 1) + default: + return (IC_ORDER(ic)) + } + } + + call error (0, "ICFIT: Unknown parameter") +end + + +# IC_GETR -- Get real valued parameters. + +real procedure ic_getr (ic, param) + +pointer ic # ICFIT pointer +char param[ARB] # Parameter to be put + +bool streq() + +begin + if (streq (param, "xmin")) + return (IC_XMIN(ic)) + else if (streq (param, "xmax")) + return (IC_XMAX(ic)) + else if (streq (param, "low")) + return (IC_LOW(ic)) + else if (streq (param, "high")) + return (IC_HIGH(ic)) + else if (streq (param, "grow")) + return (IC_GROW(ic)) + + call error (0, "ICFIT: Unknown parameter") +end diff --git a/pkg/xtools/icfit/icreject.gx b/pkg/xtools/icfit/icreject.gx new file mode 100644 index 00000000..79965384 --- /dev/null +++ b/pkg/xtools/icfit/icreject.gx @@ -0,0 +1,57 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "names.h" + +# IC_REJECT -- Reject points with large residuals from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at low_reject*sigma and high_reject*sigma. Points outside the +# rejection threshold are rejected from the fit and flagged in the rejpts +# array. Finally, the remaining points are refit. + +procedure ic_reject$t (cv, x, y, w, rejpts, npts, low_reject, high_reject, + niterate, grow, nreject) + +pointer cv # Curve descriptor +PIXEL x[npts] # Input ordinates +PIXEL y[npts] # Input data values +PIXEL w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection threshold +int niterate # Number of rejection iterations +real grow # Rejection radius +int nreject # Number of points rejected + +int i, ierr, nit, newreject +errchk ic_deviant$t + +begin + # Initialize rejection. + nreject = 0 + call amovki (NO, rejpts, npts) + + if (niterate <= 0) + return + + # Find deviant points. If an error occurs reduce the number of + # iterations and start again. + iferr { + nit = 0 + do i = 1, niterate { + call ic_deviant$t (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + nit = nit + 1 + if (newreject == 0) + break + } + } then { + call $tcvfit (cv, x, y, w, npts, WTS_USER, ierr) + nreject = 0 + call amovki (NO, rejpts, npts) + do i = 1, nit + call ic_deviant$t (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + } +end diff --git a/pkg/xtools/icfit/icrejectd.x b/pkg/xtools/icfit/icrejectd.x new file mode 100644 index 00000000..36985923 --- /dev/null +++ b/pkg/xtools/icfit/icrejectd.x @@ -0,0 +1,57 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "names.h" + +# IC_REJECT -- Reject points with large residuals from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at low_reject*sigma and high_reject*sigma. Points outside the +# rejection threshold are rejected from the fit and flagged in the rejpts +# array. Finally, the remaining points are refit. + +procedure ic_rejectd (cv, x, y, w, rejpts, npts, low_reject, high_reject, + niterate, grow, nreject) + +pointer cv # Curve descriptor +double x[npts] # Input ordinates +double y[npts] # Input data values +double w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection threshold +int niterate # Number of rejection iterations +real grow # Rejection radius +int nreject # Number of points rejected + +int i, ierr, nit, newreject +errchk ic_deviantd + +begin + # Initialize rejection. + nreject = 0 + call amovki (NO, rejpts, npts) + + if (niterate <= 0) + return + + # Find deviant points. If an error occurs reduce the number of + # iterations and start again. + iferr { + nit = 0 + do i = 1, niterate { + call ic_deviantd (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + nit = nit + 1 + if (newreject == 0) + break + } + } then { + call dcvfit (cv, x, y, w, npts, WTS_USER, ierr) + nreject = 0 + call amovki (NO, rejpts, npts) + do i = 1, nit + call ic_deviantd (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + } +end diff --git a/pkg/xtools/icfit/icrejectr.x b/pkg/xtools/icfit/icrejectr.x new file mode 100644 index 00000000..2e344279 --- /dev/null +++ b/pkg/xtools/icfit/icrejectr.x @@ -0,0 +1,57 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <math/curfit.h> +include "names.h" + +# IC_REJECT -- Reject points with large residuals from the fit. +# +# The sigma of the fit residuals is calculated. The rejection thresholds +# are set at low_reject*sigma and high_reject*sigma. Points outside the +# rejection threshold are rejected from the fit and flagged in the rejpts +# array. Finally, the remaining points are refit. + +procedure ic_rejectr (cv, x, y, w, rejpts, npts, low_reject, high_reject, + niterate, grow, nreject) + +pointer cv # Curve descriptor +real x[npts] # Input ordinates +real y[npts] # Input data values +real w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +real low_reject, high_reject # Rejection threshold +int niterate # Number of rejection iterations +real grow # Rejection radius +int nreject # Number of points rejected + +int i, ierr, nit, newreject +errchk ic_deviantr + +begin + # Initialize rejection. + nreject = 0 + call amovki (NO, rejpts, npts) + + if (niterate <= 0) + return + + # Find deviant points. If an error occurs reduce the number of + # iterations and start again. + iferr { + nit = 0 + do i = 1, niterate { + call ic_deviantr (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + nit = nit + 1 + if (newreject == 0) + break + } + } then { + call rcvfit (cv, x, y, w, npts, WTS_USER, ierr) + nreject = 0 + call amovki (NO, rejpts, npts) + do i = 1, nit + call ic_deviantr (cv, x, y, w, rejpts, npts, low_reject, + high_reject, grow, YES, nreject, newreject) + } +end diff --git a/pkg/xtools/icfit/icshow.x b/pkg/xtools/icfit/icshow.x new file mode 100644 index 00000000..d39e85d5 --- /dev/null +++ b/pkg/xtools/icfit/icshow.x @@ -0,0 +1,21 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" + +# IC_SHOW -- Show the values of the parameters. + +procedure ic_show (ic, file, gt) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer gt # GTOOLS pointer + +int fd, open() +errchk open, ic_fshow + +begin + fd = open (file, APPEND, TEXT_FILE) + IC_GT(ic) = gt + call ic_fshow (ic, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icvshow.gx b/pkg/xtools/icfit/icvshow.gx new file mode 100644 index 00000000..f356cb14 --- /dev/null +++ b/pkg/xtools/icfit/icvshow.gx @@ -0,0 +1,48 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" + +# IC_VSHOW -- Show fit parameters in verbose mode. + +procedure ic_vshow$t (ic, file, cv, x, y, wts, npts, gt) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +PIXEL x[ARB] # Ordinates +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +int npts # Number of data points +pointer gt # Graphics tools pointer + +int fd, open() +errchk open, ic_fvshow$t + +begin + fd = open (file, APPEND, TEXT_FILE) + IC_GT(ic) = gt + call ic_fvshow$t (ic, cv, x, y, wts, npts, fd) + call close (fd) +end + + +# IC_XYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_xyshow$t (ic, file, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Pointer to curfit structure +PIXEL x[npts] # Array of x data values +PIXEL y[npts] # Array of y data values +PIXEL w[npts] # Array of weight data values +int npts # Number of data values + +int fd, open() +errchk open, ic_fxyshow$t + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_fxyshow$t (ic, cv, x, y, w, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icvshowd.x b/pkg/xtools/icfit/icvshowd.x new file mode 100644 index 00000000..45b7ae85 --- /dev/null +++ b/pkg/xtools/icfit/icvshowd.x @@ -0,0 +1,48 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" + +# IC_VSHOW -- Show fit parameters in verbose mode. + +procedure ic_vshowd (ic, file, cv, x, y, wts, npts, gt) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +double x[ARB] # Ordinates +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +pointer gt # Graphics tools pointer + +int fd, open() +errchk open, ic_fvshowd + +begin + fd = open (file, APPEND, TEXT_FILE) + IC_GT(ic) = gt + call ic_fvshowd (ic, cv, x, y, wts, npts, fd) + call close (fd) +end + + +# IC_XYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_xyshowd (ic, file, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Pointer to curfit structure +double x[npts] # Array of x data values +double y[npts] # Array of y data values +double w[npts] # Array of weight data values +int npts # Number of data values + +int fd, open() +errchk open, ic_fxyshowd + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_fxyshowd (ic, cv, x, y, w, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/icvshowr.x b/pkg/xtools/icfit/icvshowr.x new file mode 100644 index 00000000..6f846ec8 --- /dev/null +++ b/pkg/xtools/icfit/icvshowr.x @@ -0,0 +1,48 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "icfit.h" + +# IC_VSHOW -- Show fit parameters in verbose mode. + +procedure ic_vshowr (ic, file, cv, x, y, wts, npts, gt) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Curfit pointer +real x[ARB] # Ordinates +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +pointer gt # Graphics tools pointer + +int fd, open() +errchk open, ic_fvshowr + +begin + fd = open (file, APPEND, TEXT_FILE) + IC_GT(ic) = gt + call ic_fvshowr (ic, cv, x, y, wts, npts, fd) + call close (fd) +end + + +# IC_XYSHOW -- List data as x, y, fit, weight lines on output. + +procedure ic_xyshowr (ic, file, cv, x, y, w, npts) + +pointer ic # ICFIT pointer +char file[ARB] # Output file +pointer cv # Pointer to curfit structure +real x[npts] # Array of x data values +real y[npts] # Array of y data values +real w[npts] # Array of weight data values +int npts # Number of data values + +int fd, open() +errchk open, ic_fxyshowr + +begin + fd = open (file, APPEND, TEXT_FILE) + call ic_fxyshowr (ic, cv, x, y, w, npts, fd) + call close (fd) +end diff --git a/pkg/xtools/icfit/mkpkg b/pkg/xtools/icfit/mkpkg new file mode 100644 index 00000000..9ad67b9e --- /dev/null +++ b/pkg/xtools/icfit/mkpkg @@ -0,0 +1,85 @@ +# ICFIT package. + +$checkout libxtools.a lib$ +$update libxtools.a +$checkin libxtools.a lib$ +$exit + +generic: + $set GEN = "$$generic -k -t rd" + $ifolder (iccleanr.x, icclean.gx) $(GEN) icclean.gx $endif + $ifolder (icdeviantr.x, icdeviant.gx) $(GEN) icdeviant.gx $endif + $ifolder (icerrorsr.x, icerrors.gx) $(GEN) icerrors.gx $endif + $ifolder (icferrorsr.x, icferrors.gx) $(GEN) icferrors.gx $endif + $ifolder (icfitr.x, icfit.gx) $(GEN) icfit.gx $endif + $ifolder (icgaddr.x, icgadd.gx) $(GEN) icgadd.gx $endif + $ifolder (icgcolonr.x, icgcolon.gx) $(GEN) icgcolon.gx $endif + $ifolder (icgdeleter.x, icgdelete.gx) $(GEN) icgdelete.gx $endif + $ifolder (icgfitr.x, icgfit.gx) $(GEN) icgfit.gx $endif + $ifolder (icgaxesr.x, icgaxes.gx) $(GEN) icgaxes.gx $endif + $ifolder (icggraphr.x, icggraph.gx) $(GEN) icggraph.gx $endif + $ifolder (icgnearestr.x, icgnearest.gx) $(GEN) icgnearest.gx $endif + $ifolder (icgparamsr.x, icgparams.gx) $(GEN) icgparams.gx $endif + $ifolder (icgsampler.x, icgsample.gx) $(GEN) icgsample.gx $endif + $ifolder (icgundeleter.x, icgundelete.gx) $(GEN) icgundelete.gx $endif + $ifolder (icguaxesr.x, icguaxes.gx) $(GEN) icguaxes.gx $endif + $ifolder (icguishowr.x, icguishow.gx) $(GEN) icguishow.gx $endif + $ifolder (icrejectr.x, icreject.gx) $(GEN) icreject.gx $endif + $ifolder (icdosetupr.x, icdosetup.gx) $(GEN) icdosetup.gx $endif + $ifolder (icvshowr.x, icvshow.gx) $(GEN) icvshow.gx $endif + $ifolder (icfvshowr.x, icfvshow.gx) $(GEN) icfvshow.gx $endif + ; + +libxtools.a: + $ifeq (USE_GENERIC, yes) $call generic $endif + + iccleand.x icfit.h names.h <pkg/rg.h> + iccleanr.x icfit.h names.h <pkg/rg.h> + icdeviantd.x names.h <mach.h> <math/curfit.h> + icdeviantr.x names.h <mach.h> <math/curfit.h> + icdosetupd.x icfit.h names.h <math/curfit.h> + icdosetupr.x icfit.h names.h <math/curfit.h> + icerrorsd.x names.h + icerrorsr.x names.h + icferrorsd.x icfit.h names.h <math/curfit.h> + icferrorsr.x icfit.h names.h <math/curfit.h> + icfitd.x icfit.h names.h <error.h> <math/curfit.h> + icfitr.x icfit.h names.h <error.h> <math/curfit.h> + icfshow.x icfit.h <pkg/gtools.h> + icfvshowd.x icfit.h names.h <math/curfit.h> + icfvshowr.x icfit.h names.h <math/curfit.h> + icgaddd.x <gset.h> + icgaddr.x <gset.h> + icgaxesd.x icfit.h names.h <pkg/gtools.h> + icgaxesr.x icfit.h names.h <pkg/gtools.h> + icgcolond.x icfit.h names.h <error.h> <pkg/gtools.h> + icgcolonr.x icfit.h names.h <error.h> <pkg/gtools.h> + icgdeleted.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> + icgdeleter.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> + icgfitd.x icfit.h names.h <error.h> <pkg/gtools.h> + icgfitr.x icfit.h names.h <error.h> <pkg/gtools.h> + icggraphd.x icfit.h names.h <gset.h> <pkg/gtools.h> + icggraphr.x icfit.h names.h <gset.h> <pkg/gtools.h> + icgnearestd.x icfit.h <mach.h> <pkg/gtools.h> + icgnearestr.x icfit.h <mach.h> <pkg/gtools.h> + icgparamsd.x icfit.h names.h <pkg/gtools.h> + icgparamsr.x icfit.h names.h <pkg/gtools.h> + icgsampled.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> <pkg/rg.h> + icgsampler.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> <pkg/rg.h> + icguaxesd.x + icguaxesr.x + icgui.x icfit.h <gio.h> <gset.h> + icguishowd.x icfit.h names.h <error.h> <gio.h> <gset.h> + icguishowr.x icfit.h names.h <error.h> <gio.h> <gset.h> + icgundeleted.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> + icgundeleter.x icfit.h <gset.h> <mach.h> <pkg/gtools.h> + icguser.x + iclistd.x icfit.h names.h + iclistr.x icfit.h names.h + icparams.x icfit.h + icrejectd.x names.h <math/curfit.h> + icrejectr.x names.h <math/curfit.h> + icshow.x icfit.h + icvshowd.x icfit.h + icvshowr.x icfit.h + ; diff --git a/pkg/xtools/icfit/names.h b/pkg/xtools/icfit/names.h new file mode 100644 index 00000000..6fce9473 --- /dev/null +++ b/pkg/xtools/icfit/names.h @@ -0,0 +1,21 @@ +# NAMES -- Map generic names to external names. + +define ic_cleanr ic_clean +define ic_fitr ic_fit +define icg_fitr icg_fit +define ic_freer ic_free +define ic_errorsr ic_errors + +define rcvcoeff cvcoeff +define rcverrors cverrors +define rcveval cveval +define rcvfit cvfit +define rcvfree cvfree +define rcvinit cvinit +define rcvrefit cvrefit +define rcvrject cvrject +define rcvsolve cvsolve +define rcvstati cvstati +define rcvvector cvvector +define rcvsave cvsave +define rcvuserfnc cvuserfnc |