.ec _
.ll 76
.ad b
.in 4
.\"====================================================================
.ti -4
1 Language
.ti +10
FIT_\ Language Summary

.nf
DISPLAY             Prints the results of the profile fit of R.
VISUALIZE [N]       Plots the current fitted profile.
MINIMIZE            Performs a profile fit.
ITERATE             Iterates the profile fit.
KEEP                Saves Gaussian fit results in the output file.
LINES [N]           Enters the initial values for the profile fit.
METHOD Arg          Selects the line profile for fits.
RESIDUAL [N]        Computes the residuals of the profile fit.
RESULT [N]          Computes the profile fit.
.fi
.\"====================================================================
.ti -4
1 DISPLAY
.ti +4
FIT_\DISPLAY [Yoff] [/NOPLOT] [/METHOD]

Displays the results of the profile fit of R for the current method,
in the terminal and in the plot header. Yoff indicates the Y offset
for the results to be printed on the plot; default value is 0.

For the Gauss (default) method (see HELP METHOD), the command displays
(1) the Line number, (2) the Area, (3) the Position, (4) the Width and
(5) the Intensity , each with their associated errors, and resulting
RMS in the Base and Line windows.

Note that the values are also available in the R% variable, for use in
procedures. See HELP MINIMIZE for details.

.br
/NOPLOT: if present, print the fit result but do not display them on
the plot.
.br
/METHOD: if present, print the fit result for the corresponding
method.
.\"====================================================================
.ti -4
1 ITERATE
.ti +4
FIT_\ITERATE [N] [/NOCHECK BASELINE]

ITERATE tries the GRADIENT technique to improve the last results of
the profile fit. Optional argument N indicates the number of
iterations. Do not expect spectacular results if the absolute minimum
is far away! Typically, this command should be used if the previous
fit did not converge, but seems close enough.  If you are using the
GAUSS method, be cautious not to change the X unit in the mean time.
.\"--------------------------------------------------------------------
.ti -4
2 /NOCHECK
.ti +4
FIT_\ITERATE [N] /NOCHECK BASELINE

Except for the CONTINUUM method, all the fitted models tend to zero at
the edges, so the command checks by default if a baseline has been
removed before fitting.

If the option /NOCHECK BASELINE is present, the command will not raise
an error if a baseline has not been removed. This assumes the spectrum
has intrinsicly a zero-level background.
.\"====================================================================
.ti -4
1 KEEP
.ti +4
FIT_\KEEP 

Save profile fit results in the output file. KEEP is equivalent to
UPDATE, but only profile fit results are saved; KEEP is subject to the
same restrictions as UPDATE.
.\"====================================================================
.ti -4
1 LINES
.ti +4
FIT_\LINES [N [Guesses]] [/NOCURSOR] [/INPUT File__Name] [/SHOW]

Enter the initial values for the profile fit.  If argument "AUTO" is
given instead of a number, then the number of lines found in the last
read spectrum will be used for ITERATE command.

If N is not specified, then the last value for N is used.  If N is 0,
MINIMIZE will attempt to guess initial values for a single line by
computing the moments of the spectrum.  If N is not 0, the user has to
provide the initial values for line parameters. N is limited to
10. These values should be separated by spaces and can be entered as
SIC expressions as follows:

.nf
Method      Code,Value     Code,Value   Code,Value     Code,Value

GAUSS       Temperature    Position     Width

SHELL       Area (K.MHz)   Offset (MHz) Width (MHz)    Horn/Center

NH3         Temperature    Position     Width (km/s)   Opacity

HFS         Temperature    Position     Width (km/s)   Opacity

ABSORPTION  Opacity        Position     Width
  (no initial guess is needed for the continuum level)
.fi

The code is an integer interpreted as follows :
.nf 
	0	adjustable parameter
	1	fixed parameter
	2	adjustable parameter (head of group)
	3	parameter fixed with respect to parameter coded 2 or 4
	4	fixed parameter (head of group)
.fi
Codes 2 3 and 4 are used to fit dependent lines (e.g. HCN, for which
the displacements are 4.842 and -7.064 km/s, or -1.431 and 2.088 MHz,
and line ratios 1:0.6:0.2). Codes 0 and 1 only are allowed for NH3
method. The value for a parameter with code 3 should be either the
ratio to the head of group value (for both intensity and width), or
the offset from head of group (for the position).

