aboutsummaryrefslogtreecommitdiff
path: root/noao/imred/quadred/src/quad/hdrmap.x
blob: ebcb253eb82794463803c18062283ad8390cbd57 (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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
include	<error.h>
include	<syserr.h>

.help hdrmap
.nf-----------------------------------------------------------------------------
HDRMAP -- Map translation between task parameters and image header parameters.

In order for tasks to be partially independent of the image header
parameter names used by different instruments and observatories a
translation is made between task parameters and image header
parameters.  This translation is given in a file consisting of the task
parameter name, the image header parameter name, and an optional
default value.  This file is turned into a symbol table.  If the
translation file is not found a null pointer is returned.  The package will
then use the task parameter names directly.  Also if there is no
translation given in the file for a particular parameter it is passed
on directly.  If a parameter is not in the image header then the symbol
table default value, if given, is returned.  This package is layered on
the IMIO header package.

	        hdmopen (fname)
		hdmclose ()
		hdmwrite (fname, mode)
		hdmname (parameter, str, max_char)
		hdmgdef (parameter, str, max_char)
		hdmpdef (parameter, str, max_char)
	  y/n = hdmaccf (im, parameter)
		hdmgstr (im, parameter, str, max_char)
	 ival = hdmgeti (im, parameter)
	 rval = hdmgetr (im, parameter)
		hdmpstr (im, parameter, str)
		hdmputi (im, parameter, value)
		hdmputr (im, parameter, value)
		hdmgstp (stp)
		hdmpstp (stp)
		hdmdelf (im, parameter)
		hdmparm (name, parameter, max_char)

hdmopen  -- Open the translation file and map it into a symbol table pointer.
hdmclose -- Close the symbol table pointer.
hdmwrite -- Write out translation file.
hdmname  -- Return the image header parameter name.
hdmpname -- Put the image header parameter name.
hdmgdef  -- Get the default value as a string (null if none).
hdmpdef  -- Put the default value as a string.
hdmaccf  -- Return whether the image header parameter exists (regardless of
	    whether there is a default value).
hdmgstr  -- Get a string valued parameter.  Return default value if not in the
	    image header.  Return null string if no default or image value.
hdmgeti  -- Get an integer valued parameter.  Return default value if not in
	    the image header and error condition if no default or image value.
hdmgetr  -- Get a real valued parameter.  Return default value if not in
	    the image header or error condition if no default or image value.
hdmpstr  -- Put a string valued parameter in the image header.
hdmputi  -- Put an integer valued parameter in the image header.
hdmputr  -- Put a real valued parameter in the image header.
hdmgstp  -- Get the symbol table pointer to save it while another map is used.
hdmpstp  -- Put the symbol table pointer to restore a map.
hdmdelf  -- Delete a field.
hdmparm  -- Return the parameter name corresponding to an image header name.
.endhelp -----------------------------------------------------------------------

# Symbol table definitions.
define	LEN_INDEX	32		# Length of symtab index
define	LEN_STAB	1024		# Length of symtab string buffer
define	SZ_SBUF		128		# Size of symtab string buffer

define	SZ_NAME		79		# Size of translation symbol name
define	SZ_DEFAULT	79		# Size of default string
define	SYMLEN		80		# Length of symbol structure

# Symbol table structure
define	NAME		Memc[P2C($1)]		# Translation name for symbol
define	DEFAULT		Memc[P2C($1+40)]	# Default value of parameter


# HDMOPEN -- Open the translation file and map it into a symbol table pointer.

procedure hdmopen (fname)

char	fname[ARB]		# Image header map file

int	fd, open(), fscan(), nscan(), errcode()
pointer	sp, parameter, sym, stopen(), stenter()
include	"hdrmap.com"

begin
	# Create an empty symbol table.
	stp = stopen (fname, LEN_INDEX, LEN_STAB, SZ_SBUF)

	# Return if file not found.
	iferr (fd = open (fname, READ_ONLY, TEXT_FILE)) {
	    if (errcode () != SYS_FNOFNAME)
		call erract (EA_WARN)
	    return
	}

	call smark (sp)
	call salloc (parameter, SZ_NAME, TY_CHAR)

	# Read the file an enter the translations in the symbol table.
	while (fscan(fd) != EOF) {
	    call gargwrd (Memc[parameter], SZ_NAME)
	    if ((nscan() == 0) || (Memc[parameter] == '#'))
		next
	    sym = stenter (stp, Memc[parameter], SYMLEN)
	    call gargwrd (NAME(sym), SZ_NAME)
	    call gargwrd (DEFAULT(sym), SZ_DEFAULT)
	}

	call close (fd)
	call sfree (sp)
end


# HDMCLOSE -- Close the symbol table pointer.

procedure hdmclose ()

include	"hdrmap.com"

begin
	if (stp != NULL)
	    call stclose (stp)
end


# HDMWRITE -- Write out translation file.

procedure hdmwrite (fname, mode)

char	fname[ARB]		# Image header map file
int	mode			# Access mode (APPEND, NEW_FILE)

int	fd, open(), stridxs()
pointer	sym, sthead(), stnext(), stname()
errchk	open
include	"hdrmap.com"

begin
	# If there is no symbol table do nothing.
	if (stp == NULL)
	    return

	fd = open (fname, mode, TEXT_FILE)

	sym = sthead (stp)
	for (sym = sthead (stp); sym != NULL; sym = stnext (stp, sym)) {
	    if (stridxs (" 	", Memc[stname (stp, sym)]) > 0)
		call fprintf (fd, "'%s'%30t")
	    else
		call fprintf (fd, "%s%30t")
	    call pargstr (Memc[stname (stp, sym)])
	    if (stridxs (" 	", NAME(sym)) > 0)
		call fprintf (fd, " '%s'%10t")
	    else
		call fprintf (fd, " %s%10t")
	    call pargstr (NAME(sym))
	    if (DEFAULT(sym) != EOS) {
		if (stridxs (" 	", DEFAULT(sym)) > 0)
		    call fprintf (fd, " '%s'")
		else
		    call fprintf (fd, " %s")
		call pargstr (DEFAULT(sym))
	    }
	    call fprintf (fd, "\n")
	}

	call close (fd)
end


# HDMNAME -- Return the image header parameter name

procedure hdmname (parameter, str, max_char)

char	parameter[ARB]		# Parameter name
char	str[max_char]		# String containing mapped parameter name
int	max_char		# Maximum characters in string

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    call strcpy (NAME(sym), str, max_char)
	else
	    call strcpy (parameter, str, max_char)
end


# HDMPNAME -- Put the image header parameter name

procedure hdmpname (parameter, str)

char	parameter[ARB]		# Parameter name
char	str[ARB]		# String containing mapped parameter name

pointer	sym, stfind(), stenter()
include	"hdrmap.com"

begin
	if (stp == NULL)
	    return

	sym = stfind (stp, parameter)
	if (sym == NULL) {
	    sym = stenter (stp, parameter, SYMLEN)
	    DEFAULT(sym) = EOS
	}

	call strcpy (str, NAME(sym), SZ_NAME)
end


# HDMGDEF -- Get the default value as a string (null string if none).

procedure hdmgdef (parameter, str, max_char)

char	parameter[ARB]		# Parameter name
char	str[max_char]		# String containing default value
int	max_char		# Maximum characters in string

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    call strcpy (DEFAULT(sym), str, max_char)
	else
	    str[1] = EOS
end


# HDMPDEF -- PUt the default value as a string.

procedure hdmpdef (parameter, str)

char	parameter[ARB]		# Parameter name
char	str[ARB]		# String containing default value

pointer	sym, stfind(), stenter()
include	"hdrmap.com"

begin
	if (stp == NULL)
	    return

	sym = stfind (stp, parameter)
	if (sym == NULL) {
	    sym = stenter (stp, parameter, SYMLEN)
	    call strcpy (parameter, NAME(sym), SZ_NAME)
	}

	call strcpy (str, DEFAULT(sym), SZ_DEFAULT)
end


# HDMACCF -- Return whether the image header parameter exists (regardless of
# whether there is a default value).

int procedure hdmaccf (im, parameter)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name

int	imaccf()
pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    return (imaccf (im, NAME(sym)))
	else
	    return (imaccf (im, parameter))
end


# HDMGSTR -- Get a string valued parameter.  Return default value if not in
# the image header.  Return null string if no default or image value.

procedure hdmgstr (im, parameter, str, max_char)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name
char	str[max_char]		# String value to return
int	max_char		# Maximum characters in returned string

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL) {
	    iferr (call imgstr (im, NAME(sym), str, max_char))
		call strcpy (DEFAULT(sym), str, max_char)
	} else {
	    iferr (call imgstr (im, parameter, str, max_char))
		str[1] = EOS
	}
