aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbfhg.x
blob: 4799909a6d8361b25f4a36b48df8edfb1db0b2a9 (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
include <tbset.h>
include "tbtables.h"

# Get a parameter from a FITS table header.
#
# Phil Hodge,  6-Jul-1995  Subroutine created
# Phil Hodge, 14-Aug-1997  In tbfhgt, allocate local buffer.
# Phil Hodge,  5-Aug-1999  In tbfhgt, for history or comment, copy the
#		comment field to output, rather than the value field.

# tbfhgd -- get double-precision header parameter

procedure tbfhgd (tp, keyword, value)

pointer tp		# i: pointer to table descriptor
char	keyword[ARB]	# i: name of parameter to get
double	value		# o: value of parameter
#--
pointer sp
pointer sval		# for getting the value as a string
pointer comment		# for getting the comment
int	status		# zero is OK
int	ip, junk, ctod()
errchk	tbferr

begin
	call smark (sp)
	call salloc (sval, SZ_LINE, TY_CHAR)
	call salloc (comment, SZ_LINE, TY_CHAR)

	status = 0

	# Get the value as a string.
	call fsgkey (TB_FILE(tp), keyword, Memc[sval], Memc[comment], status)
	if (status != 0)
	    call tbferr (status)

	ip = 1
	if (Memc[sval] == '\'')
	    ip = 2				# skip over the quote
	else if (Memc[sval] == 'T')
	    Memc[sval] = '1'
	else if (Memc[sval] == 'F')
	    Memc[sval] = '0'

	value = INDEFD
	junk = ctod (Memc[sval], ip, value)

	call sfree (sp)
end

# tbfhgr -- get single-precision header parameter

procedure tbfhgr (tp, keyword, value)

pointer tp		# i: pointer to table descriptor
char	keyword[ARB]	# i: name of parameter to get
real	value		# o: value of parameter
#--
pointer sp
pointer sval		# for getting the value as a string
pointer comment		# for getting the comment
int	status		# zero is OK
int	ip, junk, ctor()
errchk	tbferr

begin
	call smark (sp)
	call salloc (sval, SZ_LINE, TY_CHAR)
	call salloc (comment, SZ_LINE, TY_CHAR)

	status = 0

	# Get the value as a string.
	call fsgkey (TB_FILE(tp), keyword, Memc[sval], Memc[comment], status)
	if (status != 0)
	    call tbferr (status)

	ip = 1
	if (Memc[sval] == '\'')
	    ip = 2				# skip over the quote
	else if (Memc[sval] == 'T')
	    Memc[sval] = '1'
	else if (Memc[sval] == 'F')
	    Memc[sval] = '0'

	value = INDEFR
	junk = ctor (Memc[sval], ip, value)

	call sfree (sp)
end

# tbfhgi -- get integer header parameter

procedure tbfhgi (tp, keyword, value)

pointer tp		# i: pointer to table descriptor
char	keyword[ARB]	# i: name of parameter to get
int	value		# o: value of parameter
#--
pointer sp
pointer sval		# for getting the value as a string
pointer comment		# for getting the comment
double	dval
int	status		# zero is OK
int	ip, junk, ctod()
errchk	tbferr

begin
	call smark (sp)
	call salloc (sval, SZ_LINE, TY_CHAR)
	call salloc (comment, SZ_LINE, TY_CHAR)

	status = 0

	# Get the value as a string.
	call fsgkey (TB_FILE(tp), keyword, Memc[sval], Memc[comment], status)
	if (status != 0)
	    call tbferr (status)

	ip = 1
	if (Memc[sval] == '\'')
	    ip = 2				# skip over the quote
	else if (Memc[sval] == 'T')
	    Memc[sval] = '1'
	else if (Memc[sval] == 'F')
	    Memc[sval] = '0'

	dval = INDEFD
	junk = ctod (Memc[sval], ip, dval)
	if (IS_INDEFD(dval))
	    value = INDEFI
	else
	    value = nint (dval)

	call sfree (sp)
end

# tbfhgb -- get Boolean header parameter
# If the header keyword is not T or F, then zero is interpreted as false,
# and any other numerical value is true.

procedure tbfhgb (tp, keyword, value)

pointer tp		# i: pointer to table descriptor
char	keyword[ARB]	# i: name of parameter to get
bool	value		# o: value of parameter
#--
pointer sp
pointer sval		# for getting the value as a string
pointer comment		# for getting the comment
double	dval
int	status		# zero is OK
int	ip, junk, ctod()
errchk	tbferr

begin
	call smark (sp)
	call salloc (sval, SZ_LINE, TY_CHAR)
	call salloc (comment, SZ_LINE, TY_CHAR)

	status = 0

	# Get the value as a string.
	call fsgkey (TB_FILE(tp), keyword, Memc[sval], Memc[comment], status)
	if (status != 0)
	    call tbferr (status)

	call strupr (Memc[sval])

	ip = 1
	if (Memc[sval] == '\'')
	    ip = 2				# skip over the quote

	if (Memc[sval+ip-1] == 'T') {
	    value = true
	    call sfree (sp)
	    return
	} else if (Memc[sval+ip-1] == 'F') {
	    value = false
	    call sfree (sp)
	    return
	}

	dval = INDEFD
	junk = ctod (Memc[sval], ip, dval)
	if (IS_INDEFD(dval))
	    value = false
	else if (nint (dval) == 0)
	    value = false
	else
	    value = true

	call sfree (sp)
end

# tbfhgt -- get text-string header parameter

procedure tbfhgt (tp, keyword, text, maxch)

pointer tp		# i: pointer to table descriptor
char	keyword[ARB]	# i: name of parameter to get
char	text[ARB]	# o: value of parameter
int	maxch		# i: maximum number of characters to get
#--
pointer sp
pointer temp		# for getting the value
pointer comment		# for getting the comment
int	i
int	status		# zero is OK
int	strlen()
bool	tbhisc()
errchk	tbferr

begin
	call smark (sp)
	call salloc (temp, max (maxch, SZ_FNAME), TY_CHAR)
	call salloc (comment, SZ_FNAME, TY_CHAR)

	status = 0

	call fsgkys (TB_FILE(tp), keyword, Memc[temp], Memc[comment], status)
	if (status != 0)
	    call tbferr (status)

	# For COMMENT and HISTORY keywords, FITSIO returns the value in
	# the comment argument rather than the value argument.
	if (tbhisc (keyword))
	    call strcpy (Memc[comment], Memc[temp], SZ_FNAME)

	# Trim trailing blanks.
	do i = strlen (Memc[temp]), 1, -1 {
	    if (Memc[temp+i-1] == ' ')
		Memc[temp+i-1] = EOS
	    else
		break
	}
	call strcpy (Memc[temp], text, maxch)

	call sfree (sp)
end