File: prhdiff.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 (203 lines) | stat: -rw-r--r-- 5,066 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
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
include <imio.h>
include "hdiff.h"

# PR_HDIFF -- Print differences between two header files
#
# This procedure compares two sorted lists of header keywords. A line is
# printed if a keyword is found in one list and not in the other, or the
# value of the two keywords differs. Since the two lists are sorted, a 
# standard merge algorithm can be used to find the differences.
#
# B.Simon	25-Apr-90	Original

procedure pr_hdiff (im1, im2, buffer1, index1, ndx1, buffer2, index2, ndx2)

pointer	im1		# i: First image descriptor
pointer	im2		# i: Second image descriptor
char	buffer1[ARB]	# i: First buffer of keyword records
int	index1[ARB]	# i: First array of keyword record indices
int	ndx1		# i: Number of records in first buffer
char	buffer2[ARB]	# i: Second buffer of keyword records
int	index2[ARB]	# i: Second array of keyword record indices
int	ndx2		# i: Number of records in second buffer
#--
bool	title
int	idx1, idx2, jdx1, jdx2, order

string	nullstring  ""

int	strncmp(), cmp_record()

begin
	title = true

	# Since it is the index array that is sorted, and not the string
	# buffer, two indices are needed to access the next record

	idx1 = 1
	idx2 = 1
	jdx1 = index1[idx1]
	jdx2 = index2[idx2]

	# Main phase of merge, when neither list of records is empty

	while (idx1 <= ndx1 && idx2 <= ndx2) {
	    order = strncmp (buffer1[jdx1], buffer2[jdx2], SZ_KEYWORD)
	    if (order < 0) {
		if (title) {
		    title = false
		    call pr_title (im1, im2)
		}
		call pr_record (buffer1[jdx1], nullstring)
		idx1 = idx1 + 1
		jdx1 = index1[idx1]
	    } else if (order > 0) {
		if (title) {
		    title = false
		    call pr_title (im1, im2)
		}
		call pr_record (nullstring, buffer2[jdx2])
		idx2 = idx2 + 1
		jdx2 = index2[idx2]
	    } else {
		if (cmp_record (buffer1[jdx1], buffer2[jdx2]) != 0) {
		    if (title) {
			title = false
			call pr_title (im1, im2)
			}
		    call pr_record (buffer1[jdx1], buffer2[jdx2])
		}
		idx1 = idx1 + 1
		jdx1 = index1[idx1]
		idx2 = idx2 + 1
		jdx2 = index2[idx2]		
	    }
	}

	# Print the tail of the longer list. At most, only one of
	# these while loops will be called

	while (idx1 <= ndx1) {
	    if (title) {
		title = false
		call pr_title (im1, im2)
	    }
	    call pr_record (buffer1[jdx1], nullstring)
	    idx1 = idx1 + 1
	    jdx1 = index1[idx1]
	}

	while (idx2 <= ndx2) {
	    if (title) {
		title = false
		call pr_title (im1, im2)
	    }
	    call pr_record (buffer2[jdx2], nullstring)
	    idx2 = idx2 + 1
	    jdx2 = index2[idx1]
	}

end

# PR_TITLE -- Print title containing image names

procedure pr_title (im1, im2)

pointer	im1		# i: First image descriptor
pointer im2		# i: Second image descriptor
#--
int	offset1, offset2
pointer	sp, file1, file2, temp, root1, root2

int	fnldir()

begin
	call smark (sp)
	call salloc (file1, SZ_FNAME, TY_CHAR)
	call salloc (file2, SZ_FNAME, TY_CHAR)
	call salloc (temp, SZ_FNAME, TY_CHAR)

	# Remove the directory name from the root, if present

	call imgcluster (IM_NAME(im1), Memc[file1], SZ_FNAME)
	offset1 = fnldir (Memc[file1], Memc[temp], SZ_FNAME)
	call strcpy (IM_NAME(im1), Memc[file1], SZ_FNAME)
	root1 = file1 + offset1

	call imgcluster (IM_NAME(im2), Memc[file2], SZ_FNAME)
	offset2 = fnldir (Memc[file2], Memc[temp], SZ_FNAME)
	call strcpy (IM_NAME(im2), Memc[file2], SZ_FNAME)
	root2 = file2 + offset2

	call printf ("#\n#%11t%-30s%-30s\n#\n")
	call pargstr (Memc[root1])
	call pargstr (Memc[root2])

	call sfree (sp)
end

# PR_RECORD -- Print the two records that differ

procedure pr_record (record1, record2)

char	record1[ARB]	# i: Keyword record from first image
char	record2[ARB]	# i: Keyword record from second image
#--
int	ic, nc
pointer	sp, keyword, value1, value2

int	ctowrd()

begin
	call smark (sp)
	call salloc (keyword, SZ_KEYWORD, TY_CHAR)
	call salloc (value1, SZ_VALUE, TY_CHAR)
	call salloc (value2, SZ_VALUE, TY_CHAR)

	# One or the other of the records may be a null string, 
	# indicating that this record was not present in the image.

	if (record1[1] != EOS) {
	    call strcpy (record1, Memc[keyword], SZ_KEYWORD)
	} else if (record2[1] != EOS) {
	    call strcpy (record2, Memc[keyword], SZ_KEYWORD)
	} else {
	    call error (1, "pr_record: keyword not found")
	}

	# Get the value field from the record and trim trailing blanks

	if (record1[1] == EOS) {
	    Memc[value1] = EOS
	} else {
	    ic = START_VALUE
	    nc = ctowrd (record1, ic, Memc[value1], SZ_VALUE)
	    for (ic = nc - 1; nc >= 0; ic = ic - 1) {
		if (Memc[value1+ic] != ' ')
		    break
	    }
	    Memc[value1+ic+1] = EOS
	}

	if (record2[1] == EOS) {
	    Memc[value2] = EOS
	} else {
	    ic = START_VALUE
	    nc = ctowrd (record2, ic, Memc[value2], SZ_VALUE)
	    for (ic = nc - 1; nc >= 0; ic = ic - 1) {
		if (Memc[value2+ic] != ' ')
		    break
	    }
	    Memc[value2+ic+1] = EOS
	}

	# Write a line containing the keyword names and the two values,
	# either of which may be a null string

	call printf ("%-10s%-30s%-30s\n")
	call pargstr (Memc[keyword])
	call pargstr (Memc[value1])
	call pargstr (Memc[value2])

	call sfree (sp)
end