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
|
# MK_REMOVE -- Check the deletions for uniqueness and delete unwanted objects
# from the coordinates file.
procedure mk_remove (coords, deletions, cl, dl, ndelete)
char coords[ARB] # coordinate file name
char deletions[ARB] # deletions file name
int cl # coordinate file descriptor
int dl # deletions file descriptor
int ndelete # number of deletions
int i, ndel, nobj, obj, tcl, tdl, stat
pointer sp, id, tclname, tdlname, line
real xval, yval
int fscan(), nscan(), open(), getline()
begin
call smark (sp)
call salloc (id, ndelete, TY_INT)
call salloc (tclname, SZ_FNAME, TY_CHAR)
call salloc (tdlname, SZ_FNAME, TY_CHAR)
call salloc (line, SZ_LINE, TY_CHAR)
# Rewind both files to the beginning.
call seek (cl, BOF)
call seek (dl, BOF)
# Read in the ids of objects to be deleted.
ndel = 0
while (fscan (dl) != EOF) {
call gargi (Memi[id+ndel])
ndel = ndel + 1
}
# Sort the id numbers.
call asrti (Memi[id], Memi[id], ndelete)
# Remove id numbers that are not unique.
ndel = 1
do i = 2, ndelete {
if (Memi[id+i-1] == Memi[id+i-2])
next
ndel = ndel + 1
Memi[id+ndel-1] = Memi[id+i-1]
}
# Open two temporary files.
call mktemp ("tcl", Memc[tclname], SZ_FNAME)
call mktemp ("tdl", Memc[tdlname], SZ_FNAME)
tcl = open (Memc[tclname], NEW_FILE, TEXT_FILE)
tdl = open (Memc[tdlname], NEW_FILE, TEXT_FILE)
nobj = 0
do i = 1, ndel {
obj = Memi[id+i-1]
repeat {
stat = getline (cl, Memc[line])
if (stat == EOF)
break
call sscan (Memc[line])
call gargr (xval)
call gargr (yval)
if (nscan () < 2) {
call putline (tcl, Memc[line])
next
}
nobj = nobj + 1
if (nobj < obj)
call putline (tcl, Memc[line])
else
call putline (tdl, Memc[line])
} until (nobj >= obj)
}
# Copy the remainder of the file.
while (getline (cl, Memc[line]) != EOF)
call putline (tcl, Memc[line])
# Cleanup the coords file.
call close (cl)
call close (tcl)
call delete (coords)
call rename (Memc[tclname], coords)
# Cleanup the delete file.
call close (dl)
call close (tdl)
call delete (deletions)
call rename (Memc[tdlname], deletions)
call sfree (sp)
end
|