aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/multispec/t_mslist.x
blob: e21d685ebe4067433de7a934c6661a3e9bc7c84e (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
include <fset.h>
include "ms.h"

# T_MS_LIST -- Print general MULTISPEC database information.

procedure t_ms_list ()

char	image[SZ_FNAME]
char	keyword[SZ_LINE]
bool	titles

int	ms_id
pointer	ms

bool	clgetb(), streq()
int	ms_db_id()
pointer	msmap()

begin
	call fseti (STDOUT, F_FLUSHNL, YES)

	# Get task parameters.
	call clgstr ("image", image, SZ_FNAME)
	ms = msmap (image, READ_ONLY, 0)
	call clgstr ("keyword", keyword, SZ_LINE)
	titles = clgetb ("titles")

	# Check for special keywords.
	if (streq (keyword, "gauss5")) {
	    call g5_list (ms, keyword, titles)

	# Keyword is one of the database record names.  Convert to a
	# MULTISPEC id and switch to appropriate listing routine.
	} else {
	    ms_id = ms_db_id (ms, keyword)
	    switch (ms_id) {
	    case HDR:
	        call hdr_list (ms, keyword, titles)
	    case COMMENTS:
	        call com_list (ms, keyword, titles)
	    case SAMPLE:
		call sam_list (ms, keyword, titles)
	    case I0, X0, S0, S1, S2:
	        call par_list (ms, ms_id, keyword, titles)
	    case X0_FIT, S0_FIT, S1_FIT, S2_FIT:
	        call fit_list(ms, ms_id, keyword, titles)
	    }
	}

	call msunmap (ms)
end


# HDR_LIST - List the contents of the MULTISPEC database header

procedure hdr_list (ms, keyword, titles)

pointer	ms					# MULTISPEC data structure
char	keyword[ARB]				# List keyword
bool	titles					# Print titles?

begin
	call printf ("Image: %s\n")
	    call pargstr (MS_IMAGE(ms))
	call printf ("Keyword:  %s\n")
	    call pargstr (keyword)
	call printf ("Title: %s\n")
	    call pargstr (MS_TITLE(ms))
	call printf ("Number of spectra: %d\n")
	    call pargi (MS_NSPECTRA(ms))
	call printf ("Number of sample image lines: %d\n")
	    call pargi (MS_NSAMPLES(ms))
	call printf ("Image size: %d x %d\n")
	    call pargi (MS_LEN(ms, 1))
	    call pargi (MS_LEN(ms, 2))
end

procedure com_list (ms, keyword, titles)

pointer	ms					# MULTISPEC data structure
char	keyword[ARB]				# List keyword
bool	titles					# Print titles?
int	i

begin
	if (titles) {
	    call printf ("Image: %s\n")
		call pargstr (MS_IMAGE(ms))
	    call printf ("Keyword:  %s\n")
		call pargstr (keyword)
	    call printf ("Comments:\n")
	}

	for (i=1; (i <= SZ_MS_COMMENTS) && (COMMENT(ms, i) != EOS); i=i+1)
	    call putchar (COMMENT(ms, i))
end


# SAM_LIST -- List the sample image lines.

procedure sam_list (ms, keyword, titles)

pointer	ms					# MULTISPEC data structure
char	keyword[ARB]				# List keyword
bool	titles					# Print titles?
int	i

begin
	if (titles) {
	    call printf ("Image: %s\n")
		call pargstr (MS_IMAGE(ms))
	    call printf ("Keyword:  %s\n")
		call pargstr (keyword)
	    call printf ("Sample Image Lines:\n")
	}

	do i = 1, MS_NSAMPLES(ms) {
	    call printf ("%8d\n")
		call pargi (LINE(ms, i))
	}
end


# PAR_LIST -- Print MULTISPEC profile parameters.
#
# This procedure does some CLIO.

procedure par_list (ms, ms_id, keyword, titles)

pointer	ms					# MULTISPEC data structure
int	ms_id					# MULTISPEC parameter id
char	keyword[ARB]				# List keyword
bool	titles					# Print titles?

int	lines[3, MAX_RANGES], spectra[3, MAX_RANGES]
int	i, nsamples, sample, spectrum
pointer	sp, samples

int	clgranges(), get_next_number(), get_sample_lines()

begin
	if ((MS_NSAMPLES(ms) == 0) || (MS_NSPECTRA(ms) == 0))
	    return

	# Get desired image lines and spectra to be listed.
	i = clgranges ("lines", 1, MS_LEN(ms, 2), lines, MAX_RANGES)
	i = clgranges ("spectra", 1, MS_NSPECTRA(ms), spectra, MAX_RANGES)

	# Convert image lines to sample lines.
	call smark (sp)
	call salloc (samples, MS_NSAMPLES(ms), TY_INT)
	nsamples = get_sample_lines (ms, lines, Memi[samples])

	# Print header titles if needed.
	if (titles) {
	    call printf ("Image: %s\n")
		call pargstr (MS_IMAGE(ms))
	    call printf ("Keyword:  %s\n")
		call pargstr (keyword)
	    call printf ("%8s %8s %8s\n")
		call pargstr ("Line")
		call pargstr ("Spectrum")
		call pargstr (NAME(ms, ms_id))
	}

	# For each sample line get the parameter values for the selected
	# parameter and list those for the selected spectra.
	do i = 1, nsamples {
	    sample = Memi[samples + i - 1]

	    call msgparam (ms, ms_id, sample)

	    spectrum = 0
	    while (get_next_number (spectra, spectrum) != EOF) {
		call printf ("%8d %8d %8.3g\n")
		    call pargi (LINE(ms, sample))
		    call pargi (spectrum)
		    call pargr (PARAMETER(ms, ms_id, spectrum))
	    }
	}

	call sfree (sp)
end


# FIT_LIST -- Print MULTISPEC fit.
#
# This procedure does CLIO.

procedure fit_list (ms, ms_id, keyword, titles)

pointer	ms					# MULTISPEC data structure
int	ms_id					# MULTISPEC parameter id
char	keyword[ARB]				# List keyword
bool	titles					# Print header titles?

int	lines[3, MAX_RANGES]
int	spectra[3, MAX_RANGES]

int	i, line, spectrum

real	cveval()
int	clgranges(), get_next_number()

begin
	if (MS_NSPECTRA(ms) == 0)
	    return

	# Get the image lines at which to evaluate the function and
	# the spectra to be listed.

	i = clgranges ("lines", 1, MS_LEN(ms, 2), lines, MAX_RANGES)
	i = clgranges ("spectra", 1, MS_NSPECTRA(ms), spectra, MAX_RANGES)

	# Get the fits.
	call msgfits (ms, ms_id)

	# Print header titles if needed.
	if (titles) {
	    call printf ("Image: %s\n")
		call pargstr (MS_IMAGE(ms))
	    call printf ("Keyword:  %s\n")
		call pargstr (keyword)
	    call printf ("%8s %8s %8s\n")
		call pargstr ("Line")
		call pargstr ("Spectrum")
		call pargstr (NAME(ms, ms_id))
	}

	# For each selected image line evalute the functions for the
	# selected spectra and print the values.

	line = 0
	while (get_next_number (lines, line) != EOF) {
	    spectrum = 0
	    while (get_next_number (spectra, spectrum) != EOF) {
		call printf ("%8d %8d %8.3g\n")
		    call pargi (line)
		    call pargi (spectrum)
		    call pargr (cveval (CV(ms, ms_id, spectrum), real (line)))
	    }
	}
end


# G5_LIST -- Print MULTISPEC model gauss5 profile parameters.
#
# This procedure does CLIO.

procedure g5_list (ms, keyword, titles)

pointer	ms					# MULTISPEC data structure
char	keyword[ARB]				# List keyword
bool	titles					# Print header titles?

int	lines[3, MAX_RANGES], spectra[3, MAX_RANGES]
int	i, nsamples, sample, spectrum
pointer	sp, samples

int	clgranges(), get_next_number(), get_sample_lines()

begin
	if ((MS_NSAMPLES(ms) == 0) || (MS_NSPECTRA(ms) == 0))
	    return

	# Get desired image lines and spectra to be listed.
	i = clgranges ("lines", 1, MS_LEN(ms, 2), lines, MAX_RANGES)
	i = clgranges ("spectra", 1, MS_NSPECTRA(ms), spectra, MAX_RANGES)

	# Convert image lines to sample lines.
	call smark (sp)
	call salloc (samples, MS_NSAMPLES(ms), TY_INT)
	nsamples = get_sample_lines (ms, lines, Memi[samples])

	# Print header titles if needed.
	if (titles) {
	    call printf ("Image: %s\n")
		call pargstr (MS_IMAGE(ms))
	    call printf ("Keyword:  %s\n")
		call pargstr (keyword)
	    call printf ("%8s %8s %8s %8s %8s %8s %8s\n")
		call pargstr ("Line")
		call pargstr ("Spectrum")
		call pargstr (NAME (ms, X0))
		call pargstr (NAME (ms, I0))
		call pargstr (NAME (ms, S0))
		call pargstr (NAME (ms, S1))
		call pargstr (NAME (ms, S2))
	}

	# For each sample line get the GAUSS5 values and list for the
	# selected spectra.
	do i = 1, nsamples {
	    sample = Memi[samples + i - 1]

	    call msggauss5 (ms, sample)

	    spectrum = 0
	    while (get_next_number (spectra, spectrum) != EOF) {
		call printf ("%8d %8d %8.3g %8.3g %8.3g %8.3g %8.3g\n")
		    call pargi (LINE(ms, sample))
		    call pargi (spectrum)
		    call pargr (PARAMETER(ms, X0, spectrum))
		    call pargr (PARAMETER(ms, I0, spectrum))
		    call pargr (PARAMETER(ms, S0, spectrum))
		    call pargr (PARAMETER(ms, S1, spectrum))
		    call pargr (PARAMETER(ms, S2, spectrum))
	    }
	}

	call sfree (sp)
end