There are 4 possibilities for the user to provide the line parameters:
.in +8
.ti -4
LINES /INPUT File__Name
.br
Guesses are read from the input file. "Free" format is used to read in
this input file. The first line must contain the number of lines,
others are as the input at the keyboard.
.ti -4
LINES N "Code Val ..." "Code Val ..." ...
.br
The guesses can also be entered from the command line, as
double-quoted strings (one string per fitted line), e.g.
.nf
    LINES 2 "0 0.20  0 0.00  0 25.00" "0 0.10  0 0.00  0 50.00"
.fi
.ti -4
LINES N
.br
If the cursor is available, you will have to set interactively on the
plot the boundaries of the N lines. The program then computes the
moments of the spectra between these boundaries as input values. The
codes are all set to 0 (free parameters) in this way which is
meaningfull ONLY FOR FREE and INDEPENDENT lines. This cursor selection
is not used if you specify the /NOCURSOR option.
.ti -4
LINES N /NOCURSOR
.br
If none of the 3 methods above is used, then the user is prompted in
the terminal for the guesses. The parameters must be entered together,
separated by blanks, one set of guesses per prompt line.
.in -8
The option /SHOW can be used for a feedback of what initial guesses
have just been defined.

Command LINES is not supported for method CONTINUUM.
.\"====================================================================
.ti -4
1 METHOD
.ti +4
FIT_\METHOD Arg [Parameters ...]

Select the line profile for fits. Five type of profiles are available.
.in +4

.ti -2 
- GAUSS_ _ _ _  Select gaussian profiles. 
.br
Up to 10 Gaussian, dependent or independent can be fitted in a
spectrum, according to command lines. Fitted parameters are:
.ti +4
1) Area
.ti +4
2) Velocity, and
.ti +4
3) Width (FWHM)

.ti -2
- SHELL_ _ _ _  Horn-type profiles for Circumstellar Shells. 
.br
Fitted parameters are:
.ti +4
1) Area [K.MHz]
.ti +4
2) Center offset [in MHz]
.ti +4
3) Full Width at zero level, and
.in +7
.ti -3
4) Horn-to-center ratio (-1 for parabolic optically
thick lines, 0 for flat-topped lines, Infinity for perfectly double
peaked lines).
.in -7
Profiles are symmetric. Up to 10 dependent or independent lines may be
fitted. X axis must be frequency.

.ti -2
- NH3(1,1) or NH3(2,2) or NH3(3,3)
.br 
Compute ammonia line profiles, with the assumptions of gaussian
velocity distribution and equal excitation temperatures. Fitted
parameters are:
.in +7
.ti -3
1) Main group opacity times ( Excitation temperature minus Background
temperature),
.in -7
.ti +4
2) Velocity,
.ti +4
3) Width (FWHM = sqrt(8.0*alog(2.0)) * line 2nd order moment),
.ti +4
4) Main group opacity.
.br
Up to 10 independent lines may be fitted. The hyperfine structure
description can be found in the structure HFS% right after the command
METHOD is invoked.

.ti -2
- HFS FileName_ _ _  for HyperFine Structure
.br
This is very similar to the NH3 method, but the coefficients which
describe the hyperfine structure are read in the file FileName. It
must contain:
.ti +4
- the number of hyperfine components (_< 40, first line),
.in +6
.ti -2
-_ the velocity offset and relative intensity (repeated for each
component, one per line),
.in -6
The hyperfine structure description read from the this file can be
found in the structure HFS% right after the command METHOD is invoked.
The fitted parameters are the same as for the NH3 method, except for
the main group opacity.

In the HFS method the main group opacity refers to the total opacity
of the combined hyperfine components present in the description file
divided by the sum of their relative intensities. i.e. if the given
relative intensities are normalised (their sum is 1) the resulting
main group opacity will be the sum of the opacities of all hyperfine
components present in the description file. This behaviour is useful
for example in the case where we have only a part of the hyperfine
components of a transition available in a spectrum. In this case one
may fit only the hyperfine components present on the spectrum and
still recover the total opacity of the main transition. The safest way
to avoid mistakes is to always use the statistical weight of the upper
hyperfine level divided by the total statistical weight of the upper
level of the main transition. In this manner one will always recover
the total opacity of the main transition over all hyperfine
components.

.ti -2 
- ABSORPTION Filename_ _ _ for hyperfine structures in absorption
.br
Fitted parameters are:
.ti +4
1) One continuum level
.br
and for each line:
.ti +4
2) Opacity
.ti +4
3) Velocity, and
.ti +4
4) Width (FWHM)