end


# HDMGETR -- Get a real valued parameter.  Return default value if not in
# the image header.  Return error condition if no default or image value.

real procedure hdmgetr (im, parameter)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name

int	ip, ctor()
real	value, imgetr()
pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL) {
	    iferr (value = imgetr (im, NAME(sym))) {
		ip = 1
		if (ctor (DEFAULT(sym), ip, value) == 0)
		    call error (0, "HDMGETR: No value found")
	    }
	} else
	    value = imgetr (im, parameter)

	return (value)
end


# HDMGETI -- Get an integer valued parameter.  Return default value if not in
# the image header.  Return error condition if no default or image value.

int procedure hdmgeti (im, parameter)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name

int	ip, ctoi()
int	value, imgeti()
pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL) {
	    iferr (value = imgeti (im, NAME(sym))) {
		ip = 1
		if (ctoi (DEFAULT(sym), ip, value) == 0)
		    call error (0, "HDMGETI: No value found")
	    }
	} else
	    value = imgeti (im, parameter)

	return (value)
end


# HDMPSTR -- Put a string valued parameter in the image header.

procedure hdmpstr (im, parameter, str)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name
char	str[ARB]		# String value

int	imaccf(), imgftype()
pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL) {
	    if (imaccf (im, NAME(sym)) == YES)
	        if (imgftype (im, NAME(sym)) != TY_CHAR)
		    call imdelf (im, NAME(sym))
	    call imastr (im, NAME(sym), str)
	} else {
	    if (imaccf (im, parameter) == YES)
	        if (imgftype (im, parameter) != TY_CHAR)
		    call imdelf (im, parameter)
	    call imastr (im, parameter, str)
	}
