diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /pkg/utilities/nttools/tdiffer | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/utilities/nttools/tdiffer')
-rw-r--r-- | pkg/utilities/nttools/tdiffer/mkpkg | 12 | ||||
-rw-r--r-- | pkg/utilities/nttools/tdiffer/tbldiff.x | 99 | ||||
-rw-r--r-- | pkg/utilities/nttools/tdiffer/tdiffer.x | 92 |
3 files changed, 203 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/tdiffer/mkpkg b/pkg/utilities/nttools/tdiffer/mkpkg new file mode 100644 index 00000000..93240165 --- /dev/null +++ b/pkg/utilities/nttools/tdiffer/mkpkg @@ -0,0 +1,12 @@ +# Update the tdiffer application code in the ttools package library +# Author: B.Simon, 14-JUN-88 + +$checkout libpkg.a ../ +$update libpkg.a +$checkin libpkg.a ../ +$exit + +libpkg.a: + tbldiff.x <tbset.h> + tdiffer.x <tbset.h> + ; diff --git a/pkg/utilities/nttools/tdiffer/tbldiff.x b/pkg/utilities/nttools/tdiffer/tbldiff.x new file mode 100644 index 00000000..b6ee7db4 --- /dev/null +++ b/pkg/utilities/nttools/tdiffer/tbldiff.x @@ -0,0 +1,99 @@ +include <tbset.h> + +# TBL_DIFF -- Find rows in the first table which are not in the second +# +# B.Simon 15-Jun-88 First Code +# B.Simon 05-Feb-90 Revised to use tbtsrt and tbrcmp + +procedure tbl_diff (tp1, tp2, otp, nptr, col1, col2) + +pointer tp1 # i: Table descriptor of first input table +pointer tp2 # i: Table descriptor of second input table +pointer otp # i: Output table descriptor +int nptr # i: Number of column pointers +pointer col1[ARB] # i: Array of column pointers for first table +pointer col2[ARB] # i: Array of column pointers for second table +#-- +bool fold +int irow1, irow2, nrow1, nrow2, order, orow, iptr +pointer sp, colname, row1, row2, ocol + +int tbrcmp() + +begin + # Allocate dynamic memory for column name + + call smark (sp) + call salloc (colname, SZ_COLNAME, TY_CHAR) + + # Sort the array on the selected columns. + + fold = false + call allrows (tp1, nrow1, row1) + call allrows (tp2, nrow2, row2) + + call tbtsrt (tp1, nptr, col1, fold, nrow1, Memi[row1]) + call tbtsrt (tp2, nptr, col2, fold, nrow2, Memi[row2]) + + # Get the column pointers to compare on in the output tables + + call malloc (ocol, nptr, TY_INT) + do iptr = 1, nptr { + call tbcigt (col1[iptr], TBL_COL_NAME, Memc[colname], SZ_COLNAME) + call tbcfnd (otp, Memc[colname], Memi[ocol+iptr-1], 1) + } + + # Search for rows in first table which are not in the second + + orow = 1 + irow1 = 0 + irow2 = 0 + + while (irow1 < nrow1 && irow2 < nrow2) { + + # Copy rows from both tables into output table + + call tbrcpy (tp1, otp, Memi[row1+irow1], orow) + call tbrcsc (tp2, otp, col2, Memi[ocol], Memi[row2+irow2], + orow+1, nptr) + + # Update row indices and add row1 to output table + # if it is not in the second table + + order = tbrcmp (otp, nptr, Memi[ocol], fold, orow, orow+1) + + switch (order) { + case -1: + irow1 = irow1 + 1 + orow = orow + 1 + case 0: + irow1 = irow1 + 1 + case 1: + irow2 = irow2 + 1 + } + } + + # Delete extra rows from output table + + if (order < 0) + call tbrdel (otp, orow, orow) + else + call tbrdel (otp, orow, orow+1) + + # Add remaining rows of first table to output table + + while (irow1 < nrow1) { + call tbrcpy (tp1, otp, Memi[row1+irow1], orow) + irow1 = irow1 + 1 + orow = orow + 1 + } + + + # Free dynamic memory + + call mfree (row1, TY_INT) + call mfree (row2, TY_INT) + call mfree (ocol, TY_INT) + call sfree (sp) + +end diff --git a/pkg/utilities/nttools/tdiffer/tdiffer.x b/pkg/utilities/nttools/tdiffer/tdiffer.x new file mode 100644 index 00000000..9c30e82f --- /dev/null +++ b/pkg/utilities/nttools/tdiffer/tdiffer.x @@ -0,0 +1,92 @@ +include <tbset.h> + +define SYNTAX 1 + +# TDIFFER -- Create a new table which is the difference of two old tables +# +# B.Simon 14-Jun-1988 First Code +# Phil Hodge 7-Sep-1988 Change parameter names for tables. +# Phil Hodge 8-Apr-1999 Call tbfpri. + +procedure t_tdiffer() + +pointer tab1 # First table +pointer tab2 # Second table +pointer outtab # Output table +pointer colnam1 # Columns to match in first table +pointer colnam2 # Columns to match in second table +#-- +int nptr1, nptr2, ncol1, ncol2 +int phu_copied # set by tbfpri and ignored +pointer sp, tp1, tp2, otp, col1, col2 + +string notfound "Column(s) not found in table" +string colnumerr "Number of columns do not agree" + +int tbpsta() +pointer tbtopn() + +begin + # Allocate stack memory for strings + + call smark (sp) + call salloc (tab1, SZ_FNAME, TY_CHAR) + call salloc (tab2, SZ_FNAME, TY_CHAR) + call salloc (outtab, SZ_FNAME, TY_CHAR) + call salloc (colnam1, SZ_LINE, TY_CHAR) + call salloc (colnam2, SZ_LINE, TY_CHAR) + + # Read the task parameters + + call clgstr ("intable1", Memc[tab1], SZ_LINE) + call clgstr ("intable2", Memc[tab2], SZ_LINE) + call clgstr ("outtable", Memc[outtab], SZ_LINE) + call clgstr ("colnam1", Memc[colnam1], SZ_LINE) + call clgstr ("colnam2", Memc[colnam2], SZ_LINE) + + # Open the tables and create column arrays + + tp1 = tbtopn (Memc[tab1], READ_ONLY, NULL) + ncol1 = tbpsta (tp1, TBL_NCOLS) + call malloc (col1, ncol1, TY_INT) + + tp2 = tbtopn (Memc[tab2], READ_ONLY, NULL) + ncol2 = tbpsta (tp2, TBL_NCOLS) + call malloc (col2, ncol2, TY_INT) + + # Open output table and copy header(s) from first table + + call tbfpri (Memc[tab1], Memc[outtab], phu_copied) + otp = tbtopn (Memc[outtab], NEW_COPY, tp1) + call tbtcre (otp) + call tbhcal (tp1, otp) + + # Create two arrays of column pointers from the column templates + + call tctexp (tp1, Memc[colnam1], ncol1, nptr1, Memi[col1]) + if (nptr1 == 0) + call error (SYNTAX, notfound) + + call tctexp (tp2, Memc[colnam2], ncol2, nptr2, Memi[col2]) + if (nptr2 == 0) + call error (SYNTAX, notfound) + + if (nptr1 != nptr2) + call error (SYNTAX, colnumerr) + + # Retrieve the indices of the rows of the first table which are + # not in the second table + + call tbl_diff (tp1, tp2, otp, nptr1, Memi[col1], Memi[col2]) + + # Close the tables and free dynamic memory + + call tbtclo (tp1) + call tbtclo (tp2) + call tbtclo (otp) + + call mfree (col1, TY_INT) + call mfree (col2, TY_INT) + + call sfree (sp) +end |