aboutsummaryrefslogtreecommitdiff
path: root/pkg/dataio/fits/fits_params.x
blob: 6911a925ead27555b6fde8a043aa1d7dba39166f (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <time.h>
include "wfits.h"

# WFT_ENCODEB -- Procedure to encode a boolean parameter into a FITS card.

procedure wft_encodeb (keyword, param, card, comment)

char	keyword[ARB]	# FITS keyword
int	param		# integer parameter equal to YES/NO
char	card[ARB]	# FITS card image
char	comment[ARB]	# FITS comment string

char	truth

begin
	if (param == YES)
	    truth = 'T'
	else
	    truth = 'F'

	call sprintf (card, LEN_CARD, "%-8.8s= %20c  /  %-45.45s")
	    call pargstr (keyword)
	    call pargc (truth)
	    call pargstr (comment)
end


# WFT_ENCODEI -- Procedure to encode an integer parameter into a FITS card.

procedure wft_encodei (keyword, param, card, comment)

char	keyword[ARB]	# FITS keyword
int	param		# integer parameter
char	card[ARB]	# FITS card image
char	comment[ARB]	# FITS comment string

begin
	call sprintf (card, LEN_CARD, "%-8.8s= %20d  /  %-45.45s")
	    call pargstr (keyword)
	    call pargi (param)
	    call pargstr (comment)
end


# WFT_ENCODEL -- Procedure to encode a long parameter into a FITS card.

procedure wft_encodel (keyword, param, card, comment)

char	keyword[ARB]		# FITS keyword
long	param			# long integer parameter
char	card[ARB]		# FITS card image
char	comment[ARB]		# FITS comment string

begin
	call sprintf (card, LEN_CARD, "%-8.8s= %20d  /  %-45.45s")
	    call pargstr (keyword)
	    call pargl (param)
	    call pargstr (comment)
end


# WFT_ENCODER -- Procedure to encode a real parameter into a FITS card.

procedure wft_encoder (keyword, param, card, comment, precision)

char	keyword[ARB]		# FITS keyword
real	param			# real parameter
char	card[ARB]		# FITS card image
char	comment[ARB]		# FITS comment card
int	precision		# precision of real

begin
	call sprintf (card, LEN_CARD, "%-8.8s= %20.*e  /  %-45.45s")
	    call pargstr (keyword)
	    call pargi (precision)
	    call pargr (param)
	    call pargstr (comment)
end


# WFT_ENCODED -- Procedure to encode a double parameter into a FITS card.

procedure wft_encoded (keyword, param, card, comment, precision)

char	keyword[ARB]		# FITS keyword
double	param			# double parameter
char	card[ARB]		# FITS card image
char	comment[ARB]		# FITS comment string
int	precision		# FITS precision

begin
	call sprintf (card, LEN_CARD, "%-8.8s= %20.*e  /  %-45.45s")
	    call pargstr (keyword)
	    call pargi (precision)
	    call pargd (param)
	    call pargstr (comment)
end


# WFT_ENCODE_AXIS -- Procedure to add the axis number to axis dependent
# keywords.

procedure wft_encode_axis (root, keyword, axisno)

char	root[ARB]		# FITS root keyword
char	keyword[ARB]		# FITS keyword
int	axisno			# FITS axis number

begin
	call strcpy (root, keyword, LEN_KEYWORD)
	call sprintf (keyword, LEN_KEYWORD, "%-5.5s%-3.3s")
	    call pargstr (root)
	    call pargi (axisno)
end


# WFT_ENCODEC -- Procedure to encode an IRAF string parameter into a FITS card.

procedure wft_encodec (keyword, param, maxch, card, comment)

char	keyword[ARB]	# FITS keyword
char	param[ARB]	# FITS string parameter
int	maxch		# maximum number of characters in string parameter
char	card[ARB]	# FITS card image
char	comment[ARB]	# comment string

char	strparam[LEN_ALIGN+2]
int	maxchar, nblanks

begin
	maxchar = min (maxch, LEN_OBJECT)
	if (maxchar <= LEN_ALIGN - 1) {
	    strparam[1] = '\''
	    call sprintf (strparam[2], maxchar, "%*.*s")
		call pargi (-maxchar)
		call pargi (maxchar)
		call pargstr (param)
	    strparam[maxchar+2] = '\''
	    strparam[maxchar+3] = EOS
            call sprintf (card, LEN_CARD, "%-8.8s= %-20.20s  /  %-45.45s")
	        call pargstr (keyword)
	        call pargstr (strparam)
	        call pargstr (comment)
	} else {
	    nblanks = LEN_OBJECT - maxchar
	    if (comment[1] == EOS)
                call sprintf (card, LEN_CARD, "%-8.8s= '%*.*s'     %*.*s")
	    else
                call sprintf (card, LEN_CARD, "%-8.8s= '%*.*s'  /  %*.*s")
	        call pargstr (keyword)
	        call pargi (-maxchar)
	        call pargi (maxchar)
	        call pargstr (param)
	        call pargi (-nblanks)
	        call pargi (nblanks)
	        call pargstr (comment)
	}
end


# WFT_ENCODE_BLANK -- Procedure to encode the FITS blank parameter. Necessary
# because the 32 bit blank value equals INDEFL.

procedure wft_encode_blank (keyword, blank_str, card, comment)

char	keyword[ARB]		# FITS keyword
char	blank_str[ARB]		# string containing values of FITS blank integer
char	card[ARB]		# FITS card image
char	comment[ARB]		# FITS comment string

begin
    call sprintf (card, LEN_CARD, "%-8.8s= %20.20s  /  %-45.45s")
	call pargstr (keyword)
	call pargstr (blank_str)
	call pargstr (comment)
end


# WFT_ENCODE_DATE -- Procedure to encode the date in the form dd-mm-yy.

procedure wft_encode_date (datestr, szdate)

char	datestr[ARB]	# string containing the date
int	szdate		# number of chars in the date string

long	ctime
int	time[LEN_TMSTRUCT]
long	clktime(), lsttogmt()

begin
	ctime = clktime (long (0))
	ctime = lsttogmt (ctime)
	call brktime (ctime, time)

	if (TM_YEAR(time) >= NEW_CENTURY) {
	    call sprintf (datestr, szdate, "%04d-%02d-%02dT%02d:%02d:%02d")
	        call pargi (TM_YEAR(time))
	        call pargi (TM_MONTH(time))
	        call pargi (TM_MDAY(time))
	        call pargi (TM_HOUR(time))
	        call pargi (TM_MIN(time))
	        call pargi (TM_SEC(time))
	} else {
	    call sprintf (datestr, szdate, "%02d-%02d-%02d")
	        call pargi (TM_MDAY(time))
	        call pargi (TM_MONTH(time))
	        call pargi (mod (TM_YEAR(time), CENTURY))
	}
end


# WFT_FITS_CARD --  Procedure to fetch a single line from a string parameter
# padding it to a maximum of maxcols characters and trimmimg the delim
# character.

procedure wft_fits_card (instr, ip, card, col_out, maxcols, delim)

char	instr[ARB]	# input string
int	ip		# input string pointer, updated at each call
char	card[ARB]	# FITS card image
int	col_out		# pointer to column in card
int	maxcols		# maximum columns in card
int	delim		# 1 character string delimiter

int	op

begin
	op = col_out

	# Copy string
	while (op <= maxcols && instr[ip] != EOS && instr[ip] != delim) {
	    card[op] = instr[ip]
	    ip = ip + 1
	    op = op + 1
	}

	# Fill remainder of card with blanks
	while (op <= maxcols ) {
	    card[op] = ' '
	    op = op + 1
	}

	if (instr[ip] == delim)
	    ip = ip + 1

end