aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/imexamine/iemw.x
blob: 185cfbaabee46603cd7b3f037442c7fb00f597d4 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<imhdr.h>
include	<mwset.h>
include	"imexam.h"


# IE_MWINIT -- Initialize MWCS

procedure ie_mwinit (ie)

pointer	ie			# IMEXAM descriptor

int	i, j, wcsdim, mw_stati(), nowhite(), stridxs()
pointer	im, mw, ctlw, ctwl, mw_openim(), mw_sctran()
pointer	sp, axno, axval, str1, str2
bool	streq()
errchk	mw_openim, mw_sctran

begin
	im = IE_IM(ie)
	mw = IE_MW(ie)

	if (mw != NULL) {
	    call mw_close (mw)
	    IE_MW(ie) = mw
	}

	IE_XLABEL(ie) = EOS
	IE_YLABEL(ie) = EOS
	call clgstr ("xformat", IE_XFORMAT(ie), IE_SZFORMAT)
	call clgstr ("yformat", IE_YFORMAT(ie), IE_SZFORMAT)
	i = nowhite (IE_XFORMAT(ie), IE_XFORMAT(ie), IE_SZFORMAT)
	i = nowhite (IE_YFORMAT(ie), IE_YFORMAT(ie), IE_SZFORMAT)

	if (im == NULL || im == IE_DS(ie))
	    return

	call smark (sp)
	call salloc (axno, IM_MAXDIM, TY_INT)
	call salloc (axval, IM_MAXDIM, TY_INT)
	call salloc (str1, SZ_LINE, TY_CHAR)
	call salloc (str2, SZ_LINE, TY_CHAR)

	mw = mw_openim (im)
	call mw_seti (mw, MW_USEAXMAP, NO)
	wcsdim = mw_stati (mw, MW_NDIM)
	call mw_gaxmap (mw, Memi[axno], Memi[axval], wcsdim)
	IE_P1(ie) = 1
	IE_P2(ie) = 2
	do i = 1, wcsdim {
	    j = Memi[axno+i-1]
	    if (j == 0)
		IE_IN(ie,i) = 1
	    else if (j == 1)
		IE_P1(ie) = i
	    else if (j == 2)
		IE_P2(ie) = i
	}
	ctlw = mw_sctran (mw, "logical", IE_WCSNAME(ie), 0)
	ctwl = mw_sctran (mw, IE_WCSNAME(ie), "logical", 0)

	# Set coordinate labels and formats
	i = IE_P1(ie)
	j = IE_P2(ie)
	if (streq (IE_WCSNAME(ie), "logical")) {
	    call strcpy ("Column (pixels)", IE_XLABEL(ie), IE_SZFNAME)
	    call strcpy ("Line (pixels)", IE_YLABEL(ie), IE_SZFNAME)
	} else if (streq (IE_WCSNAME(ie), "physical")) {
	    if (i == 1)
		call strcpy ("Column (pixels)", IE_XLABEL(ie), IE_SZFNAME)
	    else if (i == 2)
		call strcpy ("Line (pixels)", IE_XLABEL(ie), IE_SZFNAME)
	    else
		call strcpy ("Pixels", IE_XLABEL(ie), IE_SZFNAME)
	    if (j == 1)
		call strcpy ("Column (pixels)", IE_YLABEL(ie), IE_SZFNAME)
	    else if (j == 2)
		call strcpy ("Line (pixels)", IE_YLABEL(ie), IE_SZFNAME)
	    else
		call strcpy ("Pixels", IE_YLABEL(ie), IE_SZFNAME)
	} else {
	    ifnoerr (call mw_gwattrs (mw, i, "label", Memc[str1], SZ_LINE)) {
		ifnoerr (call mw_gwattrs (mw, i, "units", Memc[str2],SZ_LINE)) {
		    call sprintf (IE_XLABEL(ie), IE_SZFNAME, "%s (%s)")
			call pargstr (Memc[str1])
			call pargstr (Memc[str2])
		} else {
		    call sprintf (IE_XLABEL(ie), IE_SZFNAME, "%s")
			call pargstr (Memc[str1])
		}
	    }
	    if (IE_XFORMAT(ie) != '%')
		ifnoerr (call mw_gwattrs (mw, i, "format", Memc[str1], SZ_LINE))
		    call strcpy (Memc[str1], IE_XFORMAT(ie), IE_SZFORMAT)

	    ifnoerr (call mw_gwattrs (mw, j, "label", Memc[str1], SZ_LINE)) {
		ifnoerr (call mw_gwattrs (mw, j, "units", Memc[str2],SZ_LINE)) {
		    call sprintf (IE_YLABEL(ie), IE_SZFNAME, "%s (%s)")
			call pargstr (Memc[str1])
			call pargstr (Memc[str2])
		} else {
		    call sprintf (IE_YLABEL(ie), IE_SZFNAME, "%s")
			call pargstr (Memc[str1])
		}
	    }
	    if (IE_YFORMAT(ie) != '%')
		ifnoerr (call mw_gwattrs (mw, j, "format", Memc[str1], SZ_LINE))
		    call strcpy (Memc[str1], IE_YFORMAT(ie), IE_SZFORMAT)

	    # Check for equitorial coordinate and reversed formats.
	    ifnoerr (call mw_gwattrs (mw, i, "axtype", Memc[str1], SZ_LINE))
		if ((streq(Memc[str1],"ra")&&stridxs("hm",IE_XFORMAT(ie))>0) ||
		    (streq(Memc[str1],"dec")&&stridxs("HM",IE_XFORMAT(ie))>0)) {
		    call strcpy (IE_XFORMAT(ie), Memc[str1], IE_SZFORMAT)
		    call strcpy (IE_YFORMAT(ie), IE_XFORMAT(ie),IE_SZFORMAT)
		    call strcpy (Memc[str1], IE_YFORMAT(ie), IE_SZFORMAT)
		}
	}

	IE_MW(ie) = mw
	IE_CTLW(ie) = ctlw
	IE_CTWL(ie) = ctwl
	IE_WCSDIM(ie) = wcsdim

	call sfree (sp)
