aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/multispec/msextract.x
blob: e301706591535c1a39fecd62d35b17828e447b53 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
include <fset.h>
include	<imhdr.h>
include "ms.h"

# EX_OUT -- Write and format the extracted spectra to the output image.
# SUM_PIXELS -- Sum pixel array between the limits lower and upper.
# EX_SET_VEBOSE -- Set and print verbose output.


# EX_OUT -- Write and format the extracted spectra to the output image.
#
# The type of output is selected by the value of ex_integral.
# If ex_integral = yes then sum the spectra profiles and output one value
# per spectrum otherwise output the strip spectra profiles.

procedure ex_out (im_out, line_out, spectra, lower, upper, ranges, profiles,
	len_profile, nspectra, ex_integral)

pointer	im_out				# Output image file descriptor
int	line_out			# Output line
int	spectra[ARB]			# Spectra range list
real	lower				# Lower integral limit
real	upper				# Upper integral limit
real	ranges[nspectra, LEN_RANGES]	# Starting points of profiles
real	profiles[len_profile, nspectra]	# Real spectra profiles
int	len_profile			# Length of spectra profiles
int	nspectra			# Number of spectra profiles
bool	ex_integral

int	i, spectrum_in, spectrum_out
real	x_min, x_max
pointer	buf_out

int	get_next_number()
real	sum_pixels()
pointer	impl3r()

begin
	# Loop through the selected spectra write an image line for one.
	spectrum_in = 0
	spectrum_out = 0
	while (get_next_number (spectra, spectrum_in) != EOF) {
	    spectrum_out = spectrum_out + 1
	    buf_out = impl3r (im_out, line_out, spectrum_out)

	    # Select between integrated and strip spectra output.  If
	    # integrated spectra call sum_pixels to integrate the spectrum
	    # profile else output the spectrum profile.
	    if (ex_integral) {
	        x_min = lower - ranges[spectrum_in, DX_START] + 1
	        x_max = upper - ranges[spectrum_in, DX_START] + 1
	        Memr[buf_out] =
		    sum_pixels (profiles[1, spectrum_in], x_min, x_max)
	    } else {
	        do i = 1, len_profile
		    Memr[buf_out + i - 1] = profiles[i, spectrum_in]
	    }
	}
end


# SUM_PIXELS -- Sum pixel array between the limits lower and upper.
# The limits may be partial pixels.  There is no checking for out of
# array range limits.

real procedure sum_pixels (pixels, x_min, x_max)

real	pixels[ARB]			# Pixel array to be summed
real	x_min				# Lower limit of sum
real	x_max				# Upper limit of sum

int	i, i_min, i_max
real	f, value

begin
	# Determine bounding integer limits.
	i_min = x_min + 0.5
	i_max = x_max + 0.5

	# Add partial pixel endpoints.

	f = min (x_max, i_min + 0.5) - x_min
	value = f * pixels[i_min]
	if (i_min >= i_max)
	    return (value)

	f = x_max - (i_max - 0.5)
	value = value + f * pixels[i_max]
	if (i_min + 1 > i_max - 1)
	    return (value)

	# Sum non-endpoint pixels.

	do i = i_min + 1, i_max - 1
	    value = value + pixels[i]

	return (value)
end

# EX_SET_VERBOSE -- Output procedures for verbose mode.

procedure ex_set_verbose (verbose)

bool	verbose

#entry ex_prnt1 (image_in, image_out)
char	image_in[1]
char	image_out[1]

# entry ex_prnt2 (line_in, line_out)
int	line_in, line_out, nreplaced

bool	flag

begin
	# Toggle verbose output.
	flag = verbose
	if (flag)
	    call fseti (STDOUT, F_FLUSHNL, YES)
	else
	    call fseti (STDOUT, F_FLUSHNL, NO)
	return

entry ex_prnt1 (image_in, image_out)

	# Set the verbose flag and print general header information.
	if (flag) {
	    call printf ("\nMULTISPEC Extraction Program\n\n")
	    call printf ("Image being extracted is %s.\n")
	        call pargstr (image_in)
	    call printf ("Output extraction image is %s.\n")
	        call pargstr (image_out)
	}
	return

entry ex_prnt2 (line_in, line_out)

	# Print the image line being extracted.
	if (flag) {
	    call printf ("Input image line = %d and output image line = %d.\n")
	        call pargi (line_in)
	        call pargi (line_out)
	}
	return

entry ex_prnt3 (nreplaced)

	# Print the number of pixels replaced in cleaning.
	if (flag && (nreplaced > 0)) {
	    call printf ("  Number of pixels replaced: %d\n")
	        call pargi (nreplaced)
	}
	return
end