File: t_pix2wl.x

package info (click to toggle)
iraf-rvsao 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 16,456 kB
  • sloc: ansic: 963; lisp: 651; fortran: 397; makefile: 27
file content (146 lines) | stat: -rw-r--r-- 3,369 bytes parent folder | download
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
# File rvsao/Util/t_pix2wl.x
# October 7, 2009
# By Doug Mink, SAO Telescope Data Center

include	<imhdr.h>
include	<smw.h>

define	LEN_USER_AREA	100000
define	SZ_FORMAT	8

# T_PIX2WL - Compute the wavelength for a specific pixel in a 
# one dimensional wavelength calibrated image

procedure t_pix2wl()

char	imname[SZ_PATHNAME]	# image name
char	objname[SZ_PATHNAME]	# object name
int	mext			# FITS image extension
int	mspec			# Number of spectrum to read from multispec file
int	mband			# Number of band to read from multispec file
pointer	im			# Image header structure
pointer	sh			# Spectrum header structure
pointer	pix			# pointer to pixel values
int	npts			# Number of pixels in spectrum
double	pixel			# Pixel for wavelength in angstroms
double	wl			# Wavelength at pixel in angstroms
int	world			# wavelength or pixel
char	waveform[SZ_FORMAT]
char	pixform[SZ_FORMAT]
double	p1, p2, w1, w2, dw, dindef
bool	debug, verbose, db
int	mode

double	clgetd()
int	clgeti()
bool	clgetb()
int	strlen()
double	wcs_p2w()


begin
	dindef = INDEFD

	call clgstr ("spectrum", imname, SZ_PATHNAME)
	if (strlen (imname) < 1) {
	    call printf ("PIX2WL returns the wavelength at a given pixel in a spectrum\n")
	    return
	    }
	mext = clgeti ("specext")
	mspec = clgeti ("specnum")
	mband = clgeti ("specband")
	world = 1

	pixel = clgetd ("pixel")

	verbose = FALSE
	verbose = clgetb ("verbose")
	debug = FALSE
	debug = clgetb ("debug")
	db = FALSE

	call strcpy ("%9.3f", waveform, SZ_FORMAT)
	call clgstr ("waveform", waveform, SZ_FORMAT)

	call strcpy ("%8.3f", pixform, SZ_FORMAT)
	call clgstr ("pixform", pixform, SZ_FORMAT)

	mode = READ_ONLY

	# Open the image
	call getimage (imname, mext, mspec, mband, pix, im, sh, npts, objname,
		       mode, world, db)
	if (im == ERR) {
	    if (debug)
		call printf ("PIX2WL: Cannot read %s\n")
		    call pargstr (imname)
	    return
	    }

	call wcs_set (sh)

# If pixel greater than 0, print wavelength at that pixel
	if (pixel > 0.0) {
	    wl = wcs_p2w (pixel)
	    call clputd ("wavelength", wl)
	    call clputd ("wave2", dindef)
	    if (verbose) {
		call printf (waveform)
		    call pargd (wl)
		call printf ("\n")
		}
	    if (debug) {
		p1 = pixel - 0.5d0
		w1 = wcs_p2w (p1)
		p2 = pixel + 0.5d0
		w2 = wcs_p2w (p2)
		dw = w2 - w1
		call printf ("%s: ")
		    call pargstr (imname)
		call printf (pixform)
		call pargd (pixel)
		    call printf (" -> ")
		call printf (waveform)
		    call pargd (wl)
		call printf (" (%.4f/pix)\n")
		    call pargd (dw)
		}
	    }

# If pixel less than or equal to 0, print wavelength range of spectrum
	else {
	    p1 = 0.5d0
	    w1 = wcs_p2w (p1)
	    call clputd ("wavelength", w1)
	    p2 = double (npts) + 0.5d0
	    w2 = wcs_p2w (p2)
	    call clputd ("wave2", w2)
	    if (verbose) {
		call printf (waveform)
		    call pargd (w1)
		call printf (" - ")
		call printf (waveform)
		    call pargd (w2)
		call printf ("\n")
		}
	    if (debug) {
		dw = (w2 - w1) / (p2 - p1 + 1.d0)
		call printf ("%s: ")
		    call pargstr (imname)
		call printf (waveform)
		    call pargd (w1)
		call printf ("-")
		call printf (waveform)
		    call pargd (w2)
		call printf (" (%d pixels, %.4f/pix)\n")
		    call pargi (npts)
		    call pargd (dw)
		}
	    }

	return
end

# Aug 12 2008	New task based on listspec

# Oct  7 2009	Change image file length from SZ_FNAME to SZ_PATHNAME