aboutsummaryrefslogtreecommitdiff
path: root/pkg/dataio/imtext/rt_cvtpix.x
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /pkg/dataio/imtext/rt_cvtpix.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/dataio/imtext/rt_cvtpix.x')
-rw-r--r--pkg/dataio/imtext/rt_cvtpix.x115
1 files changed, 115 insertions, 0 deletions
diff --git a/pkg/dataio/imtext/rt_cvtpix.x b/pkg/dataio/imtext/rt_cvtpix.x
new file mode 100644
index 00000000..170a26d4
--- /dev/null
+++ b/pkg/dataio/imtext/rt_cvtpix.x
@@ -0,0 +1,115 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <imhdr.h>
+include "imtext.h"
+
+# RT_CONVERT_PIXELS -- Called once for each text file to be converted. All
+# pixels in the text file are converted to image pixels.
+
+procedure rt_convert_pixels (tf, im, format, pixels)
+
+int tf # File descriptor of input text file
+pointer im # Pointer to image header
+int format # Format of text pixels (integer/floating point)
+int pixels # Get pixels from input text file?
+
+pointer bufptr, sp, word1, pattern
+int stat, nlines, npix, i
+long v[IM_MAXDIM], start
+int impnll(), impnld(), impnlx()
+int fscan(), stridxs(), patmatch(), patmake()
+long note()
+
+errchk impnll, impnld, impnlx
+errchk rt_get_lineptr, rt_output_line, fscan, seek, amovkl
+
+begin
+ # Determine if text file pixels were written with an integer, complex
+ # or floating point format. This information may have been already
+ # determined from the header. If not, the first pixel is read
+ # from text file. If it contains a decimal point, the character E,
+ # or a + or - sign not in the first position, it is a floating point
+ # number. Complex numbers are assumed to be written as "(r,i)".
+
+ if (pixels == YES && format == UNSET) {
+ call smark (sp)
+ call salloc (word1, SZ_LINE, TY_CHAR)
+ call salloc (pattern, SZ_LINE, TY_CHAR)
+
+ # Note position so we can return to it
+ start = note (tf)
+
+ stat = fscan (tf)
+ call gargwrd (Memc[word1], SZ_LINE)
+ if (patmake ("[DdEe]", Memc[pattern], SZ_LINE) == ERR)
+ call error (7, "Error creating format pattern")
+
+ if (stridxs ("(", Memc[word1]) > 0)
+ format = CPX_FORM
+ else if (stridxs (".", Memc[word1]) > 0)
+ format = FP_FORM
+ else if (patmatch (Memc[word1], Memc[pattern]) > 0)
+ format = FP_FORM
+ else if (stridxs ("+", Memc[word1]) > 1)
+ format = FP_FORM
+ else if (stridxs ("-", Memc[word1]) > 1)
+ format = FP_FORM
+ else
+ format = INT_FORM
+
+ call sfree (sp)
+ call seek (tf, start)
+ }
+
+ # Pixel type may not have been set by this point either...
+ if (IM_PIXTYPE(im) == UNSET) {
+ switch (format) {
+ case FP_FORM:
+ IM_PIXTYPE(im) = TY_REAL
+ case INT_FORM:
+ IM_PIXTYPE(im) = TY_INT
+ case CPX_FORM:
+ IM_PIXTYPE(im) = TY_COMPLEX
+ default:
+ call error (0, "Unrecognized format type")
+ }
+ }
+
+ nlines = 1
+ do i = 2, IM_NDIM(im)
+ nlines = nlines * IM_LEN (im, i)
+ call amovkl (long(1), v, IM_MAXDIM)
+ npix = IM_LEN (im, 1)
+
+ # Initialize text buffer
+ call rt_rinit
+
+ switch (IM_PIXTYPE(im)) {
+ case TY_SHORT, TY_INT, TY_USHORT, TY_LONG:
+ do i = 1, nlines {
+ stat = impnll (im, bufptr, v)
+ if (pixels == YES)
+ call rt_output_linel (tf, format, bufptr, npix)
+ else
+ call aclrl (Meml[bufptr], npix)
+ }
+ case TY_REAL, TY_DOUBLE:
+ do i = 1, nlines {
+ stat = impnld (im, bufptr, v)
+ if (pixels == YES)
+ call rt_output_lined (tf, format, bufptr, npix)
+ else
+ call aclrd (Memd[bufptr], npix)
+ }
+ case TY_COMPLEX:
+ do i = 1, nlines {
+ stat = impnlx (im, bufptr, v)
+ if (pixels == YES)
+ call rt_output_linex (tf, format, bufptr, npix)
+ else
+ call aclrx (Memx[bufptr], npix)
+ }
+ default:
+ call error (0, "Image pixel type unset")
+ }
+end