diff options
Diffstat (limited to 'pkg/utilities/nttools/stxtools/od')
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/mkpkg | 15 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/od.h | 32 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odget.x | 56 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odmap.x | 250 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odopep.x | 56 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odpare.x | 84 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odput.x | 50 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odsetn.x | 29 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odunmp.x | 44 | ||||
-rw-r--r-- | pkg/utilities/nttools/stxtools/od/odwcsn.x | 39 |
10 files changed, 655 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/stxtools/od/mkpkg b/pkg/utilities/nttools/stxtools/od/mkpkg new file mode 100644 index 00000000..a72fbad9 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/mkpkg @@ -0,0 +1,15 @@ +$checkout libpkg.a ../ +$update libpkg.a +$checkin libpkg.a ../ +$exit + +libpkg.a: + odget.x "od.h" + odmap.x <error.h> <imhdr.h> <imio.h> <tbset.h> "od.h" + odopep.x "od.h" + odpare.x + odput.x "od.h" + odsetn.x <imhdr.h> "od.h" + odunmp.x "od.h" + odwcsn.x <mwset.h> "od.h" + ; diff --git a/pkg/utilities/nttools/stxtools/od/od.h b/pkg/utilities/nttools/stxtools/od/od.h new file mode 100644 index 00000000..2070d551 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/od.h @@ -0,0 +1,32 @@ +#--------------------------------------------------------------------------- +.help od.h Feb93 source +.ih +NAME +od.h -- Include parameters for the 1D I/O data system. +.endhelp +#--------------------------------------------------------------------------- +#----- +# Below describes the structure and access to the OD descriptor. +define OD_FD Memi[$1] # The image/table descriptor +define OD_TYPE Memi[$1+1] # TABLE/IMAGE flag. +define OD_CD_PTR Memi[$1+2] # Table column descriptor. +define OD_CD Memi[OD_CD_PTR($1)+$2-1] +define OD_LEN Memi[$1+3] # Dimension of the data. +define OD_NGRP Memi[$1+4] # Number of groups in image. +define OD_GRP Memi[$1+5] # Current open group. +define OD_NAME_PTR Memi[$1+6] # Specified file name. +define OD_NAME Memc[OD_NAME_PTR($1)] +define OD_MW Memi[$1+7] # MWCS descriptor. +define OD_WL Memi[$1+8] # World-to-Logical transformation. +define OD_LW Memi[$1+9] # Logical-to-World transformation. +define OD_WSYS_PTR Memi[$1+10] # WCS system type. +define OD_WSYS Memc[OD_WSYS_PTR($1)] +define OD_OLD Memi[$1+11] # Template which opened this OD. +define OD_SZ_OD 12 # Size of structure. + +# The flag of what type of file we are dealing with. +define OD_TABLE 1 +define OD_IMAGE 2 +#--------------------------------------------------------------------------- +# End of od.h +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odget.x b/pkg/utilities/nttools/stxtools/od/odget.x new file mode 100644 index 00000000..013acc67 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odget.x @@ -0,0 +1,56 @@ +include "od.h" + +#--------------------------------------------------------------------------- +.help od_get Feb93 source +.ih +NAME +od_get -- Retrieve data from file. +.ih +USAGE +.nf +call od_getd (od, data) +.fi +.ih +ARGUMENTS +.ls od (pointer :input) +The OD I/O descriptor. +.le +.ls data (double[ARB] :output) +The data from the OD file. +.le +.endhelp +#--------------------------------------------------------------------------- +procedure od_get (od, data) + +pointer od # I: The OD I/O descriptor. +double data[ARB] # O: The data. + +pointer null # Null flag array for table IO. + +# Functions +pointer imgl1d() + +errchk gf_opengr, imgl1d, malloc, mfree, tbcgtd + +begin + # Check if a file is actually opened. If not, do nothing. + if (od != NULL) { + + # Get data depending on file type. + switch (OD_TYPE(od)) { + case OD_TABLE: + call malloc (null, OD_LEN(od), TY_BOOL) + call tbcgtd (OD_FD(od), OD_CD(od,OD_GRP(od)), data, Memb[null], + 1, OD_LEN(od)) + call mfree (null, TY_BOOL) + + case OD_IMAGE: + + # Retrieve the data. + call amovd (Memd[imgl1d(OD_FD(od))], data, OD_LEN(od)) + } + } +end +#--------------------------------------------------------------------------- +# End of od_get +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odmap.x b/pkg/utilities/nttools/stxtools/od/odmap.x new file mode 100644 index 00000000..f41ad5e1 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odmap.x @@ -0,0 +1,250 @@ +include <error.h> +include <imhdr.h> +include <imio.h> +include <tbset.h> +include "od.h" + +# Define the default column number to retrieve table data from +define DEFAULT_COL 1 + +#--------------------------------------------------------------------------- +.help od_map Feb93 source +.ih +NAME +.nf +od_map -- Open a file as either an image or table. + +od_image_map -- Internal: Map an image. +od_table_map -- Internal: Map a table. +.fi +.ih +USAGE +.nf +od = od_map (name, mode, old) + +call od_image_map (name, od) +call od_table_map (name, mode, od) +.fi +.ih +ARGUMENTS +.ls name (char[ARB] :input) +The name of the file to open. +.le +.ls mode (int :input) +The access mode to open the file in. Same as the standard IRAF open +modes. +.le +.ls old (pointer :input) +If creating a new file, use this as a template. If NULL, no template will +be assumed. This is the OD descriptor, not an IMIO or TABLE descriptor. +.le +.ls od (pointer :input) +The OD I/O descriptor. +.le +.ih +RETURNS +An od i/o file descriptor containing the image/table descriptor, a flag +indicating whether it is an image or table, and, if a table, the column +descriptor to retrieve the data from. +.ih +DESCRIPTION +This provides a common interface to retrieve one dimensional data from +either an image or a table. This is vary basic and is not intended to +handle a full i/o interface. Just need to open, close, and read data. + +Added some syntax to the table name specification. We will allow the +column names/numbers to be specified in a "section" notation. An +example: + +.nf + tablename[columnname1,...] +.fi + +where columnnameX are either names or numbers. If no column +specification is used, then it is assumed all columns of the table are +to be used and will be considered with the appropriate "group" of +multigroup input. +.endhelp +#--------------------------------------------------------------------------- +pointer procedure od_map(name, mode, old) + +char name[ARB] # I: The file name to open. +int mode # I: The mode to open the file in. +pointer old # I: Template OD I/O descriptor as template. + +# Declarations. +pointer od # OD I/O descriptor. +pointer sp # Stack Pointer. +pointer sx # Generic string. + +# Function prototypes +pointer immap() + +errchk malloc, od_image_map, od_table_map + +begin + call smark (sp) + call salloc (sx, SZ_LINE, TY_CHAR) + + # Allocate the od i/o descriptor. + call malloc (od, OD_SZ_OD, TY_STRUCT) + call malloc (OD_NAME_PTR(od), SZ_LINE, TY_CHAR) + call malloc (OD_WSYS_PTR(od), SZ_LINE, TY_CHAR) + + # If an old descriptor is given, base what open occurs on + # its type. + OD_OLD(od) = old + if (old != NULL) + switch (OD_TYPE(old)) { + case OD_IMAGE: + OD_FD(od) = immap (name, mode, OD_FD(old)) + call od_image_map (name, od) + case OD_TABLE: + call od_table_map (name, mode, OD_FD(old), od) + } + + # Else, just open up that data file. If the image call doesn't fail, + # then assume its an image. + else ifnoerr (OD_FD(od) = immap (name, mode, NULL)) + call od_image_map (name, od) + + # If it cannot be opened as a table, try changing the extension. + # If that fails, then give it up. + else iferr (call od_table_map (name, mode, NULL, od)) { + call change_ext (name, "c1h", Memc[sx], SZ_LINE) + iferr (OD_FD(od) = immap (Memc[sx], mode, NULL)) { + call erract (EA_ERROR) + } + call od_image_map (Memc[sx], od) + } + + # That's all folks. + call sfree (sp) + return (od) +end +#--------------------------------------------------------------------------- +# End of od_map +#--------------------------------------------------------------------------- +procedure od_image_map (name, od) + +char name[ARB] # I: Full specified name. +pointer od # I: OD I/O descriptor. + +# Declarations. +int i # Generic. + +pointer sp # Stack pointer. +pointer sx + +begin + call smark (sp) + call salloc (sx, SZ_LINE, TY_CHAR) + + # Fill the OD I/O descriptor. + OD_TYPE(od) = OD_IMAGE + OD_CD_PTR(od) = NULL + OD_LEN(od) = IM_LEN(OD_FD(od),1) + OD_NGRP(od) = max(1,IM_CLSIZE(OD_FD(od))) + call strcpy (IM_HDRFILE(OD_FD(od)), OD_NAME(od), SZ_LINE) + + # See whether a specific group was opened. + call fparse (name, Memc[sx], SZ_LINE, Memc[sx], SZ_LINE, Memc[sx], + SZ_LINE, OD_GRP(od), i, Memc[sx], SZ_LINE, Memc[sx], + SZ_LINE) + if (OD_GRP(od) > 0) + OD_NGRP(od) = 1 + else + OD_GRP(od) = 1 + + # Get world coordinate information. + call od_wcs_open (od) + + # That's all folks. + call sfree (sp) +end +#--------------------------------------------------------------------------- +# End of od_image_map +#--------------------------------------------------------------------------- +procedure od_table_map (name, mode, old, od) + +char name[ARB] # I: The specified file name. +int mode # I: The file access mode. +pointer old # I: Original OD descriptor. +pointer od # I: The OD I/O descriptor. + +# Declarations. +int i, j, k # Generic. +int ic # Pointer into section list. + +pointer colname # Current column name. +pointer section # Section specification. +pointer sp # Stack pointer. +pointer sx # Generic. + +# Functions. +int ctoi(), strlen(), word_count(), word_fetch(), tbpsta() +pointer tbcnum(), tbtopn() + +errchk tbcnum, tbpsta, tbtopn, word_count, word_fetch + +begin + call smark (sp) + call salloc (colname, SZ_LINE, TY_CHAR) + call salloc (section, SZ_LINE, TY_CHAR) + call salloc (sx, SZ_LINE, TY_CHAR) + + # Set what type of file. + OD_TYPE(od) = OD_TABLE + + # Get the base filename and section. + call od_parse (name, OD_NAME(od), SZ_LINE, Memc[section], SZ_LINE) + + # Open up and get some parameters. + OD_FD(od) = tbtopn (OD_NAME(od), mode, old) + OD_LEN(od) = tbpsta (OD_FD(od), TBL_NROWS) + OD_GRP(od) = 1 + OD_MW(od) = NULL + OD_WL(od) = NULL + OD_LW(od) = NULL + + # Now retrieve the columns. If no columns are specified, then use + # all the columns. + if (strlen (Memc[section]) <= 0) { + OD_NGRP(od) = tbpsta (OD_FD(od), TBL_NCOLS) + call malloc (OD_CD_PTR(od), OD_NGRP(od), TY_POINTER) + do i = 1, OD_NGRP(od) { + OD_CD(od,i) = tbcnum (OD_FD(od), i) + if (OD_CD(od,i) == NULL) { + call sprintf (Memc[sx], SZ_LINE, "Cannot open column %d in table %s") + call pargi (i) + call pargstr (OD_NAME(od)) + call error (1, Memc[sx]) + } + } + } else { + OD_NGRP(od) = word_count (Memc[section]) + call malloc (OD_CD_PTR(od), OD_NGRP(od), TY_POINTER) + i = 0 + ic = 1 + while (word_fetch (Memc[section], ic, Memc[colname], SZ_LINE) > 0) { + i = i + 1 + k = 1 + if (ctoi (Memc[colname], k, j) > 0) + OD_CD(od,i) = tbcnum (OD_FD(od), j) + else + call tbcfnd (OD_FD(od), Memc[colname], OD_CD(od,i), 1) + } + if (OD_CD(od,i) == NULL) { + call sprintf (Memc[sx], SZ_LINE, "Cannot open column %s in table %s") + call pargstr (Memc[colname]) + call pargstr (OD_NAME(od)) + call error (1, Memc[sx]) + } + } + + # That's all folks. + call sfree (sp) +end +#--------------------------------------------------------------------------- +# End of od_table_map +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odopep.x b/pkg/utilities/nttools/stxtools/od/odopep.x new file mode 100644 index 00000000..cd757f93 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odopep.x @@ -0,0 +1,56 @@ +include "od.h" + +#--------------------------------------------------------------------------- +.help od_open_group 11Jul95 source +.ih +NAME +od_open_group -- Open another "group" of the file +.ih +USAGE +call od_open_group (od, group) +.fi +.ih +ARGUMENTS +.ls od (pointer :input) +The OD I/O descriptor. +.le +.ls group (int :input) +The "group" to open. For tables, this means the column number to open. +.le +.endhelp +#--------------------------------------------------------------------------- +procedure od_open_group (od, group) + +pointer od # I: The 1D descriptor. +int group # I: The group to open. + +# Misc. +real rx # Generic. + +errchk gf_opengr, mw_close, od_wcs_open + +begin + switch (OD_TYPE(od)) { + case OD_TABLE: + if (group > OD_NGRP(od)) + call error (1, "Attempt to open non-existant column") + OD_GRP(od) = group + + case OD_IMAGE: + if (group > OD_NGRP(od)) + call error (1, "Attempt to open non-existant group") + + call mw_close (OD_MW(od)) + + if (OD_OLD(od) != NULL) + call gf_opengr (OD_FD(od), group, rx, rx, OD_FD(OD_OLD(od))) + else + call gf_opengr (OD_FD(od), group, rx, rx, NULL) + OD_GRP(od) = group + + call od_wcs_open (od) + } +end +#--------------------------------------------------------------------------- +# End of od_open_group +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odpare.x b/pkg/utilities/nttools/stxtools/od/odpare.x new file mode 100644 index 00000000..0bea6112 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odpare.x @@ -0,0 +1,84 @@ +#--------------------------------------------------------------------------- +.help od_parse Feb93 source +.ih +NAME +od_parse -- Parse a section for column names. +.ih +USAGE +call od_parse +.ih +ARGUMENTS +.ih +DESCRIPTION +Taken from Bernie Simon's aspare without any modifications. +.endhelp +#--------------------------------------------------------------------------- +#* HISTORY * +#* D.Ball 18-Apr-88 original +#* B.Simon 06-Aug-92 removed code which deletes commas + +# OD_PARSE -- Parse a file name specification into file name and section fields +# +# Syntax: filename[section] +# +# The [ character must be escaped to be included in the filename. +# This syntax is similar to the image section syntax in imio, but +# is intended to extract variable names or numbers, column names, etc. +# for the Astronomical Survival analysis suite of programs. +# The section field is returned as a string with no leading or trailing +# brackets. + +procedure od_parse (filespec, file, sz_file, section, sz_section) + +char filespec[ARB] # i: full file specification +char file[sz_file] # o: receives file name +int sz_file # i: max chars in file name +char section[sz_section] # o: receives section +int sz_section # i: max chars in section name +#-- +int ch, ip, op, right + +int strlen() + +begin + ip = 1 + op = 1 + + # Extract file name. The first (unescaped) [ marks the start of + # the section field. + + for (ch=filespec[ip]; ch != EOS && ch != '['; ch=filespec[ip]) { + if (ch == '\\' && filespec[ip+1] == '[') { + file[op] = '\\' + op = op + 1 + file[op] = '[' + ip = ip + 1 + } else + file[op] = ch + + op = min (sz_file, op + 1) + ip = ip + 1 + } + + file[op] = EOS + section[1] = EOS + + if (ch == EOS) + return + + # If we have a [...] field, copy the section string, + # removing the brackets, and any commas used as delimiters. + + # Eliminate the leading "[" + ip = ip + 1 + call strcpy (filespec[ip], section, sz_section) + + # Remove the trailing "]" + right = strlen (section) + if (section[right] == ']') + section[right] = EOS + +end +#--------------------------------------------------------------------------- +# End of od_parse +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odput.x b/pkg/utilities/nttools/stxtools/od/odput.x new file mode 100644 index 00000000..d02f59a5 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odput.x @@ -0,0 +1,50 @@ +include "od.h" + +#--------------------------------------------------------------------------- +.help od_put Feb93 source +.ih +NAME +od_put -- Put the data in the file. +.ih +USAGE +.nf +call od_putd (od, data) +.fi +.ih +ARGUMENTS +.ls od (input: pointer) +The OD I/O descriptor. +.le +.ls data (input: double[ARB]) +The data to put in the OD file. +.le +.endhelp +#--------------------------------------------------------------------------- +procedure od_put (od, data) + +pointer od # I: The OD I/O descriptor. +double data[ARB] # I: The data. + +# Functions +pointer impl1d() + +errchk impl1d, tbcptd + +begin + # Check if a file is actually opened. If not, do nothing. + if (od != NULL) { + + # Get data depending on file type. + switch (OD_TYPE(od)) { + case OD_TABLE: + call tbcptd (OD_FD(od), OD_CD(od,OD_GRP(od)), data, + 1, OD_LEN(od)) + + case OD_IMAGE: + call amovd (data, Memd[impl1d (OD_FD(od))], OD_LEN(od)) + } + } +end +#--------------------------------------------------------------------------- +# End of od_put +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odsetn.x b/pkg/utilities/nttools/stxtools/od/odsetn.x new file mode 100644 index 00000000..3abf97f7 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odsetn.x @@ -0,0 +1,29 @@ +include <imhdr.h> +include "od.h" + +#--------------------------------------------------------------------------- +.help od_set_len Jun93 source +.ih +NAME +od_set_len -- Set the length of data. +.ih +DESCRIPTION +This sets how much data is read/written from the OD file. For images, +the dimensionality is changed. For tables, it just changes how much +is read/written; nothing is physically changed about the table. +.endhelp +#--------------------------------------------------------------------------- +procedure od_set_len (od, len) + +pointer od # I: OD descriptor. +int len # I: New length. + +begin + OD_LEN(od) = len + if (OD_TYPE(od) == OD_IMAGE) { + IM_LEN(OD_FD(od),1) = len + } +end +#--------------------------------------------------------------------------- +# End of od_set_len +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odunmp.x b/pkg/utilities/nttools/stxtools/od/odunmp.x new file mode 100644 index 00000000..e776ecd7 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odunmp.x @@ -0,0 +1,44 @@ +include "od.h" + +#--------------------------------------------------------------------------- +.help od_unmap Feb93 source +.ih +NAME +od_unmap -- Close the 1D image. +.ih +USAGE +call od_unmap (od) +.ih +ARGUMENTS +.ls od (input/output: pointer) +The OD I/O descriptor. On return, the value will be NULL. +.le +.endhelp +#--------------------------------------------------------------------------- +procedure od_unmap (od) + +pointer od # I: The OD I/O descriptor. + +errchk tbtclo, imunmap, mfree + +begin + if (od != NULL) { + switch (OD_TYPE(od)) { + case OD_TABLE: + call tbtclo (OD_FD(od)) + call mfree (OD_CD_PTR(od), TY_POINTER) + case OD_IMAGE: + call mw_ctfree (OD_WL(od)) + call mw_ctfree (OD_LW(od)) + call mw_close (OD_MW(od)) + call imunmap (OD_FD(od)) + } + + call mfree (OD_WSYS_PTR(od), TY_CHAR) + call mfree (OD_NAME_PTR(od), TY_CHAR) + call mfree (od, TY_STRUCT) + } +end +#--------------------------------------------------------------------------- +# End of od_unmap +#--------------------------------------------------------------------------- diff --git a/pkg/utilities/nttools/stxtools/od/odwcsn.x b/pkg/utilities/nttools/stxtools/od/odwcsn.x new file mode 100644 index 00000000..e79a4154 --- /dev/null +++ b/pkg/utilities/nttools/stxtools/od/odwcsn.x @@ -0,0 +1,39 @@ +include <mwset.h> +include "od.h" + +#--------------------------------------------------------------------------- +.help od_wcs_open May93 source +.ih +NAME +od_wcs_open -- Open the WCS information for an image. +.endhelp +#--------------------------------------------------------------------------- +procedure od_wcs_open (od) + +pointer od # I: Image descriptor. + +pointer mw_openim() +pointer mw_sctran() +bool streq() + +begin + if (OD_TYPE(od) == OD_IMAGE) { + OD_MW(od) = mw_openim (OD_FD(od)) + call mw_gwattrs (OD_MW(od), 0, "system", OD_WSYS(od), SZ_LINE) + if (streq ("multispec", OD_WSYS(od))) { + call mw_seti (OD_MW(od), MW_USEAXMAP, NO) + OD_WL(od) = mw_sctran (OD_MW(od), "multispec", "logical", 3b) + OD_LW(od) = mw_sctran (OD_MW(od), "logical", "multispec", 3b) + } else { + OD_WL(od) = mw_sctran (OD_MW(od), "world", "logical", 1) + OD_LW(od) = mw_sctran (OD_MW(od), "logical", "world", 1) + } + } else { + OD_MW(od) = NULL + OD_LW(od) = NULL + OD_WL(od) = NULL + } +end +#--------------------------------------------------------------------------- +# End of od_wcs_open +#--------------------------------------------------------------------------- |