aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/threed/tiimage/tmscan.x
blob: 31af8c025df48d1d710824b83ea465e945b0ca41 (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
include <error.h>
include <imhdr.h>
include <tbset.h>

#  TM_SCAN  --  Scan input image list and create column pointer array 
#               and table from information stored in image headers.
#
#
#
#
#  Revision history:
#  ----------------
#  30-Jan-97  -  Task created (I.Busko)
#  21-May-97  -  Changes from code review (IB)


procedure tm_scan (otp, ocp, ocpsize, nocp, imlist)

pointer	otp		# i:  output table pointer
pointer	ocp		# io: output table column pointer array
int	ocpsize		# i:  size of above array
int	nocp		# o:  actual number of columns in array
char	imlist[ARB]	# i:  input image list
#--
pointer	sp, im, list
pointer	imname, cn, cn1, cu, cf, duma
int	image, column, lendata, dumi, i
bool	match

errchk	tm_header

pointer	imtopen(), immap()
int	imtlen(), imtgetim()
bool	streq()

begin
	call smark (sp)
	call salloc (imname, SZ_PATHNAME, TY_CHAR)
	call salloc (cn, SZ_COLNAME, TY_CHAR)
	call salloc (cn1, SZ_COLNAME, TY_CHAR)
	call salloc (cu, SZ_COLUNITS, TY_CHAR)
	call salloc (cf, SZ_COLFMT, TY_CHAR)
	call salloc (duma, max(SZ_COLUNITS,SZ_COLFMT),TY_CHAR)

	# Open input list and initialize number of columns.
	list = imtopen (imlist)
	nocp = 0

	# Scan input list.
	do image = 1, imtlen(list) {

	    # Open image.
	    i = imtgetim (list, Memc[imname], SZ_PATHNAME)
	    iferr (im = immap (Memc[imname], READ_ONLY, 0)) {
	        call erract (EA_WARN)
	        next
	    }

	    # Get column data from image header.
	    iferr (call tm_header (im, Memc[cn], Memc[cu], Memc[cf])) {
	        call erract (EA_WARN)
	        next
	    }

	    # Array size is full image size.
	    lendata = 1
	    do i = 1, IM_NDIM(im)
	        lendata = lendata * IM_LEN(im,i)


	    # See if column name from header matches any name
	    # already stored in column pointer array.
	    match = false
	    do column = 1, nocp {
	        call tbcinf (Memi[ocp+column-1], dumi, Memc[cn1], 
                             Memc[duma], Memc[duma], dumi, dumi, dumi)
	        if (streq (Memc[cn1], Memc[cn])) {
	            match = true
	            break
	        }
	    }
	    if (!match) {

	    # No names matched, define new column.
	        call tbcdef (otp, Memi[ocp+nocp], Memc[cn], Memc[cu], 
                             Memc[cf], IM_PIXTYPE(im), lendata, 1)
	        nocp = nocp + 1
	    }
	}

	call imtclose (list)
	call sfree (sp)
	if (nocp == 0)
	    call error (1, "No images with column data in header.")
	call tbtcre (otp)
end