.ti -2
- CONTINUUM [Width [Area__Ratio [Width__Ratio]]]_ _ for Continuum drifts
.br
Fit a single gaussian and a linear baseline at the same time, with
automatic determination of the parameters. Uses beam-switched
information for two-component fitting if required. The command METHOD
CONTINUUM accept additional arguments, which can be used to customize
the fit:
.in +6
.ti -2
- Width is the width of the beam in arc seconds. By default, Width is
a free parameter.
.ti -2
-_ Area__Ratio is the reference to main beam area ratio, used for
beam-switch observing. By default, Area__Ratio is 1.
.ti -2
- Width__Ratio is the reference to main beam width ratio, used for
beam-switch observing. By default, Width__Ratio is 1.
.in -6
A * can be used instead of a numerical value for each parameter, and
indicates that the parameter is free.
.in -4

Note that in command LINES, one enters the peak line antenna
temperature instead of the first variable in the guesses, except for
SHELL method. Command LINES has no effect for CONTINUUM.

CONTINUUM and GAUSS methods only are relevant for continuum data,
while GAUSS, SHELL, NH3, HFS and ABSORPTION methods can be used for
spectroscopic data.
.\"====================================================================
.ti -4
1 MINIMIZE
.ti +4
FIT_\MINIMIZE [/NOCHECK BASELINE]

Performs a fit of a theoretical profile in the R spectrum using
initial values specified by the command LINES. The profile is
determined by the METHOD command (GAUSS, SHELL or NH3 lines are
currently implemented, and a special method, CONTINUUM, may be used
for continuum data).

MINIMIZE performs the fit only on the part of the spectrum selected by
SET MODE X. It also ignores the regions under the masks defined by SET
MASK.

If LINES is 0, an attempt to guess initial values for a single line is
done by computing the moments of the spectrum.  A first minimisation
is performed using the Simplex technique; the results are improved and
the uncertainties computed using the Gradient technique. If MINIMIZE
did not converge, the errors quoted in the results are meaningless,
and you should use command ITERATE to try to do better.

In the fit result output, the fit is said:
.ti +2
- "optimistic" if R%HEAD%GAU%RMS__BASE > R%HEAD%GAU%RMS__LINE * 1.5,
.ti +2
- "bad" if R%HEAD%GAU%RMS__BASE < R%HEAD%GAU%RMS__LINE / 1.5
.br
where RMS__LINE and RMS__BASE are the RMS of residuals on the line
range(s) and the remaining base, respectively. This comment is purely
informative.

For CONTINUUM method, although a linear baseline is fitted with the
gaussian, only the gaussian parameters are displayed.  If the
observation was made using beam-switching method and the reference
beam appears in the drifts, a two-component gauss fit is done using
separation specified in the data.

The fitting results are saved in the R% variable, for e.g. reuse in
procedures:
.nf
  Method      Structure
  GAUSS       R%HEAD%GAU%
  SHELL       R%HEAD%SHE%
  NH3/HFS     R%HEAD%HFS%
  ABSORPTION  R%HEAD%ABS%
  CONTINUUM   R%HEAD%POI%
.fi
See subtopic for details.
.\"--------------------------------------------------------------------
.ti -4
2 GAUSSIAN
.ti +4
FIT_\MINIMIZE (parameters of the GAUSSIAN profile)

The gaussian fit parameters can be found in:

.nf
  Parameter       Variable

  Area            R%HEAD%GAU%RESULT['(ILINE-1)*3+1']
  Position        R%HEAD%GAU%RESULT['(ILINE-1)*3+2']
  Width           R%HEAD%GAU%RESULT['(ILINE-1)*3+3']

  Error(Area)     R%HEAD%GAU%ERROR['(ILINE-1)*3+1']
  Error(Position) R%HEAD%GAU%ERROR['(ILINE-1)*3+2']
  Error(Width)    R%HEAD%GAU%ERROR['(ILINE-1)*3+3']
.fi

where ILINE is the number of one of the fitted lines, between 1 and
R%HEAD%GAU%NLINE.
.\"--------------------------------------------------------------------
.ti -4
2 SHELL
.ti +4
FIT_\MINIMIZE (fit parameters of the SHELL profile)

The shell fit parameters can be found in:

.nf
  Parameter             Variable                            Unit

  Area                  R%HEAD%SHE%RESULT['(ILINE-1)*4+1']  K.MHz
  Central frequency     R%HEAD%SHE%RESULT['(ILINE-1)*4+2']  MHz, offset from RESTF
  Half width at 0-level R%HEAD%SHE%RESULT['(ILINE-1)*4+3']  MHz
  Horn/Center           R%HEAD%SHE%RESULT['(ILINE-1)*4+4']  -

  Error(Area)           R%HEAD%SHE%ERROR['(ILINE-1)*4+1']   K.MHz
  Error(Central Freq)   R%HEAD%SHE%ERROR['(ILINE-1)*4+2']   MHz, offset from RESTF
  Error(HW at 0-level)  R%HEAD%SHE%ERROR['(ILINE-1)*4+3']   MHz
  Error(Horn/Center)    R%HEAD%SHE%ERROR['(ILINE-1)*4+4']   -
