aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/threed/tiimage
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/utilities/nttools/threed/tiimage')
-rw-r--r--pkg/utilities/nttools/threed/tiimage/design1.txt353
-rw-r--r--pkg/utilities/nttools/threed/tiimage/generic/mkpkg14
-rw-r--r--pkg/utilities/nttools/threed/tiimage/generic/tmcp1d.x54
-rw-r--r--pkg/utilities/nttools/threed/tiimage/generic/tmcp1i.x54
-rw-r--r--pkg/utilities/nttools/threed/tiimage/generic/tmcp1r.x54
-rw-r--r--pkg/utilities/nttools/threed/tiimage/generic/tmcp1s.x54
-rw-r--r--pkg/utilities/nttools/threed/tiimage/list.tex789
-rw-r--r--pkg/utilities/nttools/threed/tiimage/list.toc10
-rw-r--r--pkg/utilities/nttools/threed/tiimage/loc.txt12
-rw-r--r--pkg/utilities/nttools/threed/tiimage/mkpkg29
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tiimage.h9
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tiimage.x147
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmcopy.x67
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmcp1.gx54
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmhc.x57
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmheader.x60
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmloop.x104
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmmode.x108
-rw-r--r--pkg/utilities/nttools/threed/tiimage/tmscan.x96
19 files changed, 2125 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/threed/tiimage/design1.txt b/pkg/utilities/nttools/threed/tiimage/design1.txt
new file mode 100644
index 00000000..8726f475
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/design1.txt
@@ -0,0 +1,353 @@
+
+
+ Design of 3-D table translator for image insertion
+ --------------------------------------------------
+
+
+ Author: I. Busko
+
+
+ Revision history:
+ 01/16/97 - First version.
+
+
+
+1. Specifications / requirements:
+
+This task will perform the inverse operation performed by task tximage.
+It will insert (in the tainsert task sense) one or more 1-D images into
+rows of an existing 3-D table. Alternatively, it will create a 3-D table
+from information taken either from a template 3-D table, or, if this table
+is not supplied, from the input images themselves. Each image in the input
+list is inserted as an array into a single cell at the specified row in the output table.
+
+Actions necessary to process the most complicated cases (e.g. when the
+image length does not match the table array size) will be similar to the
+ones described for task titable.
+
+If the output table does exist, insertion may take place in two ways. If the
+output table name contains a column selector that selects a single column
+in the table, all input images will be inserted in that column, starting
+at the row pointed by task parameter "row". In a similar way as in task
+titable, if "row" is negative or INDEF the task will look for the ORIG_ROW
+keyword in the image header and use that keyword value for row number.
+The second mode of insertion in an existing table is used if no matching
+column selector is found in the output table name. In this case the task
+will look for the columnar information written in the input image header by
+task tximage, and use that information to place the image in the proper
+column. If no columnar information exists in the header, or if the column
+name in there does not match any column in the output table, the image is
+skipped and the user warned. The "row" parameter processing works the same
+way in this second mode.
+
+If the output table does not exist, the task will look for a template table
+where to take column information from. If the template exists, the insertion
+operation will be performed in an analogous way as above. Notice that the
+result may be a single-column table if the template has a valid (matching)
+column selector in its name, or a sparse table if not, because only the
+actual input images will be stored in an otherwise empty table (the template
+data is not copied into the output, only the column descriptors).
+
+If the template is missing, the task will attempt to retrieve columnar
+information from the input image headers and build the output table with
+enough columns and rows to fit all images in the list. Only images that
+have columnar information in their headers can be processed, though. If
+no images are found with the proper header keywords, no output takes place.
+Notice that this task will not be able to handle the most generic case in
+which a number of unspecified 1-D images with no proper header keywords
+are input to create a 3-D table from scratch (without a template).
+
+The basic matching criterion is based on the column name. An error results
+when datatypes in input image and output column do not agree.
+
+The task will be named "tiimage" following a former proposal for naming
+the 3-D table utilities.
+
+
+
+2. Language:
+
+SPP, to allow the use of the generic datatype compiling facility, and to
+reuse significant amounts of code already developed for other tasks in this
+suite.
+
+
+
+3. Task parameters:
+
+Name Type What
+
+input image list/template list of 1D image names
+outtable file name 3-D table name with optional column selector
+ (modified in place or created from scratch).
+template file name template 3-D table name with optional column
+ selector
+row int row in output table where to begin insertion.
+
+
+
+4. Data structures:
+
+The main data structure is a pointer-type column descriptor array. This
+array is filled by information taken from the several possible sources
+described above, and used by the tbtables routines to create and fill up
+the output.
+
+
+
+5. Code structure:
+
+MAIN PROCEDURE:
+- Read task parameters (clget).
+- Decide which mode to use: mode = TMMODE (output name, template name)
+- SWITCH mode
+- CASE 1, 2: Output table exists.
+ - Break output table name into bracketed selectors (rdselect).
+ - Open output table (tbtopn with root name, READ_WRITE).
+ - Create array with either the single selected column pointer or all
+ column pointers (malloc, tcs_open).
+ - Alloc array of column pointers for output table.
+ - LOOP over all matched columns in tcs_ column array
+ - Translate pointer from tcs_ format to tbtables format (tcs_column)
+ - ENDLOOP
+ - TMLOOP (table pointer, column pointer array, rowpar, image list, mode).
+ - Close output table (tbtclo)
+ - Free array (mfree)
+- END CASE
+- CASE 3, 4: Output table does not exist but template table does exist.
+ - Break output table name into bracketed selectors (rdselect).
+ - Open output table (tbtopn with root name, NEW_FILE).
+ - Break template table name into bracketed selectors (rdselect).
+ - Open template table (tbtopn with root name, READ_ONLY).
+ - Create array with either the single selected column pointer or all
+ column pointers from template table (malloc, tcs_open).
+ - Alloc array of column pointers for output table.
+ - LOOP over all matched columns in template tcs_ column array
+ - Create column in output table (tcs_column, tbcinf, tbcdef)
+ - ENDLOOP
+ - Create output table (tbtcre).
+ - TMLOOP (table pointer, column pointer array, rowpar, image list, mode)
+ - Close template table (tbtclo)
+ - Close output table (tbtclo)
+ - Free arrays (mfree)
+- CASE 5: Neither output nor template table exist.
+ - Alloc memory for strings.
+ - Alloc memory for column pointer array, assuming the worst case of each
+ input image in the list belonging to a separate, independent column.
+ - Open output table (tbtopn with root name, NEW_FILE).
+ - IFNOTERROR TMSCAN (table pointer, column pointer array, image list)
+ - Set mode = 2 to force TMLOOP to read column data from headers.
+ - Create output table (tbtcre).
+ - TMLOOP (table pointer, column pointer array, rowpar, image list, mode)
+ - ENDIF
+ - Close output table (tbtclo)
+ - Free arrays (mfree)
+- END CASE
+- CASE -1
+ - Print error msg.
+ - Abort.
+- END SWITCH
+END MAIN
+
+
+
+PROCEDURE TMMODE: Detect mode of operation.
+ Input parameters: file name, template name (in full)
+ Return value: mode
+
+ - IF output exists (access)
+ - mode = TMM1 (output file name, output type)
+ - IF mode == -1
+ - Print error msg.
+ - return mode = -1 (error)
+ - ENDIF
+ - ELSE IF template does exist (access)
+ - mode = TMM1 (template file name, template type)
+ - IF mode == -1
+ - Print error msg.
+ - return mode = -1 (error)
+ - ENDIF
+ - ELSE
+ mode = 5
+ - ENDIF
+ return mode
+END PROCEDURE
+
+
+
+PROCEDURE TMM1: Verify status of file and column selector.
+ Input parameters: file name, file type (output or template)
+ Return value: mode
+
+ - IF file is not a table (whatfile).
+ - return mode = -1 (error)
+ - ENDIF
+ - Get bracket selector from file name (rdselect).
+ - Open table (tbtopn with root name, READ_ONLY).
+ - Get its total number of columns (tbpsta).
+ - Create array of column pointers from column selector (malloc, tcs_open).
+ - Close output table (tbtclo)
+ - Free array (mfree)
+ - IF output file type
+ - IF one column matched
+ - return mode = 1
+ - ELSE
+ - return mode = 2
+ - ENDIF
+ - ELSE IF template file type
+ - IF one column matched
+ - return mode = 3
+ - ELSE
+ - return mode = 4
+ - ENDIF
+ - ENDIF
+ return mode = -1 (error)
+END PROCEDURE
+
+
+
+PROCEDURE TMLOOP: Scan input list and insert each image in turn.
+ Input parameters: table pointer, column pointer array,row, image list,mode
+
+ - Initialize row counter.
+ - Initialize successful image counter.
+ - Open input list (imtopen)
+ - LOOP over input list (imtlen).
+ - Get image name (imtgetim).
+ - IFERROR Open input image (immap).
+ - Warn user.
+ - Skip image.
+ - ENDIF
+ - IF mode == 2 or mode == 4, look into image header for columnar info
+ and do the copy.
+ - IFERROR TMHC (table pointer, column pointer array, row, rowpar,
+ imio pointer)
+ - Close and skip image.
+ - ENDIF
+ - bump row and image counters.
+ - ELSE IF mode == 1 or mode == 3, just copy into single, fixed column.
+ - IFERROR TMCOPY (table pointer, column pointer, row, rowpar,
+ imio pointer)
+ - Warn user.
+ - Close and skip image.
+ - ENDIF
+ - bump row and image counters.
+ - ENDIF
+ - Close image (imunmap)
+ - ENDLOOP
+ - IF successful image counter == 0
+ - Print error msg.
+ - ENDIF
+ - Close input list (imtclose)
+END PROCEDURE
+
+
+
+PROCEDURE TMSCAN: Scan input list and create column pointer array from
+ information stored in image headers.
+ Input parameters: table pointer, column pointer array, its size, image list
+ Output parameter: actual number of matched columns.
+
+ - Initialize column counter.
+ - Open input list (imtopen)
+ - LOOP over input list (imtlen).
+ - Get image name (imtgetim).
+ - IFERROR Open input image (immap).
+ - Warn user.
+ - Skip image.
+ - ENDIF
+ - IFERROR TMHEADER (imio pointer, column name, units, fmt, datatype,
+ lendata
+ - Warn user.
+ - Skip image.
+ - ENDIF
+ - IF there are defined columns (column counter > 0):
+ - match = false
+ - LOOP over defined columns
+ - Get column name (tbcinf)
+ - IF column name from table matches column name from header:
+ - match = true
+ - break
+ - ENDIF
+ - ENDLOOP
+ - IF no match, this is a new column:
+ - Define new column in array (tbcdef)
+ - Bump column counter
+ - ENDIF
+ - ELSE
+ - Define first new column in array (tbcdef)
+ - Bump column counter
+ - ENDIF
+ - ENDLOOP
+ - Close input list (imtclose)
+ - IF column counter == 0
+ - Error.
+ - Create output table (tbtcre).
+END PROCEDURE
+
+
+
+PROCEDURE TMHC: Get column name from image header and copy image into table.
+ Input parameters: table pointer, column pointer array, row, rowpar,
+ imio pointer
+
+ - salloc space for column name.
+ - IFERROR TMHEADER (imio pointer, column name, etc.)
+ - Warn, return
+ - ENDIF
+ - match = false
+ - LOOP over table columns.
+ - IF column names match:
+ - IFERROR TMCOPY (table pointer, column pointer, row, rowpar,
+ imio pointer)
+ - Warn, return.
+ - ENDIF
+ - match = true
+ - ENDIF
+ - ENDLOOP
+ - IF no match
+ - Warn, return.
+ - ENDIF
+ - sfree
+END PROCEDURE
+
+
+
+PROCEDURE TMCOPY: Copy image into designated row/column.
+ Input parameters: table pointer, column pointer, row, rowpar, imio pointer
+
+ - Get table (tbcigi) and image (IM_PIXTYPE) pixel type.
+ - IF pixel type mismatch:
+ - Warn, return
+ - ENDIF
+ - Look for ORIG_ROW keyword (imaccf, imgeti). If found, and if "row"
+ parameter is negative or INDEF, supersede row counter.
+ - Get column array size (tbcinf) and image size (IM_NDIM, IM_LEN).
+ - Choose the minimum of these as the array size to be written to table.
+ - Read pixels in buffer (imgl1$t). ^
+ - Write buffer into designated row/column (tbapt$t). |
+ - IF image is larger than array: | This goes into
+ - Warn user. | a generic data
+ - ELSE IF image is smaller than array: | type procedure
+ - Set remaining elements to INDEF (tbapt$t). |
+ - Warn user. |
+ - ENDIF v
+END PROCEDURE
+
+
+
+PROCEDURE TMHEADER: Decode column info in image header.
+ Input parameter: imio pointer
+ Output parameter: column name, units, fmt, datatype, lendata
+
+ - Look for COLDATA keyword (imaccf, imgstr).
+ - IF not found:
+ return error.
+ - ENDIF
+ - Parse and get parameters (sscan, gargwrd, gargi)
+ - IF error in nscan value:
+ return error.
+ - ENDIF
+END PROCEDURE
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/generic/mkpkg b/pkg/utilities/nttools/threed/tiimage/generic/mkpkg
new file mode 100644
index 00000000..51bd24bb
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/generic/mkpkg
@@ -0,0 +1,14 @@
+# Update the generic routines.
+
+default:
+ $checkout libpkg.a ../../
+ $update libpkg.a
+ $checkin libpkg.a ../../
+$exit
+
+libpkg.a:
+ tmcp1s.x
+ tmcp1i.x
+ tmcp1r.x
+ tmcp1d.x
+ ;
diff --git a/pkg/utilities/nttools/threed/tiimage/generic/tmcp1d.x b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1d.x
new file mode 100644
index 00000000..9670c6a6
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1d.x
@@ -0,0 +1,54 @@
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1d (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1d()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1d (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbaptd (tp, cp, row, Memd[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbaptd (tp, cp, row, undefd, i, 1)
+ }
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/generic/tmcp1i.x b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1i.x
new file mode 100644
index 00000000..7e271952
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1i.x
@@ -0,0 +1,54 @@
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1i (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1i()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1i (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbapti (tp, cp, row, Memi[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbapti (tp, cp, row, undefi, i, 1)
+ }
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/generic/tmcp1r.x b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1r.x
new file mode 100644
index 00000000..00594521
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1r.x
@@ -0,0 +1,54 @@
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1r (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1r()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1r (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbaptr (tp, cp, row, Memr[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbaptr (tp, cp, row, undefr, i, 1)
+ }
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/generic/tmcp1s.x b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1s.x
new file mode 100644
index 00000000..3d308f13
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/generic/tmcp1s.x
@@ -0,0 +1,54 @@
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1s (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1s()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1s (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbapts (tp, cp, row, Mems[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbapts (tp, cp, row, undefs, i, 1)
+ }
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/list.tex b/pkg/utilities/nttools/threed/tiimage/list.tex
new file mode 100644
index 00000000..05eb3592
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/list.tex
@@ -0,0 +1,789 @@
+\documentstyle{article}
+\topmargin -30mm
+\textheight 250mm
+\oddsidemargin -5mm
+\evensidemargin -5mm
+\textwidth 170mm
+
+\begin{document}
+
+\tableofcontents
+
+\newpage
+
+\addcontentsline{toc}{section}{loc.txt}
+\begin{verbatim}
+
+Filename Total Blanks Comments Help Execute Nonexec
+============================================================================
+ tiimage.h 9 1 0 0 0 8
+ tiimage.x 141 36 31 0 53 21
+ tmloop.x 96 23 15 0 40 18
+ tmmode.x 108 24 24 0 30 30
+ tmscan.x 92 21 15 0 38 18
+ tmheader.x 59 19 8 0 19 13
+ tmhc.x 54 16 9 0 15 14
+ tmcopy.x 63 18 9 0 23 13
+ tmcp1.gx 53 17 11 0 10 15
+TOTAL 834 226 155 0 258 195
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tiimage.h}
+\begin{verbatim}
+
+define OUTPUT_TYPE 1 # Output-type file
+define TEMPLATE_TYPE 2 # Template-type file
+
+define MODE_OUT_SINGLE 1 # Output with single column
+define MODE_OUT_ALL 2 # Output with all columns
+define MODE_TEM_SINGLE 3 # Template with single column
+define MODE_TEM_ALL 4 # Template with all columns
+define MODE_SCRATCH 5 # No output nor template, create from scratch
+define MODE_ERROR -1
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tiimage.x}
+\begin{verbatim}
+
+include <tbset.h>
+include "tiimage.h"
+
+# TIIMAGE -- Insert 1D images into 3D table rows.
+#
+# Input images are given by a filename template list. The output is a
+# 3D table with optional column selector.
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure t_tiimage()
+
+char imlist[SZ_LINE] # Input image list
+char output[SZ_PATHNAME] # Output table name
+char template[SZ_PATHNAME] # Template table name
+int row # Row where to begin insertion
+bool verbose # Print operations ?
+#--
+char root[SZ_FNAME] # String storage areas used
+char rs[SZ_FNAME] # by row/column selector
+char cs[SZ_FNAME] # mechanism
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+pointer sp, otp, ttp, ocp, tcp, newocp, tempp, list
+int nocp, mode, numcol, dtyp, lend, lenf, cnum, i
+
+pointer tbtopn(), tcs_column(), imtopen()
+int clgeti(), tbpsta(), tm_mode(), imtlen()
+bool clgetb(), streq()
+
+begin
+ # Get task parameters.
+ call clgstr ("input", imlist, SZ_LINE)
+ call clgstr ("outtable", output, SZ_PATHNAME)
+ call clgstr ("template", template, SZ_PATHNAME)
+ row = clgeti ("row")
+ verbose = clgetb ("verbose")
+
+ # Abort if invalid output name.
+ if (streq (output, "STDOUT"))
+ call error (1, "Invalid output file name.")
+
+ # Decide which mode to use.
+ mode = tm_mode (output, template, root, rs, cs, cn, cu, cf)
+
+ call smark (sp)
+ switch (mode) {
+
+ case MODE_OUT_SINGLE,MODE_OUT_ALL:
+
+ # Break output table name into bracketed selectors.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+
+ # Open output table.
+ otp = tbtopn (root, READ_WRITE, 0)
+
+ # Create arrays with selected column pointer(s).
+ numcol = tbpsta (otp, TBL_NCOLS)
+ call salloc (ocp, numcol, TY_INT)
+ call salloc (newocp, numcol, TY_INT)
+ call tcs_open (otp, cs, Memi[ocp], nocp, numcol)
+
+ # Translate pointer to tbtables-compatible format.
+ do i = 1, nocp
+ Memi[newocp+i-1] = tcs_column (Memi[ocp+i-1])
+
+ # Do the insertion by looping over all input images.
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_TEM_SINGLE,MODE_TEM_ALL:
+
+ # Get output table root name and open it.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ otp = tbtopn (root, NEW_FILE, 0)
+
+ # Break template table name into bracketed
+ # selectors and open it.
+ call rdselect (template, root, rs, cs, SZ_PATHNAME)
+ ttp = tbtopn (root, READ_ONLY, 0)
+
+ # Create arrays with selected column pointer(s).
+ numcol = tbpsta (ttp, TBL_NCOLS)
+ call salloc (tcp, numcol, TY_INT)
+ call salloc (newocp, numcol, TY_INT)
+ call tcs_open (ttp, cs, Memi[tcp], nocp, numcol)
+
+ # Copy column info from template to output table.
+ do i = 1, nocp {
+ tempp = tcs_column (Memi[tcp+i-1])
+ call tbcinf (tempp, cnum, cn, cu, cf, dtyp, lend, lenf)
+ call tbcdef (otp, tempp, cn, cu, cf, dtyp, lend, 1)
+ Memi[newocp+i-1] = tempp
+ }
+
+ # Create output and close template.
+ call tbtcre (otp)
+ call tbtclo (ttp)
+
+ # Do the insertion by looping over all input images.
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_SCRATCH:
+
+ # Alloc memory for column pointer array, assuming
+ # the worst case of each input image in the list
+ # belonging to a separate column.
+ list = imtopen (imlist)
+ numcol = imtlen (list)
+ call imtclose (list)
+ call salloc (newocp, numcol, TY_INT)
+
+ # Open output table.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ otp = tbtopn (root, NEW_FILE, 0)
+
+ # Build column descriptor array from info in image headers.
+ ifnoerr (call tm_scan (otp, newocp, numcol, nocp, imlist)) {
+
+ # Pretend that template table exists and do the insertion.
+ mode = MODE_TEM_ALL
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+ }
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_ERROR:
+ call error (1, "Cannot process.")
+ }
+
+ call sfree (sp)
+end
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmloop.x}
+\begin{verbatim}
+
+include <error.h>
+include "tiimage.h"
+
+# TM_LOOP -- Scan input list and insert each image in turn.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_loop (tp, cp, ncp, row, imlist, mode, outname, verbose)
+
+pointer tp # table pointer
+pointer cp # column pointer array
+int ncp # size of column pointer array
+int row # row where to begin insertion
+char imlist[ARB] # input image list
+int mode # operating mode
+char outname[ARB] # output table name (for listing only)
+bool verbose # print info ?
+#--
+pointer sp, im, list, fname
+int i, rowc, imc, image
+bool rflag
+
+errchk immap, tm_hc, tm_copy
+
+pointer immap(), imtopen()
+int imtlen(), imtgetim()
+
+begin
+ call smark (sp)
+ call salloc (fname, SZ_PATHNAME, TY_CHAR)
+
+ # Initialize row counter.
+ rowc = row
+ rflag = false
+ if (rowc <= 0 || IS_INDEFI(rowc)) rflag = true
+
+ # Initialize successful image counter.
+ imc = 0
+
+ # Open input list.
+ list = imtopen (imlist)
+
+ # Loop over input list.
+ do image = 1, imtlen(list) {
+
+ # Get input image name and open it. Skip if error.
+ i = imtgetim (list, Memc[fname], SZ_PATHNAME)
+ iferr (im = immap (Memc[fname], READ_ONLY, 0)) {
+ call erract (EA_WARN)
+ next
+ }
+ if (verbose) {
+ call printf ("%s ")
+ call pargstr (Memc[fname])
+ call flush (STDOUT)
+ }
+
+ # Look into image header for columnar info and do the copy.
+ if (mode == MODE_OUT_ALL || mode == MODE_TEM_ALL) {
+ iferr (call tm_hc (tp, cp, ncp, rowc, rflag, im)) {
+ call erract (EA_WARN)
+ call imunmap (im)
+ next
+ }
+
+ # Bump row and image counters.
+ rowc = rowc + 1
+ imc = imc + 1
+
+ # Just copy into single column.
+ } else if (mode == MODE_OUT_SINGLE || mode == MODE_TEM_SINGLE) {
+ iferr (call tm_copy (tp, Memi[cp], rowc, rflag, im)) {
+ call erract (EA_WARN)
+ call imunmap (im)
+ next
+ }
+
+ # Bump row and image counters.
+ rowc = rowc + 1
+ imc = imc + 1
+ }
+
+ if (verbose) {
+ call printf ("-> %s row=%d \n")
+ call pargstr (outname)
+ call pargi (rowc-1)
+ call flush (STDOUT)
+ }
+
+ # Close current image.
+ call imunmap (im)
+ }
+
+ call imtclose (list)
+ call sfree (sp)
+ if (imc == 0)
+ call error (1, "No images were inserted.")
+end
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmmode.x}
+\begin{verbatim}
+
+include <tbset.h>
+include "../whatfile.h"
+include "tiimage.h"
+
+# TM_MODE -- Detect mode of operation.
+#
+# There are five possible modes:
+# 1 - Output table exists and one column was selected.
+# 2 - Output table exists and no valid column was selected.
+# 3 - Output table does not exist but template exists and one column was
+# selected.
+# 4 - Output table does not exist but template exists and no valid column
+# was selected.
+# 5 - New table has to be created from scratch.
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+int procedure tm_mode (output, template, root, rs, cs, cn, cu, cf)
+
+char output[SZ_PATHNAME]
+char template[SZ_PATHNAME]
+char root[SZ_FNAME]
+char rs[SZ_FNAME]
+char cs[SZ_FNAME]
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+#-
+int mode
+
+int access(), tm_m1()
+
+begin
+ # Process output name. Notice that routine access() must be
+ # supplied with only the root name in order to succeed.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ if (access (root, READ_WRITE, 0) == YES) {
+ mode = tm_m1 (OUTPUT_TYPE, root,rs,cs,cn,cu,cf)
+ if (mode == MODE_ERROR)
+ call error (1, "Cannot use output file.")
+
+ # If no valid output, try with template name.
+ } else {
+ call rdselect (template, root, rs, cs, SZ_PATHNAME)
+ if (access (root, READ_ONLY, 0) == YES) {
+ mode = tm_m1 (TEMPLATE_TYPE, root, rs, cs, cn, cu, cf)
+ if (mode == MODE_ERROR)
+ call error (1, "Cannot use template file.")
+ } else {
+ mode = MODE_SCRATCH
+ }
+ }
+
+ return (mode)
+end
+
+
+# TM_M1 -- Verify status of file and column selector.
+
+int procedure tm_m1 (type, root, rs, cs, cn, cu, cf)
+
+int type
+char root[SZ_FNAME]
+char rs[SZ_FNAME]
+char cs[SZ_FNAME]
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+#-
+pointer tp, cp
+int numcol, ncp
+
+pointer tbtopn()
+int whatfile(), tbpsta()
+
+begin
+ # Test if it is a valid table.
+ if (whatfile (root) != IS_TABLE)
+ return (MODE_ERROR)
+
+ # Open table
+ tp = tbtopn (root, READ_ONLY)
+
+ # Get its total number of columns.
+ numcol = tbpsta (tp, TBL_NCOLS)
+
+ # Create array of column pointers from column selector.
+ # This is just to get the actual number of selected columns.
+ call malloc (cp, numcol, TY_INT)
+ call tcs_open (tp, cs, Memi[cp], ncp, numcol)
+ call tbtclo (tp)
+ call mfree (cp)
+
+ # Decide mode.
+ if (type == OUTPUT_TYPE) {
+ if (ncp == 1)
+ return (MODE_OUT_SINGLE)
+ else
+ return (MODE_OUT_ALL)
+ } else if (type == TEMPLATE_TYPE) {
+ if (ncp == 1)
+ return (MODE_TEM_SINGLE)
+ else
+ return (MODE_TEM_ALL)
+ }
+ return (MODE_ERROR)
+end
+
+
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmscan.x}
+\begin{verbatim}
+
+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)
+
+
+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 = 0
+ do i = 1, IM_NDIM(im)
+ lendata = lendata + IM_LEN(im,i)
+
+ if (nocp > 0) {
+
+ # 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, efine new column.
+ call tbcdef (otp, Memi[ocp+nocp], Memc[cn], Memc[cu],
+ Memc[cf], IM_PIXTYPE(im), lendata, 1)
+ nocp = nocp + 1
+ }
+ } else {
+
+ # Array is empty, define first column.
+ call tbcdef (otp, Memi[ocp], Memc[cn], Memc[cu], Memc[cf],
+ IM_PIXTYPE(im), lendata, 1)
+ 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
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmheader.x}
+\begin{verbatim}
+
+include <tbset.h>
+
+# TM_HEADER -- Decode column info in image header.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_header (im, colname, colunits, colfmt)
+
+pointer im # image pointer
+char colname[SZ_COLNAME] # column name
+char colunits[SZ_COLUNITS] # column units
+char colfmt[SZ_COLFMT] # column print format
+#--
+pointer sp, kwval
+int colnum
+
+string corrupt "Corrupted header in input image."
+
+bool streq()
+int imaccf(), nscan()
+
+begin
+ if (imaccf (im, "COLDATA") == NO)
+ call error (1, "No column information in image header.")
+
+ call smark (sp)
+ call salloc (kwval, SZ_LINE, TY_CHAR)
+
+ # Get keyword value.
+ call imgstr (im, "COLDATA", Memc[kwval], SZ_LINE)
+
+ # Read fields.
+ call sscan (Memc[kwval])
+ call gargi (colnum)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colname, SZ_COLNAME)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colunits, SZ_COLUNITS)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colfmt, SZ_COLFMT)
+ if (nscan() < 1) call error (1, corrupt)
+
+ # Decode custom-encoded values.
+ if (streq (colunits, "default"))
+ call strcpy ("", colunits, SZ_COLUNITS)
+ if (streq (colfmt, "default"))
+ call strcpy ("", colfmt, SZ_COLFMT)
+
+ call sfree (sp)
+end
+
+
+
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmhc.x}
+\begin{verbatim}
+
+include <tbset.h>
+
+# TM_HC -- Get column name from image header and copy image into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_hc (tp, cp, ncp, row, rflag, im)
+
+pointer tp # table pointer
+pointer cp # column pointer array
+int ncp # size of column pointer array
+int row # row where to begin insertion
+bool rflag # use row number in header ?
+pointer im # image pointer
+#--
+pointer sp, colname, cn, duma
+int i, dumi
+bool match
+
+errchk tm_header, tm_copy
+
+bool streq()
+
+begin
+ call smark (sp)
+ call salloc (colname, SZ_COLNAME, TY_CHAR)
+ call salloc (cn, SZ_COLNAME, TY_CHAR)
+ call salloc (duma, max(SZ_COLUNITS,SZ_COLFMT),TY_CHAR)
+
+ # Get column name from image header.
+ call tm_header (im, Memc[colname], Memc[duma], Memc[duma])
+
+ # Loop over table columns.
+ match = false
+ do i = 1, ncp {
+
+ # Get column name from table.
+ call tbcinf (Memi[cp+i-1], dumi, Memc[cn], Memc[duma],
+ Memc[duma], dumi, dumi, dumi)
+
+ # Copy array if names match.
+ if (streq (Memc[colname], Memc[cn])) {
+ call tm_copy (tp, Memi[cp+i-1], row, rflag, im)
+ match = true
+ }
+ }
+ if (!match)
+ call error (1, "No column matched.")
+
+ call sfree (sp)
+end
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmcopy.x}
+\begin{verbatim}
+
+include <imhdr.h>
+include <tbset.h>
+
+# TM_COPY -- Copy image into designated row/column.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_copy (tp, cp, row, rflag, im)
+
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+bool rflag # use row number in image header ?
+pointer im # imio pointer
+#--
+pointer sp, duma
+int i, lena, leni, dumi
+
+int tbcigi(), imgeti(), imaccf()
+
+begin
+ # See if table and image pixel types match.
+ if (tbcigi (tp, TBL_COL_DATATYPE) == IM_PIXTYPE(im))
+ call error (1, "Pixel type mismatch.")
+
+ # Look for row information in image header.
+ if (imaccf (im, "ORIG_ROW") == YES) {
+ if (rflag)
+ row = imgeti (im, "ORIG_ROW")
+ }
+
+ # Get column array size and image size.
+ call smark (sp)
+ call salloc (duma, max(max(SZ_COLNAME,SZ_COLUNITS),SZ_COLFMT),TY_CHAR)
+ call tbcinf (cp, dumi, Memc[duma], Memc[duma], Memc[duma], dumi,
+ lena, dumi)
+ call sfree (sp)
+ leni = 0
+ do i = 1, IM_NDIM(im)
+ leni = leni + IM_LEN(im,i)
+
+ # Copy.
+ switch (IM_PIXTYPE(im)) {
+ case TY_SHORT:
+ call tm_cp1s (im, tp, cp, row, lena, leni)
+ case TY_INT:
+ call tm_cp1i (im, tp, cp, row, lena, leni)
+ case TY_REAL:
+ call tm_cp1r (im, tp, cp, row, lena, leni)
+ case TY_DOUBLE:
+ call tm_cp1d (im, tp, cp, row, lena, leni)
+ default:
+ call error (1, "Non-supported data type.")
+ }
+
+end
+
+
+
+
+\end{verbatim}
+\newpage
+\addcontentsline{toc}{section}{tmcp1.gx}
+\begin{verbatim}
+
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1$t (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1$t()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1$t (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbapt$t (tp, cp, row, Mem$t[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbapt$t (tp, cp, row, undef$t, i, 1)
+ }
+end
+
+
+
+
+\end{verbatim}
+\newpage
+\end{document}
diff --git a/pkg/utilities/nttools/threed/tiimage/list.toc b/pkg/utilities/nttools/threed/tiimage/list.toc
new file mode 100644
index 00000000..06d86919
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/list.toc
@@ -0,0 +1,10 @@
+\contentsline {section}{loc.txt}{2}
+\contentsline {section}{tiimage.h}{3}
+\contentsline {section}{tiimage.x}{4}
+\contentsline {section}{tmloop.x}{7}
+\contentsline {section}{tmmode.x}{9}
+\contentsline {section}{tmscan.x}{11}
+\contentsline {section}{tmheader.x}{13}
+\contentsline {section}{tmhc.x}{15}
+\contentsline {section}{tmcopy.x}{16}
+\contentsline {section}{tmcp1.gx}{18}
diff --git a/pkg/utilities/nttools/threed/tiimage/loc.txt b/pkg/utilities/nttools/threed/tiimage/loc.txt
new file mode 100644
index 00000000..43db97fc
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/loc.txt
@@ -0,0 +1,12 @@
+Filename Total Blanks Comments Help Execute Nonexec
+============================================================================
+ tiimage.h 9 1 0 0 0 8
+ tiimage.x 141 36 31 0 53 21
+ tmloop.x 96 23 15 0 40 18
+ tmmode.x 108 24 24 0 30 30
+ tmscan.x 92 21 15 0 38 18
+ tmheader.x 59 19 8 0 19 13
+ tmhc.x 54 16 9 0 15 14
+ tmcopy.x 63 18 9 0 23 13
+ tmcp1.gx 53 17 11 0 10 15
+TOTAL 834 226 155 0 258 195
diff --git a/pkg/utilities/nttools/threed/tiimage/mkpkg b/pkg/utilities/nttools/threed/tiimage/mkpkg
new file mode 100644
index 00000000..6a3588af
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/mkpkg
@@ -0,0 +1,29 @@
+# Update the tiimage application code in the threed package library.
+# Author: I.Busko, 30-Jan-1997
+
+$checkout libpkg.a ../
+$update libpkg.a
+$checkin libpkg.a ../
+$exit
+
+# This module is called from the threed mkpkg.
+generic:
+ $ifnfile (generic/tmcp1i.x)
+ $generic -k -p generic/ -t sird tmcp1.gx
+ $endif
+ $ifolder (generic/tmcp1i.x, tmcp1.gx)
+ $generic -k -p generic/ -t sird tmcp1.gx
+ $endif
+ ;
+
+libpkg.a:
+ @generic
+ tiimage.x <tbset.h> tiimage.h
+ tmcopy.x <imhdr.h> <tbset.h>
+ tmhc.x <tbset.h>
+ tmheader.x <tbset.h>
+ tmloop.x <error.h> tiimage.h
+ tmmode.x <tbset.h> tiimage.h
+ tmscan.x <error.h> <imhdr.h> <tbset.h>
+ ;
+
diff --git a/pkg/utilities/nttools/threed/tiimage/tiimage.h b/pkg/utilities/nttools/threed/tiimage/tiimage.h
new file mode 100644
index 00000000..86e0d000
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tiimage.h
@@ -0,0 +1,9 @@
+define OUTPUT_TYPE 1 # Output-type file
+define TEMPLATE_TYPE 2 # Template-type file
+
+define MODE_OUT_SINGLE 1 # Output with single column
+define MODE_OUT_ALL 2 # Output with all columns
+define MODE_TEM_SINGLE 3 # Template with single column
+define MODE_TEM_ALL 4 # Template with all columns
+define MODE_SCRATCH 5 # No output nor template, create from scratch
+define MODE_ERROR -1
diff --git a/pkg/utilities/nttools/threed/tiimage/tiimage.x b/pkg/utilities/nttools/threed/tiimage/tiimage.x
new file mode 100644
index 00000000..85aab676
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tiimage.x
@@ -0,0 +1,147 @@
+include <tbset.h>
+include "tiimage.h"
+
+# TIIMAGE -- Insert 1D images into 3D table rows.
+#
+# Input images are given by a filename template list. The output is a
+# 3D table with optional column selector.
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure t_tiimage()
+
+char imlist[SZ_LINE] # Input image list
+char output[SZ_PATHNAME] # Output table name
+char template[SZ_PATHNAME] # Template table name
+int row # Row where to begin insertion
+bool verbose # Print operations ?
+#--
+char root[SZ_FNAME] # String storage areas used
+char rs[SZ_FNAME] # by row/column selector
+char cs[SZ_FNAME] # mechanism
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+pointer sp, otp, ttp, ocp, tcp, newocp, tempp, list
+int nocp, mode, numcol, dtyp, lend, lenf, cnum, i
+
+pointer tbtopn(), tcs_column(), imtopen()
+int clgeti(), tbpsta(), tm_mode(), imtlen()
+bool clgetb(), streq()
+
+begin
+ # Get task parameters.
+ call clgstr ("input", imlist, SZ_LINE)
+ call clgstr ("outtable", output, SZ_PATHNAME)
+ call clgstr ("template", template, SZ_PATHNAME)
+ row = clgeti ("row")
+ verbose = clgetb ("verbose")
+
+ # Abort if invalid output name.
+ if (streq (output, "STDOUT"))
+ call error (1, "Invalid output file name.")
+
+ # Decide which mode to use.
+ mode = tm_mode (output, template, root, rs, cs, cn, cu, cf)
+
+ call smark (sp)
+ switch (mode) {
+
+ case MODE_OUT_SINGLE,MODE_OUT_ALL:
+
+ # Break output table name into bracketed selectors.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+
+ # Open output table.
+ otp = tbtopn (root, READ_WRITE, 0)
+
+ # Create arrays with selected column pointer(s).
+ numcol = tbpsta (otp, TBL_NCOLS)
+ call salloc (ocp, numcol, TY_INT)
+ call salloc (newocp, numcol, TY_INT)
+ call tcs_open (otp, cs, Memi[ocp], nocp, numcol)
+
+ # Translate pointer to tbtables-compatible format.
+ do i = 1, nocp
+ Memi[newocp+i-1] = tcs_column (Memi[ocp+i-1])
+
+ # Do the insertion by looping over all input images.
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_TEM_SINGLE,MODE_TEM_ALL:
+
+ # Get output table root name and open it.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ otp = tbtopn (root, NEW_FILE, 0)
+
+ # Break template table name into bracketed
+ # selectors and open it.
+ call rdselect (template, root, rs, cs, SZ_PATHNAME)
+ ttp = tbtopn (root, READ_ONLY, 0)
+
+ # Create arrays with selected column pointer(s).
+ numcol = tbpsta (ttp, TBL_NCOLS)
+ call salloc (tcp, numcol, TY_INT)
+ call salloc (newocp, numcol, TY_INT)
+ call tcs_open (ttp, cs, Memi[tcp], nocp, numcol)
+
+ # Copy column info from template to output table.
+ do i = 1, nocp {
+ tempp = tcs_column (Memi[tcp+i-1])
+ call tbcinf (tempp, cnum, cn, cu, cf, dtyp, lend, lenf)
+ call tbcdef (otp, tempp, cn, cu, cf, dtyp, lend, 1)
+ Memi[newocp+i-1] = tempp
+ }
+
+ # Create output and close template.
+ call tbtcre (otp)
+ call tbtclo (ttp)
+
+ # Do the insertion by looping over all input images.
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_SCRATCH:
+
+ # Alloc memory for column pointer array, assuming
+ # the worst case of each input image in the list
+ # belonging to a separate column.
+ list = imtopen (imlist)
+ numcol = imtlen (list)
+ call imtclose (list)
+ call salloc (newocp, numcol, TY_INT)
+
+ # Open output table.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ otp = tbtopn (root, NEW_FILE, 0)
+
+ # Build column descriptor array from info in image headers.
+ ifnoerr (call tm_scan (otp, newocp, numcol, nocp, imlist)) {
+
+ # Pretend that template table exists and do the insertion.
+ mode = MODE_TEM_ALL
+ call tm_loop (otp, newocp, nocp, row, imlist, mode, output,
+ verbose)
+ }
+
+ # Close output table.
+ call tbtclo (otp)
+
+ case MODE_ERROR:
+ call error (1, "Cannot process.")
+ }
+
+ call sfree (sp)
+end
diff --git a/pkg/utilities/nttools/threed/tiimage/tmcopy.x b/pkg/utilities/nttools/threed/tiimage/tmcopy.x
new file mode 100644
index 00000000..8d2673c5
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmcopy.x
@@ -0,0 +1,67 @@
+include <imhdr.h>
+include <tbset.h>
+
+# TM_COPY -- Copy image into designated row/column.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+# 21-May-97 - Changes from code review (IB)
+
+
+procedure tm_copy (tp, cp, row, rflag, im)
+
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+bool rflag # use row number in image header ?
+pointer im # imio pointer
+#--
+pointer sp, duma
+int i, lena, leni, dumi
+
+int tbcigi(), imgeti(), imaccf()
+
+begin
+ # See if table and image pixel types match.
+ if (tbcigi (tp, TBL_COL_DATATYPE) == IM_PIXTYPE(im))
+ call error (1, "Pixel type mismatch.")
+
+ # Look for row information in image header.
+ if (imaccf (im, "ORIG_ROW") == YES) {
+ if (rflag)
+ row = imgeti (im, "ORIG_ROW")
+ }
+
+ # Get column array size and image size.
+ call smark (sp)
+ call salloc (duma, max(max(SZ_COLNAME,SZ_COLUNITS),SZ_COLFMT),TY_CHAR)
+ call tbcinf (cp, dumi, Memc[duma], Memc[duma], Memc[duma], dumi,
+ lena, dumi)
+ call sfree (sp)
+ leni = 1
+ do i = 1, IM_NDIM(im)
+ leni = leni * IM_LEN(im,i)
+
+ # Copy.
+ switch (IM_PIXTYPE(im)) {
+ case TY_SHORT:
+ call tm_cp1s (im, tp, cp, row, lena, leni)
+ case TY_INT:
+ call tm_cp1i (im, tp, cp, row, lena, leni)
+ case TY_REAL:
+ call tm_cp1r (im, tp, cp, row, lena, leni)
+ case TY_DOUBLE:
+ call tm_cp1d (im, tp, cp, row, lena, leni)
+ default:
+ call error (1, "Non-supported data type.")
+ }
+
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/tmcp1.gx b/pkg/utilities/nttools/threed/tiimage/tmcp1.gx
new file mode 100644
index 00000000..b90ca406
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmcp1.gx
@@ -0,0 +1,54 @@
+
+# TM_CP1 -- Fill pixel buffer and copy into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_cp1$t (im, tp, cp, row, lena, leni)
+
+pointer im # imio pointer
+pointer tp # table pointer
+pointer cp # column pointer
+int row # row where to begin insertion
+int lena # array length
+int leni # image length
+#--
+pointer buf
+double undefd
+real undefr
+int undefi, i, len
+short undefs
+
+pointer imgl1$t()
+
+begin
+ # Read pixels into buffer.
+ buf = imgl1$t (im)
+
+ # Choose the minimum between image and table array
+ # lengths as the array size to be written to table.
+ len = min (lena, leni)
+
+ # Write buffer into array cell element.
+ call tbapt$t (tp, cp, row, Mem$t[buf], 1, len)
+
+ # If image is smaller than array, set
+ # remaining elements to INDEF.
+ if (leni < lena) {
+ undefd = INDEFD
+ undefr = INDEFR
+ undefi = INDEFI
+ undefs = INDEFS
+ do i = len+1, lena
+ call tbapt$t (tp, cp, row, undef$t, i, 1)
+ }
+end
+
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/tmhc.x b/pkg/utilities/nttools/threed/tiimage/tmhc.x
new file mode 100644
index 00000000..30ad4eb3
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmhc.x
@@ -0,0 +1,57 @@
+include <tbset.h>
+
+# TM_HC -- Get column name from image header and copy image into table.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_hc (tp, cp, ncp, row, rflag, im)
+
+pointer tp # table pointer
+pointer cp # column pointer array
+int ncp # size of column pointer array
+int row # row where to begin insertion
+bool rflag # use row number in header ?
+pointer im # image pointer
+#--
+pointer sp, colname, cn, duma
+int i, dumi
+bool match
+
+errchk tm_header, tm_copy
+
+bool streq()
+
+begin
+ call smark (sp)
+ call salloc (colname, SZ_COLNAME, TY_CHAR)
+ call salloc (cn, SZ_COLNAME, TY_CHAR)
+ call salloc (duma, max(SZ_COLUNITS,SZ_COLFMT),TY_CHAR)
+
+ # Get column name from image header.
+ call tm_header (im, Memc[colname], Memc[duma], Memc[duma])
+
+ # Loop over table columns.
+ match = false
+ do i = 1, ncp {
+
+ # Get column name from table.
+ call tbcinf (Memi[cp+i-1], dumi, Memc[cn], Memc[duma],
+ Memc[duma], dumi, dumi, dumi)
+
+ # Copy array if names match.
+ if (streq (Memc[colname], Memc[cn])) {
+ call tm_copy (tp, Memi[cp+i-1], row, rflag, im)
+ match = true
+ }
+ }
+ if (!match)
+ call error (1, "No column matched.")
+
+ call sfree (sp)
+end
diff --git a/pkg/utilities/nttools/threed/tiimage/tmheader.x b/pkg/utilities/nttools/threed/tiimage/tmheader.x
new file mode 100644
index 00000000..b6481fa4
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmheader.x
@@ -0,0 +1,60 @@
+include <tbset.h>
+
+# TM_HEADER -- Decode column info in image header.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+# 21-May-97 - Changes from code review (IB)
+
+
+procedure tm_header (im, colname, colunits, colfmt)
+
+pointer im # image pointer
+char colname[SZ_COLNAME] # column name
+char colunits[SZ_COLUNITS] # column units
+char colfmt[SZ_COLFMT] # column print format
+#--
+pointer sp, kwval
+int colnum
+
+string corrupt "Corrupted header in input image."
+
+bool streq()
+int imaccf(), nscan()
+
+begin
+ if (imaccf (im, "COLDATA") == NO)
+ call error (1, "No column information in image header.")
+
+ call smark (sp)
+ call salloc (kwval, SZ_LINE, TY_CHAR)
+
+ # Get keyword value.
+ call imgstr (im, "COLDATA", Memc[kwval], SZ_LINE)
+
+ # Read fields.
+ call sscan (Memc[kwval])
+ call gargi (colnum)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colname, SZ_COLNAME)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colunits, SZ_COLUNITS)
+ if (nscan() < 1) call error (1, corrupt)
+ call gargwrd (colfmt, SZ_COLFMT)
+ if (nscan() < 1) call error (1, corrupt)
+
+ # Decode custom-encoded values.
+ if (streq (colunits, "default"))
+ colunits[1] = EOS
+ if (streq (colfmt, "default"))
+ colfmt[1] = EOS
+
+ call sfree (sp)
+end
+
+
+
diff --git a/pkg/utilities/nttools/threed/tiimage/tmloop.x b/pkg/utilities/nttools/threed/tiimage/tmloop.x
new file mode 100644
index 00000000..e99d8e8b
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmloop.x
@@ -0,0 +1,104 @@
+include <error.h>
+include "tiimage.h"
+
+# TM_LOOP -- Scan input list and insert each image in turn.
+#
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+
+
+procedure tm_loop (tp, cp, ncp, row, imlist, mode, outname, verbose)
+
+pointer tp # table pointer
+pointer cp # column pointer array
+int ncp # size of column pointer array
+int row # row where to begin insertion
+char imlist[ARB] # input image list
+int mode # operating mode
+char outname[ARB] # output table name (for listing only)
+bool verbose # print info ?
+#--
+pointer sp, im, list, fname
+int i, rowc, imc, image
+bool rflag
+
+errchk immap, tm_hc, tm_copy
+
+pointer immap(), imtopen()
+int imtlen(), imtgetim()
+
+begin
+ call smark (sp)
+ call salloc (fname, SZ_PATHNAME, TY_CHAR)
+
+ # Initialize row counter.
+ rowc = row
+ rflag = false
+ if (rowc <= 0 || IS_INDEFI(rowc)) rflag = true
+
+ # Initialize successful image counter.
+ imc = 0
+
+ # Open input list.
+ list = imtopen (imlist)
+
+ # Loop over input list.
+ do image = 1, imtlen(list) {
+
+ # Get input image name and open it. Skip if error.
+ i = imtgetim (list, Memc[fname], SZ_PATHNAME)
+ iferr (im = immap (Memc[fname], READ_ONLY, 0)) {
+ call erract (EA_WARN)
+ next
+ }
+ if (verbose) {
+ call printf ("%s ")
+ call pargstr (Memc[fname])
+ call flush (STDOUT)
+ }
+
+ # Look into image header for columnar info and do the copy.
+ if (mode == MODE_OUT_ALL || mode == MODE_TEM_ALL) {
+ iferr (call tm_hc (tp, cp, ncp, rowc, rflag, im)) {
+ call erract (EA_WARN)
+ call imunmap (im)
+ next
+ }
+
+ # Bump row and image counters.
+ rowc = rowc + 1
+ imc = imc + 1
+
+ # Just copy into single column.
+ } else if (mode == MODE_OUT_SINGLE || mode == MODE_TEM_SINGLE) {
+ iferr (call tm_copy (tp, Memi[cp], rowc, rflag, im)) {
+ call erract (EA_WARN)
+ call imunmap (im)
+ next
+ }
+
+ # Bump row and image counters.
+ rowc = rowc + 1
+ imc = imc + 1
+ }
+
+ if (verbose) {
+ call printf ("-> %s row=%d \n")
+ call pargstr (outname)
+ call pargi (rowc-1)
+ call flush (STDOUT)
+ }
+
+ # Close current image.
+ call imunmap (im)
+ }
+
+ call imtclose (list)
+ call sfree (sp)
+ if (imc == 0)
+ call error (1, "No images were inserted.")
+end
diff --git a/pkg/utilities/nttools/threed/tiimage/tmmode.x b/pkg/utilities/nttools/threed/tiimage/tmmode.x
new file mode 100644
index 00000000..0f159763
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmmode.x
@@ -0,0 +1,108 @@
+include <tbset.h>
+include "tiimage.h"
+
+# TM_MODE -- Detect mode of operation.
+#
+# There are five possible modes:
+# 1 - Output table exists and one column was selected.
+# 2 - Output table exists and no valid column was selected.
+# 3 - Output table does not exist but template exists and one column was
+# selected.
+# 4 - Output table does not exist but template exists and no valid column
+# was selected.
+# 5 - New table has to be created from scratch.
+#
+#
+#
+# Revision history:
+# ----------------
+# 30-Jan-97 - Task created (I.Busko)
+# 8-Apr-02 - Remove the call to whatfile (P. Hodge)
+
+
+int procedure tm_mode (output, template, root, rs, cs, cn, cu, cf)
+
+char output[SZ_PATHNAME]
+char template[SZ_PATHNAME]
+char root[SZ_FNAME]
+char rs[SZ_FNAME]
+char cs[SZ_FNAME]
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+#-
+int mode
+
+int access(), tm_m1()
+
+begin
+ # Process output name. Notice that routine access() must be
+ # supplied with only the root name in order to succeed.
+ call rdselect (output, root, rs, cs, SZ_PATHNAME)
+ if (access (root, READ_WRITE, 0) == YES) {
+ mode = tm_m1 (OUTPUT_TYPE, root,rs,cs,cn,cu,cf)
+ if (mode == MODE_ERROR)
+ call error (1, "Cannot use output file.")
+
+ # If no valid output, try with template name.
+ } else {
+ call rdselect (template, root, rs, cs, SZ_PATHNAME)
+ if (access (root, READ_ONLY, 0) == YES) {
+ mode = tm_m1 (TEMPLATE_TYPE, root, rs, cs, cn, cu, cf)
+ if (mode == MODE_ERROR)
+ call error (1, "Cannot use template file.")
+ } else {
+ mode = MODE_SCRATCH
+ }
+ }
+
+ return (mode)
+end
+
+
+# TM_M1 -- Verify status of file and column selector.
+
+int procedure tm_m1 (type, root, rs, cs, cn, cu, cf)
+
+int type
+char root[SZ_FNAME]
+char rs[SZ_FNAME]
+char cs[SZ_FNAME]
+char cn[SZ_COLNAME]
+char cu[SZ_COLUNITS]
+char cf[SZ_COLFMT]
+#-
+pointer tp, cp
+int numcol, ncp
+
+pointer tbtopn()
+int tbpsta()
+
+begin
+ # Open table
+ tp = tbtopn (root, READ_ONLY, 0)
+
+ # Get its total number of columns.
+ numcol = tbpsta (tp, TBL_NCOLS)
+
+ # Create array of column pointers from column selector.
+ # This is just to get the actual number of selected columns.
+ call malloc (cp, numcol, TY_INT)
+ call tcs_open (tp, cs, Memi[cp], ncp, numcol)
+ call tbtclo (tp)
+ call mfree (cp, TY_INT)
+
+ # Decide mode.
+ if (type == OUTPUT_TYPE) {
+ if (ncp == 1)
+ return (MODE_OUT_SINGLE)
+ else
+ return (MODE_OUT_ALL)
+ } else if (type == TEMPLATE_TYPE) {
+ if (ncp == 1)
+ return (MODE_TEM_SINGLE)
+ else
+ return (MODE_TEM_ALL)
+ }
+ return (MODE_ERROR)
+end
diff --git a/pkg/utilities/nttools/threed/tiimage/tmscan.x b/pkg/utilities/nttools/threed/tiimage/tmscan.x
new file mode 100644
index 00000000..31af8c02
--- /dev/null
+++ b/pkg/utilities/nttools/threed/tiimage/tmscan.x
@@ -0,0 +1,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