aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/iki/fxf/fxfencode.x
blob: ea2e83ddf0076243ee723a801b68d3a7aa4049a1 (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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 
include <time.h>
include "fxf.h"

# FXFENCODE.X -- Routines to encode a keyword, its value and a comment into
# a FITS card.
#
#	fxf_encode_axis (root, keyword, axisno)
#	fxf_encode_date (ctime, datestr, szdate, format, cutover)
#
#	    fxf_encodeb (keyword, param, card, comment)
#	    fxf_encodei (keyword, param, card, comment)
#	    fxf_encodel (keyword, param, card, comment)
#	    fxf_encoder (keyword, param, card, comment, precision)
#	    fxf_encoded (keyword, param, card, comment, precision)
#	    fxf_encodec (keyword, param, maxch, card, comment)
#
#	       fxf_akwc (keyword, value, len, comment, pn)
#	       fxf_akwb (keyword, value, comment, pn)
#	       fxf_akwi (keyword, value, comment, pn)
#	       fxf_akwr (keyword, value, comment, precision, pn)
#	       fxf_akwd (keyword, value, comment, precision, pn)
#
# Encode_axis adds an axis number to a keyword ("rootXXX").  Encode_date
# encodes the current date as a string in the form "dd/mm/yy".


# FXF_ENCODEB -- Encode a boolean parameter into a FITS card.

procedure fxf_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 / %-47.47s")
	    call pargstr (keyword)
	    call pargc (truth)
	    call pargstr (comment)
end


# FXF_ENCODEI -- Encode an integer parameter into a FITS card.

procedure fxf_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 / %-47.47s")
	    call pargstr (keyword)
	    call pargi (param)
	    call pargstr (comment)
end


# FXF_ENCODEL -- Encode a long parameter into a FITS card.

procedure fxf_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 / %-47.47s")
	    call pargstr (keyword)
	    call pargl (param)
	    call pargstr (comment)
end


# FXF_ENCODER -- Encode a real parameter into a FITS card.

procedure fxf_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 / %-47.47s")
	    call pargstr (keyword)
	    call pargi (precision)
	    call pargr (param)
	    call pargstr (comment)
end


# FXF_ENCODED -- Encode a double parameter into a FITS card.

procedure fxf_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 / %-47.47s")
	    call pargstr (keyword)
	    call pargi (precision)
	    call pargd (param)
	    call pargstr (comment)
end


# FXF_ENCODE_AXIS -- Add the axis number to axis dependent keywords.

procedure fxf_encode_axis (root, keyword, axisno)

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

int	len, strlen()

begin
	call strcpy (root, keyword, SZ_KEYWORD)
	len = strlen (keyword)
	call sprintf (keyword, SZ_KEYWORD, "%*.*s%d")
	    call pargi (-len)
	    call pargi (len)
	    call pargstr (root)
	    call pargi (axisno)
end


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

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

char	keyword[LEN_CARD]	# FITS keyword
char	param[LEN_CARD]		# FITS string parameter
int	maxch			# maximum chars in value string
char	card[LEN_CARD+1]	# FITS card image
char	comment[LEN_CARD]	# comment string

int	nblanks, maxchar, slashp

begin
	maxchar = max(8, min (maxch, LEN_OBJECT))
	slashp = 32 
	nblanks = LEN_CARD - (slashp + 1)
	if (maxchar >= 19) {
	   slashp = 1
	   nblanks = max (LEN_OBJECT - maxchar - slashp+3, 1)
	}

	call sprintf (card, LEN_CARD, "%-8.8s= '%*.*s' %*t/ %*.*s")
	    call pargstr (keyword)
	    call pargi (-maxchar)
	    call pargi (maxchar)
	    call pargstr (param)
	    call pargi (slashp)
	    call pargi (-nblanks)
	    call pargi (nblanks)
	    call pargstr (comment)
end


# FXF_ENCODE_DATE -- Encode the current date as a string value.
#
# New Y2K format:	yyyy-mm-ddThh:mm:sec
# Old FITS format:	dd/mm/yy
# Old TLM format:	hh:mm:ss (dd/mm/yyyy)
#
# We still write the old format for dates 1999 or less.

procedure fxf_encode_date (ctime, datestr, maxch, format, cutover)

long	ctime			#I time value to be encoded
char	datestr[ARB]		#O string containing the date
int	maxch			#I number of chars in the date string
char	format[ARB]		#I desired date format for old dates
int	cutover			#I write new format for years >= cutover

int	tm[LEN_TMSTRUCT], nchars
int	dtm_encode_hms()
long	lsttogmt()
bool	streq()

begin
	# Find out what year it is.
	call brktime (ctime, tm)

	# Encode in ISO format for years >= cutover year.

	if (TM_YEAR(tm) >= cutover) {
	    # ISO format is used for all new date stamps.
	    call brktime (lsttogmt(ctime), tm)
	    nchars = dtm_encode_hms (datestr, maxch,
		TM_YEAR(tm), TM_MONTH(tm), TM_MDAY(tm),
		TM_HOUR(tm), TM_MIN(tm), double(TM_SEC(tm)), 0, 0)

	} else if (streq (format, "TLM")) {
	    # TLM format is for old-format DATE-TLM keywords.
	    call sprintf (datestr, maxch, "%02d:%02d:%02d (%02d/%02d/%d)")
		call pargi (TM_HOUR(tm))
		call pargi (TM_MIN(tm))
		call pargi (TM_SEC(tm))
		call pargi (TM_MDAY(tm))
		call pargi (TM_MONTH(tm))
		call pargi (TM_YEAR(tm))

	} else {
	    # The default otherwise is the old FITS format.
	    call sprintf (datestr, maxch, "%02d/%02d/%02d")
		call pargi (TM_MDAY(tm))
		call pargi (TM_MONTH(tm))
		call pargi (mod(TM_YEAR(tm),100))

	}
end


# FXF_AKWC -- Encode keyword, value and comment into a FITS card and
# append it to a buffer pointed by pn.
 
procedure fxf_akwc (keyword, value, len, comment, pn)

char	keyword[SZ_KEYWORD]	# keyword name
char	value[ARB]		# keyword value
int	len			# length of value
char	comment[ARB]		# comment
pointer pn			# pointer to a char area
char	card[LEN_CARD]

begin
	call fxf_encodec (keyword, value, len, card, comment)
	call amovc (card, Memc[pn], LEN_CARD)
	pn = pn + LEN_CARD
end


# FXF_AKWB -- Encode keyword, value and comment into a FITS card and
# append it to a buffer pointed by pn.
 
procedure fxf_akwb (keyword, value, comment, pn)

char	keyword[SZ_KEYWORD]	# I keyword name
int	value			# I Keyword value (YES, NO)
char	comment[ARB]		# I Comment
pointer pn			# I/O Pointer to a char area

pointer sp, pc

begin
	call smark (sp)
	call salloc (pc, LEN_CARD, TY_CHAR)

	call fxf_encodeb (keyword, value, Memc[pc], comment)
	call amovc (Memc[pc], Memc[pn], LEN_CARD)
	pn = pn + LEN_CARD

	call sfree (sp)
end


# FXF_AKWI -- Encode keyword, value and comment into a FITS card and
# append it to a buffer pointed by pn.
 
procedure fxf_akwi (keyword, value, comment, pn)

char	keyword[SZ_KEYWORD]	# I keyword name
int	value			# I Keyword value 
char	comment[ARB]		# I Comment
pointer pn			# I/O Pointer to a char area

pointer sp, pc

begin
	call smark (sp)
	call salloc (pc, LEN_CARD, TY_CHAR)

	call fxf_encodei (keyword, value, Memc[pc], comment)
	call amovc (Memc[pc], Memc[pn], LEN_CARD)
	pn = pn + LEN_CARD

	call sfree (sp)
end


# FXF_AKWR -- Encode keyword, value and comment into a FITS card and
# append it to a buffer pointed by pn.
 
procedure fxf_akwr (keyword, value, comment, precision, pn)

char	keyword[SZ_KEYWORD]	# I keyword name
real	value			# I Keyword value 
char	comment[ARB]		# I Comment
int	precision
pointer pn			# I/O Pointer to a char area

pointer sp, pc

begin
	call smark (sp)
	call salloc (pc, LEN_CARD, TY_CHAR)

	call fxf_encoder (keyword, value, Memc[pc], comment, precision)
	call amovc (Memc[pc], Memc[pn], LEN_CARD)
	pn = pn + LEN_CARD

	call sfree (sp)
end


# FXF_AKWD -- Encode keyword, value and comment into a FITS card and
# append it to a buffer pointed by pn.
 
procedure fxf_akwd (keyword, value, comment, precision, pn)

char	keyword[SZ_KEYWORD]	# I keyword name
double	value			# I Keyword value 
char	comment[ARB]		# I Comment
int	precision
pointer pn			# I/O Pointer to a char area

pointer sp, pc

begin
	call smark (sp)
	call salloc (pc, LEN_CARD, TY_CHAR)

	call fxf_encoded (keyword, value, Memc[pc], comment, precision)
	call amovc (Memc[pc], Memc[pn], LEN_CARD)
	pn = pn + LEN_CARD

	call sfree (sp)
end