aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/photcal/mctable/mctshrink.x
diff options
context:
space:
mode:
Diffstat (limited to 'noao/digiphot/photcal/mctable/mctshrink.x')
-rw-r--r--noao/digiphot/photcal/mctable/mctshrink.x31
1 files changed, 31 insertions, 0 deletions
diff --git a/noao/digiphot/photcal/mctable/mctshrink.x b/noao/digiphot/photcal/mctable/mctshrink.x
new file mode 100644
index 00000000..6a88f230
--- /dev/null
+++ b/noao/digiphot/photcal/mctable/mctshrink.x
@@ -0,0 +1,31 @@
+include "../lib/mctable.h"
+
+
+# MCT_SHRINK - Free unused table memory
+
+procedure mct_shrink (table)
+
+pointer table # table descriptor
+
+int lsize, psize
+
+begin
+ # Check pointer and magic number.
+ if (table == NULL)
+ call error (0, "mct_shrink: Null table pointer")
+ if (MCT_MAGIC (table) != MAGIC)
+ call error (0, "mct_shrink: Bad magic number")
+
+ # Compute aproximate logical size, and exact physical
+ # sizes. This might produce a little bit of space wasted.
+
+ lsize = MCT_NPROWS (table) * MCT_MAXCOL (table)
+ psize = MCT_MAXROW (table) * MCT_MAXCOL (table)
+
+ # Reallocate table sapace and update physical size.
+ if (lsize != psize) {
+ call realloc (MCT_DATA (table), lsize, MCT_TYPE (table))
+ MCT_MAXROW (table) = MCT_NPROWS (table)
+ MCT_INCROWS (table) = GROWFACTOR (MCT_MAXROW (table))
+ }
+end