File: t_wl2pix.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 (110 lines) | stat: -rw-r--r-- 2,513 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
# File rvsao/Util/t_wl2pix.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_WL2PIX - Compute the pixel for a specific wavelength in a 
# one dimensional wavelength calibrated image

procedure t_wl2pix()

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	wl			# Wavelength at pixel in angstroms
double	pixel			# Pixel at wavelength
int	world			# wavelength or pixel
int	mode
double	p1, p2, w1, w2, dw
char	waveform[SZ_FORMAT]
char	pixform[SZ_FORMAT]
bool	debug, verbose, db

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

begin


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

	wl = clgetd ("wavelength")

	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)
	pixel = wcs_w2p (wl)
	call clputd ("pixel", pixel)

	if (verbose) {
	    call printf (pixform)
		call pargd (pixel)
	    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 (waveform)
		call pargd (wl)
	    call printf (" -> ")
	    call printf (pixform)
		call pargd (pixel)
	    call printf (" (%.4f/pix)\n")
		call pargd (dw)
	    }

	return
end

# Aug 12 2008	New task based on listspec

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