diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
commit | fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch) | |
tree | bdda434976bc09c864f2e4fa6f16ba1952b1e555 /noao/digiphot/photcal/mctable/mctrestore.gx | |
download | iraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz |
Initial commit
Diffstat (limited to 'noao/digiphot/photcal/mctable/mctrestore.gx')
-rw-r--r-- | noao/digiphot/photcal/mctable/mctrestore.gx | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/noao/digiphot/photcal/mctable/mctrestore.gx b/noao/digiphot/photcal/mctable/mctrestore.gx new file mode 100644 index 00000000..2e0a807f --- /dev/null +++ b/noao/digiphot/photcal/mctable/mctrestore.gx @@ -0,0 +1,135 @@ +include "../lib/mctable.h" + + +# MCT_RESTORE - Restore table from a text file. + +procedure mct_restore (fname, table) + +char fname[ARB] # file name +pointer table # table descriptor + +char cval +short sval +int fd, magic, type, row, col, nprows, npcols +int maxcol, maxrow, lastcol, ival +long lval +pointer pval +real rval +double dval +complex xval + +int open(), fscan(), nscan() +errchk mct_alloc() +errchk mct_putc(), mct_puts(), mct_puti(), mct_putl() +errchk mct_putr(), mct_putd(), mct_putx(), mct_putp() + +begin + # Open file. + iferr (fd = open (fname, READ_ONLY, TEXT_FILE)) + call error (0, "mct_restore: Cannot open file") + + # Read and check magic number. + if (fscan (fd) != EOF) { + call gargi (magic) + if (magic != MAGIC) + call error (0, "mct_restore: Bad magic number") + } else + call error (0, "mct_restore: Unexpected end of file (magic)") + + # Read type. + if (fscan (fd) != EOF) + call gargi (type) + else + call error (0, "mct_restore: Unexpected end of file (type)") + + # Read max number of rows. + if (fscan (fd) != EOF) + call gargi (maxrow) + else + call error (0, "mct_restore: Unexpected end of file (maxrow)") + + # Read max number of columns. + if (fscan (fd) != EOF) + call gargi (maxcol) + else + call error (0, "mct_restore: Unexpected end of file (maxcol)") + + # Discard row increment. + if (fscan (fd) != EOF) + call gargi (ival) + else + call error (0, "mct_restore: Unexpected end of file (incrows)") + + # Read number of rows entered. + if (fscan (fd) != EOF) + call gargi (nprows) + else + call error (0, "mct_restore: Unexpected end of file (nprows)") + + # Read number of columns entered. + if (fscan (fd) != EOF) + call gargi (npcols) + else + call error (0, "mct_restore: Unexpected end of file (npcols)") + + # Read number of rows gotten. + if (fscan (fd) != EOF) + call gargi (ival) + else + call error (0, "mct_restore: Unexpected end of file (ngrows)") + + # Read number of columns gotten + if (fscan (fd) != EOF) + call gargi (ival) + else + call error (0, "mct_restore: Unexpected end of file (ngcols)") + + # Discard data pointer. + if (fscan (fd) != EOF) + call gargi (ival) + else + call error (0, "mct_restore: Unexpected end of file (pointer)") + + # Allocate table. + call mct_alloc (table, maxrow, maxcol, type) + + # Loop over rows. + lastcol = maxcol + do row = 1, nprows { + + # In the last row the column loop should go only until the + # highest column. + if (row == nprows) + lastcol = npcols + + # Start scanning next line. + if (fscan (fd) == EOF) + call error (0, "mct_restore: Unexpected end of file (row)") + + # Loop over columns. + for (col = 1; col <= lastcol; col = col + 1) { + + # Read data. + switch (MCT_TYPE (table)) { + $for (csilrdxp) + case TY_PIXEL: + $if (datatype == p) + call gargi ($tval) + $else + call garg$t ($tval) + $endif + call mct_put$t (table, row, col, $tval) + $endfor + default: + call error (0, "mct_save: Unknown data type") + } + + # Check column read. + if (nscan () != col) + call error (0, "mct_restore: Unexpcted end of file (col)") + } + } + + # Close file. + call close (fd) +end |