File: getkeybuf.x

package info (click to toggle)
iraf-st4gem 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,316 kB
  • sloc: fortran: 4,161; ansic: 2,564; pascal: 1,092; lisp: 1,046; yacc: 969; makefile: 89; python: 18; sh: 7
file content (89 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download | duplicates (2)
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
include	<imhdr.h>
include "hdiff.h"

# GETKEYBUF -- Create a sorted buffer of keyword values

procedure getkeybuf (im, igroup, negate, keynames, buffer, index, nindex)

pointer	im		# i: Image descriptor
int	igroup		# i: Group number
bool	negate		# i: Include keywords NOT in the keyword list
char	keynames[ARB]	# i: List of keyword names
char	buffer[ARB]	# o: String buffer to hold keyword records
int	index[ARB]	# o: Array of pointers to keyword records
int	nindex		# o: Number of keyword records
#--
bool	copy
int	ibuf, keylen
pointer sp, key, iua

string	excluded  "HISTORY,COMMENT"

int	word_match(), gf_gfind()

begin
	# Allocate dynamic memory to hold the keyword

	call smark (sp)
	call salloc (key, SZ_KEYWORD, TY_CHAR)

	ibuf = 1
	nindex = 0

	iua = IM_USERAREA(im)
	while (Memc[iua] != EOS) {

	    # Read keyword name and trim trailing blanks

	    call strcpy (Memc[iua], Memc[key], SZ_KEYWORD)
	    for (keylen = SZ_KEYWORD; keylen > 0; keylen = keylen - 1) {
		if (Memc[key+keylen-1] != ' ')
		    break
	    }
	    Memc[key+keylen] = EOS

	    # Check to see whether this keyword should be copied to the buffer

	    if (keylen == 0) {
		copy = false
	    } else if (negate) {
		copy = word_match (Memc[key], keynames) == 0 &&
		       word_match (Memc[key], excluded) == 0
	    } else {
		copy = word_match (Memc[key], keynames) > 0 &&
		       word_match (Memc[key], excluded) == 0
	    }

	    if (copy && igroup > 1)
		copy = gf_gfind (im, Memc[key]) > 0

	    # Copy record to output buffer

	    if (copy) {
		nindex = nindex + 1
		index[nindex] = ibuf
		while (Memc[iua] != '\n') {
		    buffer[ibuf] = Memc[iua]
		    ibuf = ibuf + 1
		    iua = iua + 1
		}
		buffer[ibuf] = EOS
		ibuf = ibuf + 1
		iua = iua + 1

	    # Otherwise, skip to next record

	    } else {

		while (Memc[iua] != '\n')
		    iua = iua + 1
		iua = iua + 1
	    }
	}

	# Sort the buffer array

	if (nindex > 1)
	    call strsrt (index, buffer, nindex)
	call sfree (sp)
end