end


# IE_MWCTRAN -- Evaluate MWCS coordinate

procedure  ie_mwctran (ie, xin, yin, xout, yout) 

pointer	ie			# IMEXAM descriptor
real	xin,  yin		# Input coordinate
real	xout, yout		# Output coordinate

begin
	if (IE_MW(ie) == NULL) {
	    xout = xin
	    yout = yin
	    return
	}

	IE_IN(ie,IE_P1(ie)) = xin
	IE_IN(ie,IE_P2(ie)) = yin
	call mw_ctranr (IE_CTLW(ie), IE_IN(ie,1), IE_OUT(ie,1), IE_WCSDIM(ie))
	xout = IE_OUT(ie,IE_P1(ie))
	yout = IE_OUT(ie,IE_P2(ie))
end


# IE_IMWCTRAN -- Evaluate inverse MWCS coordinate

procedure  ie_imwctran (ie, xin, yin, xout, yout) 

pointer	ie			# IMEXAM descriptor
real	xin,  yin		# Input coordinate
real	xout, yout		# Output coordinate

begin
	if (IE_MW(ie) == NULL) {
	    xout = xin
	    yout = yin
	    return
	}

	IE_OUT(ie,IE_P1(ie)) = xin
	IE_OUT(ie,IE_P2(ie)) = yin
	call mw_ctranr (IE_CTWL(ie), IE_OUT(ie,1), IE_IN(ie,1), IE_WCSDIM(ie))
	xout = IE_IN(ie,IE_P1(ie))
	yout = IE_IN(ie,IE_P2(ie))
end


# IE_IFORMATR -- Determine the inverse formatted real value
# This temporary routine is used to account for scaling of the H and M formats.

real procedure ie_iformatr (value, format)

real	value			# Value to be inverse formated
char	format[ARB]		# Format

int	strldxs()

begin
	if (!IS_INDEF(value) && strldxs ("HM", format) > 0)
	    return (value * 15.)
	else
	    return (value)
end