end


# HDMPUTI -- Put an integer valued parameter in the image header.

procedure hdmputi (im, parameter, value)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name
int	value			# Integer value to put

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    call imaddi (im, NAME(sym), value)
	else
	    call imaddi (im, parameter, value)
end


# HDMPUTR -- Put a real valued parameter in the image header.

procedure hdmputr (im, parameter, value)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name
real	value			# Real value to put

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    call imaddr (im, NAME(sym), value)
	else
	    call imaddr (im, parameter, value)
end


# HDMGSTP -- Get the symbol table pointer to save a translation map.
# The symbol table is restored with HDMPSTP.

procedure hdmgstp (ptr)

pointer	ptr		# Symbol table pointer to return

include	"hdrmap.com"

begin
	ptr = stp
end


# HDMPSTP -- Put a symbol table pointer to restore a header map.
# The symbol table is optained with HDMGSTP.

procedure hdmpstp (ptr)

pointer	ptr		# Symbol table pointer to restore

include	"hdrmap.com"

begin
	stp = ptr
end


# HDMDELF -- Delete a field.  It is an error if the field does not exist.

procedure hdmdelf (im, parameter)

pointer	im			# IMIO pointer
char	parameter[ARB]		# Parameter name

pointer	sym, stfind()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = stfind (stp, parameter)
	else
	    sym = NULL

	if (sym != NULL)
	    call imdelf (im, NAME(sym))
	else
	    call imdelf (im, parameter)
end


# HDMPARAM -- Get parameter given the image header name.

procedure hdmparam (name, parameter, max_char)

char	name[ARB]		# Image header name
char	parameter[max_char]	# Parameter
int	max_char		# Maximum size of parameter string

bool	streq()
pointer	sym, sthead(), stname(), stnext()
include	"hdrmap.com"

begin
	if (stp != NULL)
	    sym = sthead (stp)
	else
	    sym = NULL

	while (sym != NULL) {
	    if (streq (NAME(sym), name)) {
		call strcpy (Memc[stname(stp, sym)], parameter, max_char)
		return
	    }
	    sym = stnext (stp, sym)
	}
	call strcpy (name, parameter, max_char)
end