aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/photcal/mctable/mctput.gx
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/digiphot/photcal/mctable/mctput.gx
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'noao/digiphot/photcal/mctable/mctput.gx')
-rw-r--r--noao/digiphot/photcal/mctable/mctput.gx68
1 files changed, 68 insertions, 0 deletions
diff --git a/noao/digiphot/photcal/mctable/mctput.gx b/noao/digiphot/photcal/mctable/mctput.gx
new file mode 100644
index 00000000..893678b1
--- /dev/null
+++ b/noao/digiphot/photcal/mctable/mctput.gx
@@ -0,0 +1,68 @@
+include "../lib/mctable.h"
+
+$for (csilrdxp)
+# MCT_PUT - Put value randomly (generic)
+
+procedure mct_put$t (table, row, col, value)
+
+pointer table # table descriptor
+int row # row number
+int col # column number
+PIXEL value # data value
+
+int offset
+pointer base
+errchk mct_indef()
+
+begin
+ # Check pointer and magic number.
+ if (table == NULL)
+ call error (0, "mct_put: Null table pointer")
+ if (MCT_MAGIC (table) != MAGIC)
+ call error (0, "mct_put: Bad magic number")
+
+ # Check the table type.
+ if (MCT_TYPE (table) != TY_PIXEL)
+ call error (0, "mct_put: Wrong table type")
+
+ # Test row and column values.
+ if (row < 1)
+ call error (0, "mct_put: Row number less than one")
+ if (col < 1 || col > MCT_MAXCOL (table))
+ call error (0, "mct_put: Column out of range")
+
+ # Reallocate space if necessary.
+ if (row > MCT_MAXROW (table)) {
+
+ # Compute offset of new area.
+ offset = MCT_MAXROW (table) * MCT_MAXCOL (table)
+
+ # Recompute new number of rows and reallocate buffer.
+ MCT_MAXROW (table) = MCT_MAXROW (table) + MCT_INCROWS (table)
+ call realloc (MCT_DATA (table),
+ MCT_MAXROW (table) * MCT_MAXCOL (table), TY_PIXEL)
+
+ # Compute base address of new area and clear it with INDEF.
+ base = MCT_DATA (table) + offset
+ call mct_indef (table, base,
+ MCT_INCROWS (table) * MCT_MAXCOL (table))
+ }
+
+ # Update row and column counter, only if the new entries are beyond
+ # the old limits.
+
+ if (row > MCT_NPROWS (table)) {
+ MCT_NPROWS (table) = row
+ MCT_NPCOLS (table) = col
+ } else if (col > MCT_NPCOLS (table))
+ MCT_NPCOLS (table) = col
+
+ # Enter variable.
+ base = MCT_DATA (table) + (row - 1) * MCT_MAXCOL (table)
+ $if (datatype == p)
+ MEMP[base + col - 1] = value
+ $else
+ Mem$t[base + col - 1] = value
+ $endif
+end
+$endfor