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/inlfit | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/xtools/inlfit')
98 files changed, 10539 insertions, 0 deletions
diff --git a/pkg/xtools/inlfit/README b/pkg/xtools/inlfit/README new file mode 100644 index 00000000..56d72836 --- /dev/null +++ b/pkg/xtools/inlfit/README @@ -0,0 +1,165 @@ + THE INLFIT PACKAGE + +This subdirectory contains the routines of the interactive non-linear +least squares fitting package INLFIT. This package is layered on the NLFIT +package in MATH. NLFIT uses the Levenberg-Marquardt method to solve for +the parameters of a user specified non-linear equation. The user must supply +two routines. The first routine evaluates the function in terms of its +parameters. The second routine evaluates the function and its derivatives +in terms of its parameters. The user must also supply initial guesses for +the parameters and parameter increments, the list of parameters to be +varied during the fitting process, a fitting tolerance, and the maximum +number of iterations. + +The entry points into the INLFIT package are listed below. + + ininit - Initialize the fitting routines + inget - Get the value of an INLFIT parameter + input - Store the value of an INLFIT parameter + ingkey - Get the value of an INLFIT graphics/axis parameter + inpkey - Store the value of an INLFIT graphics/axis parameter + infit - Fit the function non-interactively + ingfit - Fit the function interactively + inerrors - Compute the errors of the fit + infree - Free memory allocated by ininit + +The calling sequences for the above routines are listed below. The [iprd] +stand for integer, pointer, real and double precision versions of each +routine respectively. [str] stands for string. + + in_init[rd] (in, address(func), address(dfunc), param, dparam, + nparams, plist, nfparams) + [irdp]val = in_get[irdp] (in, param) + in_gstr (in, params, str, maxch) + in_put[irdp] (in, param, val) + in_pstr (in, param, str) + in_gkey (in, key, axis, type, varnum) + in_pkey (in, key, axis, type, varnum) + in_fit[rd] (in, nl, x, y, wts, npts, nvars, wtflag, stat) + ing_fit[rd] (in, gp, cursor, gt, nl, x, y, wts, names, npts, + nvars, len_names, wtflag, stat) + in_errors[rd] (in, nl, x, y, wts, npts, nvars, variance, + chisqr, scatter, rms, errors) + in_free[rd] (in) + + +The user supplied functions fnc and dfnc have the following calling +sequences. + + fnc (x, nvars, nparams, nparams, zfit) + dfnc (x, nvars, params, dparams, nparams, zfit, derivs) + +The addresses of the user supplied functions can be obtained with a call +to locpr as follows. + + address = locpr (fnc) + +The user definition for the INLFIT package can be found in the file +lib$pkg/inlfit.h and can be made available to user applications programs +with the statement "include <pkg/inlfit.h>". + +The permitted values for the param argument are the following. + +# Integer valued parameters (in_geti, in_puti) + +define INLFUNCTION # Fitting function +define INLDERIVATIVE # Fitting function derivatives +define INLNPARAMS # Total number of parameters +define INLNFPARAMS # Number of fitting parameters +define INLNVARS # Number of variables +define INLNPTS # Number of variables +define INLMAXITER # Max. number of iterations +define INLNREJECT # Number of rejection iterations +define INLNREJPTS # Number of rejected points +define INLUAXES # User plot function +define INLUCOLON # User colon function +define INLUFIT # User fit function +define INLOVERPLOT # Overplot next plot ? +define INLPLOTFIT # Overplot fit ? +define INLFITERROR # Error fit code +define INLGKEY # Graph key + + +# Real/double valued parameters (in_get[rd], in_put[rd]) + +define INLTOLERANCE # Tolerance of convergence +define INLLOW # Low rejection value +define INLHIGH # High rejection value +define INLGROW # Rejection growing radius + + +# Pointer valued parameters (in_getp, in_getp) + +define INLNL # NLFIT descriptor +define INLPARAM # Parameter vector +define INLDPARAM # Parameter change vector +define INLPLIST # Parameter list +define INLREJPTS # Rejected points +define INLXMIN # Minimum value for curve +define INLXMAX # Maximum value for curve +define INLSFLOAT # Floating point substructure +define INLSGAXES # Graphics substructure + + +# String valued parameters (in_gstr, in_pstr) + +define INLLABELS # standard axis labels +define INLUNITS # standard axis units +define INLFLABELS # Function labels +define INLFUNITS # Function units +define INLPLABELS # Parameter labels +define INLPUNITS # Parameter units +define INLVLABELS # Variable labels +define INLVUNITS # Variable units +define INLUSERLABELS # User plot labels +define INLUSERUNITS # User plot units +define INLHELP # Help file name +define INLPROMPT # Help prompt + + +The permitted values for the key argument are the following. + +# in_gkey, in_pkey + +define KEY_FUNCTION # Function +define KEY_FIT # Fit +define KEY_RESIDUALS # Residuals +define KEY_RATIO # Ratio +define KEY_NONLINEAR # Non-linear part +define KEY_VARIABLE # Variable (user or default) +define KEY_UAXIS # User plot function +define KEY_MIN # Min. key type +define KEY_MAX # Max. key type + +The permitted values for the axis argument are the following. + +# in_gkey, in_pkey + +define INLXAXIS # X axis +define INLYAXIS # Y axis + + +The permitted values of the weights flag argument wtflag input to +in_fit[rd] or in_gfit[rd], and the stat argument returned by in_fit[rd] +or in_gfit[rd] are defined in lib$math/nlfit.h. They can be included in +the user's application with the statement "include <math/nlfit.h>". +The values are listed below. + +# Permitted values for wtflag + +define WTS_USER # User supplied weights +define WTS_UNIFORM # Uniform weighting +define WTS_CHISQ # Chi-squared weighting +define WTS_SCATTER # Weights include computed scatter term + +# Permitted values for stat + +define DONE # Solution converged +define SINGULAR # Singular solution +define NO_DEG_FREEDOM # Too few points +define NOT_DONE # Solution did not converge. + +Note the pointer to the NLFIT structure nl is returned by the in_fit[rd] +and in_gfit[rd] routines and input to the in_errors[rd] routine. This +pointer must be freed separately with a call to nl_free when the fitting +process terminates. diff --git a/pkg/xtools/inlfit/incopy.gx b/pkg/xtools/inlfit/incopy.gx new file mode 100644 index 00000000..8165cf6d --- /dev/null +++ b/pkg/xtools/inlfit/incopy.gx @@ -0,0 +1,126 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_COPY -- Copy INLFIT parameter structure, into another. The destination +# structure is allocated if the pointer is NULL. + +procedure in_copy$t (insrc, indst) + +pointer insrc # source INLFIT pointer +pointer indst # destination INLFIT pointer + +int in_geti() +PIXEL in_get$t() +pointer in_getp() + +begin +# # Debug. +# call eprintf ( +# "in_copy: insrc=%d, indst=%d\n") +# call pargi (insrc) +# call pargi (indst) + + # Allocate destination. + if (indst == NULL) { + + # Allocate structure memory. + call malloc (indst, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (indst), in_geti (insrc, INLNPARAMS), + TY_PIXEL) + call malloc (IN_DPARAM (indst), in_geti (insrc, INLNPARAMS), + TY_PIXEL) + call malloc (IN_PLIST (indst), in_geti (insrc, INLNPARAMS), + TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_HELP (indst), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT (indst), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (indst), LEN_INLFLOAT, TY_PIXEL) + call malloc (IN_SGAXES (indst), INLNGKEYS * LEN_INLGRAPH, TY_INT) + } + + # Copy integer parameters. + call in_puti (indst, INLFUNCTION, in_geti (insrc, INLFUNCTION)) + call in_puti (indst, INLDERIVATIVE, in_geti (insrc, INLDERIVATIVE)) + call in_puti (indst, INLNPARAMS, in_geti (insrc, INLNPARAMS)) + call in_puti (indst, INLNFPARAMS, in_geti (insrc, INLNFPARAMS)) + + # Copy parameter values, changes, and list. + call amov$t (Mem$t[in_getp (insrc, INLPARAM)], + Mem$t[in_getp (indst, INLPARAM)], + in_geti (insrc, INLNPARAMS)) + call amov$t (Mem$t[in_getp (insrc, INLDPARAM)], + Mem$t[in_getp (indst, INLDPARAM)], + in_geti (insrc, INLNPARAMS)) + call amovi (Memi[in_getp (insrc, INLPLIST)], + Memi[in_getp (indst, INLPLIST)], + in_geti (insrc, INLNPARAMS)) + + # Copy defaults. + call in_put$t (indst, INLTOLERANCE, in_get$t (insrc, INLTOLERANCE)) + call in_puti (indst, INLMAXITER, in_geti (insrc, INLMAXITER)) + call in_puti (indst, INLNREJECT, in_geti (insrc, INLNREJECT)) + call in_put$t (indst, INLLOW, in_get$t (insrc, INLLOW)) + call in_put$t (indst, INLHIGH, in_get$t (insrc, INLHIGH)) + call in_put$t (indst, INLGROW, in_get$t (insrc, INLGROW)) + + # Copy character strings. + call in_pstr (indst, INLLABELS, Memc[IN_LABELS (insrc)]) + call in_pstr (indst, INLUNITS, Memc[IN_UNITS (insrc)]) + call in_pstr (indst, INLFLABELS, Memc[IN_FLABELS (insrc)]) + call in_pstr (indst, INLFUNITS, Memc[IN_FUNITS (insrc)]) + call in_pstr (indst, INLPLABELS, Memc[IN_PLABELS (insrc)]) + call in_pstr (indst, INLPUNITS, Memc[IN_PUNITS (insrc)]) + call in_pstr (indst, INLVLABELS, Memc[IN_VLABELS (insrc)]) + call in_pstr (indst, INLVUNITS, Memc[IN_VUNITS (insrc)]) + call in_pstr (indst, INLUSERLABELS, Memc[IN_USERLABELS (insrc)]) + call in_pstr (indst, INLUSERUNITS, Memc[IN_USERUNITS (insrc)]) + call in_pstr (indst, INLHELP, Memc[IN_HELP (insrc)]) + call in_pstr (indst, INLPROMPT, Memc[IN_PROMPT (insrc)]) + + # Copy user defined functions. + call in_puti (indst, INLUAXES, in_geti (insrc, INLUAXES)) + call in_puti (indst, INLUCOLON, in_geti (insrc, INLUCOLON)) + call in_puti (indst, INLUFIT, in_geti (insrc, INLUFIT)) + + # Copy graph key, and axes. + call in_puti (indst, INLGKEY, in_geti (insrc, INLGKEY)) + call amovi (IN_SGAXES (insrc), IN_SGAXES (indst), + INLNGKEYS * LEN_INLGRAPH) + + # Copy flags and counters. + call in_puti (indst, INLOVERPLOT, in_geti (insrc, INLOVERPLOT)) + call in_puti (indst, INLPLOTFIT, in_geti (insrc, INLPLOTFIT)) + call in_puti (indst, INLNREJPTS, in_geti (insrc, INLNREJPTS)) + + # Initialize number of points and variables. + call in_puti (indst, INLNVARS, 0) + call in_puti (indst, INLNPTS, 0) + + # Reallocate rejected point list and limit values. + call in_bfinit (indst, in_geti (insrc, INLNPTS), + in_geti (insrc, INLNVARS)) + + # Copy rejected point list and limit values. + call amovi (MEMP[in_getp (insrc, INLREJPTS)], + MEMP[in_getp (indst, INLREJPTS)], in_geti (indst, INLNPTS)) + call amov$t (Mem$t[in_getp (insrc, INLXMIN)], + Mem$t[in_getp (indst, INLXMIN)], in_geti (indst, INLNVARS)) + call amov$t (Mem$t[in_getp (insrc, INLXMAX)], + Mem$t[in_getp (indst, INLXMAX)], in_geti (indst, INLNVARS)) +end diff --git a/pkg/xtools/inlfit/incopyd.x b/pkg/xtools/inlfit/incopyd.x new file mode 100644 index 00000000..01ae6793 --- /dev/null +++ b/pkg/xtools/inlfit/incopyd.x @@ -0,0 +1,126 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_COPY -- Copy INLFIT parameter structure, into another. The destination +# structure is allocated if the pointer is NULL. + +procedure in_copyd (insrc, indst) + +pointer insrc # source INLFIT pointer +pointer indst # destination INLFIT pointer + +int in_geti() +double in_getd() +pointer in_getp() + +begin +# # Debug. +# call eprintf ( +# "in_copy: insrc=%d, indst=%d\n") +# call pargi (insrc) +# call pargi (indst) + + # Allocate destination. + if (indst == NULL) { + + # Allocate structure memory. + call malloc (indst, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (indst), in_geti (insrc, INLNPARAMS), + TY_DOUBLE) + call malloc (IN_DPARAM (indst), in_geti (insrc, INLNPARAMS), + TY_DOUBLE) + call malloc (IN_PLIST (indst), in_geti (insrc, INLNPARAMS), + TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_HELP (indst), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT (indst), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (indst), LEN_INLFLOAT, TY_DOUBLE) + call malloc (IN_SGAXES (indst), INLNGKEYS * LEN_INLGRAPH, TY_INT) + } + + # Copy integer parameters. + call in_puti (indst, INLFUNCTION, in_geti (insrc, INLFUNCTION)) + call in_puti (indst, INLDERIVATIVE, in_geti (insrc, INLDERIVATIVE)) + call in_puti (indst, INLNPARAMS, in_geti (insrc, INLNPARAMS)) + call in_puti (indst, INLNFPARAMS, in_geti (insrc, INLNFPARAMS)) + + # Copy parameter values, changes, and list. + call amovd (Memd[in_getp (insrc, INLPARAM)], + Memd[in_getp (indst, INLPARAM)], + in_geti (insrc, INLNPARAMS)) + call amovd (Memd[in_getp (insrc, INLDPARAM)], + Memd[in_getp (indst, INLDPARAM)], + in_geti (insrc, INLNPARAMS)) + call amovi (Memi[in_getp (insrc, INLPLIST)], + Memi[in_getp (indst, INLPLIST)], + in_geti (insrc, INLNPARAMS)) + + # Copy defaults. + call in_putd (indst, INLTOLERANCE, in_getd (insrc, INLTOLERANCE)) + call in_puti (indst, INLMAXITER, in_geti (insrc, INLMAXITER)) + call in_puti (indst, INLNREJECT, in_geti (insrc, INLNREJECT)) + call in_putd (indst, INLLOW, in_getd (insrc, INLLOW)) + call in_putd (indst, INLHIGH, in_getd (insrc, INLHIGH)) + call in_putd (indst, INLGROW, in_getd (insrc, INLGROW)) + + # Copy character strings. + call in_pstr (indst, INLLABELS, Memc[IN_LABELS (insrc)]) + call in_pstr (indst, INLUNITS, Memc[IN_UNITS (insrc)]) + call in_pstr (indst, INLFLABELS, Memc[IN_FLABELS (insrc)]) + call in_pstr (indst, INLFUNITS, Memc[IN_FUNITS (insrc)]) + call in_pstr (indst, INLPLABELS, Memc[IN_PLABELS (insrc)]) + call in_pstr (indst, INLPUNITS, Memc[IN_PUNITS (insrc)]) + call in_pstr (indst, INLVLABELS, Memc[IN_VLABELS (insrc)]) + call in_pstr (indst, INLVUNITS, Memc[IN_VUNITS (insrc)]) + call in_pstr (indst, INLUSERLABELS, Memc[IN_USERLABELS (insrc)]) + call in_pstr (indst, INLUSERUNITS, Memc[IN_USERUNITS (insrc)]) + call in_pstr (indst, INLHELP, Memc[IN_HELP (insrc)]) + call in_pstr (indst, INLPROMPT, Memc[IN_PROMPT (insrc)]) + + # Copy user defined functions. + call in_puti (indst, INLUAXES, in_geti (insrc, INLUAXES)) + call in_puti (indst, INLUCOLON, in_geti (insrc, INLUCOLON)) + call in_puti (indst, INLUFIT, in_geti (insrc, INLUFIT)) + + # Copy graph key, and axes. + call in_puti (indst, INLGKEY, in_geti (insrc, INLGKEY)) + call amovi (IN_SGAXES (insrc), IN_SGAXES (indst), + INLNGKEYS * LEN_INLGRAPH) + + # Copy flags and counters. + call in_puti (indst, INLOVERPLOT, in_geti (insrc, INLOVERPLOT)) + call in_puti (indst, INLPLOTFIT, in_geti (insrc, INLPLOTFIT)) + call in_puti (indst, INLNREJPTS, in_geti (insrc, INLNREJPTS)) + + # Initialize number of points and variables. + call in_puti (indst, INLNVARS, 0) + call in_puti (indst, INLNPTS, 0) + + # Reallocate rejected point list and limit values. + call in_bfinit (indst, in_geti (insrc, INLNPTS), + in_geti (insrc, INLNVARS)) + + # Copy rejected point list and limit values. + call amovi (MEMP[in_getp (insrc, INLREJPTS)], + MEMP[in_getp (indst, INLREJPTS)], in_geti (indst, INLNPTS)) + call amovd (Memd[in_getp (insrc, INLXMIN)], + Memd[in_getp (indst, INLXMIN)], in_geti (indst, INLNVARS)) + call amovd (Memd[in_getp (insrc, INLXMAX)], + Memd[in_getp (indst, INLXMAX)], in_geti (indst, INLNVARS)) +end diff --git a/pkg/xtools/inlfit/incopyr.x b/pkg/xtools/inlfit/incopyr.x new file mode 100644 index 00000000..1e698374 --- /dev/null +++ b/pkg/xtools/inlfit/incopyr.x @@ -0,0 +1,126 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_COPY -- Copy INLFIT parameter structure, into another. The destination +# structure is allocated if the pointer is NULL. + +procedure in_copyr (insrc, indst) + +pointer insrc # source INLFIT pointer +pointer indst # destination INLFIT pointer + +int in_geti() +real in_getr() +pointer in_getp() + +begin +# # Debug. +# call eprintf ( +# "in_copy: insrc=%d, indst=%d\n") +# call pargi (insrc) +# call pargi (indst) + + # Allocate destination. + if (indst == NULL) { + + # Allocate structure memory. + call malloc (indst, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (indst), in_geti (insrc, INLNPARAMS), + TY_REAL) + call malloc (IN_DPARAM (indst), in_geti (insrc, INLNPARAMS), + TY_REAL) + call malloc (IN_PLIST (indst), in_geti (insrc, INLNPARAMS), + TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS (indst), SZ_LINE, TY_CHAR) + call malloc (IN_HELP (indst), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT (indst), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (indst), LEN_INLFLOAT, TY_REAL) + call malloc (IN_SGAXES (indst), INLNGKEYS * LEN_INLGRAPH, TY_INT) + } + + # Copy integer parameters. + call in_puti (indst, INLFUNCTION, in_geti (insrc, INLFUNCTION)) + call in_puti (indst, INLDERIVATIVE, in_geti (insrc, INLDERIVATIVE)) + call in_puti (indst, INLNPARAMS, in_geti (insrc, INLNPARAMS)) + call in_puti (indst, INLNFPARAMS, in_geti (insrc, INLNFPARAMS)) + + # Copy parameter values, changes, and list. + call amovr (Memr[in_getp (insrc, INLPARAM)], + Memr[in_getp (indst, INLPARAM)], + in_geti (insrc, INLNPARAMS)) + call amovr (Memr[in_getp (insrc, INLDPARAM)], + Memr[in_getp (indst, INLDPARAM)], + in_geti (insrc, INLNPARAMS)) + call amovi (Memi[in_getp (insrc, INLPLIST)], + Memi[in_getp (indst, INLPLIST)], + in_geti (insrc, INLNPARAMS)) + + # Copy defaults. + call in_putr (indst, INLTOLERANCE, in_getr (insrc, INLTOLERANCE)) + call in_puti (indst, INLMAXITER, in_geti (insrc, INLMAXITER)) + call in_puti (indst, INLNREJECT, in_geti (insrc, INLNREJECT)) + call in_putr (indst, INLLOW, in_getr (insrc, INLLOW)) + call in_putr (indst, INLHIGH, in_getr (insrc, INLHIGH)) + call in_putr (indst, INLGROW, in_getr (insrc, INLGROW)) + + # Copy character strings. + call in_pstr (indst, INLLABELS, Memc[IN_LABELS (insrc)]) + call in_pstr (indst, INLUNITS, Memc[IN_UNITS (insrc)]) + call in_pstr (indst, INLFLABELS, Memc[IN_FLABELS (insrc)]) + call in_pstr (indst, INLFUNITS, Memc[IN_FUNITS (insrc)]) + call in_pstr (indst, INLPLABELS, Memc[IN_PLABELS (insrc)]) + call in_pstr (indst, INLPUNITS, Memc[IN_PUNITS (insrc)]) + call in_pstr (indst, INLVLABELS, Memc[IN_VLABELS (insrc)]) + call in_pstr (indst, INLVUNITS, Memc[IN_VUNITS (insrc)]) + call in_pstr (indst, INLUSERLABELS, Memc[IN_USERLABELS (insrc)]) + call in_pstr (indst, INLUSERUNITS, Memc[IN_USERUNITS (insrc)]) + call in_pstr (indst, INLHELP, Memc[IN_HELP (insrc)]) + call in_pstr (indst, INLPROMPT, Memc[IN_PROMPT (insrc)]) + + # Copy user defined functions. + call in_puti (indst, INLUAXES, in_geti (insrc, INLUAXES)) + call in_puti (indst, INLUCOLON, in_geti (insrc, INLUCOLON)) + call in_puti (indst, INLUFIT, in_geti (insrc, INLUFIT)) + + # Copy graph key, and axes. + call in_puti (indst, INLGKEY, in_geti (insrc, INLGKEY)) + call amovi (IN_SGAXES (insrc), IN_SGAXES (indst), + INLNGKEYS * LEN_INLGRAPH) + + # Copy flags and counters. + call in_puti (indst, INLOVERPLOT, in_geti (insrc, INLOVERPLOT)) + call in_puti (indst, INLPLOTFIT, in_geti (insrc, INLPLOTFIT)) + call in_puti (indst, INLNREJPTS, in_geti (insrc, INLNREJPTS)) + + # Initialize number of points and variables. + call in_puti (indst, INLNVARS, 0) + call in_puti (indst, INLNPTS, 0) + + # Reallocate rejected point list and limit values. + call in_bfinit (indst, in_geti (insrc, INLNPTS), + in_geti (insrc, INLNVARS)) + + # Copy rejected point list and limit values. + call amovi (MEMP[in_getp (insrc, INLREJPTS)], + MEMP[in_getp (indst, INLREJPTS)], in_geti (indst, INLNPTS)) + call amovr (Memr[in_getp (insrc, INLXMIN)], + Memr[in_getp (indst, INLXMIN)], in_geti (indst, INLNVARS)) + call amovr (Memr[in_getp (insrc, INLXMAX)], + Memr[in_getp (indst, INLXMAX)], in_geti (indst, INLNVARS)) +end diff --git a/pkg/xtools/inlfit/indeviant.gx b/pkg/xtools/inlfit/indeviant.gx new file mode 100644 index 00000000..4ee2f372 --- /dev/null +++ b/pkg/xtools/inlfit/indeviant.gx @@ -0,0 +1,121 @@ +include <mach.h> + + +# IN_DEVIANT -- Find deviant points with large residuals from the fit +# and reject them 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 in_deviant$t (nl, x, y, w, rejpts, npts, nvars, low_reject, + high_reject, grow, nreject, newreject) + +pointer nl # NLFIT descriptor +PIXEL x[ARB] # Input ordinates (npts * nvars) +PIXEL y[npts] # Input data values +PIXEL w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +int nvars # Number of input variables +PIXEL low_reject, high_reject # Rejection thresholds +PIXEL grow # Rejection radius +int nreject # Number of points rejected (output) +int newreject # Number of new points rej. (output) + +int i, j, i_min, i_max, ilast +PIXEL sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin +# # Debug. +# call eprintf ( +# "in_deviant: nl=%d, npts=%d, nvars=%d, low=%g, high=%g, grow=%g\n") +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) +# call parg$t (low_reject) +# call parg$t (high_reject) +# call parg$t (grow) + + # Initialize. + nreject = 0 + newreject = 0 + + # If low_reject and high_reject are zero then just return. + if ((low_reject == PIXEL (0.0)) && (high_reject == PIXEL (0.0))) + return + + # Allocate memory for the residuals. + call smark (sp) + call salloc (residuals, npts, TY_PIXEL) + + # Compute the residuals. + call nlvector$t (nl, x, Mem$t[residuals], npts, nvars) + call asub$t (y, Mem$t[residuals], Mem$t[residuals], npts) + + # Compute the sigma of the residuals. + j = 0 + sigma = PIXEL (0.0) + do i = 1, npts { + if ((w[i] != PIXEL (0.0)) && (rejpts[i] == NO)) { + sigma = sigma + Mem$t[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + # If there are less than five points for the sigma calculation, + # just return. + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + # Set the lower and upper cut limits according the the sigma value. + + if (low_reject > PIXEL (0.0)) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > PIXEL (0.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. + + for (i = 1; i <= npts; i = i + 1) { + + # Do not process points with zero weigth or already rejected. + if ((w[i] == PIXEL (0.0)) || (rejpts[i] == YES)) + next + + # Reject point, and all other points closer than the growing + # factor. + + residual = Mem$t[residuals + i - 1] + if ((residual > high_cut) || (residual < low_cut)) { + + # Determine region to reject. + i_min = max (1, int (i - grow)) + i_max = min (npts, int (i + grow)) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != PIXEL (0.0)) && + (rejpts[j] == NO)) { + rejpts[j] = YES + newreject = newreject + 1 + ilast = j + } + } + i = ilast + } + } + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/indeviantd.x b/pkg/xtools/inlfit/indeviantd.x new file mode 100644 index 00000000..ec32e637 --- /dev/null +++ b/pkg/xtools/inlfit/indeviantd.x @@ -0,0 +1,121 @@ +include <mach.h> + + +# IN_DEVIANT -- Find deviant points with large residuals from the fit +# and reject them 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 in_deviantd (nl, x, y, w, rejpts, npts, nvars, low_reject, + high_reject, grow, nreject, newreject) + +pointer nl # NLFIT descriptor +double x[ARB] # Input ordinates (npts * nvars) +double y[npts] # Input data values +double w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +int nvars # Number of input variables +double low_reject, high_reject # Rejection thresholds +double grow # Rejection radius +int nreject # Number of points rejected (output) +int newreject # Number of new points rej. (output) + +int i, j, i_min, i_max, ilast +double sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin +# # Debug. +# call eprintf ( +# "in_deviant: nl=%d, npts=%d, nvars=%d, low=%g, high=%g, grow=%g\n") +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) +# call parg$t (low_reject) +# call parg$t (high_reject) +# call parg$t (grow) + + # Initialize. + nreject = 0 + newreject = 0 + + # If low_reject and high_reject are zero then just return. + if ((low_reject == double (0.0)) && (high_reject == double (0.0))) + return + + # Allocate memory for the residuals. + call smark (sp) + call salloc (residuals, npts, TY_DOUBLE) + + # Compute the residuals. + call nlvectord (nl, x, Memd[residuals], npts, nvars) + call asubd (y, Memd[residuals], Memd[residuals], npts) + + # Compute the sigma of the residuals. + j = 0 + sigma = double (0.0) + do i = 1, npts { + if ((w[i] != double (0.0)) && (rejpts[i] == NO)) { + sigma = sigma + Memd[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + # If there are less than five points for the sigma calculation, + # just return. + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + # Set the lower and upper cut limits according the the sigma value. + + if (low_reject > double (0.0)) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > double (0.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. + + for (i = 1; i <= npts; i = i + 1) { + + # Do not process points with zero weigth or already rejected. + if ((w[i] == double (0.0)) || (rejpts[i] == YES)) + next + + # Reject point, and all other points closer than the growing + # factor. + + residual = Memd[residuals + i - 1] + if ((residual > high_cut) || (residual < low_cut)) { + + # Determine region to reject. + i_min = max (1, int (i - grow)) + i_max = min (npts, int (i + grow)) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != double (0.0)) && + (rejpts[j] == NO)) { + rejpts[j] = YES + newreject = newreject + 1 + ilast = j + } + } + i = ilast + } + } + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/indeviantr.x b/pkg/xtools/inlfit/indeviantr.x new file mode 100644 index 00000000..334d7ef8 --- /dev/null +++ b/pkg/xtools/inlfit/indeviantr.x @@ -0,0 +1,121 @@ +include <mach.h> + + +# IN_DEVIANT -- Find deviant points with large residuals from the fit +# and reject them 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 in_deviantr (nl, x, y, w, rejpts, npts, nvars, low_reject, + high_reject, grow, nreject, newreject) + +pointer nl # NLFIT descriptor +real x[ARB] # Input ordinates (npts * nvars) +real y[npts] # Input data values +real w[npts] # Weights +int rejpts[npts] # Points rejected +int npts # Number of input points +int nvars # Number of input variables +real low_reject, high_reject # Rejection thresholds +real grow # Rejection radius +int nreject # Number of points rejected (output) +int newreject # Number of new points rej. (output) + +int i, j, i_min, i_max, ilast +real sigma, low_cut, high_cut, residual +pointer sp, residuals + +begin +# # Debug. +# call eprintf ( +# "in_deviant: nl=%d, npts=%d, nvars=%d, low=%g, high=%g, grow=%g\n") +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) +# call parg$t (low_reject) +# call parg$t (high_reject) +# call parg$t (grow) + + # Initialize. + nreject = 0 + newreject = 0 + + # If low_reject and high_reject are zero then just return. + if ((low_reject == real (0.0)) && (high_reject == real (0.0))) + return + + # Allocate memory for the residuals. + call smark (sp) + call salloc (residuals, npts, TY_REAL) + + # Compute the residuals. + call nlvectorr (nl, x, Memr[residuals], npts, nvars) + call asubr (y, Memr[residuals], Memr[residuals], npts) + + # Compute the sigma of the residuals. + j = 0 + sigma = real (0.0) + do i = 1, npts { + if ((w[i] != real (0.0)) && (rejpts[i] == NO)) { + sigma = sigma + Memr[residuals+i-1] ** 2 + j = j + 1 + } else if (rejpts[i] == YES) + nreject = nreject + 1 + } + + # If there are less than five points for the sigma calculation, + # just return. + + if (j < 5) { + call sfree (sp) + return + } else + sigma = sqrt (sigma / j) + + # Set the lower and upper cut limits according the the sigma value. + + if (low_reject > real (0.0)) + low_cut = -low_reject * sigma + else + low_cut = -MAX_REAL + if (high_reject > real (0.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. + + for (i = 1; i <= npts; i = i + 1) { + + # Do not process points with zero weigth or already rejected. + if ((w[i] == real (0.0)) || (rejpts[i] == YES)) + next + + # Reject point, and all other points closer than the growing + # factor. + + residual = Memr[residuals + i - 1] + if ((residual > high_cut) || (residual < low_cut)) { + + # Determine region to reject. + i_min = max (1, int (i - grow)) + i_max = min (npts, int (i + grow)) + + # Reject points from the fit and flag them. + do j = i_min, i_max { + if ((abs (x[i] - x[j]) <= grow) && (w[j] != real (0.0)) && + (rejpts[j] == NO)) { + rejpts[j] = YES + newreject = newreject + 1 + ilast = j + } + } + i = ilast + } + } + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/indump.gx b/pkg/xtools/inlfit/indump.gx new file mode 100644 index 00000000..ee624a4e --- /dev/null +++ b/pkg/xtools/inlfit/indump.gx @@ -0,0 +1,233 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_DUMP -- INLFIT debugging routine. + +procedure in_dump$t (fd, in) + +int fd # file descriptor +pointer in # INLFIT descriptor + +int i, npars, nfpars, nvars + +begin + # Test INLFIT pointer. + if (in == NULL) { + call fprintf (fd, "\n****** in_dump: Null INLFIT pointer\n") + call flush (fd) + return + } + + # File and INLFIT descriptors. + call fprintf (fd, "\n****** in_dump: (fd=%d), (in=%d)\n") + call pargi (fd) + call pargi (in) + call flush (fd) + + # Function and derivative pointers. + call fprintf (fd, "Fitting function pointer = %d\n") + call pargi (IN_FUNC (in)) + call fprintf (fd, "Derivative function pointer = %d\n") + call pargi (IN_DFUNC (in)) + call flush (fd) + + # Number of parameters, fitting parameters, and variables. + npars = IN_NPARAMS (in) + nfpars = IN_NFPARAMS (in) + nvars = IN_NVARS (in) + call fprintf (fd, "Number of parameters = %d\n") + call pargi (npars) + call fprintf (fd, "Number of fitted parameters = %d\n") + call pargi (nfpars) + call fprintf (fd, "Number of variables = %d\n") + call pargi (nvars) + call fprintf (fd, "Number of points = %d\n") + call pargi (IN_NPTS (in)) + call flush (fd) + + # Parameter values. + call fprintf (fd, "Parameter values (%d):\n") + call pargi (npars) + if (IN_PARAM (in) != NULL) { + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call parg$t (Mem$t [IN_PARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter value pointer\n") + call flush (fd) + + # Parameter changes. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter changes (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call parg$t (Mem$t [IN_DPARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter change pointer\n") + call flush (fd) + + # Parameter list. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter list (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %d\n") + call pargi (i) + call pargi (Memi[IN_PLIST (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter list pointer\n") + call flush (fd) + + # Floating point parameters. + if (IN_SFLOAT (in) != NULL) { + call fprintf (fd, "Fit tolerance = %g\n") + call parg$t (IN_TOL$T (in)) + call fprintf (fd, "Low reject = %g\n") + call parg$t (IN_LOW$T (in)) + call fprintf (fd, "High reject = %g\n") + call parg$t (IN_HIGH$T (in)) + call fprintf (fd, "Growing radius = %g\n") + call parg$t (IN_GROW$T (in)) + } else + call fprintf (fd, "Null floating point pointer\n") + call flush (fd) + + # Max number of iterations, and rejection iterations. + call fprintf (fd, "Maximum number of iterations = %d\n") + call pargi (IN_MAXITER (in)) + call fprintf (fd, "Number of rejection iterations = %d\n") + call pargi (IN_MAXITER (in)) + + # Rejected points. + call fprintf (fd, "Number of rejected points = %d\n") + call pargi (IN_NREJPTS (in)) + call fprintf (fd, "Rejected point list pointer = %d\n") + call pargi (IN_REJPTS (in)) + + # User procedures. + call fprintf (fd, "User axis procedure pointer = %d\n") + call pargi (IN_UAXES (in)) + call fprintf (fd, "User colon procedure pointer = %d\n") + call pargi (IN_UCOLON (in)) + call fprintf (fd, "User fit procedure pointer = %d\n") + call pargi (IN_UFIT (in)) + + # Minimum variable values. + if (IN_XMIN (in) != NULL) { + call fprintf (fd, "Minimum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call parg$t (Mem$t[IN_XMIN (in) + i - 1]) + } + } else + call fprintf (fd, "Null minimum value pointer\n") + call flush (fd) + + # Maximum variable values. + if (IN_XMAX (in) != NULL) { + call fprintf (fd, "Maximum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call parg$t (Mem$t[IN_XMAX (in) + i - 1]) + } + } else + call fprintf (fd, "Null maximum value pointer\n") + call flush (fd) + + # Flags. + call fprintf (fd, "Overplot next flag = %d\n") + call pargi (IN_OVERPLOT (in)) + call fprintf (fd, "Overplot fit flag = %d\n") + call pargi (IN_PLOTFIT (in)) + call fprintf (fd, "Fit error code = %d\n") + call pargi (IN_FITERROR (in)) + + # Strings. + if (IN_LABELS (in) != NULL) { + call fprintf (fd, "Axis labels = [%s]\n") + call pargstr (Memc[IN_LABELS (in)]) + } else + call fprintf (fd, "Null axis label pointer\n") + if (IN_UNITS (in) != NULL) { + call fprintf (fd, "Axis units = [%s]\n") + call pargstr (Memc[IN_UNITS (in)]) + } else + call fprintf (fd, "Null axis unit pointer\n") + if (IN_FLABELS (in) != NULL) { + call fprintf (fd, "Function/fit labels = [%s]\n") + call pargstr (Memc[IN_FLABELS (in)]) + } else + call fprintf (fd, "Null function/fit label pointer\n") + if (IN_FUNITS (in) != NULL) { + call fprintf (fd, "Function/fit units = [%s]\n") + call pargstr (Memc[IN_FUNITS (in)]) + } else + call fprintf (fd, "Null function/fit unit pointer\n") + if (IN_PLABELS (in) != NULL) { + call fprintf (fd, "Parameter labels = [%s]\n") + call pargstr (Memc[IN_PLABELS (in)]) + } else + call fprintf (fd, "Null parameter label pointer\n") + if (IN_PUNITS (in) != NULL) { + call fprintf (fd, "Parameter units = [%s]\n") + call pargstr (Memc[IN_PUNITS (in)]) + } else + call fprintf (fd, "Null parameter unit pointer\n") + if (IN_VLABELS (in) != NULL) { + call fprintf (fd, "Variable labels = [%s]\n") + call pargstr (Memc[IN_VLABELS (in)]) + } else + call fprintf (fd, "Null variable label pointer\n") + if (IN_VUNITS (in) != NULL) { + call fprintf (fd, "Variable units = [%s]\n") + call pargstr (Memc[IN_VUNITS (in)]) + } else + call fprintf (fd, "Null variable unit pointer\n") + if (IN_USERLABELS (in) != NULL) { + call fprintf (fd, "User plot labels = [%s]\n") + call pargstr (Memc[IN_USERLABELS (in)]) + } else + call fprintf (fd, "Null user plot label pointer\n") + if (IN_USERUNITS (in) != NULL) { + call fprintf (fd, "User plot units = [%s]\n") + call pargstr (Memc[IN_USERUNITS (in)]) + } else + call fprintf (fd, "Null user plot unit pointer\n") + if (IN_HELP (in) != NULL) { + call fprintf (fd, "Help page = [%s]\n") + call pargstr (Memc[IN_HELP (in)]) + } else + call fprintf (fd, "Null help page pointer\n") + if (IN_PROMPT (in) != NULL) { + call fprintf (fd, "Help prompt = [%s]\n") + call pargstr (Memc[IN_PROMPT (in)]) + } else + call fprintf (fd, "Null help prompt\n") + call flush (fd) + + # Graph keys. + if (IN_SGAXES (in) != NULL) { + call fprintf (fd, "Current graph key = %d\n") + call pargi (IN_GKEY (in)) + do i = 1, INLNGKEYS { + call fprintf (fd, "%d, xtype=%d, xnum=%d, ytype=%d, ynum=%d\n") + call pargi (i) + call pargi (IN_GXTYPE (in, i)) + call pargi (IN_GXNUMBER (in, i)) + call pargi (IN_GYTYPE (in, i)) + call pargi (IN_GYNUMBER (in, i)) + } + } else + call fprintf (fd, "Null key pointer\n") + call flush (fd) +end diff --git a/pkg/xtools/inlfit/indumpd.x b/pkg/xtools/inlfit/indumpd.x new file mode 100644 index 00000000..8e388f4a --- /dev/null +++ b/pkg/xtools/inlfit/indumpd.x @@ -0,0 +1,233 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_DUMP -- INLFIT debugging routine. + +procedure in_dumpd (fd, in) + +int fd # file descriptor +pointer in # INLFIT descriptor + +int i, npars, nfpars, nvars + +begin + # Test INLFIT pointer. + if (in == NULL) { + call fprintf (fd, "\n****** in_dump: Null INLFIT pointer\n") + call flush (fd) + return + } + + # File and INLFIT descriptors. + call fprintf (fd, "\n****** in_dump: (fd=%d), (in=%d)\n") + call pargi (fd) + call pargi (in) + call flush (fd) + + # Function and derivative pointers. + call fprintf (fd, "Fitting function pointer = %d\n") + call pargi (IN_FUNC (in)) + call fprintf (fd, "Derivative function pointer = %d\n") + call pargi (IN_DFUNC (in)) + call flush (fd) + + # Number of parameters, fitting parameters, and variables. + npars = IN_NPARAMS (in) + nfpars = IN_NFPARAMS (in) + nvars = IN_NVARS (in) + call fprintf (fd, "Number of parameters = %d\n") + call pargi (npars) + call fprintf (fd, "Number of fitted parameters = %d\n") + call pargi (nfpars) + call fprintf (fd, "Number of variables = %d\n") + call pargi (nvars) + call fprintf (fd, "Number of points = %d\n") + call pargi (IN_NPTS (in)) + call flush (fd) + + # Parameter values. + call fprintf (fd, "Parameter values (%d):\n") + call pargi (npars) + if (IN_PARAM (in) != NULL) { + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargd (Memd [IN_PARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter value pointer\n") + call flush (fd) + + # Parameter changes. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter changes (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargd (Memd [IN_DPARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter change pointer\n") + call flush (fd) + + # Parameter list. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter list (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %d\n") + call pargi (i) + call pargi (Memi[IN_PLIST (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter list pointer\n") + call flush (fd) + + # Floating point parameters. + if (IN_SFLOAT (in) != NULL) { + call fprintf (fd, "Fit tolerance = %g\n") + call pargd (IN_TOLD (in)) + call fprintf (fd, "Low reject = %g\n") + call pargd (IN_LOWD (in)) + call fprintf (fd, "High reject = %g\n") + call pargd (IN_HIGHD (in)) + call fprintf (fd, "Growing radius = %g\n") + call pargd (IN_GROWD (in)) + } else + call fprintf (fd, "Null floating point pointer\n") + call flush (fd) + + # Max number of iterations, and rejection iterations. + call fprintf (fd, "Maximum number of iterations = %d\n") + call pargi (IN_MAXITER (in)) + call fprintf (fd, "Number of rejection iterations = %d\n") + call pargi (IN_MAXITER (in)) + + # Rejected points. + call fprintf (fd, "Number of rejected points = %d\n") + call pargi (IN_NREJPTS (in)) + call fprintf (fd, "Rejected point list pointer = %d\n") + call pargi (IN_REJPTS (in)) + + # User procedures. + call fprintf (fd, "User axis procedure pointer = %d\n") + call pargi (IN_UAXES (in)) + call fprintf (fd, "User colon procedure pointer = %d\n") + call pargi (IN_UCOLON (in)) + call fprintf (fd, "User fit procedure pointer = %d\n") + call pargi (IN_UFIT (in)) + + # Minimum variable values. + if (IN_XMIN (in) != NULL) { + call fprintf (fd, "Minimum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargd (Memd[IN_XMIN (in) + i - 1]) + } + } else + call fprintf (fd, "Null minimum value pointer\n") + call flush (fd) + + # Maximum variable values. + if (IN_XMAX (in) != NULL) { + call fprintf (fd, "Maximum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargd (Memd[IN_XMAX (in) + i - 1]) + } + } else + call fprintf (fd, "Null maximum value pointer\n") + call flush (fd) + + # Flags. + call fprintf (fd, "Overplot next flag = %d\n") + call pargi (IN_OVERPLOT (in)) + call fprintf (fd, "Overplot fit flag = %d\n") + call pargi (IN_PLOTFIT (in)) + call fprintf (fd, "Fit error code = %d\n") + call pargi (IN_FITERROR (in)) + + # Strings. + if (IN_LABELS (in) != NULL) { + call fprintf (fd, "Axis labels = [%s]\n") + call pargstr (Memc[IN_LABELS (in)]) + } else + call fprintf (fd, "Null axis label pointer\n") + if (IN_UNITS (in) != NULL) { + call fprintf (fd, "Axis units = [%s]\n") + call pargstr (Memc[IN_UNITS (in)]) + } else + call fprintf (fd, "Null axis unit pointer\n") + if (IN_FLABELS (in) != NULL) { + call fprintf (fd, "Function/fit labels = [%s]\n") + call pargstr (Memc[IN_FLABELS (in)]) + } else + call fprintf (fd, "Null function/fit label pointer\n") + if (IN_FUNITS (in) != NULL) { + call fprintf (fd, "Function/fit units = [%s]\n") + call pargstr (Memc[IN_FUNITS (in)]) + } else + call fprintf (fd, "Null function/fit unit pointer\n") + if (IN_PLABELS (in) != NULL) { + call fprintf (fd, "Parameter labels = [%s]\n") + call pargstr (Memc[IN_PLABELS (in)]) + } else + call fprintf (fd, "Null parameter label pointer\n") + if (IN_PUNITS (in) != NULL) { + call fprintf (fd, "Parameter units = [%s]\n") + call pargstr (Memc[IN_PUNITS (in)]) + } else + call fprintf (fd, "Null parameter unit pointer\n") + if (IN_VLABELS (in) != NULL) { + call fprintf (fd, "Variable labels = [%s]\n") + call pargstr (Memc[IN_VLABELS (in)]) + } else + call fprintf (fd, "Null variable label pointer\n") + if (IN_VUNITS (in) != NULL) { + call fprintf (fd, "Variable units = [%s]\n") + call pargstr (Memc[IN_VUNITS (in)]) + } else + call fprintf (fd, "Null variable unit pointer\n") + if (IN_USERLABELS (in) != NULL) { + call fprintf (fd, "User plot labels = [%s]\n") + call pargstr (Memc[IN_USERLABELS (in)]) + } else + call fprintf (fd, "Null user plot label pointer\n") + if (IN_USERUNITS (in) != NULL) { + call fprintf (fd, "User plot units = [%s]\n") + call pargstr (Memc[IN_USERUNITS (in)]) + } else + call fprintf (fd, "Null user plot unit pointer\n") + if (IN_HELP (in) != NULL) { + call fprintf (fd, "Help page = [%s]\n") + call pargstr (Memc[IN_HELP (in)]) + } else + call fprintf (fd, "Null help page pointer\n") + if (IN_PROMPT (in) != NULL) { + call fprintf (fd, "Help prompt = [%s]\n") + call pargstr (Memc[IN_PROMPT (in)]) + } else + call fprintf (fd, "Null help prompt\n") + call flush (fd) + + # Graph keys. + if (IN_SGAXES (in) != NULL) { + call fprintf (fd, "Current graph key = %d\n") + call pargi (IN_GKEY (in)) + do i = 1, INLNGKEYS { + call fprintf (fd, "%d, xtype=%d, xnum=%d, ytype=%d, ynum=%d\n") + call pargi (i) + call pargi (IN_GXTYPE (in, i)) + call pargi (IN_GXNUMBER (in, i)) + call pargi (IN_GYTYPE (in, i)) + call pargi (IN_GYNUMBER (in, i)) + } + } else + call fprintf (fd, "Null key pointer\n") + call flush (fd) +end diff --git a/pkg/xtools/inlfit/indumpr.x b/pkg/xtools/inlfit/indumpr.x new file mode 100644 index 00000000..bdcc6be7 --- /dev/null +++ b/pkg/xtools/inlfit/indumpr.x @@ -0,0 +1,233 @@ +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_DUMP -- INLFIT debugging routine. + +procedure in_dumpr (fd, in) + +int fd # file descriptor +pointer in # INLFIT descriptor + +int i, npars, nfpars, nvars + +begin + # Test INLFIT pointer. + if (in == NULL) { + call fprintf (fd, "\n****** in_dump: Null INLFIT pointer\n") + call flush (fd) + return + } + + # File and INLFIT descriptors. + call fprintf (fd, "\n****** in_dump: (fd=%d), (in=%d)\n") + call pargi (fd) + call pargi (in) + call flush (fd) + + # Function and derivative pointers. + call fprintf (fd, "Fitting function pointer = %d\n") + call pargi (IN_FUNC (in)) + call fprintf (fd, "Derivative function pointer = %d\n") + call pargi (IN_DFUNC (in)) + call flush (fd) + + # Number of parameters, fitting parameters, and variables. + npars = IN_NPARAMS (in) + nfpars = IN_NFPARAMS (in) + nvars = IN_NVARS (in) + call fprintf (fd, "Number of parameters = %d\n") + call pargi (npars) + call fprintf (fd, "Number of fitted parameters = %d\n") + call pargi (nfpars) + call fprintf (fd, "Number of variables = %d\n") + call pargi (nvars) + call fprintf (fd, "Number of points = %d\n") + call pargi (IN_NPTS (in)) + call flush (fd) + + # Parameter values. + call fprintf (fd, "Parameter values (%d):\n") + call pargi (npars) + if (IN_PARAM (in) != NULL) { + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargr (Memr [IN_PARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter value pointer\n") + call flush (fd) + + # Parameter changes. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter changes (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargr (Memr [IN_DPARAM (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter change pointer\n") + call flush (fd) + + # Parameter list. + if (IN_PARAM (in) != NULL) { + call fprintf (fd, "Parameter list (%d):\n") + call pargi (npars) + do i = 1, npars { + call fprintf (fd, "%d -> %d\n") + call pargi (i) + call pargi (Memi[IN_PLIST (in) + i - 1]) + } + } else + call fprintf (fd, "Null parameter list pointer\n") + call flush (fd) + + # Floating point parameters. + if (IN_SFLOAT (in) != NULL) { + call fprintf (fd, "Fit tolerance = %g\n") + call pargr (IN_TOLR (in)) + call fprintf (fd, "Low reject = %g\n") + call pargr (IN_LOWR (in)) + call fprintf (fd, "High reject = %g\n") + call pargr (IN_HIGHR (in)) + call fprintf (fd, "Growing radius = %g\n") + call pargr (IN_GROWR (in)) + } else + call fprintf (fd, "Null floating point pointer\n") + call flush (fd) + + # Max number of iterations, and rejection iterations. + call fprintf (fd, "Maximum number of iterations = %d\n") + call pargi (IN_MAXITER (in)) + call fprintf (fd, "Number of rejection iterations = %d\n") + call pargi (IN_MAXITER (in)) + + # Rejected points. + call fprintf (fd, "Number of rejected points = %d\n") + call pargi (IN_NREJPTS (in)) + call fprintf (fd, "Rejected point list pointer = %d\n") + call pargi (IN_REJPTS (in)) + + # User procedures. + call fprintf (fd, "User axis procedure pointer = %d\n") + call pargi (IN_UAXES (in)) + call fprintf (fd, "User colon procedure pointer = %d\n") + call pargi (IN_UCOLON (in)) + call fprintf (fd, "User fit procedure pointer = %d\n") + call pargi (IN_UFIT (in)) + + # Minimum variable values. + if (IN_XMIN (in) != NULL) { + call fprintf (fd, "Minimum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargr (Memr[IN_XMIN (in) + i - 1]) + } + } else + call fprintf (fd, "Null minimum value pointer\n") + call flush (fd) + + # Maximum variable values. + if (IN_XMAX (in) != NULL) { + call fprintf (fd, "Maximum variable values (%d):\n") + call pargi (nvars) + do i = 1, nvars { + call fprintf (fd, "%d -> %g\n") + call pargi (i) + call pargr (Memr[IN_XMAX (in) + i - 1]) + } + } else + call fprintf (fd, "Null maximum value pointer\n") + call flush (fd) + + # Flags. + call fprintf (fd, "Overplot next flag = %d\n") + call pargi (IN_OVERPLOT (in)) + call fprintf (fd, "Overplot fit flag = %d\n") + call pargi (IN_PLOTFIT (in)) + call fprintf (fd, "Fit error code = %d\n") + call pargi (IN_FITERROR (in)) + + # Strings. + if (IN_LABELS (in) != NULL) { + call fprintf (fd, "Axis labels = [%s]\n") + call pargstr (Memc[IN_LABELS (in)]) + } else + call fprintf (fd, "Null axis label pointer\n") + if (IN_UNITS (in) != NULL) { + call fprintf (fd, "Axis units = [%s]\n") + call pargstr (Memc[IN_UNITS (in)]) + } else + call fprintf (fd, "Null axis unit pointer\n") + if (IN_FLABELS (in) != NULL) { + call fprintf (fd, "Function/fit labels = [%s]\n") + call pargstr (Memc[IN_FLABELS (in)]) + } else + call fprintf (fd, "Null function/fit label pointer\n") + if (IN_FUNITS (in) != NULL) { + call fprintf (fd, "Function/fit units = [%s]\n") + call pargstr (Memc[IN_FUNITS (in)]) + } else + call fprintf (fd, "Null function/fit unit pointer\n") + if (IN_PLABELS (in) != NULL) { + call fprintf (fd, "Parameter labels = [%s]\n") + call pargstr (Memc[IN_PLABELS (in)]) + } else + call fprintf (fd, "Null parameter label pointer\n") + if (IN_PUNITS (in) != NULL) { + call fprintf (fd, "Parameter units = [%s]\n") + call pargstr (Memc[IN_PUNITS (in)]) + } else + call fprintf (fd, "Null parameter unit pointer\n") + if (IN_VLABELS (in) != NULL) { + call fprintf (fd, "Variable labels = [%s]\n") + call pargstr (Memc[IN_VLABELS (in)]) + } else + call fprintf (fd, "Null variable label pointer\n") + if (IN_VUNITS (in) != NULL) { + call fprintf (fd, "Variable units = [%s]\n") + call pargstr (Memc[IN_VUNITS (in)]) + } else + call fprintf (fd, "Null variable unit pointer\n") + if (IN_USERLABELS (in) != NULL) { + call fprintf (fd, "User plot labels = [%s]\n") + call pargstr (Memc[IN_USERLABELS (in)]) + } else + call fprintf (fd, "Null user plot label pointer\n") + if (IN_USERUNITS (in) != NULL) { + call fprintf (fd, "User plot units = [%s]\n") + call pargstr (Memc[IN_USERUNITS (in)]) + } else + call fprintf (fd, "Null user plot unit pointer\n") + if (IN_HELP (in) != NULL) { + call fprintf (fd, "Help page = [%s]\n") + call pargstr (Memc[IN_HELP (in)]) + } else + call fprintf (fd, "Null help page pointer\n") + if (IN_PROMPT (in) != NULL) { + call fprintf (fd, "Help prompt = [%s]\n") + call pargstr (Memc[IN_PROMPT (in)]) + } else + call fprintf (fd, "Null help prompt\n") + call flush (fd) + + # Graph keys. + if (IN_SGAXES (in) != NULL) { + call fprintf (fd, "Current graph key = %d\n") + call pargi (IN_GKEY (in)) + do i = 1, INLNGKEYS { + call fprintf (fd, "%d, xtype=%d, xnum=%d, ytype=%d, ynum=%d\n") + call pargi (i) + call pargi (IN_GXTYPE (in, i)) + call pargi (IN_GXNUMBER (in, i)) + call pargi (IN_GYTYPE (in, i)) + call pargi (IN_GYNUMBER (in, i)) + } + } else + call fprintf (fd, "Null key pointer\n") + call flush (fd) +end diff --git a/pkg/xtools/inlfit/inerrors.gx b/pkg/xtools/inlfit/inerrors.gx new file mode 100644 index 00000000..f21f805f --- /dev/null +++ b/pkg/xtools/inlfit/inerrors.gx @@ -0,0 +1,66 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_ERRORS -- Compute the reduced chi-square of the fit and the +# parameter errors. This procedure must be used instead of nlerrors() +# because the weigths are changed during the data rejection process. +# If no data rejection is used, then both procedures are equivalent. + +procedure in_errors$t (in, nl, x, y, wts, npts, nvars, variance, chisqr, + scatter, rms, errors) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[npts] # Data to be fit +PIXEL wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +PIXEL variance # variance of the fit (output) +PIXEL chisqr # reduced chi-squared of fit (output) +PIXEL scatter # additional scatter in equation +PIXEL rms # RMS of the fit (output) +PIXEL errors[ARB] # errors in coefficients (output) + +int i +PIXEL in_rms$t(), nlstat$t +pointer sp, fit, wts1, rejpts + +int in_geti() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_errors: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate memory for fit and weights. + call smark (sp) + call salloc (fit, npts, TY_PIXEL) + call salloc (wts1, npts, TY_PIXEL) + + # Set zero weight for rejeceted points. + call amov$t (wts, Mem$t[wts1], npts) + if (in_geti (in, INLNREJPTS) > 0) { + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Mem$t[wts1+i-1] = PIXEL (0.0) + } + } + + # Evaluate the fit, and compute the rms, reduced chi + # squared and errors. + + call nlvector$t (nl, x, Mem$t[fit], npts, nvars) + call nlerrors$t (nl, y, Mem$t[fit], Mem$t[wts1], npts, + variance, chisqr, errors) + rms = in_rms$t (y, Mem$t[fit], Mem$t[wts1], npts) + scatter = nlstat$t (nl, NLSCATTER) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inerrorsd.x b/pkg/xtools/inlfit/inerrorsd.x new file mode 100644 index 00000000..deae56d2 --- /dev/null +++ b/pkg/xtools/inlfit/inerrorsd.x @@ -0,0 +1,66 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_ERRORS -- Compute the reduced chi-square of the fit and the +# parameter errors. This procedure must be used instead of nlerrors() +# because the weigths are changed during the data rejection process. +# If no data rejection is used, then both procedures are equivalent. + +procedure in_errorsd (in, nl, x, y, wts, npts, nvars, variance, chisqr, + scatter, rms, errors) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[npts] # Data to be fit +double wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +double variance # variance of the fit (output) +double chisqr # reduced chi-squared of fit (output) +double scatter # additional scatter in equation +double rms # RMS of the fit (output) +double errors[ARB] # errors in coefficients (output) + +int i +double in_rmsd(), nlstatd +pointer sp, fit, wts1, rejpts + +int in_geti() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_errors: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate memory for fit and weights. + call smark (sp) + call salloc (fit, npts, TY_DOUBLE) + call salloc (wts1, npts, TY_DOUBLE) + + # Set zero weight for rejeceted points. + call amovd (wts, Memd[wts1], npts) + if (in_geti (in, INLNREJPTS) > 0) { + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memd[wts1+i-1] = double (0.0) + } + } + + # Evaluate the fit, and compute the rms, reduced chi + # squared and errors. + + call nlvectord (nl, x, Memd[fit], npts, nvars) + call nlerrorsd (nl, y, Memd[fit], Memd[wts1], npts, + variance, chisqr, errors) + rms = in_rmsd (y, Memd[fit], Memd[wts1], npts) + scatter = nlstatd (nl, NLSCATTER) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inerrorsr.x b/pkg/xtools/inlfit/inerrorsr.x new file mode 100644 index 00000000..c481f565 --- /dev/null +++ b/pkg/xtools/inlfit/inerrorsr.x @@ -0,0 +1,66 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_ERRORS -- Compute the reduced chi-square of the fit and the +# parameter errors. This procedure must be used instead of nlerrors() +# because the weigths are changed during the data rejection process. +# If no data rejection is used, then both procedures are equivalent. + +procedure in_errorsr (in, nl, x, y, wts, npts, nvars, variance, chisqr, + scatter, rms, errors) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[npts] # Data to be fit +real wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +real variance # variance of the fit (output) +real chisqr # reduced chi-squared of fit (output) +real scatter # additional scatter in equation +real rms # RMS of the fit (output) +real errors[ARB] # errors in coefficients (output) + +int i +real in_rmsr(), nlstatr +pointer sp, fit, wts1, rejpts + +int in_geti() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_errors: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate memory for fit and weights. + call smark (sp) + call salloc (fit, npts, TY_REAL) + call salloc (wts1, npts, TY_REAL) + + # Set zero weight for rejeceted points. + call amovr (wts, Memr[wts1], npts) + if (in_geti (in, INLNREJPTS) > 0) { + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memr[wts1+i-1] = real (0.0) + } + } + + # Evaluate the fit, and compute the rms, reduced chi + # squared and errors. + + call nlvectorr (nl, x, Memr[fit], npts, nvars) + call nlerrorsr (nl, y, Memr[fit], Memr[wts1], npts, + variance, chisqr, errors) + rms = in_rmsr (y, Memr[fit], Memr[wts1], npts) + scatter = nlstatr (nl, NLSCATTER) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/infit.gx b/pkg/xtools/inlfit/infit.gx new file mode 100644 index 00000000..069bf584 --- /dev/null +++ b/pkg/xtools/inlfit/infit.gx @@ -0,0 +1,99 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_FIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the non-interactive part of the INLFIT package. + +procedure in_fit$t (in, nl, x, y, wts, npts, nvars, wtflag, stat) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[npts] # Data to be fit +PIXEL wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting +int stat # Error code (output) + +int i, ndeleted +pointer sp, wts1, str +int in_geti() +PIXEL in_get$t + +begin + +# # Debug. +# call eprintf ("in_fit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate string, and rejection weight space. The latter are + # are used to mark rejected points with a zero weight before + # calling NLFIT. + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (wts1, npts, TY_PIXEL) + call amov$t (wts, Mem$t[wts1], npts) + + # Initialize rejected point list, and the buffer containing + # the minimum and maximum variable values. + call in_bfinit$t (in, npts, nvars) + + # Set independent variable limits. + call in_limit$t (in, x, npts, nvars) + + # Reinitialize. + call in_nlinit$t (in, nl) + + # Check number of data points. If no points are present + # set the error flag to the appropiate value, and return. + if (npts == 0) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Check the number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= PIXEL(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti (in, INLNFPARAMS)) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Call NLFIT. + call nlfit$t (nl, x, y, wts, npts, nvars, wtflag, stat) + + # Update fit status into the INLFIT structure. + call in_puti (in, INLFITERROR, stat) + + # Do pixel rejection and refit, if at least one of the rejection + # limits is positive. Otherwise clear number of rejected points. + + if (in_get$t (in, INLLOW) > PIXEL (0.0) || + in_get$t (in, INLHIGH) > PIXEL (0.0)) { + call in_reject$t (in, nl, x, y, Mem$t[wts1], npts, nvars, wtflag) + if (in_geti (in, INLNREJPTS) > 0) { + do i = 1, npts { + if (Mem$t[wts1+i-1] > PIXEL(0.0)) + wts[i] = Mem$t[wts1+i-1] + } + } + stat = in_geti (in, INLFITERROR) + } else + call in_puti (in, INLNREJPTS, 0) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/infitd.x b/pkg/xtools/inlfit/infitd.x new file mode 100644 index 00000000..f57bbb6c --- /dev/null +++ b/pkg/xtools/inlfit/infitd.x @@ -0,0 +1,99 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_FIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the non-interactive part of the INLFIT package. + +procedure in_fitd (in, nl, x, y, wts, npts, nvars, wtflag, stat) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[npts] # Data to be fit +double wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting +int stat # Error code (output) + +int i, ndeleted +pointer sp, wts1, str +int in_geti() +double in_getd + +begin + +# # Debug. +# call eprintf ("in_fit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate string, and rejection weight space. The latter are + # are used to mark rejected points with a zero weight before + # calling NLFIT. + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (wts1, npts, TY_DOUBLE) + call amovd (wts, Memd[wts1], npts) + + # Initialize rejected point list, and the buffer containing + # the minimum and maximum variable values. + call in_bfinitd (in, npts, nvars) + + # Set independent variable limits. + call in_limitd (in, x, npts, nvars) + + # Reinitialize. + call in_nlinitd (in, nl) + + # Check number of data points. If no points are present + # set the error flag to the appropiate value, and return. + if (npts == 0) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Check the number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= double(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti (in, INLNFPARAMS)) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Call NLFIT. + call nlfitd (nl, x, y, wts, npts, nvars, wtflag, stat) + + # Update fit status into the INLFIT structure. + call in_puti (in, INLFITERROR, stat) + + # Do pixel rejection and refit, if at least one of the rejection + # limits is positive. Otherwise clear number of rejected points. + + if (in_getd (in, INLLOW) > double (0.0) || + in_getd (in, INLHIGH) > double (0.0)) { + call in_rejectd (in, nl, x, y, Memd[wts1], npts, nvars, wtflag) + if (in_geti (in, INLNREJPTS) > 0) { + do i = 1, npts { + if (Memd[wts1+i-1] > double(0.0)) + wts[i] = Memd[wts1+i-1] + } + } + stat = in_geti (in, INLFITERROR) + } else + call in_puti (in, INLNREJPTS, 0) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/infitr.x b/pkg/xtools/inlfit/infitr.x new file mode 100644 index 00000000..1a46a09c --- /dev/null +++ b/pkg/xtools/inlfit/infitr.x @@ -0,0 +1,99 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + +# IN_FIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the non-interactive part of the INLFIT package. + +procedure in_fitr (in, nl, x, y, wts, npts, nvars, wtflag, stat) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[npts] # Data to be fit +real wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting +int stat # Error code (output) + +int i, ndeleted +pointer sp, wts1, str +int in_geti() +real in_getr + +begin + +# # Debug. +# call eprintf ("in_fit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Allocate string, and rejection weight space. The latter are + # are used to mark rejected points with a zero weight before + # calling NLFIT. + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (wts1, npts, TY_REAL) + call amovr (wts, Memr[wts1], npts) + + # Initialize rejected point list, and the buffer containing + # the minimum and maximum variable values. + call in_bfinitr (in, npts, nvars) + + # Set independent variable limits. + call in_limitr (in, x, npts, nvars) + + # Reinitialize. + call in_nlinitr (in, nl) + + # Check number of data points. If no points are present + # set the error flag to the appropiate value, and return. + if (npts == 0) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Check the number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= real(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti (in, INLNFPARAMS)) { + stat = NO_DEG_FREEDOM + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + call sfree (sp) + return + } + + # Call NLFIT. + call nlfitr (nl, x, y, wts, npts, nvars, wtflag, stat) + + # Update fit status into the INLFIT structure. + call in_puti (in, INLFITERROR, stat) + + # Do pixel rejection and refit, if at least one of the rejection + # limits is positive. Otherwise clear number of rejected points. + + if (in_getr (in, INLLOW) > real (0.0) || + in_getr (in, INLHIGH) > real (0.0)) { + call in_rejectr (in, nl, x, y, Memr[wts1], npts, nvars, wtflag) + if (in_geti (in, INLNREJPTS) > 0) { + do i = 1, npts { + if (Memr[wts1+i-1] > real(0.0)) + wts[i] = Memr[wts1+i-1] + } + } + stat = in_geti (in, INLFITERROR) + } else + call in_puti (in, INLNREJPTS, 0) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/infree.gx b/pkg/xtools/inlfit/infree.gx new file mode 100644 index 00000000..80fed996 --- /dev/null +++ b/pkg/xtools/inlfit/infree.gx @@ -0,0 +1,52 @@ +include "inlfitdef.h" + + +# IN_FREE -- Free INLFIT parameter structure, substructures, and auxiliary +# buffers. + +procedure in_free$t (in) + +pointer in # INLFIT pointer + +begin + +# # Debug. +# call eprintf ("in_free: in=%d\n") +# call pargi (in) + + # Free only if it's not NULL. + if (in != NULL) { + + # Free parameter values, changes, and list. + call mfree (IN_PARAM (in), TY_PIXEL) + call mfree (IN_DPARAM (in), TY_PIXEL) + call mfree (IN_PLIST (in), TY_INT) + + # Free string space. + call mfree (IN_LABELS (in), TY_CHAR) + call mfree (IN_UNITS (in), TY_CHAR) + call mfree (IN_PLABELS (in), TY_CHAR) + call mfree (IN_PUNITS (in), TY_CHAR) + call mfree (IN_VLABELS (in), TY_CHAR) + call mfree (IN_VUNITS (in), TY_CHAR) + call mfree (IN_USERLABELS (in), TY_CHAR) + call mfree (IN_USERUNITS (in), TY_CHAR) + call mfree (IN_HELP (in), TY_CHAR) + call mfree (IN_PROMPT (in), TY_CHAR) + + # Free rejected point list, and limit values for variables. + if (IN_REJPTS (in) != NULL) + call mfree (IN_REJPTS (in), TY_INT) + if (IN_XMIN (in) != NULL) + call mfree (IN_XMIN (in), TY_PIXEL) + if (IN_XMAX (in) != NULL) + call mfree (IN_XMAX (in), TY_PIXEL) + + # Free substructures. + call mfree (IN_SFLOAT (in), TY_PIXEL) + call mfree (IN_SGAXES (in), TY_INT) + + # Free structure. + call mfree (in, TY_STRUCT) + } +end diff --git a/pkg/xtools/inlfit/infreed.x b/pkg/xtools/inlfit/infreed.x new file mode 100644 index 00000000..09f2c8ea --- /dev/null +++ b/pkg/xtools/inlfit/infreed.x @@ -0,0 +1,52 @@ +include "inlfitdef.h" + + +# IN_FREE -- Free INLFIT parameter structure, substructures, and auxiliary +# buffers. + +procedure in_freed (in) + +pointer in # INLFIT pointer + +begin + +# # Debug. +# call eprintf ("in_free: in=%d\n") +# call pargi (in) + + # Free only if it's not NULL. + if (in != NULL) { + + # Free parameter values, changes, and list. + call mfree (IN_PARAM (in), TY_DOUBLE) + call mfree (IN_DPARAM (in), TY_DOUBLE) + call mfree (IN_PLIST (in), TY_INT) + + # Free string space. + call mfree (IN_LABELS (in), TY_CHAR) + call mfree (IN_UNITS (in), TY_CHAR) + call mfree (IN_PLABELS (in), TY_CHAR) + call mfree (IN_PUNITS (in), TY_CHAR) + call mfree (IN_VLABELS (in), TY_CHAR) + call mfree (IN_VUNITS (in), TY_CHAR) + call mfree (IN_USERLABELS (in), TY_CHAR) + call mfree (IN_USERUNITS (in), TY_CHAR) + call mfree (IN_HELP (in), TY_CHAR) + call mfree (IN_PROMPT (in), TY_CHAR) + + # Free rejected point list, and limit values for variables. + if (IN_REJPTS (in) != NULL) + call mfree (IN_REJPTS (in), TY_INT) + if (IN_XMIN (in) != NULL) + call mfree (IN_XMIN (in), TY_DOUBLE) + if (IN_XMAX (in) != NULL) + call mfree (IN_XMAX (in), TY_DOUBLE) + + # Free substructures. + call mfree (IN_SFLOAT (in), TY_DOUBLE) + call mfree (IN_SGAXES (in), TY_INT) + + # Free structure. + call mfree (in, TY_STRUCT) + } +end diff --git a/pkg/xtools/inlfit/infreer.x b/pkg/xtools/inlfit/infreer.x new file mode 100644 index 00000000..55136dfd --- /dev/null +++ b/pkg/xtools/inlfit/infreer.x @@ -0,0 +1,52 @@ +include "inlfitdef.h" + + +# IN_FREE -- Free INLFIT parameter structure, substructures, and auxiliary +# buffers. + +procedure in_freer (in) + +pointer in # INLFIT pointer + +begin + +# # Debug. +# call eprintf ("in_free: in=%d\n") +# call pargi (in) + + # Free only if it's not NULL. + if (in != NULL) { + + # Free parameter values, changes, and list. + call mfree (IN_PARAM (in), TY_REAL) + call mfree (IN_DPARAM (in), TY_REAL) + call mfree (IN_PLIST (in), TY_INT) + + # Free string space. + call mfree (IN_LABELS (in), TY_CHAR) + call mfree (IN_UNITS (in), TY_CHAR) + call mfree (IN_PLABELS (in), TY_CHAR) + call mfree (IN_PUNITS (in), TY_CHAR) + call mfree (IN_VLABELS (in), TY_CHAR) + call mfree (IN_VUNITS (in), TY_CHAR) + call mfree (IN_USERLABELS (in), TY_CHAR) + call mfree (IN_USERUNITS (in), TY_CHAR) + call mfree (IN_HELP (in), TY_CHAR) + call mfree (IN_PROMPT (in), TY_CHAR) + + # Free rejected point list, and limit values for variables. + if (IN_REJPTS (in) != NULL) + call mfree (IN_REJPTS (in), TY_INT) + if (IN_XMIN (in) != NULL) + call mfree (IN_XMIN (in), TY_REAL) + if (IN_XMAX (in) != NULL) + call mfree (IN_XMAX (in), TY_REAL) + + # Free substructures. + call mfree (IN_SFLOAT (in), TY_REAL) + call mfree (IN_SGAXES (in), TY_INT) + + # Free structure. + call mfree (in, TY_STRUCT) + } +end diff --git a/pkg/xtools/inlfit/ingaxes.gx b/pkg/xtools/inlfit/ingaxes.gx new file mode 100644 index 00000000..d836e074 --- /dev/null +++ b/pkg/xtools/inlfit/ingaxes.gx @@ -0,0 +1,105 @@ +include <pkg/gtools.h> +include <pkg/inlfit.h> + +# ING_AXES -- Set axes data. The applications program may set additional +# axes types. + +procedure ing_axes$t (in, gt, nl, axis, x, y, z, npts, nvars) + +pointer in # INLFIT pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +int axis # Output axis +PIXEL x[ARB] # Independent variables (npts * nvars) +PIXEL y[npts] # Dependent variable +PIXEL z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int i, j +int axistype, axisnum +int gtlabel[2], gtunits[2] +PIXEL a, b, xmin, xmax +pointer sp, label, units, minptr, maxptr + +PIXEL nleval$t() +PIXEL ing_dvz$t() +errchk adiv$t() +extern ing_dvz$t() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (label, SZ_LINE, TY_CHAR) + call salloc (units, SZ_LINE, TY_CHAR) + + # Get the appropiate axis type and variable number. + call in_gkey (in, in_geti (in, INLGKEY), axis, axistype, axisnum) + + # Get and set axes labels and units. + call ing_getlabel (in, axistype, axisnum, Memc[label], Memc[units], + SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + + # Branch on axis type. + switch (axistype) { + case KEY_VARIABLE: # Independent variable + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + case KEY_FUNCTION: # Function variable + call amov$t (y, z, npts) + case KEY_FIT: # Fitted values + call nlvector$t (nl, x, z, npts, nvars) + case KEY_RESIDUALS: # Residuals + call nlvector$t (nl, x, z, npts, nvars) + call asub$t (y, z, z, npts) + case KEY_RATIO: # Ratio + call nlvector$t (nl, x, z, npts, nvars) + call advz$t (y, z, z, npts, ing_dvz$t) + case KEY_NONLINEAR: # Linear component removed + call aclr$t (z, npts) + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + a = nleval$t (nl, Mem$t[minptr], nvars) + do i = 1, nvars { + xmin = Mem$t[minptr+i-1] + xmax = Mem$t[maxptr+i-1] + Mem$t[minptr+i-1] = xmax + b = (nleval$t (nl, Mem$t[minptr], nvars) - a) / + (xmax - xmin) + Mem$t[minptr+i-1] = xmin + do j = 1, npts + z[j] = z[j] + y[j] - a - b * (x[(j-1)*nvars+i] - xmin) + } + case KEY_UAXIS: # User axes plots. + if (axis == 1) { + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + } else + call amov$t (y, z, npts) + call ing_uaxes$t (axisnum, in, nl, x, y, z, npts, nvars) + default: + call error (0, "ing_axes: Unknown axis type") + } + + # Free memory. + call sfree (sp) +end + + +# ING_DVZ -- Error action to take on zero division. + +PIXEL procedure ing_dvz$t (x) + +PIXEL x # Numerator + +begin + return (PIXEL (1.0)) +end diff --git a/pkg/xtools/inlfit/ingaxesd.x b/pkg/xtools/inlfit/ingaxesd.x new file mode 100644 index 00000000..9a9816a6 --- /dev/null +++ b/pkg/xtools/inlfit/ingaxesd.x @@ -0,0 +1,105 @@ +include <pkg/gtools.h> +include <pkg/inlfit.h> + +# ING_AXES -- Set axes data. The applications program may set additional +# axes types. + +procedure ing_axesd (in, gt, nl, axis, x, y, z, npts, nvars) + +pointer in # INLFIT pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +int axis # Output axis +double x[ARB] # Independent variables (npts * nvars) +double y[npts] # Dependent variable +double z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int i, j +int axistype, axisnum +int gtlabel[2], gtunits[2] +double a, b, xmin, xmax +pointer sp, label, units, minptr, maxptr + +double nlevald() +double ing_dvzd() +errchk adivd() +extern ing_dvzd() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (label, SZ_LINE, TY_CHAR) + call salloc (units, SZ_LINE, TY_CHAR) + + # Get the appropiate axis type and variable number. + call in_gkey (in, in_geti (in, INLGKEY), axis, axistype, axisnum) + + # Get and set axes labels and units. + call ing_getlabel (in, axistype, axisnum, Memc[label], Memc[units], + SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + + # Branch on axis type. + switch (axistype) { + case KEY_VARIABLE: # Independent variable + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + case KEY_FUNCTION: # Function variable + call amovd (y, z, npts) + case KEY_FIT: # Fitted values + call nlvectord (nl, x, z, npts, nvars) + case KEY_RESIDUALS: # Residuals + call nlvectord (nl, x, z, npts, nvars) + call asubd (y, z, z, npts) + case KEY_RATIO: # Ratio + call nlvectord (nl, x, z, npts, nvars) + call advzd (y, z, z, npts, ing_dvzd) + case KEY_NONLINEAR: # Linear component removed + call aclrd (z, npts) + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + a = nlevald (nl, Memd[minptr], nvars) + do i = 1, nvars { + xmin = Memd[minptr+i-1] + xmax = Memd[maxptr+i-1] + Memd[minptr+i-1] = xmax + b = (nlevald (nl, Memd[minptr], nvars) - a) / + (xmax - xmin) + Memd[minptr+i-1] = xmin + do j = 1, npts + z[j] = z[j] + y[j] - a - b * (x[(j-1)*nvars+i] - xmin) + } + case KEY_UAXIS: # User axes plots. + if (axis == 1) { + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + } else + call amovd (y, z, npts) + call ing_uaxesd (axisnum, in, nl, x, y, z, npts, nvars) + default: + call error (0, "ing_axes: Unknown axis type") + } + + # Free memory. + call sfree (sp) +end + + +# ING_DVZ -- Error action to take on zero division. + +double procedure ing_dvzd (x) + +double x # Numerator + +begin + return (double (1.0)) +end diff --git a/pkg/xtools/inlfit/ingaxesr.x b/pkg/xtools/inlfit/ingaxesr.x new file mode 100644 index 00000000..5af7f3d8 --- /dev/null +++ b/pkg/xtools/inlfit/ingaxesr.x @@ -0,0 +1,105 @@ +include <pkg/gtools.h> +include <pkg/inlfit.h> + +# ING_AXES -- Set axes data. The applications program may set additional +# axes types. + +procedure ing_axesr (in, gt, nl, axis, x, y, z, npts, nvars) + +pointer in # INLFIT pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +int axis # Output axis +real x[ARB] # Independent variables (npts * nvars) +real y[npts] # Dependent variable +real z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int i, j +int axistype, axisnum +int gtlabel[2], gtunits[2] +real a, b, xmin, xmax +pointer sp, label, units, minptr, maxptr + +real nlevalr() +real ing_dvzr() +errchk adivr() +extern ing_dvzr() + +data gtlabel/GTXLABEL, GTYLABEL/ +data gtunits/GTXUNITS, GTYUNITS/ + +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (label, SZ_LINE, TY_CHAR) + call salloc (units, SZ_LINE, TY_CHAR) + + # Get the appropiate axis type and variable number. + call in_gkey (in, in_geti (in, INLGKEY), axis, axistype, axisnum) + + # Get and set axes labels and units. + call ing_getlabel (in, axistype, axisnum, Memc[label], Memc[units], + SZ_LINE) + call gt_sets (gt, gtlabel[axis], Memc[label]) + call gt_sets (gt, gtunits[axis], Memc[units]) + + # Branch on axis type. + switch (axistype) { + case KEY_VARIABLE: # Independent variable + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + case KEY_FUNCTION: # Function variable + call amovr (y, z, npts) + case KEY_FIT: # Fitted values + call nlvectorr (nl, x, z, npts, nvars) + case KEY_RESIDUALS: # Residuals + call nlvectorr (nl, x, z, npts, nvars) + call asubr (y, z, z, npts) + case KEY_RATIO: # Ratio + call nlvectorr (nl, x, z, npts, nvars) + call advzr (y, z, z, npts, ing_dvzr) + case KEY_NONLINEAR: # Linear component removed + call aclrr (z, npts) + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + a = nlevalr (nl, Memr[minptr], nvars) + do i = 1, nvars { + xmin = Memr[minptr+i-1] + xmax = Memr[maxptr+i-1] + Memr[minptr+i-1] = xmax + b = (nlevalr (nl, Memr[minptr], nvars) - a) / + (xmax - xmin) + Memr[minptr+i-1] = xmin + do j = 1, npts + z[j] = z[j] + y[j] - a - b * (x[(j-1)*nvars+i] - xmin) + } + case KEY_UAXIS: # User axes plots. + if (axis == 1) { + do i = 1, npts + z[i] = x[(i-1)*nvars+axisnum] + } else + call amovr (y, z, npts) + call ing_uaxesr (axisnum, in, nl, x, y, z, npts, nvars) + default: + call error (0, "ing_axes: Unknown axis type") + } + + # Free memory. + call sfree (sp) +end + + +# ING_DVZ -- Error action to take on zero division. + +real procedure ing_dvzr (x) + +real x # Numerator + +begin + return (real (1.0)) +end diff --git a/pkg/xtools/inlfit/ingcolon.gx b/pkg/xtools/inlfit/ingcolon.gx new file mode 100644 index 00000000..5b9f7bfb --- /dev/null +++ b/pkg/xtools/inlfit/ingcolon.gx @@ -0,0 +1,362 @@ +include <gset.h> +include <error.h> +include <pkg/inlfit.h> + +# List of colon commands. +define CMDS "|show|low_reject|high_reject|nreject|grow|errors|vshow|constant|\ +fit|tolerance|maxiter|variables|data|page|results|" + +define SHOW 1 # Show fit information +define LOW_REJECT 2 # Set or show lower rejection factor +define HIGH_REJECT 3 # Set or show upper rejection factor +define NREJECT 4 # Set or show rejection iterations +define GROW 5 # Set or show rejection growing radius +define ERRORS 6 # Show fit errors +define VSHOW 7 # Show verbose information +define CONSTANT 8 # Set constant parameter +define FIT 9 # Set fitting parameter +define TOL 10 # Set or show fitting tolerance +define MAXITER 11 # Set or show max number of iterations +define VARIABLES 12 # List the variables +define DATA 13 # List of data +define PAGE 14 # Page through a file +define RESULTS 15 # List the results of the fit + + +# ING_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure ing_colon$t (in, cmdstr, gp, gt, nl, x, y, wts, names, npts, nvars, + len_name, newgraph) + +pointer in # INLFIT pointer +char cmdstr[ARB] # Command string +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer for error listing +PIXEL x[ARB] # Independent variabels (npts * nvars) +PIXEL y[npts] # dependent variables +PIXEL wts[npts] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of object name +int newgraph # New graph ? + +int ncmd, ival +PIXEL fval +pointer sp, cmd + +int nscan(), strdic() +int in_geti() +PIXEL in_get$t() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # 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 sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CMDS) + + # Branch on command code. + switch (ncmd) { + case SHOW: # :show - Show the values of the fitting parameters. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_show$t (in, "STDOUT") + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_show$t (in, Memc[cmd]) + } then + call erract (EA_WARN) + } + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call garg$t (fval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call parg$t (in_get$t (in, INLLOW)) + } else + call in_put$t (in, INLLOW, fval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call garg$t (fval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call parg$t (in_get$t (in, INLHIGH)) + } else + call in_put$t (in, INLHIGH, fval) + + case NREJECT: # :nreject - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("nreject = %d\n") + call pargi (in_geti (in, INLNREJECT)) + } else + call in_puti (in, INLNREJECT, ival) + + case GROW: # :grow - List or set the rejection growing. + call garg$t (fval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call parg$t (in_get$t (in, INLGROW)) + } else + call in_put$t (in, INLGROW, fval) + + case ERRORS: # :errors - print errors analysis of fit + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_show$t (in, "STDOUT") + call ing_errors$t (in, "STDOUT", nl, x, y, wts, npts, nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_show$t (in, Memc[cmd]) + call ing_errors$t (in, Memc[cmd], nl, x, y, wts, npts, + nvars) + } then + call erract (EA_WARN) + } + + case VSHOW: # Verbose list of the fitting parameters and results. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_vshow$t (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name, gt) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_vshow$t (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name, gt) + } then + call erract (EA_WARN) + } + + case CONSTANT: # Set constant parameter. + call ing_change$t (in, CONSTANT) + + case FIT: # Set fitting parameter. + call ing_change$t (in, FIT) + + case TOL: # Set or show tolerance. + call garg$t (fval) + if (nscan() == 1) { + call printf ("tol = %g\n") + call parg$t (in_get$t (in, INLTOLERANCE)) + } else + call in_put$t (in, INLTOLERANCE, fval) + + case MAXITER: # Set or show max number of iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("maxiter = %d\n") + call pargi (in_geti (in, INLMAXITER)) + } else + call in_puti (in, INLMAXITER, ival) + + case VARIABLES: # Show the list of variables. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_variables$t (in, "STDOUT", nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_variables$t (in, Memc[cmd], nvars) + } then + call erract (EA_WARN) + } + + case DATA: # List the raw data. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_data$t (in, "STDOUT", x, names, npts, nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_data$t (in, Memc[cmd], x, names, npts, nvars, + len_name) + } then + call erract (EA_WARN) + } + + case PAGE: # Page through a file. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) + call printf ("File to be paged is undefined\n") + else + call gpagefile (gp, Memc[cmd], "") + + case RESULTS: # List the results of the fit. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_results$t (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_results$t (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name) + } then + call erract (EA_WARN) + } + + default: # User definable action. + call ing_ucolon$t (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + } + + # Free memory + call sfree (sp) +end + + +# ING_CHANGE -- Change fitting parameter into constant parameter, and +# viceversa. Parameters can be specified either by a name, supplied in +# the parameter labels, or just by a sequence number. + +procedure ing_change$t (in, type) + +pointer in # INLFIT descriptor +int type # parameter type (fit, constant) + +bool isfit +int ip, pos, number, npars +PIXEL $tval +pointer param, value, pname +pointer pvalues, plist, plabels +pointer sp + +bool streq() +int ctoi(), cto$t() +int strdic() +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (param, SZ_LINE, TY_CHAR) + call salloc (value, SZ_LINE, TY_CHAR) + call salloc (pname, SZ_LINE, TY_CHAR) + call salloc (plabels, SZ_LINE, TY_CHAR) + + # Get parameter name. + Memc[param] = EOS + call gargwrd (Memc[param], SZ_LINE) + if (streq (Memc[param], "")) { + call eprintf ("Parameter not specified\n") + call sfree (sp) + return + } + + # Try to find the parameter name in the parameter labels. + call in_gstr (in, INLPLABELS, Memc[plabels], SZ_LINE) + number = strdic (Memc[param], Memc[pname], SZ_LINE, Memc[plabels]) + + # Try to find the parameter by number if it was not found + # by name in the dictionary. + if (number == 0) { + ip = 1 + if (ctoi (Memc[param], ip, number) == 0) { + call eprintf ("Parameter not found (%s)\n") + call pargstr (Memc[param]) + call sfree (sp) + return + } + } + + # Test parameter number. + npars = in_geti (in, INLNPARAMS) + if (number < 1 || number > npars) { + call eprintf ("Parameter out of range (%d)\n") + call pargi (number) + call sfree (sp) + return + } + + # Get pointers to parameter values and list. + pvalues = in_getp (in, INLPARAM) + plist = in_getp (in, INLPLIST) + + # Get new value if specified. Otherwise assume + # old parameter value. + Memc[value] = EOS + call gargwrd (Memc[value], SZ_LINE) + if (streq (Memc[value], "")) + $tval = Mem$t[pvalues + number - 1] + else { + ip = 1 + if (cto$t (Memc[value], ip, $tval) == 0) { + call eprintf ("Bad parameter value (%s)\n") + call pargstr (Memc[value]) + call sfree (sp) + return + } + } + + # Update parameter value. + Mem$t[pvalues + number - 1] = $tval + + # Find the parameter position in the parameter list. + do pos = 1, npars { + if (Memi[plist + pos - 1] >= number || + Memi[plist + pos - 1] == 0) + break + } + + # Insert or remove parameter from the parameter list + # according with its type, i.e., with the type of change. + # The list is not changed if it's not necesary to do so. + + if (type == FIT) { + if (Memi[plist + pos - 1] != number) { + do ip = npars, pos + 1, -1 + Memi[plist + ip - 1] = Memi[plist + ip - 2] + Memi[plist + pos - 1] = number + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) + 1) + } + isfit = true + } else { + if (Memi[plist + pos - 1] == number) { + do ip = pos, npars - 1 + Memi[plist + ip - 1] = Memi[plist + ip] + Memi[plist + npars - 1] = 0 + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) - 1) + } + isfit = false + } + + # Print setting. + call printf ("(%s) changed to %s parameter, with value=%g\n") + call pargstr (Memc[pname]) + if (isfit) + call pargstr ("fitting") + else + call pargstr ("constant") + call parg$t ($tval) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingcolond.x b/pkg/xtools/inlfit/ingcolond.x new file mode 100644 index 00000000..453895e3 --- /dev/null +++ b/pkg/xtools/inlfit/ingcolond.x @@ -0,0 +1,362 @@ +include <gset.h> +include <error.h> +include <pkg/inlfit.h> + +# List of colon commands. +define CMDS "|show|low_reject|high_reject|nreject|grow|errors|vshow|constant|\ +fit|tolerance|maxiter|variables|data|page|results|" + +define SHOW 1 # Show fit information +define LOW_REJECT 2 # Set or show lower rejection factor +define HIGH_REJECT 3 # Set or show upper rejection factor +define NREJECT 4 # Set or show rejection iterations +define GROW 5 # Set or show rejection growing radius +define ERRORS 6 # Show fit errors +define VSHOW 7 # Show verbose information +define CONSTANT 8 # Set constant parameter +define FIT 9 # Set fitting parameter +define TOL 10 # Set or show fitting tolerance +define MAXITER 11 # Set or show max number of iterations +define VARIABLES 12 # List the variables +define DATA 13 # List of data +define PAGE 14 # Page through a file +define RESULTS 15 # List the results of the fit + + +# ING_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure ing_colond (in, cmdstr, gp, gt, nl, x, y, wts, names, npts, nvars, + len_name, newgraph) + +pointer in # INLFIT pointer +char cmdstr[ARB] # Command string +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer for error listing +double x[ARB] # Independent variabels (npts * nvars) +double y[npts] # dependent variables +double wts[npts] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of object name +int newgraph # New graph ? + +int ncmd, ival +double fval +pointer sp, cmd + +int nscan(), strdic() +int in_geti() +double in_getd() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # 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 sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CMDS) + + # Branch on command code. + switch (ncmd) { + case SHOW: # :show - Show the values of the fitting parameters. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_showd (in, "STDOUT") + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_showd (in, Memc[cmd]) + } then + call erract (EA_WARN) + } + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call gargd (fval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call pargd (in_getd (in, INLLOW)) + } else + call in_putd (in, INLLOW, fval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call gargd (fval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call pargd (in_getd (in, INLHIGH)) + } else + call in_putd (in, INLHIGH, fval) + + case NREJECT: # :nreject - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("nreject = %d\n") + call pargi (in_geti (in, INLNREJECT)) + } else + call in_puti (in, INLNREJECT, ival) + + case GROW: # :grow - List or set the rejection growing. + call gargd (fval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call pargd (in_getd (in, INLGROW)) + } else + call in_putd (in, INLGROW, fval) + + case ERRORS: # :errors - print errors analysis of fit + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_showd (in, "STDOUT") + call ing_errorsd (in, "STDOUT", nl, x, y, wts, npts, nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_showd (in, Memc[cmd]) + call ing_errorsd (in, Memc[cmd], nl, x, y, wts, npts, + nvars) + } then + call erract (EA_WARN) + } + + case VSHOW: # Verbose list of the fitting parameters and results. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_vshowd (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name, gt) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_vshowd (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name, gt) + } then + call erract (EA_WARN) + } + + case CONSTANT: # Set constant parameter. + call ing_changed (in, CONSTANT) + + case FIT: # Set fitting parameter. + call ing_changed (in, FIT) + + case TOL: # Set or show tolerance. + call gargd (fval) + if (nscan() == 1) { + call printf ("tol = %g\n") + call pargd (in_getd (in, INLTOLERANCE)) + } else + call in_putd (in, INLTOLERANCE, fval) + + case MAXITER: # Set or show max number of iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("maxiter = %d\n") + call pargi (in_geti (in, INLMAXITER)) + } else + call in_puti (in, INLMAXITER, ival) + + case VARIABLES: # Show the list of variables. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_variablesd (in, "STDOUT", nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_variablesd (in, Memc[cmd], nvars) + } then + call erract (EA_WARN) + } + + case DATA: # List the raw data. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_datad (in, "STDOUT", x, names, npts, nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_datad (in, Memc[cmd], x, names, npts, nvars, + len_name) + } then + call erract (EA_WARN) + } + + case PAGE: # Page through a file. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) + call printf ("File to be paged is undefined\n") + else + call gpagefile (gp, Memc[cmd], "") + + case RESULTS: # List the results of the fit. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_resultsd (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_resultsd (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name) + } then + call erract (EA_WARN) + } + + default: # User definable action. + call ing_ucolond (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + } + + # Free memory + call sfree (sp) +end + + +# ING_CHANGE -- Change fitting parameter into constant parameter, and +# viceversa. Parameters can be specified either by a name, supplied in +# the parameter labels, or just by a sequence number. + +procedure ing_changed (in, type) + +pointer in # INLFIT descriptor +int type # parameter type (fit, constant) + +bool isfit +int ip, pos, number, npars +double dval +pointer param, value, pname +pointer pvalues, plist, plabels +pointer sp + +bool streq() +int ctoi(), ctod() +int strdic() +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (param, SZ_LINE, TY_CHAR) + call salloc (value, SZ_LINE, TY_CHAR) + call salloc (pname, SZ_LINE, TY_CHAR) + call salloc (plabels, SZ_LINE, TY_CHAR) + + # Get parameter name. + Memc[param] = EOS + call gargwrd (Memc[param], SZ_LINE) + if (streq (Memc[param], "")) { + call eprintf ("Parameter not specified\n") + call sfree (sp) + return + } + + # Try to find the parameter name in the parameter labels. + call in_gstr (in, INLPLABELS, Memc[plabels], SZ_LINE) + number = strdic (Memc[param], Memc[pname], SZ_LINE, Memc[plabels]) + + # Try to find the parameter by number if it was not found + # by name in the dictionary. + if (number == 0) { + ip = 1 + if (ctoi (Memc[param], ip, number) == 0) { + call eprintf ("Parameter not found (%s)\n") + call pargstr (Memc[param]) + call sfree (sp) + return + } + } + + # Test parameter number. + npars = in_geti (in, INLNPARAMS) + if (number < 1 || number > npars) { + call eprintf ("Parameter out of range (%d)\n") + call pargi (number) + call sfree (sp) + return + } + + # Get pointers to parameter values and list. + pvalues = in_getp (in, INLPARAM) + plist = in_getp (in, INLPLIST) + + # Get new value if specified. Otherwise assume + # old parameter value. + Memc[value] = EOS + call gargwrd (Memc[value], SZ_LINE) + if (streq (Memc[value], "")) + dval = Memd[pvalues + number - 1] + else { + ip = 1 + if (ctod (Memc[value], ip, dval) == 0) { + call eprintf ("Bad parameter value (%s)\n") + call pargstr (Memc[value]) + call sfree (sp) + return + } + } + + # Update parameter value. + Memd[pvalues + number - 1] = dval + + # Find the parameter position in the parameter list. + do pos = 1, npars { + if (Memi[plist + pos - 1] >= number || + Memi[plist + pos - 1] == 0) + break + } + + # Insert or remove parameter from the parameter list + # according with its type, i.e., with the type of change. + # The list is not changed if it's not necesary to do so. + + if (type == FIT) { + if (Memi[plist + pos - 1] != number) { + do ip = npars, pos + 1, -1 + Memi[plist + ip - 1] = Memi[plist + ip - 2] + Memi[plist + pos - 1] = number + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) + 1) + } + isfit = true + } else { + if (Memi[plist + pos - 1] == number) { + do ip = pos, npars - 1 + Memi[plist + ip - 1] = Memi[plist + ip] + Memi[plist + npars - 1] = 0 + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) - 1) + } + isfit = false + } + + # Print setting. + call printf ("(%s) changed to %s parameter, with value=%g\n") + call pargstr (Memc[pname]) + if (isfit) + call pargstr ("fitting") + else + call pargstr ("constant") + call pargd (dval) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingcolonr.x b/pkg/xtools/inlfit/ingcolonr.x new file mode 100644 index 00000000..b9179fc6 --- /dev/null +++ b/pkg/xtools/inlfit/ingcolonr.x @@ -0,0 +1,362 @@ +include <gset.h> +include <error.h> +include <pkg/inlfit.h> + +# List of colon commands. +define CMDS "|show|low_reject|high_reject|nreject|grow|errors|vshow|constant|\ +fit|tolerance|maxiter|variables|data|page|results|" + +define SHOW 1 # Show fit information +define LOW_REJECT 2 # Set or show lower rejection factor +define HIGH_REJECT 3 # Set or show upper rejection factor +define NREJECT 4 # Set or show rejection iterations +define GROW 5 # Set or show rejection growing radius +define ERRORS 6 # Show fit errors +define VSHOW 7 # Show verbose information +define CONSTANT 8 # Set constant parameter +define FIT 9 # Set fitting parameter +define TOL 10 # Set or show fitting tolerance +define MAXITER 11 # Set or show max number of iterations +define VARIABLES 12 # List the variables +define DATA 13 # List of data +define PAGE 14 # Page through a file +define RESULTS 15 # List the results of the fit + + +# ING_COLON -- Processes colon commands. The common flags and newgraph +# signal changes in fitting parameters or the need to redraw the graph. + +procedure ing_colonr (in, cmdstr, gp, gt, nl, x, y, wts, names, npts, nvars, + len_name, newgraph) + +pointer in # INLFIT pointer +char cmdstr[ARB] # Command string +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer for error listing +real x[ARB] # Independent variabels (npts * nvars) +real y[npts] # dependent variables +real wts[npts] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of object name +int newgraph # New graph ? + +int ncmd, ival +real fval +pointer sp, cmd + +int nscan(), strdic() +int in_geti() +real in_getr() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # 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 sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CMDS) + + # Branch on command code. + switch (ncmd) { + case SHOW: # :show - Show the values of the fitting parameters. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_showr (in, "STDOUT") + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_showr (in, Memc[cmd]) + } then + call erract (EA_WARN) + } + + case LOW_REJECT: # :low_reject - List or set lower rejection factor. + call gargr (fval) + if (nscan() == 1) { + call printf ("low_reject = %g\n") + call pargr (in_getr (in, INLLOW)) + } else + call in_putr (in, INLLOW, fval) + + case HIGH_REJECT: # :high_reject - List or set high rejection factor. + call gargr (fval) + if (nscan() == 1) { + call printf ("high_reject = %g\n") + call pargr (in_getr (in, INLHIGH)) + } else + call in_putr (in, INLHIGH, fval) + + case NREJECT: # :nreject - List or set the rejection iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("nreject = %d\n") + call pargi (in_geti (in, INLNREJECT)) + } else + call in_puti (in, INLNREJECT, ival) + + case GROW: # :grow - List or set the rejection growing. + call gargr (fval) + if (nscan() == 1) { + call printf ("grow = %g\n") + call pargr (in_getr (in, INLGROW)) + } else + call in_putr (in, INLGROW, fval) + + case ERRORS: # :errors - print errors analysis of fit + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_showr (in, "STDOUT") + call ing_errorsr (in, "STDOUT", nl, x, y, wts, npts, nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_showr (in, Memc[cmd]) + call ing_errorsr (in, Memc[cmd], nl, x, y, wts, npts, + nvars) + } then + call erract (EA_WARN) + } + + case VSHOW: # Verbose list of the fitting parameters and results. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_vshowr (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name, gt) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_vshowr (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name, gt) + } then + call erract (EA_WARN) + } + + case CONSTANT: # Set constant parameter. + call ing_changer (in, CONSTANT) + + case FIT: # Set fitting parameter. + call ing_changer (in, FIT) + + case TOL: # Set or show tolerance. + call gargr (fval) + if (nscan() == 1) { + call printf ("tol = %g\n") + call pargr (in_getr (in, INLTOLERANCE)) + } else + call in_putr (in, INLTOLERANCE, fval) + + case MAXITER: # Set or show max number of iterations. + call gargi (ival) + if (nscan() == 1) { + call printf ("maxiter = %d\n") + call pargi (in_geti (in, INLMAXITER)) + } else + call in_puti (in, INLMAXITER, ival) + + case VARIABLES: # Show the list of variables. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_variablesr (in, "STDOUT", nvars) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_variablesr (in, Memc[cmd], nvars) + } then + call erract (EA_WARN) + } + + case DATA: # List the raw data. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_datar (in, "STDOUT", x, names, npts, nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_datar (in, Memc[cmd], x, names, npts, nvars, + len_name) + } then + call erract (EA_WARN) + } + + case PAGE: # Page through a file. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) + call printf ("File to be paged is undefined\n") + else + call gpagefile (gp, Memc[cmd], "") + + case RESULTS: # List the results of the fit. + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call gdeactivate (gp, AW_CLEAR) + call ing_title (in, "STDOUT", gt) + call ing_resultsr (in, "STDOUT", nl, x, y, wts, names, npts, + nvars, len_name) + call greactivate (gp, AW_PAUSE) + } else { + iferr { + call ing_title (in, Memc[cmd], gt) + call ing_resultsr (in, Memc[cmd], nl, x, y, wts, names, + npts, nvars, len_name) + } then + call erract (EA_WARN) + } + + default: # User definable action. + call ing_ucolonr (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + } + + # Free memory + call sfree (sp) +end + + +# ING_CHANGE -- Change fitting parameter into constant parameter, and +# viceversa. Parameters can be specified either by a name, supplied in +# the parameter labels, or just by a sequence number. + +procedure ing_changer (in, type) + +pointer in # INLFIT descriptor +int type # parameter type (fit, constant) + +bool isfit +int ip, pos, number, npars +real rval +pointer param, value, pname +pointer pvalues, plist, plabels +pointer sp + +bool streq() +int ctoi(), ctor() +int strdic() +int in_geti() +pointer in_getp() + +begin + # Allocate string space. + call smark (sp) + call salloc (param, SZ_LINE, TY_CHAR) + call salloc (value, SZ_LINE, TY_CHAR) + call salloc (pname, SZ_LINE, TY_CHAR) + call salloc (plabels, SZ_LINE, TY_CHAR) + + # Get parameter name. + Memc[param] = EOS + call gargwrd (Memc[param], SZ_LINE) + if (streq (Memc[param], "")) { + call eprintf ("Parameter not specified\n") + call sfree (sp) + return + } + + # Try to find the parameter name in the parameter labels. + call in_gstr (in, INLPLABELS, Memc[plabels], SZ_LINE) + number = strdic (Memc[param], Memc[pname], SZ_LINE, Memc[plabels]) + + # Try to find the parameter by number if it was not found + # by name in the dictionary. + if (number == 0) { + ip = 1 + if (ctoi (Memc[param], ip, number) == 0) { + call eprintf ("Parameter not found (%s)\n") + call pargstr (Memc[param]) + call sfree (sp) + return + } + } + + # Test parameter number. + npars = in_geti (in, INLNPARAMS) + if (number < 1 || number > npars) { + call eprintf ("Parameter out of range (%d)\n") + call pargi (number) + call sfree (sp) + return + } + + # Get pointers to parameter values and list. + pvalues = in_getp (in, INLPARAM) + plist = in_getp (in, INLPLIST) + + # Get new value if specified. Otherwise assume + # old parameter value. + Memc[value] = EOS + call gargwrd (Memc[value], SZ_LINE) + if (streq (Memc[value], "")) + rval = Memr[pvalues + number - 1] + else { + ip = 1 + if (ctor (Memc[value], ip, rval) == 0) { + call eprintf ("Bad parameter value (%s)\n") + call pargstr (Memc[value]) + call sfree (sp) + return + } + } + + # Update parameter value. + Memr[pvalues + number - 1] = rval + + # Find the parameter position in the parameter list. + do pos = 1, npars { + if (Memi[plist + pos - 1] >= number || + Memi[plist + pos - 1] == 0) + break + } + + # Insert or remove parameter from the parameter list + # according with its type, i.e., with the type of change. + # The list is not changed if it's not necesary to do so. + + if (type == FIT) { + if (Memi[plist + pos - 1] != number) { + do ip = npars, pos + 1, -1 + Memi[plist + ip - 1] = Memi[plist + ip - 2] + Memi[plist + pos - 1] = number + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) + 1) + } + isfit = true + } else { + if (Memi[plist + pos - 1] == number) { + do ip = pos, npars - 1 + Memi[plist + ip - 1] = Memi[plist + ip] + Memi[plist + npars - 1] = 0 + call in_puti (in, INLNFPARAMS, in_geti (in, INLNFPARAMS) - 1) + } + isfit = false + } + + # Print setting. + call printf ("(%s) changed to %s parameter, with value=%g\n") + call pargstr (Memc[pname]) + if (isfit) + call pargstr ("fitting") + else + call pargstr ("constant") + call pargr (rval) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingdata.gx b/pkg/xtools/inlfit/ingdata.gx new file mode 100644 index 00000000..80637be1 --- /dev/null +++ b/pkg/xtools/inlfit/ingdata.gx @@ -0,0 +1,86 @@ +include <pkg/inlfit.h> + +define NPERLINE 5 + +# ING_DATA -- List the raw data on the screen. + +procedure ing_data$t (in, file, x, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +PIXEL x[ARB] # Ordinates (npts * nvars) +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of the name + +int i, j, fd +pointer sp, vnames, name +int open() +int inlstrwrd() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of data points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (vnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + + # Get the variable names. + call in_gstr (in, INLVLABELS, Memc[vnames], SZ_LINE) + + # Print title. + do j = 1, nvars + 1 { + if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "#") + } + if (j == 1) { + call fprintf (fd, "%14.14s ") + call pargstr ("objectid") + } else if (inlstrwrd (j-1, Memc[name], SZ_LINE, Memc[vnames]) != + 0) { + call fprintf (fd, "%14.14s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%12.12s%02.2d ") + call pargstr ("var") + call pargi (j-1) + } + } + call fprintf (fd, "\n") + + # List the variables values. + do i = 1, npts { + do j = 1, nvars + 1 { + if (j == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "%15.15s") + call pargstr (names[(i-1)*len_name+1]) + } else if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "*%14.7g") + call parg$t (x[(i-1)*nvars+j-1]) + } else { + call fprintf (fd, " %14.7g") + call parg$t (x[(i-1)*nvars+j-1]) + } + } + } + call fprintf (fd, "\n\n") + + # Free allocated memory and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingdatad.x b/pkg/xtools/inlfit/ingdatad.x new file mode 100644 index 00000000..c1a82797 --- /dev/null +++ b/pkg/xtools/inlfit/ingdatad.x @@ -0,0 +1,86 @@ +include <pkg/inlfit.h> + +define NPERLINE 5 + +# ING_DATA -- List the raw data on the screen. + +procedure ing_datad (in, file, x, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +double x[ARB] # Ordinates (npts * nvars) +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of the name + +int i, j, fd +pointer sp, vnames, name +int open() +int inlstrwrd() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of data points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (vnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + + # Get the variable names. + call in_gstr (in, INLVLABELS, Memc[vnames], SZ_LINE) + + # Print title. + do j = 1, nvars + 1 { + if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "#") + } + if (j == 1) { + call fprintf (fd, "%14.14s ") + call pargstr ("objectid") + } else if (inlstrwrd (j-1, Memc[name], SZ_LINE, Memc[vnames]) != + 0) { + call fprintf (fd, "%14.14s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%12.12s%02.2d ") + call pargstr ("var") + call pargi (j-1) + } + } + call fprintf (fd, "\n") + + # List the variables values. + do i = 1, npts { + do j = 1, nvars + 1 { + if (j == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "%15.15s") + call pargstr (names[(i-1)*len_name+1]) + } else if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "*%14.7g") + call pargd (x[(i-1)*nvars+j-1]) + } else { + call fprintf (fd, " %14.7g") + call pargd (x[(i-1)*nvars+j-1]) + } + } + } + call fprintf (fd, "\n\n") + + # Free allocated memory and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingdatar.x b/pkg/xtools/inlfit/ingdatar.x new file mode 100644 index 00000000..21674540 --- /dev/null +++ b/pkg/xtools/inlfit/ingdatar.x @@ -0,0 +1,86 @@ +include <pkg/inlfit.h> + +define NPERLINE 5 + +# ING_DATA -- List the raw data on the screen. + +procedure ing_datar (in, file, x, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +real x[ARB] # Ordinates (npts * nvars) +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of the name + +int i, j, fd +pointer sp, vnames, name +int open() +int inlstrwrd() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of data points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (vnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + + # Get the variable names. + call in_gstr (in, INLVLABELS, Memc[vnames], SZ_LINE) + + # Print title. + do j = 1, nvars + 1 { + if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "#") + } + if (j == 1) { + call fprintf (fd, "%14.14s ") + call pargstr ("objectid") + } else if (inlstrwrd (j-1, Memc[name], SZ_LINE, Memc[vnames]) != + 0) { + call fprintf (fd, "%14.14s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%12.12s%02.2d ") + call pargstr ("var") + call pargi (j-1) + } + } + call fprintf (fd, "\n") + + # List the variables values. + do i = 1, npts { + do j = 1, nvars + 1 { + if (j == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "%15.15s") + call pargstr (names[(i-1)*len_name+1]) + } else if (mod (j, NPERLINE) == 1) { + call fprintf (fd, "\n") + call fprintf (fd, "*%14.7g") + call pargr (x[(i-1)*nvars+j-1]) + } else { + call fprintf (fd, " %14.7g") + call pargr (x[(i-1)*nvars+j-1]) + } + } + } + call fprintf (fd, "\n\n") + + # Free allocated memory and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingdefkey.x b/pkg/xtools/inlfit/ingdefkey.x new file mode 100644 index 00000000..2154389d --- /dev/null +++ b/pkg/xtools/inlfit/ingdefkey.x @@ -0,0 +1,182 @@ +include "inlfitdef.h" +include <pkg/inlfit.h> + +# Abort label +define abort 9999 + + +# ING_DEFKEY - Define graph keys + +procedure ing_defkey (in, nvars, newgraph) + +pointer in # INLFIT descriptor +int nvars # number of variables +int newgraph # update graph ? + +char ch +int key # graph key +int axis # axis number +int type[2], num[2] # key types and numbers +int n, ip +pointer line, word, vlabels, str, sp + +int scan() +int ctoi() +int strdic(), strlen() +int inlstrext(), inlstrwrd() +int in_geti() + +begin + # Allocate string space. + call smark (sp) + call salloc (line, SZ_LINE + 1, TY_CHAR) + call salloc (word, SZ_LINE + 1, TY_CHAR) + call salloc (vlabels, SZ_LINE + 1, TY_CHAR) + call salloc (str, SZ_LINE + 1, TY_CHAR) + + # Get graph key to define. + call printf ("Graph key to be defined: ") + call flush (STDOUT) + if (scan() == EOF) + goto abort + call gargc (ch) + + # Convert key type into key number. + switch (ch) { + case '\n': + goto abort + case 'h', 'i', 'j', 'k', 'l': + switch (ch) { + case 'h': + key = 1 + case 'i': + key = 2 + case 'j': + key = 3 + case 'k': + key = 4 + case 'l': + key = 5 + } + default: + call eprintf ("Not a graph key, choose: [h, i, j, k, l]\n") + goto abort + } + + # Get variable label pointer. + call in_gstr (in, INLVLABELS, Memc[vlabels], SZ_LINE) + + # Print current settings for the axis types. + call printf ("Set graph axis types (") + do axis = 1, 2 { + call in_gkey (in, key, axis, type[axis], num[axis]) + switch (type[axis]) { + case KEY_FUNCTION: + call printf ("function") + case KEY_FIT: + call printf ("fit") + case KEY_RESIDUALS: + call printf ("residuals") + case KEY_RATIO: + call printf ("ratio") + case KEY_NONLINEAR: + call printf ("nonlinear") + case KEY_UAXIS: + call sprintf (Memc[str], SZ_LINE, "user%d") + call pargi (num[axis]) + call printf (Memc[str]) + case KEY_VARIABLE: + if (inlstrwrd (num[axis], Memc[str], SZ_LINE, + Memc[vlabels]) != 0) + call printf (Memc[str]) + else { + call sprintf (Memc[str], SZ_LINE, "var%d") + call pargi (num[axis]) + call printf (Memc[str]) + } + default: + call error (0, "ing_defkey: Illegal key type") + } + if (axis == 1) + call printf (", ") + } + call printf (") : ") + call flush (STDOUT) + + # Get line from the input stream. + if (scan() == EOF) + goto abort + call gargstr (Memc[line], SZ_LINE) + + # Get new axis types from input line. + ip = 1 + axis = 1 + call sscan (Memc[line]) + while (axis <= 2) { + + # Get word from line. + if (inlstrext (Memc[line], ip, ", ", YES, Memc[word], + SZ_LINE) == 0) { + if (axis == 2) + call eprintf ("Incomplete definition, usage: X,Y\n") + goto abort + } + + # Search for word in the type dictionary. Keywords can + # be abreviated up to three characters to avoid conflicts + # with user variables. + if (strlen (Memc[word]) >= 3) + type[axis] = strdic (Memc[word], Memc[str], SZ_LINE, KEY_TYPES) + else + type[axis] = 0 + + # Check type. + if (type[axis] == 0) { + type[axis] = KEY_VARIABLE + num[axis] = strdic (Memc[word], Memc[str], SZ_LINE, + Memc[vlabels]) + if (num[axis] == 0) { + call eprintf ("Not a defined key type (%s), choose: [%s]\n") + call pargstr (Memc[word]) + call pargstr (Memc[vlabels]) + goto abort + } + } else if (type[axis] == KEY_VARIABLE || type[axis] == + KEY_UAXIS) { + if (inlstrext (Memc[line], ip, ", ", YES, Memc[word], + SZ_LINE) == 0) { + call eprintf ("Incomplete definition, usage: X,Y\n") + goto abort + } + n = 1 + if (ctoi (Memc[word], n, num[axis]) == 0) { + call eprintf ( "Not a valid var/user number (%s)\n") + call pargstr (Memc[word]) + goto abort + } + if (type[axis] == KEY_VARIABLE && num[axis] > nvars) { + call eprintf ( "Variable number does not exist (%s)\n") + call pargstr (Memc[word]) + goto abort + } + } else + num[axis] = INDEFI + + # Count axis + axis = axis + 1 + } + + # Update axis types. + call in_pkey (in, key, 1, type[1], num[1]) + call in_pkey (in, key, 2, type[2], num[2]) + + # Test if screen needs to be refreshed. + if (in_geti (in, INLGKEY) == key) + newgraph = YES + else + newgraph = NO + +abort + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingdelete.gx b/pkg/xtools/inlfit/ingdelete.gx new file mode 100644 index 00000000..c4cac6d7 --- /dev/null +++ b/pkg/xtools/inlfit/ingdelete.gx @@ -0,0 +1,87 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure ing_delete$t (in, gp, gt, nl, x, y, wts, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variables (npts * nvars) +PIXEL y[npts] # Dependent variables +PIXEL wts[npts] # Weight array +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + # Get axes data + call ing_axes$t (in, gt, nl, 1, x, y, Mem$t[xout], npts, nvars) + call ing_axes$t (in, gt, nl, 2, x, y, Mem$t[yout], npts, nvars) + + # Transpose axes if necessary + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_d1$t (in, gp, Mem$t[xout], Mem$t[yout], wts, npts, wx, wy) + else + call ing_d1$t (in, gp, Mem$t[yout], Mem$t[xout], wts, npts, wy, wx) + + # Free memory + call sfree (sp) +end + + +# ING_D1 -- Do the actual delete. Mark deleted point with zero weigth. + +procedure ing_d1$t (in, gp, x, y, wts, npts, wx, wy) + +pointer in # ICFIT pointer +pointer gp # GIO pointer +PIXEL x[npts], y[npts] # Data points +PIXEL wts[npts] # Weight array +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] == PIXEL (0.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] = PIXEL (0.0) + } +end diff --git a/pkg/xtools/inlfit/ingdeleted.x b/pkg/xtools/inlfit/ingdeleted.x new file mode 100644 index 00000000..47f66b06 --- /dev/null +++ b/pkg/xtools/inlfit/ingdeleted.x @@ -0,0 +1,87 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure ing_deleted (in, gp, gt, nl, x, y, wts, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +double x[ARB] # Independent variables (npts * nvars) +double y[npts] # Dependent variables +double wts[npts] # Weight array +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + # Get axes data + call ing_axesd (in, gt, nl, 1, x, y, Memd[xout], npts, nvars) + call ing_axesd (in, gt, nl, 2, x, y, Memd[yout], npts, nvars) + + # Transpose axes if necessary + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_d1d (in, gp, Memd[xout], Memd[yout], wts, npts, wx, wy) + else + call ing_d1d (in, gp, Memd[yout], Memd[xout], wts, npts, wy, wx) + + # Free memory + call sfree (sp) +end + + +# ING_D1 -- Do the actual delete. Mark deleted point with zero weigth. + +procedure ing_d1d (in, gp, x, y, wts, npts, wx, wy) + +pointer in # ICFIT pointer +pointer gp # GIO pointer +double x[npts], y[npts] # Data points +double wts[npts] # Weight array +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] == double (0.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] = double (0.0) + } +end diff --git a/pkg/xtools/inlfit/ingdeleter.x b/pkg/xtools/inlfit/ingdeleter.x new file mode 100644 index 00000000..27fbd16c --- /dev/null +++ b/pkg/xtools/inlfit/ingdeleter.x @@ -0,0 +1,87 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_DELETE -- Delete data point nearest the cursor. +# The nearest point to the cursor in NDC coordinates is determined. + +procedure ing_deleter (in, gp, gt, nl, x, y, wts, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +real x[ARB] # Independent variables (npts * nvars) +real y[npts] # Dependent variables +real wts[npts] # Weight array +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +int gt_geti() +pointer sp, xout, yout + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + # Get axes data + call ing_axesr (in, gt, nl, 1, x, y, Memr[xout], npts, nvars) + call ing_axesr (in, gt, nl, 2, x, y, Memr[yout], npts, nvars) + + # Transpose axes if necessary + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_d1r (in, gp, Memr[xout], Memr[yout], wts, npts, wx, wy) + else + call ing_d1r (in, gp, Memr[yout], Memr[xout], wts, npts, wy, wx) + + # Free memory + call sfree (sp) +end + + +# ING_D1 -- Do the actual delete. Mark deleted point with zero weigth. + +procedure ing_d1r (in, gp, x, y, wts, npts, wx, wy) + +pointer in # ICFIT pointer +pointer gp # GIO pointer +real x[npts], y[npts] # Data points +real wts[npts] # Weight array +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] == real (0.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] = real (0.0) + } +end diff --git a/pkg/xtools/inlfit/ingerrors.gx b/pkg/xtools/inlfit/ingerrors.gx new file mode 100644 index 00000000..1125a39a --- /dev/null +++ b/pkg/xtools/inlfit/ingerrors.gx @@ -0,0 +1,139 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_ERRORS -- Compute error diagnostic information and print it on the +# screen. + +procedure ing_errors$t (in, file, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables + +bool isfit +int i, j, deleted, rejected, nparams, fd +PIXEL chisqr, variance, rms +pointer sp, fit, wts1, params, errors, rejpts, plist +pointer name, pvnames, labels + +int open(), nlstati(), inlstrwrd(), in_geti() +pointer in_getp() +PIXEL in_rms$t(), nlstat$t() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Determine the number of coefficients. + nparams = nlstati (nl, NLNPARAMS) + + # Allocate memory for parameters, errors, and parameter list. + call smark (sp) + call salloc (params, nparams, TY_PIXEL) + call salloc (errors, nparams, TY_PIXEL) + call salloc (labels, SZ_LINE + 1, TY_CHAR) + + # Allocate memory for the fit and strings. + call salloc (fit, npts, TY_PIXEL) + call salloc (wts1, npts, TY_PIXEL) + call salloc (name, SZ_LINE + 1, TY_CHAR) + call salloc (pvnames, SZ_LINE + 1, TY_CHAR) + + # Get number of rejected points and rejected point list. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + + # Count deleted points. + deleted = 0 + do i = 1, npts { + if (wts[i] == PIXEL (0.0)) + deleted = deleted + 1 + } + + # Assign a zero weight to rejected points. + call amov$t (wts, Mem$t[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Mem$t[wts1+i-1] = PIXEL (0.0) + } + } + + # Get the parameter values and errors. + call nlvector$t (nl, x, Mem$t[fit], npts, nvars) + call nlpget$t (nl, Mem$t[params], nparams) + call nlerrors$t (nl, y, Mem$t[fit], Mem$t[wts1], npts, variance, + chisqr, Mem$t[errors]) + + # Compute the RMS. + rms = in_rms$t (y, Mem$t[fit], Mem$t[wts1], npts) + + # Print the error analysis. + call fprintf (fd, "\nniterations %d\n") + call pargi (nlstati (nl, NLITER)) + call fprintf (fd, "total_points %d\n") + call pargi (npts) + call fprintf (fd, "rejected %d\n") + call pargi (in_geti (in, INLNREJPTS)) + call fprintf (fd, "deleted %d\n") + call pargi (deleted) + call fprintf (fd, "standard deviation %10.7g\n") + call parg$t (sqrt (variance)) + call fprintf (fd, "reduced chi %10.7g\n") + call parg$t (sqrt (chisqr)) + call fprintf (fd, "average error %10.7g\n") + if (chisqr <= 0) + call parg$t (PIXEL(0.0)) + else + call parg$t (sqrt (max (variance, PIXEL (0.0)) / chisqr)) + call fprintf (fd, "average scatter %10.7g\n") + call parg$t (sqrt (nlstat$t (nl, NLSCATTER))) + call fprintf (fd, "RMS %10.7g\n") + call parg$t (rms) + + # Print parameter values and errors. + call in_gstr (in, INLPLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + call fprintf (fd, "\n%-10.10s %14.14s %14.14s\n") + call pargstr ("parameter") + call pargstr ("value") + call pargstr ("error") + plist = in_getp (in, INLPLIST) + do i = 1, nparams { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) != 0) { + call fprintf (fd, "%-10.10s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%-10.2d ") + call pargi (i) + } + call fprintf (fd, "%14.7f %14.7f (%s)\n") + call parg$t (Mem$t[params+i-1]) + call parg$t (Mem$t[errors+i-1]) + isfit = false + do j = 1, nparams { + if (Memi[plist+j-1] == i) { + isfit = true + break + } + } + if (isfit) + call pargstr ("fit") + else + call pargstr ("constant") + } + call fprintf (fd, "\n") + + # Free allocated memory. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingerrorsd.x b/pkg/xtools/inlfit/ingerrorsd.x new file mode 100644 index 00000000..44302b68 --- /dev/null +++ b/pkg/xtools/inlfit/ingerrorsd.x @@ -0,0 +1,139 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_ERRORS -- Compute error diagnostic information and print it on the +# screen. + +procedure ing_errorsd (in, file, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables + +bool isfit +int i, j, deleted, rejected, nparams, fd +double chisqr, variance, rms +pointer sp, fit, wts1, params, errors, rejpts, plist +pointer name, pvnames, labels + +int open(), nlstati(), inlstrwrd(), in_geti() +pointer in_getp() +double in_rmsd(), nlstatd() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Determine the number of coefficients. + nparams = nlstati (nl, NLNPARAMS) + + # Allocate memory for parameters, errors, and parameter list. + call smark (sp) + call salloc (params, nparams, TY_DOUBLE) + call salloc (errors, nparams, TY_DOUBLE) + call salloc (labels, SZ_LINE + 1, TY_CHAR) + + # Allocate memory for the fit and strings. + call salloc (fit, npts, TY_DOUBLE) + call salloc (wts1, npts, TY_DOUBLE) + call salloc (name, SZ_LINE + 1, TY_CHAR) + call salloc (pvnames, SZ_LINE + 1, TY_CHAR) + + # Get number of rejected points and rejected point list. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + + # Count deleted points. + deleted = 0 + do i = 1, npts { + if (wts[i] == double (0.0)) + deleted = deleted + 1 + } + + # Assign a zero weight to rejected points. + call amovd (wts, Memd[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memd[wts1+i-1] = double (0.0) + } + } + + # Get the parameter values and errors. + call nlvectord (nl, x, Memd[fit], npts, nvars) + call nlpgetd (nl, Memd[params], nparams) + call nlerrorsd (nl, y, Memd[fit], Memd[wts1], npts, variance, + chisqr, Memd[errors]) + + # Compute the RMS. + rms = in_rmsd (y, Memd[fit], Memd[wts1], npts) + + # Print the error analysis. + call fprintf (fd, "\nniterations %d\n") + call pargi (nlstati (nl, NLITER)) + call fprintf (fd, "total_points %d\n") + call pargi (npts) + call fprintf (fd, "rejected %d\n") + call pargi (in_geti (in, INLNREJPTS)) + call fprintf (fd, "deleted %d\n") + call pargi (deleted) + call fprintf (fd, "standard deviation %10.7g\n") + call pargd (sqrt (variance)) + call fprintf (fd, "reduced chi %10.7g\n") + call pargd (sqrt (chisqr)) + call fprintf (fd, "average error %10.7g\n") + if (chisqr <= 0) + call pargd (double(0.0)) + else + call pargd (sqrt (max (variance, double (0.0)) / chisqr)) + call fprintf (fd, "average scatter %10.7g\n") + call pargd (sqrt (nlstatd (nl, NLSCATTER))) + call fprintf (fd, "RMS %10.7g\n") + call pargd (rms) + + # Print parameter values and errors. + call in_gstr (in, INLPLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + call fprintf (fd, "\n%-10.10s %14.14s %14.14s\n") + call pargstr ("parameter") + call pargstr ("value") + call pargstr ("error") + plist = in_getp (in, INLPLIST) + do i = 1, nparams { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) != 0) { + call fprintf (fd, "%-10.10s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%-10.2d ") + call pargi (i) + } + call fprintf (fd, "%14.7f %14.7f (%s)\n") + call pargd (Memd[params+i-1]) + call pargd (Memd[errors+i-1]) + isfit = false + do j = 1, nparams { + if (Memi[plist+j-1] == i) { + isfit = true + break + } + } + if (isfit) + call pargstr ("fit") + else + call pargstr ("constant") + } + call fprintf (fd, "\n") + + # Free allocated memory. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingerrorsr.x b/pkg/xtools/inlfit/ingerrorsr.x new file mode 100644 index 00000000..7d1b86d4 --- /dev/null +++ b/pkg/xtools/inlfit/ingerrorsr.x @@ -0,0 +1,139 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_ERRORS -- Compute error diagnostic information and print it on the +# screen. + +procedure ing_errorsr (in, file, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables + +bool isfit +int i, j, deleted, rejected, nparams, fd +real chisqr, variance, rms +pointer sp, fit, wts1, params, errors, rejpts, plist +pointer name, pvnames, labels + +int open(), nlstati(), inlstrwrd(), in_geti() +pointer in_getp() +real in_rmsr(), nlstatr() +errchk open() + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Determine the number of coefficients. + nparams = nlstati (nl, NLNPARAMS) + + # Allocate memory for parameters, errors, and parameter list. + call smark (sp) + call salloc (params, nparams, TY_REAL) + call salloc (errors, nparams, TY_REAL) + call salloc (labels, SZ_LINE + 1, TY_CHAR) + + # Allocate memory for the fit and strings. + call salloc (fit, npts, TY_REAL) + call salloc (wts1, npts, TY_REAL) + call salloc (name, SZ_LINE + 1, TY_CHAR) + call salloc (pvnames, SZ_LINE + 1, TY_CHAR) + + # Get number of rejected points and rejected point list. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + + # Count deleted points. + deleted = 0 + do i = 1, npts { + if (wts[i] == real (0.0)) + deleted = deleted + 1 + } + + # Assign a zero weight to rejected points. + call amovr (wts, Memr[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memr[wts1+i-1] = real (0.0) + } + } + + # Get the parameter values and errors. + call nlvectorr (nl, x, Memr[fit], npts, nvars) + call nlpgetr (nl, Memr[params], nparams) + call nlerrorsr (nl, y, Memr[fit], Memr[wts1], npts, variance, + chisqr, Memr[errors]) + + # Compute the RMS. + rms = in_rmsr (y, Memr[fit], Memr[wts1], npts) + + # Print the error analysis. + call fprintf (fd, "\nniterations %d\n") + call pargi (nlstati (nl, NLITER)) + call fprintf (fd, "total_points %d\n") + call pargi (npts) + call fprintf (fd, "rejected %d\n") + call pargi (in_geti (in, INLNREJPTS)) + call fprintf (fd, "deleted %d\n") + call pargi (deleted) + call fprintf (fd, "standard deviation %10.7g\n") + call pargr (sqrt (variance)) + call fprintf (fd, "reduced chi %10.7g\n") + call pargr (sqrt (chisqr)) + call fprintf (fd, "average error %10.7g\n") + if (chisqr <= 0) + call pargr (real(0.0)) + else + call pargr (sqrt (max (variance, real (0.0)) / chisqr)) + call fprintf (fd, "average scatter %10.7g\n") + call pargr (sqrt (nlstatr (nl, NLSCATTER))) + call fprintf (fd, "RMS %10.7g\n") + call pargr (rms) + + # Print parameter values and errors. + call in_gstr (in, INLPLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + call fprintf (fd, "\n%-10.10s %14.14s %14.14s\n") + call pargstr ("parameter") + call pargstr ("value") + call pargstr ("error") + plist = in_getp (in, INLPLIST) + do i = 1, nparams { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) != 0) { + call fprintf (fd, "%-10.10s ") + call pargstr (Memc[name]) + } else { + call fprintf (fd, "%-10.2d ") + call pargi (i) + } + call fprintf (fd, "%14.7f %14.7f (%s)\n") + call pargr (Memr[params+i-1]) + call pargr (Memr[errors+i-1]) + isfit = false + do j = 1, nparams { + if (Memi[plist+j-1] == i) { + isfit = true + break + } + } + if (isfit) + call pargstr ("fit") + else + call pargstr ("constant") + } + call fprintf (fd, "\n") + + # Free allocated memory. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/inget.gx b/pkg/xtools/inlfit/inget.gx new file mode 100644 index 00000000..907a0331 --- /dev/null +++ b/pkg/xtools/inlfit/inget.gx @@ -0,0 +1,220 @@ +.help inget + int = in_geti (in, param) + pointer= in_getp (in, param) + real = in_getr (in, param) + double = in_getd (in, param) + in_gstr (in, param, str, maxch) + in_gkey (in, key, axis, type, varnum) +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_GETI -- Get integer valued parameters. + +int procedure in_geti (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLFUNCTION: + return (IN_FUNC (in)) + case INLDERIVATIVE: + return (IN_DFUNC (in)) + case INLNPARAMS: + return (IN_NPARAMS (in)) + case INLNFPARAMS: + return (IN_NFPARAMS (in)) + case INLNVARS: + return (IN_NVARS (in)) + case INLNPTS: + return (IN_NPTS (in)) + case INLMAXITER: + return (IN_MAXITER (in)) + case INLNREJECT: + return (IN_NREJECT(in)) + case INLNREJPTS: + return (IN_NREJPTS (in)) + case INLUAXES: + return (IN_UAXES (in)) + case INLUCOLON: + return (IN_UCOLON (in)) + case INLUFIT: + return (IN_UFIT (in)) + case INLOVERPLOT: + return (IN_OVERPLOT (in)) + case INLPLOTFIT: + return (IN_PLOTFIT (in)) + case INLFITERROR: + return (IN_FITERROR (in)) + case INLGKEY: + return (IN_GKEY (in)) + default: + call error (0, "INLFIT, in_geti: Unknown parameter") + } +end + + +$for (rd) +# IN_GET[RD] -- Get real/double valued parameters. + +PIXEL procedure in_get$t (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLTOLERANCE: + return (IN_TOL$T (in)) + case INLLOW: + return (IN_LOW$T (in)) + case INLHIGH: + return (IN_HIGH$T (in)) + case INLGROW: + return (IN_GROW$T (in)) + default: + call error (0, "INLFIT, in_get[rd]: Unknown parameter") + } +end +$endfor + + +# IN_GETP -- Get pointer valued parameters. + +pointer procedure in_getp (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLPARAM: + return (IN_PARAM (in)) + case INLDPARAM: + return (IN_DPARAM (in)) + case INLPLIST: + return (IN_PLIST (in)) + case INLSFLOAT: + return (IN_SFLOAT (in)) + case INLREJPTS: + return (IN_REJPTS (in)) + case INLXMIN: + return (IN_XMIN (in)) + case INLXMAX: + return (IN_XMAX (in)) + case INLSGAXES: + return (IN_SGAXES (in)) + default: + call error (0, "INLFIT, in_getp: Unknown parameter") + } +end + + +# IN_GETC -- Get character pointer valued parameters. + +pointer procedure in_getc (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLLABELS: + return (IN_LABELS (in)) + case INLUNITS: + return (IN_UNITS (in)) + case INLFLABELS: + return (IN_FLABELS (in)) + case INLFUNITS: + return (IN_FUNITS (in)) + case INLPLABELS: + return (IN_PLABELS (in)) + case INLPUNITS: + return (IN_PUNITS (in)) + case INLVLABELS: + return (IN_VLABELS (in)) + case INLVUNITS: + return (IN_VUNITS (in)) + case INLUSERLABELS: + return (IN_USERLABELS (in)) + case INLUSERUNITS: + return (IN_USERUNITS (in)) + case INLHELP: + return (IN_HELP (in)) + case INLPROMPT: + return (IN_PROMPT (in)) + default: + call error (0, "INLFIT, in_getc: Unknown parameter") + } +end + + +# IN_GSTR -- Get string valued parameters. + +procedure in_gstr (in, param, str, maxch) + +pointer in # INLFIT pointer +int param # parameter to get +char str[maxch] # string value +int maxch # maximum number of characters + +begin + switch (param) { + case INLLABELS: + call strcpy (Memc[IN_LABELS (in)], str, maxch) + case INLUNITS: + call strcpy (Memc[IN_UNITS (in)], str, maxch) + case INLFLABELS: + call strcpy (Memc[IN_FLABELS (in)], str, maxch) + case INLFUNITS: + call strcpy (Memc[IN_FUNITS (in)], str, maxch) + case INLPLABELS: + call strcpy (Memc[IN_PLABELS (in)], str, maxch) + case INLPUNITS: + call strcpy (Memc[IN_PUNITS (in)], str, maxch) + case INLVLABELS: + call strcpy (Memc[IN_VLABELS (in)], str, maxch) + case INLVUNITS: + call strcpy (Memc[IN_VUNITS (in)], str, maxch) + case INLUSERLABELS: + call strcpy (Memc[IN_USERLABELS (in)], str, maxch) + case INLUSERUNITS: + call strcpy (Memc[IN_USERUNITS (in)], str, maxch) + case INLHELP: + call strcpy (Memc[IN_HELP (in)], str, maxch) + case INLPROMPT: + call strcpy (Memc[IN_PROMPT (in)], str, maxch) + default: + call error (0, "INLFIT, in_gstr: Unknown parameter") + } +end + + +# IN_GKEY -- Get key parameters. + +procedure in_gkey (in, key, axis, type, varnum) + +pointer in # INLFIT pointer +int key # key to get +int axis # axis number +int type # axis type (output) +int varnum # axis variable number (output) + +begin + # Check ranges + if (key < 1 || key > INLNGKEYS) + call error (0, "INLFIT, in_pkey: Illegal key") + + # Get data + if (axis == INLXAXIS) { + type = IN_GXTYPE (in, key) + varnum = IN_GXNUMBER (in, key) + } else if (axis == INLYAXIS) { + type = IN_GYTYPE (in, key) + varnum = IN_GYNUMBER (in, key) + } else + call error (0, "INLFIT, in_gkey: Illegal axis") +end diff --git a/pkg/xtools/inlfit/inget.x b/pkg/xtools/inlfit/inget.x new file mode 100644 index 00000000..aa31a8cb --- /dev/null +++ b/pkg/xtools/inlfit/inget.x @@ -0,0 +1,242 @@ +.help inget + int = in_geti (in, param) + pointer= in_getp (in, param) + real = in_getr (in, param) + double = in_getd (in, param) + in_gstr (in, param, str, maxch) + in_gkey (in, key, axis, type, varnum) +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + +# IN_GETI -- Get integer valued parameters. + +int procedure in_geti (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLFUNCTION: + return (IN_FUNC (in)) + case INLDERIVATIVE: + return (IN_DFUNC (in)) + case INLNPARAMS: + return (IN_NPARAMS (in)) + case INLNFPARAMS: + return (IN_NFPARAMS (in)) + case INLNVARS: + return (IN_NVARS (in)) + case INLNPTS: + return (IN_NPTS (in)) + case INLMAXITER: + return (IN_MAXITER (in)) + case INLNREJECT: + return (IN_NREJECT(in)) + case INLNREJPTS: + return (IN_NREJPTS (in)) + case INLUAXES: + return (IN_UAXES (in)) + case INLUCOLON: + return (IN_UCOLON (in)) + case INLUFIT: + return (IN_UFIT (in)) + case INLOVERPLOT: + return (IN_OVERPLOT (in)) + case INLPLOTFIT: + return (IN_PLOTFIT (in)) + case INLFITERROR: + return (IN_FITERROR (in)) + case INLGKEY: + return (IN_GKEY (in)) + default: + call error (0, "INLFIT, in_geti: Unknown parameter") + } +end + + + +# IN_GET[RD] -- Get real/double valued parameters. + +real procedure in_getr (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLTOLERANCE: + return (IN_TOLR (in)) + case INLLOW: + return (IN_LOWR (in)) + case INLHIGH: + return (IN_HIGHR (in)) + case INLGROW: + return (IN_GROWR (in)) + default: + call error (0, "INLFIT, in_get[rd]: Unknown parameter") + } +end + +# IN_GET[RD] -- Get real/double valued parameters. + +double procedure in_getd (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLTOLERANCE: + return (IN_TOLD (in)) + case INLLOW: + return (IN_LOWD (in)) + case INLHIGH: + return (IN_HIGHD (in)) + case INLGROW: + return (IN_GROWD (in)) + default: + call error (0, "INLFIT, in_get[rd]: Unknown parameter") + } +end + + + +# IN_GETP -- Get pointer valued parameters. + +pointer procedure in_getp (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLPARAM: + return (IN_PARAM (in)) + case INLDPARAM: + return (IN_DPARAM (in)) + case INLPLIST: + return (IN_PLIST (in)) + case INLSFLOAT: + return (IN_SFLOAT (in)) + case INLREJPTS: + return (IN_REJPTS (in)) + case INLXMIN: + return (IN_XMIN (in)) + case INLXMAX: + return (IN_XMAX (in)) + case INLSGAXES: + return (IN_SGAXES (in)) + default: + call error (0, "INLFIT, in_getp: Unknown parameter") + } +end + + +# IN_GETC -- Get character pointer valued parameters. + +pointer procedure in_getc (in, param) + +pointer in # INLFIT pointer +int param # parameter to get + +begin + switch (param) { + case INLLABELS: + return (IN_LABELS (in)) + case INLUNITS: + return (IN_UNITS (in)) + case INLFLABELS: + return (IN_FLABELS (in)) + case INLFUNITS: + return (IN_FUNITS (in)) + case INLPLABELS: + return (IN_PLABELS (in)) + case INLPUNITS: + return (IN_PUNITS (in)) + case INLVLABELS: + return (IN_VLABELS (in)) + case INLVUNITS: + return (IN_VUNITS (in)) + case INLUSERLABELS: + return (IN_USERLABELS (in)) + case INLUSERUNITS: + return (IN_USERUNITS (in)) + case INLHELP: + return (IN_HELP (in)) + case INLPROMPT: + return (IN_PROMPT (in)) + default: + call error (0, "INLFIT, in_getc: Unknown parameter") + } +end + + +# IN_GSTR -- Get string valued parameters. + +procedure in_gstr (in, param, str, maxch) + +pointer in # INLFIT pointer +int param # parameter to get +char str[maxch] # string value +int maxch # maximum number of characters + +begin + switch (param) { + case INLLABELS: + call strcpy (Memc[IN_LABELS (in)], str, maxch) + case INLUNITS: + call strcpy (Memc[IN_UNITS (in)], str, maxch) + case INLFLABELS: + call strcpy (Memc[IN_FLABELS (in)], str, maxch) + case INLFUNITS: + call strcpy (Memc[IN_FUNITS (in)], str, maxch) + case INLPLABELS: + call strcpy (Memc[IN_PLABELS (in)], str, maxch) + case INLPUNITS: + call strcpy (Memc[IN_PUNITS (in)], str, maxch) + case INLVLABELS: + call strcpy (Memc[IN_VLABELS (in)], str, maxch) + case INLVUNITS: + call strcpy (Memc[IN_VUNITS (in)], str, maxch) + case INLUSERLABELS: + call strcpy (Memc[IN_USERLABELS (in)], str, maxch) + case INLUSERUNITS: + call strcpy (Memc[IN_USERUNITS (in)], str, maxch) + case INLHELP: + call strcpy (Memc[IN_HELP (in)], str, maxch) + case INLPROMPT: + call strcpy (Memc[IN_PROMPT (in)], str, maxch) + default: + call error (0, "INLFIT, in_gstr: Unknown parameter") + } +end + + +# IN_GKEY -- Get key parameters. + +procedure in_gkey (in, key, axis, type, varnum) + +pointer in # INLFIT pointer +int key # key to get +int axis # axis number +int type # axis type (output) +int varnum # axis variable number (output) + +begin + # Check ranges + if (key < 1 || key > INLNGKEYS) + call error (0, "INLFIT, in_pkey: Illegal key") + + # Get data + if (axis == INLXAXIS) { + type = IN_GXTYPE (in, key) + varnum = IN_GXNUMBER (in, key) + } else if (axis == INLYAXIS) { + type = IN_GYTYPE (in, key) + varnum = IN_GYNUMBER (in, key) + } else + call error (0, "INLFIT, in_gkey: Illegal axis") +end diff --git a/pkg/xtools/inlfit/ingfit.gx b/pkg/xtools/inlfit/ingfit.gx new file mode 100644 index 00000000..4dc5b330 --- /dev/null +++ b/pkg/xtools/inlfit/ingfit.gx @@ -0,0 +1,204 @@ +include <error.h> +include <mach.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_GFIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the interactive part of the INLFIT package. + + +procedure ing_fit$t (in, gp, cursor, gt, nl, x, y, wts, names, npts, nvars, + len_name, wtflag, stat) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # independent variables (npts * nvars) +PIXEL y[ARB] # dependent variables +PIXEL wts[ARB] # weigths +char names[ARB] # star ids +int npts # number of points +int nvars # number of variables +int len_name # length of an object name +int wtflag # type of weighting +int stat # Error code (output) + +int i, wcs, key, gkey, newgraph +int xtype, xvar, ytype, yvar, xt, xv, yt, yv +PIXEL fit +pointer sp, cmd, oldwts, help, prompt +real wx, wy + +int gt_gcur1(), ing_nearest$t(), in_geti() +PIXEL nleval$t() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Allocate and initialize a copy of the weights. A new copy + # of the weights is used because it is necessary to have the + # original values to restore them back when the user deletes + # and undeletes points. + + call salloc (oldwts, npts, TY_PIXEL) + call amov$t (wts, Mem$t[oldwts], npts) + + # Allocate space for help page and prompt, and get them. + call salloc (help, SZ_LINE, TY_CHAR) + call salloc (prompt, SZ_LINE, TY_CHAR) + call in_gstr (in, INLHELP, Memc[help], SZ_LINE) + call in_gstr (in, INLPROMPT, Memc[prompt], SZ_LINE) + + # Initialize INLFIT flags. + call in_puti (in, INLOVERPLOT, NO) + + # Initialize loop control variables. The first action + # is to fit the data, in order to have all the fit + # parameters set. + key = 'f' + newgraph = YES + + # Get initial setup for axes. + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call in_gkey (in, gkey, INLYAXIS, xtype, xvar) + + # Loop reading cursor commands. + repeat { + switch (key) { + case '?': # Print help text. + call gpagefile (gp, Memc[help], Memc[prompt]) + + case ':': # List or set parameters. + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call ing_colon$t (in, Memc[cmd], gp, gt, nl, x, y, wts, + names, npts, nvars, len_name, newgraph) + + case 'c': # Print the positions and useful info on data points. + + i = ing_nearest$t (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + if (i != 0) { + fit = nleval$t (nl, x[(i-1)*nvars+1], nvars) + call printf ( + "%d %s x=%g y=%g func=%g fit=%g, resid=%g\n") + call pargi (i) + call pargstr (names[(i-1)*len_name+1]) + call pargr (wx) + call pargr (wy) + call parg$t (y[i]) + call parg$t (fit) + call parg$t (y[i] - fit) + } + + case 'd': # Delete data points. + call ing_delete$t (in, gp, gt, nl, x, y, wts, npts, nvars, + wx, wy) + + case 'f': # Fit the function. + + # Fit. + do i = 1, npts { + if (wts[i] > PIXEL(0.0)) + wts[i] = Mem$t[oldwts+i-1] + } + call in_fit$t (in, nl, x, y, wts, npts, nvars, wtflag, stat) + + newgraph = YES + + case 'g': # Set graph axistype types. + call ing_defkey (in, nvars, newgraph) + + case 'h': + if (in_geti (in, INLGKEY) != 1) { + call in_puti (in, INLGKEY, 1) + newgraph = YES + } + + case 'i': + if (in_geti (in, INLGKEY) != 2) { + call in_puti (in, INLGKEY, 2) + newgraph = YES + } + + case 'j': + if (in_geti (in, INLGKEY) != 3) { + call in_puti (in, INLGKEY, 3) + newgraph = YES + } + + case 'k': + if (in_geti (in, INLGKEY) != 4) { + call in_puti (in, INLGKEY, 4) + newgraph = YES + } + + case 'l': + if (in_geti (in, INLGKEY) != 5) { + call in_puti (in, INLGKEY, 5) + newgraph = YES + } + + case 'o': # Set the overplot flag. + call in_puti (in, INLOVERPLOT, YES) + + case 'r': # Redraw the graph. + newgraph = YES + + case 't': # Toggle overplot fit flag. + if (in_geti (in, INLPLOTFIT) == YES) + call in_puti (in, INLPLOTFIT, NO) + else + call in_puti (in, INLPLOTFIT, YES) + newgraph = YES + + case 'u': # Undelete data points. + call ing_undelete$t (in, gp, gt, nl, x, y, wts, Mem$t[oldwts], + npts, nvars, wx, wy) + + case 'w': # Window graph. + call gt_window (gt, gp, cursor, newgraph) + + case 'I': # Interrupt. + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call ing_ufit (in, gp, gt, nl, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. + if (newgraph == YES) { + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xt, xv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + call in_gkey (in, gkey, INLYAXIS, yt, yv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLYAXIS, ytype, yvar) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + call ing_graph$t (in, gp, gt, nl, x, y, wts, npts, nvars) + newgraph = NO + } + + if (cursor[1] == EOS) + break + + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + SZ_LINE) == EOF) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingfitd.x b/pkg/xtools/inlfit/ingfitd.x new file mode 100644 index 00000000..b31364e0 --- /dev/null +++ b/pkg/xtools/inlfit/ingfitd.x @@ -0,0 +1,204 @@ +include <error.h> +include <mach.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_GFIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the interactive part of the INLFIT package. + + +procedure ing_fitd (in, gp, cursor, gt, nl, x, y, wts, names, npts, nvars, + len_name, wtflag, stat) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +double x[ARB] # independent variables (npts * nvars) +double y[ARB] # dependent variables +double wts[ARB] # weigths +char names[ARB] # star ids +int npts # number of points +int nvars # number of variables +int len_name # length of an object name +int wtflag # type of weighting +int stat # Error code (output) + +int i, wcs, key, gkey, newgraph +int xtype, xvar, ytype, yvar, xt, xv, yt, yv +double fit +pointer sp, cmd, oldwts, help, prompt +real wx, wy + +int gt_gcur1(), ing_nearestd(), in_geti() +double nlevald() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Allocate and initialize a copy of the weights. A new copy + # of the weights is used because it is necessary to have the + # original values to restore them back when the user deletes + # and undeletes points. + + call salloc (oldwts, npts, TY_DOUBLE) + call amovd (wts, Memd[oldwts], npts) + + # Allocate space for help page and prompt, and get them. + call salloc (help, SZ_LINE, TY_CHAR) + call salloc (prompt, SZ_LINE, TY_CHAR) + call in_gstr (in, INLHELP, Memc[help], SZ_LINE) + call in_gstr (in, INLPROMPT, Memc[prompt], SZ_LINE) + + # Initialize INLFIT flags. + call in_puti (in, INLOVERPLOT, NO) + + # Initialize loop control variables. The first action + # is to fit the data, in order to have all the fit + # parameters set. + key = 'f' + newgraph = YES + + # Get initial setup for axes. + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call in_gkey (in, gkey, INLYAXIS, xtype, xvar) + + # Loop reading cursor commands. + repeat { + switch (key) { + case '?': # Print help text. + call gpagefile (gp, Memc[help], Memc[prompt]) + + case ':': # List or set parameters. + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call ing_colond (in, Memc[cmd], gp, gt, nl, x, y, wts, + names, npts, nvars, len_name, newgraph) + + case 'c': # Print the positions and useful info on data points. + + i = ing_nearestd (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + if (i != 0) { + fit = nlevald (nl, x[(i-1)*nvars+1], nvars) + call printf ( + "%d %s x=%g y=%g func=%g fit=%g, resid=%g\n") + call pargi (i) + call pargstr (names[(i-1)*len_name+1]) + call pargr (wx) + call pargr (wy) + call pargd (y[i]) + call pargd (fit) + call pargd (y[i] - fit) + } + + case 'd': # Delete data points. + call ing_deleted (in, gp, gt, nl, x, y, wts, npts, nvars, + wx, wy) + + case 'f': # Fit the function. + + # Fit. + do i = 1, npts { + if (wts[i] > double(0.0)) + wts[i] = Memd[oldwts+i-1] + } + call in_fitd (in, nl, x, y, wts, npts, nvars, wtflag, stat) + + newgraph = YES + + case 'g': # Set graph axistype types. + call ing_defkey (in, nvars, newgraph) + + case 'h': + if (in_geti (in, INLGKEY) != 1) { + call in_puti (in, INLGKEY, 1) + newgraph = YES + } + + case 'i': + if (in_geti (in, INLGKEY) != 2) { + call in_puti (in, INLGKEY, 2) + newgraph = YES + } + + case 'j': + if (in_geti (in, INLGKEY) != 3) { + call in_puti (in, INLGKEY, 3) + newgraph = YES + } + + case 'k': + if (in_geti (in, INLGKEY) != 4) { + call in_puti (in, INLGKEY, 4) + newgraph = YES + } + + case 'l': + if (in_geti (in, INLGKEY) != 5) { + call in_puti (in, INLGKEY, 5) + newgraph = YES + } + + case 'o': # Set the overplot flag. + call in_puti (in, INLOVERPLOT, YES) + + case 'r': # Redraw the graph. + newgraph = YES + + case 't': # Toggle overplot fit flag. + if (in_geti (in, INLPLOTFIT) == YES) + call in_puti (in, INLPLOTFIT, NO) + else + call in_puti (in, INLPLOTFIT, YES) + newgraph = YES + + case 'u': # Undelete data points. + call ing_undeleted (in, gp, gt, nl, x, y, wts, Memd[oldwts], + npts, nvars, wx, wy) + + case 'w': # Window graph. + call gt_window (gt, gp, cursor, newgraph) + + case 'I': # Interrupt. + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call ing_ufit (in, gp, gt, nl, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. + if (newgraph == YES) { + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xt, xv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + call in_gkey (in, gkey, INLYAXIS, yt, yv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLYAXIS, ytype, yvar) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + call ing_graphd (in, gp, gt, nl, x, y, wts, npts, nvars) + newgraph = NO + } + + if (cursor[1] == EOS) + break + + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + SZ_LINE) == EOF) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingfitr.x b/pkg/xtools/inlfit/ingfitr.x new file mode 100644 index 00000000..9e685506 --- /dev/null +++ b/pkg/xtools/inlfit/ingfitr.x @@ -0,0 +1,204 @@ +include <error.h> +include <mach.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_GFIT -- Fit a function using non-linear least squares. The function +# can have an arbitrary number of independent variables. This is the main +# entry point for the interactive part of the INLFIT package. + + +procedure ing_fitr (in, gp, cursor, gt, nl, x, y, wts, names, npts, nvars, + len_name, wtflag, stat) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +char cursor[ARB] # GIO cursor input +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +real x[ARB] # independent variables (npts * nvars) +real y[ARB] # dependent variables +real wts[ARB] # weigths +char names[ARB] # star ids +int npts # number of points +int nvars # number of variables +int len_name # length of an object name +int wtflag # type of weighting +int stat # Error code (output) + +int i, wcs, key, gkey, newgraph +int xtype, xvar, ytype, yvar, xt, xv, yt, yv +real fit +pointer sp, cmd, oldwts, help, prompt +real wx, wy + +int gt_gcur1(), ing_nearestr(), in_geti() +real nlevalr() + +begin + # Allocate string space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Allocate and initialize a copy of the weights. A new copy + # of the weights is used because it is necessary to have the + # original values to restore them back when the user deletes + # and undeletes points. + + call salloc (oldwts, npts, TY_REAL) + call amovr (wts, Memr[oldwts], npts) + + # Allocate space for help page and prompt, and get them. + call salloc (help, SZ_LINE, TY_CHAR) + call salloc (prompt, SZ_LINE, TY_CHAR) + call in_gstr (in, INLHELP, Memc[help], SZ_LINE) + call in_gstr (in, INLPROMPT, Memc[prompt], SZ_LINE) + + # Initialize INLFIT flags. + call in_puti (in, INLOVERPLOT, NO) + + # Initialize loop control variables. The first action + # is to fit the data, in order to have all the fit + # parameters set. + key = 'f' + newgraph = YES + + # Get initial setup for axes. + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call in_gkey (in, gkey, INLYAXIS, xtype, xvar) + + # Loop reading cursor commands. + repeat { + switch (key) { + case '?': # Print help text. + call gpagefile (gp, Memc[help], Memc[prompt]) + + case ':': # List or set parameters. + if (Memc[cmd] == '/') + call gt_colon (Memc[cmd], gp, gt, newgraph) + else + call ing_colonr (in, Memc[cmd], gp, gt, nl, x, y, wts, + names, npts, nvars, len_name, newgraph) + + case 'c': # Print the positions and useful info on data points. + + i = ing_nearestr (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + if (i != 0) { + fit = nlevalr (nl, x[(i-1)*nvars+1], nvars) + call printf ( + "%d %s x=%g y=%g func=%g fit=%g, resid=%g\n") + call pargi (i) + call pargstr (names[(i-1)*len_name+1]) + call pargr (wx) + call pargr (wy) + call pargr (y[i]) + call pargr (fit) + call pargr (y[i] - fit) + } + + case 'd': # Delete data points. + call ing_deleter (in, gp, gt, nl, x, y, wts, npts, nvars, + wx, wy) + + case 'f': # Fit the function. + + # Fit. + do i = 1, npts { + if (wts[i] > real(0.0)) + wts[i] = Memr[oldwts+i-1] + } + call in_fitr (in, nl, x, y, wts, npts, nvars, wtflag, stat) + + newgraph = YES + + case 'g': # Set graph axistype types. + call ing_defkey (in, nvars, newgraph) + + case 'h': + if (in_geti (in, INLGKEY) != 1) { + call in_puti (in, INLGKEY, 1) + newgraph = YES + } + + case 'i': + if (in_geti (in, INLGKEY) != 2) { + call in_puti (in, INLGKEY, 2) + newgraph = YES + } + + case 'j': + if (in_geti (in, INLGKEY) != 3) { + call in_puti (in, INLGKEY, 3) + newgraph = YES + } + + case 'k': + if (in_geti (in, INLGKEY) != 4) { + call in_puti (in, INLGKEY, 4) + newgraph = YES + } + + case 'l': + if (in_geti (in, INLGKEY) != 5) { + call in_puti (in, INLGKEY, 5) + newgraph = YES + } + + case 'o': # Set the overplot flag. + call in_puti (in, INLOVERPLOT, YES) + + case 'r': # Redraw the graph. + newgraph = YES + + case 't': # Toggle overplot fit flag. + if (in_geti (in, INLPLOTFIT) == YES) + call in_puti (in, INLPLOTFIT, NO) + else + call in_puti (in, INLPLOTFIT, YES) + newgraph = YES + + case 'u': # Undelete data points. + call ing_undeleter (in, gp, gt, nl, x, y, wts, Memr[oldwts], + npts, nvars, wx, wy) + + case 'w': # Window graph. + call gt_window (gt, gp, cursor, newgraph) + + case 'I': # Interrupt. + call fatal (0, "Interrupt") + + default: # Let the user decide on any other keys. + call ing_ufit (in, gp, gt, nl, wx, wy, wcs, key, Memc[cmd]) + } + + # Redraw the graph if necessary. + if (newgraph == YES) { + gkey = in_geti (in, INLGKEY) + call in_gkey (in, gkey, INLXAXIS, xt, xv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLXAXIS, xtype, xvar) + call gt_setr (gt, GTXMIN, INDEFR) + call gt_setr (gt, GTXMAX, INDEFR) + } + call in_gkey (in, gkey, INLYAXIS, yt, yv) + if (xt != xtype || xv != xvar) { + call in_gkey (in, gkey, INLYAXIS, ytype, yvar) + call gt_setr (gt, GTYMIN, INDEFR) + call gt_setr (gt, GTYMAX, INDEFR) + } + call ing_graphr (in, gp, gt, nl, x, y, wts, npts, nvars) + newgraph = NO + } + + if (cursor[1] == EOS) + break + + } until (gt_gcur1 (gt, cursor, wx, wy, wcs, key, Memc[cmd], + SZ_LINE) == EOF) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inggetlabel.x b/pkg/xtools/inlfit/inggetlabel.x new file mode 100644 index 00000000..7693b2a9 --- /dev/null +++ b/pkg/xtools/inlfit/inggetlabel.x @@ -0,0 +1,78 @@ +include <pkg/inlfit.h> + + +# ING_GETLABEL -- Get label and units for a given axis + +procedure ing_getlabel (in, xtype, xnum, label, units, maxch) + +pointer in # INLFIT descriptor +int xtype # axis type +int xnum # axis number +char label[ARB] # label +char units[ARB] # units +int maxch # max chars. in label and units + +int dummy +pointer sp, str +pointer labels, lunits, vlabels, vunits +pointer userlabels, userunits + +int inlstrwrd() + +begin + # Begin allocation of string space. + call smark (sp) + call salloc (str, SZ_LINE + 1, TY_CHAR) + + # Branch on axis type. + switch (xtype) { + case KEY_VARIABLE: + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (vlabels, SZ_LINE, TY_CHAR) + call salloc (vunits, SZ_LINE, TY_CHAR) + call in_gstr (in, INLLABELS, Memc[labels], SZ_LINE) + call in_gstr (in, INLVLABELS, Memc[vlabels], SZ_LINE) + call in_gstr (in, INLVUNITS, Memc[vunits], SZ_LINE) + + if (inlstrwrd (xnum, label, maxch, Memc[vlabels]) == 0) { + if (inlstrwrd (xtype, Memc[str], SZ_LINE, Memc[labels]) != 0) { + call sprintf (label, maxch, "%s%d") + call pargstr (Memc[str]) + call pargi (xnum) + } + } + dummy = inlstrwrd (xnum, units, maxch, Memc[vunits]) + + case KEY_FUNCTION, KEY_FIT, KEY_RESIDUALS, KEY_RATIO, KEY_NONLINEAR: + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (lunits, SZ_LINE, TY_CHAR) + call in_gstr (in, INLLABELS, Memc[labels], SZ_LINE) + call in_gstr (in, INLUNITS, Memc[lunits], SZ_LINE) + + dummy = inlstrwrd (xtype, label, maxch, Memc[labels]) + dummy = inlstrwrd (xtype, units, maxch, Memc[lunits]) + + case KEY_UAXIS: + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (userlabels, SZ_LINE, TY_CHAR) + call salloc (userunits, SZ_LINE, TY_CHAR) + call in_gstr (in, INLLABELS, Memc[labels], SZ_LINE) + call in_gstr (in, INLUSERLABELS, Memc[userlabels], SZ_LINE) + call in_gstr (in, INLUSERUNITS, Memc[userunits], SZ_LINE) + + if (inlstrwrd (xnum, label, maxch, Memc[userlabels]) == 0) { + if (inlstrwrd (xtype, Memc[str], SZ_LINE, Memc[labels]) != 0) { + call sprintf (label, maxch, "%s%d") + call pargstr (Memc[str]) + call pargi (xnum) + } + } + dummy = inlstrwrd (xnum, units, maxch, Memc[userunits]) + + default: + call error (0, "INLFIT, ing_getlabel: Unknown axis type") + } + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inggraph.gx b/pkg/xtools/inlfit/inggraph.gx new file mode 100644 index 00000000..0eeb48d8 --- /dev/null +++ b/pkg/xtools/inlfit/inggraph.gx @@ -0,0 +1,240 @@ +include <gset.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 3.0 # mark size for rejected points (real) + + +# ING_GRAPH -- Graph data and fit. First plot the data marking deleted +# points, then overplot rejected points, and finally overplot the fit. + +procedure ing_graph$t (in, gp, gt, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variables (npts * nvars) +PIXEL y[npts] # Dependent variables +PIXEL wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables + +pointer xout, yout +pointer sp + +begin + # Alloacate axes data memory. + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + # Set axes data. + call ing_axes$t (in, gt, nl, 1, x, y, Mem$t[xout], npts, nvars) + call ing_axes$t (in, gt, nl, 2, x, y, Mem$t[yout], npts, nvars) + + # Set graphic parameters. + call ing_params$t (in, nl, x, y, wts, npts, nvars, gt) + + # Plot data and deleted points. + call ing_g1$t (in, gp, gt, Mem$t[xout], Mem$t[yout], wts, npts) + + # Overplot rejected points. + call ing_g2$t (in, gp, gt, Mem$t[xout], Mem$t[yout], npts) + + # Overplot the fit. + call ing_gf$t (in, gp, gt, nl, x, wts, npts, nvars) + + # Free memory + call sfree (sp) +end + + +# ING_G1 - Plot data and deleted points (weight = 0.0). + +procedure ing_g1$t (in, gp, gt, x, y, wts, npts) + +pointer in # INLFIT 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 + +int in_geti() + +begin + # Allocate memory. + 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) + + # Change type to real for plotting. + call acht$tr (x, Memr[xr], npts) + call acht$tr (y, Memr[yr], npts) + + # Start new graph if not overplotting. + if (in_geti (in, INLOVERPLOT) == NO) { + call gclear (gp) + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + # Initialize auxiliaray GTOOLS descriptor for deleted points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + # Plot data points marking deleted points with other symbol. + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == PIXEL (0.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] + + call gt_plot (gp, gt, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + # Reset overplot flag. + call in_puti (in, INLOVERPLOT, NO) + + # Free memory and auxiliary GTOOLS descriptor. + call sfree (sp) + call gt_free (gt1) +end + + +# ING_G2 - Overplot rejected points. + +procedure ing_g2$t (in, gp, gt, x, y, npts) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +PIXEL x[npts], y[npts] # Data points +int npts # Number of data points + +int i +pointer sp, xr, yr, gt1 +pointer rejpts + +int in_geti() +int in_getp() + +begin + # Don't plot if there are no rejected points + if (in_geti (in, INLNREJPTS) == 0) + return + + # Allocate axes memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + + # Change type to real for plotting. + call acht$tr (x, Memr[xr], npts) + call acht$tr (y, Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor + # for rejected points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + + # Plot rejected points if there are any. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts + i - 1] == YES) + call gt_plot (gp, gt1, Memr[xr + i - 1], Memr[yr + i - 1], 1) + } + + # Free memory and auxiliary GTOOLS descriptor. + call gt_free (gt1) + call sfree (sp) +end + + +# ING_GF - Overplot the fit using dashed lines. + +procedure ing_gf$t (in, gp, gt, nl, xin, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer nl # NLFIT pointer +PIXEL xin[ARB] # Independent variables +PIXEL wts[npts] # weights +int npts # Number of points to plot +int nvars # Number of variables + +int i +pointer sp, xr, yr, x, y, xo, yo, gt1 + +int in_geti() + +begin + # Don't plot if there is a fit error. + if (in_geti (in, INLFITERROR) != DONE || + in_geti (in, INLPLOTFIT) == NO) + return + + # Allocate memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts * nvars, TY_PIXEL) + call salloc (y, npts, TY_PIXEL) + call salloc (xo, npts, TY_PIXEL) + call salloc (yo, npts, TY_PIXEL) + + # Move input data into vector. + call amov$t (xin, Mem$t[x], npts * nvars) + + # Calculate vector of fit values. + call nlvector$t (nl, Mem$t[x], Mem$t[y], npts, nvars) + + # Set axes data. + call ing_axes$t (in, gt, nl, 1, Mem$t[x], Mem$t[y], Mem$t[xo], + npts, nvars) + call ing_axes$t (in, gt, nl, 2, Mem$t[x], Mem$t[y], Mem$t[yo], + npts, nvars) + + # Convert to real for plotting. + call acht$tr (Mem$t[xo], Memr[xr], npts) + call acht$tr (Mem$t[yo], Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor, plot the + # fit and free the auxiliary descriptor. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "box") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTXSIZE, MSIZE) + do i = 1, npts { + if (wts[i] != PIXEL (0.0)) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + call gt_free (gt1) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inggraphd.x b/pkg/xtools/inlfit/inggraphd.x new file mode 100644 index 00000000..245afa63 --- /dev/null +++ b/pkg/xtools/inlfit/inggraphd.x @@ -0,0 +1,240 @@ +include <gset.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 3.0 # mark size for rejected points (real) + + +# ING_GRAPH -- Graph data and fit. First plot the data marking deleted +# points, then overplot rejected points, and finally overplot the fit. + +procedure ing_graphd (in, gp, gt, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer nl # NLFIT pointer +double x[ARB] # Independent variables (npts * nvars) +double y[npts] # Dependent variables +double wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables + +pointer xout, yout +pointer sp + +begin + # Alloacate axes data memory. + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + # Set axes data. + call ing_axesd (in, gt, nl, 1, x, y, Memd[xout], npts, nvars) + call ing_axesd (in, gt, nl, 2, x, y, Memd[yout], npts, nvars) + + # Set graphic parameters. + call ing_paramsd (in, nl, x, y, wts, npts, nvars, gt) + + # Plot data and deleted points. + call ing_g1d (in, gp, gt, Memd[xout], Memd[yout], wts, npts) + + # Overplot rejected points. + call ing_g2d (in, gp, gt, Memd[xout], Memd[yout], npts) + + # Overplot the fit. + call ing_gfd (in, gp, gt, nl, x, wts, npts, nvars) + + # Free memory + call sfree (sp) +end + + +# ING_G1 - Plot data and deleted points (weight = 0.0). + +procedure ing_g1d (in, gp, gt, x, y, wts, npts) + +pointer in # INLFIT 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 + +int in_geti() + +begin + # Allocate memory. + 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) + + # Change type to real for plotting. + call achtdr (x, Memr[xr], npts) + call achtdr (y, Memr[yr], npts) + + # Start new graph if not overplotting. + if (in_geti (in, INLOVERPLOT) == NO) { + call gclear (gp) + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + # Initialize auxiliaray GTOOLS descriptor for deleted points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + # Plot data points marking deleted points with other symbol. + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == double (0.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] + + call gt_plot (gp, gt, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + # Reset overplot flag. + call in_puti (in, INLOVERPLOT, NO) + + # Free memory and auxiliary GTOOLS descriptor. + call sfree (sp) + call gt_free (gt1) +end + + +# ING_G2 - Overplot rejected points. + +procedure ing_g2d (in, gp, gt, x, y, npts) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +double x[npts], y[npts] # Data points +int npts # Number of data points + +int i +pointer sp, xr, yr, gt1 +pointer rejpts + +int in_geti() +int in_getp() + +begin + # Don't plot if there are no rejected points + if (in_geti (in, INLNREJPTS) == 0) + return + + # Allocate axes memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + + # Change type to real for plotting. + call achtdr (x, Memr[xr], npts) + call achtdr (y, Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor + # for rejected points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + + # Plot rejected points if there are any. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts + i - 1] == YES) + call gt_plot (gp, gt1, Memr[xr + i - 1], Memr[yr + i - 1], 1) + } + + # Free memory and auxiliary GTOOLS descriptor. + call gt_free (gt1) + call sfree (sp) +end + + +# ING_GF - Overplot the fit using dashed lines. + +procedure ing_gfd (in, gp, gt, nl, xin, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer nl # NLFIT pointer +double xin[ARB] # Independent variables +double wts[npts] # weights +int npts # Number of points to plot +int nvars # Number of variables + +int i +pointer sp, xr, yr, x, y, xo, yo, gt1 + +int in_geti() + +begin + # Don't plot if there is a fit error. + if (in_geti (in, INLFITERROR) != DONE || + in_geti (in, INLPLOTFIT) == NO) + return + + # Allocate memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts * nvars, TY_DOUBLE) + call salloc (y, npts, TY_DOUBLE) + call salloc (xo, npts, TY_DOUBLE) + call salloc (yo, npts, TY_DOUBLE) + + # Move input data into vector. + call amovd (xin, Memd[x], npts * nvars) + + # Calculate vector of fit values. + call nlvectord (nl, Memd[x], Memd[y], npts, nvars) + + # Set axes data. + call ing_axesd (in, gt, nl, 1, Memd[x], Memd[y], Memd[xo], + npts, nvars) + call ing_axesd (in, gt, nl, 2, Memd[x], Memd[y], Memd[yo], + npts, nvars) + + # Convert to real for plotting. + call achtdr (Memd[xo], Memr[xr], npts) + call achtdr (Memd[yo], Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor, plot the + # fit and free the auxiliary descriptor. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "box") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTXSIZE, MSIZE) + do i = 1, npts { + if (wts[i] != double (0.0)) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + call gt_free (gt1) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inggraphr.x b/pkg/xtools/inlfit/inggraphr.x new file mode 100644 index 00000000..6ddac343 --- /dev/null +++ b/pkg/xtools/inlfit/inggraphr.x @@ -0,0 +1,240 @@ +include <gset.h> +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + +define NGRAPH 100 # Number of fit points to graph +define MSIZE 3.0 # mark size for rejected points (real) + + +# ING_GRAPH -- Graph data and fit. First plot the data marking deleted +# points, then overplot rejected points, and finally overplot the fit. + +procedure ing_graphr (in, gp, gt, nl, x, y, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointers +pointer nl # NLFIT pointer +real x[ARB] # Independent variables (npts * nvars) +real y[npts] # Dependent variables +real wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables + +pointer xout, yout +pointer sp + +begin + # Alloacate axes data memory. + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + # Set axes data. + call ing_axesr (in, gt, nl, 1, x, y, Memr[xout], npts, nvars) + call ing_axesr (in, gt, nl, 2, x, y, Memr[yout], npts, nvars) + + # Set graphic parameters. + call ing_paramsr (in, nl, x, y, wts, npts, nvars, gt) + + # Plot data and deleted points. + call ing_g1r (in, gp, gt, Memr[xout], Memr[yout], wts, npts) + + # Overplot rejected points. + call ing_g2r (in, gp, gt, Memr[xout], Memr[yout], npts) + + # Overplot the fit. + call ing_gfr (in, gp, gt, nl, x, wts, npts, nvars) + + # Free memory + call sfree (sp) +end + + +# ING_G1 - Plot data and deleted points (weight = 0.0). + +procedure ing_g1r (in, gp, gt, x, y, wts, npts) + +pointer in # INLFIT 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 + +int in_geti() + +begin + # Allocate memory. + 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) + + # Change type to real for plotting. + call achtrr (x, Memr[xr], npts) + call achtrr (y, Memr[yr], npts) + + # Start new graph if not overplotting. + if (in_geti (in, INLOVERPLOT) == NO) { + call gclear (gp) + call gascale (gp, Memr[xr], npts, 1) + call gascale (gp, Memr[yr], npts, 2) + call gt_swind (gp, gt) + call gt_labax (gp, gt) + } + + # Initialize auxiliaray GTOOLS descriptor for deleted points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "cross") + + # Plot data points marking deleted points with other symbol. + Memr[xr1] = Memr[xr] + Memr[yr1] = Memr[yr] + do i = 1, npts { + if (wts[i] == real (0.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] + + call gt_plot (gp, gt, Memr[xr+i-1], Memr[yr+i-1], 1) + } + } + + # Reset overplot flag. + call in_puti (in, INLOVERPLOT, NO) + + # Free memory and auxiliary GTOOLS descriptor. + call sfree (sp) + call gt_free (gt1) +end + + +# ING_G2 - Overplot rejected points. + +procedure ing_g2r (in, gp, gt, x, y, npts) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +real x[npts], y[npts] # Data points +int npts # Number of data points + +int i +pointer sp, xr, yr, gt1 +pointer rejpts + +int in_geti() +int in_getp() + +begin + # Don't plot if there are no rejected points + if (in_geti (in, INLNREJPTS) == 0) + return + + # Allocate axes memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + + # Change type to real for plotting. + call achtrr (x, Memr[xr], npts) + call achtrr (y, Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor + # for rejected points. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "diamond") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTYSIZE, MSIZE) + + # Plot rejected points if there are any. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts + i - 1] == YES) + call gt_plot (gp, gt1, Memr[xr + i - 1], Memr[yr + i - 1], 1) + } + + # Free memory and auxiliary GTOOLS descriptor. + call gt_free (gt1) + call sfree (sp) +end + + +# ING_GF - Overplot the fit using dashed lines. + +procedure ing_gfr (in, gp, gt, nl, xin, wts, npts, nvars) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOL pointer +pointer nl # NLFIT pointer +real xin[ARB] # Independent variables +real wts[npts] # weights +int npts # Number of points to plot +int nvars # Number of variables + +int i +pointer sp, xr, yr, x, y, xo, yo, gt1 + +int in_geti() + +begin + # Don't plot if there is a fit error. + if (in_geti (in, INLFITERROR) != DONE || + in_geti (in, INLPLOTFIT) == NO) + return + + # Allocate memory. + call smark (sp) + call salloc (xr, npts, TY_REAL) + call salloc (yr, npts, TY_REAL) + call salloc (x, npts * nvars, TY_REAL) + call salloc (y, npts, TY_REAL) + call salloc (xo, npts, TY_REAL) + call salloc (yo, npts, TY_REAL) + + # Move input data into vector. + call amovr (xin, Memr[x], npts * nvars) + + # Calculate vector of fit values. + call nlvectorr (nl, Memr[x], Memr[y], npts, nvars) + + # Set axes data. + call ing_axesr (in, gt, nl, 1, Memr[x], Memr[y], Memr[xo], + npts, nvars) + call ing_axesr (in, gt, nl, 2, Memr[x], Memr[y], Memr[yo], + npts, nvars) + + # Convert to real for plotting. + call achtrr (Memr[xo], Memr[xr], npts) + call achtrr (Memr[yo], Memr[yr], npts) + + # Initialize auxiliary GTOOLS descriptor, plot the + # fit and free the auxiliary descriptor. + call gt_copy (gt, gt1) + call gt_sets (gt1, GTTYPE, "mark") + call gt_sets (gt1, GTMARK, "box") + call gt_setr (gt1, GTXSIZE, MSIZE) + call gt_setr (gt1, GTXSIZE, MSIZE) + do i = 1, npts { + if (wts[i] != real (0.0)) + call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) + } + call gt_free (gt1) + + # Free memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingnearest.gx b/pkg/xtools/inlfit/ingnearest.gx new file mode 100644 index 00000000..1d208678 --- /dev/null +++ b/pkg/xtools/inlfit/ingnearest.gx @@ -0,0 +1,81 @@ +include <mach.h> +include <pkg/gtools.h> + + +# ING_NEAREST -- Find the nearest point to the cursor and return the index. +# The cursor is moved to the nearest point selected. + +int procedure ing_nearest$t (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variables (npts * nvars) +PIXEL y[npts] # Dependent variables +int npts # Number of points +int nvars # Number of variables +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int ing_n$t(), gt_geti() + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + # Set axes data + call ing_axes$t (in, gt, nl, 1, x, y, Mem$t[xout], npts, nvars) + call ing_axes$t (in, gt, nl, 2, x, y, Mem$t[yout], npts, nvars) + + # Check for transposed axes + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = ing_n$t (gp, Mem$t[xout], Mem$t[yout], npts, wx, wy) + else + pt = ing_n$t (gp, Mem$t[yout], Mem$t[xout], npts, wy, wx) + call sfree (sp) + + # Return index + return (pt) +end + + +# ING_N -- Find position and move the cursor. + +int procedure ing_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 xc, yc, x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + call gctran (gp, wx, wy, xc, yc, 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 - xc) ** 2 + (y0 - yc) ** 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])) + wx = x[j] + wy = y[j] + } + return (j) +end diff --git a/pkg/xtools/inlfit/ingnearestd.x b/pkg/xtools/inlfit/ingnearestd.x new file mode 100644 index 00000000..d27f7a6b --- /dev/null +++ b/pkg/xtools/inlfit/ingnearestd.x @@ -0,0 +1,81 @@ +include <mach.h> +include <pkg/gtools.h> + + +# ING_NEAREST -- Find the nearest point to the cursor and return the index. +# The cursor is moved to the nearest point selected. + +int procedure ing_nearestd (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +double x[ARB] # Independent variables (npts * nvars) +double y[npts] # Dependent variables +int npts # Number of points +int nvars # Number of variables +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int ing_nd(), gt_geti() + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + # Set axes data + call ing_axesd (in, gt, nl, 1, x, y, Memd[xout], npts, nvars) + call ing_axesd (in, gt, nl, 2, x, y, Memd[yout], npts, nvars) + + # Check for transposed axes + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = ing_nd (gp, Memd[xout], Memd[yout], npts, wx, wy) + else + pt = ing_nd (gp, Memd[yout], Memd[xout], npts, wy, wx) + call sfree (sp) + + # Return index + return (pt) +end + + +# ING_N -- Find position and move the cursor. + +int procedure ing_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 xc, yc, x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + call gctran (gp, wx, wy, xc, yc, 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 - xc) ** 2 + (y0 - yc) ** 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])) + wx = x[j] + wy = y[j] + } + return (j) +end diff --git a/pkg/xtools/inlfit/ingnearestr.x b/pkg/xtools/inlfit/ingnearestr.x new file mode 100644 index 00000000..2ac7de51 --- /dev/null +++ b/pkg/xtools/inlfit/ingnearestr.x @@ -0,0 +1,81 @@ +include <mach.h> +include <pkg/gtools.h> + + +# ING_NEAREST -- Find the nearest point to the cursor and return the index. +# The cursor is moved to the nearest point selected. + +int procedure ing_nearestr (in, gp, gt, nl, x, y, npts, nvars, wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +real x[ARB] # Independent variables (npts * nvars) +real y[npts] # Dependent variables +int npts # Number of points +int nvars # Number of variables +real wx, wy # Cursor position + +int pt +pointer sp, xout, yout + +int ing_nr(), gt_geti() + +begin + # Allocate memory for axes data + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + # Set axes data + call ing_axesr (in, gt, nl, 1, x, y, Memr[xout], npts, nvars) + call ing_axesr (in, gt, nl, 2, x, y, Memr[yout], npts, nvars) + + # Check for transposed axes + if (gt_geti (gt, GTTRANSPOSE) == NO) + pt = ing_nr (gp, Memr[xout], Memr[yout], npts, wx, wy) + else + pt = ing_nr (gp, Memr[yout], Memr[xout], npts, wy, wx) + call sfree (sp) + + # Return index + return (pt) +end + + +# ING_N -- Find position and move the cursor. + +int procedure ing_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 xc, yc, x0, y0, r2, r2min + +begin + # Transform world cursor coordinates to NDC. + call gctran (gp, wx, wy, xc, yc, 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 - xc) ** 2 + (y0 - yc) ** 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])) + wx = x[j] + wy = y[j] + } + return (j) +end diff --git a/pkg/xtools/inlfit/ingparams.gx b/pkg/xtools/inlfit/ingparams.gx new file mode 100644 index 00000000..e250d681 --- /dev/null +++ b/pkg/xtools/inlfit/ingparams.gx @@ -0,0 +1,120 @@ +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_PARAMS -- Set parameter string. + +procedure ing_params$t (in, nl, x, y, wts, npts, nvars, gt) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables +pointer gt # GTOOLS pointer + +int i, rejected, deleted, length +int len3, len4 +PIXEL rms +pointer sp, fit, wts1, rejpts +pointer str1, str2, str3, str4, line + +int strlen() +int nlstati() +int inlstrwrd() +int in_geti() +PIXEL nlstat$t() +PIXEL in_rms$t() +PIXEL in_get$t() +pointer in_getp() + +begin + # Allocate memory + call smark (sp) + call salloc (fit, npts, TY_PIXEL) + call salloc (wts1, npts, TY_PIXEL) + call salloc (str1, SZ_LINE, TY_CHAR) + call salloc (str2, SZ_LINE, TY_CHAR) + call salloc (str3, SZ_LINE, TY_CHAR) + call salloc (str4, SZ_LINE, TY_CHAR) + + # Mark rejected points as deleted for rms comnputation, + # and count number of deleted points. + call amov$t (wts, Mem$t[wts1], npts) + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Mem$t[wts1+i-1] = PIXEL (0.0) + } + } + deleted = 0 + do i = 1, npts { + if (wts[i] == PIXEL (0.0)) + deleted = deleted + 1 + } + + # Set the fit and compute the RMS error. + if (in_geti (in, INLFITERROR) == DONE) { + call nlvector$t (nl, x, Mem$t[fit], npts, nvars) + rms = in_rms$t (y, Mem$t[fit], Mem$t[wts1], npts) + } else + rms = INDEF + + # Build interactive graphics and NLFIT parameter strings + call sprintf (Memc[str1], SZ_LINE, + #"low_rej=%7.4g, high_rej=%7.4g, nreject=%d, grow=%7.4g") + "low_rej=%.4g, high_rej=%.4g, nreject=%d, grow=%.4g") + call parg$t (in_get$t (in, INLLOW)) + call parg$t (in_get$t (in, INLHIGH)) + call pargi (in_geti (in, INLNREJECT)) + call parg$t (in_get$t (in, INLGROW)) + call sprintf (Memc[str2], SZ_LINE, + #"total=%d, rejected=%d, deleted=%d, RMS=%7.4g") + "total=%d, rejected=%d, deleted=%d, RMS=%.4g") + call pargi (npts) + call pargi (rejected) + call pargi (deleted) + call parg$t (rms) + call sprintf (Memc[str3], SZ_LINE, + #"tolerance=%7.4g, maxiter=%d, iterations=%d") + "tolerance=%.4g, maxiter=%d, iterations=%d") + call parg$t (nlstat$t (nl, NLTOL)) + call pargi (nlstati (nl, NLITMAX)) + call pargi (nlstati (nl, NLITER)) + + # Set the output parameter line. + length = strlen (Memc[str1]) + strlen (Memc[str2]) + + strlen (Memc[str3]) + 3 + call salloc (line, length + 1, TY_CHAR) + call sprintf (Memc[line], length, "%s\n%s\n%s") + call pargstr (Memc[str1]) + call pargstr (Memc[str2]) + call pargstr (Memc[str3]) + call gt_sets (gt, GTPARAMS, Memc[line]) + + # Get the error and function label strings. + call nlerrmsg (in_geti (in, INLFITERROR), Memc[str1], SZ_LINE) + call in_gstr (in, INLFLABELS, Memc[str2], SZ_LINE) + + # Set the output title line. + len3 = inlstrwrd (1, Memc[str3], SZ_LINE, Memc[str2]) + len4 = inlstrwrd (2, Memc[str4], SZ_LINE, Memc[str2]) + if (len3 != 0 && len4 != 0) { + call sprintf (Memc[line], length, "%s = %s\n%s") + call pargstr (Memc[str3]) + call pargstr (Memc[str4]) + call pargstr (Memc[str1]) + } else { + call sprintf (Memc[line], length, "%s") + call pargstr (Memc[str2]) + } + call gt_sets (gt, GTTITLE, Memc[line]) + + # Free allocated memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingparamsd.x b/pkg/xtools/inlfit/ingparamsd.x new file mode 100644 index 00000000..eceea41c --- /dev/null +++ b/pkg/xtools/inlfit/ingparamsd.x @@ -0,0 +1,120 @@ +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_PARAMS -- Set parameter string. + +procedure ing_paramsd (in, nl, x, y, wts, npts, nvars, gt) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[ARB] # Abscissas +double wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables +pointer gt # GTOOLS pointer + +int i, rejected, deleted, length +int len3, len4 +double rms +pointer sp, fit, wts1, rejpts +pointer str1, str2, str3, str4, line + +int strlen() +int nlstati() +int inlstrwrd() +int in_geti() +double nlstatd() +double in_rmsd() +double in_getd() +pointer in_getp() + +begin + # Allocate memory + call smark (sp) + call salloc (fit, npts, TY_DOUBLE) + call salloc (wts1, npts, TY_DOUBLE) + call salloc (str1, SZ_LINE, TY_CHAR) + call salloc (str2, SZ_LINE, TY_CHAR) + call salloc (str3, SZ_LINE, TY_CHAR) + call salloc (str4, SZ_LINE, TY_CHAR) + + # Mark rejected points as deleted for rms comnputation, + # and count number of deleted points. + call amovd (wts, Memd[wts1], npts) + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memd[wts1+i-1] = double (0.0) + } + } + deleted = 0 + do i = 1, npts { + if (wts[i] == double (0.0)) + deleted = deleted + 1 + } + + # Set the fit and compute the RMS error. + if (in_geti (in, INLFITERROR) == DONE) { + call nlvectord (nl, x, Memd[fit], npts, nvars) + rms = in_rmsd (y, Memd[fit], Memd[wts1], npts) + } else + rms = INDEFD + + # Build interactive graphics and NLFIT parameter strings + call sprintf (Memc[str1], SZ_LINE, + #"low_rej=%7.4g, high_rej=%7.4g, nreject=%d, grow=%7.4g") + "low_rej=%.4g, high_rej=%.4g, nreject=%d, grow=%.4g") + call pargd (in_getd (in, INLLOW)) + call pargd (in_getd (in, INLHIGH)) + call pargi (in_geti (in, INLNREJECT)) + call pargd (in_getd (in, INLGROW)) + call sprintf (Memc[str2], SZ_LINE, + #"total=%d, rejected=%d, deleted=%d, RMS=%7.4g") + "total=%d, rejected=%d, deleted=%d, RMS=%.4g") + call pargi (npts) + call pargi (rejected) + call pargi (deleted) + call pargd (rms) + call sprintf (Memc[str3], SZ_LINE, + #"tolerance=%7.4g, maxiter=%d, iterations=%d") + "tolerance=%.4g, maxiter=%d, iterations=%d") + call pargd (nlstatd (nl, NLTOL)) + call pargi (nlstati (nl, NLITMAX)) + call pargi (nlstati (nl, NLITER)) + + # Set the output parameter line. + length = strlen (Memc[str1]) + strlen (Memc[str2]) + + strlen (Memc[str3]) + 3 + call salloc (line, length + 1, TY_CHAR) + call sprintf (Memc[line], length, "%s\n%s\n%s") + call pargstr (Memc[str1]) + call pargstr (Memc[str2]) + call pargstr (Memc[str3]) + call gt_sets (gt, GTPARAMS, Memc[line]) + + # Get the error and function label strings. + call nlerrmsg (in_geti (in, INLFITERROR), Memc[str1], SZ_LINE) + call in_gstr (in, INLFLABELS, Memc[str2], SZ_LINE) + + # Set the output title line. + len3 = inlstrwrd (1, Memc[str3], SZ_LINE, Memc[str2]) + len4 = inlstrwrd (2, Memc[str4], SZ_LINE, Memc[str2]) + if (len3 != 0 && len4 != 0) { + call sprintf (Memc[line], length, "%s = %s\n%s") + call pargstr (Memc[str3]) + call pargstr (Memc[str4]) + call pargstr (Memc[str1]) + } else { + call sprintf (Memc[line], length, "%s") + call pargstr (Memc[str2]) + } + call gt_sets (gt, GTTITLE, Memc[line]) + + # Free allocated memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingparamsr.x b/pkg/xtools/inlfit/ingparamsr.x new file mode 100644 index 00000000..53f9ffc9 --- /dev/null +++ b/pkg/xtools/inlfit/ingparamsr.x @@ -0,0 +1,120 @@ +include <pkg/gtools.h> +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_PARAMS -- Set parameter string. + +procedure ing_paramsr (in, nl, x, y, wts, npts, nvars, gt) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[ARB] # Abscissas +real wts[ARB] # Weights +int npts # Number of data points +int nvars # Number of variables +pointer gt # GTOOLS pointer + +int i, rejected, deleted, length +int len3, len4 +real rms +pointer sp, fit, wts1, rejpts +pointer str1, str2, str3, str4, line + +int strlen() +int nlstati() +int inlstrwrd() +int in_geti() +real nlstatr() +real in_rmsr() +real in_getr() +pointer in_getp() + +begin + # Allocate memory + call smark (sp) + call salloc (fit, npts, TY_REAL) + call salloc (wts1, npts, TY_REAL) + call salloc (str1, SZ_LINE, TY_CHAR) + call salloc (str2, SZ_LINE, TY_CHAR) + call salloc (str3, SZ_LINE, TY_CHAR) + call salloc (str4, SZ_LINE, TY_CHAR) + + # Mark rejected points as deleted for rms comnputation, + # and count number of deleted points. + call amovr (wts, Memr[wts1], npts) + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memr[wts1+i-1] = real (0.0) + } + } + deleted = 0 + do i = 1, npts { + if (wts[i] == real (0.0)) + deleted = deleted + 1 + } + + # Set the fit and compute the RMS error. + if (in_geti (in, INLFITERROR) == DONE) { + call nlvectorr (nl, x, Memr[fit], npts, nvars) + rms = in_rmsr (y, Memr[fit], Memr[wts1], npts) + } else + rms = INDEFR + + # Build interactive graphics and NLFIT parameter strings + call sprintf (Memc[str1], SZ_LINE, + #"low_rej=%7.4g, high_rej=%7.4g, nreject=%d, grow=%7.4g") + "low_rej=%.4g, high_rej=%.4g, nreject=%d, grow=%.4g") + call pargr (in_getr (in, INLLOW)) + call pargr (in_getr (in, INLHIGH)) + call pargi (in_geti (in, INLNREJECT)) + call pargr (in_getr (in, INLGROW)) + call sprintf (Memc[str2], SZ_LINE, + #"total=%d, rejected=%d, deleted=%d, RMS=%7.4g") + "total=%d, rejected=%d, deleted=%d, RMS=%.4g") + call pargi (npts) + call pargi (rejected) + call pargi (deleted) + call pargr (rms) + call sprintf (Memc[str3], SZ_LINE, + #"tolerance=%7.4g, maxiter=%d, iterations=%d") + "tolerance=%.4g, maxiter=%d, iterations=%d") + call pargr (nlstatr (nl, NLTOL)) + call pargi (nlstati (nl, NLITMAX)) + call pargi (nlstati (nl, NLITER)) + + # Set the output parameter line. + length = strlen (Memc[str1]) + strlen (Memc[str2]) + + strlen (Memc[str3]) + 3 + call salloc (line, length + 1, TY_CHAR) + call sprintf (Memc[line], length, "%s\n%s\n%s") + call pargstr (Memc[str1]) + call pargstr (Memc[str2]) + call pargstr (Memc[str3]) + call gt_sets (gt, GTPARAMS, Memc[line]) + + # Get the error and function label strings. + call nlerrmsg (in_geti (in, INLFITERROR), Memc[str1], SZ_LINE) + call in_gstr (in, INLFLABELS, Memc[str2], SZ_LINE) + + # Set the output title line. + len3 = inlstrwrd (1, Memc[str3], SZ_LINE, Memc[str2]) + len4 = inlstrwrd (2, Memc[str4], SZ_LINE, Memc[str2]) + if (len3 != 0 && len4 != 0) { + call sprintf (Memc[line], length, "%s = %s\n%s") + call pargstr (Memc[str3]) + call pargstr (Memc[str4]) + call pargstr (Memc[str1]) + } else { + call sprintf (Memc[line], length, "%s") + call pargstr (Memc[str2]) + } + call gt_sets (gt, GTTITLE, Memc[line]) + + # Free allocated memory. + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingresults.gx b/pkg/xtools/inlfit/ingresults.gx new file mode 100644 index 00000000..6582bd35 --- /dev/null +++ b/pkg/xtools/inlfit/ingresults.gx @@ -0,0 +1,85 @@ +include <pkg/inlfit.h> + +# ING_RESULTS -- Print the results of the fit. + +procedure ing_results$t (in, file, nl, x, y, wts, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of a name + +int i, fd, rejected +pointer sp, fit, wts1, rejpts +int open(), in_geti() +pointer in_getp() +errchk open + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (fit, npts, TY_PIXEL) + call salloc (wts1, npts, TY_PIXEL) + + # Evaluate the fit. + call nlvector$t (nl, x, Mem$t[fit], npts, nvars) + + # Assign a zero weight to the rejected points. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + call amov$t (wts, Mem$t[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Mem$t[wts1+i-1] = PIXEL (0.0) + } + } + + # Print the title. + call fprintf (fd, "\n#%14.14s %14.14s %14.14s") + call pargstr ("objectid") + call pargstr ("function") + call pargstr ("fit") + call fprintf (fd, " %14.14s %14.14s\n") + call pargstr ("residuals") + call pargstr ("sigma") + + # List function value, fit value, residual and error values. + do i = 1, npts { + call fprintf (fd, " %14.14s %14.7g %14.7g %14.7g %14.7g\n") + call pargstr (names[(i-1)*len_name+1]) + if (Mem$t[wts1+i-1] <= 0.0) { + call parg$t (INDEF) + call parg$t (INDEF) + call parg$t (INDEF) + call parg$t (INDEF) + } else { + call parg$t (y[i]) + call parg$t (Mem$t[fit+i-1]) + call parg$t (y[i] - Mem$t[fit+i-1]) + call parg$t (sqrt (PIXEL (1.0) / Mem$t[wts1+i-1])) + } + } + call fprintf (fd, "\n") + + # Free allocated memory, and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingresultsd.x b/pkg/xtools/inlfit/ingresultsd.x new file mode 100644 index 00000000..c19d8166 --- /dev/null +++ b/pkg/xtools/inlfit/ingresultsd.x @@ -0,0 +1,85 @@ +include <pkg/inlfit.h> + +# ING_RESULTS -- Print the results of the fit. + +procedure ing_resultsd (in, file, nl, x, y, wts, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[ARB] # Abscissas +double wts[ARB] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of a name + +int i, fd, rejected +pointer sp, fit, wts1, rejpts +int open(), in_geti() +pointer in_getp() +errchk open + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (fit, npts, TY_DOUBLE) + call salloc (wts1, npts, TY_DOUBLE) + + # Evaluate the fit. + call nlvectord (nl, x, Memd[fit], npts, nvars) + + # Assign a zero weight to the rejected points. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + call amovd (wts, Memd[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memd[wts1+i-1] = double (0.0) + } + } + + # Print the title. + call fprintf (fd, "\n#%14.14s %14.14s %14.14s") + call pargstr ("objectid") + call pargstr ("function") + call pargstr ("fit") + call fprintf (fd, " %14.14s %14.14s\n") + call pargstr ("residuals") + call pargstr ("sigma") + + # List function value, fit value, residual and error values. + do i = 1, npts { + call fprintf (fd, " %14.14s %14.7g %14.7g %14.7g %14.7g\n") + call pargstr (names[(i-1)*len_name+1]) + if (Memd[wts1+i-1] <= 0.0) { + call pargd (INDEFD) + call pargd (INDEFD) + call pargd (INDEFD) + call pargd (INDEFD) + } else { + call pargd (y[i]) + call pargd (Memd[fit+i-1]) + call pargd (y[i] - Memd[fit+i-1]) + call pargd (sqrt (double (1.0) / Memd[wts1+i-1])) + } + } + call fprintf (fd, "\n") + + # Free allocated memory, and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingresultsr.x b/pkg/xtools/inlfit/ingresultsr.x new file mode 100644 index 00000000..d6e6f43c --- /dev/null +++ b/pkg/xtools/inlfit/ingresultsr.x @@ -0,0 +1,85 @@ +include <pkg/inlfit.h> + +# ING_RESULTS -- Print the results of the fit. + +procedure ing_resultsr (in, file, nl, x, y, wts, names, npts, nvars, len_name) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[ARB] # Abscissas +real wts[ARB] # Weights +char names[ARB] # Object names +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of a name + +int i, fd, rejected +pointer sp, fit, wts1, rejpts +int open(), in_geti() +pointer in_getp() +errchk open + +begin + # Open the output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Test the number of points. + if (npts == 0) { + call eprintf ("Incomplete output - no data points for fit\n") + return + } + + # Allocate memory. + call smark (sp) + call salloc (fit, npts, TY_REAL) + call salloc (wts1, npts, TY_REAL) + + # Evaluate the fit. + call nlvectorr (nl, x, Memr[fit], npts, nvars) + + # Assign a zero weight to the rejected points. + rejected = in_geti (in, INLNREJPTS) + rejpts = in_getp (in, INLREJPTS) + call amovr (wts, Memr[wts1], npts) + if (rejected > 0) { + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + Memr[wts1+i-1] = real (0.0) + } + } + + # Print the title. + call fprintf (fd, "\n#%14.14s %14.14s %14.14s") + call pargstr ("objectid") + call pargstr ("function") + call pargstr ("fit") + call fprintf (fd, " %14.14s %14.14s\n") + call pargstr ("residuals") + call pargstr ("sigma") + + # List function value, fit value, residual and error values. + do i = 1, npts { + call fprintf (fd, " %14.14s %14.7g %14.7g %14.7g %14.7g\n") + call pargstr (names[(i-1)*len_name+1]) + if (Memr[wts1+i-1] <= 0.0) { + call pargr (INDEFR) + call pargr (INDEFR) + call pargr (INDEFR) + call pargr (INDEFR) + } else { + call pargr (y[i]) + call pargr (Memr[fit+i-1]) + call pargr (y[i] - Memr[fit+i-1]) + call pargr (sqrt (real (1.0) / Memr[wts1+i-1])) + } + } + call fprintf (fd, "\n") + + # Free allocated memory, and close output file. + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingshow.gx b/pkg/xtools/inlfit/ingshow.gx new file mode 100644 index 00000000..28efcc6e --- /dev/null +++ b/pkg/xtools/inlfit/ingshow.gx @@ -0,0 +1,40 @@ +include <pkg/inlfit.h> + + +# ING_SHOW -- Show the values of all the user defined parameters that +# can be changed with colon commands. The output can be any file. + +procedure ing_show$t (in, file) + +pointer in # INLFIT pointer +char file[ARB] # Output file + +int fd +int open(), in_geti() +PIXEL in_get$t +errchk open() + +begin + # Open output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Print parameters. + call fprintf (fd, "low_reject %g\n") + call parg$t (in_get$t (in, INLLOW)) + call fprintf (fd, "high_reject %g\n") + call parg$t (in_get$t (in, INLHIGH)) + call fprintf (fd, "nreject %d\n") + call pargi (in_geti (in, INLNREJECT)) + call fprintf (fd, "grow %g\n") + call parg$t (in_get$t (in, INLGROW)) + call fprintf (fd, "tol %g\n") + call parg$t (in_get$t (in, INLTOLERANCE)) + call fprintf (fd, "maxiter %d\n") + call pargi (in_geti (in, INLMAXITER)) + call fprintf (fd, "\n") + + # Free memory and close file. + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingshowd.x b/pkg/xtools/inlfit/ingshowd.x new file mode 100644 index 00000000..031ae3f3 --- /dev/null +++ b/pkg/xtools/inlfit/ingshowd.x @@ -0,0 +1,40 @@ +include <pkg/inlfit.h> + + +# ING_SHOW -- Show the values of all the user defined parameters that +# can be changed with colon commands. The output can be any file. + +procedure ing_showd (in, file) + +pointer in # INLFIT pointer +char file[ARB] # Output file + +int fd +int open(), in_geti() +double in_getd +errchk open() + +begin + # Open output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Print parameters. + call fprintf (fd, "low_reject %g\n") + call pargd (in_getd (in, INLLOW)) + call fprintf (fd, "high_reject %g\n") + call pargd (in_getd (in, INLHIGH)) + call fprintf (fd, "nreject %d\n") + call pargi (in_geti (in, INLNREJECT)) + call fprintf (fd, "grow %g\n") + call pargd (in_getd (in, INLGROW)) + call fprintf (fd, "tol %g\n") + call pargd (in_getd (in, INLTOLERANCE)) + call fprintf (fd, "maxiter %d\n") + call pargi (in_geti (in, INLMAXITER)) + call fprintf (fd, "\n") + + # Free memory and close file. + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingshowr.x b/pkg/xtools/inlfit/ingshowr.x new file mode 100644 index 00000000..237c90df --- /dev/null +++ b/pkg/xtools/inlfit/ingshowr.x @@ -0,0 +1,40 @@ +include <pkg/inlfit.h> + + +# ING_SHOW -- Show the values of all the user defined parameters that +# can be changed with colon commands. The output can be any file. + +procedure ing_showr (in, file) + +pointer in # INLFIT pointer +char file[ARB] # Output file + +int fd +int open(), in_geti() +real in_getr +errchk open() + +begin + # Open output file. + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + # Print parameters. + call fprintf (fd, "low_reject %g\n") + call pargr (in_getr (in, INLLOW)) + call fprintf (fd, "high_reject %g\n") + call pargr (in_getr (in, INLHIGH)) + call fprintf (fd, "nreject %d\n") + call pargi (in_geti (in, INLNREJECT)) + call fprintf (fd, "grow %g\n") + call pargr (in_getr (in, INLGROW)) + call fprintf (fd, "tol %g\n") + call pargr (in_getr (in, INLTOLERANCE)) + call fprintf (fd, "maxiter %d\n") + call pargi (in_geti (in, INLMAXITER)) + call fprintf (fd, "\n") + + # Free memory and close file. + call close (fd) +end diff --git a/pkg/xtools/inlfit/ingtitle.x b/pkg/xtools/inlfit/ingtitle.x new file mode 100644 index 00000000..8b9fd877 --- /dev/null +++ b/pkg/xtools/inlfit/ingtitle.x @@ -0,0 +1,49 @@ +include <pkg/gtools.h> + +# ING_TITLE -- Write out the time stamp and the title of the current fit. + +procedure ing_title (in, file, gt) + +pointer in # pointer to the inlfit structure (not used yet) +char file[ARB] # arbitrary file name +pointer gt # pointer to the gtools structure + +int fd, sfd +pointer sp, str +int open(), stropen(), fscan() +long clktime() + +begin + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Put time stamp in. + call cnvtime (clktime(0), Memc[str], SZ_LINE) + call fprintf (fd, "\n#%s\n") + call pargstr (Memc[str]) + + # Print plot title. + call gt_gets (gt, GTTITLE, Memc[str], SZ_LINE) + sfd = stropen (Memc[str], SZ_LINE, READ_ONLY) + while (fscan (sfd) != EOF) { + call gargstr (Memc[str], SZ_LINE) + call fprintf (fd, "#%s\n") + call pargstr (Memc[str]) + } + call fprintf (fd, "\n") + call strclose (sfd) + + # Print fit units. + #call gt_gets (gt, GTYUNITS, Memc[str], SZ_LINE) + #if (Memc[str] != EOS) { + #call fprintf (fd, "fit_units %s\n") + #call pargstr (Memc[str]) + #} + + call sfree (sp) + call close (fd) +end diff --git a/pkg/xtools/inlfit/inguaxes.gx b/pkg/xtools/inlfit/inguaxes.gx new file mode 100644 index 00000000..58942f52 --- /dev/null +++ b/pkg/xtools/inlfit/inguaxes.gx @@ -0,0 +1,47 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_UAXES -- Set user axis + +procedure ing_uaxes$t (keynum, in, nl, x, y, z, npts, nvars) + +int keynum # Key number for axes +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variable +PIXEL y[npts] # Dependent variable +PIXEL z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int npars # number of parameters +int uaxes # user defined procedure +pointer params # parameter values +pointer sp + +int nlstati() +int in_geti() + +begin + # Check if equation is defined + uaxes = in_geti (in, INLUAXES) + if (!IS_INDEFI (uaxes)) { + + # Get number of parameters, allocate space + # for parameter values, and get parameter values + npars = nlstati (nl, NLNPARAMS) + call smark (sp) + call salloc (params, npars, TY_PIXEL) + call nlpget$t (nl, Mem$t[params], npars) + + # Call user plot functions + call zcall8 (uaxes, keynum, Mem$t[params], npars, + x, y, z, npts, nvars) + + # Free memory + call sfree (sp) + + } else + call eprintf ("Warning: User plot function not defined\n") +end diff --git a/pkg/xtools/inlfit/inguaxesd.x b/pkg/xtools/inlfit/inguaxesd.x new file mode 100644 index 00000000..48759bc0 --- /dev/null +++ b/pkg/xtools/inlfit/inguaxesd.x @@ -0,0 +1,47 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_UAXES -- Set user axis + +procedure ing_uaxesd (keynum, in, nl, x, y, z, npts, nvars) + +int keynum # Key number for axes +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +double x[ARB] # Independent variable +double y[npts] # Dependent variable +double z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int npars # number of parameters +int uaxes # user defined procedure +pointer params # parameter values +pointer sp + +int nlstati() +int in_geti() + +begin + # Check if equation is defined + uaxes = in_geti (in, INLUAXES) + if (!IS_INDEFI (uaxes)) { + + # Get number of parameters, allocate space + # for parameter values, and get parameter values + npars = nlstati (nl, NLNPARAMS) + call smark (sp) + call salloc (params, npars, TY_DOUBLE) + call nlpgetd (nl, Memd[params], npars) + + # Call user plot functions + call zcall8 (uaxes, keynum, Memd[params], npars, + x, y, z, npts, nvars) + + # Free memory + call sfree (sp) + + } else + call eprintf ("Warning: User plot function not defined\n") +end diff --git a/pkg/xtools/inlfit/inguaxesr.x b/pkg/xtools/inlfit/inguaxesr.x new file mode 100644 index 00000000..53905563 --- /dev/null +++ b/pkg/xtools/inlfit/inguaxesr.x @@ -0,0 +1,47 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# ING_UAXES -- Set user axis + +procedure ing_uaxesr (keynum, in, nl, x, y, z, npts, nvars) + +int keynum # Key number for axes +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +real x[ARB] # Independent variable +real y[npts] # Dependent variable +real z[npts] # Output values +int npts # Number of points +int nvars # Number of variables + +int npars # number of parameters +int uaxes # user defined procedure +pointer params # parameter values +pointer sp + +int nlstati() +int in_geti() + +begin + # Check if equation is defined + uaxes = in_geti (in, INLUAXES) + if (!IS_INDEFI (uaxes)) { + + # Get number of parameters, allocate space + # for parameter values, and get parameter values + npars = nlstati (nl, NLNPARAMS) + call smark (sp) + call salloc (params, npars, TY_REAL) + call nlpgetr (nl, Memr[params], npars) + + # Call user plot functions + call zcall8 (uaxes, keynum, Memr[params], npars, + x, y, z, npts, nvars) + + # Free memory + call sfree (sp) + + } else + call eprintf ("Warning: User plot function not defined\n") +end diff --git a/pkg/xtools/inlfit/ingucolon.gx b/pkg/xtools/inlfit/ingucolon.gx new file mode 100644 index 00000000..3e858789 --- /dev/null +++ b/pkg/xtools/inlfit/ingucolon.gx @@ -0,0 +1,19 @@ +# ING_UCOLON -- User default colon commands + +procedure ing_ucolon$t (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variables +PIXEL y[npts] # Dependent variables +PIXEL wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int newgraph # New graph ? (output) + +begin + # Ring bell + call printf ("\07\n") +end diff --git a/pkg/xtools/inlfit/ingucolond.x b/pkg/xtools/inlfit/ingucolond.x new file mode 100644 index 00000000..db3ab047 --- /dev/null +++ b/pkg/xtools/inlfit/ingucolond.x @@ -0,0 +1,19 @@ +# ING_UCOLON -- User default colon commands + +procedure ing_ucolond (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +double x[ARB] # Independent variables +double y[npts] # Dependent variables +double wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int newgraph # New graph ? (output) + +begin + # Ring bell + call printf ("\07\n") +end diff --git a/pkg/xtools/inlfit/ingucolonr.x b/pkg/xtools/inlfit/ingucolonr.x new file mode 100644 index 00000000..1a7de7a5 --- /dev/null +++ b/pkg/xtools/inlfit/ingucolonr.x @@ -0,0 +1,19 @@ +# ING_UCOLON -- User default colon commands + +procedure ing_ucolonr (in, gp, gt, nl, x, y, wts, npts, nvars, newgraph) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +real x[ARB] # Independent variables +real y[npts] # Dependent variables +real wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int newgraph # New graph ? (output) + +begin + # Ring bell + call printf ("\07\n") +end diff --git a/pkg/xtools/inlfit/ingufit.x b/pkg/xtools/inlfit/ingufit.x new file mode 100644 index 00000000..5780d755 --- /dev/null +++ b/pkg/xtools/inlfit/ingufit.x @@ -0,0 +1,17 @@ +# ING_UFIT -- User default action for interactive fitting commands + +procedure ing_ufit (in, gp, gt, nl, wx, wy, wcs, key, cmd) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT 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/inlfit/ingundelete.gx b/pkg/xtools/inlfit/ingundelete.gx new file mode 100644 index 00000000..4b59156f --- /dev/null +++ b/pkg/xtools/inlfit/ingundelete.gx @@ -0,0 +1,92 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_UNDELETE -- Undelete data point nearest the cursor. The nearest point to +# the cursor in NDC coordinates is determined. + +procedure ing_undelete$t (in, gp, gt, nl, x, y, wts, userwts, npts, nvars, + wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Independent variables (npts * nvars) +PIXEL y[npts] # Dependent variables +PIXEL wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +pointer sp, xout, yout +int gt_geti() + +begin + # Allocate memory for the axes data. + call smark (sp) + call salloc (xout, npts, TY_PIXEL) + call salloc (yout, npts, TY_PIXEL) + + # Get the axes data. + call ing_axes$t (in, gt, nl, 1, x, y, Mem$t[xout], npts, nvars) + call ing_axes$t (in, gt, nl, 2, x, y, Mem$t[yout], npts, nvars) + + # Transpose axes if necessary. + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_u1$t (in, gp, Mem$t[xout], Mem$t[yout], wts, userwts, + npts, wx, wy) + else + call ing_u1$t (in, gp, Mem$t[yout], Mem$t[xout], wts, userwts, + npts, wy, wx) + + # Free memory. + call sfree (sp) +end + + +# ING_U1 -- Do the actual undelete. + +procedure ing_u1$t (in, gp, x, y, wts, userwts, npts, wx, wy) + +pointer in # 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] != PIXEL (0.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])) + call gmark (gp, real (x[j]), real (y[j]), GM_PLUS, MSIZE, MSIZE) + wts[j] = userwts[j] + } +end diff --git a/pkg/xtools/inlfit/ingundeleted.x b/pkg/xtools/inlfit/ingundeleted.x new file mode 100644 index 00000000..5b7717d9 --- /dev/null +++ b/pkg/xtools/inlfit/ingundeleted.x @@ -0,0 +1,92 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_UNDELETE -- Undelete data point nearest the cursor. The nearest point to +# the cursor in NDC coordinates is determined. + +procedure ing_undeleted (in, gp, gt, nl, x, y, wts, userwts, npts, nvars, + wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +double x[ARB] # Independent variables (npts * nvars) +double y[npts] # Dependent variables +double wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +pointer sp, xout, yout +int gt_geti() + +begin + # Allocate memory for the axes data. + call smark (sp) + call salloc (xout, npts, TY_DOUBLE) + call salloc (yout, npts, TY_DOUBLE) + + # Get the axes data. + call ing_axesd (in, gt, nl, 1, x, y, Memd[xout], npts, nvars) + call ing_axesd (in, gt, nl, 2, x, y, Memd[yout], npts, nvars) + + # Transpose axes if necessary. + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_u1d (in, gp, Memd[xout], Memd[yout], wts, userwts, + npts, wx, wy) + else + call ing_u1d (in, gp, Memd[yout], Memd[xout], wts, userwts, + npts, wy, wx) + + # Free memory. + call sfree (sp) +end + + +# ING_U1 -- Do the actual undelete. + +procedure ing_u1d (in, gp, x, y, wts, userwts, npts, wx, wy) + +pointer in # 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] != double (0.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])) + call gmark (gp, real (x[j]), real (y[j]), GM_PLUS, MSIZE, MSIZE) + wts[j] = userwts[j] + } +end diff --git a/pkg/xtools/inlfit/ingundeleter.x b/pkg/xtools/inlfit/ingundeleter.x new file mode 100644 index 00000000..149003e5 --- /dev/null +++ b/pkg/xtools/inlfit/ingundeleter.x @@ -0,0 +1,92 @@ +include <gset.h> +include <mach.h> +include <pkg/gtools.h> + +define MSIZE 2.0 # Mark size (real) + + +# ING_UNDELETE -- Undelete data point nearest the cursor. The nearest point to +# the cursor in NDC coordinates is determined. + +procedure ing_undeleter (in, gp, gt, nl, x, y, wts, userwts, npts, nvars, + wx, wy) + +pointer in # INLFIT pointer +pointer gp # GIO pointer +pointer gt # GTOOLS pointer +pointer nl # NLFIT pointer +real x[ARB] # Independent variables (npts * nvars) +real y[npts] # Dependent variables +real wts[npts], userwts[npts] # Weight arrays +int npts # Number of points +int nvars # Number of variables +real wx, wy # Position to be nearest + +pointer sp, xout, yout +int gt_geti() + +begin + # Allocate memory for the axes data. + call smark (sp) + call salloc (xout, npts, TY_REAL) + call salloc (yout, npts, TY_REAL) + + # Get the axes data. + call ing_axesr (in, gt, nl, 1, x, y, Memr[xout], npts, nvars) + call ing_axesr (in, gt, nl, 2, x, y, Memr[yout], npts, nvars) + + # Transpose axes if necessary. + if (gt_geti (gt, GTTRANSPOSE) == NO) + call ing_u1r (in, gp, Memr[xout], Memr[yout], wts, userwts, + npts, wx, wy) + else + call ing_u1r (in, gp, Memr[yout], Memr[xout], wts, userwts, + npts, wy, wx) + + # Free memory. + call sfree (sp) +end + + +# ING_U1 -- Do the actual undelete. + +procedure ing_u1r (in, gp, x, y, wts, userwts, npts, wx, wy) + +pointer in # 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] != real (0.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])) + call gmark (gp, real (x[j]), real (y[j]), GM_PLUS, MSIZE, MSIZE) + wts[j] = userwts[j] + } +end diff --git a/pkg/xtools/inlfit/ingvars.gx b/pkg/xtools/inlfit/ingvars.gx new file mode 100644 index 00000000..291284a0 --- /dev/null +++ b/pkg/xtools/inlfit/ingvars.gx @@ -0,0 +1,55 @@ +include <pkg/inlfit.h> + +# ING_VARIABLES -- Write the variable numbers, names and minimum and maximum +# values to a file. + +procedure ing_variables$t (in, file, nvars) + +pointer in # pointer to the inlfit structure +char file[ARB] # output file name +int nvars # number of variables + +int i, fd +pointer sp, labels, pvnames, name, minptr, maxptr +int open(), inlstrwrd() +pointer in_getp() + +begin + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + call smark (sp) + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (pvnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + call in_gstr (in, INLVLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + + # Print the title string. + call fprintf (fd, "\n%-10.10s %-10.10s %14.14s %14.14s\n") + call pargstr ("number") + call pargstr ("variable") + call pargstr ("minimum") + call pargstr ("maximum") + + # Print the variables. + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + do i = 1, nvars { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) == 0) { + call sprintf (Memc[name], SZ_LINE, "var %d") + call pargi (i) + } + call fprintf (fd, "%-10.2d %-10.10s ") + call pargi (i) + call pargstr (Memc[name]) + call fprintf (fd, "%14.7f %14.7f\n") + call parg$t (Mem$t[minptr+i-1]) + call parg$t (Mem$t[maxptr+i-1]) + } + call fprintf (fd, "\n") + + call close (fd) + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingvarsd.x b/pkg/xtools/inlfit/ingvarsd.x new file mode 100644 index 00000000..257b51fb --- /dev/null +++ b/pkg/xtools/inlfit/ingvarsd.x @@ -0,0 +1,55 @@ +include <pkg/inlfit.h> + +# ING_VARIABLES -- Write the variable numbers, names and minimum and maximum +# values to a file. + +procedure ing_variablesd (in, file, nvars) + +pointer in # pointer to the inlfit structure +char file[ARB] # output file name +int nvars # number of variables + +int i, fd +pointer sp, labels, pvnames, name, minptr, maxptr +int open(), inlstrwrd() +pointer in_getp() + +begin + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + call smark (sp) + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (pvnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + call in_gstr (in, INLVLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + + # Print the title string. + call fprintf (fd, "\n%-10.10s %-10.10s %14.14s %14.14s\n") + call pargstr ("number") + call pargstr ("variable") + call pargstr ("minimum") + call pargstr ("maximum") + + # Print the variables. + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + do i = 1, nvars { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) == 0) { + call sprintf (Memc[name], SZ_LINE, "var %d") + call pargi (i) + } + call fprintf (fd, "%-10.2d %-10.10s ") + call pargi (i) + call pargstr (Memc[name]) + call fprintf (fd, "%14.7f %14.7f\n") + call pargd (Memd[minptr+i-1]) + call pargd (Memd[maxptr+i-1]) + } + call fprintf (fd, "\n") + + call close (fd) + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingvarsr.x b/pkg/xtools/inlfit/ingvarsr.x new file mode 100644 index 00000000..b0855805 --- /dev/null +++ b/pkg/xtools/inlfit/ingvarsr.x @@ -0,0 +1,55 @@ +include <pkg/inlfit.h> + +# ING_VARIABLES -- Write the variable numbers, names and minimum and maximum +# values to a file. + +procedure ing_variablesr (in, file, nvars) + +pointer in # pointer to the inlfit structure +char file[ARB] # output file name +int nvars # number of variables + +int i, fd +pointer sp, labels, pvnames, name, minptr, maxptr +int open(), inlstrwrd() +pointer in_getp() + +begin + if (file[1] == EOS) + return + fd = open (file, APPEND, TEXT_FILE) + + call smark (sp) + call salloc (labels, SZ_LINE, TY_CHAR) + call salloc (pvnames, SZ_LINE, TY_CHAR) + call salloc (name, SZ_LINE, TY_CHAR) + call in_gstr (in, INLVLABELS, Memc[labels], SZ_LINE) + call strcpy (Memc[labels], Memc[pvnames], SZ_LINE) + + # Print the title string. + call fprintf (fd, "\n%-10.10s %-10.10s %14.14s %14.14s\n") + call pargstr ("number") + call pargstr ("variable") + call pargstr ("minimum") + call pargstr ("maximum") + + # Print the variables. + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + do i = 1, nvars { + if (inlstrwrd (i, Memc[name], SZ_LINE, Memc[pvnames]) == 0) { + call sprintf (Memc[name], SZ_LINE, "var %d") + call pargi (i) + } + call fprintf (fd, "%-10.2d %-10.10s ") + call pargi (i) + call pargstr (Memc[name]) + call fprintf (fd, "%14.7f %14.7f\n") + call pargr (Memr[minptr+i-1]) + call pargr (Memr[maxptr+i-1]) + } + call fprintf (fd, "\n") + + call close (fd) + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/ingvshow.gx b/pkg/xtools/inlfit/ingvshow.gx new file mode 100644 index 00000000..129e6b4c --- /dev/null +++ b/pkg/xtools/inlfit/ingvshow.gx @@ -0,0 +1,34 @@ +include <pkg/inlfit.h> + + +# ING_VSHOW -- Show fit parameters in verbose mode on the screen. + +procedure ing_vshow$t (in, file, nl, x, y, wts, names, npts, nvars, len_name, + gt) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates (npts * nvars) +PIXEL y[ARB] # Abscissas +PIXEL wts[ARB] # Weights +char names[ARB] # Object ids +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of id name +pointer gt # Graphics tools pointer + +begin + # Print the title. + call ing_title (in, file, gt) + + # Do the standard ing_show option. + call ing_show$t (in, file) + + # Print the error analysis information. + call ing_errors$t (in, file, nl, x, y, wts, npts, nvars) + + # Print the results. + call ing_results$t (in, file, nl, x, y, wts, names, npts, nvars, + len_name) +end diff --git a/pkg/xtools/inlfit/ingvshowd.x b/pkg/xtools/inlfit/ingvshowd.x new file mode 100644 index 00000000..e7a2af30 --- /dev/null +++ b/pkg/xtools/inlfit/ingvshowd.x @@ -0,0 +1,34 @@ +include <pkg/inlfit.h> + + +# ING_VSHOW -- Show fit parameters in verbose mode on the screen. + +procedure ing_vshowd (in, file, nl, x, y, wts, names, npts, nvars, len_name, + gt) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +double x[ARB] # Ordinates (npts * nvars) +double y[ARB] # Abscissas +double wts[ARB] # Weights +char names[ARB] # Object ids +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of id name +pointer gt # Graphics tools pointer + +begin + # Print the title. + call ing_title (in, file, gt) + + # Do the standard ing_show option. + call ing_showd (in, file) + + # Print the error analysis information. + call ing_errorsd (in, file, nl, x, y, wts, npts, nvars) + + # Print the results. + call ing_resultsd (in, file, nl, x, y, wts, names, npts, nvars, + len_name) +end diff --git a/pkg/xtools/inlfit/ingvshowr.x b/pkg/xtools/inlfit/ingvshowr.x new file mode 100644 index 00000000..aed987ce --- /dev/null +++ b/pkg/xtools/inlfit/ingvshowr.x @@ -0,0 +1,34 @@ +include <pkg/inlfit.h> + + +# ING_VSHOW -- Show fit parameters in verbose mode on the screen. + +procedure ing_vshowr (in, file, nl, x, y, wts, names, npts, nvars, len_name, + gt) + +pointer in # INLFIT pointer +char file[ARB] # Output file name +pointer nl # NLFIT pointer +real x[ARB] # Ordinates (npts * nvars) +real y[ARB] # Abscissas +real wts[ARB] # Weights +char names[ARB] # Object ids +int npts # Number of data points +int nvars # Number of variables +int len_name # Length of id name +pointer gt # Graphics tools pointer + +begin + # Print the title. + call ing_title (in, file, gt) + + # Do the standard ing_show option. + call ing_showr (in, file) + + # Print the error analysis information. + call ing_errorsr (in, file, nl, x, y, wts, npts, nvars) + + # Print the results. + call ing_resultsr (in, file, nl, x, y, wts, names, npts, nvars, + len_name) +end diff --git a/pkg/xtools/inlfit/ininit.gx b/pkg/xtools/inlfit/ininit.gx new file mode 100644 index 00000000..a0df0ffe --- /dev/null +++ b/pkg/xtools/inlfit/ininit.gx @@ -0,0 +1,172 @@ +.help ininit +INLFIT memory allocation procedures. All the calls to malloc() and realloc() +are grouped in this file. Acces to the INLFIT structure is restricted to +the in_get() and in_put() procedures, except for buffer allocation and +initialization. +.nf + +User entry points: + + in_init$t (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +Low level entry point: + + in_bfinit$t (in, npts, nvars) +.fi +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + + +# IN_INIT -- Initialize INLFIT parameter structure. + +procedure in_init$t (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +pointer in # INLFIT pointer +int func # fitting function address +int dfunc # derivative function address +PIXEL param[nparams] # parameter values +PIXEL dparam[nparams] # initial guess at uncertenties in parameters +int nparams # number of parameters +int plist[nparams] # list of active parameters +int nfparams # number of fitting paramters + +begin +# # Debug. +# call eprintf ( +# "in_init: in=%d, func=%d, dfunc=%d, npars=%d, nfpars=%d\n") +# call pargi (in) +# call pargi (func) +# call pargi (dfunc) +# call pargi (nparams) +# call pargi (nfparams) + + # Allocate the structure memory. + call malloc (in, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (in), nparams, TY_PIXEL) + call malloc (IN_DPARAM (in), nparams, TY_PIXEL) + call malloc (IN_PLIST (in), nparams, TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_HELP(in), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT(in), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (in), LEN_INLFLOAT, TY_PIXEL) + call malloc (IN_SGAXES (in), INLNGKEYS * LEN_INLGRAPH, TY_INT) + + # Enter procedure parameters into the structure. + call in_puti (in, INLFUNCTION, func) + call in_puti (in, INLDERIVATIVE, dfunc) + call in_puti (in, INLNPARAMS, nparams) + call in_puti (in, INLNFPARAMS, nfparams) + call amov$t (param, Mem$t[IN_PARAM(in)], nparams) + call amov$t (dparam, Mem$t[IN_DPARAM(in)], nparams) + call amovi (plist, Memi[IN_PLIST(in)], nparams) + + # Set defaults, just in case. + call in_put$t (in, INLTOLERANCE, PIXEL (0.01)) + call in_puti (in, INLMAXITER, 3) + call in_puti (in, INLNREJECT, 0) + call in_put$t (in, INLLOW, PIXEL (3.0)) + call in_put$t (in, INLHIGH, PIXEL (3.0)) + call in_put$t (in, INLGROW, PIXEL (0.0)) + + # Initialize the character strings. + call in_pstr (in, INLLABELS, KEY_TYPES) + call in_pstr (in, INLUNITS, "") + call in_pstr (in, INLFLABELS, "") + call in_pstr (in, INLFUNITS, "") + call in_pstr (in, INLPLABELS, "") + call in_pstr (in, INLPUNITS, "") + call in_pstr (in, INLVLABELS, "") + call in_pstr (in, INLVUNITS, "") + call in_pstr (in, INLUSERLABELS, "") + call in_pstr (in, INLUSERUNITS, "") + call in_pstr (in, INLHELP, IN_DEFHELP) + call in_pstr (in, INLPROMPT, IN_DEFPROMPT) + + # Initialize user defined functions. + call in_puti (in, INLUAXES, INDEFI) + call in_puti (in, INLUCOLON, INDEFI) + call in_puti (in, INLUFIT, INDEFI) + + # Initialize graph key, and axes. + call in_puti (in, INLGKEY, 2) + call in_pkey (in, 1, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 1, INLYAXIS, KEY_FIT, INDEFI) + call in_pkey (in, 2, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 2, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 3, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 3, INLYAXIS, KEY_RATIO, INDEFI) + call in_pkey (in, 4, INLXAXIS, KEY_VARIABLE, 1) + call in_pkey (in, 4, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 5, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 5, INLYAXIS, KEY_RESIDUALS, INDEFI) + + # Initialize flags and counters. + call in_puti (in, INLOVERPLOT, NO) + call in_puti (in, INLPLOTFIT, NO) + call in_puti (in, INLNREJPTS, 0) + call in_puti (in, INLNVARS, 0) + call in_puti (in, INLNPTS, 0) + + # Initialize pointers. + call in_putp (in, INLREJPTS, NULL) + call in_putp (in, INLXMIN, NULL) + call in_putp (in, INLXMAX, NULL) +end + + +# IN_BFINIT -- Initialize the rejected point counter, number of variables, +# rejected point list, and the buffers containing the minimum and maximum +# variable values. The rejected point list and limit value buffers are +# reallocated, if necessary. + +procedure in_bfinit$t (in, npts, nvars) + +pointer in # INLFIT descriptor +int npts # number of points +int nvars # number of variables + +int in_geti() + +begin +# # Debug. +# call eprintf ("in_bfinit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Clear rejected point counter, and initialize number of variables. + call in_puti (in, INLNREJPTS, 0) + + # Reallocate space for rejected point list and initialize it. + if (in_geti (in, INLNPTS) != npts) { + call in_puti (in, INLNPTS, npts) + call realloc (IN_REJPTS (in), npts, TY_INT) + } + call amovki (NO, Memi[IN_REJPTS(in)], npts) + + # Reallocate space for minimum and maximum variable values. + # Initialization is made afterwards. + if (in_geti (in, INLNVARS) != nvars) { + call in_puti (in, INLNVARS, nvars) + call realloc (IN_XMIN (in), nvars, TY_PIXEL) + call realloc (IN_XMAX (in), nvars, TY_PIXEL) + } +end diff --git a/pkg/xtools/inlfit/ininitd.x b/pkg/xtools/inlfit/ininitd.x new file mode 100644 index 00000000..147f2886 --- /dev/null +++ b/pkg/xtools/inlfit/ininitd.x @@ -0,0 +1,172 @@ +.help ininit +INLFIT memory allocation procedures. All the calls to malloc() and realloc() +are grouped in this file. Acces to the INLFIT structure is restricted to +the in_get() and in_put() procedures, except for buffer allocation and +initialization. +.nf + +User entry points: + + in_initd (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +Low level entry point: + + in_bfinitd (in, npts, nvars) +.fi +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + + +# IN_INIT -- Initialize INLFIT parameter structure. + +procedure in_initd (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +pointer in # INLFIT pointer +int func # fitting function address +int dfunc # derivative function address +double param[nparams] # parameter values +double dparam[nparams] # initial guess at uncertenties in parameters +int nparams # number of parameters +int plist[nparams] # list of active parameters +int nfparams # number of fitting paramters + +begin +# # Debug. +# call eprintf ( +# "in_init: in=%d, func=%d, dfunc=%d, npars=%d, nfpars=%d\n") +# call pargi (in) +# call pargi (func) +# call pargi (dfunc) +# call pargi (nparams) +# call pargi (nfparams) + + # Allocate the structure memory. + call malloc (in, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (in), nparams, TY_DOUBLE) + call malloc (IN_DPARAM (in), nparams, TY_DOUBLE) + call malloc (IN_PLIST (in), nparams, TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_HELP(in), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT(in), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (in), LEN_INLFLOAT, TY_DOUBLE) + call malloc (IN_SGAXES (in), INLNGKEYS * LEN_INLGRAPH, TY_INT) + + # Enter procedure parameters into the structure. + call in_puti (in, INLFUNCTION, func) + call in_puti (in, INLDERIVATIVE, dfunc) + call in_puti (in, INLNPARAMS, nparams) + call in_puti (in, INLNFPARAMS, nfparams) + call amovd (param, Memd[IN_PARAM(in)], nparams) + call amovd (dparam, Memd[IN_DPARAM(in)], nparams) + call amovi (plist, Memi[IN_PLIST(in)], nparams) + + # Set defaults, just in case. + call in_putd (in, INLTOLERANCE, double (0.01)) + call in_puti (in, INLMAXITER, 3) + call in_puti (in, INLNREJECT, 0) + call in_putd (in, INLLOW, double (3.0)) + call in_putd (in, INLHIGH, double (3.0)) + call in_putd (in, INLGROW, double (0.0)) + + # Initialize the character strings. + call in_pstr (in, INLLABELS, KEY_TYPES) + call in_pstr (in, INLUNITS, "") + call in_pstr (in, INLFLABELS, "") + call in_pstr (in, INLFUNITS, "") + call in_pstr (in, INLPLABELS, "") + call in_pstr (in, INLPUNITS, "") + call in_pstr (in, INLVLABELS, "") + call in_pstr (in, INLVUNITS, "") + call in_pstr (in, INLUSERLABELS, "") + call in_pstr (in, INLUSERUNITS, "") + call in_pstr (in, INLHELP, IN_DEFHELP) + call in_pstr (in, INLPROMPT, IN_DEFPROMPT) + + # Initialize user defined functions. + call in_puti (in, INLUAXES, INDEFI) + call in_puti (in, INLUCOLON, INDEFI) + call in_puti (in, INLUFIT, INDEFI) + + # Initialize graph key, and axes. + call in_puti (in, INLGKEY, 2) + call in_pkey (in, 1, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 1, INLYAXIS, KEY_FIT, INDEFI) + call in_pkey (in, 2, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 2, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 3, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 3, INLYAXIS, KEY_RATIO, INDEFI) + call in_pkey (in, 4, INLXAXIS, KEY_VARIABLE, 1) + call in_pkey (in, 4, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 5, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 5, INLYAXIS, KEY_RESIDUALS, INDEFI) + + # Initialize flags and counters. + call in_puti (in, INLOVERPLOT, NO) + call in_puti (in, INLPLOTFIT, NO) + call in_puti (in, INLNREJPTS, 0) + call in_puti (in, INLNVARS, 0) + call in_puti (in, INLNPTS, 0) + + # Initialize pointers. + call in_putp (in, INLREJPTS, NULL) + call in_putp (in, INLXMIN, NULL) + call in_putp (in, INLXMAX, NULL) +end + + +# IN_BFINIT -- Initialize the rejected point counter, number of variables, +# rejected point list, and the buffers containing the minimum and maximum +# variable values. The rejected point list and limit value buffers are +# reallocated, if necessary. + +procedure in_bfinitd (in, npts, nvars) + +pointer in # INLFIT descriptor +int npts # number of points +int nvars # number of variables + +int in_geti() + +begin +# # Debug. +# call eprintf ("in_bfinit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Clear rejected point counter, and initialize number of variables. + call in_puti (in, INLNREJPTS, 0) + + # Reallocate space for rejected point list and initialize it. + if (in_geti (in, INLNPTS) != npts) { + call in_puti (in, INLNPTS, npts) + call realloc (IN_REJPTS (in), npts, TY_INT) + } + call amovki (NO, Memi[IN_REJPTS(in)], npts) + + # Reallocate space for minimum and maximum variable values. + # Initialization is made afterwards. + if (in_geti (in, INLNVARS) != nvars) { + call in_puti (in, INLNVARS, nvars) + call realloc (IN_XMIN (in), nvars, TY_DOUBLE) + call realloc (IN_XMAX (in), nvars, TY_DOUBLE) + } +end diff --git a/pkg/xtools/inlfit/ininitr.x b/pkg/xtools/inlfit/ininitr.x new file mode 100644 index 00000000..8c0f3469 --- /dev/null +++ b/pkg/xtools/inlfit/ininitr.x @@ -0,0 +1,172 @@ +.help ininit +INLFIT memory allocation procedures. All the calls to malloc() and realloc() +are grouped in this file. Acces to the INLFIT structure is restricted to +the in_get() and in_put() procedures, except for buffer allocation and +initialization. +.nf + +User entry points: + + in_initr (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +Low level entry point: + + in_bfinitr (in, npts, nvars) +.fi +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + + +# IN_INIT -- Initialize INLFIT parameter structure. + +procedure in_initr (in, func, dfunc, param, dparam, nparams, plist, nfparams) + +pointer in # INLFIT pointer +int func # fitting function address +int dfunc # derivative function address +real param[nparams] # parameter values +real dparam[nparams] # initial guess at uncertenties in parameters +int nparams # number of parameters +int plist[nparams] # list of active parameters +int nfparams # number of fitting paramters + +begin +# # Debug. +# call eprintf ( +# "in_init: in=%d, func=%d, dfunc=%d, npars=%d, nfpars=%d\n") +# call pargi (in) +# call pargi (func) +# call pargi (dfunc) +# call pargi (nparams) +# call pargi (nfparams) + + # Allocate the structure memory. + call malloc (in, LEN_INLSTRUCT, TY_STRUCT) + + # Allocate memory for parameter values, changes, and list. + call malloc (IN_PARAM (in), nparams, TY_REAL) + call malloc (IN_DPARAM (in), nparams, TY_REAL) + call malloc (IN_PLIST (in), nparams, TY_INT) + + # Allocate space for strings. All strings are limited + # to SZ_LINE or SZ_FNAME. + call malloc (IN_LABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_UNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_FUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_PUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_VUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERLABELS(in), SZ_LINE, TY_CHAR) + call malloc (IN_USERUNITS(in), SZ_LINE, TY_CHAR) + call malloc (IN_HELP(in), SZ_FNAME, TY_CHAR) + call malloc (IN_PROMPT(in), SZ_FNAME, TY_CHAR) + + # Allocate space for floating point and graph substructures. + call malloc (IN_SFLOAT (in), LEN_INLFLOAT, TY_REAL) + call malloc (IN_SGAXES (in), INLNGKEYS * LEN_INLGRAPH, TY_INT) + + # Enter procedure parameters into the structure. + call in_puti (in, INLFUNCTION, func) + call in_puti (in, INLDERIVATIVE, dfunc) + call in_puti (in, INLNPARAMS, nparams) + call in_puti (in, INLNFPARAMS, nfparams) + call amovr (param, Memr[IN_PARAM(in)], nparams) + call amovr (dparam, Memr[IN_DPARAM(in)], nparams) + call amovi (plist, Memi[IN_PLIST(in)], nparams) + + # Set defaults, just in case. + call in_putr (in, INLTOLERANCE, real (0.01)) + call in_puti (in, INLMAXITER, 3) + call in_puti (in, INLNREJECT, 0) + call in_putr (in, INLLOW, real (3.0)) + call in_putr (in, INLHIGH, real (3.0)) + call in_putr (in, INLGROW, real (0.0)) + + # Initialize the character strings. + call in_pstr (in, INLLABELS, KEY_TYPES) + call in_pstr (in, INLUNITS, "") + call in_pstr (in, INLFLABELS, "") + call in_pstr (in, INLFUNITS, "") + call in_pstr (in, INLPLABELS, "") + call in_pstr (in, INLPUNITS, "") + call in_pstr (in, INLVLABELS, "") + call in_pstr (in, INLVUNITS, "") + call in_pstr (in, INLUSERLABELS, "") + call in_pstr (in, INLUSERUNITS, "") + call in_pstr (in, INLHELP, IN_DEFHELP) + call in_pstr (in, INLPROMPT, IN_DEFPROMPT) + + # Initialize user defined functions. + call in_puti (in, INLUAXES, INDEFI) + call in_puti (in, INLUCOLON, INDEFI) + call in_puti (in, INLUFIT, INDEFI) + + # Initialize graph key, and axes. + call in_puti (in, INLGKEY, 2) + call in_pkey (in, 1, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 1, INLYAXIS, KEY_FIT, INDEFI) + call in_pkey (in, 2, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 2, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 3, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 3, INLYAXIS, KEY_RATIO, INDEFI) + call in_pkey (in, 4, INLXAXIS, KEY_VARIABLE, 1) + call in_pkey (in, 4, INLYAXIS, KEY_RESIDUALS, INDEFI) + call in_pkey (in, 5, INLXAXIS, KEY_FUNCTION, INDEFI) + call in_pkey (in, 5, INLYAXIS, KEY_RESIDUALS, INDEFI) + + # Initialize flags and counters. + call in_puti (in, INLOVERPLOT, NO) + call in_puti (in, INLPLOTFIT, NO) + call in_puti (in, INLNREJPTS, 0) + call in_puti (in, INLNVARS, 0) + call in_puti (in, INLNPTS, 0) + + # Initialize pointers. + call in_putp (in, INLREJPTS, NULL) + call in_putp (in, INLXMIN, NULL) + call in_putp (in, INLXMAX, NULL) +end + + +# IN_BFINIT -- Initialize the rejected point counter, number of variables, +# rejected point list, and the buffers containing the minimum and maximum +# variable values. The rejected point list and limit value buffers are +# reallocated, if necessary. + +procedure in_bfinitr (in, npts, nvars) + +pointer in # INLFIT descriptor +int npts # number of points +int nvars # number of variables + +int in_geti() + +begin +# # Debug. +# call eprintf ("in_bfinit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Clear rejected point counter, and initialize number of variables. + call in_puti (in, INLNREJPTS, 0) + + # Reallocate space for rejected point list and initialize it. + if (in_geti (in, INLNPTS) != npts) { + call in_puti (in, INLNPTS, npts) + call realloc (IN_REJPTS (in), npts, TY_INT) + } + call amovki (NO, Memi[IN_REJPTS(in)], npts) + + # Reallocate space for minimum and maximum variable values. + # Initialization is made afterwards. + if (in_geti (in, INLNVARS) != nvars) { + call in_puti (in, INLNVARS, nvars) + call realloc (IN_XMIN (in), nvars, TY_REAL) + call realloc (IN_XMAX (in), nvars, TY_REAL) + } +end diff --git a/pkg/xtools/inlfit/inlfitdef.h b/pkg/xtools/inlfit/inlfitdef.h new file mode 100644 index 00000000..0153f20f --- /dev/null +++ b/pkg/xtools/inlfit/inlfitdef.h @@ -0,0 +1,148 @@ +# The INLFIT data structure and private definitions. + +# Pointer Mem + +define MEMP Memi + + +# Default help file and prompt + +define IN_DEFHELP "lib$scr/inlgfit.key" +define IN_DEFPROMPT "inlfit cursor options" + + +# Graphic key/axis types +define KEY_TYPES "|function|fit|residuals|ratio|nonlinear|var|user|" + + +# ---------------------------------------------------------------------- +# INLFIT structure definition. + +# Structure length. +define LEN_INLSTRUCT 37 + +# NLFIT parameters. These parameters are stored in the INLFIT structure, +# and passed without change to the NLFIT package. The NLFIT descriptor +# is stored here as well. + +#define IN_TYPE Memi[$1+0] # calculation type (TY_REAL, TY_DOUBLE) +define IN_FUNC Memi[$1+1] # fitting function +define IN_DFUNC Memi[$1+2] # derivative function +define IN_NPARAMS Memi[$1+3] # number of parameters +define IN_NFPARAMS Memi[$1+4] # number of fitted parameters +define IN_PARAM MEMP[$1+5] # pointer to parameter vector +define IN_DPARAM MEMP[$1+6] # pointer to par. change vector +define IN_PLIST MEMP[$1+7] # parameter list +define IN_MAXITER Memi[$1+8] # max number of iterations + +# INLFIT parameters used to keep track of the number of variables and +# number of points in the fit. These numbers are used to decide buffer +# reallocation. + +define IN_NVARS Memi[$1+9] # number of variables +define IN_NPTS Memi[$1+10] # number of points + +# INLFIT floating point substructure. This substructure is used to +# store a pointer to a separate buffer, containing floating point +# numbers. + +define IN_SFLOAT MEMP[$1+11] # pointer to subs. with reals/doubles + +# INLFIT parameters used for automatic data rejection. The rejection +# limits and the grow radius are stored in the floating point substructure. + +define IN_NREJECT Memi[$1+12] # number of rejection iteration + +# INLFIT parameters used to store the rejected point counter, and a +# pointer to the rejected point list. + +define IN_NREJPTS Memi[$1+13] # number of rejected points +define IN_REJPTS MEMP[$1+14] # pointer to buffer with rejected pts. + +# INLFIT parameters used to store user defined procedures addresses. +# These parameters are used by the zcall*() procedures. + +define IN_UAXES Memi[$1+15] # plot function +define IN_UCOLON Memi[$1+16] # default colon command +define IN_UFIT Memi[$1+17] # default interactive fit command + +# INLFIT parameters used to store pointers to separate buffers, containing +# the minimum and maximum values of all the input variables. The number +# of variables is kept as well. + +define IN_XMIN MEMP[$1+18] # pointer to buffer with min. values +define IN_XMAX MEMP[$1+19] # pointer to buffer with max. values + +# INLFIT flags. + +define IN_OVERPLOT Memi[$1+20] # overplot next plot ? +define IN_PLOTFIT Memi[$1+21] # overplot fit ? +define IN_FITERROR Memi[$1+22] # error fit code + +# INLFIT string parameters used for interactive graphics. These are +# pointers to the actual strings. + +define IN_LABELS MEMP[$1+23] # standard axis labels +define IN_UNITS MEMP[$1+24] # standard axis units +define IN_FLABELS MEMP[$1+25] # function and fit labels +define IN_FUNITS MEMP[$1+26] # function and fit units +define IN_PLABELS MEMP[$1+27] # parameter labels +define IN_PUNITS MEMP[$1+28] # parameter units +define IN_VLABELS MEMP[$1+29] # variable labels +define IN_VUNITS MEMP[$1+30] # variable units +define IN_USERLABELS MEMP[$1+31] # user plot labels +define IN_USERUNITS MEMP[$1+32] # user plot units +define IN_HELP MEMP[$1+33] # help file name +define IN_PROMPT MEMP[$1+34] # help prompt + +# INLFIT graph key definitions. + +define IN_GKEY Memi[$1+35] # current graph key +define IN_SGAXES MEMP[$1+36] # pointer to subs. with graph keys + +# next free location ($1 + 37) == LEN_INLSTRUCT + + +# ---------------------------------------------------------------------- +# Floating point number substructures (real, double). This is an easy way +# to avoid having to deal with mixed floating point types in the main +# structure. The macro parameter is the main structure pointer. The +# substructure used depends on the calculation type. + +# Substructure length + +define LEN_INLFLOAT 4 + +# Real version + +define IN_TOLR Memr[IN_SFLOAT($1)+0] # tolerance of convergence +define IN_LOWR Memr[IN_SFLOAT($1)+1] # low rejection value +define IN_HIGHR Memr[IN_SFLOAT($1)+2] # high rejection value +define IN_GROWR Memr[IN_SFLOAT($1)+3] # rejection growing radius + +# Double precission version + +define IN_TOLD Memd[IN_SFLOAT($1)+0] # tolerance of convergence +define IN_LOWD Memd[IN_SFLOAT($1)+1] # low rejection value +define IN_HIGHD Memd[IN_SFLOAT($1)+2] # high rejection value +define IN_GROWD Memd[IN_SFLOAT($1)+3] # rejection growing radius + + +# ---------------------------------------------------------------------- +# Graph axes substructure. The macro parameters are the pointer to the +# main structure, and the key number. The actual size of the graph axes +# buffer will be equal to the maximum number of keys (IN_GKEYS) times +# the substructure length (LEN_INLGRAPH). The type is one of the possible +# codes for KEY_TYPES, and the number is used to keep track of the variable +# or user supplied function numbers. + +# Substructure length + +define LEN_INLGRAPH 4 + +# Substructure definition + +define IN_GXTYPE Memi[IN_SGAXES($1)+($2-1)*LEN_INLGRAPH+0] # x axis type +define IN_GXNUMBER Memi[IN_SGAXES($1)+($2-1)*LEN_INLGRAPH+1] # x axis num. +define IN_GYTYPE Memi[IN_SGAXES($1)+($2-1)*LEN_INLGRAPH+2] # y axis type +define IN_GYNUMBER Memi[IN_SGAXES($1)+($2-1)*LEN_INLGRAPH+3] # y axis num. diff --git a/pkg/xtools/inlfit/inlgfit.key b/pkg/xtools/inlfit/inlgfit.key new file mode 100644 index 00000000..c01f9a9d --- /dev/null +++ b/pkg/xtools/inlfit/inlgfit.key @@ -0,0 +1,77 @@ +1. INTERACTIVE NONLINEAR LEAST SQUARES FITTING CURSOR OPTIONS + +? Print options +c Print coordinates and fit of point nearest the cursor +d Delete point nearest the cursor +f Do the fit and redraw or overplot the graph +g Redefine graph keys. The following data types may be along + either axis. + function Dependent variable, or function + fit Fitted value + residuals Residuals (function - fit) + ratio Ratio (function / fit) + nonlinear Nonlinear component of function + var n Independent variable number "n" + identifier Independent variable "identifier" (if defined) + user n User defined plot function (if defined) +h-l Graph keys. The defaults are the following. + h=(function, fit) + i=(function, residual) + j=(function, ratio) + k=(var 1, residual) + l=(user 1, user 2) +o Overplot the next graph +q Exit interactive curve fitting +r Redraw graph +t Overplot fit +u Undelete the deleted point nearest the cursor +w Set graph window. + For help type 'w' followed by '?' after the prompt. +I Interrupt task immediately + + +2. INTERACTIVE NONLINEAR LEAST SQUARES FITTING COLON COMMANDS + +The parameters are listed or set with the following commands which may be +abbreviated. To list the value of a parameter type the command alone. + +:show [file] Print the values of the task fitting parameters +:variables [file] Print the variable names, min and max values +:data [file] Print the values of all the variables +:errors [file] Print an error analysis of the fit +:results [file] Print the results of the fit +:vshow [file] Print an error analysis and results of the fit +:page file Page through a file +:const [param] [value] Change parameter to constant parameter +:fit [param] [value] Change parameter to fitting parameter +:tolerance [value] Show/set the convergence criteria +:maxiter [value] Show/set the maximum number of fitting iterations +:nreject [value] Show/set the maximum number of rejection iterations +:low_reject [value] Show/set the low rejection threshold +:high_reject [value] Show/set the high rejection threshold +:grow [value] Show/set the rejection growing radius + +Additional commands are available for setting graph formats and manipulating +the graphics. Use the following commands for help. + +:/help Print help for graph formatting option +:.help Print help for general graphics options + + +3. INTERACTIVE NONLINEAR LEAST SQUARES FITTING GRAPH KEYS + +The graph keys are h, i, j, k, and l. The graph keys may be redefined to +put any combination of axes types along either graph axis with the 'g' key. +To define a graph key select the desired key to redefine and then specify +the axes types for the horizontal and vertical axes by a pair of comma +separated types from the following (they may be abreviated up to three +characters, except for 'identifier'): + +function Dependent variable +fit Fitted value +ratio Ratio (function / fit) +residuuals Residuals of fit (function - fit) +nonlinear Nonlinear part of data (linear component of fit subtracted) +var [n] Indepedent variable number "n" +user [n] User defined plot equation "n" (if defined) +identifier Independent variable named "identifier" (if defined) diff --git a/pkg/xtools/inlfit/inlimit.gx b/pkg/xtools/inlfit/inlimit.gx new file mode 100644 index 00000000..ed4c2b43 --- /dev/null +++ b/pkg/xtools/inlfit/inlimit.gx @@ -0,0 +1,51 @@ +include <pkg/inlfit.h> + + +# IN_LIMIT -- Compute the independent variable limits for all variables, +# and store them in the INLFIT structure. + +procedure in_limit$t (in, x, npts, nvars) + +pointer in # INLFIT descriptor +PIXEL x[ARB] # Independent values (npts * nvars) +int npts # number of points +int nvars # number of variables + +int i, j +PIXEL aux, xmin, xmax +pointer minptr, maxptr + +pointer in_getp() + +begin +# # Debug +# call eprintf ("in_limit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Get minimum and maximum buffer pointers + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + + # Loop over variables + do i = 1, nvars { + + # Set initial values + xmin = x[i] + xmax = x[i] + + # Search for maximum and minimum values + do j = 1, npts { + aux = x[(j - 1) * nvars + i] + if (xmin > aux) + xmin = aux + else if (xmax < aux) + xmax = aux + } + + # Enter values into the structure + Mem$t[minptr + i - 1] = xmin + Mem$t[maxptr + i - 1] = xmax + } +end diff --git a/pkg/xtools/inlfit/inlimitd.x b/pkg/xtools/inlfit/inlimitd.x new file mode 100644 index 00000000..cc0ba12e --- /dev/null +++ b/pkg/xtools/inlfit/inlimitd.x @@ -0,0 +1,51 @@ +include <pkg/inlfit.h> + + +# IN_LIMIT -- Compute the independent variable limits for all variables, +# and store them in the INLFIT structure. + +procedure in_limitd (in, x, npts, nvars) + +pointer in # INLFIT descriptor +double x[ARB] # Independent values (npts * nvars) +int npts # number of points +int nvars # number of variables + +int i, j +double aux, xmin, xmax +pointer minptr, maxptr + +pointer in_getp() + +begin +# # Debug +# call eprintf ("in_limit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Get minimum and maximum buffer pointers + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + + # Loop over variables + do i = 1, nvars { + + # Set initial values + xmin = x[i] + xmax = x[i] + + # Search for maximum and minimum values + do j = 1, npts { + aux = x[(j - 1) * nvars + i] + if (xmin > aux) + xmin = aux + else if (xmax < aux) + xmax = aux + } + + # Enter values into the structure + Memd[minptr + i - 1] = xmin + Memd[maxptr + i - 1] = xmax + } +end diff --git a/pkg/xtools/inlfit/inlimitr.x b/pkg/xtools/inlfit/inlimitr.x new file mode 100644 index 00000000..e85b6c62 --- /dev/null +++ b/pkg/xtools/inlfit/inlimitr.x @@ -0,0 +1,51 @@ +include <pkg/inlfit.h> + + +# IN_LIMIT -- Compute the independent variable limits for all variables, +# and store them in the INLFIT structure. + +procedure in_limitr (in, x, npts, nvars) + +pointer in # INLFIT descriptor +real x[ARB] # Independent values (npts * nvars) +int npts # number of points +int nvars # number of variables + +int i, j +real aux, xmin, xmax +pointer minptr, maxptr + +pointer in_getp() + +begin +# # Debug +# call eprintf ("in_limit: in=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (npts) +# call pargi (nvars) + + # Get minimum and maximum buffer pointers + minptr = in_getp (in, INLXMIN) + maxptr = in_getp (in, INLXMAX) + + # Loop over variables + do i = 1, nvars { + + # Set initial values + xmin = x[i] + xmax = x[i] + + # Search for maximum and minimum values + do j = 1, npts { + aux = x[(j - 1) * nvars + i] + if (xmin > aux) + xmin = aux + else if (xmax < aux) + xmax = aux + } + + # Enter values into the structure + Memr[minptr + i - 1] = xmin + Memr[maxptr + i - 1] = xmax + } +end diff --git a/pkg/xtools/inlfit/inlstrext.x b/pkg/xtools/inlfit/inlstrext.x new file mode 100644 index 00000000..b2b071d9 --- /dev/null +++ b/pkg/xtools/inlfit/inlstrext.x @@ -0,0 +1,47 @@ +include <ctype.h> + +# INLSTREXT - Extract a word (delimited substring) from a string. +# The input string is scanned from the given initial value until one +# of the delimiters is found. The delimiters are not included in the +# output word. +# Leading white spaces in a word may be optionally skipped. White +# spaces are skipped before looking at the delimiters string, so it's +# possible to remove leading white spaces and use them as delimiters +# at the same time. +# The value returned is the number of characters in the output string. +# Upon return, the pointer is located at the begining of the next word. + +int procedure inlstrext (str, ip, dict, skip, outstr, maxch) + +char str[ARB] # input string +int ip # pointer into input string +char dict[ARB] # dictionary of delimiters +int skip # skip leading white spaces ? +char outstr[ARB] # extracted word +int maxch # max number of chars + +int op +int stridx() + +begin + # Skip leading white spaces + if (skip == YES) { + while (IS_WHITE (str[ip])) + ip = ip + 1 + } + + # Process input string + for (op=1; str[ip] != EOS && op <= maxch; op=op+1) + if (stridx (str[ip], dict) == 0) { + outstr[op] = str[ip] + ip = ip + 1 + } else { + repeat { + ip = ip + 1 + } until (stridx (str[ip], dict) == 0 || str[ip] == EOS) + break + } + + outstr[op] = EOS + return (op - 1) +end diff --git a/pkg/xtools/inlfit/inlstrwrd.x b/pkg/xtools/inlfit/inlstrwrd.x new file mode 100644 index 00000000..23aa8bdf --- /dev/null +++ b/pkg/xtools/inlfit/inlstrwrd.x @@ -0,0 +1,51 @@ +# INLSTRWRD -- Search a dictionary string for a given string index number. +# This is the opposite function of strdic(), that returns the index for +# given string. The entries in the dictionary string are separated by +# a delimiter character which is the first character of the dictionary +# string. The index of the string found is returned as the function value. +# Otherwise, if there is no string for that index, a zero is returned. + +int procedure inlstrwrd (index, outstr, maxch, dict) + +int index # String index +char outstr[ARB] # Output string as found in dictionary +int maxch # Maximum length of output string +char dict[ARB] # Dictionary string + +int i, len, start, count + +int strlen() + +begin + # Clear output string + outstr[1] = EOS + + # Return if the dictionary is not long enough + if (dict[1] == EOS) + return (0) + + # Initialize counters + count = 1 + len = strlen (dict) + + # Search the dictionary string. This loop only terminates + # successfully if the index is found. Otherwise the procedure + # returns with and error condition. + for (start = 2; count < index; start = start + 1) { + if (dict[start] == dict[1]) + count = count + 1 + if (start == len) + return (0) + } + + # Extract the output string from the dictionary + for (i = start; dict[i] != EOS && dict[i] != dict[1]; i = i + 1) { + if (i - start + 1 > maxch) + break + outstr[i - start + 1] = dict[i] + } + outstr[i - start + 1] = EOS + + # Return index for output string + return (count) +end diff --git a/pkg/xtools/inlfit/innlinit.gx b/pkg/xtools/inlfit/innlinit.gx new file mode 100644 index 00000000..87c2aab1 --- /dev/null +++ b/pkg/xtools/inlfit/innlinit.gx @@ -0,0 +1,28 @@ +include "inlfitdef.h" + + +# IN_NLINIT -- Initialize (reinitialize) NLFIT descriptor. The new +# NLFIT descriptor is returned as a procedure argument. + +procedure in_nlinit$t (in, nl) + +pointer in # INLFIT descriptor +pointer nl # NLFIT descriptor + +errchk nlinit(), nlfree() + +begin +# # Debug. +# call eprintf ("in_nlinit: in=%d, nl=%d\n") +# call pargi (in) +# call pargi (nl) + + # Free old NLFIT structure if any. + if (nl != NULL) + call nlfree$t (nl) + + # Initialize new NLFIT structure. + call nlinit$t (nl, IN_FUNC (in), IN_DFUNC (in), Mem$t[IN_PARAM (in)], + Mem$t[IN_DPARAM (in)], IN_NPARAMS (in), Memi[IN_PLIST (in)], + IN_NFPARAMS (in), IN_TOL$T (in), IN_MAXITER (in)) +end diff --git a/pkg/xtools/inlfit/innlinitd.x b/pkg/xtools/inlfit/innlinitd.x new file mode 100644 index 00000000..87a82c91 --- /dev/null +++ b/pkg/xtools/inlfit/innlinitd.x @@ -0,0 +1,28 @@ +include "inlfitdef.h" + + +# IN_NLINIT -- Initialize (reinitialize) NLFIT descriptor. The new +# NLFIT descriptor is returned as a procedure argument. + +procedure in_nlinitd (in, nl) + +pointer in # INLFIT descriptor +pointer nl # NLFIT descriptor + +errchk nlinit(), nlfree() + +begin +# # Debug. +# call eprintf ("in_nlinit: in=%d, nl=%d\n") +# call pargi (in) +# call pargi (nl) + + # Free old NLFIT structure if any. + if (nl != NULL) + call nlfreed (nl) + + # Initialize new NLFIT structure. + call nlinitd (nl, IN_FUNC (in), IN_DFUNC (in), Memd[IN_PARAM (in)], + Memd[IN_DPARAM (in)], IN_NPARAMS (in), Memi[IN_PLIST (in)], + IN_NFPARAMS (in), IN_TOLD (in), IN_MAXITER (in)) +end diff --git a/pkg/xtools/inlfit/innlinitr.x b/pkg/xtools/inlfit/innlinitr.x new file mode 100644 index 00000000..21e7b932 --- /dev/null +++ b/pkg/xtools/inlfit/innlinitr.x @@ -0,0 +1,28 @@ +include "inlfitdef.h" + + +# IN_NLINIT -- Initialize (reinitialize) NLFIT descriptor. The new +# NLFIT descriptor is returned as a procedure argument. + +procedure in_nlinitr (in, nl) + +pointer in # INLFIT descriptor +pointer nl # NLFIT descriptor + +errchk nlinit(), nlfree() + +begin +# # Debug. +# call eprintf ("in_nlinit: in=%d, nl=%d\n") +# call pargi (in) +# call pargi (nl) + + # Free old NLFIT structure if any. + if (nl != NULL) + call nlfreer (nl) + + # Initialize new NLFIT structure. + call nlinitr (nl, IN_FUNC (in), IN_DFUNC (in), Memr[IN_PARAM (in)], + Memr[IN_DPARAM (in)], IN_NPARAMS (in), Memi[IN_PLIST (in)], + IN_NFPARAMS (in), IN_TOLR (in), IN_MAXITER (in)) +end diff --git a/pkg/xtools/inlfit/input.gx b/pkg/xtools/inlfit/input.gx new file mode 100644 index 00000000..4fac25a5 --- /dev/null +++ b/pkg/xtools/inlfit/input.gx @@ -0,0 +1,188 @@ +.help input + in_puti (in, param, ival) + in_putr (in, param, rval) + in_putd (in, param, dval) + in_putp (in, param, pval) + in_pstr (in, param, str) + in_pkey (in, key, axis, type, varnum) +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + + +# IN_PUTI -- Put integer valued parameters. + +procedure in_puti (in, param, ival) + +pointer in # INLFIT pointer +int param # parameter to put +int ival # integer value + +begin + switch (param) { + case INLFUNCTION: + IN_FUNC (in) = ival + case INLDERIVATIVE: + IN_DFUNC (in) = ival + case INLNPARAMS: + IN_NPARAMS (in) = ival + case INLNFPARAMS: + IN_NFPARAMS (in) = ival + case INLNVARS: + IN_NVARS (in) = ival + case INLNPTS: + IN_NPTS (in) = ival + case INLMAXITER: + IN_MAXITER (in) = ival + case INLNREJECT: + IN_NREJECT (in) = ival + case INLNREJPTS: + IN_NREJPTS (in) = ival + case INLUAXES: + IN_UAXES (in) = ival + case INLUCOLON: + IN_UCOLON (in) = ival + case INLUFIT: + IN_UFIT (in) = ival + case INLOVERPLOT: + IN_OVERPLOT (in) = ival + case INLPLOTFIT: + IN_PLOTFIT (in) = ival + case INLFITERROR: + IN_FITERROR (in) = ival + case INLGKEY: + if (ival < 1 || ival > INLNGKEYS) + call error (0, "INLFIT, in_puti: Bad key number (INLGKEY)") + IN_GKEY (in) = ival + default: + call error (0, "INLFIT, in_puti: Unknown parameter") + } +end + + +$for (rd) +# IN_PUT[RD] -- Put real/double valued parameters. + +procedure in_put$t (in, param, $tval) + +pointer in # INLFIT pointer +int param # parameter to put +PIXEL $tval # value + +begin + switch (param) { + case INLTOLERANCE: + IN_TOL$T (in) = $tval + case INLLOW: + IN_LOW$T (in) = $tval + case INLHIGH: + IN_HIGH$T (in) = $tval + case INLGROW: + IN_GROW$T (in) = $tval + default: + call error (0, "INLFIT, in_put[rd]: Unknown parameter") + } +end +$endfor + + +# IN_PUTP -- Put pointer valued parameters. + +procedure in_putp (in, param, pval) + +pointer in # INLFIT pointer +int param # parameter to put +pointer pval # pointer value + +begin + switch (param) { + case INLPARAM: + IN_PARAM (in) = pval + case INLDPARAM: + IN_DPARAM (in) = pval + case INLPLIST: + IN_PLIST (in) = pval + case INLSFLOAT: + IN_SFLOAT (in) = pval + case INLREJPTS: + IN_REJPTS (in) = pval + case INLXMIN: + IN_XMIN (in) = pval + case INLXMAX: + IN_XMAX (in) = pval + case INLSGAXES: + IN_SGAXES (in) = pval + default: + call error (0, "INLFIT, in_putp: Unknown parameter") + } +end + + +# IN_PSTR -- Put string valued parameters. + +procedure in_pstr (in, param, str) + +pointer in # INLFIT pointer +int param # parameter to put +char str[ARB] # string value + +begin + switch (param) { + case INLLABELS: + call strcpy (str, Memc[IN_LABELS (in)], SZ_LINE) + case INLUNITS: + call strcpy (str, Memc[IN_UNITS (in)], SZ_LINE) + case INLFLABELS: + call strcpy (str, Memc[IN_FLABELS (in)], SZ_LINE) + case INLFUNITS: + call strcpy (str, Memc[IN_FUNITS (in)], SZ_LINE) + case INLPLABELS: + call strcpy (str, Memc[IN_PLABELS (in)], SZ_LINE) + case INLPUNITS: + call strcpy (str, Memc[IN_PUNITS (in)], SZ_LINE) + case INLVLABELS: + call strcpy (str, Memc[IN_VLABELS (in)], SZ_LINE) + case INLVUNITS: + call strcpy (str, Memc[IN_VUNITS (in)], SZ_LINE) + case INLUSERLABELS: + call strcpy (str, Memc[IN_USERLABELS (in)], SZ_LINE) + case INLUSERUNITS: + call strcpy (str, Memc[IN_USERUNITS (in)], SZ_LINE) + case INLHELP: + call strcpy (str, Memc[IN_HELP (in)], SZ_FNAME) + case INLPROMPT: + call strcpy (str, Memc[IN_PROMPT (in)], SZ_FNAME) + default: + call error (0, "INLFIT, in_pstr: Unknown parameter") + } +end + + +# IN_PKEY -- Put key parameters. + +procedure in_pkey (in, key, axis, type, varnum) + +pointer in # INLFIT pointer +int key # key to put +int axis # axis number +int type # axis type +int varnum # axis variable number + +begin + # Check ranges + if (key < 1 || key > INLNGKEYS) + call error (0, "INLFIT, in_pkey: Illegal key") + if (type < KEY_MIN || type > KEY_MAX) + call error (0, "INLFIT, in_pkey: Illegal key type") + + # Enter data + if (axis == INLXAXIS) { + IN_GXTYPE (in, key) = type + IN_GXNUMBER (in, key) = varnum + } else if (axis == INLYAXIS) { + IN_GYTYPE (in, key) = type + IN_GYNUMBER (in, key) = varnum + } else + call error (0,"INLFIT, in_pkey: Illegal axis number") +end diff --git a/pkg/xtools/inlfit/input.x b/pkg/xtools/inlfit/input.x new file mode 100644 index 00000000..db1613cb --- /dev/null +++ b/pkg/xtools/inlfit/input.x @@ -0,0 +1,211 @@ +.help input + in_puti (in, param, ival) + in_putr (in, param, rval) + in_putd (in, param, dval) + in_putp (in, param, pval) + in_pstr (in, param, str) + in_pkey (in, key, axis, type, varnum) +.endhelp + +include <pkg/inlfit.h> +include "inlfitdef.h" + + +# IN_PUTI -- Put integer valued parameters. + +procedure in_puti (in, param, ival) + +pointer in # INLFIT pointer +int param # parameter to put +int ival # integer value + +begin + switch (param) { + case INLFUNCTION: + IN_FUNC (in) = ival + case INLDERIVATIVE: + IN_DFUNC (in) = ival + case INLNPARAMS: + IN_NPARAMS (in) = ival + case INLNFPARAMS: + IN_NFPARAMS (in) = ival + case INLNVARS: + IN_NVARS (in) = ival + case INLNPTS: + IN_NPTS (in) = ival + case INLMAXITER: + IN_MAXITER (in) = ival + case INLNREJECT: + IN_NREJECT (in) = ival + case INLNREJPTS: + IN_NREJPTS (in) = ival + case INLUAXES: + IN_UAXES (in) = ival + case INLUCOLON: + IN_UCOLON (in) = ival + case INLUFIT: + IN_UFIT (in) = ival + case INLOVERPLOT: + IN_OVERPLOT (in) = ival + case INLPLOTFIT: + IN_PLOTFIT (in) = ival + case INLFITERROR: + IN_FITERROR (in) = ival + case INLGKEY: + if (ival < 1 || ival > INLNGKEYS) + call error (0, "INLFIT, in_puti: Bad key number (INLGKEY)") + IN_GKEY (in) = ival + default: + call error (0, "INLFIT, in_puti: Unknown parameter") + } +end + + + +# IN_PUT[RD] -- Put real/double valued parameters. + +procedure in_putr (in, param, rval) + +pointer in # INLFIT pointer +int param # parameter to put +real rval # value + +begin + switch (param) { + case INLTOLERANCE: + IN_TOLR (in) = rval + case INLLOW: + IN_LOWR (in) = rval + case INLHIGH: + IN_HIGHR (in) = rval + case INLGROW: + IN_GROWR (in) = rval + default: + call error (0, "INLFIT, in_put[rd]: Unknown parameter") + } +end + +# IN_PUT[RD] -- Put real/double valued parameters. + +procedure in_putd (in, param, dval) + +pointer in # INLFIT pointer +int param # parameter to put +double dval # value + +begin + switch (param) { + case INLTOLERANCE: + IN_TOLD (in) = dval + case INLLOW: + IN_LOWD (in) = dval + case INLHIGH: + IN_HIGHD (in) = dval + case INLGROW: + IN_GROWD (in) = dval + default: + call error (0, "INLFIT, in_put[rd]: Unknown parameter") + } +end + + + +# IN_PUTP -- Put pointer valued parameters. + +procedure in_putp (in, param, pval) + +pointer in # INLFIT pointer +int param # parameter to put +pointer pval # pointer value + +begin + switch (param) { + case INLPARAM: + IN_PARAM (in) = pval + case INLDPARAM: + IN_DPARAM (in) = pval + case INLPLIST: + IN_PLIST (in) = pval + case INLSFLOAT: + IN_SFLOAT (in) = pval + case INLREJPTS: + IN_REJPTS (in) = pval + case INLXMIN: + IN_XMIN (in) = pval + case INLXMAX: + IN_XMAX (in) = pval + case INLSGAXES: + IN_SGAXES (in) = pval + default: + call error (0, "INLFIT, in_putp: Unknown parameter") + } +end + + +# IN_PSTR -- Put string valued parameters. + +procedure in_pstr (in, param, str) + +pointer in # INLFIT pointer +int param # parameter to put +char str[ARB] # string value + +begin + switch (param) { + case INLLABELS: + call strcpy (str, Memc[IN_LABELS (in)], SZ_LINE) + case INLUNITS: + call strcpy (str, Memc[IN_UNITS (in)], SZ_LINE) + case INLFLABELS: + call strcpy (str, Memc[IN_FLABELS (in)], SZ_LINE) + case INLFUNITS: + call strcpy (str, Memc[IN_FUNITS (in)], SZ_LINE) + case INLPLABELS: + call strcpy (str, Memc[IN_PLABELS (in)], SZ_LINE) + case INLPUNITS: + call strcpy (str, Memc[IN_PUNITS (in)], SZ_LINE) + case INLVLABELS: + call strcpy (str, Memc[IN_VLABELS (in)], SZ_LINE) + case INLVUNITS: + call strcpy (str, Memc[IN_VUNITS (in)], SZ_LINE) + case INLUSERLABELS: + call strcpy (str, Memc[IN_USERLABELS (in)], SZ_LINE) + case INLUSERUNITS: + call strcpy (str, Memc[IN_USERUNITS (in)], SZ_LINE) + case INLHELP: + call strcpy (str, Memc[IN_HELP (in)], SZ_FNAME) + case INLPROMPT: + call strcpy (str, Memc[IN_PROMPT (in)], SZ_FNAME) + default: + call error (0, "INLFIT, in_pstr: Unknown parameter") + } +end + + +# IN_PKEY -- Put key parameters. + +procedure in_pkey (in, key, axis, type, varnum) + +pointer in # INLFIT pointer +int key # key to put +int axis # axis number +int type # axis type +int varnum # axis variable number + +begin + # Check ranges + if (key < 1 || key > INLNGKEYS) + call error (0, "INLFIT, in_pkey: Illegal key") + if (type < KEY_MIN || type > KEY_MAX) + call error (0, "INLFIT, in_pkey: Illegal key type") + + # Enter data + if (axis == INLXAXIS) { + IN_GXTYPE (in, key) = type + IN_GXNUMBER (in, key) = varnum + } else if (axis == INLYAXIS) { + IN_GYTYPE (in, key) = type + IN_GYNUMBER (in, key) = varnum + } else + call error (0,"INLFIT, in_pkey: Illegal axis number") +end diff --git a/pkg/xtools/inlfit/inrefit.gx b/pkg/xtools/inlfit/inrefit.gx new file mode 100644 index 00000000..2effe21e --- /dev/null +++ b/pkg/xtools/inlfit/inrefit.gx @@ -0,0 +1,67 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_REFIT -- Refit a function. This procedure is analogous to in_fit(), +# except that this one does not initialize the weigths and the rejected +# point list, and it does not reject points after the fit, because it is +# intended to be called from the data rejection procedure. + +procedure in_refit$t (in, nl, x, y, wts, npts, nvars, wtflag) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +PIXEL x[ARB] # Ordinates +PIXEL y[npts] # Data to be fit +PIXEL wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, ndeleted, ier +pointer rejpts +pointer in_getp() +int in_geti() + +begin +# # Debug +# call eprintf ("in_refit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + + # Assign a zero weight to each rejected point. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + wts[i] = PIXEL (0.0) + } + + # Reinitialize NLFIT. + call in_nlinit$t (in, nl) + + # Check number of data points. + if (npts == 0) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Check number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= PIXEL(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti(in, INLNFPARAMS)) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Refit. + call nlfit$t (nl, x, y, wts, npts, nvars, wtflag, ier) + + # Store fit status in the INLFIT structure. + call in_puti (in, INLFITERROR, ier) +end diff --git a/pkg/xtools/inlfit/inrefitd.x b/pkg/xtools/inlfit/inrefitd.x new file mode 100644 index 00000000..956e125e --- /dev/null +++ b/pkg/xtools/inlfit/inrefitd.x @@ -0,0 +1,67 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_REFIT -- Refit a function. This procedure is analogous to in_fit(), +# except that this one does not initialize the weigths and the rejected +# point list, and it does not reject points after the fit, because it is +# intended to be called from the data rejection procedure. + +procedure in_refitd (in, nl, x, y, wts, npts, nvars, wtflag) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +double x[ARB] # Ordinates +double y[npts] # Data to be fit +double wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, ndeleted, ier +pointer rejpts +pointer in_getp() +int in_geti() + +begin +# # Debug +# call eprintf ("in_refit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + + # Assign a zero weight to each rejected point. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + wts[i] = double (0.0) + } + + # Reinitialize NLFIT. + call in_nlinitd (in, nl) + + # Check number of data points. + if (npts == 0) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Check number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= double(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti(in, INLNFPARAMS)) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Refit. + call nlfitd (nl, x, y, wts, npts, nvars, wtflag, ier) + + # Store fit status in the INLFIT structure. + call in_puti (in, INLFITERROR, ier) +end diff --git a/pkg/xtools/inlfit/inrefitr.x b/pkg/xtools/inlfit/inrefitr.x new file mode 100644 index 00000000..3dea7f9f --- /dev/null +++ b/pkg/xtools/inlfit/inrefitr.x @@ -0,0 +1,67 @@ +include <math/nlfit.h> +include <pkg/inlfit.h> + + +# IN_REFIT -- Refit a function. This procedure is analogous to in_fit(), +# except that this one does not initialize the weigths and the rejected +# point list, and it does not reject points after the fit, because it is +# intended to be called from the data rejection procedure. + +procedure in_refitr (in, nl, x, y, wts, npts, nvars, wtflag) + +pointer in # INLFIT pointer +pointer nl # NLFIT pointer +real x[ARB] # Ordinates +real y[npts] # Data to be fit +real wts[npts] # Weights +int npts # Number of points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, ndeleted, ier +pointer rejpts +pointer in_getp() +int in_geti() + +begin +# # Debug +# call eprintf ("in_refit: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + + # Assign a zero weight to each rejected point. + rejpts = in_getp (in, INLREJPTS) + do i = 1, npts { + if (Memi[rejpts+i-1] == YES) + wts[i] = real (0.0) + } + + # Reinitialize NLFIT. + call in_nlinitr (in, nl) + + # Check number of data points. + if (npts == 0) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Check number of deleted points. + ndeleted = 0 + do i = 1, npts { + if (wts[i] <= real(0.0)) + ndeleted = ndeleted + 1 + } + if ((npts - ndeleted) < in_geti(in, INLNFPARAMS)) { + call in_puti (in, INLFITERROR, NO_DEG_FREEDOM) + return + } + + # Refit. + call nlfitr (nl, x, y, wts, npts, nvars, wtflag, ier) + + # Store fit status in the INLFIT structure. + call in_puti (in, INLFITERROR, ier) +end diff --git a/pkg/xtools/inlfit/inreject.gx b/pkg/xtools/inlfit/inreject.gx new file mode 100644 index 00000000..5aad8596 --- /dev/null +++ b/pkg/xtools/inlfit/inreject.gx @@ -0,0 +1,72 @@ +include <pkg/inlfit.h> + + +# IN_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 in_reject$t (in, nl, x, y, w, npts, nvars, wtflag) + +pointer in # INLFIT decriptor +pointer nl # NLFIT decriptor +PIXEL x[ARB] # Input ordinates (npts * nvars) +PIXEL y[npts] # Input data values +PIXEL w[npts] # Weights +int npts # Number of input points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, nreject, newreject, niter +PIXEL low, high, grow +pointer sp, wts1, rejpts + +int in_geti() +PIXEL in_get$t() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_reject: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Get number of reject iterations, and return if they + # are less than one. + niter = in_geti (in, INLNREJECT) + if (niter < 1) + return + + call smark (sp) + call salloc (wts1, npts, TY_PIXEL) + call amov$t (w, Mem$t[wts1], npts) + + # Get rejection parameters, and rejected point list. + low = in_get$t (in, INLLOW) + high = in_get$t (in, INLHIGH) + grow = in_get$t (in, INLGROW) + rejpts = in_getp (in, INLREJPTS) + + # Loop looking for deviant points, and refitting. + do i = 1, niter { + + # Look for new deviant points. + call in_deviant$t (nl, x, y, w, Memi[rejpts], npts, nvars, low, + high, grow, nreject, newreject) + + # Refit if there are new rejected points. + if (newreject != 0) { + call amov$t (Mem$t[wts1], w, npts) + call in_refit$t (in, nl, x, y, w, npts, nvars, wtflag) + } else + break + } + + # Update number of rejected points. + call in_puti (in, INLNREJPTS, nreject + newreject) + + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inrejectd.x b/pkg/xtools/inlfit/inrejectd.x new file mode 100644 index 00000000..670cbce6 --- /dev/null +++ b/pkg/xtools/inlfit/inrejectd.x @@ -0,0 +1,72 @@ +include <pkg/inlfit.h> + + +# IN_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 in_rejectd (in, nl, x, y, w, npts, nvars, wtflag) + +pointer in # INLFIT decriptor +pointer nl # NLFIT decriptor +double x[ARB] # Input ordinates (npts * nvars) +double y[npts] # Input data values +double w[npts] # Weights +int npts # Number of input points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, nreject, newreject, niter +double low, high, grow +pointer sp, wts1, rejpts + +int in_geti() +double in_getd() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_reject: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Get number of reject iterations, and return if they + # are less than one. + niter = in_geti (in, INLNREJECT) + if (niter < 1) + return + + call smark (sp) + call salloc (wts1, npts, TY_DOUBLE) + call amovd (w, Memd[wts1], npts) + + # Get rejection parameters, and rejected point list. + low = in_getd (in, INLLOW) + high = in_getd (in, INLHIGH) + grow = in_getd (in, INLGROW) + rejpts = in_getp (in, INLREJPTS) + + # Loop looking for deviant points, and refitting. + do i = 1, niter { + + # Look for new deviant points. + call in_deviantd (nl, x, y, w, Memi[rejpts], npts, nvars, low, + high, grow, nreject, newreject) + + # Refit if there are new rejected points. + if (newreject != 0) { + call amovd (Memd[wts1], w, npts) + call in_refitd (in, nl, x, y, w, npts, nvars, wtflag) + } else + break + } + + # Update number of rejected points. + call in_puti (in, INLNREJPTS, nreject + newreject) + + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inrejectr.x b/pkg/xtools/inlfit/inrejectr.x new file mode 100644 index 00000000..98116fe9 --- /dev/null +++ b/pkg/xtools/inlfit/inrejectr.x @@ -0,0 +1,72 @@ +include <pkg/inlfit.h> + + +# IN_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 in_rejectr (in, nl, x, y, w, npts, nvars, wtflag) + +pointer in # INLFIT decriptor +pointer nl # NLFIT decriptor +real x[ARB] # Input ordinates (npts * nvars) +real y[npts] # Input data values +real w[npts] # Weights +int npts # Number of input points +int nvars # Number of variables +int wtflag # Type of weighting + +int i, nreject, newreject, niter +real low, high, grow +pointer sp, wts1, rejpts + +int in_geti() +real in_getr() +pointer in_getp() + +begin +# # Debug. +# call eprintf ("in_reject: in=%d, nl=%d, npts=%d, nvars=%d\n") +# call pargi (in) +# call pargi (nl) +# call pargi (npts) +# call pargi (nvars) + + # Get number of reject iterations, and return if they + # are less than one. + niter = in_geti (in, INLNREJECT) + if (niter < 1) + return + + call smark (sp) + call salloc (wts1, npts, TY_REAL) + call amovr (w, Memr[wts1], npts) + + # Get rejection parameters, and rejected point list. + low = in_getr (in, INLLOW) + high = in_getr (in, INLHIGH) + grow = in_getr (in, INLGROW) + rejpts = in_getp (in, INLREJPTS) + + # Loop looking for deviant points, and refitting. + do i = 1, niter { + + # Look for new deviant points. + call in_deviantr (nl, x, y, w, Memi[rejpts], npts, nvars, low, + high, grow, nreject, newreject) + + # Refit if there are new rejected points. + if (newreject != 0) { + call amovr (Memr[wts1], w, npts) + call in_refitr (in, nl, x, y, w, npts, nvars, wtflag) + } else + break + } + + # Update number of rejected points. + call in_puti (in, INLNREJPTS, nreject + newreject) + + call sfree (sp) +end diff --git a/pkg/xtools/inlfit/inrms.gx b/pkg/xtools/inlfit/inrms.gx new file mode 100644 index 00000000..a2c5015b --- /dev/null +++ b/pkg/xtools/inlfit/inrms.gx @@ -0,0 +1,31 @@ +# IN_RMS -- Compute rms of points which have a non-zero weight. + +PIXEL procedure in_rms$t (y, fit, wts, npts) + +PIXEL y[npts] # function +PIXEL fit[npts] # fit +PIXEL wts[npts] # weights +int npts # number of points + +int i, ndata +PIXEL resid, rms + +begin + rms = PIXEL (0.0) + ndata = 0 + + do i = 1, npts { + if (wts[i] == PIXEL (0.0)) + next + resid = y[i] - fit[i] + rms = rms + resid * resid + ndata = ndata + 1 + } + + if (ndata > 0) + rms = sqrt (rms / ndata) + else + rms = PIXEL (0.0) + + return (rms) +end diff --git a/pkg/xtools/inlfit/inrmsd.x b/pkg/xtools/inlfit/inrmsd.x new file mode 100644 index 00000000..26800de7 --- /dev/null +++ b/pkg/xtools/inlfit/inrmsd.x @@ -0,0 +1,31 @@ +# IN_RMS -- Compute rms of points which have a non-zero weight. + +double procedure in_rmsd (y, fit, wts, npts) + +double y[npts] # function +double fit[npts] # fit +double wts[npts] # weights +int npts # number of points + +int i, ndata +double resid, rms + +begin + rms = double (0.0) + ndata = 0 + + do i = 1, npts { + if (wts[i] == double (0.0)) + next + resid = y[i] - fit[i] + rms = rms + resid * resid + ndata = ndata + 1 + } + + if (ndata > 0) + rms = sqrt (rms / ndata) + else + rms = double (0.0) + + return (rms) +end diff --git a/pkg/xtools/inlfit/inrmsr.x b/pkg/xtools/inlfit/inrmsr.x new file mode 100644 index 00000000..e28696a1 --- /dev/null +++ b/pkg/xtools/inlfit/inrmsr.x @@ -0,0 +1,31 @@ +# IN_RMS -- Compute rms of points which have a non-zero weight. + +real procedure in_rmsr (y, fit, wts, npts) + +real y[npts] # function +real fit[npts] # fit +real wts[npts] # weights +int npts # number of points + +int i, ndata +real resid, rms + +begin + rms = real (0.0) + ndata = 0 + + do i = 1, npts { + if (wts[i] == real (0.0)) + next + resid = y[i] - fit[i] + rms = rms + resid * resid + ndata = ndata + 1 + } + + if (ndata > 0) + rms = sqrt (rms / ndata) + else + rms = real (0.0) + + return (rms) +end diff --git a/pkg/xtools/inlfit/mkpkg b/pkg/xtools/inlfit/mkpkg new file mode 100644 index 00000000..4dd38bfb --- /dev/null +++ b/pkg/xtools/inlfit/mkpkg @@ -0,0 +1,122 @@ +# INLFIT mkpkg file + +$checkout libxtools.a lib$ +$update libxtools.a +$checkin libxtools.a lib$ +$exit + +generic: + $set GEN = "$$generic -k -t rd" + $ifnewer (inget.gx, inget.x) + $generic -k -o inget.x inget.gx + $endif + $ifnewer (input.gx, input.x) + $generic -k -o input.x input.gx + $endif + + $ifnewer (indump.gx, indumpr.x) $(GEN) indump.gx $endif + + $ifnewer (incopy.gx, incopyr.x) $(GEN) incopy.gx $endif + $ifnewer (infree.gx, infreer.x) $(GEN) infree.gx $endif + $ifnewer (ininit.gx, ininitr.x) $(GEN) ininit.gx $endif + $ifnewer (innlinit.gx, innlinitr.x) $(GEN) innlinit.gx $endif + + $ifnewer (indeviant.gx, indeviantr.x) $(GEN) indeviant.gx $endif + $ifnewer (inerrors.gx, inerrorsr.x) $(GEN) inerrors.gx $endif + $ifnewer (infit.gx, infitr.x) $(GEN) infit.gx $endif + $ifnewer (inlimit.gx, inlimitr.x) $(GEN) inlimit.gx $endif + $ifnewer (inrefit.gx, inrefitr.x) $(GEN) inrefit.gx $endif + $ifnewer (inreject.gx, inrejectr.x) $(GEN) inreject.gx $endif + $ifnewer (inrms.gx, inrmsr.x) $(GEN) inrms.gx $endif + + $ifnewer (ingaxes.gx, ingaxesr.x) $(GEN) ingaxes.gx $endif + $ifnewer (ingcolon.gx, ingcolonr.x) $(GEN) ingcolon.gx $endif + $ifnewer (ingdata.gx, ingdatar.x) $(GEN) ingdata.gx $endif + $ifnewer (ingdelete.gx, ingdeleter.x) $(GEN) ingdelete.gx $endif + $ifnewer (ingerrors.gx, ingerrorsr.x) $(GEN) ingerrors.gx $endif + $ifnewer (ingfit.gx, ingfitr.x) $(GEN) ingfit.gx $endif + $ifnewer (inggraph.gx, inggraphr.x) $(GEN) inggraph.gx $endif + $ifnewer (ingnearest.gx, ingnearestr.x) $(GEN) ingnearest.gx $endif + $ifnewer (ingparams.gx, ingparamsr.x) $(GEN) ingparams.gx $endif + $ifnewer (ingresults.gx, ingresultsr.x) $(GEN) ingresults.gx $endif + $ifnewer (ingshow.gx, ingshowr.x) $(GEN) ingshow.gx $endif + $ifnewer (inguaxes.gx, inguaxesr.x) $(GEN) inguaxes.gx $endif + $ifnewer (ingucolon.gx, ingucolonr.x) $(GEN) ingucolon.gx $endif + $ifnewer (ingundelete.gx, ingundeleter.x) $(GEN) ingundelete.gx $endif + $ifnewer (ingvars.gx, ingvarsr.x) $(GEN) ingvars.gx $endif + $ifnewer (ingvshow.gx, ingvshowr.x) $(GEN) ingvshow.gx $endif + ; + +libxtools.a: + + $ifeq (USE_GENERIC, yes) $call generic $endif + + incopyd.x <pkg/inlfit.h> "inlfitdef.h" + incopyr.x <pkg/inlfit.h> "inlfitdef.h" + indeviantd.x <mach.h> + indeviantr.x <mach.h> + indumpd.x <pkg/inlfit.h> "inlfitdef.h" + indumpr.x <pkg/inlfit.h> "inlfitdef.h" + inerrorsd.x <pkg/inlfit.h> <math/nlfit.h> + inerrorsr.x <pkg/inlfit.h> <math/nlfit.h> + infitd.x <pkg/inlfit.h> <math/nlfit.h> + infitr.x <pkg/inlfit.h> <math/nlfit.h> + infreed.x "inlfitdef.h" + infreer.x "inlfitdef.h" + ingaxesd.x <pkg/inlfit.h> <pkg/gtools.h> + ingaxesr.x <pkg/inlfit.h> <pkg/gtools.h> + ingcolond.x <pkg/inlfit.h> <error.h> <gset.h> + ingcolonr.x <pkg/inlfit.h> <error.h> <gset.h> + ingdatar.x <pkg/inlfit.h> + ingdatad.x <pkg/inlfit.h> + ingdefkey.x <pkg/inlfit.h> "inlfitdef.h" + ingdeleted.x <gset.h> <mach.h> <pkg/gtools.h> + ingdeleter.x <gset.h> <mach.h> <pkg/gtools.h> + ingerrorsd.x <pkg/inlfit.h> <math/nlfit.h> + ingerrorsr.x <pkg/inlfit.h> <math/nlfit.h> + inget.x <pkg/inlfit.h> "inlfitdef.h" + ingfitd.x <pkg/inlfit.h> <math/nlfit.h> <error.h> <mach.h>\ + <pkg/gtools.h> + ingfitr.x <pkg/inlfit.h> <math/nlfit.h> <error.h> <mach.h>\ + <pkg/gtools.h> + inggetlabel.x <pkg/inlfit.h> + inggraphd.x <pkg/inlfit.h> <math/nlfit.h> <gset.h>\ + <pkg/gtools.h> + inggraphr.x <pkg/inlfit.h> <math/nlfit.h> <gset.h>\ + <pkg/gtools.h> + ingnearestd.x <mach.h> <pkg/gtools.h> + ingnearestr.x <mach.h> <pkg/gtools.h> + ingparamsd.x <pkg/inlfit.h> <math/nlfit.h> <pkg/gtools.h> + ingparamsr.x <pkg/inlfit.h> <math/nlfit.h> <pkg/gtools.h> + ingresultsr.x <pkg/inlfit.h> + ingresultsd.x <pkg/inlfit.h> + ingshowd.x <pkg/inlfit.h> + ingshowr.x <pkg/inlfit.h> + inguaxesd.x <pkg/inlfit.h> <math/nlfit.h> + inguaxesr.x <pkg/inlfit.h> <math/nlfit.h> + ingucolond.x + ingucolonr.x + ingufit.x + ingundeleted.x <gset.h> <mach.h> <pkg/gtools.h> + ingundeleter.x <gset.h> <mach.h> <pkg/gtools.h> + ingvarsr.x <pkg/inlfit.h> + ingvarsd.x <pkg/inlfit.h> + ingvshowd.x <pkg/inlfit.h> + ingvshowr.x <pkg/inlfit.h> + ininitd.x <pkg/inlfit.h> "inlfitdef.h" + ininitr.x <pkg/inlfit.h> "inlfitdef.h" + inlimitd.x <pkg/inlfit.h> + inlimitr.x <pkg/inlfit.h> + inlstrext.x <ctype.h> + inlstrwrd.x + innlinitd.x "inlfitdef.h" + innlinitr.x "inlfitdef.h" + input.x <pkg/inlfit.h> "inlfitdef.h" + inrefitd.x <pkg/inlfit.h> <math/nlfit.h> + inrefitr.x <pkg/inlfit.h> <math/nlfit.h> + inrejectd.x <pkg/inlfit.h> + inrejectr.x <pkg/inlfit.h> + inrmsd.x + inrmsr.x + ingtitle.x <pkg/gtools.h> + ; |