aboutsummaryrefslogtreecommitdiff
path: root/pkg/plot/crtpict/tweakndc.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/plot/crtpict/tweakndc.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/plot/crtpict/tweakndc.x')
-rw-r--r--pkg/plot/crtpict/tweakndc.x66
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/plot/crtpict/tweakndc.x b/pkg/plot/crtpict/tweakndc.x
new file mode 100644
index 00000000..1a8f674b
--- /dev/null
+++ b/pkg/plot/crtpict/tweakndc.x
@@ -0,0 +1,66 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# CRT_TWEAK_NDC -- Alter the input ndc endpoints so that the ratio
+# of device_pixels to image_pixels is an integer. This procedure insures
+# an integer replication (or decimation) factor. For replication,
+# ndevice_pixels_spanned / nimage_values_output = an_integer. For
+# decimation, ndevice_pixels_spanned / nimage_values_output = 1 / an_integer.
+# The NDC coordinates returned also represent integer device pixels.
+
+procedure crt_tweak_ndc (nvalues, ndc_start, ndc_end, device_res)
+
+int nvalues # Number of image values to output
+real ndc_start, ndc_end # NDC endpoints - changed on output
+int device_res # Full device resolution
+
+int ndevice_elements, first_device_element, last_device_element, int_extra
+int dev_pixel_1, dev_pixel_2, desired_dev_elements, desired_inverse
+real ndc_extra, extra, real_extra
+double gki_tweak
+
+begin
+ gki_tweak = double (32767) / double (32768)
+ if (int (ndc_end) == 1)
+ ndc_end = gki_tweak
+ first_device_element = ndc_start * device_res
+ last_device_element = ndc_end * device_res
+ ndevice_elements = (last_device_element - first_device_element) + 1
+
+ if (mod (ndevice_elements, nvalues) != 0) {
+ # Calculate amount to be altered
+ real_extra = real (ndevice_elements) / real (nvalues)
+ if (real_extra > 1.0) {
+ # Tweak to get an integer replication factor
+ int_extra = ndevice_elements / nvalues
+ extra = real ((real_extra - int_extra) * nvalues)
+ ndc_extra = extra / device_res
+ ndc_start = ndc_start + (ndc_extra / 2.0)
+ ndc_end = ndc_end - (ndc_extra / 2.0)
+ } else {
+ # Tweak to get an integer decimation factor
+ real_extra = real (nvalues) / real (ndevice_elements)
+ desired_inverse = int (real_extra) + 1
+ desired_dev_elements = nvalues / desired_inverse
+ extra = desired_dev_elements - ndevice_elements
+ ndc_extra = real (extra) / real (device_res)
+ ndc_start = ndc_start - (ndc_extra / 2.0)
+ ndc_end = ndc_end + (ndc_extra / 2.0)
+ }
+ }
+
+ # Now have ndc coordinates of starting and ending pixel such
+ # that the replication or decimation factor is
+ # an integer. Now insure that the ndc coordinates refer to
+ # integer device pixels so that truncation later in the
+ # processing doesn't alter this replication factor. In what
+ # follows, note that dev_pixel_1 and dev_pixel_2
+ # are 0-based; dev_pixel_1 is the first pixel to be filled, and
+ # dev_pixel_2 is the first pixel NOT to be filled, in accordance
+ # with Richard's notes.
+
+ dev_pixel_1 = ndc_start * device_res
+ dev_pixel_2 = (ndc_end * device_res) + 1
+
+ ndc_start = real (dev_pixel_1) / real (device_res) / gki_tweak
+ ndc_end = real (dev_pixel_2) / real (device_res) / gki_tweak
+end