aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/multispec/setmodel.x
blob: 98c1a63076dc67ae799b2429e5a04b0992a78e7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
include "ms.h"

# SET_MODEL -- Set a line of model data from profiles based on their
# ranges starting values.

procedure set_model (ms, model, model_profiles, ranges, len_line, len_profile,
    nspectra)

pointer	ms					# MULTISPEC data structure
real	model[len_line]				# Model line created
real	model_profiles[len_profile, nspectra]	# Model profiles
real	ranges[nspectra, LEN_RANGES]		# Ranges array for the profiles
int	len_line				# The length of the model line
int	len_profile				# The length of the profiles
int	nspectra				# The number of spectra

int	i, x, spectrum

begin
	# Set the model background to zero.
	call aclrr (model, len_line)

	# For each spectrum and each profile point add contribution to model.
	do spectrum = 1, nspectra {
	    do i = 1, len_profile {
		# Column corresponding to profile point i and spectrum.
	        x = ranges[spectrum, X_START] + i - 1

		# Scale the model profile by the model parameter I0 and
		# add to the model line.
		if ((x >= 1) && (x <= len_line))
		    model[x] = model[x] + PARAMETER(ms, I0, spectrum) *
			model_profiles[i, spectrum]
	    }
	}
end

# SET_MODEL1 -- Set a line of model data from profiles based on the spectra
# function fit position centers and the ranges dx_start value.

procedure set_model1 (ms, line, profiles, coeff, ranges, len_line, len_profile,
    nspectra, model)

pointer	ms					# MULTISPEC data structure
int	line					# Image line for model
real	profiles[len_profile, nspectra]		# Profiles
real	coeff[ARB]				# Image interpolation coeff.
real	ranges[nspectra, LEN_RANGES]		# Ranges array for profiles
int	len_line				# Length of model line
int	len_profile				# Length of profiles
int	nspectra				# Number of spectra
real	model[len_line]				# Model line to be created

int	i, x, spectrum
real	x_start, dx

real	cveval(), asival()

begin
	# Clear the model to a zero background.
	call aclrr (model, len_line)

	# Add the contribution for each spectrum.
	do spectrum = 1, nspectra {
	    # Fit image interpolator to profile.
	    call asifit (profiles[1,spectrum], len_profile, coeff)

	    # Determine starting column corresponding to spectrum at specified
	    # line whose central position is given by the fit function.
	    x_start = cveval (CV(ms, X0_FIT, spectrum), real (line)) +
		ranges[spectrum, DX_START]

	    # For each column corresponding to a point in the profile determine
	    # the interpolation point dx within the profile and evaluate the
	    # the image interpolation function.

	    x = x_start
	    do i = 1, len_profile - 1 {
		x = x + 1
		if ((x >= 1) && (x <= len_line)) {
		    dx = x - x_start + 1
		    model[x] = model[x] + asival (dx, coeff)
		}
	    }
	}
end