.fi

where ILINE is the number of one of the fitted lines, between 1 and
R%HEAD%SHE%NLINE. See Class documentation for a detailed description
of the fitting formula.
.\"--------------------------------------------------------------------
.ti -4
2 HFS
.ti +4
FIT_\MINIMIZE (parameters of the NH3/HFS profile)

The NH3/HFS fit parameters can be found in:

.nf
  Parameter       Variable

  Tant * Tau      R%HEAD%HFS%RESULT['(ILINE-1)*4+1']
  V lsr           R%HEAD%HFS%RESULT['(ILINE-1)*4+2']
  Delta V         R%HEAD%HFS%RESULT['(ILINE-1)*4+3']
  Tau main        R%HEAD%HFS%RESULT['(ILINE-1)*4+4'] 

  Error(Tant*Tau) R%HEAD%HFS%ERROR['(ILINE-1)*4+1'] 
  Error(V lsr)    R%HEAD%HFS%ERROR['(ILINE-1)*4+2'] 
  Error(Delta V)  R%HEAD%HFS%ERROR['(ILINE-1)*4+3'] 
  Error(Tau main) R%HEAD%HFS%ERROR['(ILINE-1)*4+4'] 
.fi

where ILINE is the number of one of the fitted lines, between 1 and
R%HEAD%NFS%NLINE. See Class documentation for a detailed description
of the fitting formula.
.\"--------------------------------------------------------------------
.ti -4
2 CONTINUUM
.ti +4
FIT_\MINIMIZE (parameters of the CONTINUUM profile)

The continuum drift fit parameters can be found in:

.nf
  Parameter       Variable                          Unit

  Baseline Offset R%HEAD%POI%NCONT[1]               counts
  Baseline Slope  R%HEAD%POI%NCONT[2]               counts/rad
  Area            R%HEAD%POI%NCONT['(ILINE-1)*3+3'] counts.rad
  Position        R%HEAD%POI%NCONT['(ILINE-1)*3+4'] rad
  Width           R%HEAD%POI%NCONT['(ILINE-1)*3+5'] rad

  Error(Base Off) R%HEAD%POI%ECONT[1]               counts
  Error(Base Slo) R%HEAD%POI%ECONT[2]               counts/rad
  Error(Area)     R%HEAD%POI%ECONT['(ILINE-1)*3+3'] counts.rad
  Error(Position) R%HEAD%POI%ECONT['(ILINE-1)*3+4'] rad
  Error(Width)    R%HEAD%POI%ECONT['(ILINE-1)*3+5'] rad
.fi

where ILINE is the number of one of the fitted lines, between 1 and
R%HEAD%POI%LCONT. Note that these values are available in radians
angles, but they are displayed or plotted in CLASS using the current
SET ANGLE setting.
.\"--------------------------------------------------------------------
.ti -4
2 /NOCHECK
.ti +4
FIT_\MINIMIZE /NOCHECK BASELINE

Except for the CONTINUUM method, all the fitted models tend to zero at
the edges, so the command checks by default if a baseline has been
removed before fitting.

If the option /NOCHECK BASELINE is present, the command will not raise
an error if a baseline has not been removed. This assumes the spectrum
has intrinsicly a zero-level background.
.\"====================================================================
.ti -4
1 RESIDUAL
.ti +4
FIT_\RESIDUAL [N]

Compute the residuals of the last MINIMIZE fit. Copies R into T, then
subtract the line profile number N from the spectrum in R. If N is 0,
the sum of all components is subtracted.
.\"====================================================================
.ti -4
1 RESULT
.ti +4
FIT_\RESULT [N]

Compute the last MINIMIZE fit. Copies R into T, then save the line
profile number N into R. If N is 0, the sum of all components is
computed.
.\"====================================================================
.ti -4
1 VISUALIZE
.ti +4
FIT_\VISUALIZE [N] [/PEN [i]]

Plot the current fitted profile. The Nth line obtained the last time
MINIMIZE was executed, or recovered by DISPLAY, is plotted on the
screen. If N is 0, the sum of all lines is plotted, and if N is not
given, the last value of N is used.

.ti +6
/PEN [ipen]: if ipen is present, use the given pencil 'ipen'
properties (defined with "pen ipen"), otherwise use the last defined
pencil. Without option, use pencil 2 properties.
.\"====================================================================
.ti -4
1 ENDOFHELP
