aboutsummaryrefslogtreecommitdiff
path: root/noao/nproto/ir/irimisec.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /noao/nproto/ir/irimisec.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'noao/nproto/ir/irimisec.x')
-rw-r--r--noao/nproto/ir/irimisec.x105
1 files changed, 105 insertions, 0 deletions
diff --git a/noao/nproto/ir/irimisec.x b/noao/nproto/ir/irimisec.x
new file mode 100644
index 00000000..1b6936db
--- /dev/null
+++ b/noao/nproto/ir/irimisec.x
@@ -0,0 +1,105 @@
+include <ctype.h>
+
+# IR_DECODE_SECTION -- Procedure to decode the reference section.
+
+int procedure ir_decode_section (section, ncols, nrows, c1ref, c2ref, l1ref,
+ l2ref)
+
+char section[ARB] # reference subraster section
+int ncols # number of columns in the image
+int nrows # number of rows in the image
+int c1ref # initial column
+int c2ref # final reference column
+int l1ref # initial reference line
+int l2ref # final reference line
+
+char leftbkt
+int index, ip, step
+int ir_decode_subscript(), stridx()
+
+begin
+ leftbkt = '['
+ index = stridx (leftbkt, section)
+ if (index == 0)
+ return (ERR)
+ ip = index + 1
+ if (ir_decode_subscript (section, ip, ncols, c1ref, c2ref, step) == ERR)
+ return (ERR)
+ if (ir_decode_subscript (section, ip, nrows, l1ref, l2ref, step) == ERR)
+ return (ERR)
+ return (OK)
+end
+
+
+# IR_DECODE_SUBSCRIPT -- Decode a single subscript expression to produce the
+# range of values for that subscript (X1:X2), and the sampling step size, STEP.
+# Note that X1 may be less than, greater than, or equal to X2, and STEP may
+# be a positive or negative nonzero integer. Various shorthand notations are
+# permitted, as is embedded whitespace.
+
+int procedure ir_decode_subscript (section, ip, maxnumber, x1, x2, step)
+
+char section[ARB]
+int ip
+int maxnumber
+long x1, x2, step, temp
+int ctol()
+
+begin
+ x1 = 1
+ x2 = maxnumber
+ step = 1
+
+ while (IS_WHITE(section[ip]))
+ ip = ip + 1
+
+ # Get X1, X2.
+ if (ctol (section, ip, temp) > 0) { # [x1
+ x1 = temp
+ if (section[ip] == ':') {
+ ip = ip + 1
+ if (ctol (section, ip, x2) == 0) # [x1:x2
+ return (ERR)
+ } else
+ x2 = x1
+
+ } else if (section[ip] == '-') {
+ x1 = maxnumber # [-*
+ x2 = 1
+ ip = ip + 1
+ if (section[ip] == '*')
+ ip = ip + 1
+
+ } else if (section[ip] == '*') # [*
+ ip = ip + 1
+
+ while (IS_WHITE(section[ip]))
+ ip = ip + 1
+
+ # Get sample step size, if give.
+ if (section[ip] == ':') { # ..:step
+ ip = ip + 1
+ if (ctol (section, ip, step) == 0)
+ return (ERR)
+ else if (step == 0)
+ return (ERR)
+ }
+
+ # Allow notation such as "-*:5", (or even "-:5") where the step
+ # is obviously supposed to be negative.
+
+ if (x1 > x2 && step > 0)
+ step = -step
+
+ while (IS_WHITE(section[ip]))
+ ip = ip + 1
+
+ if (section[ip] == ',') {
+ ip = ip + 1
+ return (OK)
+ } else if (section[ip] == ']')
+ return (OK)
+ else
+ return (ERR)
+
+end